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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/external/wpt/webusb/resources/usb-helpers.js
diff --git a/third_party/WebKit/LayoutTests/external/wpt/webusb/resources/usb-helpers.js b/third_party/WebKit/LayoutTests/external/wpt/webusb/resources/usb-helpers.js
new file mode 100644
index 0000000000000000000000000000000000000000..79eb3e54e282066c57553f4c5949382c11dbf58e
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/webusb/resources/usb-helpers.js
@@ -0,0 +1,58 @@
+'use strict';
+
+function usb_test(func, name, properties) {
+ promise_test(() => {
+ return navigator.usb.test.initialize().then(() => {
+ let testResult = func();
+ let cleanup = () => {
+ navigator.usb.test.reset();
+ };
+ testResult.then(cleanup, cleanup);
+ return testResult;
+ });
+ }, name, properties);
+}
+
+function assertRejectsWithError(promise, name, message) {
+ return promise.then(() => {
+ assert_unreached('expected promise to reject with ' + name);
+ }, error => {
+ assert_equals(error.name, name);
+ if (message !== undefined)
+ assert_equals(error.message, message);
+ });
+}
+
+function assertDeviceInfoEquals(usbDevice, deviceInit) {
+ for (var property in deviceInit) {
+ if (property == 'activeConfigurationValue') {
+ if (deviceInit.activeConfigurationValue == 0) {
+ assert_equals(usbDevice.configuration, null);
+ } else {
+ assert_equals(usbDevice.configuration.configurationValue,
+ deviceInit.activeConfigurationValue);
+ }
+ } else if (Array.isArray(deviceInit[property])) {
+ assert_equals(usbDevice[property].length, deviceInit[property].length);
+ for (var i = 0; i < usbDevice[property].length; ++i)
+ assertDeviceInfoEquals(usbDevice[property][i], deviceInit[property][i]);
+ } else {
+ assert_equals(usbDevice[property], deviceInit[property], property);
+ }
+ }
+}
+
+function callWithTrustedClick(callback) {
+ return new Promise(resolve => {
+ let button = document.createElement('button');
+ button.textContent = 'click to continue test';
+ button.style.display = 'block';
+ button.style.fontSize = '20px';
+ button.style.padding = '10px';
+ button.onclick = () => {
+ resolve(callback());
+ document.body.removeChild(button);
+ };
+ document.body.appendChild(button);
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698