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/external/wpt/webusb/usbDevice-iframe.https.html

Issue 2789723003: Migrate WebUSB LayoutTests into external/wpt (Closed)
Patch Set: Addressed comments from ortuno@ and foolip@ Created 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/external/wpt/webusb/usbDevice-iframe.https.html
diff --git a/third_party/WebKit/LayoutTests/external/wpt/webusb/usbDevice-iframe.https.html b/third_party/WebKit/LayoutTests/external/wpt/webusb/usbDevice-iframe.https.html
new file mode 100644
index 0000000000000000000000000000000000000000..faf967e68cf0d1b638c29b9a3c81091cd4cec955
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/webusb/usbDevice-iframe.https.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/fake-devices.js"></script>
+<script src="resources/usb-helpers.js"></script>
+<script>
+'use strict';
+
+function runIframeDisconnectTest(onDeviceConnected) {
+ return navigator.usb.test.initialize().then(() => {
+ return new Promise((resolve, reject) => {
+ let opened = false;
+ let fakeDeviceGuid = null;
+
+ let iframe = document.createElement('iframe');
+ iframe.src = 'resources/open-in-iframe.html';
+ iframe.onload = () => {
+ navigator.usb.test.attachToWindow(iframe.contentWindow).then(() => {
+ iframe.contentWindow.postMessage('Ready', '*');
+ });
+ };
+
+ window.onmessage = messageEvent => {
+ if (messageEvent.data == 'Ready') {
+ fakeDeviceGuid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
+ } else if (messageEvent.data == 'Success') {
+ opened = true;
+ onDeviceConnected(iframe);
+ } else {
+ reject(messageEvent.data);
+ }
+ };
+
+ navigator.usb.test.ondeviceclose = guid => {
+ assert_equals(guid, fakeDeviceGuid);
+ assert_true(opened);
+ resolve();
+ };
+
+ document.body.appendChild(iframe);
+ });
+ });
+}
+
+promise_test(() => {
+ return runIframeDisconnectTest(iframe => {
+ document.body.removeChild(iframe);
+ });
+}, 'detaching iframe disconnects device.');
+
+promise_test(() => {
+ return runIframeDisconnectTest(iframe => {
+ iframe.src = 'about:blank';
+ });
+}, 'navigating iframe disconnects device.');
+</script>

Powered by Google App Engine
This is Rietveld 408576698