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

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

Issue 1820173002: Close USB device connections when the page is hidden. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and fixed nit. Created 4 years, 9 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 | third_party/WebKit/LayoutTests/usb/resources/usb-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
(Empty)
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="../resources/mojo-helpers.js"></script>
5 <script src="resources/fake-devices.js"></script>
6 <script src="resources/usb-helpers.js"></script>
7 <script>
8 'use strict';
9
10 const visibilityError =
11 'Connection is only allowed while the page is visible. This is a ' +
12 'temporary measure until we are able to effectively communicate to the ' +
13 'user that the page is connected to a device.';
14
15 usb_test(usb => {
16 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
17 testRunner.setPageVisibility('visible');
18 return navigator.usb.getDevices().then(devices => {
19 assert_equals(devices.length, 1);
20 let device = devices[0];
21 testRunner.setPageVisibility('hidden');
22 return assertRejectsWithError(
23 device.open(), 'SecurityError', visibilityError).then(() => {
24 assert_false(device.opened);
25 });
26 });
27 }, 'device connection is disallowed while the tab is hidden');
28
29 usb_test(usb => {
30 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
31 testRunner.setPageVisibility('visible');
32 return navigator.usb.getDevices().then(devices => {
33 assert_equals(devices.length, 1);
34 let device = devices[0];
35 let promise = assertRejectsWithError(
36 device.open(), 'SecurityError', visibilityError);
37 testRunner.setPageVisibility('hidden');
38 return promise.then(() => {
39 assert_false(device.opened);
40 });
41 });
42 }, 'device connection is disallowed when it finishes while the tab is hidden');
43
44 usb_test(usb => {
45 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
46 testRunner.setPageVisibility('visible');
47 return navigator.usb.getDevices().then(devices => {
48 assert_equals(devices.length, 1);
49 let device = devices[0];
50 return device.open().then(() => {
51 testRunner.setPageVisibility('hidden');
52 return assertRejectsWithError(
53 device.selectConfiguration(1), 'SecurityError', visibilityError);
54 }).then(() => {
55 assert_false(device.opened);
56 });
57 });
58 }, 'device connection is closed when tab becomes hidden');
59
60 usb_test(usb => {
61 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
62 testRunner.setPageVisibility('visible');
63 return navigator.usb.getDevices().then(devices => {
64 assert_equals(devices.length, 1);
65 let device = devices[0];
66 return device.open().then(() => {
67 testRunner.setPageVisibility('hidden');
68 return assertRejectsWithError(
69 device.selectConfiguration(0), 'SecurityError', visibilityError);
70 }).then(() => {
71 assert_false(device.opened);
72 testRunner.setPageVisibility('visible');
73 return device.open()
74 .then(() => device.selectConfiguration(1))
75 .then(() => device.close());
76 });
77 });
78 }, 'device can be reopened when the page is visible');
79 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698