Skip to content

Commit

Permalink
[testdriver.js] Don't expose testdriver-internal messages to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-j-lee committed Oct 2, 2024
1 parent 5e053f0 commit d43eccd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion infrastructure/testdriver/actions/crossOrigin.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
if (msg.data === "PASS") {
done();
} else if (msg.data === "FAIL") {
assert_unreached("actions failed")
assert_unreached("actions failed");
} else {
assert_unreached("testdriver.js-internal messages should not be exposed to tests");
}
});
</script>
2 changes: 2 additions & 0 deletions infrastructure/testdriver/actions/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
resolve();
} else if (msg.data === "FAIL") {
reject("actions failed");
} else {
reject("testdriver.js-internal messages should not be exposed to tests");
}
});
addEventListener("click", (event) => {
Expand Down
4 changes: 3 additions & 1 deletion infrastructure/testdriver/click_iframe_crossorigin.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
if (msg.data === "PASS") {
done();
} else if (msg.data === "FAIL") {
assert_unreached("click failed")
assert_unreached("click failed");
} else {
assert_unreached("testdriver.js-internal messages should not be exposed to tests");
}
});
</script>
Expand Down
4 changes: 3 additions & 1 deletion infrastructure/testdriver/click_nested_crossorigin.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
if (msg.data === "PASS") {
done();
} else if (msg.data === "FAIL") {
assert_unreached("click failed")
assert_unreached("click failed");
} else {
assert_unreached("testdriver.js-internal messages should not be exposed to tests");
}
});
</script>
15 changes: 12 additions & 3 deletions tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@
} else if (data.type === "testdriver-event") {
const event_data = JSON.parse(data.message);
const event_name = event_data.method;
const event = new Event(event_name);
event.payload = event_data.params;
event_target.dispatchEvent(event);
const testdriver_event = new Event(event_name);
testdriver_event.payload = event_data.params;
event_target.dispatchEvent(testdriver_event);
} else {
return;
}

// Don't expose testdriver.js-internal messages to tests. Because
// `testdriver.js` precedes test scripts in the markup, this "message"
// listener should be registered and run first [0].
//
// [0]: https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attributes
event.stopImmediatePropagation();
});

function is_test_context() {
Expand Down

0 comments on commit d43eccd

Please sign in to comment.