From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- testing/web-platform/tests/serial/META.yml | 1 + testing/web-platform/tests/serial/README.md | 10 ++ .../getPorts/reject_opaque_origin.https.html | 14 +++ .../reject_opaque_origin.https.html.headers | 1 + .../getPorts/sandboxed_iframe.https.window.js | 20 ++++ .../tests/serial/idlharness.https.any.js | 22 +++++ .../requestPort/reject_opaque_origin.https.html | 14 +++ .../reject_opaque_origin.https.html.headers | 1 + .../requestPort/sandboxed_iframe.https.window.js | 24 +++++ .../web-platform/tests/serial/resources/common.js | 33 +++++++ .../web-platform/tests/serial/resources/manual.js | 38 ++++++++ .../tests/serial/resources/open-in-iframe.html | 33 +++++++ .../serial-allowed-by-permissions-policy-worker.js | 14 +++ ...serial-disabled-by-permissions-policy-worker.js | 17 ++++ ...olicy-attribute-redirect-on-load.https.sub.html | 44 +++++++++ ...-by-permissions-policy-attribute.https.sub.html | 46 +++++++++ ...al-allowed-by-permissions-policy.https.sub.html | 49 ++++++++++ ...ed-by-permissions-policy.https.sub.html.headers | 1 + ...erial-default-permissions-policy.https.sub.html | 27 ++++++ ...l-disabled-by-permissions-policy.https.sub.html | 50 ++++++++++ ...ed-by-permissions-policy.https.sub.html.headers | 1 + .../serial/serialPort_disconnect-manual.https.html | 83 ++++++++++++++++ .../serial/serialPort_loopback-manual.https.html | 97 +++++++++++++++++++ ...erialPort_loopback_BreakError-manual.https.html | 55 +++++++++++ ...t_loopback_BufferOverrunError-manual.https.html | 65 +++++++++++++ ...rialPort_loopback_flowControl-manual.https.html | 59 ++++++++++++ .../serial/serialPort_readable-manual.https.html | 107 +++++++++++++++++++++ 27 files changed, 926 insertions(+) create mode 100644 testing/web-platform/tests/serial/META.yml create mode 100644 testing/web-platform/tests/serial/README.md create mode 100644 testing/web-platform/tests/serial/getPorts/reject_opaque_origin.https.html create mode 100644 testing/web-platform/tests/serial/getPorts/reject_opaque_origin.https.html.headers create mode 100644 testing/web-platform/tests/serial/getPorts/sandboxed_iframe.https.window.js create mode 100644 testing/web-platform/tests/serial/idlharness.https.any.js create mode 100644 testing/web-platform/tests/serial/requestPort/reject_opaque_origin.https.html create mode 100644 testing/web-platform/tests/serial/requestPort/reject_opaque_origin.https.html.headers create mode 100644 testing/web-platform/tests/serial/requestPort/sandboxed_iframe.https.window.js create mode 100644 testing/web-platform/tests/serial/resources/common.js create mode 100644 testing/web-platform/tests/serial/resources/manual.js create mode 100644 testing/web-platform/tests/serial/resources/open-in-iframe.html create mode 100644 testing/web-platform/tests/serial/resources/serial-allowed-by-permissions-policy-worker.js create mode 100644 testing/web-platform/tests/serial/resources/serial-disabled-by-permissions-policy-worker.js create mode 100644 testing/web-platform/tests/serial/serial-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html create mode 100644 testing/web-platform/tests/serial/serial-allowed-by-permissions-policy-attribute.https.sub.html create mode 100644 testing/web-platform/tests/serial/serial-allowed-by-permissions-policy.https.sub.html create mode 100644 testing/web-platform/tests/serial/serial-allowed-by-permissions-policy.https.sub.html.headers create mode 100644 testing/web-platform/tests/serial/serial-default-permissions-policy.https.sub.html create mode 100644 testing/web-platform/tests/serial/serial-disabled-by-permissions-policy.https.sub.html create mode 100644 testing/web-platform/tests/serial/serial-disabled-by-permissions-policy.https.sub.html.headers create mode 100644 testing/web-platform/tests/serial/serialPort_disconnect-manual.https.html create mode 100644 testing/web-platform/tests/serial/serialPort_loopback-manual.https.html create mode 100644 testing/web-platform/tests/serial/serialPort_loopback_BreakError-manual.https.html create mode 100644 testing/web-platform/tests/serial/serialPort_loopback_BufferOverrunError-manual.https.html create mode 100644 testing/web-platform/tests/serial/serialPort_loopback_flowControl-manual.https.html create mode 100644 testing/web-platform/tests/serial/serialPort_readable-manual.https.html (limited to 'testing/web-platform/tests/serial') diff --git a/testing/web-platform/tests/serial/META.yml b/testing/web-platform/tests/serial/META.yml new file mode 100644 index 0000000000..64938c9298 --- /dev/null +++ b/testing/web-platform/tests/serial/META.yml @@ -0,0 +1 @@ +spec: https://wicg.github.io/serial/ diff --git a/testing/web-platform/tests/serial/README.md b/testing/web-platform/tests/serial/README.md new file mode 100644 index 0000000000..019eebd06b --- /dev/null +++ b/testing/web-platform/tests/serial/README.md @@ -0,0 +1,10 @@ +# Web Serial Testing + +Currently Web Serial only provide permission policy and maualy tests. The goal in future is to define test API specification similar to [WebUSB] and provide test-only interface to support more comprehensive tests. + +Tests with the "-manual" suffix do not use the test-only interface and expect a +real hardware device to be connected. The specific characteristics of the device +are described in each test. + +[WebUSB]: webusb +[Web Serial API]: https://wicg.github.io/serial diff --git a/testing/web-platform/tests/serial/getPorts/reject_opaque_origin.https.html b/testing/web-platform/tests/serial/getPorts/reject_opaque_origin.https.html new file mode 100644 index 0000000000..b2f630a319 --- /dev/null +++ b/testing/web-platform/tests/serial/getPorts/reject_opaque_origin.https.html @@ -0,0 +1,14 @@ + + + + + diff --git a/testing/web-platform/tests/serial/getPorts/reject_opaque_origin.https.html.headers b/testing/web-platform/tests/serial/getPorts/reject_opaque_origin.https.html.headers new file mode 100644 index 0000000000..1efcf8c226 --- /dev/null +++ b/testing/web-platform/tests/serial/getPorts/reject_opaque_origin.https.html.headers @@ -0,0 +1 @@ +Content-Security-Policy: sandbox allow-scripts diff --git a/testing/web-platform/tests/serial/getPorts/sandboxed_iframe.https.window.js b/testing/web-platform/tests/serial/getPorts/sandboxed_iframe.https.window.js new file mode 100644 index 0000000000..0a99f75aae --- /dev/null +++ b/testing/web-platform/tests/serial/getPorts/sandboxed_iframe.https.window.js @@ -0,0 +1,20 @@ +'use strict'; + +promise_test(async (t) => { + let iframe = document.createElement('iframe'); + await new Promise(resolve => { + iframe.src = '../resources/open-in-iframe.html'; + iframe.sandbox.add('allow-scripts'); + iframe.allow = 'serial'; + document.body.appendChild(iframe); + iframe.addEventListener('load', resolve); + }); + + await new Promise(resolve => { + window.addEventListener('message', t.step_func(messageEvent => { + assert_equals(messageEvent.data, 'Success'); + resolve(); + })); + iframe.contentWindow.postMessage({type: 'GetPorts'}, '*'); + }); +}, 'GetPorts from a sandboxed iframe is valid.'); diff --git a/testing/web-platform/tests/serial/idlharness.https.any.js b/testing/web-platform/tests/serial/idlharness.https.any.js new file mode 100644 index 0000000000..b240da933a --- /dev/null +++ b/testing/web-platform/tests/serial/idlharness.https.any.js @@ -0,0 +1,22 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js + +'use strict'; + +idl_test( + ['serial'], + ['html', 'dom'], + idl_array => { + idl_array.add_objects({ + Serial: ['navigator.serial'], + // TODO: SerialPort + // TODO: SerialPortInfo + }); + + if (self.GLOBAL.isWorker()) { + idl_array.add_objects({ WorkerNavigator: ['navigator'] }); + } else { + idl_array.add_objects({ Navigator: ['navigator'] }); + } + } +); diff --git a/testing/web-platform/tests/serial/requestPort/reject_opaque_origin.https.html b/testing/web-platform/tests/serial/requestPort/reject_opaque_origin.https.html new file mode 100644 index 0000000000..ade8ae7392 --- /dev/null +++ b/testing/web-platform/tests/serial/requestPort/reject_opaque_origin.https.html @@ -0,0 +1,14 @@ + + + + + diff --git a/testing/web-platform/tests/serial/requestPort/reject_opaque_origin.https.html.headers b/testing/web-platform/tests/serial/requestPort/reject_opaque_origin.https.html.headers new file mode 100644 index 0000000000..1efcf8c226 --- /dev/null +++ b/testing/web-platform/tests/serial/requestPort/reject_opaque_origin.https.html.headers @@ -0,0 +1 @@ +Content-Security-Policy: sandbox allow-scripts diff --git a/testing/web-platform/tests/serial/requestPort/sandboxed_iframe.https.window.js b/testing/web-platform/tests/serial/requestPort/sandboxed_iframe.https.window.js new file mode 100644 index 0000000000..f6d7abad10 --- /dev/null +++ b/testing/web-platform/tests/serial/requestPort/sandboxed_iframe.https.window.js @@ -0,0 +1,24 @@ +'use strict'; + +promise_test(async (t) => { + let iframe = document.createElement('iframe'); + await new Promise(resolve => { + iframe.src = '../resources/open-in-iframe.html'; + iframe.sandbox.add('allow-scripts'); + iframe.allow = 'serial'; + document.body.appendChild(iframe); + iframe.addEventListener('load', resolve); + }); + + await new Promise(resolve => { + window.addEventListener('message', t.step_func(messageEvent => { + // The failure message of no device chosen is expected. The point here is + // to validate not failing because of a sandboxed iframe. + assert_equals( + 'FAIL: NotFoundError: Failed to execute \'requestPort\' on \'Serial\': No port selected by the user.', + messageEvent.data); + resolve(); + })); + iframe.contentWindow.postMessage({type: 'RequestPort'}, '*'); + }); +}, 'RequestPort from a sandboxed iframe is valid.'); diff --git a/testing/web-platform/tests/serial/resources/common.js b/testing/web-platform/tests/serial/resources/common.js new file mode 100644 index 0000000000..5177f83a86 --- /dev/null +++ b/testing/web-platform/tests/serial/resources/common.js @@ -0,0 +1,33 @@ +// Compare two Uint8Arrays. +function compareArrays(actual, expected) { + assert_true(actual instanceof Uint8Array, 'actual is Uint8Array'); + assert_true(expected instanceof Uint8Array, 'expected is Uint8Array'); + assert_equals(actual.byteLength, expected.byteLength, 'lengths equal'); + for (let i = 0; i < expected.byteLength; ++i) + assert_equals(actual[i], expected[i], `Mismatch at position ${i}.`); +} + +// Reads from |reader| until at least |targetLength| is read or the stream is +// closed. The data is returned as a combined Uint8Array. +async function readWithLength(reader, targetLength) { + const chunks = []; + let actualLength = 0; + + while (true) { + let {value, done} = await reader.read(); + chunks.push(value); + actualLength += value.byteLength; + + if (actualLength >= targetLength || done) { + // It would be better to allocate |buffer| up front with the number of + // of bytes expected but this is the best that can be done without a + // BYOB reader to control the amount of data read. + const buffer = new Uint8Array(actualLength); + chunks.reduce((offset, chunk) => { + buffer.set(chunk, offset); + return offset + chunk.byteLength; + }, 0); + return buffer; + } + } +} diff --git a/testing/web-platform/tests/serial/resources/manual.js b/testing/web-platform/tests/serial/resources/manual.js new file mode 100644 index 0000000000..ac19136b35 --- /dev/null +++ b/testing/web-platform/tests/serial/resources/manual.js @@ -0,0 +1,38 @@ +let manualTestPort = null; + +navigator.serial.addEventListener('disconnect', (e) => { + if (e.target === manualTestPort) { + manualTestPort = null; + } +}) + +async function getPortForManualTest() { + if (manualTestPort) { + return manualTestPort; + } + + const button = document.createElement('button'); + button.textContent = 'Click to select a device'; + button.style.display = 'block'; + button.style.fontSize = '20px'; + button.style.padding = '10px'; + + await new Promise((resolve) => { + button.onclick = () => { + document.body.removeChild(button); + resolve(); + }; + document.body.appendChild(button); + }); + + manualTestPort = await navigator.serial.requestPort({filters: []}); + assert_true(manualTestPort instanceof SerialPort); + + return manualTestPort; +} + +function manual_serial_test(func, name, properties) { + promise_test(async (test) => { + await func(test, await getPortForManualTest()); + }, name, properties); +} diff --git a/testing/web-platform/tests/serial/resources/open-in-iframe.html b/testing/web-platform/tests/serial/resources/open-in-iframe.html new file mode 100644 index 0000000000..9bf8beb66a --- /dev/null +++ b/testing/web-platform/tests/serial/resources/open-in-iframe.html @@ -0,0 +1,33 @@ + + + + + + + + + + diff --git a/testing/web-platform/tests/serial/resources/serial-allowed-by-permissions-policy-worker.js b/testing/web-platform/tests/serial/resources/serial-allowed-by-permissions-policy-worker.js new file mode 100644 index 0000000000..cef0aacdfc --- /dev/null +++ b/testing/web-platform/tests/serial/resources/serial-allowed-by-permissions-policy-worker.js @@ -0,0 +1,14 @@ +'use strict'; + +importScripts('/resources/testharness.js'); + +let workerType; + +if (typeof postMessage === 'function') { + workerType = 'dedicated'; +} + +promise_test(() => navigator.serial.getPorts(), + `Inherited header permissions policy allows ${workerType} workers.`); + +done(); diff --git a/testing/web-platform/tests/serial/resources/serial-disabled-by-permissions-policy-worker.js b/testing/web-platform/tests/serial/resources/serial-disabled-by-permissions-policy-worker.js new file mode 100644 index 0000000000..afac442974 --- /dev/null +++ b/testing/web-platform/tests/serial/resources/serial-disabled-by-permissions-policy-worker.js @@ -0,0 +1,17 @@ +'use strict'; + +importScripts('/resources/testharness.js'); + +const header = 'Permissions-Policy header serial=()'; +let workerType; + +if (typeof postMessage === 'function') { + workerType = 'dedicated'; +} + +promise_test(() => navigator.serial.getPorts().then( + () => assert_unreached('expected promise to reject with SecurityError'), + error => assert_equals(error.name, 'SecurityError')), + `Inherited ${header} disallows ${workerType} workers.`); + +done(); diff --git a/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html b/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html new file mode 100644 index 0000000000..ac278ff0cf --- /dev/null +++ b/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html @@ -0,0 +1,44 @@ + + + + + + + diff --git a/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy-attribute.https.sub.html b/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy-attribute.https.sub.html new file mode 100644 index 0000000000..02560b180f --- /dev/null +++ b/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy-attribute.https.sub.html @@ -0,0 +1,46 @@ + + + + + + + diff --git a/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy.https.sub.html b/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy.https.sub.html new file mode 100644 index 0000000000..1be8eb979f --- /dev/null +++ b/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy.https.sub.html @@ -0,0 +1,49 @@ + + + + + + + + diff --git a/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy.https.sub.html.headers new file mode 100644 index 0000000000..27deb82758 --- /dev/null +++ b/testing/web-platform/tests/serial/serial-allowed-by-permissions-policy.https.sub.html.headers @@ -0,0 +1 @@ +Permissions-Policy: serial=* diff --git a/testing/web-platform/tests/serial/serial-default-permissions-policy.https.sub.html b/testing/web-platform/tests/serial/serial-default-permissions-policy.https.sub.html new file mode 100644 index 0000000000..e3908d9215 --- /dev/null +++ b/testing/web-platform/tests/serial/serial-default-permissions-policy.https.sub.html @@ -0,0 +1,27 @@ + + + + + + + diff --git a/testing/web-platform/tests/serial/serial-disabled-by-permissions-policy.https.sub.html b/testing/web-platform/tests/serial/serial-disabled-by-permissions-policy.https.sub.html new file mode 100644 index 0000000000..d482b19cae --- /dev/null +++ b/testing/web-platform/tests/serial/serial-disabled-by-permissions-policy.https.sub.html @@ -0,0 +1,50 @@ + + + + + + + + diff --git a/testing/web-platform/tests/serial/serial-disabled-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/serial/serial-disabled-by-permissions-policy.https.sub.html.headers new file mode 100644 index 0000000000..690b696751 --- /dev/null +++ b/testing/web-platform/tests/serial/serial-disabled-by-permissions-policy.https.sub.html.headers @@ -0,0 +1 @@ +Permissions-Policy: serial=() diff --git a/testing/web-platform/tests/serial/serialPort_disconnect-manual.https.html b/testing/web-platform/tests/serial/serialPort_disconnect-manual.https.html new file mode 100644 index 0000000000..5386201e6c --- /dev/null +++ b/testing/web-platform/tests/serial/serialPort_disconnect-manual.https.html @@ -0,0 +1,83 @@ + + + + + + + + + + + +

