Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that BroadcastChannel settings object is current, not incumbent
Follows whatwg/html#5729.
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
webmessaging/multi-globals/broadcastchannel-current.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>The current page being cross-origin must prevent the BroadcastChannel message from being seen</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<!-- This is the entry global --> | ||
|
||
<iframe src="support/incumbent-document-domain.sub.html" id="incumbent"></iframe> | ||
<iframe src="http://{{hosts[][www]}}:{{ports[http][0]}}/webmessaging/multi-globals/support/current-document-domain.sub.html" id="current"></iframe> | ||
|
||
<script> | ||
"use strict"; | ||
document.domain = "{{hosts[][]}}"; | ||
|
||
setup({ explicit_done: true }); | ||
|
||
const incumbentIframe = document.querySelector("#incumbent"); | ||
const currentIframe = document.querySelector("#current"); | ||
|
||
window.onload = () => { | ||
promise_test(async t => { | ||
const createdCrossOrigin = frames[0].createBroadcastChannel("current"); | ||
const createdSameOrigin = new BroadcastChannel("current"); | ||
|
||
createdSameOrigin.onmessage = t.unreached_func("message event fired"); | ||
createdSameOrigin.onmessageerror = t.unreached_func("messageerror event fired"); | ||
|
||
createdCrossOrigin.postMessage("the message"); | ||
|
||
// BroadcastChannel messages are guaranteed to be ordered within an event loop, as they all use | ||
// the DOM manipulation task source. So, any messages from the "current" channel, if they are | ||
// going to be erroneously delivered, would have to be delivered before those from this | ||
// channel. I.e., if we recieve a message from this channel without first recieving one from | ||
// the "current" channel, then the test passes. | ||
const testEnder = new BroadcastChannel("current / test-ender"); | ||
const testEnder2 = new BroadcastChannel("current / test-ender"); | ||
|
||
testEnder.postMessage("end test"); | ||
await new Promise(resolve => testEnder2.onmessage = resolve); | ||
}); | ||
|
||
done(); | ||
}; | ||
</script> |
34 changes: 34 additions & 0 deletions
34
webmessaging/multi-globals/broadcastchannel-incumbent.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>The incumbent page being cross-origin must not prevent the BroadcastChannel message from being seen</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<!-- This is the entry global --> | ||
|
||
<iframe src="http://{{hosts[][www]}}:{{ports[http][0]}}/webmessaging/multi-globals/support/incumbent-document-domain.sub.html" id="incumbent"></iframe> | ||
<iframe src="support/current-document-domain.sub.html" id="current"></iframe> | ||
|
||
<script> | ||
"use strict"; | ||
document.domain = "{{hosts[][]}}"; | ||
|
||
setup({ explicit_done: true }); | ||
|
||
const incumbentIframe = document.querySelector("#incumbent"); | ||
const currentIframe = document.querySelector("#current"); | ||
|
||
window.onload = () => { | ||
async_test(t => { | ||
const createdThroughCrossOrigin = frames[0].createBroadcastChannel("incumbent"); | ||
const createdSameOrigin = new BroadcastChannel("incumbent"); | ||
|
||
createdSameOrigin.onmessage = () => t.done(); | ||
createdSameOrigin.onmessageerror = t.unreached_func("messageerror event fired"); | ||
|
||
createdThroughCrossOrigin.postMessage("the message"); | ||
}); | ||
|
||
done(); | ||
}; | ||
</script> |
10 changes: 10 additions & 0 deletions
10
webmessaging/multi-globals/support/current-document-domain.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Current page used as a test helper</title> | ||
|
||
<h1>Current</h1> | ||
|
||
<script> | ||
"use strict"; | ||
document.domain = "{{hosts[][]}}"; | ||
</script> |
14 changes: 14 additions & 0 deletions
14
webmessaging/multi-globals/support/incumbent-document-domain.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Incumbent page used as a test helper</title> | ||
|
||
<h1>Incumbent</h1> | ||
|
||
<script> | ||
"use strict"; | ||
document.domain = "{{hosts[][]}}"; | ||
|
||
window.createBroadcastChannel = (...args) => { | ||
return new parent.frames[1].BroadcastChannel(...args); | ||
}; | ||
</script> |