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

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

Issue 1972353002: Implement the notifyCharacteristicValueChanged API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notifications_bluez
Patch Set: Created 4 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/notify_characteristic_value_changed_error_conditions/runtest.js
diff --git a/chrome/test/data/extensions/api_test/bluetooth_low_energy/notify_characteristic_value_changed_error_conditions/runtest.js b/chrome/test/data/extensions/api_test/bluetooth_low_energy/notify_characteristic_value_changed_error_conditions/runtest.js
new file mode 100644
index 0000000000000000000000000000000000000000..aea31659cc40ec8c9d86dbe7757934f0cd373e44
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bluetooth_low_energy/notify_characteristic_value_changed_error_conditions/runtest.js
@@ -0,0 +1,69 @@
+// 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 failOnError(result) {
+ if (chrome.runtime.lastError || !result) {
+ chrome.test.fail(chrome.runtime.lastError.message);
+ return true;
+ }
+ return false;
+}
+
+function failOnSuccess() {
+ if (!chrome.runtime.lastError) {
+ chrome.test.fail('lastError not set, operation succeeded.');
+ return true;
+ }
+ return false;
+}
+
+var service = { uuid: '00001234-0000-1000-8000-00805f9b34fb', isPrimary: true };
+chrome.bluetoothLowEnergy.createService(service, function(serviceId) {
+ if (failOnError(serviceId))
+ return;
+
+ var characteristic1 = { uuid: '00001234-0000-1000-8000-00805f9b34fa',
+ properties: ['notify']};
+ var characteristic2 = { uuid: '00001234-0000-1000-8000-00805f9b34fa',
+ properties: ['indicate']};
+ chrome.bluetoothLowEnergy.createCharacteristic(characteristic1, serviceId,
+ function(characteristicId1) {
+ if (failOnError(characteristicId1))
+ return;
+ chrome.bluetoothLowEnergy.createCharacteristic(characteristic2, serviceId,
+ function(characteristicId2) {
+ if (failOnError(characteristicId2))
+ return;
+
+ var bytes = [0xBA, 0xAD, 0x72, 0xF0, 0x0D, 0x65];
+ var newValue = (new Uint8Array(bytes)).buffer;
+ // Notifying without registering first. Should fail.
+ chrome.bluetoothLowEnergy.notifyCharacteristicValueChanged(
+ characteristicId1, {value: newValue, shouldIndicate: false},
+ function() {
+ if (failOnSuccess())
+ return;
+ chrome.bluetoothLowEnergy.registerService(serviceId, function() {
+ if (failOnError('result'))
+ return;
+ // Using notify with indicate property. Should fail.
+ chrome.bluetoothLowEnergy.notifyCharacteristicValueChanged(
+ characteristicId2, {value: newValue, shouldIndicate: false},
+ function() {
+ if (failOnSuccess())
+ return;
+ // Using indicate with notify property. Should fail.
+ chrome.bluetoothLowEnergy.notifyCharacteristicValueChanged(
+ characteristicId1, {value: newValue, shouldIndicate: true},
+ function() {
+ if (failOnSuccess())
+ return;
+ chrome.test.succeed();
+ });
+ });
+ });
+ });
+ });
+ });
+});
« no previous file with comments | « chrome/test/data/extensions/api_test/bluetooth_low_energy/notify_characteristic_value_changed_error_conditions/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698