[go: nahoru, domu]

serial: Upstream wpt_internal tests to Web Platform Tests

This change upstreams most of the wpt_internal tests for the Web Serial
API to the Web Platform Tests repository. The remaining tests validate
Chromium-specific concerns.

To isolate Chromium-specific implementation details from the tests
fake-serial.js is moved to resources/chromium and exports a generic API
for controlling fake ports which could be provided by any
implementation. automation.js will fail tests early on platforms which
do not provide this service.

Bug: 884928
Change-Id: I86d3ff864bc4d38a923dbd96da464e74533dfba5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2577488
Commit-Queue: Michael Moss <mmoss@chromium.org>
Reviewed-by: Michael Moss <mmoss@chromium.org>
Reviewed-by: Robert Ma <robertma@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835257}
diff --git a/chrome/tools/build/linux/FILES.cfg b/chrome/tools/build/linux/FILES.cfg
index e34811d..48152bb 100644
--- a/chrome/tools/build/linux/FILES.cfg
+++ b/chrome/tools/build/linux/FILES.cfg
@@ -489,4 +489,15 @@
     'buildtype': ['dev', 'official'],
     'archive': 'mojojs.zip',
   },
+  # MojoJS support data (Web Serial):
+  {
+    'filename': 'gen/services/device/public/mojom/serial.mojom.js',
+    'buildtype': ['dev', 'official'],
+    'archive': 'mojojs.zip',
+  },
+  {
+    'filename': 'gen/third_party/blink/public/mojom/serial/serial.mojom.js',
+    'buildtype': ['dev', 'official'],
+    'archive': 'mojojs.zip',
+  },
 ]
diff --git a/third_party/blink/web_tests/external/wpt/lint.ignore b/third_party/blink/web_tests/external/wpt/lint.ignore
index 86c71544..20f90ed 100644
--- a/third_party/blink/web_tests/external/wpt/lint.ignore
+++ b/third_party/blink/web_tests/external/wpt/lint.ignore
@@ -724,6 +724,7 @@
 MISSING DEPENDENCY: orientation-event/resources/orientation-event-helpers.js
 MISSING DEPENDENCY: resources/test-only-api.js
 MISSING DEPENDENCY: screen_enumeration/resources/screenenumeration-helpers.js
+MISSING DEPENDENCY: serial/resources/automation.js
 MISSING DEPENDENCY: shape-detection/resources/shapedetection-helpers.js
 MISSING DEPENDENCY: web-nfc/resources/nfc-helpers.js
 MISSING DEPENDENCY: webusb/resources/usb-helpers.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/resources/fake-serial.js b/third_party/blink/web_tests/external/wpt/resources/chromium/fake-serial.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/resources/fake-serial.js
