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 | |
24 // should be the same ArrayBuffer as the one saved in the | |
25 // characteristic. | |
26 // http://crbug.com/543347 | |
27 // assert_equals(event.target.value, value); | |
ortuno
2016/01/19 20:08:23
You should either assert the objects are the same
| |
28 assert_array_equals(event_value, read_value); | 23 assert_array_equals(event_value, read_value); |
29 }); | 24 }); |
30 }, 'Reading a characteristic should fire an event.'); | 25 }, 'Reading a characteristic should fire an event.'); |
31 | 26 |
32 promise_test(() => { | 27 promise_test(() => { |
33 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 28 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
34 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 29 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
35 .then(device => device.connectGATT()) | 30 .then(device => device.connectGATT()) |
36 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | 31 .then(gattServer => gattServer.getPrimaryService('heart_rate')) |
37 .then(service => service.getCharacteristic('body_sensor_location')) | 32 .then(service => service.getCharacteristic('body_sensor_location')) |
38 .then(characteristic => { | 33 .then(characteristic => { |
39 return assert_event_fires_after_promise(characteristic, | 34 return assert_event_fires_after_promise(characteristic, |
40 'readValue', | 35 'readValue', |
41 'characteristicvaluechanged', | 36 'characteristicvaluechanged', |
42 3 /* attach 3 listeners */); | 37 3 /* attach 3 listeners */); |
43 }).then(results => { | 38 }).then(results => { |
44 let read_value = new Uint8Array(results[0]); | 39 let read_value = results[0].buffer; |
45 let event_values = results.slice(1).map(v => new Uint8Array(v)); | 40 let event_values = results.slice(1).map(v => v.buffer); |
46 for (let event_value of event_values) { | 41 for (let event_value of event_values) { |
47 // TODO(ortuno): The ArrayBuffer used to resolve the promise | |
48 // should be the same ArrayBuffer as the one saved in the | |
49 // characteristic. | |
50 // http://crbug.com/543347 | |
51 // assert_equals(event.target.value, value); | |
ortuno
2016/01/19 20:08:23
Same here.
| |
52 assert_array_equals(event_value, read_value); | 42 assert_array_equals(event_value, read_value); |
53 } | 43 } |
54 }); | 44 }); |
55 }, 'Add multiple event listeners then readValue().'); | 45 }, 'Add multiple event listeners then readValue().'); |
56 | 46 |
57 promise_test(() => { | 47 promise_test(() => { |
58 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 48 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
59 let char; | 49 let char; |
60 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 50 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
61 .then(device => device.connectGATT()) | 51 .then(device => device.connectGATT()) |
(...skipping 18 matching lines...) Expand all Loading... | |
80 .then(characteristic => { | 70 .then(characteristic => { |
81 char = characteristic; | 71 char = characteristic; |
82 return assert_event_fires_after_promise(characteristic, | 72 return assert_event_fires_after_promise(characteristic, |
83 'startNotifications', | 73 'startNotifications', |
84 'characteristicvaluechanged', | 74 'characteristicvaluechanged', |
85 3 /* add 3 listeners */); | 75 3 /* add 3 listeners */); |
86 }).then(() => char.stopNotifications()) | 76 }).then(() => char.stopNotifications()) |
87 .then(() => assert_no_events(char, 'characteristicvaluechanged')); | 77 .then(() => assert_no_events(char, 'characteristicvaluechanged')); |
88 }, 'Add multiple event listeners then startNotifications().'); | 78 }, 'Add multiple event listeners then startNotifications().'); |
89 </script> | 79 </script> |
OLD | NEW |