summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_dynamic_frames.js
blob: e4355fee3f78ebd47823164fa456bb7d6284bc08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* 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(function () {
  // 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 = gBrowser.addTab(URL);
  let browser = tab.linkedBrowser;
  yield promiseBrowserLoaded(browser);

  yield 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(function () {
  // 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 = gBrowser.addTab(URL);
  let browser = tab.linkedBrowser;
  yield promiseBrowserLoaded(browser);

  yield 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.
  browser.messageManager.sendAsyncMessage("ss-test:click", {id: "lnk"});
  yield promiseBrowserLoaded(browser, false /* don't ignore subframes */);

  yield 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);
});