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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc
diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc
index 1a35bb48cae385013655764cec7c4cba044d1e35..03f04ea11b05a7831a83d3f99d3494aed4d100cc 100644
--- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc
+++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc
@@ -24,7 +24,9 @@ using device::MockBluetoothDevice;
using device::MockBluetoothGattCharacteristic;
using device::MockBluetoothGattService;
using testing::Return;
+using testing::ReturnRef;
using testing::ReturnRefOfCopy;
+using testing::SaveArg;
using testing::_;
namespace utils = extension_function_test_utils;
@@ -163,6 +165,18 @@ class BluetoothLowEnergyApiTest : public ExtensionApiTest {
scoped_refptr<extensions::Extension> empty_extension_;
};
+void WriteValueSuccessCallback(const std::vector<uint8>& value,
+ const base::Closure& callback,
+ const base::Closure& error_callback) {
+ callback.Run();
+}
+
+void WriteValueErrorCallback(const std::vector<uint8>& value,
+ const base::Closure& callback,
+ const base::Closure& error_callback) {
+ error_callback.Run();
+}
+
IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) {
ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile());
@@ -465,4 +479,45 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) {
event_router()->DeviceRemoved(mock_adapter_, device_.get());
}
+IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) {
+ ResultCatcher catcher;
+ catcher.RestrictToProfile(browser()->profile());
+
+ event_router()->DeviceAdded(mock_adapter_, device_.get());
+ event_router()->GattServiceAdded(device_.get(), service0_.get());
+ event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get());
+
+ EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly(
keybuk 2014/05/06 16:44:19 nit: break across multiple lines
armansito 2014/05/06 19:26:36 Done.
+ Return(device_.get()));
+
+ EXPECT_CALL(*device_, GetGattService(kTestServiceId0))
+ .Times(3)
+ .WillRepeatedly(Return(service0_.get()));
+
+ EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
+ .Times(3)
+ .WillRepeatedly(Return(chrc0_.get()));
+
+ std::vector<uint8> write_value;
+ EXPECT_CALL(*chrc0_, WriteRemoteCharacteristic(_, _, _))
+ .Times(2)
+ .WillOnce(Invoke(&WriteValueErrorCallback))
+ .WillOnce(
+ DoAll(SaveArg<0>(&write_value), Invoke(&WriteValueSuccessCallback)));
+ EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
+
+ ExtensionTestMessageListener listener("ready", true);
+ ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
+ "bluetooth_low_energy/write_characteristic_value")));
+ EXPECT_TRUE(listener.WaitUntilSatisfied());
+
+ listener.Reply("go");
+
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+
+ event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get());
+ event_router()->GattServiceRemoved(device_.get(), service0_.get());
+ event_router()->DeviceRemoved(mock_adapter_, device_.get());
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698