Commit 4f328a7f authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

WPT: service worker: Fix potential race in navigation-redirect.https.html.

Before this CL, the test makes a frame which posts a message to the test
window. But if the test fails, we might not consume the message with
`await` and move on the next test. It's possible the next test gets an
unexpected message from the previous test.

I think a related issue caused the timeout after the Clients variant was
added to the test, since the message handler was created after the frame
was created and it was possible the message arrived after that.

Fix things by explicitly asking the frame for the message when we're
ready for it.

Bug: 876223, 778497
Change-Id: I82b8685df2977aeadea7475965ecccf69bd33111
Reviewed-on: https://chromium-review.googlesource.com/1249423Reviewed-by: default avatarBen Kelly <wanderview@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594723}
parent d22862c2
...@@ -92,10 +92,6 @@ function redirect_test(url, ...@@ -92,10 +92,6 @@ function redirect_test(url,
expected_request_infos, expected_request_infos,
test_name) { test_name) {
promise_test(async t => { promise_test(async t => {
const message_promise = new Promise(resolve => {
// A message with ID 'last_url' will be sent from the iframe.
message_resolvers['last_url'] = resolve;
});
const frame = await with_iframe(url); const frame = await with_iframe(url);
t.add_cleanup(() => { frame.remove(); }); t.add_cleanup(() => { frame.remove(); });
...@@ -105,7 +101,7 @@ function redirect_test(url, ...@@ -105,7 +101,7 @@ function redirect_test(url,
}); });
}); });
await check_all_intercepted_urls(expected_intercepted_urls); await check_all_intercepted_urls(expected_intercepted_urls);
const last_url = await message_promise; const last_url = await send_to_iframe(frame, 'getLocation');
assert_equals(last_url, expected_last_url, 'Last URL should match.'); assert_equals(last_url, expected_last_url, 'Last URL should match.');
}, test_name); }, test_name);
} }
...@@ -129,7 +125,7 @@ function send_to_iframe(frame, message) { ...@@ -129,7 +125,7 @@ function send_to_iframe(frame, message) {
message_resolvers[message_id] = resolve; message_resolvers[message_id] = resolve;
frame.contentWindow.postMessage( frame.contentWindow.postMessage(
{id: message_id, message}, {id: message_id, message},
host_info['HTTPS_REMOTE_ORIGIN']); '*');
}); });
} }
......
...@@ -11,10 +11,12 @@ def main(request, response): ...@@ -11,10 +11,12 @@ def main(request, response):
return status, [("content-type", "text/html")], ''' return status, [("content-type", "text/html")], '''
<!DOCTYPE html> <!DOCTYPE html>
<script> <script>
onmessage = event => {
window.parent.postMessage( window.parent.postMessage(
{ {
id: 'last_url', id: event.data.id,
result: location.href result: location.href
}, '*'); }, '*');
};
</script> </script>
''' '''
...@@ -11,10 +11,12 @@ def main(request, response): ...@@ -11,10 +11,12 @@ def main(request, response):
return status, [("content-type", "text/html")], ''' return status, [("content-type", "text/html")], '''
<!DOCTYPE html> <!DOCTYPE html>
<script> <script>
onmessage = event => {
window.parent.postMessage( window.parent.postMessage(
{ {
id: 'last_url', id: event.data.id,
result: location.href result: location.href
}, '*'); }, '*');
};
</script> </script>
''' '''
...@@ -11,10 +11,12 @@ def main(request, response): ...@@ -11,10 +11,12 @@ def main(request, response):
return status, [("content-type", "text/html")], ''' return status, [("content-type", "text/html")], '''
<!DOCTYPE html> <!DOCTYPE html>
<script> <script>
onmessage = event => {
window.parent.postMessage( window.parent.postMessage(
{ {
id: 'last_url', id: event.data.id,
result: location.href result: location.href
}, '*'); }, '*');
};
</script> </script>
''' '''
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment