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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc

Issue 263333003: chrome.bluetoothLowEnergy: Implement writeCharacteristicValue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" 6 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h"
7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h" 7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/extensions/extension_test_message_listener.h" 10 #include "chrome/browser/extensions/extension_test_message_listener.h"
11 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 11 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
12 #include "device/bluetooth/test/mock_bluetooth_device.h" 12 #include "device/bluetooth/test/mock_bluetooth_device.h"
13 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" 13 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"
14 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h" 14 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 16
17 using device::BluetoothUUID; 17 using device::BluetoothUUID;
18 using device::BluetoothAdapter; 18 using device::BluetoothAdapter;
19 using device::BluetoothDevice; 19 using device::BluetoothDevice;
20 using device::BluetoothGattCharacteristic; 20 using device::BluetoothGattCharacteristic;
21 using device::BluetoothGattService; 21 using device::BluetoothGattService;
22 using device::MockBluetoothAdapter; 22 using device::MockBluetoothAdapter;
23 using device::MockBluetoothDevice; 23 using device::MockBluetoothDevice;
24 using device::MockBluetoothGattCharacteristic; 24 using device::MockBluetoothGattCharacteristic;
25 using device::MockBluetoothGattService; 25 using device::MockBluetoothGattService;
26 using extensions::BluetoothLowEnergyEventRouter; 26 using extensions::BluetoothLowEnergyEventRouter;
27 using testing::Invoke; 27 using testing::Invoke;
28 using testing::Return; 28 using testing::Return;
29 using testing::ReturnRef;
29 using testing::ReturnRefOfCopy; 30 using testing::ReturnRefOfCopy;
31 using testing::SaveArg;
30 using testing::_; 32 using testing::_;
31 33
32 namespace utils = extension_function_test_utils; 34 namespace utils = extension_function_test_utils;
33 35
34 namespace { 36 namespace {
35 37
36 const char kTestLeDeviceAddress[] = "11:22:33:44:55:66"; 38 const char kTestLeDeviceAddress[] = "11:22:33:44:55:66";
37 const char kTestLeDeviceName[] = "Test LE Device"; 39 const char kTestLeDeviceName[] = "Test LE Device";
38 40
39 const char kTestServiceId0[] = "service_id0"; 41 const char kTestServiceId0[] = "service_id0";
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 std::vector<uint8> value; 173 std::vector<uint8> value;
172 callback.Run(value); 174 callback.Run(value);
173 } 175 }
174 176
175 void ReadValueErrorCallback( 177 void ReadValueErrorCallback(
176 const base::Callback<void(const std::vector<uint8>&)>& callback, 178 const base::Callback<void(const std::vector<uint8>&)>& callback,
177 const base::Closure& error_callback) { 179 const base::Closure& error_callback) {
178 error_callback.Run(); 180 error_callback.Run();
179 } 181 }
180 182
183 void WriteValueSuccessCallback(const std::vector<uint8>& value,
184 const base::Closure& callback,
185 const base::Closure& error_callback) {
186 callback.Run();
187 }
188
189 void WriteValueErrorCallback(const std::vector<uint8>& value,
190 const base::Closure& callback,
191 const base::Closure& error_callback) {
192 error_callback.Run();
193 }
194
181 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { 195 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) {
182 ResultCatcher catcher; 196 ResultCatcher catcher;
183 catcher.RestrictToProfile(browser()->profile()); 197 catcher.RestrictToProfile(browser()->profile());
184 198
185 std::vector<BluetoothGattService*> services; 199 std::vector<BluetoothGattService*> services;
186 services.push_back(service0_.get()); 200 services.push_back(service0_.get());
187 services.push_back(service1_.get()); 201 services.push_back(service1_.get());
188 202
189 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 203 EXPECT_CALL(*mock_adapter_, GetDevice(_))
190 .Times(3) 204 .Times(3)
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 559
546 listener.Reply("go"); 560 listener.Reply("go");
547 561
548 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 562 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
549 563
550 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 564 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get());
551 event_router()->GattServiceRemoved(device_.get(), service0_.get()); 565 event_router()->GattServiceRemoved(device_.get(), service0_.get());
552 event_router()->DeviceRemoved(mock_adapter_, device_.get()); 566 event_router()->DeviceRemoved(mock_adapter_, device_.get());
553 } 567 }
554 568
569 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) {
570 ResultCatcher catcher;
571 catcher.RestrictToProfile(browser()->profile());
572
573 event_router()->DeviceAdded(mock_adapter_, device_.get());
574 event_router()->GattServiceAdded(device_.get(), service0_.get());
575 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get());
576
577 EXPECT_CALL(*mock_adapter_, GetDevice(_))
578 .Times(3)
579 .WillRepeatedly(Return(device_.get()));
580
581 EXPECT_CALL(*device_, GetGattService(kTestServiceId0))
582 .Times(3)
583 .WillRepeatedly(Return(service0_.get()));
584
585 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
586 .Times(3)
587 .WillRepeatedly(Return(chrc0_.get()));
588
589 std::vector<uint8> write_value;
590 EXPECT_CALL(*chrc0_, WriteRemoteCharacteristic(_, _, _))
591 .Times(2)
592 .WillOnce(Invoke(&WriteValueErrorCallback))
593 .WillOnce(
594 DoAll(SaveArg<0>(&write_value), Invoke(&WriteValueSuccessCallback)));
595 EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
596
597 ExtensionTestMessageListener listener("ready", true);
598 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
599 "bluetooth_low_energy/write_characteristic_value")));
600 EXPECT_TRUE(listener.WaitUntilSatisfied());
601
602 listener.Reply("go");
603
604 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
605
606 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get());
607 event_router()->GattServiceRemoved(device_.get(), service0_.get());
608 event_router()->DeviceRemoved(mock_adapter_, device_.get());
609 }
610
555 } // namespace 611 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698