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

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 ortuno's comments 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');
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 events = testRunner.getBluetoothManualChooserEvents();
141 while (events.length < 5) {
ortuno 2015/09/18 19:56:20 You do something similar in your other test. Have
142 events.push(...testRunner.getBluetoothManualChooserEvents());
143 }
144 assert_equals(events.length, 5, events);
145 assert_equals(events[0], 'chooser-opened(file:///)', 'events[0]');
146 let idsByName = new AddDeviceEventSet();
147 for (let addedDevice of [events[1], events[2]]) {
148 idsByName.assert_add_device_event(addedDevice);
149 }
150 assert_true(idsByName.has('Heart Rate Device'));
151 assert_true(idsByName.has('Glucose Device'));
152 assert_equals(events[3], 'discovering');
153 assert_equals(events[4], 'discovery-idle');
154 testRunner.sendBluetoothManualChooserEvent('selected',
155 idsByName.get('Glucose Device'));
156 return requestDevicePromise
157 .then(device => assert_equals(device.name, 'Glucose Device'));
158 }, 'The chooser includes all devices.');
159
160 promise_test(() => {
161 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
126 return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]}) 162 return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]})
127 .then(device => assert_equals(device.name, 'Glucose Device')); 163 .then(device => assert_equals(device.name, 'Glucose Device'));
128 }, 'Simple filter selects matching device.'); 164 }, 'Simple filter selects matching device.');
129 165
130 promise_test(() => { 166 promise_test(() => {
131 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 167 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
132 return requestDeviceWithKeyDown({ 168 return requestDeviceWithKeyDown({
133 filters: [{services: ['generic_access', 'heart_rate']}] 169 filters: [{services: ['generic_access', 'heart_rate']}]
134 }).then(device => assert_equals(device.name, 'Heart Rate Device')); 170 }).then(device => assert_equals(device.name, 'Heart Rate Device'));
135 }, 'Filter with 2 services returns a matching device.'); 171 }, 'Filter with 2 services returns a matching device.');
136 172
137 promise_test(() => { 173 promise_test(() => {
138 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 174 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
139 return requestDeviceWithKeyDown({ 175 return requestDeviceWithKeyDown({
140 filters: [{services: ['battery_service']}, 176 filters: [{services: ['battery_service']},
141 {services: ['heart_rate']}] 177 {services: ['heart_rate']}]
142 }).then(device => assert_equals(device.name, 'Heart Rate Device')); 178 }).then(device => assert_equals(device.name, 'Heart Rate Device'));
143 }, 'An extra filter doesn\'t prevent matching.'); 179 }, 'An extra filter doesn\'t prevent matching.');
144 180
145 promise_test(() => { 181 promise_test(() => {
146 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 182 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
147 // Both devices support the Generic Access service, but things need to 183 // Both devices support the Generic Access service, but things need to
148 // support both services to pass the filter, and neither has a Battery 184 // support both services to pass the filter, and neither has a Battery
149 // service. 185 // service.
150 return assert_promise_rejects(requestDeviceWithKeyDown({ 186 return assert_promise_rejects(requestDeviceWithKeyDown({
151 filters: [{services: ['generic_access', 'battery_service']}] 187 filters: [{services: ['generic_access', 'battery_service']}]
152 }), 'NotFoundError'); 188 }), 'NotFoundError');
153 }, 'Too-strict filters do prevent matching.'); 189 }, 'Too-strict filters do prevent matching.');
154 </script> 190 </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