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

Side by Side Diff: third_party/WebKit/LayoutTests/bluetooth/disconnect-when-hidden-or-closed.html

Issue 1815483003: bluetooth: Create Mojo equivalent of SetBluetoothMockDataSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-mojo
Patch Set: MMerge with ToT Created 4 years, 8 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script> 2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/bluetooth-helpers.js"></script> 4 <script src="resources/bluetooth-helpers.js"></script>
5 <script> 5 <script>
6 'use strict'; 6 'use strict';
7 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, 7 test(t => { assert_true(window.testRunner instanceof Object); t.done(); },
8 'window.testRunner is required for the following tests.'); 8 'window.testRunner is required for the following tests.');
9 9
10 // TODO(ortuno): Allow connections when the tab is in the background. 10 // TODO(ortuno): Allow connections when the tab is in the background.
11 // This is a short term solution instead of implementing a tab indicator 11 // This is a short term solution instead of implementing a tab indicator
12 // for bluetooth connections. 12 // for bluetooth connections.
13 // https://crbug.com/579746 13 // https://crbug.com/579746
14 promise_test(() => { 14 promise_test(() => {
15 testRunner.setPageVisibility("visible"); 15 testRunner.setPageVisibility("visible");
16 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); 16 return setBluetoothFakeAdapter('HeartRateAdapter')
17 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) 17 .then(() => requestDeviceWithKeyDown({
18 filters: [{services: ['heart_rate']}]}))
18 .then(device => { 19 .then(device => {
19 return device.gatt.connect().then(gatt_server => { 20 return device.gatt.connect().then(gatt_server => {
20 assert_true(gatt_server.connected); 21 assert_true(gatt_server.connected);
21 22
22 let event_catcher1 = new EventCatcher(device, 'gattserverdisconnected'); 23 let event_catcher1 = new EventCatcher(device, 'gattserverdisconnected');
23 testRunner.setPageVisibility("hidden"); 24 testRunner.setPageVisibility("hidden");
24 assert_false(gatt_server.connected); 25 assert_false(gatt_server.connected);
25 assert_true(event_catcher1.eventFired); 26 assert_true(event_catcher1.eventFired);
26 27
27 let event_catcher2 = new EventCatcher(device, 'gattserverdisconnected'); 28 let event_catcher2 = new EventCatcher(device, 'gattserverdisconnected');
28 testRunner.setPageVisibility("visible"); 29 testRunner.setPageVisibility("visible");
29 assert_false(gatt_server.connected); 30 assert_false(gatt_server.connected);
30 assert_false(event_catcher2.eventFired); 31 assert_false(event_catcher2.eventFired);
31 }); 32 });
32 }); 33 });
33 }, 'Test device disconnects and event is fired when tab becomes hidden.'); 34 }, 'Test device disconnects and event is fired when tab becomes hidden.');
34 35
35 promise_test(() => { 36 promise_test(() => {
36 testRunner.setPageVisibility('visible'); 37 testRunner.setPageVisibility('visible');
37 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); 38 return setBluetoothFakeAdapter('HeartRateAdapter')
38 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) 39 .then(() => requestDeviceWithKeyDown({
40 filters: [{services: ['heart_rate']}]}))
39 .then(device => device.gatt.connect()) 41 .then(device => device.gatt.connect())
40 .then(gatt_server => {}) 42 .then(gatt_server => {})
41 .then(() => runGarbageCollection()) 43 .then(() => runGarbageCollection())
42 .then(() => testRunner.setPageVisibility('hidden')); 44 .then(() => testRunner.setPageVisibility('hidden'));
43 }, 'Test object gets garbage collected before tab becomes hidden. ' + 45 }, 'Test object gets garbage collected before tab becomes hidden. ' +
44 'We shouldn\'t crash.'); 46 'We shouldn\'t crash.');
45 47
46 promise_test(() => { 48 promise_test(() => {
47 testRunner.setPageVisibility('visible'); 49 testRunner.setPageVisibility('visible');
48 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); 50 return setBluetoothFakeAdapter('HeartRateAdapter')
49 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) 51 .then(() => requestDeviceWithKeyDown({
52 filters: [{services: ['heart_rate']}]}))
50 .then(device => device.gatt.connect()) 53 .then(device => device.gatt.connect())
51 .then(gatt_server => testRunner.setPageVisibility('hidden')) 54 .then(gatt_server => testRunner.setPageVisibility('hidden'))
52 .then(() => runGarbageCollection()); 55 .then(() => runGarbageCollection());
53 }, 'Test object gets garbage collected after tab becomes hidden. ' + 56 }, 'Test object gets garbage collected after tab becomes hidden. ' +
54 'We shouldn\'t crash.'); 57 'We shouldn\'t crash.');
55 58
56 promise_test(() => { 59 promise_test(() => {
57 testRunner.setPageVisibility('visible'); 60 testRunner.setPageVisibility('visible');
58 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); 61 return setBluetoothFakeAdapter('HeartRateAdapter')
59 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) 62 .then(() => requestDeviceWithKeyDown({
63 filters: [{services: ['heart_rate']}]}))
60 .then(device => { 64 .then(device => {
61 let connect_promise = device.gatt.connect(); 65 let connect_promise = device.gatt.connect();
62 testRunner.setPageVisibility('hidden'); 66 testRunner.setPageVisibility('hidden');
63 return assert_promise_rejects_with_message( 67 return assert_promise_rejects_with_message(
64 connect_promise, 68 connect_promise,
65 new DOMException('Connection is only allowed while the page is visible. ' + 69 new DOMException('Connection is only allowed while the page is visible. ' +
66 'This is a temporary measure until we are able to ' + 70 'This is a temporary measure until we are able to ' +
67 'effectively communicate to the user that a page is ' + 71 'effectively communicate to the user that a page is ' +
68 'connected to a device.', 72 'connected to a device.',
69 'SecurityError')) 73 'SecurityError'))
70 .then(() => { 74 .then(() => {
71 assert_false(device.gatt.connected); 75 assert_false(device.gatt.connected);
72 }); 76 });
73 }); 77 });
74 }, 'Visibility changes during connection. Should disconnect and reject.'); 78 }, 'Visibility changes during connection. Should disconnect and reject.');
75 </script> 79 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698