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

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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 'use strict';
2
3 function usb_test(func, name, properties) {
4 promise_test(() => {
5 return navigator.usb.test.initialize().then(() => {
6 let testResult = func();
7 let cleanup = () => {
8 navigator.usb.test.reset();
9 };
10 testResult.then(cleanup, cleanup);
11 return testResult;
12 });
13 }, name, properties);
14 }
15
16 function assertRejectsWithError(promise, name, message) {
17 return promise.then(() => {
18 assert_unreached('expected promise to reject with ' + name);
19 }, error => {
20 assert_equals(error.name, name);
21 if (message !== undefined)
22 assert_equals(error.message, message);
23 });
24 }
25
26 function assertDeviceInfoEquals(usbDevice, deviceInit) {
27 for (var property in deviceInit) {
28 if (property == 'activeConfigurationValue') {
29 if (deviceInit.activeConfigurationValue == 0) {
30 assert_equals(usbDevice.configuration, null);
31 } else {
32 assert_equals(usbDevice.configuration.configurationValue,
33 deviceInit.activeConfigurationValue);
34 }
35 } else if (Array.isArray(deviceInit[property])) {
36 assert_equals(usbDevice[property].length, deviceInit[property].length);
37 for (var i = 0; i < usbDevice[property].length; ++i)
38 assertDeviceInfoEquals(usbDevice[property][i], deviceInit[property][i]);
39 } else {
40 assert_equals(usbDevice[property], deviceInit[property], property);
41 }
42 }
43 }
44
45 function callWithTrustedClick(callback) {
46 return new Promise(resolve => {
47 let button = document.createElement('button');
48 button.textContent = 'click to continue test';
49 button.style.display = 'block';
50 button.style.fontSize = '20px';
51 button.style.padding = '10px';
52 button.onclick = () => {
53 resolve(callback());
54 document.body.removeChild(button);
55 };
56 document.body.appendChild(button);
57 });
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698