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

Side by Side Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1382743002: bluetooth: Add characteristicvaluechanged event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1
Patch Set: Address more comments Created 5 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 16 matching lines...) Expand all
27 using device::BluetoothUUID; 27 using device::BluetoothUUID;
28 using device::MockBluetoothAdapter; 28 using device::MockBluetoothAdapter;
29 using device::MockBluetoothDevice; 29 using device::MockBluetoothDevice;
30 using device::MockBluetoothDiscoverySession; 30 using device::MockBluetoothDiscoverySession;
31 using device::MockBluetoothGattCharacteristic; 31 using device::MockBluetoothGattCharacteristic;
32 using device::MockBluetoothGattConnection; 32 using device::MockBluetoothGattConnection;
33 using device::MockBluetoothGattNotifySession; 33 using device::MockBluetoothGattNotifySession;
34 using device::MockBluetoothGattService; 34 using device::MockBluetoothGattService;
35 using testing::ElementsAre; 35 using testing::ElementsAre;
36 using testing::Invoke; 36 using testing::Invoke;
37 using testing::InvokeWithoutArgs;
37 using testing::ResultOf; 38 using testing::ResultOf;
38 using testing::Return; 39 using testing::Return;
39 using testing::_; 40 using testing::_;
40 41
41 typedef testing::NiceMock<MockBluetoothAdapter> NiceMockBluetoothAdapter; 42 typedef testing::NiceMock<MockBluetoothAdapter> NiceMockBluetoothAdapter;
42 typedef testing::NiceMock<MockBluetoothDevice> NiceMockBluetoothDevice; 43 typedef testing::NiceMock<MockBluetoothDevice> NiceMockBluetoothDevice;
43 typedef testing::NiceMock<MockBluetoothDiscoverySession> 44 typedef testing::NiceMock<MockBluetoothDiscoverySession>
44 NiceMockBluetoothDiscoverySession; 45 NiceMockBluetoothDiscoverySession;
45 typedef testing::NiceMock<MockBluetoothGattCharacteristic> 46 typedef testing::NiceMock<MockBluetoothGattCharacteristic>
46 NiceMockBluetoothGattCharacteristic; 47 NiceMockBluetoothGattCharacteristic;
47 typedef testing::NiceMock<MockBluetoothGattConnection> 48 typedef testing::NiceMock<MockBluetoothGattConnection>
48 NiceMockBluetoothGattConnection; 49 NiceMockBluetoothGattConnection;
49 typedef testing::NiceMock<MockBluetoothGattService> 50 typedef testing::NiceMock<MockBluetoothGattService>
50 NiceMockBluetoothGattService; 51 NiceMockBluetoothGattService;
51 typedef testing::NiceMock<MockBluetoothGattNotifySession> 52 typedef testing::NiceMock<MockBluetoothGattNotifySession>
52 NiceMockBluetoothGattNotifySession; 53 NiceMockBluetoothGattNotifySession;
53 54
54 namespace { 55 namespace {
55 // Bluetooth UUIDs suitable to pass to BluetoothUUID(). 56 // Bluetooth UUIDs suitable to pass to BluetoothUUID().
56 const char kBatteryServiceUUID[] = "180f"; 57 const char kBatteryServiceUUID[] = "180f";
57 const char kGenericAccessServiceUUID[] = "1800"; 58 const char kGenericAccessServiceUUID[] = "1800";
58 const char kGlucoseServiceUUID[] = "1808"; 59 const char kGlucoseServiceUUID[] = "1808";
59 const char kHeartRateServiceUUID[] = "180d"; 60 const char kHeartRateServiceUUID[] = "180d";
60 const char kHeartRateMeasurementUUID[] = "2a37"; 61 const char kHeartRateMeasurementUUID[] = "2a37";
62 const char kBodySensorLocation[] = "2a38";
61 const char kDeviceNameUUID[] = "2a00"; 63 const char kDeviceNameUUID[] = "2a00";
62 64
63 // Invokes Run() on the k-th argument of the function with no arguments. 65 // Invokes Run() on the k-th argument of the function with no arguments.
64 ACTION_TEMPLATE(RunCallback, 66 ACTION_TEMPLATE(RunCallback,
65 HAS_1_TEMPLATE_PARAMS(int, k), 67 HAS_1_TEMPLATE_PARAMS(int, k),
66 AND_0_VALUE_PARAMS()) { 68 AND_0_VALUE_PARAMS()) {
67 return ::testing::get<k>(args).Run(); 69 return ::testing::get<k>(args).Run();
68 } 70 }
69 71
70 // Invokes Run() on the k-th argument of the function with 1 argument. 72 // Invokes Run() on the k-th argument of the function with 1 argument.
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 device->AddMockService(generic_access.Pass()); 358 device->AddMockService(generic_access.Pass());
357 adapter->AddMockDevice(device.Pass()); 359 adapter->AddMockDevice(device.Pass());
358 360
359 return adapter.Pass(); 361 return adapter.Pass();
360 } 362 }
361 363
362 // static 364 // static
363 scoped_refptr<NiceMockBluetoothAdapter> 365 scoped_refptr<NiceMockBluetoothAdapter>
364 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { 366 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
365 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 367 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
368 // Used by lambdas that need the adapter.
369 NiceMockBluetoothAdapter* adapter_ptr = adapter.get();
370
366 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); 371 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get()));
367 scoped_ptr<NiceMockBluetoothGattService> heart_rate( 372 scoped_ptr<NiceMockBluetoothGattService> heart_rate(
368 GetBaseGATTService(device.get(), kHeartRateServiceUUID)); 373 GetBaseGATTService(device.get(), kHeartRateServiceUUID));
369 374
370 // TODO(ortuno): Implement the rest of the service's characteristics 375 // TODO(ortuno): Implement the rest of the service's characteristics
371 // See: http://crbug.com/529975 376 // See: http://crbug.com/529975
377
378 // Body Sensor Location Characteristic
379 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location(
380 GetBaseGATTCharacteristic(heart_rate.get(), kBodySensorLocation));
381 BluetoothGattCharacteristic* location_ptr = body_sensor_location.get();
382
383 ON_CALL(*body_sensor_location, ReadRemoteCharacteristic(_, _))
384 .WillByDefault(RunCallbackWithResult<0>([adapter_ptr, location_ptr]() {
scheib 2015/10/16 20:39:25 "0 /* success_callback */" just for consistency.
ortuno 2015/10/16 21:55:48 Done.
385 std::vector<uint8_t> location(1 /* size */);
386 location[0] = 1; // Chest
387 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
scheib 2015/10/16 20:39:25 Comment, E.G.: // Reading a characteristic has a s
ortuno 2015/10/16 21:55:48 Done.
388 adapter_ptr->GetObservers(),
389 GattCharacteristicValueChanged(
390 adapter_ptr, location_ptr, location));
391 return location;
392 }));
393
394 // Heart Rate Measurement Characteristic
372 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( 395 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement(
373 GetBaseGATTCharacteristic(heart_rate.get(), kHeartRateMeasurementUUID)); 396 GetBaseGATTCharacteristic(heart_rate.get(), kHeartRateMeasurementUUID));
374 BluetoothGattCharacteristic* measurement_ptr = heart_rate_measurement.get(); 397 NiceMockBluetoothGattCharacteristic* measurement_ptr =
398 heart_rate_measurement.get();
399
375 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) 400 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _))
376 .WillByDefault( 401 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
377 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() { 402 [adapter_ptr, measurement_ptr]() {
378 return GetBaseGATTNotifySession(measurement_ptr->GetIdentifier()); 403 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session(
404 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier()));
405
406 std::vector<uint8_t> rate(1 /* size */);
407 rate[0] = 60;
408
409 notify_session->StartTestNotifications(adapter_ptr, measurement_ptr,
410 rate);
411
412 return notify_session.Pass();
379 })); 413 }));
380 414
381 heart_rate->AddMockCharacteristic(heart_rate_measurement.Pass()); 415 heart_rate->AddMockCharacteristic(heart_rate_measurement.Pass());
416 heart_rate->AddMockCharacteristic(body_sensor_location.Pass());
382 device->AddMockService(heart_rate.Pass()); 417 device->AddMockService(heart_rate.Pass());
383 adapter->AddMockDevice(device.Pass()); 418 adapter->AddMockDevice(device.Pass());
384 419
385 return adapter.Pass(); 420 return adapter.Pass();
386 } 421 }
387 422
388 // static 423 // static
389 scoped_refptr<NiceMockBluetoothAdapter> 424 scoped_refptr<NiceMockBluetoothAdapter>
390 LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() { 425 LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() {
391 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 426 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 661
627 // Notify sessions 662 // Notify sessions
628 663
629 // static 664 // static
630 scoped_ptr<NiceMockBluetoothGattNotifySession> 665 scoped_ptr<NiceMockBluetoothGattNotifySession>
631 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( 666 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession(
632 const std::string& characteristic_identifier) { 667 const std::string& characteristic_identifier) {
633 scoped_ptr<NiceMockBluetoothGattNotifySession> session( 668 scoped_ptr<NiceMockBluetoothGattNotifySession> session(
634 new NiceMockBluetoothGattNotifySession(characteristic_identifier)); 669 new NiceMockBluetoothGattNotifySession(characteristic_identifier));
635 670
636 ON_CALL(*session, Stop(_)).WillByDefault(RunCallback<0>()); 671 ON_CALL(*session, Stop(_))
672 .WillByDefault(testing::DoAll(
673 InvokeWithoutArgs(
674 session.get(),
675 &MockBluetoothGattNotifySession::StopTestNotifications),
676 RunCallback<0>()));
637 677
638 return session.Pass(); 678 return session.Pass();
639 } 679 }
640 680
641 // Helper functions 681 // Helper functions
642 682
643 // static 683 // static
644 std::string LayoutTestBluetoothAdapterProvider::errorUUID(uint32_t alias) { 684 std::string LayoutTestBluetoothAdapterProvider::errorUUID(uint32_t alias) {
645 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); 685 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias);
646 } 686 }
647 687
648 // static 688 // static
649 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 689 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
650 return BluetoothDevice::CanonicalizeAddress( 690 return BluetoothDevice::CanonicalizeAddress(
651 base::StringPrintf("%012" PRIx64, addr)); 691 base::StringPrintf("%012" PRIx64, addr));
652 } 692 }
653 693
654 } // namespace content 694 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698