rename to third_party/blink/web_tests/external/wpt/resources/chromium/fake-serial.js
diff --git a/third_party/blink/web_tests/external/wpt/serial/resources/automation.js b/third_party/blink/web_tests/external/wpt/serial/resources/automation.js
new file mode 100644
index 0000000..98f67fb6
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/serial/resources/automation.js
@@ -0,0 +1,75 @@
+'use strict';
+
+// These tests rely on the User Agent providing an implementation of the
+// FakeSerialService interface which replaces the platform-specific
+// implementation of the Web Serial API with one that can be automated from
+// Javascript for testing purposes.
+//
+// In Chromium-based browsers this implementation is provided by a polyfill
+// in order to reduce the amount of test-only code shipped to users. To enable
+// these tests the browser must be run with these options:
+//
+//   --enable-blink-features=MojoJS,MojoJSTest
+
+async function loadChromiumResources() {
+  const chromiumResources = [
+    '/gen/mojo/public/mojom/base/unguessable_token.mojom.js',
+    '/gen/services/device/public/mojom/serial.mojom.js',
+    '/gen/third_party/blink/public/mojom/serial/serial.mojom.js',
+  ];
+  await loadMojoResources(chromiumResources);
+}
+
+// Returns a SerialPort instance and associated FakeSerialPort instance.
+async function getFakeSerialPort(fake) {
+  let token = fake.addPort();
+  let fakePort = fake.getFakePort(token);
+
+  let ports = await navigator.serial.getPorts();
+  assert_equals(ports.length, 1);
+
+  let port = ports[0];
+  assert_true(port instanceof SerialPort);
+
+  return { port, fakePort };
+}
+
+let fakeSerialService = undefined;
+
+function serial_test(func, name, properties) {
+  promise_test(async (test) => {
+    assert_implements(navigator.serial, 'missing navigator.serial');
+    if (fakeSerialService === undefined) {
+      // Try loading a polyfill for the fake serial service.
+      if (isChromiumBased) {
+        await loadChromiumResources();
+        await loadScript('/resources/chromium/fake-serial.js');
+      }
+    }
+    assert_implements(fakeSerialService, 'missing fakeSerialService after initialization');
+
+    fakeSerialService.start();
+    try {
+      await func(test, fakeSerialService);
+    } finally {
+      fakeSerialService.stop();
+      fakeSerialService.reset();
+    }
+  }, name, properties);
+}
+
+function trustedClick() {
+  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. => {
+      document.body.removeChild(button);
+      resolve();
+    };
+    document.body.appendChild(button);
+    test_driver.click(button);
+  });
+}
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_close.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_close.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_close.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_close.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_events.https.any-expected.txt b/third_party/blink/web_tests/external/wpt/serial/serialPort_events.https.any-expected.txt
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_events.https.any-expected.txt
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_events.https.any-expected.txt
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_events.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_events.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_events.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_events.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_events.https.any.worker-expected.txt b/third_party/blink/web_tests/external/wpt/serial/serialPort_events.https.any.worker-expected.txt
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_events.https.any.worker-expected.txt
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_events.https.any.worker-expected.txt
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_getInfo.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_getInfo.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_getInfo.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_getInfo.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_getSignals.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_getSignals.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_getSignals.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_getSignals.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_ondisconnect.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_ondisconnect.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_ondisconnect.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_ondisconnect.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_open.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_open.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_open.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_open.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_cancel.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_cancel.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_cancel.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_cancel.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_chain.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_chain.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_chain.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_chain.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_closeLocked.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_closeLocked.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_closeLocked.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_closeLocked.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_disconnect.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_disconnect.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_disconnect.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_disconnect.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_largeRead.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_largeRead.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_largeRead.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_largeRead.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_open.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_open.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_open.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_open.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_parityError.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_parityError.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_parityError.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_parityError.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_pipeThrough.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_pipeThrough.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_pipeThrough.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_pipeThrough.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_smallRead.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_readable_smallRead.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_smallRead.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_readable_smallRead.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_setSignals.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_setSignals.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_setSignals.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_setSignals.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_writable.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serialPort_writable.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serialPort_writable.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serialPort_writable.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serial_getPorts.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serial_getPorts.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serial_getPorts.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serial_getPorts.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serial_onconnect.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serial_onconnect.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serial_onconnect.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serial_onconnect.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serial_ondisconnect.https.any.js b/third_party/blink/web_tests/external/wpt/serial/serial_ondisconnect.https.any.js
similarity index 100%
rename from third_party/blink/web_tests/wpt_internal/serial/serial_ondisconnect.https.any.js
rename to third_party/blink/web_tests/external/wpt/serial/serial_ondisconnect.https.any.js
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serial_requestPort.https.window.js b/third_party/blink/web_tests/external/wpt/serial/serial_requestPort.https.window.js
similarity index 85%
rename from third_party/blink/web_tests/wpt_internal/serial/serial_requestPort.https.window.js
rename to third_party/blink/web_tests/external/wpt/serial/serial_requestPort.https.window.js
index 5b79b8f..4edcfa6 100644
--- a/third_party/blink/web_tests/wpt_internal/serial/serial_requestPort.https.window.js
+++ b/third_party/blink/web_tests/external/wpt/serial/serial_requestPort.https.window.js
@@ -16,8 +16,8 @@
 }, 'requestPort() rejects if no port has been selected');
 
 serial_test(async (t, fake) => {
-  let guid = fake.addPort();
-  fake.setSelectedPort(guid);
+  let token = fake.addPort();
+  fake.setSelectedPort(token);
 
   await trustedClick();
   let port = await navigator.serial.requestPort();
@@ -25,8 +25,8 @@
 }, 'requestPort() returns the selected port');
 
 serial_test(async (t, fake) => {
-  let guid = fake.addPort();
-  fake.setSelectedPort(guid);
+  let token = fake.addPort();
+  fake.setSelectedPort(token);
 
   await trustedClick();
   let firstPort = await navigator.serial.requestPort();
@@ -37,8 +37,8 @@
 }, 'requestPort() returns the same port object every time');
 
 serial_test(async (t, fake) => {
-  let guid = fake.addPort();
-  fake.setSelectedPort(guid);
+  let token = fake.addPort();
+  fake.setSelectedPort(token);
 
   await trustedClick();
   let port = await navigator.serial.requestPort({filters: []});
@@ -46,8 +46,8 @@
 }, 'An empty list of filters is valid');
 
 serial_test(async (t, fake) => {
-  let guid = fake.addPort();
-  fake.setSelectedPort(guid);
+  let token = fake.addPort();
+  fake.setSelectedPort(token);
 
   await trustedClick();
   return promise_rejects_js(t, TypeError, navigator.serial.requestPort({
@@ -56,8 +56,8 @@
 }, 'An empty filter is not valid');
 
 serial_test(async (t, fake) => {
-  let guid = fake.addPort();
-  fake.setSelectedPort(guid);
+  let token = fake.addPort();
+  fake.setSelectedPort(token);
 
   await trustedClick();
   return promise_rejects_js(t, TypeError, navigator.serial.requestPort({
diff --git a/third_party/blink/web_tests/wpt_internal/serial/resources/automation.js b/third_party/blink/web_tests/wpt_internal/serial/resources/automation.js
deleted file mode 100644
index de50a25..0000000
--- a/third_party/blink/web_tests/wpt_internal/serial/resources/automation.js
+++ /dev/null
@@ -1,52 +0,0 @@
-// Returns a SerialPort instance and associated FakeSerialPort instance.
-async function getFakeSerialPort(fake) {
-  let token = fake.addPort();
-  let fakePort = fake.getFakePort(token);
-
-  let ports = await navigator.serial.getPorts();
-  assert_equals(ports.length, 1);
-
-  let port = ports[0];
-  assert_true(port instanceof SerialPort);
-
-  return { port, fakePort };
-}
-
-let fakeSerialService = undefined;
-
-function serial_test(func, name, properties) {
-  promise_test(async (test) => {
-    if (fakeSerialService === undefined) {
-      await loadMojoResources([
-        '/gen/mojo/public/mojom/base/unguessable_token.mojom.js',
-        '/gen/services/device/public/mojom/serial.mojom.js',
-        '/gen/third_party/blink/public/mojom/serial/serial.mojom.js',
-      ]);
-      await loadScript('resources/fake-serial.js');
-    }
-
-    fakeSerialService.start();
-    try {
-      await func(test, fakeSerialService);
-    } finally {
-      fakeSerialService.stop();
-      fakeSerialService.reset();
-    }
-  }, name, properties);
-}
-
-function trustedClick() {
-  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. => {
-      document.body.removeChild(button);
-      resolve();
-    };
-    document.body.appendChild(button);
-    test_driver.click(button);
-  });
-}
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_gc.https.window.js b/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_gc.https.window.js
index 480ccff..f9df9a4 100644
--- a/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_gc.https.window.js
+++ b/third_party/blink/web_tests/wpt_internal/serial/serialPort_readable_gc.https.window.js
@@ -1,6 +1,6 @@
 // META: script=/resources/test-only-api.js
 // META: script=/serial/resources/common.js
-// META: script=resources/automation.js
+// META: script=/serial/resources/automation.js
 
 serial_test(async (t, fake) => {
   let fakePort;
diff --git a/third_party/blink/web_tests/wpt_internal/serial/serial_requestPort-mojoServiceUnavailable.https.window.js b/third_party/blink/web_tests/wpt_internal/serial/serial_requestPort-mojoServiceUnavailable.https.window.js
index c318779..82d29842 100644
--- a/third_party/blink/web_tests/wpt_internal/serial/serial_requestPort-mojoServiceUnavailable.https.window.js
+++ b/third_party/blink/web_tests/wpt_internal/serial/serial_requestPort-mojoServiceUnavailable.https.window.js
@@ -1,7 +1,7 @@
 // META: script=/resources/testdriver.js
 // META: script=/resources/testdriver-vendor.js
 // META: script=/resources/test-only-api.js
-// META: script=resources/automation.js
+// META: script=/serial/resources/automation.js
 
 promise_test(async (t) => {
   await loadMojoResources([