Skip to content

Commit

Permalink
Bug 1705146 [wpt PR 28480] - Attempt to test replace before load, a=t…
Browse files Browse the repository at this point in the history
…estonly

Automatic update from web-platform-tests
Test replace vs. push before/during load and pageshow

Follows whatwg/html#6714.
--

wpt-commits: c1bb1fdaa510c14d31ca8307f4778b015a6bb30d
wpt-pr: 28480
  • Loading branch information
domenic authored and moz-wptsync-bot committed Jun 26, 2021
1 parent 2e0bdce commit 6658279
Show file tree
Hide file tree
Showing 45 changed files with 1,628 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onload = () => {
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
document.body.append(a);
a.click();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "aElement.click() during the load event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onpageshow = () => {
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
document.body.append(a);
a.click();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "aElement.click() during the pageshow event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
document.currentScript.before(a);
a.click();
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoad(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "aElement.click() before the load event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onload = () => {
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
a.id = "the-anchor";
a.textContent = "needs to have content to be clickable";
document.body.append(a);
parent.test_driver.click(a);
};
`;

const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "User click on <a> during the load event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onpageshow = () => {
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
a.id = "the-anchor";
a.textContent = "needs to have content to be clickable";
document.body.append(a);
parent.test_driver.click(a);
};
`;

const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "User click on <a> during the pageshow event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
a.id = "the-anchor";
a.textContent = "needs to have content to be clickable";
document.currentScript.before(a);
parent.test_driver.click(a);
`;

const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoad(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "User click on <a> before the load event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onload = () => {
const form = document.createElement("form");
form.action = "/common/blank.html";
const input = document.createElement("input");
input.type = "hidden";
input.name = "thereplacement";
form.append(input);
document.body.append(form);
form.requestSubmit();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement=";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");

await checkSentinelIframe(t, sentinelIframe);
assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
}, "Replace during the load event, triggered by formElement.submit()");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onpageshow = () => {
const form = document.createElement("form");
form.action = "/common/blank.html";
const input = document.createElement("input");
input.type = "hidden";
input.name = "thereplacement";
form.append(input);
document.body.append(form);
form.requestSubmit();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement=";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");

await checkSentinelIframe(t, sentinelIframe);
assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
}, "Replace during the pageshow event, triggered by formElement.submit()");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
const form = document.createElement("form");
form.action = "/common/blank.html";
const input = document.createElement("input");
input.type = "hidden";
input.name = "thereplacement";
form.append(input);
document.currentScript.before(form);
form.requestSubmit();
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement=";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoad(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");

await checkSentinelIframe(t, sentinelIframe);
assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
}, "Replace before load, triggered by formElement.requestSubmit()");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onload = () => {
const form = document.createElement("form");
form.action = "/common/blank.html";
const input = document.createElement("input");
input.type = "hidden";
input.name = "thereplacement";
form.append(input);
const button = document.createElement("button");
button.type = "submit";
form.append(button);
document.body.append(form);
button.click();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement=";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");

await checkSentinelIframe(t, sentinelIframe);
assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
}, "Replace during load, triggered by submitButton.click()");
</script>
Loading

0 comments on commit 6658279

Please sign in to comment.