browser/components/sessionstore/test/browser_dynamic_frames.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:65b7a87fe280
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 "use strict";
5
6 /**
7 * Ensure that static frames of framesets are serialized but dynamically
8 * inserted iframes are ignored.
9 */
10 add_task(function () {
11 // This URL has the following frames:
12 // + about:mozilla (static)
13 // + about:robots (static)
14 // + about:rights (dynamic iframe)
15 const URL = "data:text/html;charset=utf-8," +
16 "<frameset cols=50%25,50%25><frame src=about%3Amozilla>" +
17 "<frame src=about%3Arobots></frameset>" +
18 "<script>var i=document.createElement('iframe');" +
19 "i.setAttribute('src', 'about%3Arights');" +
20 "document.body.appendChild(i);</script>";
21
22 // Add a new tab with two "static" and one "dynamic" frame.
23 let tab = gBrowser.addTab(URL);
24 let browser = tab.linkedBrowser;
25 yield promiseBrowserLoaded(browser);
26
27 SyncHandlers.get(browser).flush();
28 let {entries} = JSON.parse(ss.getTabState(tab));
29
30 // Check URLs.
31 ok(entries[0].url.startsWith("data:text/html"), "correct root url");
32 is(entries[0].children[0].url, "about:mozilla", "correct url for 1st frame");
33 is(entries[0].children[1].url, "about:robots", "correct url for 2nd frame");
34
35 // Check the number of children.
36 is(entries.length, 1, "there is one root entry ...");
37 is(entries[0].children.length, 2, "... with two child entries");
38
39 // Cleanup.
40 gBrowser.removeTab(tab);
41 });
42
43 /**
44 * Ensure that iframes created by the network parser are serialized but
45 * dynamically inserted iframes are ignored. Navigating a subframe should
46 * create a second root entry that doesn't contain any dynamic children either.
47 */
48 add_task(function () {
49 // This URL has the following frames:
50 // + about:mozilla (static iframe)
51 // + about:rights (dynamic iframe)
52 const URL = "data:text/html;charset=utf-8," +
53 "<iframe name=t src=about%3Amozilla></iframe>" +
54 "<a id=lnk href=about%3Arobots target=t>clickme</a>" +
55 "<script>var i=document.createElement('iframe');" +
56 "i.setAttribute('src', 'about%3Arights');" +
57 "document.body.appendChild(i);</script>";
58
59 // Add a new tab with one "static" and one "dynamic" frame.
60 let tab = gBrowser.addTab(URL);
61 let browser = tab.linkedBrowser;
62 yield promiseBrowserLoaded(browser);
63
64 SyncHandlers.get(browser).flush();
65 let {entries} = JSON.parse(ss.getTabState(tab));
66
67 // Check URLs.
68 ok(entries[0].url.startsWith("data:text/html"), "correct root url");
69 is(entries[0].children[0].url, "about:mozilla", "correct url for static frame");
70
71 // Check the number of children.
72 is(entries.length, 1, "there is one root entry ...");
73 is(entries[0].children.length, 1, "... with a single child entry");
74
75 // Navigate the subframe.
76 browser.messageManager.sendAsyncMessage("ss-test:click", {id: "lnk"});
77 yield promiseBrowserLoaded(browser, false /* don't ignore subframes */);
78
79 SyncHandlers.get(browser).flush();
80 let {entries} = JSON.parse(ss.getTabState(tab));
81
82 // Check URLs.
83 ok(entries[0].url.startsWith("data:text/html"), "correct 1st root url");
84 ok(entries[1].url.startsWith("data:text/html"), "correct 2nd root url");
85 is(entries[0].children[0].url, "about:mozilla", "correct url for 1st static frame");
86 is(entries[1].children[0].url, "about:robots", "correct url for 2ns static frame");
87
88 // Check the number of children.
89 is(entries.length, 2, "there are two root entries ...");
90 is(entries[0].children.length, 1, "... with a single child entry ...");
91 is(entries[1].children.length, 1, "... each");
92
93 // Cleanup.
94 gBrowser.removeTab(tab);
95 });

mercurial