+ These tests require a serial device to be connected and disconnected. +

+ + + diff --git a/testing/web-platform/tests/serial/serialPort_loopback-manual.https.html b/testing/web-platform/tests/serial/serialPort_loopback-manual.https.html new file mode 100644 index 0000000000..bf876b6610 --- /dev/null +++ b/testing/web-platform/tests/serial/serialPort_loopback-manual.https.html @@ -0,0 +1,97 @@ + + + + + + + + + + + +

+ These tests require a connected serial device configured to act as a + "loopback" device, with the transmit and receive pins wired together. +

+ + + diff --git a/testing/web-platform/tests/serial/serialPort_loopback_BreakError-manual.https.html b/testing/web-platform/tests/serial/serialPort_loopback_BreakError-manual.https.html new file mode 100644 index 0000000000..369fac6155 --- /dev/null +++ b/testing/web-platform/tests/serial/serialPort_loopback_BreakError-manual.https.html @@ -0,0 +1,55 @@ + + + + + + + + + + + +

+ These tests require a connected serial device configured to act as a + "loopback" device, with the transmit and receive pins wired together. +

+ + + diff --git a/testing/web-platform/tests/serial/serialPort_loopback_BufferOverrunError-manual.https.html b/testing/web-platform/tests/serial/serialPort_loopback_BufferOverrunError-manual.https.html new file mode 100644 index 0000000000..06f8271ac9 --- /dev/null +++ b/testing/web-platform/tests/serial/serialPort_loopback_BufferOverrunError-manual.https.html @@ -0,0 +1,65 @@ + + + + + + + + + + + +

