chromium/device/bluetooth/floss/floss_manager_client_unittest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device/bluetooth/floss/floss_manager_client.h"

#include <utility>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/task_environment.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/mock_bus.h"
#include "dbus/mock_exported_object.h"
#include "dbus/mock_object_proxy.h"
#include "dbus/object_manager.h"
#include "dbus/object_path.h"
#include "device/bluetooth/floss/floss_dbus_client.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace floss {
namespace {

DoAll;

const std::vector<std::pair<int, bool>> kMockAdaptersAvailable =;

void FakeExportMethod(
    const std::string& interface_name,
    const std::string& method_name,
    const dbus::ExportedObject::MethodCallCallback& method_call_callback,
    dbus::ExportedObject::OnExportedCallback on_exported_callback) {}

class TestManagerObserver : public FlossManagerClient::Observer {};

}  // namespace

class FlossManagerClientTest : public testing::Test {};

// Make sure adapter presence is updated on init
TEST_F(FlossManagerClientTest, QueriesAdapterPresenceOnInit) {}

// Make sure adapter presence is plumbed through callbacks
TEST_F(FlossManagerClientTest, VerifyAdapterPresent) {}

// Make sure we query the enabled state when adapter presents
TEST_F(FlossManagerClientTest, VerifyAdapterPresentEnabled) {}

// Make sure adapter powered is plumbed through callbacks
TEST_F(FlossManagerClientTest, VerifyAdapterEnabled) {}

// Make sure manager presence is correctly detected
TEST_F(FlossManagerClientTest, HandleManagerPresence) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(FlossManagerClientTest, SetFlossEnabledRetries) {
  base::RunLoop loop;

  TestManagerObserver observer(client_.get());
  floss_enabled_target_ = false;
  client_->Init(bus_.get(), kManagerInterface, /*adapter_index=*/-1,
                GetCurrVersion(), base::DoNothing());

  // First confirm we had it set to False
  EXPECT_EQ(method_called_[manager::kSetFlossEnabled], 1);
  EXPECT_EQ(method_called_[manager::kGetFlossEnabled], 1);

  method_called_.clear();

  // Retries up to 3 times across both Get and Set.
  fail_setfloss_count_ = 1;
  fail_getfloss_count_ = 1;
  floss_enabled_target_ = true;
  SetFlossEnabled(true, 3, 0, loop.QuitClosure());
  loop.Run();

  EXPECT_EQ(method_called_[manager::kSetFlossEnabled], 2);
  EXPECT_EQ(method_called_[manager::kGetFlossEnabled], 2);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

TEST_F(FlossManagerClientTest, GetFlossApiVersion) {}

TEST_F(FlossManagerClientTest, NewFlossDaemonIsNotCompatible) {}
}  // namespace floss