Skip to content

Commit

Permalink
Make 2 tests immune to legitimate races between cross-origin subframes
Browse files Browse the repository at this point in the history
Bug: 820589
Change-Id: I16c02746c61f42fafead5f96ae436b331fba4f85
  • Loading branch information
anforowicz authored and chromium-wpt-export-bot committed Mar 10, 2018
1 parent 83b0a62 commit ae5ecb0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
24 changes: 17 additions & 7 deletions webmessaging/event.origin.sub.htm
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,23 @@

window.onmessage = t.step_func(function(e)
{
// testharness.js uses postMessage so we must check what data we want to receive
if (e.data.toString() === "#1" || e.data.toString() === "#2") {
ActualResult.push(e.data, e.origin);
if (ActualResult.length === ExpectedResult.length) {
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
t.done();
}
// Messages from TARGET1 and TARGET2 can come in any order
// (since one of them is cross-origin and can run in parallel).
// To make the tests immune to message reordering, always
// put the response from TARGET1 at the start of the list.
if (e.data.toString() === "#1")
{
ActualResult = [e.data, e.origin].concat(ActualResult);
}
else if (e.data.toString() === "#2")
{
ActualResult = ActualResult.concat([e.data, e.origin]);
}

if (ActualResult.length >= ExpectedResult.length)
{
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
t.done();
}
});
</script>
Expand Down
13 changes: 12 additions & 1 deletion webmessaging/postMessage_asterisk_xorigin.sub.htm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@

window.onmessage = t.step_func(function(e)
{
ActualResult.push(e.data, e.origin);
// Messages from TARGET1 and TARGET2 can come in any order
// (since one of them is cross-origin and can run in parallel).
// To make the tests immune to message reordering, always
// put the response from TARGET1 at the start of the list.
if (e.data.toString() === "#1")
{
ActualResult = [e.data, e.origin].concat(ActualResult);
}
else if (e.data.toString() === "#2")
{
ActualResult = ActualResult.concat([e.data, e.origin]);
}

if (ActualResult.length >= ExpectedResult.length)
{
Expand Down

0 comments on commit ae5ecb0

Please sign in to comment.