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

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

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