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

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

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Fix build Created 4 years, 5 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/frame_connected_bluetooth_devices.h" 5 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "content/test/test_render_view_host.h" 9 #include "content/test/test_render_view_host.h"
10 #include "content/test/test_web_contents.h" 10 #include "content/test/test_web_contents.h"
11 #include "device/bluetooth/bluetooth_gatt_connection.h" 11 #include "device/bluetooth/bluetooth_gatt_connection.h"
12 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 12 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
13 #include "device/bluetooth/test/mock_bluetooth_device.h" 13 #include "device/bluetooth/test/mock_bluetooth_device.h"
14 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" 14 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using web_bluetooth::WebBluetoothDeviceId;
19
18 namespace content { 20 namespace content {
19 21
20 typedef testing::NiceMock<device::MockBluetoothAdapter> 22 typedef testing::NiceMock<device::MockBluetoothAdapter>
21 NiceMockBluetoothAdapter; 23 NiceMockBluetoothAdapter;
22 typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice; 24 typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice;
23 typedef testing::NiceMock<device::MockBluetoothGattConnection> 25 typedef testing::NiceMock<device::MockBluetoothGattConnection>
24 NiceMockBluetoothGattConnection; 26 NiceMockBluetoothGattConnection;
25 27
26 using testing::Return; 28 using testing::Return;
27 using testing::StrEq; 29 using testing::StrEq;
28 using testing::_; 30 using testing::_;
29 31
30 namespace { 32 namespace {
31 33
32 constexpr char kDeviceId0[] = "0"; 34 const WebBluetoothDeviceId kDeviceId0("000000000000000000000A==");
33 constexpr char kDeviceAddress0[] = "0"; 35 constexpr char kDeviceAddress0[] = "0";
34 constexpr char kDeviceName0[] = "Device0"; 36 constexpr char kDeviceName0[] = "Device0";
35 37
36 constexpr char kDeviceId1[] = "1"; 38 const WebBluetoothDeviceId kDeviceId1("111111111111111111111A==");
37 constexpr char kDeviceAddress1[] = "1"; 39 constexpr char kDeviceAddress1[] = "1";
38 constexpr char kDeviceName1[] = "Device1"; 40 constexpr char kDeviceName1[] = "Device1";
39 41
40 class FrameConnectedBluetoothDevicesTest 42 class FrameConnectedBluetoothDevicesTest
41 : public RenderViewHostImplTestHarness { 43 : public RenderViewHostImplTestHarness {
42 public: 44 public:
43 FrameConnectedBluetoothDevicesTest() 45 FrameConnectedBluetoothDevicesTest()
44 : adapter_(new NiceMockBluetoothAdapter()), 46 : adapter_(new NiceMockBluetoothAdapter()),
45 device0_(adapter_.get(), 47 device0_(adapter_.get(),
46 0 /* class */, 48 0 /* class */,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 222 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
221 } 223 }
222 224
223 TEST_F(FrameConnectedBluetoothDevicesTest, 225 TEST_F(FrameConnectedBluetoothDevicesTest,
224 CloseConnectionAddress_OneDevice_AddOnce_RemoveOnce) { 226 CloseConnectionAddress_OneDevice_AddOnce_RemoveOnce) {
225 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 227 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
226 228
227 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 229 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
228 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 230 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
229 231
230 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 232 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
231 kDeviceId0); 233 kDeviceId0);
232 234
233 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 235 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
234 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 236 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
235 } 237 }
236 238
237 TEST_F(FrameConnectedBluetoothDevicesTest, 239 TEST_F(FrameConnectedBluetoothDevicesTest,
238 CloseConnectionAddress_OneDevice_AddOnce_RemoveTwice) { 240 CloseConnectionAddress_OneDevice_AddOnce_RemoveTwice) {
239 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 241 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
240 242
241 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 243 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
242 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 244 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
243 245
244 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 246 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
245 kDeviceId0); 247 kDeviceId0);
246 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), ""); 248 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0));
247 249
248 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 250 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
249 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 251 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
250 } 252 }
251 253
252 TEST_F(FrameConnectedBluetoothDevicesTest, 254 TEST_F(FrameConnectedBluetoothDevicesTest,
253 CloseConnectionAddress_OneDevice_AddTwice_RemoveOnce) { 255 CloseConnectionAddress_OneDevice_AddTwice_RemoveOnce) {
254 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 256 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
255 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 257 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
256 258
257 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 259 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
258 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 260 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
259 261
260 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 262 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
261 kDeviceId0); 263 kDeviceId0);
262 264
263 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 265 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
264 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 266 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
265 } 267 }
266 268
267 TEST_F(FrameConnectedBluetoothDevicesTest, 269 TEST_F(FrameConnectedBluetoothDevicesTest,
268 CloseConnectionAddress_OneDevice_AddTwice_RemoveTwice) { 270 CloseConnectionAddress_OneDevice_AddTwice_RemoveTwice) {
269 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 271 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
270 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 272 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
271 273
272 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 274 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
273 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 275 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
274 276
275 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 277 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
276 kDeviceId0); 278 kDeviceId0);
277 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), ""); 279 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0));
278 280
279 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 281 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
280 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 282 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
281 } 283 }
282 284
283 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoDevices) { 285 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoDevices) {
284 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 286 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
285 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 287 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1));
286 288
287 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 289 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
288 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 290 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
289 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 291 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
290 292
291 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 293 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
292 kDeviceId0); 294 kDeviceId0);
293 295
294 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 296 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
295 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 297 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
296 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 298 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
297 299
298 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress1), 300 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(),
299 kDeviceId1); 301 kDeviceId1);
300 302
301 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 303 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
302 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 304 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
303 } 305 }
304 306
305 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoMaps) { 307 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoMaps) {
306 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 308 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
307 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 309 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1));
308 310
309 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 311 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
310 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 312 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
311 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 313 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
312 314
313 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 315 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
314 kDeviceId0); 316 kDeviceId0);
315 317
316 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 318 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
317 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 319 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
318 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 320 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
319 321
320 EXPECT_EQ(map1_->CloseConnectionToDeviceWithAddress(kDeviceAddress1), 322 EXPECT_EQ(map1_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(),
321 kDeviceId1); 323 kDeviceId1);
322 324
323 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 325 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
324 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 326 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
325 } 327 }
326 328
327 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) { 329 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) {
328 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 330 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
329 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 331 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1));
330 332
(...skipping 27 matching lines...) Expand all
358 DestroyedByWebContentsImplDestruction) { 360 DestroyedByWebContentsImplDestruction) {
359 // Tests that we don't crash when FrameConnectedBluetoothDevices contains 361 // Tests that we don't crash when FrameConnectedBluetoothDevices contains
360 // at least one device, and it is destroyed while WebContentsImpl is being 362 // at least one device, and it is destroyed while WebContentsImpl is being
361 // destroyed. 363 // destroyed.
362 364
363 // TODO(ortuno): Write test. 365 // TODO(ortuno): Write test.
364 // http://crbug.com/615319 366 // http://crbug.com/615319
365 } 367 }
366 368
367 } // namespace content 369 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698