|
| 1 | +test(t => { |
| 2 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 3 | + t.add_cleanup(() => frame.remove()); |
| 4 | + assert_equals(frame.contentDocument.URL, "about:blank"); |
| 5 | + assert_equals(frame.contentWindow.location.href, "about:blank"); |
| 6 | + frame.contentDocument.open(); |
| 7 | + assert_equals(frame.contentDocument.URL, document.URL); |
| 8 | + assert_equals(frame.contentWindow.location.href, document.URL); |
| 9 | +}, "document.open() changes document's URL (fully active document)"); |
| 10 | + |
| 11 | +async_test(t => { |
| 12 | + const blankURL = new URL("/common/blank.html", document.URL).href; |
| 13 | + const frameURL = new URL("resources/page-with-frame.html", document.URL).href; |
| 14 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 15 | + t.add_cleanup(() => frame.remove()); |
| 16 | + frame.onload = t.step_func(() => { |
| 17 | + assert_equals(frame.contentDocument.URL, frameURL); |
| 18 | + assert_equals(frame.contentWindow.location.href, frameURL); |
| 19 | + const childFrame = frame.contentDocument.querySelector("iframe"); |
| 20 | + const childDoc = childFrame.contentDocument; |
| 21 | + const childWin = childFrame.contentWindow; |
| 22 | + assert_equals(childDoc.URL, blankURL); |
| 23 | + assert_equals(childWin.location.href, blankURL); |
| 24 | + |
| 25 | + // Right now childDoc is still fully active. |
| 26 | + |
| 27 | + frame.onload = t.step_func_done(() => { |
| 28 | + // Now childDoc is still active but no longer fully active. |
| 29 | + childDoc.open(); |
| 30 | + assert_equals(childDoc.URL, blankURL); |
| 31 | + assert_equals(childWin.location.href, blankURL); |
| 32 | + }); |
| 33 | + frame.src = "/common/blank.html"; |
| 34 | + }); |
| 35 | + frame.src = frameURL; |
| 36 | +}, "document.open() does not change document's URL (active but not fully active document)"); |
| 37 | + |
| 38 | +test(t => { |
| 39 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 40 | + t.add_cleanup(() => frame.remove()); |
| 41 | + const doc = frame.contentDocument; |
| 42 | + |
| 43 | + // Right now the frame is connected and it has an active document. |
| 44 | + assert_equals(doc.URL, "about:blank"); |
| 45 | + |
| 46 | + frame.remove(); |
| 47 | + |
| 48 | + // Now the frame is no longer connected. Its document is no longer active. |
| 49 | + assert_equals(doc.URL, "about:blank"); |
| 50 | + assert_equals(doc.open(), doc); |
| 51 | + assert_equals(doc.URL, "about:blank"); |
| 52 | +}, "document.open() does not change document's URL (non-active document with an associated Window object; frame is removed)"); |
| 53 | + |
| 54 | +async_test(t => { |
| 55 | + const frame = document.createElement("iframe"); |
| 56 | + t.add_cleanup(() => frame.remove()); |
| 57 | + |
| 58 | + frame.onload = t.step_func(() => { |
| 59 | + const doc = frame.contentDocument; |
| 60 | + // Right now the frame is connected and it has an active document. |
| 61 | + assert_equals(doc.URL, "about:blank"); |
| 62 | + |
| 63 | + frame.onload = t.step_func_done(() => { |
| 64 | + // Now even though the frame is still connected, its document is no |
| 65 | + // longer active. |
| 66 | + assert_not_equals(frame.contentDocument, doc); |
| 67 | + assert_equals(doc.URL, "about:blank"); |
| 68 | + assert_equals(doc.open(), doc); |
| 69 | + assert_equals(doc.URL, "about:blank"); |
| 70 | + }); |
| 71 | + |
| 72 | + frame.src = "/common/blank.html"; |
| 73 | + }); |
| 74 | + |
| 75 | + // We need to connect the frame after the load event is set up to mitigate |
| 76 | + // against https://crbug.com/569511. |
| 77 | + document.body.appendChild(frame); |
| 78 | +}, "document.open() does not change document's URL (non-active document with an associated Window object; navigated away)"); |
| 79 | + |
| 80 | +test(t => { |
| 81 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 82 | + t.add_cleanup(() => frame.remove()); |
| 83 | + const doc = frame.contentDocument.implementation.createHTMLDocument(); |
| 84 | + assert_equals(doc.URL, "about:blank"); |
| 85 | + assert_equals(doc.open(), doc); |
| 86 | + assert_equals(doc.URL, "about:blank"); |
| 87 | +}, "document.open() does not change document's URL (non-active document without an associated Window object)"); |
0 commit comments