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

Side by Side Diff: LayoutTests/bluetooth/requestDevice.html

Issue 1304353004: Test that the right events are sent to the Bluetooth chooser. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@pinned
Patch Set: Fix requestDevice LayoutTest for new BT chooser event names. Created 5 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/testharness-helpers.js"></script> 3 <script src="../resources/testharness-helpers.js"></script>
4 <script src="../resources/testharnessreport.js"></script> 4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/bluetooth-helpers.js"></script> 5 <script src="resources/bluetooth-helpers.js"></script>
6 <script> 6 <script>
7 'use strict'; 7 'use strict';
8 8
9 test(function(t) { assert_true(window.testRunner instanceof Object); t.done(); } , 9 test(function(t) { assert_true(window.testRunner instanceof Object); t.done(); } ,
10 'window.testRunner is required for the following tests.'); 10 'window.testRunner is required for the following tests.');
11 11
12 promise_test(() => { 12 promise_test(() => {
13 testRunner.setBluetoothMockDataSet('EmptyAdapter'); 13 testRunner.setBluetoothMockDataSet('EmptyAdapter');
14 return assert_promise_rejects(requestDeviceWithKeyDown(), 14 return assert_promise_rejects(requestDeviceWithKeyDown(),
15 new TypeError()); 15 new TypeError());
16 }, 'Requires an argument.'); 16 }, 'Requires an argument.');
17 17
18 promise_test(() => { 18 promise_test(() => {
19 testRunner.setBluetoothMockDataSet('EmptyAdapter'); 19 testRunner.setBluetoothMockDataSet('EmptyAdapter');
20 return assert_promise_rejects(requestDeviceWithKeyDown({}), 20 return assert_promise_rejects(requestDeviceWithKeyDown({}),
21 new TypeError()); 21 new TypeError());
22 }, 'RequestDeviceOptions requires a |filters| member.'); 22 }, 'RequestDeviceOptions requires a |filters| member.');
23 23
24 // TODO(jyasskin): Add a test that the chooser is informed of a failed discovery
25 // session.
26 promise_test(() => { 24 promise_test(() => {
27 testRunner.setBluetoothMockDataSet('FailStartDiscoveryAdapter'); 25 testRunner.setBluetoothMockDataSet('FailStartDiscoveryAdapter');
26 testRunner.setBluetoothManualChooser();
27 let requestDevicePromise =
28 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]});
29 assert_array_equals(testRunner.getBluetoothManualChooserEvents(),
30 ['chooser-opened(file:///)',
31 'discovering',
32 'discovery-failed-to-start']);
33 testRunner.sendBluetoothManualChooserEvent('cancelled', '');
28 return assert_promise_rejects_with_message( 34 return assert_promise_rejects_with_message(
29 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), 35 requestDevicePromise,
30 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'}, 36 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'},
31 'The adapter failed to start a discovery session.'); 37 'The adapter failed to start a discovery session.');
32 }, 'Discovery session fails to start.'); 38 }, 'Discovery session fails to start.');
33 39
34 promise_test(() => { 40 promise_test(() => {
35 testRunner.setBluetoothMockDataSet('NotPresentAdapter'); 41 testRunner.setBluetoothMockDataSet('NotPresentAdapter');
36 return assert_promise_rejects_with_message( 42 return assert_promise_rejects_with_message(
37 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), 43 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}),
38 {name: 'NotFoundError', message: 'Bluetooth adapter not available.'}, 44 {name: 'NotFoundError', message: 'Bluetooth adapter not available.'},
39 'Bluetooth adapter is not present.'); 45 'Bluetooth adapter is not present.');
40 }, 'Reject with NotFoundError if the adapter is not present.'); 46 }, 'Reject with NotFoundError if the adapter is not present.');
41 47
42 // TODO(jyasskin): Add a test that the chooser is informed of a disabled
43 // Bluetooth adapter.
44 promise_test(() => { 48 promise_test(() => {
45 testRunner.setBluetoothMockDataSet('NotPoweredAdapter'); 49 testRunner.setBluetoothMockDataSet('NotPoweredAdapter');
50 testRunner.setBluetoothManualChooser();
51 let requestDevicePromise =
52 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]});
53 assert_array_equals(testRunner.getBluetoothManualChooserEvents(),
54 ['chooser-opened(file:///)',
55 'adapter-disabled']);
56 testRunner.sendBluetoothManualChooserEvent('cancelled', '');
46 return assert_promise_rejects_with_message( 57 return assert_promise_rejects_with_message(
47 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), 58 requestDevicePromise,
48 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'}, 59 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'},
49 'Bluetooth adapter is not powered.'); 60 'Bluetooth adapter is not powered.');
50 }, 'Reject with NotFoundError if the adapter is off.'); 61 }, 'Reject with NotFoundError if the adapter is off.');
51 62
52 // TODO(jyasskin): Add a test that the chooser gets a full list of found
53 // devices.
54 promise_test(() => { 63 promise_test(() => {
55 testRunner.setBluetoothMockDataSet('EmptyAdapter'); 64 testRunner.setBluetoothMockDataSet('EmptyAdapter');
56 return assert_promise_rejects_with_message( 65 return assert_promise_rejects_with_message(
57 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), 66 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}),
58 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'}, 67 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'},
59 'No Bluetooth devices in range.'); 68 'No Bluetooth devices in range.');
60 }, 'Reject with NotFoundError if there are no devices around.'); 69 }, 'Reject with NotFoundError if there are no devices around.');
61 70
62 promise_test(() => { 71 promise_test(() => {
63 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); 72 testRunner.setBluetoothMockDataSet('GenericAccessAdapter');
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 {services: ['battery_service']}, 125 {services: ['battery_service']},
117 {services: ['glucose', 'heart_rate']} 126 {services: ['glucose', 'heart_rate']}
118 ], 127 ],
119 // The optionalServices shouldn't affect the platform's scan. 128 // The optionalServices shouldn't affect the platform's scan.
120 optionalServices: [generic_access.name] 129 optionalServices: [generic_access.name]
121 }); 130 });
122 }, 'Filters restrict the platform\'s Bluetooth scan.'); 131 }, 'Filters restrict the platform\'s Bluetooth scan.');
123 132
124 promise_test(() => { 133 promise_test(() => {
125 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 134 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
135 testRunner.setBluetoothManualChooser();
136 let requestDevicePromise = requestDeviceWithKeyDown({
137 filters: [{services: ['glucose']},
138 {services: ['heart_rate']}]
139 });
140 let deadline = Date.now() + 500;
ortuno 2015/09/18 00:21:02 do we really need this? testharness will timeout t
Jeffrey Yasskin 2015/09/18 01:27:44 I guess we can do without it.
141 let events = testRunner.getBluetoothManualChooserEvents();
142 while (events.length < 5 && Date.now() < deadline) {
143 Array.prototype.push.apply(events,
ortuno 2015/09/18 00:21:02 Array spreads! :p
Jeffrey Yasskin 2015/09/18 01:27:44 Done. :)
144 testRunner.getBluetoothManualChooserEvents());
145 }
146 assert_equals(events.length, 5, events);
147 assert_equals(events[0], 'chooser-opened(file:///)', 'events[0]');
148 let idsByName = new Map();
149 let addDeviceRegex = /^add-device\(([^)]+)\)=([0-9:]+)$/
ortuno 2015/09/18 00:21:02 Semicolon. I wish we had something like jshint to
Jeffrey Yasskin 2015/09/18 01:27:44 Done. I've also moved this to a class in resources
150 for (let addedDevice of [events[1], events[2]]) {
151 let device = addDeviceRegex.exec(addedDevice);
ortuno 2015/09/18 00:21:02 What about: assert_regexp_match(events[1], GetReg
Jeffrey Yasskin 2015/09/18 01:27:44 If we get live devices working, the order of these
ortuno 2015/09/18 19:56:20 Ahh good point.
152 assert_true(!!device, addedDevice);
153 idsByName.set(device[1], device[2]);
154 }
155 assert_true(idsByName.has('Heart Rate Device'));
156 assert_true(idsByName.has('Glucose Device'));
157 assert_equals(events[3], 'discovering');
158 assert_equals(events[4], 'discovery-idle');
159 testRunner.sendBluetoothManualChooserEvent('selected',
160 idsByName.get('Glucose Device'));
161 return requestDevicePromise
162 .then(device => assert_equals(device.name, 'Glucose Device'));
163 }, 'The chooser includes all devices.');
164
165 promise_test(() => {
166 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
126 return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]}) 167 return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]})
127 .then(device => assert_equals(device.name, 'Glucose Device')); 168 .then(device => assert_equals(device.name, 'Glucose Device'));
128 }, 'Simple filter selects matching device.'); 169 }, 'Simple filter selects matching device.');
129 170
130 promise_test(() => { 171 promise_test(() => {
131 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 172 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
132 return requestDeviceWithKeyDown({ 173 return requestDeviceWithKeyDown({
133 filters: [{services: ['generic_access', 'heart_rate']}] 174 filters: [{services: ['generic_access', 'heart_rate']}]
134 }).then(device => assert_equals(device.name, 'Heart Rate Device')); 175 }).then(device => assert_equals(device.name, 'Heart Rate Device'));
135 }, 'Filter with 2 services returns a matching device.'); 176 }, 'Filter with 2 services returns a matching device.');
136 177
137 promise_test(() => { 178 promise_test(() => {
138 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 179 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
139 return requestDeviceWithKeyDown({ 180 return requestDeviceWithKeyDown({
140 filters: [{services: ['battery_service']}, 181 filters: [{services: ['battery_service']},
141 {services: ['heart_rate']}] 182 {services: ['heart_rate']}]
142 }).then(device => assert_equals(device.name, 'Heart Rate Device')); 183 }).then(device => assert_equals(device.name, 'Heart Rate Device'));
143 }, 'An extra filter doesn\'t prevent matching.'); 184 }, 'An extra filter doesn\'t prevent matching.');
144 185
145 promise_test(() => { 186 promise_test(() => {
146 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 187 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
147 // Both devices support the Generic Access service, but things need to 188 // Both devices support the Generic Access service, but things need to
148 // support both services to pass the filter, and neither has a Battery 189 // support both services to pass the filter, and neither has a Battery
149 // service. 190 // service.
150 return assert_promise_rejects(requestDeviceWithKeyDown({ 191 return assert_promise_rejects(requestDeviceWithKeyDown({
151 filters: [{services: ['generic_access', 'battery_service']}] 192 filters: [{services: ['generic_access', 'battery_service']}]
152 }), 'NotFoundError'); 193 }), 'NotFoundError');
153 }, 'Too-strict filters do prevent matching.'); 194 }, 'Too-strict filters do prevent matching.');
154 </script> 195 </script>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698