summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_docshell_uuid_consistency.js
blob: 6fc212eb2b89cf44ba530341f2698249fbf23dd3 (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
// First test - open a tab and duplicate it, using session restore to restore the history into the new tab.
add_task(async function duplicateTab() {
  const TEST_URL = "data:text/html,foo";
  let tab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

  let historyID = tab.linkedBrowser.browsingContext.historyID;
  let shEntry =
    tab.linkedBrowser.browsingContext.sessionHistory.getEntryAtIndex(0);
  is(shEntry.docshellID.toString(), historyID.toString());

  let tab2 = gBrowser.duplicateTab(tab);
  await BrowserTestUtils.browserLoaded(tab2.linkedBrowser);

  historyID = tab2.linkedBrowser.browsingContext.historyID;
  shEntry =
    tab2.linkedBrowser.browsingContext.sessionHistory.getEntryAtIndex(0);
  is(shEntry.docshellID.toString(), historyID.toString());

  BrowserTestUtils.removeTab(tab);
  BrowserTestUtils.removeTab(tab2);
});

// Second test - open a tab and navigate across processes, which triggers sessionrestore to persist history.
add_task(async function contentToChromeNavigate() {
  const TEST_URL = "data:text/html,foo";
  let tab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

  let historyID = tab.linkedBrowser.browsingContext.historyID;
  let sh = tab.linkedBrowser.browsingContext.sessionHistory;
  is(sh.count, 1);
  is(sh.getEntryAtIndex(0).docshellID.toString(), historyID.toString());

  // Force the browser to navigate to the chrome process.
  BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, "about:config");
  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

  // Check to be sure that we're in the chrome process.
  let docShell = tab.linkedBrowser.frameLoader.docShell;

  // 'cause we're in the chrome process, we can just directly poke at the shistory.
  sh = docShell.browsingContext.sessionHistory;

  is(sh.count, 2);
  is(
    sh.getEntryAtIndex(0).docshellID.toString(),
    docShell.historyID.toString()
  );
  is(
    sh.getEntryAtIndex(1).docshellID.toString(),
    docShell.historyID.toString()
  );

  BrowserTestUtils.removeTab(tab);
});