Chromium Code Reviews| 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..5223718572284087aca6ea1ac6e806983642de05 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/bluetooth/characteristicvaluechanged.html |
| @@ -0,0 +1,91 @@ |
| +<!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(() => { |
| + let char; |
| + 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', |
|
Jeffrey Yasskin
2015/10/16 01:40:18
Check the indentation.
ortuno
2015/10/16 19:41:00
Done.
|
| + '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 than 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(() => { |
| + let char; |
|
Jeffrey Yasskin
2015/10/16 01:40:18
It looks like you never use this variable. (And ab
ortuno
2015/10/16 19:40:59
Done.
|
| + 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', |
|
Jeffrey Yasskin
2015/10/16 01:40:18
Indentation
ortuno
2015/10/16 19:41:00
Done.
|
| + 'characteristicvaluechanged', |
| + 3 /* attach 3 listeners */); |
| + }).then(results => { |
| + let read_value = new Uint8Array(results[0]); |
| + let event_values = Array.prototype.map.call(results.slice(1), v => new Uint8Array(v)); |
|
Jeffrey Yasskin
2015/10/16 01:40:18
Why not results.slice(1).map(...)?
ortuno
2015/10/16 19:41:00
Done.
|
| + for (let event_value of event_values) { |
| + // TODO(ortuno): The ArrayBuffer used to resolve the promise |
|
Jeffrey Yasskin
2015/10/16 01:40:18
Indent this to the body of the for loop.
ortuno
2015/10/16 19:40:59
Done.
|
| + // should be the same ArrayBuffer than the one saved in the |
|
Jeffrey Yasskin
2015/10/16 01:40:17
s/than/as/
ortuno
2015/10/16 19:40:59
Done.
|
| + // 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 events.'); |
| + |
| +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> |