Skip to content

Commit

Permalink
[wpt] Ignore testdriver messages in sandboxed_iframe.https.window.js
Browse files Browse the repository at this point in the history
Fix two issues causing the test to fail spuriously upstream when run
with WebDriver [0]:
a. testdriver.js uses regular `postMessage()`/`onmessage` to communicate
   testdriver commands between the parent and child frames.
   Unfortunately, until [1] is resolved, tests that use `onmessage` need
   to be aware of this implementation detail and ignore the internal
   messages.
b. The parent needs `testdriver(-vendor).js` too so that testdriver
   commands from the child frame are correctly pumped out [2] to the
   harness, which will send the WebDriver command.

Content shell currently passes the test because its testdriver is backed
by internal JS bindings that directly hook into the browser.

[0]: https://wpt.fyi/results/serial/requestPort/sandboxed_iframe.https.window.html?run_id=5088854063448064
[1]: #48326
[2]: https://github.com/web-platform-tests/wpt/blob/8ae822f0/tools/wptrunner/wptrunner/testdriver-extra.js#L22

Bug: None
Change-Id: Iddb130f92c1877e389a46cb89a35c21bbfd1b625
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5888384
Reviewed-by: Jack Hsieh <chengweih@chromium.org>
Commit-Queue: Jonathan Lee <jonathanjlee@google.com>
Cr-Commit-Position: refs/heads/main@{#1359563}
  • Loading branch information
jonathan-j-lee authored and chromium-wpt-export-bot committed Sep 24, 2024
1 parent 4a381c7 commit 83d47de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions serial/requestPort/sandboxed_iframe.https.window.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js

'use strict';

promise_test(async (t) => {
Expand All @@ -12,6 +15,10 @@ promise_test(async (t) => {

await new Promise(resolve => {
window.addEventListener('message', t.step_func(messageEvent => {
// Ignore internal testdriver.js messages (web-platform-tests/wpt#48326)
if ((messageEvent.data.type || '').startsWith('testdriver-')) {
return;
}
// The failure message of no device chosen is expected. The point here is
// to validate not failing because of a sandboxed iframe.
assert_true(messageEvent.data.includes('NotFoundError'));
Expand Down
4 changes: 4 additions & 0 deletions serial/resources/open-in-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
test_driver.set_test_context(parent);

window.onmessage = messageEvent => {
// Ignore internal testdriver.js messages (web-platform-tests/wpt#48326)
if ((messageEvent.data.type || '').startsWith('testdriver-')) {
return;
}
switch (messageEvent.data.type) {
case 'GetPorts':
navigator.serial.getPorts()
Expand Down

0 comments on commit 83d47de

Please sign in to comment.