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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/webusb/resources/usb-helpers.js

Issue 2789723003: Migrate WebUSB LayoutTests into external/wpt (Closed)
Patch Set: Upstream tests that will work in stable Chrome Created 3 years, 6 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
1 'use strict'; 1 'use strict';
2 2
3 // To enable these tests Chrome must be run with these options:
4 //
5 // --enable-blink-features=MojoJS,MojoJSTest
6 let loadChromiumResources = Promise.resolve().then(() => {
ortuno 2017/06/21 00:43:50 Sad that we have to include Chrome-specific code i
foolip 2017/06/21 08:23:29 Could this be made part of wpt_automation instead?
Reilly Grant (use Gerrit) 2017/06/21 21:35:16 One of the goals of this patch is to make these te
foolip 2017/06/22 22:30:38 Hmm, I didn't notice that /resources/chromium/*.js
foolip 2017/06/22 22:52:18 Discussed in https://codereview.chromium.org/27897
7 if (!MojoInterfaceInterceptor) {
8 // Do nothing on non-Chromium-based browsers or when the Mojo bindings are
9 // not present in the global namespace.
10 return;
11 }
12
13 let chain = Promise.resolve();
14 [
15 '/resources/chromium/mojo_bindings.js',
16 '/resources/chromium/device.mojom.js',
17 '/resources/chromium/device_manager.mojom.js',
18 '/resources/chromium/chooser_service.mojom.js',
19 '/resources/chromium/webusb-test.js',
20 ].forEach(path => {
21 let script = document.createElement('script');
22 script.src = path;
23 script.async = false;
24 chain = chain.then(() => new Promise(resolve => {
25 script.onload = () => resolve();
26 }));
27 document.head.appendChild(script);
28 });
29
30 return chain;
31 });
32
3 function usb_test(func, name, properties) { 33 function usb_test(func, name, properties) {
4 promise_test(async () => { 34 promise_test(async () => {
5 await navigator.usb.test.initialize() 35 await loadChromiumResources;
36 await navigator.usb.test.initialize();
6 try { 37 try {
7 await func(); 38 await func();
8 } finally { 39 } finally {
9 await navigator.usb.test.reset(); 40 await navigator.usb.test.reset();
10 } 41 }
11 }, name, properties); 42 }, name, properties);
12 } 43 }
13 44
14 // Returns a promise that is resolved when the next USBConnectionEvent of the 45 // Returns a promise that is resolved when the next USBConnectionEvent of the
15 // given type is received. 46 // given type is received.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } else if (Array.isArray(deviceInit[property])) { 96 } else if (Array.isArray(deviceInit[property])) {
66 assert_equals(usbDevice[property].length, deviceInit[property].length); 97 assert_equals(usbDevice[property].length, deviceInit[property].length);
67 for (var i = 0; i < usbDevice[property].length; ++i) 98 for (var i = 0; i < usbDevice[property].length; ++i)
68 assertDeviceInfoEquals(usbDevice[property][i], deviceInit[property][i]); 99 assertDeviceInfoEquals(usbDevice[property][i], deviceInit[property][i]);
69 } else { 100 } else {
70 assert_equals(usbDevice[property], deviceInit[property], property); 101 assert_equals(usbDevice[property], deviceInit[property], property);
71 } 102 }
72 } 103 }
73 } 104 }
74 105
75 // TODO(reillyg): Remove when jyasskin upstreams this to testharness.js: 106 function callWithTrustedClick(callback) {
76 // https://crbug.com/509058.
77 function callWithKeyDown(functionCalledOnKeyPress) {
78 return new Promise(resolve => { 107 return new Promise(resolve => {
79 function onKeyPress() { 108 let button = document.createElement('button');
80 document.removeEventListener('keypress', onKeyPress, false); 109 button.textContent = 'click to continue test';
81 resolve(functionCalledOnKeyPress()); 110 button.style.display = 'block';
82 } 111 button.style.fontSize = '20px';
83 document.addEventListener('keypress', onKeyPress, false); 112 button.style.padding = '10px';
84 113 button.onclick = () => {
85 eventSender.keyDown(' ', []); 114 resolve(callback());
115 document.body.removeChild(button);
116 };
117 document.body.appendChild(button);
86 }); 118 });
87 } 119 }
88
89 function runGarbageCollection() {
90 // Run gc() as a promise.
91 return new Promise((resolve, reject) => {
92 GCController.collect();
93 setTimeout(resolve, 0);
94 });
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698