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

Side by Side Diff: third_party/WebKit/LayoutTests/bluetooth/characteristicvaluechanged.html

Issue 1815483003: bluetooth: Create Mojo equivalent of SetBluetoothMockDataSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-mojo
Patch Set: MMerge with ToT Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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 return setBluetoothFakeAdapter('HeartRateAdapter')
12 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) 12 .then(() => requestDeviceWithKeyDown({
13 filters: [{services: ['heart_rate']}]}))
13 .then(device => device.gatt.connect()) 14 .then(device => device.gatt.connect())
14 .then(gattServer => gattServer.getPrimaryService('heart_rate')) 15 .then(gattServer => gattServer.getPrimaryService('heart_rate'))
15 .then(service => service.getCharacteristic('body_sensor_location')) 16 .then(service => service.getCharacteristic('body_sensor_location'))
16 .then(characteristic => { 17 .then(characteristic => {
17 return assert_event_fires_after_promise(characteristic, 18 return assert_event_fires_after_promise(characteristic,
18 'readValue', 19 'readValue',
19 'characteristicvaluechanged'); 20 'characteristicvaluechanged');
20 }).then(results => { 21 }).then(results => {
21 let read_value = results[0].buffer; 22 let read_value = results[0].buffer;
22 let event_value = results[1].buffer; 23 let event_value = results[1].buffer;
23 // TODO(ortuno): The DataView used to resolve the promise 24 // TODO(ortuno): The DataView used to resolve the promise
24 // should be the same DataView as the one saved in the 25 // should be the same DataView as the one saved in the
25 // characteristic. 26 // characteristic.
26 // http://crbug.com/543347 27 // http://crbug.com/543347
27 // assert_equals(event.target.value, value); 28 // assert_equals(event.target.value, value);
28 assert_array_equals(event_value, read_value); 29 assert_array_equals(event_value, read_value);
29 }); 30 });
30 }, 'Reading a characteristic should fire an event.'); 31 }, 'Reading a characteristic should fire an event.');
31 32
32 promise_test(() => { 33 promise_test(() => {
33 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); 34 return setBluetoothFakeAdapter('HeartRateAdapter')
34 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) 35 .then(() => requestDeviceWithKeyDown({
36 filters: [{services: ['heart_rate']}]}))
35 .then(device => device.gatt.connect()) 37 .then(device => device.gatt.connect())
36 .then(gattServer => gattServer.getPrimaryService('heart_rate')) 38 .then(gattServer => gattServer.getPrimaryService('heart_rate'))
37 .then(service => service.getCharacteristic('body_sensor_location')) 39 .then(service => service.getCharacteristic('body_sensor_location'))
38 .then(characteristic => { 40 .then(characteristic => {
39 return assert_event_fires_after_promise(characteristic, 41 return assert_event_fires_after_promise(characteristic,
40 'readValue', 42 'readValue',
41 'characteristicvaluechanged', 43 'characteristicvaluechanged',
42 3 /* attach 3 listeners */); 44 3 /* attach 3 listeners */);
43 }).then(results => { 45 }).then(results => {
44 let read_value = results[0].buffer; 46 let read_value = results[0].buffer;
45 let event_values = results.slice(1).map(v => v.buffer); 47 let event_values = results.slice(1).map(v => v.buffer);
46 for (let event_value of event_values) { 48 for (let event_value of event_values) {
47 // TODO(ortuno): The DataView used to resolve the promise 49 // TODO(ortuno): The DataView used to resolve the promise
48 // should be the same DataView as the one saved in the 50 // should be the same DataView as the one saved in the
49 // characteristic. 51 // characteristic.
50 // http://crbug.com/543347 52 // http://crbug.com/543347
51 // assert_equals(event.target.value, value); 53 // assert_equals(event.target.value, value);
52 assert_array_equals(event_value, read_value); 54 assert_array_equals(event_value, read_value);
53 } 55 }
54 }); 56 });
55 }, 'Add multiple event listeners then readValue().'); 57 }, 'Add multiple event listeners then readValue().');
56 58
57 promise_test(() => { 59 promise_test(() => {
58 testRunner.setBluetoothMockDataSet('HeartRateAdapter');
59 let char; 60 let char;
60 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) 61 return setBluetoothFakeAdapter('HeartRateAdapter')
61 .then(device => device.gatt.connect()) 62 .then(() => requestDeviceWithKeyDown({
62 .then(gattServer => gattServer.getPrimaryService('heart_rate')) 63 filters: [{services: ['heart_rate']}]}))
63 .then(service => service.getCharacteristic('heart_rate_measurement')) 64 .then(device => device.gatt.connect())
64 .then(characteristic => { 65 .then(gattServer => gattServer.getPrimaryService('heart_rate'))
65 char = characteristic; 66 .then(service => service.getCharacteristic('heart_rate_measurement'))
66 return assert_event_fires_after_promise(characteristic, 67 .then(characteristic => {
67 'startNotifications', 68 char = characteristic;
68 'characteristicvaluechanged'); 69 return assert_event_fires_after_promise(characteristic,
69 }).then(() => char.stopNotifications()) 70 'startNotifications',
70 .then(() => assert_no_events(char, 'characteristicvaluechanged')); 71 'characteristicvaluechanged');
72 })
73 .then(() => char.stopNotifications())
74 .then(() => assert_no_events(char, 'characteristicvaluechanged'));
71 }, 'Starting notifications should fire an event.'); 75 }, 'Starting notifications should fire an event.');
72 76
73 promise_test(() => { 77 promise_test(() => {
74 testRunner.setBluetoothMockDataSet('HeartRateAdapter');
75 let char; 78 let char;
76 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) 79 return setBluetoothFakeAdapter('HeartRateAdapter')
77 .then(device => device.gatt.connect()) 80 .then(() => requestDeviceWithKeyDown({
78 .then(gattServer => gattServer.getPrimaryService('heart_rate')) 81 filters: [{services: ['heart_rate']}]}))
79 .then(service => service.getCharacteristic('heart_rate_measurement')) 82 .then(device => device.gatt.connect())
80 .then(characteristic => { 83 .then(gattServer => gattServer.getPrimaryService('heart_rate'))
81 char = characteristic; 84 .then(service => service.getCharacteristic('heart_rate_measurement'))
82 return assert_event_fires_after_promise(characteristic, 85 .then(characteristic => {
83 'startNotifications', 86 char = characteristic;
84 'characteristicvaluechanged', 87 return assert_event_fires_after_promise(characteristic,
85 3 /* add 3 listeners */); 88 'startNotifications',
86 }).then(() => char.stopNotifications()) 89 'characteristicvaluechanged',
87 .then(() => assert_no_events(char, 'characteristicvaluechanged')); 90 3 /* add 3 listeners */);
91 })
92 .then(() => char.stopNotifications())
93 .then(() => assert_no_events(char, 'characteristicvaluechanged'));
88 }, 'Add multiple event listeners then startNotifications().'); 94 }, 'Add multiple event listeners then startNotifications().');
89 </script> 95 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698