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

Unified Diff: chrome/test/data/extensions/api_test/bluetooth_low_energy/write_characteristic_value/runtest.js

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/test/data/extensions/api_test/bluetooth_low_energy/write_characteristic_value/runtest.js
diff --git a/chrome/test/data/extensions/api_test/bluetooth_low_energy/write_characteristic_value/runtest.js b/chrome/test/data/extensions/api_test/bluetooth_low_energy/write_characteristic_value/runtest.js
new file mode 100644
index 0000000000000000000000000000000000000000..017664c6fe8a1d23fb9f2d68dce249098db9790e
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bluetooth_low_energy/write_characteristic_value/runtest.js
@@ -0,0 +1,58 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function testWriteCharacteristicValue() {
+ chrome.test.assertTrue(characteristic != null, '\'characteristic\' is null');
+ chrome.test.assertEq(charId, characteristic.instanceId);
+
+ chrome.test.assertEq(writeValue.byteLength, characteristic.value.byteLength);
+
+ var receivedValueBytes = new Uint8Array(characteristic.value);
+ for (var i = 0; i < writeValue.byteLength; i++) {
+ chrome.test.assertEq(valueBytes[i], receivedValueBytes[i]);
+ }
+
+ chrome.test.succeed();
+}
+
+var writeCharacteristicValue =
+ chrome.bluetoothLowEnergy.writeCharacteristicValue;
+
+var charId = 'char_id0';
+var badCharId = 'char_id1';
+
+var characteristic = null;
+var bytes = [0x43, 0x68, 0x72, 0x6F, 0x6D, 0x65];
+var writeValue = new ArrayBuffer(bytes.length);
+var valueBytes = new Uint8Array(writeValue);
+valueBytes.set(bytes);
+
+// 1. Unknown characteristic instanceId.
+writeCharacteristicValue(badCharId, writeValue, function (result) {
+ if (result || !chrome.runtime.lastError) {
+ chrome.test.fail('badCharId did not cause failure');
+ }
+
+ // 2. Known characteristic instanceId, but call failure.
+ writeCharacteristicValue(charId, writeValue, function (result) {
+ if (result || !chrome.runtime.lastError) {
+ chrome.test.fail('writeCharacteristicValue should have failed');
+ }
+
+ // 3. Call should succeed.
+ writeCharacteristicValue(charId, writeValue, function (result) {
+ if (chrome.runtime.lastError) {
+ chrome.test.fail(chrome.runtime.lastError.message);
+ }
+
+ chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
+ characteristic = result;
+
+ chrome.test.sendMessage('ready', function (message) {
+ chrome.test.runTests([testWriteCharacteristicValue]);
+ });
+ });
+ });
+ });
+});

Powered by Google App Engine
This is Rietveld 408576698