tor-browser

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

browser_session_store_pageproxystate.js (2630B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* Any copyright is dedicated to the Public Domain.
      4 * http://creativecommons.org/publicdomain/zero/1.0/ */
      5 
      6 const triggeringPrincipal_base64 = E10SUtils.SERIALIZED_SYSTEMPRINCIPAL;
      7 
      8 let origBrowserState = SessionStore.getBrowserState();
      9 
     10 add_setup(async function () {
     11  registerCleanupFunction(() => {
     12    SessionStore.setBrowserState(origBrowserState);
     13  });
     14 });
     15 
     16 // Test that when restoring tabs via SessionStore, we directly show the correct
     17 // security state.
     18 add_task(async function test_session_store_security_state() {
     19  const state = {
     20    windows: [
     21      {
     22        tabs: [
     23          {
     24            entries: [
     25              { url: "https://example.net", triggeringPrincipal_base64 },
     26            ],
     27          },
     28          {
     29            entries: [
     30              { url: "https://example.org", triggeringPrincipal_base64 },
     31            ],
     32          },
     33        ],
     34        selected: 1,
     35      },
     36    ],
     37  };
     38 
     39  // Create a promise that resolves when the tabs have finished restoring.
     40  let promiseTabsRestored = Promise.all([
     41    TestUtils.topicObserved("sessionstore-browser-state-restored"),
     42    BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "SSTabRestored"),
     43  ]);
     44 
     45  SessionStore.setBrowserState(JSON.stringify(state));
     46 
     47  await promiseTabsRestored;
     48 
     49  is(gBrowser.selectedTab, gBrowser.tabs[0], "First tab is selected initially");
     50 
     51  info("Switch to second tab which has not been loaded yet.");
     52  BrowserTestUtils.switchTab(gBrowser, gBrowser.tabs[1]);
     53  is(
     54    gURLBar.getAttribute("pageproxystate"),
     55    "invalid",
     56    "Page proxy state is invalid after tab switch"
     57  );
     58 
     59  // Wait for valid pageproxystate. As soon as we have a valid pageproxystate,
     60  // showing the identity box, it should indicate a secure connection.
     61  await BrowserTestUtils.waitForMutationCondition(
     62    gURLBar,
     63    {
     64      attributeFilter: ["pageproxystate"],
     65    },
     66    () => gURLBar.getAttribute("pageproxystate") == "valid"
     67  );
     68 
     69  // Wait for a tick for security state to apply.
     70  await new Promise(resolve => setTimeout(resolve, 0));
     71 
     72  is(
     73    gBrowser.currentURI.spec,
     74    "https://example.org/",
     75    "Should have loaded example.org"
     76  );
     77  is(
     78    gIdentityHandler._identityBox.getAttribute("pageproxystate"),
     79    "valid",
     80    "identityBox pageproxystate is valid"
     81  );
     82 
     83  ok(
     84    gIdentityHandler._isSecureConnection,
     85    "gIdentityHandler._isSecureConnection is true"
     86  );
     87  is(
     88    gIdentityHandler._identityBox.className,
     89    "verifiedDomain",
     90    "identityBox class signals secure connection."
     91  );
     92 });