tor-browser

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

browser_captivePortalTabReference.js (1941B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const CPS = Cc["@mozilla.org/network/captive-portal-service;1"].getService(
      7  Ci.nsICaptivePortalService
      8 );
      9 
     10 async function checkCaptivePortalTabReference(evt, currState) {
     11  await portalDetected();
     12  let errorTab = await openCaptivePortalErrorTab();
     13  let portalTab = await openCaptivePortalLoginTab(errorTab);
     14 
     15  // Release the reference held to the portal tab by sending success/abort events.
     16  Services.obs.notifyObservers(null, evt);
     17  await TestUtils.waitForCondition(
     18    () => CPS.state == currState,
     19    "Captive portal has been released"
     20  );
     21  gBrowser.removeTab(errorTab);
     22 
     23  await portalDetected();
     24  Assert.equal(CPS.state, CPS.LOCKED_PORTAL, "Captive portal is locked again");
     25  errorTab = await openCaptivePortalErrorTab();
     26  let portalTab2 = await openCaptivePortalLoginTab(errorTab);
     27  Assert.notEqual(
     28    portalTab,
     29    portalTab2,
     30    "waitForNewTab in openCaptivePortalLoginTab should not have completed at this point if references were held to the old captive portal tab after login/abort."
     31  );
     32  gBrowser.removeTab(portalTab);
     33  gBrowser.removeTab(portalTab2);
     34 
     35  let errorTabReloaded = BrowserTestUtils.waitForErrorPage(
     36    errorTab.linkedBrowser
     37  );
     38  Services.obs.notifyObservers(null, "captive-portal-login-success");
     39  await errorTabReloaded;
     40 
     41  gBrowser.removeTab(errorTab);
     42 }
     43 
     44 add_setup(async function () {
     45  await SpecialPowers.pushPrefEnv({
     46    set: [
     47      ["captivedetect.canonicalURL", CANONICAL_URL],
     48      ["captivedetect.canonicalContent", CANONICAL_CONTENT],
     49    ],
     50  });
     51 });
     52 
     53 let capPortalStates = [
     54  {
     55    evt: "captive-portal-login-success",
     56    state: CPS.UNLOCKED_PORTAL,
     57  },
     58  {
     59    evt: "captive-portal-login-abort",
     60    state: CPS.UNKNOWN,
     61  },
     62 ];
     63 
     64 for (let elem of capPortalStates) {
     65  add_task(checkCaptivePortalTabReference.bind(null, elem.evt, elem.state));
     66 }