+ These tests require a connected serial device configured to act as a + "loopback" device, with the transmit and receive pins wired together. +

+ + + diff --git a/testing/web-platform/tests/serial/serialPort_loopback_flowControl-manual.https.html b/testing/web-platform/tests/serial/serialPort_loopback_flowControl-manual.https.html new file mode 100644 index 0000000000..930dab74d6 --- /dev/null +++ b/testing/web-platform/tests/serial/serialPort_loopback_flowControl-manual.https.html @@ -0,0 +1,59 @@ + + + + + + + + + + + +

+ These tests require a connected serial device configured to act as a + "loopback" device, with the TX and RX pins and RTS and CTS pins wired + together. +

+ + + diff --git a/testing/web-platform/tests/serial/serialPort_readable-manual.https.html b/testing/web-platform/tests/serial/serialPort_readable-manual.https.html new file mode 100644 index 0000000000..4e49ef4061 --- /dev/null +++ b/testing/web-platform/tests/serial/serialPort_readable-manual.https.html @@ -0,0 +1,107 @@ + + + + + + + + + + + +

+ These tests require a device configured with the following Arduino sketch: + +

+uint32_t seed = 0;
+uint32_t bytesToSend = 0;
+
+uint8_t nextByte() {
+  seed = (1103515245 * seed + 12345) % 0x8000000;
+  return (seed >> 16) & 0xFF;
+}
+
+void setup() {
+  Serial.begin(115200);
+}
+
+void loop() {
+  if (!Serial) {
+    return;
+  }
+
+  if (bytesToSend == 0) {
+    // Read the seed and number of bytes to send from the host as 32-bit
+    // little-endian values.
+    if (Serial.available() < 8) {
+      return;
+    }
+
+    uint8_t buf[8];
+    Serial.readBytes((char*)buf, sizeof buf);
+    seed = (uint32_t)buf[0] |
+            ((uint32_t)buf[1] << 8) |
+            ((uint32_t)buf[2] << 16) |
+            ((uint32_t)buf[3] << 24);
+    bytesToSend = (uint32_t)buf[4] |
+                  ((uint32_t)buf[5] << 8) |
+                  ((uint32_t)buf[6] << 16) |
+                  ((uint32_t)buf[7] << 24);
+  } else {
+    uint8_t buf[64];
+    uint32_t count = min(sizeof buf, bytesToSend);
+    for (uint32_t i = 0; i < count; ++i) {
+      buf[i] = nextByte();
+    }
+    bytesToSend -= count;
+    Serial.write((char*)buf, count);
+  }
+}
+      
+

+

+ +

+ + + -- cgit v1.2.3