1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_dynamic_frames.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +"use strict"; 1.8 + 1.9 +/** 1.10 + * Ensure that static frames of framesets are serialized but dynamically 1.11 + * inserted iframes are ignored. 1.12 + */ 1.13 +add_task(function () { 1.14 + // This URL has the following frames: 1.15 + // + about:mozilla (static) 1.16 + // + about:robots (static) 1.17 + // + about:rights (dynamic iframe) 1.18 + const URL = "data:text/html;charset=utf-8," + 1.19 + "<frameset cols=50%25,50%25><frame src=about%3Amozilla>" + 1.20 + "<frame src=about%3Arobots></frameset>" + 1.21 + "<script>var i=document.createElement('iframe');" + 1.22 + "i.setAttribute('src', 'about%3Arights');" + 1.23 + "document.body.appendChild(i);</script>"; 1.24 + 1.25 + // Add a new tab with two "static" and one "dynamic" frame. 1.26 + let tab = gBrowser.addTab(URL); 1.27 + let browser = tab.linkedBrowser; 1.28 + yield promiseBrowserLoaded(browser); 1.29 + 1.30 + SyncHandlers.get(browser).flush(); 1.31 + let {entries} = JSON.parse(ss.getTabState(tab)); 1.32 + 1.33 + // Check URLs. 1.34 + ok(entries[0].url.startsWith("data:text/html"), "correct root url"); 1.35 + is(entries[0].children[0].url, "about:mozilla", "correct url for 1st frame"); 1.36 + is(entries[0].children[1].url, "about:robots", "correct url for 2nd frame"); 1.37 + 1.38 + // Check the number of children. 1.39 + is(entries.length, 1, "there is one root entry ..."); 1.40 + is(entries[0].children.length, 2, "... with two child entries"); 1.41 + 1.42 + // Cleanup. 1.43 + gBrowser.removeTab(tab); 1.44 +}); 1.45 + 1.46 +/** 1.47 + * Ensure that iframes created by the network parser are serialized but 1.48 + * dynamically inserted iframes are ignored. Navigating a subframe should 1.49 + * create a second root entry that doesn't contain any dynamic children either. 1.50 + */ 1.51 +add_task(function () { 1.52 + // This URL has the following frames: 1.53 + // + about:mozilla (static iframe) 1.54 + // + about:rights (dynamic iframe) 1.55 + const URL = "data:text/html;charset=utf-8," + 1.56 + "<iframe name=t src=about%3Amozilla></iframe>" + 1.57 + "<a id=lnk href=about%3Arobots target=t>clickme</a>" + 1.58 + "<script>var i=document.createElement('iframe');" + 1.59 + "i.setAttribute('src', 'about%3Arights');" + 1.60 + "document.body.appendChild(i);</script>"; 1.61 + 1.62 + // Add a new tab with one "static" and one "dynamic" frame. 1.63 + let tab = gBrowser.addTab(URL); 1.64 + let browser = tab.linkedBrowser; 1.65 + yield promiseBrowserLoaded(browser); 1.66 + 1.67 + SyncHandlers.get(browser).flush(); 1.68 + let {entries} = JSON.parse(ss.getTabState(tab)); 1.69 + 1.70 + // Check URLs. 1.71 + ok(entries[0].url.startsWith("data:text/html"), "correct root url"); 1.72 + is(entries[0].children[0].url, "about:mozilla", "correct url for static frame"); 1.73 + 1.74 + // Check the number of children. 1.75 + is(entries.length, 1, "there is one root entry ..."); 1.76 + is(entries[0].children.length, 1, "... with a single child entry"); 1.77 + 1.78 + // Navigate the subframe. 1.79 + browser.messageManager.sendAsyncMessage("ss-test:click", {id: "lnk"}); 1.80 + yield promiseBrowserLoaded(browser, false /* don't ignore subframes */); 1.81 + 1.82 + SyncHandlers.get(browser).flush(); 1.83 + let {entries} = JSON.parse(ss.getTabState(tab)); 1.84 + 1.85 + // Check URLs. 1.86 + ok(entries[0].url.startsWith("data:text/html"), "correct 1st root url"); 1.87 + ok(entries[1].url.startsWith("data:text/html"), "correct 2nd root url"); 1.88 + is(entries[0].children[0].url, "about:mozilla", "correct url for 1st static frame"); 1.89 + is(entries[1].children[0].url, "about:robots", "correct url for 2ns static frame"); 1.90 + 1.91 + // Check the number of children. 1.92 + is(entries.length, 2, "there are two root entries ..."); 1.93 + is(entries[0].children.length, 1, "... with a single child entry ..."); 1.94 + is(entries[1].children.length, 1, "... each"); 1.95 + 1.96 + // Cleanup. 1.97 + gBrowser.removeTab(tab); 1.98 +});