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

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: Rebase Created 4 years, 4 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/browser/bluetooth/web_bluetooth_service_impl.h" 9 #include "content/browser/bluetooth/web_bluetooth_service_impl.h"
10 #include "content/test/test_render_view_host.h" 10 #include "content/test/test_render_view_host.h"
(...skipping 12 matching lines...) Expand all
23 typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice; 23 typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice;
24 typedef testing::NiceMock<device::MockBluetoothGattConnection> 24 typedef testing::NiceMock<device::MockBluetoothGattConnection>
25 NiceMockBluetoothGattConnection; 25 NiceMockBluetoothGattConnection;
26 26
27 using testing::Return; 27 using testing::Return;
28 using testing::StrEq; 28 using testing::StrEq;
29 using testing::_; 29 using testing::_;
30 30
31 namespace { 31 namespace {
32 32
33 constexpr char kDeviceId0[] = "0"; 33 const WebBluetoothDeviceId kDeviceId0("000000000000000000000A==");
34 constexpr char kDeviceAddress0[] = "0"; 34 constexpr char kDeviceAddress0[] = "0";
35 constexpr char kDeviceName0[] = "Device0"; 35 constexpr char kDeviceName0[] = "Device0";
36 36
37 constexpr char kDeviceId1[] = "1"; 37 const WebBluetoothDeviceId kDeviceId1("111111111111111111111A==");
38 constexpr char kDeviceAddress1[] = "1"; 38 constexpr char kDeviceAddress1[] = "1";
39 constexpr char kDeviceName1[] = "Device1"; 39 constexpr char kDeviceName1[] = "Device1";
40 40
41 } // namespace 41 } // namespace
42 42
43 class FrameConnectedBluetoothDevicesTest 43 class FrameConnectedBluetoothDevicesTest
44 : public RenderViewHostImplTestHarness { 44 : public RenderViewHostImplTestHarness {
45 public: 45 public:
46 FrameConnectedBluetoothDevicesTest() 46 FrameConnectedBluetoothDevicesTest()
47 : adapter_(new NiceMockBluetoothAdapter()), 47 : adapter_(new NiceMockBluetoothAdapter()),
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 248 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
249 } 249 }
250 250
251 TEST_F(FrameConnectedBluetoothDevicesTest, 251 TEST_F(FrameConnectedBluetoothDevicesTest,
252 CloseConnectionAddress_OneDevice_AddOnce_RemoveOnce) { 252 CloseConnectionAddress_OneDevice_AddOnce_RemoveOnce) {
253 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 253 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
254 254
255 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 255 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
256 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 256 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
257 257
258 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 258 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
259 kDeviceId0); 259 kDeviceId0);
260 260
261 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 261 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
262 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 262 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
263 } 263 }
264 264
265 TEST_F(FrameConnectedBluetoothDevicesTest, 265 TEST_F(FrameConnectedBluetoothDevicesTest,
266 CloseConnectionAddress_OneDevice_AddOnce_RemoveTwice) { 266 CloseConnectionAddress_OneDevice_AddOnce_RemoveTwice) {
267 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 267 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
268 268
269 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 269 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
270 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 270 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
271 271
272 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 272 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
273 kDeviceId0); 273 kDeviceId0);
274 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), ""); 274 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0));
275 275
276 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 276 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
277 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 277 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
278 } 278 }
279 279
280 TEST_F(FrameConnectedBluetoothDevicesTest, 280 TEST_F(FrameConnectedBluetoothDevicesTest,
281 CloseConnectionAddress_OneDevice_AddTwice_RemoveOnce) { 281 CloseConnectionAddress_OneDevice_AddTwice_RemoveOnce) {
282 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 282 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
283 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 283 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
284 284
285 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 285 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
286 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 286 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
287 287
288 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 288 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
289 kDeviceId0); 289 kDeviceId0);
290 290
291 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 291 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
292 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 292 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
293 } 293 }
294 294
295 TEST_F(FrameConnectedBluetoothDevicesTest, 295 TEST_F(FrameConnectedBluetoothDevicesTest,
296 CloseConnectionAddress_OneDevice_AddTwice_RemoveTwice) { 296 CloseConnectionAddress_OneDevice_AddTwice_RemoveTwice) {
297 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 297 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
298 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 298 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
299 299
300 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 300 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
301 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 301 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
302 302
303 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 303 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
304 kDeviceId0); 304 kDeviceId0);
305 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), ""); 305 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0));
306 306
307 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 307 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
308 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 308 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
309 } 309 }
310 310
311 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoDevices) { 311 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoDevices) {
312 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 312 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
313 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 313 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1));
314 314
315 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 315 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
316 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 316 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
317 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 317 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
318 318
319 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 319 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
320 kDeviceId0); 320 kDeviceId0);
321 321
322 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 322 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
323 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 323 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
324 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 324 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
325 325
326 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress1), 326 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(),
327 kDeviceId1); 327 kDeviceId1);
328 328
329 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 329 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
330 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 330 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
331 } 331 }
332 332
333 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoMaps) { 333 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoMaps) {
334 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 334 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
335 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 335 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1));
336 336
337 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 337 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
338 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 338 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
339 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 339 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
340 340
341 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0), 341 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
342 kDeviceId0); 342 kDeviceId0);
343 343
344 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 344 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
345 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 345 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
346 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 346 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
347 347
348 EXPECT_EQ(map1_->CloseConnectionToDeviceWithAddress(kDeviceAddress1), 348 EXPECT_EQ(map1_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(),
349 kDeviceId1); 349 kDeviceId1);
350 350
351 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 351 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
352 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 352 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
353 } 353 }
354 354
355 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) { 355 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) {
356 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 356 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
357 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 357 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1));
358 358
(...skipping 26 matching lines...) Expand all
385 TEST_F(FrameConnectedBluetoothDevicesTest, 385 TEST_F(FrameConnectedBluetoothDevicesTest,
386 DestroyedByWebContentsImplDestruction) { 386 DestroyedByWebContentsImplDestruction) {
387 // Tests that we don't crash when FrameConnectedBluetoothDevices contains 387 // Tests that we don't crash when FrameConnectedBluetoothDevices contains
388 // at least one device, and it is destroyed while WebContentsImpl is being 388 // at least one device, and it is destroyed while WebContentsImpl is being
389 // destroyed. 389 // destroyed.
390 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 390 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
391 DeleteContents(); 391 DeleteContents();
392 } 392 }
393 393
394 } // namespace content 394 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/frame_connected_bluetooth_devices.cc ('k') | content/browser/bluetooth/web_bluetooth_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698