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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" 5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/memory/ref_counted.h"
9 #include "content/browser/bluetooth/web_bluetooth_service_impl.h"
10 #include "content/test/test_render_view_host.h"
11 #include "content/test/test_web_contents.h"
12 #include "device/bluetooth/bluetooth_gatt_connection.h"
13 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
14 #include "device/bluetooth/test/mock_bluetooth_device.h"
15 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
16 #include "testing/gmock/include/gmock/gmock.h"
6 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
7 18
19 #include "base/logging.h"
20
8 namespace content { 21 namespace content {
9 22
10 class BluetoothDeviceChooserControllerTest : public testing::Test {}; 23 typedef testing::NiceMock<device::MockBluetoothAdapter>
24 NiceMockBluetoothAdapter;
25 typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice;
26 //typedef testing::NiceMock<device::MockBluetoothGattConnection>
27 // NiceMockBluetoothGattConnection;
11 28
29 //using testing::Return;
30 //using testing::StrEq;
31 //using testing::_;
32
33 namespace {
34
35 const WebBluetoothDeviceId kDeviceId("000000000000000000000A==");
36 constexpr char kDeviceAddress[] = "0";
37 constexpr char kDeviceName[] = "Device0";
38
39 } // namespace
40
41 // class BluetoothDeviceChooserControllerTest : public testing::Test {};
42 class BluetoothDeviceChooserControllerTest
43 : public RenderViewHostImplTestHarness {
44 public:
45 BluetoothDeviceChooserControllerTest()
46 : adapter_(new NiceMockBluetoothAdapter()),
47 device_(adapter_.get(),
48 0 /* class */,
49 kDeviceName,
50 kDeviceAddress,
51 false /* paired */,
52 false /* connected */) {
53 LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::BluetoothDevice ChooserControllerTest";
54 //ON_CALL(*adapter_, GetDevice(_)).WillByDefault(Return(nullptr));
55 //ON_CALL(*adapter_, GetDevice(StrEq(kDeviceAddress)))
56 // .WillByDefault(Return(&device_));
57 }
58
59 ~BluetoothDeviceChooserControllerTest() override {}
60
61 void SetUp() override {
62 LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::SetUp";
63 RenderViewHostImplTestHarness::SetUp();
64
65 // Create subframe to simulate two maps on the same WebContents.
66 // contents()->GetMainFrame()->InitializeRenderFrameIfNeeded();
67 //TestRenderFrameHost* subframe =
68 // contents()->GetMainFrame()->AppendChild("bluetooth_frame");
69 //subframe->InitializeRenderFrameIfNeeded();
70
71 service_ =
72 contents()->GetMainFrame()->CreateWebBluetoothServiceForTesting();
73
74 //contents()->GetMainFrame()->SimulateRequestDevice(service_);
75 //controller_ = new BluetoothDeviceChooserController(service_, contents()->G etMainFrame(), adapter_.get());
76 //service_->DeviceAdded(adapter_.get(), &device_);
77
78 //service_->SimulateRequestDevice();
79 }
80
81 void TearDown() override {
82 LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::TearDown";
83 service_ = nullptr;
84 RenderViewHostImplTestHarness::TearDown();
85 }
86
87 //std::unique_ptr<NiceMockBluetoothGattConnection> GetConnection(
88 // const std::string& address) {
89 // LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::GetConnection ";
90 // return base::MakeUnique<NiceMockBluetoothGattConnection>(adapter_.get(),
91 // address);
92 //}
93
94 void StartDeviceDiscovery() {
95 controller_->StartDeviceDiscoveryForTesting();
96 }
97 void AdapterDiscoveringChanged(bool discovering) {
98 LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::AdapterDiscover ingChanged";
99 service_->AdapterDiscoveringChanged(adapter_.get(), discovering);
100 }
101
102 bool IsDiscoverySessionActive() {
103 return service_->IsDiscoverySessionActive();
104 }
105
106 private:
107 WebBluetoothServiceImpl* service_;
108 scoped_refptr<NiceMockBluetoothAdapter> adapter_;
109 NiceMockBluetoothDevice device_;
110 BluetoothDeviceChooserController* controller_;
111 };
112
113 #if 0
12 TEST_F(BluetoothDeviceChooserControllerTest, CalculateSignalStrengthLevel) { 114 TEST_F(BluetoothDeviceChooserControllerTest, CalculateSignalStrengthLevel) {
13 EXPECT_EQ( 115 EXPECT_EQ(
14 0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-128)); 116 0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-128));
15 EXPECT_EQ( 117 EXPECT_EQ(
16 0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-72)); 118 0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-72));
17 119
18 EXPECT_EQ( 120 EXPECT_EQ(
19 1, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-71)); 121 1, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-71));
20 EXPECT_EQ( 122 EXPECT_EQ(
21 1, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-64)); 123 1, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-64));
22 124
23 EXPECT_EQ( 125 EXPECT_EQ(
24 2, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-63)); 126 2, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-63));
25 EXPECT_EQ( 127 EXPECT_EQ(
26 2, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-56)); 128 2, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-56));
27 129
28 EXPECT_EQ( 130 EXPECT_EQ(
29 3, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-55)); 131 3, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-55));
30 EXPECT_EQ( 132 EXPECT_EQ(
31 3, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-48)); 133 3, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-48));
32 134
33 EXPECT_EQ( 135 EXPECT_EQ(
34 4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-47)); 136 4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-47));
35 EXPECT_EQ( 137 EXPECT_EQ(
36 4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(127)); 138 4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(127));
37 } 139 }
140 #endif
141
142 TEST_F(BluetoothDeviceChooserControllerTest, AdapterDiscoveringChanged) {
143 LOG(ERROR) << "[DJKim] BluetoothDeviceChooserControllerTest::AdapterDiscoverin gChanged start";
144 StartDeviceDiscovery();
145 EXPECT_TRUE(IsDiscoverySessionActive());
146 AdapterDiscoveringChanged(true);
147 EXPECT_FALSE(IsDiscoverySessionActive());
148 }
38 149
39 } // namespace content 150 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698