-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test that various MessageEvents are trusted #4025
Conversation
Note that I cannot get the BroadcastChannel tests to work in Chrome or Firefox---they timeout instead---so if someone can figure out my mistake that would be great. |
You need to have at least two |
The following works (though not sure it’s the best way to do it…) diff --git a/webmessaging/MessageEvent-trusted.html b/webmessaging/MessageEvent-trusted.html
index e3d26f8..502cd51 100644
--- a/webmessaging/MessageEvent-trusted.html
+++ b/webmessaging/MessageEvent-trusted.html
@@ -1,3 +1,8 @@
+<!--
+const channel = new BroadcastChannel("name");
+channel.postMessage("ping");
+/*
+-->
<!DOCTYPE html>
<title>MessagePort message events are trusted</title>
<script src="/resources/testharness.js"></script>
@@ -26,13 +31,13 @@ async_test(t => {
async_test(t => {
assert_true("BroadcastChannel" in self, "The browser must support BroadcastChannel");
+ const worker = new Worker("#");
const channel = new BroadcastChannel("name");
channel.onmessage = t.step_func_done(e => {
assert_equals(e.isTrusted, true);
});
- channel.postMessage("ping");
}, "With a BroadcastChannel");
async_test(t => {
@@ -43,3 +48,6 @@ async_test(t => {
window.postMessage("ping", "*");
}, "With window");
</script>
+<!--
+*/
+--> (btw would be nice if we could just use template literals in WPT tests but I’m told we shouldn’t yet) |
Thanks all, fixed the test, and now it indeed passes in Chrome and Firefox. |
Testing in Chrome
All results were stable All results
|
Testing in Firefox
All results were stable All results
|
Wow, it now runs tests in browsers!? so cool! |
FirefoxTesting revision ab50501 All results/eventsource/eventsource-onmessage-trusted.htm
/webmessaging/MessageEvent-trusted.html
|
ChromeTesting revision 4fd89ca All results/eventsource/eventsource-onmessage-trusted.htm
/webmessaging/MessageEvent-trusted.html
|
async_test(t => { | ||
assert_true("BroadcastChannel" in self, "The browser must support BroadcastChannel"); | ||
|
||
new Worker("MessageEvent-trusted-worker.js"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is probably safer to not create this worker until after you've created the BroadcastChannel instance and added the onmessage event handler. I don't think there is anything that guarantees the worker won't be created, ran, and posts its message to the channel before this method has a chance to connect to the channel itself (unless I'm missing something in how cross-thread-synchronization is specified in the html spec)
00fcdc8
to
4eb4b2e
Compare
@mkruisselbrink fixed, thanks! |
FirefoxTesting revision 814f27d All results/eventsource/eventsource-onmessage-trusted.htm
/webmessaging/MessageEvent-trusted.html
|
ChromeTesting revision 814f27d All results/eventsource/eventsource-onmessage-trusted.htm
/webmessaging/MessageEvent-trusted.html
|
Ping @mkruisselbrink for a final sign-off? This seems to have gotten left behind at some point. |
Looks good to me. |
See whatwg/html#1935.