tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_docshell_uuid_consistency.js (2128B)


      1 // First test - open a tab and duplicate it, using session restore to restore the history into the new tab.
      2 add_task(async function duplicateTab() {
      3  const TEST_URL = "data:text/html,foo";
      4  let tab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
      5  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
      6 
      7  let historyID = tab.linkedBrowser.browsingContext.historyID;
      8  let shEntry =
      9    tab.linkedBrowser.browsingContext.sessionHistory.getEntryAtIndex(0);
     10  is(shEntry.docshellID.toString(), historyID.toString());
     11 
     12  let tab2 = gBrowser.duplicateTab(tab);
     13  await BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
     14 
     15  historyID = tab2.linkedBrowser.browsingContext.historyID;
     16  shEntry =
     17    tab2.linkedBrowser.browsingContext.sessionHistory.getEntryAtIndex(0);
     18  is(shEntry.docshellID.toString(), historyID.toString());
     19 
     20  BrowserTestUtils.removeTab(tab);
     21  BrowserTestUtils.removeTab(tab2);
     22 });
     23 
     24 // Second test - open a tab and navigate across processes, which triggers sessionrestore to persist history.
     25 add_task(async function contentToChromeNavigate() {
     26  const TEST_URL = "data:text/html,foo";
     27  let tab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
     28  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
     29 
     30  let historyID = tab.linkedBrowser.browsingContext.historyID;
     31  let sh = tab.linkedBrowser.browsingContext.sessionHistory;
     32  is(sh.count, 1);
     33  is(sh.getEntryAtIndex(0).docshellID.toString(), historyID.toString());
     34 
     35  // Force the browser to navigate to the chrome process.
     36  BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, "about:config");
     37  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
     38 
     39  // Check to be sure that we're in the chrome process.
     40  let docShell = tab.linkedBrowser.frameLoader.docShell;
     41 
     42  // 'cause we're in the chrome process, we can just directly poke at the shistory.
     43  sh = docShell.browsingContext.sessionHistory;
     44 
     45  is(sh.count, 2);
     46  is(
     47    sh.getEntryAtIndex(0).docshellID.toString(),
     48    docShell.historyID.toString()
     49  );
     50  is(
     51    sh.getEntryAtIndex(1).docshellID.toString(),
     52    docShell.historyID.toString()
     53  );
     54 
     55  BrowserTestUtils.removeTab(tab);
     56 });