consecutive-srcdoc.html (2983B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>changing srcdoc to a different srcdoc</title> 4 <link rel="help" href="https://github.com/whatwg/html/issues/6809#issuecomment-905677979"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="../../resources/helpers.js"></script> 8 9 <script> 10 "use strict"; 11 12 // Note: bfcache won't mess with any windows with openers, so it doesn't 13 // interfere with these tests. 14 15 promise_test(async t => { 16 // Set up a window whose iframe contains [normal page, srcdoc] entries. 17 const w = await openWindow("../../resources/has-iframe.html", t); 18 const iframe = w.document.querySelector("iframe"); 19 20 await waitToAvoidReplace(t); 21 iframe.srcdoc = srcdocThatPostsParentOpener("srcdoc1"); 22 await waitForMessage(iframe.contentWindow); 23 24 assert_equals(w.history.length, 2); 25 26 // Now navigate to a different srcdoc 27 iframe.srcdoc = srcdocThatPostsParentOpener("srcdoc2"); 28 29 // Test that it's a replace. 30 await waitForMessage(iframe.contentWindow); 31 assert_equals(w.history.length, 2, 32 "history.length must not change since it was a replace"); 33 assert_equals( 34 iframe.contentDocument.querySelector("p").textContent, 35 "srcdoc2", 36 "Sanity check: the srcdoc document did indeed update" 37 ); 38 }, "changing srcdoc does a replace navigation since the URL is still " + 39 "about:srcdoc"); 40 41 promise_test(async t => { 42 // Set up a window whose iframe contains [normal page, srcdoc] entries. 43 const w = await openWindow("../../resources/has-iframe.html", t); 44 const iframe = w.document.querySelector("iframe"); 45 46 await waitToAvoidReplace(t); 47 iframe.srcdoc = srcdocThatPostsParentOpener("srcdoc1"); 48 await waitForMessage(iframe.contentWindow); 49 50 assert_equals(w.history.length, 2); 51 52 // Now navigate to about:srcdoc#yo 53 iframe.contentWindow.location.href = "about:srcdoc#yo"; 54 assert_equals(iframe.contentWindow.location.href, "about:srcdoc#yo"); 55 assert_equals(w.history.length, 3); 56 57 // Now navigate to a different srcdoc 58 iframe.srcdoc = srcdocThatPostsParentOpener("srcdoc2"); 59 60 // Test that it's a push back to about:srcdoc. 61 await waitForMessage(iframe.contentWindow); 62 assert_equals( 63 w.history.length, 64 4, 65 "history.length must increase since it was a push" 66 ); 67 assert_equals(iframe.contentWindow.location.href, "about:srcdoc"); 68 assert_equals( 69 iframe.contentDocument.querySelector("p").textContent, 70 "srcdoc2", 71 "Sanity check: the srcdoc document did indeed update" 72 ); 73 74 // Test that we can go back to about:srcdoc#yo. 75 w.history.back(); 76 await waitForMessage(iframe.contentWindow); 77 assert_equals(iframe.contentWindow.location.href, "about:srcdoc#yo"); 78 assert_equals( 79 iframe.contentDocument.querySelector("p").textContent, 80 "srcdoc1", 81 "srcdoc content must be restored from history" 82 ); 83 }, "changing srcdoc to about:srcdoc#yo then another srcdoc does two push " + 84 "navigations and we can navigate back"); 85 </script>