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

Side by Side Diff: content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc

Issue 2735773002: work in progress
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
10 #include "base/bind.h"
11 #include "base/callback.h"
12
13 #include "content/browser/bluetooth/web_bluetooth_service_impl.h"
14 #include "content/test/test_render_view_host.h"
15 #include "content/test/test_web_contents.h"
16 #include "device/bluetooth/bluetooth_gatt_connection.h"
17 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
18 #include "device/bluetooth/test/mock_bluetooth_device.h"
19 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
20 #include "testing/gmock/include/gmock/gmock.h"
6 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
7 22
23 #include "base/macros.h"
24 #include "base/optional.h"
25
26 #include "content/browser/bad_message.h"
27 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
28 #include "content/common/content_export.h"
29 #include "content/public/browser/web_contents_observer.h"
30
31 #include "device/bluetooth/bluetooth_gatt_connection.h"
32 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
33 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
34 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
35
36 #include "mojo/public/cpp/bindings/binding.h"
37
38 #include "device/bluetooth/bluetooth_advertisement.h"
39 #include "device/bluetooth/bluetooth_device.h"
40 #include "device/bluetooth/bluetooth_export.h"
41
8 namespace content { 42 namespace content {
9 43
10 class BluetoothDeviceChooserControllerTest : public testing::Test {}; 44 // class BluetoothDeviceChooserControllerTest : public testing::Test {};
45 typedef testing::NiceMock<device::MockBluetoothAdapter>
46 NiceMockBluetoothAdapter;
47 typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice;
48 typedef testing::NiceMock<device::MockBluetoothDiscoverySession>
49 NiceMockBluetoothDiscoverySession;
50
51 namespace {
52
53 const WebBluetoothDeviceId kDeviceId("000000000000000000000A==");
54 constexpr char kDeviceAddress[] = "0";
55 constexpr char kDeviceName[] = "Device0";
56
57 } // namespace
58
59 class BluetoothDeviceChooserControllerTest
60 : public RenderViewHostImplTestHarness {
61 public:
62 BluetoothDeviceChooserControllerTest()
63 : adapter_(new NiceMockBluetoothAdapter()),
64 device_(adapter_.get(),
65 0 /* class */,
66 kDeviceName,
67 kDeviceAddress,
68 false /* paired */,
69 false /* connected */),
70 weak_ptr_factory_(this) {}
71
72 ~BluetoothDeviceChooserControllerTest() override {}
73
74 void SetUp() override {
75 RenderViewHostImplTestHarness::SetUp();
76
77 service_ =
78 contents()->GetMainFrame()->CreateWebBluetoothServiceForTesting();
79
80 controller_ = new BluetoothDeviceChooserController(
81 service_, contents()->GetMainFrame(), adapter_.get());
82 }
83
84 void TearDown() override {
85 service_ = nullptr;
86 if (controller_)
87 delete controller_;
88 RenderViewHostImplTestHarness::TearDown();
89 }
90
91 void AdapterDiscoveringChanged(bool discovering) {
92 service_->ChangeAdapterDiscoveringForTesting(adapter_.get(), discovering);
93 }
94
95 bool IsDiscoverySessionActive() {
96 return service_->IsDiscoverySessionActiveForTesting();
97 }
98
99 void GetDevice() {
100 // blink::mojom::WebBluetoothRequestDeviceOptionsPtr options;
101 // blink::mojom::WebBluetoothRequestDeviceOptionsPtr empty_options_;
102 // VoidSyncCallbackHelper* helper = VoidSyncCallbackHelper::create();
103
104 // controller_->GetDevice(blink::mojom::WebBluetoothRequestDeviceOptions::Ne w(),//,
105 // helper->getSuccessCallback(), helper->getErrorCallback());
106
107 // base::Bind(&BluetoothDeviceChooserControllerTest::OnGetDeviceFailed,
108 // weak_ptr_factory_.GetWeakPtr(), nullptr));
109
110 // service_->OnGetDeviceSuccess,
111 }
112
113 #if 0
114 void OnGetDeviceSuccess(
115 const blink::RequestDeviceCallback& callback,
116 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options,
117 const std::string& device_address) {
118 LOG(ERROR) << "[DJKim] OnGetDeviceSuccess";
119 }
120
121 void OnGetDeviceFailed(
122 const blink::RequestDeviceCallback& callback,
123 blink::mojom::WebBluetoothResult result) {
124 LOG(ERROR) << "[DJKim] OnGetDeviceFailed";
125 }
126 #endif
127
128 protected:
129 WebBluetoothServiceImpl* service_;
130
131 private:
132 scoped_refptr<NiceMockBluetoothAdapter> adapter_;
133 NiceMockBluetoothDevice device_;
134 BluetoothDeviceChooserController* controller_;
135 base::WeakPtrFactory<BluetoothDeviceChooserControllerTest> weak_ptr_factory_;
136
137 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChooserControllerTest);
138 };
11 139
12 TEST_F(BluetoothDeviceChooserControllerTest, CalculateSignalStrengthLevel) { 140 TEST_F(BluetoothDeviceChooserControllerTest, CalculateSignalStrengthLevel) {
13 EXPECT_EQ( 141 EXPECT_EQ(
14 0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-128)); 142 0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-128));
15 EXPECT_EQ( 143 EXPECT_EQ(
16 0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-72)); 144 0, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-72));
17 145
18 EXPECT_EQ( 146 EXPECT_EQ(
19 1, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-71)); 147 1, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-71));
20 EXPECT_EQ( 148 EXPECT_EQ(
21 1, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-64)); 149 1, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-64));
22 150
23 EXPECT_EQ( 151 EXPECT_EQ(
24 2, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-63)); 152 2, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-63));
25 EXPECT_EQ( 153 EXPECT_EQ(
26 2, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-56)); 154 2, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-56));
27 155
28 EXPECT_EQ( 156 EXPECT_EQ(
29 3, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-55)); 157 3, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-55));
30 EXPECT_EQ( 158 EXPECT_EQ(
31 3, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-48)); 159 3, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-48));
32 160
33 EXPECT_EQ( 161 EXPECT_EQ(
34 4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-47)); 162 4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(-47));
35 EXPECT_EQ( 163 EXPECT_EQ(
36 4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(127)); 164 4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(127));
37 } 165 }
38 166
167 TEST_F(BluetoothDeviceChooserControllerTest, AdapterDiscoveringChanged) {
168 GetDevice();
169 AdapterDiscoveringChanged(true);
170 EXPECT_TRUE(IsDiscoverySessionActive());
171 }
172
39 } // namespace content 173 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698