Skip to content

Commit 24b49df

Browse files
vinhillmoz-wptsync-bot
authored andcommitted
Avoid flakiness in history{-iframe}.sub.html.
Differential Revision: https://phabricator.services.mozilla.com/D297627 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=2026147 gecko-commit: 91d0458eb329d0914df3eec3a325664b3fd1831c gecko-commit-git: 329705a5c23d176fd84ebc9e8c31ca8d028f2881 gecko-reviewers: dom-core, smaug
1 parent 93e1df0 commit 24b49df

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

content-security-policy/inheritance/history-iframe.sub.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
await t.step_wait(
5353
condition = () => {
5454
try {
55-
return iframe.contentWindow.location.href == "about:blank";
55+
return iframe.contentWindow.location.href == "about:blank" &&
56+
iframe.contentDocument.readyState == "complete";
5657
} catch {}
5758
return false;
5859
},

content-security-policy/inheritance/history.sub.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,29 @@
148148

149149
// Navigate to the local scheme document. We need to wait for the
150150
// navigation to succeed.
151-
let wait = () => t.step_wait(
151+
let wait = (msg) => t.step_wait(
152152
condition = () => {
153153
try {
154-
return popup.location.href == testCase.url;
154+
return popup.location.href == testCase.url &&
155+
popup.document.readyState == "complete";
155156
} catch {}
156157
return false;
157158
},
158-
description = "Wait for the popup to navigate.",
159+
description = "Wait for the popup to navigate: " + msg,
159160
timeout=3000,
160161
interval=50);
161162

162163
let message = message_from(testCase.token);
163164
popup.location = testCase.url;
164-
await wait();
165+
await wait("to test url");
165166
if (testCase.add_img_function) {
166167
testCase.add_img_function(popup);
167168
}
168169

169170
// Check that the local scheme document inherits CSP from the initiator.
170171
assert_equals(await message, "img blocked",
171172
"Image should be blocked by CSP inherited from navigation initiator.");
173+
assert_equals(popup.history.length, 2, "History entry for test url added");
172174

173175
const token_2 = token();
174176
let loaded_2 = message_from(token_2, "ready");
@@ -181,7 +183,10 @@
181183
"Could not navigate popup.");
182184

183185
// We need to wait for the history navigation to be performed.
184-
await wait();
186+
await Promise.race([
187+
message_from(token_1).then(() => assert_unreached("Navigated back too far")),
188+
wait("history.back() to test url")
189+
])
185190

186191
// Check that the "about:blank" document reloaded from history has the
187192
// original CSPs.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script>
2+
window.onload = () => {
23
const params = new URLSearchParams(window.location.search);
34
opener.postMessage({msg: "ready", token: params.get("token")}, "*");
5+
}
46
</script>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<!DOCTYPE html>
22
<script>
3+
window.onload = () => {
34
const params = new URLSearchParams(window.location.search);
45
top.postMessage({msg: "ready", token: params.get("token")}, "*");
6+
}
57
</script>

0 commit comments

Comments
 (0)