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

Side by Side Diff: third_party/WebKit/LayoutTests/usb/usbDevice-iframe.html

Issue 2789723003: Migrate WebUSB LayoutTests into external/wpt (Closed)
Patch Set: Add README.md and more comments explaining the polyfill Created 3 years, 5 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 | « third_party/WebKit/LayoutTests/usb/usbDevice.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/fake-devices.js"></script> 4 <script src="../external/wpt/webusb/resources/fake-devices.js"></script>
5 <script src="resources/usb-helpers.js"></script> 5 <script src="../external/wpt/resources/chromium/mojo_bindings.js"></script>
6 <script src="resources/webusb-test.js"></script> 6 <script src="../external/wpt/resources/chromium/device.mojom.js"></script>
7 <script src="../external/wpt/resources/chromium/device_manager.mojom.js"></scrip t>
8 <script src="../external/wpt/resources/chromium/chooser_service.mojom.js"></scri pt>
9 <script src="../external/wpt/resources/chromium/webusb-test.js"></script>
7 <body> 10 <body>
8 <script> 11 <script>
9 'use strict'; 12 'use strict';
10 13
11 function runIframeDisconnectTest(onDeviceConnected) {
12 return navigator.usb.test.initialize().then(() => {
13 return new Promise((resolve, reject) => {
14 let opened = false;
15
16 let iframe = document.createElement('iframe');
17 iframe.src = 'resources/open-in-iframe.html';
18 iframe.onload = () => {
19 navigator.usb.test.attachToWindow(iframe.contentWindow).then(() => {
20 iframe.contentWindow.postMessage('Ready', '*');
21 });
22 };
23
24 window.onmessage = messageEvent => {
25 if (messageEvent.data == 'Ready') {
26 let fakeDevice = navigator.usb.test.addFakeDevice(fakeDeviceInit);
27 fakeDevice.onclose = () => {
28 assert_true(opened);
29 resolve();
30 };
31 } else if (messageEvent.data == 'Success') {
32 opened = true;
33 onDeviceConnected(iframe);
34 } else {
35 reject(messageEvent.data);
36 }
37 };
38
39 document.body.appendChild(iframe);
40 });
41 });
42 }
43
44 promise_test(() => {
45 return runIframeDisconnectTest(iframe => {
46 document.body.removeChild(iframe);
47 });
48 }, 'detaching iframe disconnects device.');
49
50 promise_test(() => {
51 return runIframeDisconnectTest(iframe => {
52 iframe.src = 'about:blank';
53 });
54 }, 'navigating iframe disconnects device.');
55
56 promise_test(() => { 14 promise_test(() => {
57 return navigator.usb.test.initialize().then(() => { 15 return navigator.usb.test.initialize().then(() => {
58 return new Promise((resolve, reject) => { 16 return new Promise((resolve, reject) => {
59 let opened = false; 17 let opened = false;
60 let fakeDeviceGuid = null; 18 let fakeDeviceGuid = null;
61 19
62 let iframe = document.createElement('iframe'); 20 let iframe = document.createElement('iframe');
63 iframe.src = 'resources/open-in-iframe.html'; 21 iframe.src = '../external/wpt/webusb/resources/open-in-iframe.html';
64 iframe.onload = () => { 22 iframe.onload = () => {
65 navigator.usb.test.attachToWindow(iframe.contentWindow).then(() => { 23 navigator.usb.test.attachToWindow(iframe.contentWindow).then(() => {
66 iframe.contentWindow.postMessage('Ready', '*'); 24 iframe.contentWindow.postMessage('Ready', '*');
67 }); 25 });
68 }; 26 };
69 27
70 window.onmessage = messageEvent => { 28 window.onmessage = messageEvent => {
71 if (messageEvent.data == 'Ready') { 29 if (messageEvent.data == 'Ready') {
72 document.body.removeChild(iframe); 30 document.body.removeChild(iframe);
73 runGarbageCollection().then(() => { 31 GCController.collect();
74 navigator.usb.test.addFakeDevice(fakeDeviceInit); 32 navigator.usb.test.addFakeDevice(fakeDeviceInit);
75 resolve(); 33 resolve();
76 });
77 } else { 34 } else {
78 reject(messageEvent.data); 35 reject(messageEvent.data);
79 } 36 }
80 }; 37 };
81 38
82 document.body.appendChild(iframe); 39 document.body.appendChild(iframe);
83 }); 40 });
84 }); 41 });
85 }, 'events are not delivered to detached frames'); 42 }, 'events are not delivered to detached frames');
86 </script> 43 </script>
87 </body> 44 </body>
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/usb/usbDevice.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698