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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/usb/disconnect-when-hidden-or-closed.html
diff --git a/third_party/WebKit/LayoutTests/usb/disconnect-when-hidden-or-closed.html b/third_party/WebKit/LayoutTests/usb/disconnect-when-hidden-or-closed.html
new file mode 100644
index 0000000000000000000000000000000000000000..b897726ae9a9a8b7bfc1b78e51768f0015cab211
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/usb/disconnect-when-hidden-or-closed.html
@@ -0,0 +1,79 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="../resources/mojo-helpers.js"></script>
+<script src="resources/fake-devices.js"></script>
+<script src="resources/usb-helpers.js"></script>
+<script>
+'use strict';
+
+const visibilityError =
+ 'Connection is only allowed while the page is visible. This is a ' +
+ 'temporary measure until we are able to effectively communicate to the ' +
+ 'user that the page is connected to a device.';
+
+usb_test(usb => {
+ usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
+ testRunner.setPageVisibility('visible');
+ return navigator.usb.getDevices().then(devices => {
+ assert_equals(devices.length, 1);
+ let device = devices[0];
+ testRunner.setPageVisibility('hidden');
+ return assertRejectsWithError(
+ device.open(), 'SecurityError', visibilityError).then(() => {
+ assert_false(device.opened);
+ });
+ });
+}, 'device connection is disallowed while the tab is hidden');
+
+usb_test(usb => {
+ usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
+ testRunner.setPageVisibility('visible');
+ return navigator.usb.getDevices().then(devices => {
+ assert_equals(devices.length, 1);
+ let device = devices[0];
+ let promise = assertRejectsWithError(
+ device.open(), 'SecurityError', visibilityError);
+ testRunner.setPageVisibility('hidden');
+ return promise.then(() => {
+ assert_false(device.opened);
+ });
+ });
+}, 'device connection is disallowed when it finishes while the tab is hidden');
+
+usb_test(usb => {
+ usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
+ testRunner.setPageVisibility('visible');
+ return navigator.usb.getDevices().then(devices => {
+ assert_equals(devices.length, 1);
+ let device = devices[0];
+ return device.open().then(() => {
+ testRunner.setPageVisibility('hidden');
+ return assertRejectsWithError(
+ device.selectConfiguration(1), 'SecurityError', visibilityError);
+ }).then(() => {
+ assert_false(device.opened);
+ });
+ });
+}, 'device connection is closed when tab becomes hidden');
+
+usb_test(usb => {
+ usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
+ testRunner.setPageVisibility('visible');
+ return navigator.usb.getDevices().then(devices => {
+ assert_equals(devices.length, 1);
+ let device = devices[0];
+ return device.open().then(() => {
+ testRunner.setPageVisibility('hidden');
+ return assertRejectsWithError(
+ device.selectConfiguration(0), 'SecurityError', visibilityError);
+ }).then(() => {
+ assert_false(device.opened);
+ testRunner.setPageVisibility('visible');
+ return device.open()
+ .then(() => device.selectConfiguration(1))
+ .then(() => device.close());
+ });
+ });
+}, 'device can be reopened when the page is visible');
+</script>
« 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