Skip to content

Commit

Permalink
Don't duplicate this function
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Oct 17, 2022
1 parent 178d7c5 commit 3c2f2da
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// META: script=../resources/helpers.js

promise_test(async t => {
const iframe = await setupAndWaitForSrcdocIframe();
const iframe = await addSrcdocIframe();

iframe.contentWindow.location = "/common/blank.html";
await waitForIframeLoad(iframe);
Expand All @@ -22,7 +22,7 @@ promise_test(async t => {
}, "Navigations to about:srcdoc via window.location must be blocked");

promise_test(async t => {
const iframe = await setupAndWaitForSrcdocIframe();
const iframe = await addSrcdocIframe();
iframe.contentWindow.name = "test_frame";

iframe.contentWindow.location = "/common/blank.html";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// META: script=../resources/helpers.js

promise_test(async () => {
const iframe = await setupAndWaitForIframe();
const iframe = await addIframe();

iframe.contentWindow.addEventListener("unload", () => {
iframe.contentWindow.location.href = "//{{hosts[][www]}}/common/blank.html?fail";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// META: script=../resources/helpers.js

promise_test(async () => {
const iframe = await setupAndWaitForIframe();
const iframe = await addIframe();

iframe.contentWindow.addEventListener("unload", () => {
iframe.contentWindow.location.href =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// META: script=../resources/helpers.js

promise_test(async () => {
const iframe = await setupAndWaitForIframe();
const iframe = await addIframe();

iframe.contentWindow.addEventListener("unload", () => {
iframe.contentWindow.location.href = "/common/blank.html?fail";
Expand Down
20 changes: 5 additions & 15 deletions html/browsers/browsing-the-web/resources/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,7 @@ window.addIframe = (url = "/common/blank.html", doc = document) => {
});
};

window.waitToAvoidReplace = t => {
return new Promise(resolve => t.step_timeout(resolve, 0));
};

window.setupAndWaitForIframe = async (url = "/common/blank.html") => {
const iframe = document.createElement("iframe");
iframe.src = url;
document.body.append(iframe);

await waitForIframeLoad(iframe);

return iframe;
};

window.setupAndWaitForSrcdocIframe = async () => {
window.addSrcdocIframe = async () => {
const iframe = document.createElement("iframe");
iframe.srcdoc = `<script>window.parent.postMessage("srcdoc ready", "*")</scr` + `ipt>`;
document.body.append(iframe);
Expand All @@ -50,6 +36,10 @@ window.setupAndWaitForSrcdocIframe = async () => {
return iframe;
};

window.waitToAvoidReplace = t => {
return new Promise(resolve => t.step_timeout(resolve, 0));
};

window.waitForIframeLoad = iframe => {
return new Promise(resolve => {
iframe.addEventListener("load", () => resolve(), { once: true });
Expand Down

0 comments on commit 3c2f2da

Please sign in to comment.