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

Side by Side 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 jyasskin'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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/bluetooth-helpers.js"></script>
5 <script>
6 'use strict';
7 test(t => { assert_true(window.testRunner instanceof Object); t.done(); },
8 'window.testRunner is required for the following tests.');
9
10 promise_test(() => {
11 let char;
12 testRunner.setBluetoothMockDataSet('HeartRateAdapter');
13 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
14 .then(device => device.connectGATT())
15 .then(gattServer => gattServer.getPrimaryService('heart_rate'))
16 .then(service => service.getCharacteristic('body_sensor_location'))
17 .then(characteristic => {
18 return assert_event_fires_after_promise(characteristic,
19 'readValue',
Jeffrey Yasskin 2015/10/16 01:40:18 Check the indentation.
ortuno 2015/10/16 19:41:00 Done.
20 'characteristicvaluechanged');
21 }).then(results => {
22 let read_value = new Uint8Array(results[0]);
23 let event_value = new Uint8Array(results[1]);
24 // TODO(ortuno): The ArrayBuffer used to resolve the promise
25 // should be the same ArrayBuffer than the one saved in the
26 // characteristic.
27 // http://crbug.com/543347
28 // assert_equals(event.target.value, value);
29 assert_array_equals(event_value, read_value);
30 });
31 }, 'Reading a characteristic should fire an event.');
32
33 promise_test(() => {
34 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.
35 testRunner.setBluetoothMockDataSet('HeartRateAdapter');
36 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
37 .then(device => device.connectGATT())
38 .then(gattServer => gattServer.getPrimaryService('heart_rate'))
39 .then(service => service.getCharacteristic('body_sensor_location'))
40 .then(characteristic => {
41 return assert_event_fires_after_promise(characteristic,
42 'readValue',
Jeffrey Yasskin 2015/10/16 01:40:18 Indentation
ortuno 2015/10/16 19:41:00 Done.
43 'characteristicvaluechanged',
44 3 /* attach 3 listeners */);
45 }).then(results => {
46 let read_value = new Uint8Array(results[0]);
47 let event_values = Array.prototype.map.call(results.slice(1), v => new Uin t8Array(v));
Jeffrey Yasskin 2015/10/16 01:40:18 Why not results.slice(1).map(...)?
ortuno 2015/10/16 19:41:00 Done.
48 for (let event_value of event_values) {
49 // 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.
50 // 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.
51 // characteristic.
52 // http://crbug.com/543347
53 // assert_equals(event.target.value, value);
54 assert_array_equals(event_value, read_value);
55 }
56 });
57 }, 'Add multiple event listeners then readValue().');
58
59 promise_test(() => {
60 testRunner.setBluetoothMockDataSet('HeartRateAdapter');
61 let char;
62 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
63 .then(device => device.connectGATT())
64 .then(gattServer => gattServer.getPrimaryService('heart_rate'))
65 .then(service => service.getCharacteristic('heart_rate_measurement'))
66 .then(characteristic => {
67 char = characteristic;
68 return assert_event_fires_after_promise(characteristic,
69 'startNotifications',
70 'characteristicvaluechanged');
71 }).then(() => char.stopNotifications())
72 .then(() => assert_no_events(char, 'characteristicvaluechanged'));
73 }, 'Starting notifications should fire an events.');
74
75 promise_test(() => {
76 testRunner.setBluetoothMockDataSet('HeartRateAdapter');
77 let char;
78 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
79 .then(device => device.connectGATT())
80 .then(gattServer => gattServer.getPrimaryService('heart_rate'))
81 .then(service => service.getCharacteristic('heart_rate_measurement'))
82 .then(characteristic => {
83 char = characteristic;
84 return assert_event_fires_after_promise(characteristic,
85 'startNotifications',
86 'characteristicvaluechanged',
87 3 /* add 3 listeners */);
88 }).then(() => char.stopNotifications())
89 .then(() => assert_no_events(char, 'characteristicvaluechanged'));
90 }, 'Add multiple event listeners then startNotifications().');
91 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698