summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_707862.js
blob: 765c63257f63cbcf5cbb4025f2b342985e8d4d6f (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
88
89
90
91
92
93
94
95
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
/* eslint-disable mozilla/no-arbitrary-setTimeout */

var tabState = {
  entries: [
    {
      url: "about:robots",
      triggeringPrincipal_base64,
      children: [{ url: "about:mozilla", triggeringPrincipal_base64 }],
    },
  ],
};

function test() {
  waitForExplicitFinish();
  requestLongerTimeout(2);

  Services.prefs.setIntPref("browser.sessionstore.interval", 4000);
  registerCleanupFunction(function () {
    Services.prefs.clearUserPref("browser.sessionstore.interval");
  });

  let tab = BrowserTestUtils.addTab(gBrowser, "about:blank");

  let browser = tab.linkedBrowser;

  promiseTabState(tab, tabState).then(() => {
    let entry;
    if (!Services.appinfo.sessionHistoryInParent) {
      let sessionHistory = browser.sessionHistory;
      entry = sessionHistory.legacySHistory.getEntryAtIndex(0);
    } else {
      let sessionHistory = browser.browsingContext.sessionHistory;
      entry = sessionHistory.getEntryAtIndex(0);
    }

    whenChildCount(entry, 1, function () {
      whenChildCount(entry, 2, function () {
        promiseBrowserLoaded(browser).then(() => {
          let newEntry;
          if (!Services.appinfo.sessionHistoryInParent) {
            let newSessionHistory = browser.sessionHistory;
            newEntry = newSessionHistory.legacySHistory.getEntryAtIndex(0);
          } else {
            let newSessionHistory = browser.browsingContext.sessionHistory;
            newEntry = newSessionHistory.getEntryAtIndex(0);
          }

          whenChildCount(newEntry, 0, function () {
            // Make sure that we reset the state.
            let blankState = {
              windows: [
                {
                  tabs: [
                    {
                      entries: [
                        { url: "about:blank", triggeringPrincipal_base64 },
                      ],
                    },
                  ],
                },
              ],
            };
            waitForBrowserState(blankState, finish);
          });
        });

        // Force reload the browser to deprecate the subframes.
        browser.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE);
      });

      // Create a dynamic subframe.
      let doc = browser.contentDocument;
      let iframe = doc.createElement("iframe");
      doc.body.appendChild(iframe);
      iframe.setAttribute("src", "about:mozilla");
    });
  });

  // This test relies on the test timing out in order to indicate failure so
  // let's add a dummy pass.
  ok(
    true,
    "Each test requires at least one pass, fail or todo so here is a pass."
  );
}

function whenChildCount(aEntry, aChildCount, aCallback) {
  if (aEntry.childCount == aChildCount) {
    aCallback();
  } else {
    setTimeout(() => whenChildCount(aEntry, aChildCount, aCallback), 100);
  }
}