Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc

Issue 2762023002: work in progress 2
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc
diff --git a/content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc b/content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc
index 42e689d8d340f722dd550410e09d5763141a52d1..e1aef880ca3531eeecf0e6c67fbffbe4ba13a473 100644
--- a/content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc
+++ b/content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc
@@ -3,12 +3,114 @@
// found in the LICENSE file.
#include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/memory/ref_counted.h"
+#include "content/browser/bluetooth/web_bluetooth_service_impl.h"
+#include "content/test/test_render_view_host.h"
+#include "content/test/test_web_contents.h"
+#include "device/bluetooth/bluetooth_gatt_connection.h"
+#include "device/bluetooth/test/mock_bluetooth_adapter.h"
+#include "device/bluetooth/test/mock_bluetooth_device.h"
+#include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "base/logging.h"
+
namespace content {
-class BluetoothDeviceChooserControllerTest : public testing::Test {};
+typedef testing::NiceMock<device::MockBluetoothAdapter>
+ NiceMockBluetoothAdapter;
+typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice;
+//typedef testing::NiceMock<device::MockBluetoothGattConnection>
+// NiceMockBluetoothGattConnection;
+
+//using testing::Return;
+//using testing::StrEq;
+//using testing::_;
+
+namespace {
+
+const WebBluetoothDeviceId kDeviceId("000000000000000000000A==");
+constexpr char kDeviceAddress[] = "0";
+constexpr char kDeviceName[] = "Device0";
+
+} // namespace
+
+// class BluetoothDeviceChooserControllerTest : public testing::Test {};
+class BluetoothDeviceChooserControllerTest
+ : public RenderViewHostImplTestHarness {
+ public:
+ BluetoothDeviceChooserControllerTest()
+ : adapter_(new NiceMockBluetoothAdapter()),
+ device_(adapter_.get(),
+ 0 /* class */,
+ kDeviceName,
+ kDeviceAddress,
+ false /* paired */,
+ false /* connected */) {
+ LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::BluetoothDeviceChooserControllerTest";
+ //ON_CALL(*adapter_, GetDevice(_)).WillByDefault(Return(nullptr));
+ //ON_CALL(*adapter_, GetDevice(StrEq(kDeviceAddress)))
+ // .WillByDefault(Return(&device_));
+ }
+
+ ~BluetoothDeviceChooserControllerTest() override {}
+
+ void SetUp() override {
+ LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::SetUp";
+ RenderViewHostImplTestHarness::SetUp();
+
+ // Create subframe to simulate two maps on the same WebContents.
+ // contents()->GetMainFrame()->InitializeRenderFrameIfNeeded();
+ //TestRenderFrameHost* subframe =
+ // contents()->GetMainFrame()->AppendChild("bluetooth_frame");
+ //subframe->InitializeRenderFrameIfNeeded();
+ service_ =
+ contents()->GetMainFrame()->CreateWebBluetoothServiceForTesting();
+
+ //contents()->GetMainFrame()->SimulateRequestDevice(service_);
+ //controller_ = new BluetoothDeviceChooserController(service_, contents()->GetMainFrame(), adapter_.get());
+ //service_->DeviceAdded(adapter_.get(), &device_);
+
+ //service_->SimulateRequestDevice();
+ }
+
+ void TearDown() override {
+ LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::TearDown";
+ service_ = nullptr;
+ RenderViewHostImplTestHarness::TearDown();
+ }
+
+ //std::unique_ptr<NiceMockBluetoothGattConnection> GetConnection(
+ // const std::string& address) {
+ // LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::GetConnection";
+ // return base::MakeUnique<NiceMockBluetoothGattConnection>(adapter_.get(),
+ // address);
+ //}
+
+ void StartDeviceDiscovery() {
+ controller_->StartDeviceDiscoveryForTesting();
+ }
+ void AdapterDiscoveringChanged(bool discovering) {
+ LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::AdapterDiscoveringChanged";
+ service_->AdapterDiscoveringChanged(adapter_.get(), discovering);
+ }
+
+ bool IsDiscoverySessionActive() {
+ return service_->IsDiscoverySessionActive();
+ }
+
+ private:
+ WebBluetoothServiceImpl* service_;
+ scoped_refptr<NiceMockBluetoothAdapter> adapter_;
+ NiceMockBluetoothDevice device_;
+ BluetoothDeviceChooserController* controller_;
+};
+
+#if 0
TEST_F(BluetoothDeviceChooserControllerTest, CalculateSignalStrengthLevel) {
EXPECT_EQ(
0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-128));
@@ -35,5 +137,14 @@ TEST_F(BluetoothDeviceChooserControllerTest, CalculateSignalStrengthLevel) {
EXPECT_EQ(
4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(127));
}
+#endif
+
+TEST_F(BluetoothDeviceChooserControllerTest, AdapterDiscoveringChanged) {
+ LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::AdapterDiscoveringChanged start";
+ StartDeviceDiscovery();
+ EXPECT_TRUE(IsDiscoverySessionActive());
+ AdapterDiscoveringChanged(true);
+ EXPECT_FALSE(IsDiscoverySessionActive());
+}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698