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

Unified Diff: third_party/WebKit/LayoutTests/bluetooth/characteristicvaluechanged.html

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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/bluetooth/characteristicvaluechanged.html
diff --git a/third_party/WebKit/LayoutTests/bluetooth/characteristicvaluechanged.html b/third_party/WebKit/LayoutTests/bluetooth/characteristicvaluechanged.html
new file mode 100644
index 0000000000000000000000000000000000000000..d21107a0ca5f9307ef29bf8474b4cfb88e24fd2d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/bluetooth/characteristicvaluechanged.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+test(t => { assert_true(window.testRunner instanceof Object); t.done(); },
+ 'window.testRunner is required for the following tests.');
+
+promise_test(() => {
+ testRunner.setBluetoothMockDataSet('HeartRateAdapter');
+ return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
+ .then(device => device.connectGATT())
+ .then(gattServer => gattServer.getPrimaryService('heart_rate'))
+ .then(service => service.getCharacteristic('body_sensor_location'))
+ .then(characteristic => {
+ return assert_event_fires_after_promise(characteristic,
+ 'readValue',
+ 'characteristicvaluechanged');
+ }).then(results => {
+ let read_value = new Uint8Array(results[0]);
+ let event_value = new Uint8Array(results[1]);
+ // TODO(ortuno): The ArrayBuffer used to resolve the promise
+ // should be the same ArrayBuffer as the one saved in the
+ // characteristic.
+ // http://crbug.com/543347
+ // assert_equals(event.target.value, value);
+ assert_array_equals(event_value, read_value);
+ });
+}, 'Reading a characteristic should fire an event.');
+
+promise_test(() => {
+ testRunner.setBluetoothMockDataSet('HeartRateAdapter');
+ return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
+ .then(device => device.connectGATT())
+ .then(gattServer => gattServer.getPrimaryService('heart_rate'))
+ .then(service => service.getCharacteristic('body_sensor_location'))
+ .then(characteristic => {
+ return assert_event_fires_after_promise(characteristic,
+ 'readValue',
+ 'characteristicvaluechanged',
+ 3 /* attach 3 listeners */);
+ }).then(results => {
+ let read_value = new Uint8Array(results[0]);
+ let event_values = results.slice(1).map(v => new Uint8Array(v));
+ for (let event_value of event_values) {
+ // TODO(ortuno): The ArrayBuffer used to resolve the promise
+ // should be the same ArrayBuffer as the one saved in the
+ // characteristic.
+ // http://crbug.com/543347
+ // assert_equals(event.target.value, value);
+ assert_array_equals(event_value, read_value);
+ }
+ });
+}, 'Add multiple event listeners then readValue().');
+
+promise_test(() => {
+ testRunner.setBluetoothMockDataSet('HeartRateAdapter');
+ let char;
+ return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
+ .then(device => device.connectGATT())
+ .then(gattServer => gattServer.getPrimaryService('heart_rate'))
+ .then(service => service.getCharacteristic('heart_rate_measurement'))
+ .then(characteristic => {
+ char = characteristic;
+ return assert_event_fires_after_promise(characteristic,
+ 'startNotifications',
+ 'characteristicvaluechanged');
+ }).then(() => char.stopNotifications())
+ .then(() => assert_no_events(char, 'characteristicvaluechanged'));
+}, 'Starting notifications should fire an event.');
+
+promise_test(() => {
+ testRunner.setBluetoothMockDataSet('HeartRateAdapter');
+ let char;
+ return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
+ .then(device => device.connectGATT())
+ .then(gattServer => gattServer.getPrimaryService('heart_rate'))
+ .then(service => service.getCharacteristic('heart_rate_measurement'))
+ .then(characteristic => {
+ char = characteristic;
+ return assert_event_fires_after_promise(characteristic,
+ 'startNotifications',
+ 'characteristicvaluechanged',
+ 3 /* add 3 listeners */);
+ }).then(() => char.stopNotifications())
+ .then(() => assert_no_events(char, 'characteristicvaluechanged'));
+}, 'Add multiple event listeners then startNotifications().');
+</script>

Powered by Google App Engine
This is Rietveld 408576698