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

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

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

Powered by Google App Engine
This is Rietveld 408576698