tor-browser

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

browser_739805.js (1588B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 var url = "data:text/html;charset=utf-8,<input%20id='foo'>";
      5 var tabState = {
      6  entries: [{ url, triggeringPrincipal_base64 }],
      7  formdata: { id: { foo: "bar" }, url },
      8 };
      9 
     10 function test() {
     11  waitForExplicitFinish();
     12  Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
     13 
     14  registerCleanupFunction(function () {
     15    if (gBrowser.tabs.length > 1) {
     16      gBrowser.removeTab(gBrowser.tabs[1]);
     17    }
     18    Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
     19  });
     20 
     21  let tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
     22  let browser = tab.linkedBrowser;
     23 
     24  BrowserTestUtils.browserLoaded(browser, { wantLoad: "about:blank" }).then(
     25    () => {
     26      isnot(gBrowser.selectedTab, tab, "newly created tab is not selected");
     27 
     28      ss.setTabState(tab, JSON.stringify(tabState));
     29      is(
     30        ss.getInternalObjectState(browser),
     31        TAB_STATE_NEEDS_RESTORE,
     32        "tab needs restoring"
     33      );
     34 
     35      let { formdata } = JSON.parse(ss.getTabState(tab));
     36      is(formdata && formdata.id.foo, "bar", "tab state's formdata is valid");
     37 
     38      promiseTabRestored(tab).then(() => {
     39        SpecialPowers.spawn(browser, [], function () {
     40          let input = content.document.getElementById("foo");
     41          is(input.value, "bar", "formdata has been restored correctly");
     42        }).then(() => {
     43          finish();
     44        });
     45      });
     46 
     47      // Restore the tab by selecting it.
     48      gBrowser.selectedTab = tab;
     49    }
     50  );
     51 }