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

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: 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 var requestDevicePromise =
28 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]});
29 assert_array_equals(testRunner.getBluetoothManualChooserEvents(),
30 ['RunBluetoothChooser(file:///)',
31 'ShowDiscoveryState(DISCOVERING)',
32 'ShowDiscoveryState(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 var requestDevicePromise =
52 requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]});
53 assert_array_equals(testRunner.getBluetoothManualChooserEvents(),
54 ['RunBluetoothChooser(file:///)',
55 'SetAdapterPresence(POWERED_OFF)']);
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 var requestDevicePromise = requestDeviceWithKeyDown({
137 filters: [{services: ['glucose']},
138 {services: ['heart_rate']}]
139 });
140 var deadline = Date.now() + 500;
141 var events = testRunner.getBluetoothManualChooserEvents();
142 while (events.length < 5 && Date.now() < deadline) {
143 Array.prototype.push.apply(events, testRunner.getBluetoothManualChooserEvent s());
144 }
145 assert_array_equals(events,
146 ['RunBluetoothChooser(file:///)',
147 'AddDevice(00:00:00:00:00:03, Heart Rate Device)',
148 'AddDevice(00:00:00:00:00:02, Glucose Device)',
149 'ShowDiscoveryState(DISCOVERING)',
150 'ShowDiscoveryState(IDLE)',
151 ]);
152 testRunner.sendBluetoothManualChooserEvent('selected', '00:00:00:00:00:02');
153 return requestDevicePromise
154 .then(device => assert_equals(device.name, 'Glucose Device'));
155 }, 'The chooser includes all devices.');
156
157 promise_test(() => {
158 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
126 return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]}) 159 return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]})
127 .then(device => assert_equals(device.name, 'Glucose Device')); 160 .then(device => assert_equals(device.name, 'Glucose Device'));
128 }, 'Simple filter selects matching device.'); 161 }, 'Simple filter selects matching device.');
129 162
130 promise_test(() => { 163 promise_test(() => {
131 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 164 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
132 return requestDeviceWithKeyDown({ 165 return requestDeviceWithKeyDown({
133 filters: [{services: ['generic_access', 'heart_rate']}] 166 filters: [{services: ['generic_access', 'heart_rate']}]
134 }).then(device => assert_equals(device.name, 'Heart Rate Device')); 167 }).then(device => assert_equals(device.name, 'Heart Rate Device'));
135 }, 'Filter with 2 services returns a matching device.'); 168 }, 'Filter with 2 services returns a matching device.');
136 169
137 promise_test(() => { 170 promise_test(() => {
138 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 171 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
139 return requestDeviceWithKeyDown({ 172 return requestDeviceWithKeyDown({
140 filters: [{services: ['battery_service']}, 173 filters: [{services: ['battery_service']},
141 {services: ['heart_rate']}] 174 {services: ['heart_rate']}]
142 }).then(device => assert_equals(device.name, 'Heart Rate Device')); 175 }).then(device => assert_equals(device.name, 'Heart Rate Device'));
143 }, 'An extra filter doesn\'t prevent matching.'); 176 }, 'An extra filter doesn\'t prevent matching.');
144 177
145 promise_test(() => { 178 promise_test(() => {
146 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); 179 testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter');
147 // Both devices support the Generic Access service, but things need to 180 // Both devices support the Generic Access service, but things need to
148 // support both services to pass the filter, and neither has a Battery 181 // support both services to pass the filter, and neither has a Battery
149 // service. 182 // service.
150 return assert_promise_rejects(requestDeviceWithKeyDown({ 183 return assert_promise_rejects(requestDeviceWithKeyDown({
151 filters: [{services: ['generic_access', 'battery_service']}] 184 filters: [{services: ['generic_access', 'battery_service']}]
152 }), 'NotFoundError'); 185 }), 'NotFoundError');
153 }, 'Too-strict filters do prevent matching.'); 186 }, 'Too-strict filters do prevent matching.');
154 </script> 187 </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