diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/components/sessionstore/test/browser_dynamic_frames.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/sessionstore/test/browser_dynamic_frames.js')
-rw-r--r-- | browser/components/sessionstore/test/browser_dynamic_frames.js | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/browser/components/sessionstore/test/browser_dynamic_frames.js b/browser/components/sessionstore/test/browser_dynamic_frames.js new file mode 100644 index 0000000000..7852d683cc --- /dev/null +++ b/browser/components/sessionstore/test/browser_dynamic_frames.js @@ -0,0 +1,105 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Ensure that static frames of framesets are serialized but dynamically + * inserted iframes are ignored. + */ +add_task(async function() { + // allow top level data: URI navigations, otherwise clicking a data: link fails + await SpecialPowers.pushPrefEnv({ + set: [["security.data_uri.block_toplevel_data_uri_navigations", false]], + }); + // This URL has the following frames: + // + data:text/html,A (static) + // + data:text/html,B (static) + // + data:text/html,C (dynamic iframe) + const URL = + "data:text/html;charset=utf-8," + + "<frameset cols=50%25,50%25><frame src='data:text/html,A'>" + + "<frame src='data:text/html,B'></frameset>" + + "<script>var i=document.createElement('iframe');" + + "i.setAttribute('src', 'data:text/html,C');" + + "document.body.appendChild(i);</script>"; + + // Add a new tab with two "static" and one "dynamic" frame. + let tab = BrowserTestUtils.addTab(gBrowser, URL); + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + await TabStateFlusher.flush(browser); + let { entries } = JSON.parse(ss.getTabState(tab)); + + // Check URLs. + ok(entries[0].url.startsWith("data:text/html"), "correct root url"); + is( + entries[0].children[0].url, + "data:text/html,A", + "correct url for 1st frame" + ); + is( + entries[0].children[1].url, + "data:text/html,B", + "correct url for 2nd frame" + ); + + // Check the number of children. + is(entries.length, 1, "there is one root entry ..."); + is(entries[0].children.length, 2, "... with two child entries"); + + // Cleanup. + gBrowser.removeTab(tab); +}); + +/** + * Ensure that iframes created by the network parser are serialized but + * dynamically inserted iframes are ignored. Navigating a subframe should + * create a second root entry that doesn't contain any dynamic children either. + */ +add_task(async function() { + // allow top level data: URI navigations, otherwise clicking a data: link fails + await SpecialPowers.pushPrefEnv({ + set: [["security.data_uri.block_toplevel_data_uri_navigations", false]], + }); + // This URL has the following frames: + // + data:text/html,A (static) + // + data:text/html,C (dynamic iframe) + const URL = + "data:text/html;charset=utf-8," + + "<iframe name=t src='data:text/html,A'></iframe>" + + "<a id=lnk href='data:text/html,B' target=t>clickme</a>" + + "<script>var i=document.createElement('iframe');" + + "i.setAttribute('src', 'data:text/html,C');" + + "document.body.appendChild(i);</script>"; + + // Add a new tab with one "static" and one "dynamic" frame. + let tab = BrowserTestUtils.addTab(gBrowser, URL); + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + await TabStateFlusher.flush(browser); + let { entries } = JSON.parse(ss.getTabState(tab)); + + // Check URLs. + ok(entries[0].url.startsWith("data:text/html"), "correct root url"); + ok(!entries[0].children, "no children collected"); + + // Navigate the subframe. + await BrowserTestUtils.synthesizeMouseAtCenter("#lnk", {}, browser); + await promiseBrowserLoaded(browser, false /* don't ignore subframes */); + + await TabStateFlusher.flush(browser); + ({ entries } = JSON.parse(ss.getTabState(tab))); + + // Check URLs. + ok(entries[0].url.startsWith("data:text/html"), "correct 1st root url"); + ok(entries[1].url.startsWith("data:text/html"), "correct 2nd root url"); + ok(!entries.children, "no children collected"); + ok(!entries[0].children, "no children collected"); + ok(!entries[1].children, "no children collected"); + + // Cleanup. + gBrowser.removeTab(tab); +}); |