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

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: Give expected_count a default. 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 | LayoutTests/bluetooth/resources/bluetooth-helpers.js » ('j') | 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');
28 return assert_promise_rejects_with_message( 26 testRunner.setBluetoothManualChooser();
29 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), 27 let requestDevicePromise =
30 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'}, 28 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]});
31 'The adapter failed to start a discovery session.'); 29 return getBluetoothManualChooserEvents()
30 .then(events => {
31 assert_array_equals(events,
32 ['chooser-opened(file:///)',
33 'discovering',
34 'discovery-failed-to-start']);
35 testRunner.sendBluetoothManualChooserEvent('cancelled', '');
36 return assert_promise_rejects_with_message(
37 requestDevicePromise,
38 {name: 'NotFoundError', message: 'User cancelled the requestDevice() cho oser.'},
39 'The adapter failed to start a discovery session.');
40 });
32 }, 'Discovery session fails to start.'); 41 }, 'Discovery session fails to start.');
33 42
34 promise_test(() => { 43 promise_test(() => {
35 testRunner.setBluetoothMockDataSet('NotPresentAdapter'); 44 testRunner.setBluetoothMockDataSet('NotPresentAdapter');
36 return assert_promise_rejects_with_message( 45 return assert_promise_rejects_with_message(
37 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), 46 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}),
38 {name: 'NotFoundError', message: 'Bluetooth adapter not available.'}, 47 {name: 'NotFoundError', message: 'Bluetooth adapter not available.'},
39 'Bluetooth adapter is not present.'); 48 'Bluetooth adapter is not present.');
40 }, 'Reject with NotFoundError if the adapter is not present.'); 49 }, 'Reject with NotFoundError if the adapter is not present.');
41 50
42 // TODO(jyasskin): Add a test that the chooser is informed of a disabled
43 // Bluetooth adapter.
44 promise_test(() => { 51 promise_test(() => {
45 testRunner.setBluetoothMockDataSet('NotPoweredAdapter'); 52 testRunner.setBluetoothMockDataSet('NotPoweredAdapter');
46 return assert_promise_rejects_with_message( 53 testRunner.setBluetoothManualChooser();
47 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), 54 let requestDevicePromise =
48 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'}, 55 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]});
49 'Bluetooth adapter is not powered.'); 56 return getBluetoothManualChooserEvents()
57 .then(events => {
58 assert_array_equals(events,
59 ['chooser-opened(file:///)',
60 'adapter-disabled']);
61 testRunner.sendBluetoothManualChooserEvent('cancelled', '');
62 return assert_promise_rejects_with_message(
63 requestDevicePromise,
64 {name: 'NotFoundError', message: 'User cancelled the requestDevice() cho oser.'},
65 'Bluetooth adapter is not powered.');
66 });
50 }, 'Reject with NotFoundError if the adapter is off.'); 67 }, 'Reject with NotFoundError if the adapter is off.');
51 68
52 // TODO(jyasskin): Add a test that the chooser gets a full list of found
53 // devices.
54 promise_test(() => { 69 promise_test(() => {
55 testRunner.setBluetoothMockDataSet('EmptyAdapter'); 70 testRunner.setBluetoothMockDataSet('EmptyAdapter');
56 return assert_promise_rejects_with_message( 71 return assert_promise_rejects_with_message(
57 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), 72 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}),
58 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'}, 73 {name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser .'},
59 'No Bluetooth devices in range.'); 74 'No Bluetooth devices in range.');
60 }, 'Reject with NotFoundError if there are no devices around.'); 75 }, 'Reject with NotFoundError if there are no devices around.');
61 76
62 promise_test(() => { 77 promise_test(() => {
63 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); 78 testRunner.setBluetoothMockDataSet('GenericAccessAdapter');
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 {services: ['battery_service']}, 131 {services: ['battery_service']},
117 {services: ['glucose', 'heart_rate']} 132 {services: ['glucose', 'heart_rate']}
118 ], 133 ],
119 // The optionalServices shouldn't affect the platform's scan. 134 // The optionalServices shouldn't affect the platform's scan.
120 optionalServices: [generic_access.name] 135 optionalServices: [generic_access.name]
121 }); 136 });
122 }, 'Filters restrict the platform\'s Bluetooth scan.'); 137 }, 'Filters restrict the platform\'s Bluetooth scan.');
123 138
124 promise_test(() => { 139 promise_test(() => {
125 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 140 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
141 testRunner.setBluetoothManualChooser();
142 let requestDevicePromise = requestDeviceWithKeyDown({
143 filters: [{services: ['glucose']},
144 {services: ['heart_rate']}]
145 });
146 return getBluetoothManualChooserEvents(5)
147 .then(events => {
148 assert_equals(events.length, 5, events);
149 assert_equals(events[0], 'chooser-opened(file:///)', 'events[0]');
150 let idsByName = new AddDeviceEventSet();
151 for (let addedDevice of [events[1], events[2]]) {
152 idsByName.assert_add_device_event(addedDevice);
153 }
154 assert_true(idsByName.has('Heart Rate Device'));
155 assert_true(idsByName.has('Glucose Device'));
156 assert_equals(events[3], 'discovering');
157 assert_equals(events[4], 'discovery-idle');
158 testRunner.sendBluetoothManualChooserEvent('selected',
159 idsByName.get('Glucose Device') );
160 return requestDevicePromise;
161 }).then(device => assert_equals(device.name, 'Glucose Device'));
162 }, 'The chooser includes all devices.');
163
164 promise_test(() => {
165 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
126 return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]}) 166 return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]})
127 .then(device => assert_equals(device.name, 'Glucose Device')); 167 .then(device => assert_equals(device.name, 'Glucose Device'));
128 }, 'Simple filter selects matching device.'); 168 }, 'Simple filter selects matching device.');
129 169
130 promise_test(() => { 170 promise_test(() => {
131 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 171 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
132 return requestDeviceWithKeyDown({ 172 return requestDeviceWithKeyDown({
133 filters: [{services: ['generic_access', 'heart_rate']}] 173 filters: [{services: ['generic_access', 'heart_rate']}]
134 }).then(device => assert_equals(device.name, 'Heart Rate Device')); 174 }).then(device => assert_equals(device.name, 'Heart Rate Device'));
135 }, 'Filter with 2 services returns a matching device.'); 175 }, 'Filter with 2 services returns a matching device.');
136 176
137 promise_test(() => { 177 promise_test(() => {
138 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 178 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
139 return requestDeviceWithKeyDown({ 179 return requestDeviceWithKeyDown({
140 filters: [{services: ['battery_service']}, 180 filters: [{services: ['battery_service']},
141 {services: ['heart_rate']}] 181 {services: ['heart_rate']}]
142 }).then(device => assert_equals(device.name, 'Heart Rate Device')); 182 }).then(device => assert_equals(device.name, 'Heart Rate Device'));
143 }, 'An extra filter doesn\'t prevent matching.'); 183 }, 'An extra filter doesn\'t prevent matching.');
144 184
145 promise_test(() => { 185 promise_test(() => {
146 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 186 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
147 // Both devices support the Generic Access service, but things need to 187 // Both devices support the Generic Access service, but things need to
148 // support both services to pass the filter, and neither has a Battery 188 // support both services to pass the filter, and neither has a Battery
149 // service. 189 // service.
150 return assert_promise_rejects(requestDeviceWithKeyDown({ 190 return assert_promise_rejects(requestDeviceWithKeyDown({
151 filters: [{services: ['generic_access', 'battery_service']}] 191 filters: [{services: ['generic_access', 'battery_service']}]
152 }), 'NotFoundError'); 192 }), 'NotFoundError');
153 }, 'Too-strict filters do prevent matching.'); 193 }, 'Too-strict filters do prevent matching.');
154 </script> 194 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/bluetooth/resources/bluetooth-helpers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698