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

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 tkent's 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 /* success_callback */>(
385 [adapter_ptr, location_ptr]() {
386 std::vector<uint8_t> location(1 /* size */);
387 location[0] = 1; // Chest
388 // Read a characteristic has a side effect of
389 // GattCharacteristicValueChanged being called.
390 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
391 adapter_ptr->GetObservers(),
392 GattCharacteristicValueChanged(
393 adapter_ptr, location_ptr, location));
394 return location;
395 }));
396
397 // Heart Rate Measurement Characteristic
372 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( 398 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement(
373 GetBaseGATTCharacteristic(heart_rate.get(), kHeartRateMeasurementUUID)); 399 GetBaseGATTCharacteristic(heart_rate.get(), kHeartRateMeasurementUUID));
374 BluetoothGattCharacteristic* measurement_ptr = heart_rate_measurement.get(); 400 NiceMockBluetoothGattCharacteristic* measurement_ptr =
401 heart_rate_measurement.get();
402
375 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) 403 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _))
376 .WillByDefault( 404 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
377 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() { 405 [adapter_ptr, measurement_ptr]() {
378 return GetBaseGATTNotifySession(measurement_ptr->GetIdentifier()); 406 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session(
407 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier()));
408
409 std::vector<uint8_t> rate(1 /* size */);
410 rate[0] = 60;
411
412 notify_session->StartTestNotifications(adapter_ptr, measurement_ptr,
413 rate);
414
415 return notify_session.Pass();
379 })); 416 }));
380 417
381 heart_rate->AddMockCharacteristic(heart_rate_measurement.Pass()); 418 heart_rate->AddMockCharacteristic(heart_rate_measurement.Pass());
419 heart_rate->AddMockCharacteristic(body_sensor_location.Pass());
382 device->AddMockService(heart_rate.Pass()); 420 device->AddMockService(heart_rate.Pass());
383 adapter->AddMockDevice(device.Pass()); 421 adapter->AddMockDevice(device.Pass());
384 422
385 return adapter.Pass(); 423 return adapter.Pass();
386 } 424 }
387 425
388 // static 426 // static
389 scoped_refptr<NiceMockBluetoothAdapter> 427 scoped_refptr<NiceMockBluetoothAdapter>
390 LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() { 428 LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() {
391 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 429 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 664
627 // Notify sessions 665 // Notify sessions
628 666
629 // static 667 // static
630 scoped_ptr<NiceMockBluetoothGattNotifySession> 668 scoped_ptr<NiceMockBluetoothGattNotifySession>
631 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( 669 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession(
632 const std::string& characteristic_identifier) { 670 const std::string& characteristic_identifier) {
633 scoped_ptr<NiceMockBluetoothGattNotifySession> session( 671 scoped_ptr<NiceMockBluetoothGattNotifySession> session(
634 new NiceMockBluetoothGattNotifySession(characteristic_identifier)); 672 new NiceMockBluetoothGattNotifySession(characteristic_identifier));
635 673
636 ON_CALL(*session, Stop(_)).WillByDefault(RunCallback<0>()); 674 ON_CALL(*session, Stop(_))
675 .WillByDefault(testing::DoAll(
676 InvokeWithoutArgs(
677 session.get(),
678 &MockBluetoothGattNotifySession::StopTestNotifications),
679 RunCallback<0>()));
637 680
638 return session.Pass(); 681 return session.Pass();
639 } 682 }
640 683
641 // Helper functions 684 // Helper functions
642 685
643 // static 686 // static
644 std::string LayoutTestBluetoothAdapterProvider::errorUUID(uint32_t alias) { 687 std::string LayoutTestBluetoothAdapterProvider::errorUUID(uint32_t alias) {
645 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); 688 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias);
646 } 689 }
647 690
648 // static 691 // static
649 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 692 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
650 return BluetoothDevice::CanonicalizeAddress( 693 return BluetoothDevice::CanonicalizeAddress(
651 base::StringPrintf("%012" PRIx64, addr)); 694 base::StringPrintf("%012" PRIx64, addr));
652 } 695 }
653 696
654 } // namespace content 697 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698