OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="resources/bluetooth-helpers.js"></script> | 4 <script src="resources/bluetooth-helpers.js"></script> |
5 <script> | 5 <script> |
6 'use strict'; | 6 'use strict'; |
7 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | 7 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, |
8 'window.testRunner is required for the following tests.'); | 8 'window.testRunner is required for the following tests.'); |
9 | 9 |
10 promise_test(() => { | 10 promise_test(() => { |
11 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 11 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
12 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 12 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
13 .then(device => device.connectGATT()) | 13 .then(device => device.connectGATT()) |
14 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | 14 .then(gattServer => gattServer.getPrimaryService('heart_rate')) |
15 .then(service => service.getCharacteristic('body_sensor_location')) | 15 .then(service => service.getCharacteristic('body_sensor_location')) |
16 .then(characteristic => { | 16 .then(characteristic => { |
17 return assert_event_fires_after_promise(characteristic, | 17 return assert_event_fires_after_promise(characteristic, |
18 'readValue', | 18 'readValue', |
19 'characteristicvaluechanged'); | 19 'characteristicvaluechanged'); |
20 }).then(results => { | 20 }).then(results => { |
21 let read_value = new Uint8Array(results[0]); | 21 let read_value = results[0].buffer; |
22 let event_value = new Uint8Array(results[1]); | 22 let event_value = results[1].buffer; |
23 // TODO(ortuno): The ArrayBuffer used to resolve the promise | 23 // TODO(ortuno): The DataView used to resolve the promise |
24 // should be the same ArrayBuffer as the one saved in the | 24 // should be the same DataView as the one saved in the |
25 // characteristic. | 25 // characteristic. |
26 // http://crbug.com/543347 | 26 // http://crbug.com/543347 |
27 // assert_equals(event.target.value, value); | 27 // assert_equals(event.target.value, value); |
28 assert_array_equals(event_value, read_value); | 28 assert_array_equals(event_value, read_value); |
29 }); | 29 }); |
30 }, 'Reading a characteristic should fire an event.'); | 30 }, 'Reading a characteristic should fire an event.'); |
31 | 31 |
32 promise_test(() => { | 32 promise_test(() => { |
33 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 33 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
34 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 34 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
35 .then(device => device.connectGATT()) | 35 .then(device => device.connectGATT()) |
36 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | 36 .then(gattServer => gattServer.getPrimaryService('heart_rate')) |
37 .then(service => service.getCharacteristic('body_sensor_location')) | 37 .then(service => service.getCharacteristic('body_sensor_location')) |
38 .then(characteristic => { | 38 .then(characteristic => { |
39 return assert_event_fires_after_promise(characteristic, | 39 return assert_event_fires_after_promise(characteristic, |
40 'readValue', | 40 'readValue', |
41 'characteristicvaluechanged', | 41 'characteristicvaluechanged', |
42 3 /* attach 3 listeners */); | 42 3 /* attach 3 listeners */); |
43 }).then(results => { | 43 }).then(results => { |
44 let read_value = new Uint8Array(results[0]); | 44 let read_value = results[0].buffer; |
45 let event_values = results.slice(1).map(v => new Uint8Array(v)); | 45 let event_values = results.slice(1).map(v => v.buffer); |
46 for (let event_value of event_values) { | 46 for (let event_value of event_values) { |
47 // TODO(ortuno): The ArrayBuffer used to resolve the promise | 47 // TODO(ortuno): The DataView used to resolve the promise |
48 // should be the same ArrayBuffer as the one saved in the | 48 // should be the same DataView as the one saved in the |
49 // characteristic. | 49 // characteristic. |
50 // http://crbug.com/543347 | 50 // http://crbug.com/543347 |
51 // assert_equals(event.target.value, value); | 51 // assert_equals(event.target.value, value); |
52 assert_array_equals(event_value, read_value); | 52 assert_array_equals(event_value, read_value); |
53 } | 53 } |
54 }); | 54 }); |
55 }, 'Add multiple event listeners then readValue().'); | 55 }, 'Add multiple event listeners then readValue().'); |
56 | 56 |
57 promise_test(() => { | 57 promise_test(() => { |
58 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 58 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
(...skipping 21 matching lines...) Expand all Loading... |
80 .then(characteristic => { | 80 .then(characteristic => { |
81 char = characteristic; | 81 char = characteristic; |
82 return assert_event_fires_after_promise(characteristic, | 82 return assert_event_fires_after_promise(characteristic, |
83 'startNotifications', | 83 'startNotifications', |
84 'characteristicvaluechanged', | 84 'characteristicvaluechanged', |
85 3 /* add 3 listeners */); | 85 3 /* add 3 listeners */); |
86 }).then(() => char.stopNotifications()) | 86 }).then(() => char.stopNotifications()) |
87 .then(() => assert_no_events(char, 'characteristicvaluechanged')); | 87 .then(() => assert_no_events(char, 'characteristicvaluechanged')); |
88 }, 'Add multiple event listeners then startNotifications().'); | 88 }, 'Add multiple event listeners then startNotifications().'); |
89 </script> | 89 </script> |
OLD | NEW |