url.window.js (3925B)
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 assert_equals(frame.contentDocument.open(), frame.contentDocument); 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 assert_equals(childDoc.open(), childDoc); 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 // We do not test for win.location.href in this test due to 44 // https://github.com/whatwg/html/issues/3959. 45 46 // Right now the frame is connected and it has an active document. 47 assert_equals(doc.URL, "about:blank"); 48 49 frame.remove(); 50 51 // Now the frame is no longer connected. Its document is no longer active. 52 assert_equals(doc.URL, "about:blank"); 53 assert_equals(doc.open(), doc); 54 assert_equals(doc.URL, "about:blank"); 55 }, "document.open() does not change document's URL (non-active document with an associated Window object; frame is removed)"); 56 57 async_test(t => { 58 const frame = document.createElement("iframe"); 59 t.add_cleanup(() => frame.remove()); 60 61 // We do not test for win.location.href in this test due to 62 // https://github.com/whatwg/html/issues/3959. 63 64 frame.onload = t.step_func(() => { 65 const doc = frame.contentDocument; 66 // Right now the frame is connected and it has an active document. 67 assert_equals(doc.URL, "about:blank"); 68 69 frame.onload = t.step_func_done(() => { 70 // Now even though the frame is still connected, its document is no 71 // longer active. 72 assert_not_equals(frame.contentDocument, doc); 73 assert_equals(doc.URL, "about:blank"); 74 assert_equals(doc.open(), doc); 75 assert_equals(doc.URL, "about:blank"); 76 }); 77 78 frame.src = "/common/blank.html"; 79 }); 80 81 // We need to connect the frame after the load event is set up to mitigate 82 // against https://crbug.com/569511. 83 document.body.appendChild(frame); 84 }, "document.open() does not change document's URL (non-active document with an associated Window object; navigated away)"); 85 86 test(t => { 87 const frame = document.body.appendChild(document.createElement("iframe")); 88 t.add_cleanup(() => frame.remove()); 89 const doc = frame.contentDocument.implementation.createHTMLDocument(); 90 assert_equals(doc.URL, "about:blank"); 91 assert_equals(doc.open(), doc); 92 assert_equals(doc.URL, "about:blank"); 93 }, "document.open() does not change document's URL (non-active document without an associated Window object)");