Commit b53d383b authored by Nihanth Subramanya's avatar Nihanth Subramanya
Browse files

Bug 1743148 - Call ensureCaptivePortalTab() directly from NetErrorParent...

Bug 1743148 - Call ensureCaptivePortalTab() directly from NetErrorParent instead of firing an obs notification. r=lyavor,valentin

Differential Revision: https://phabricator.services.mozilla.com/D132254
parent 55e73f4b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -276,7 +276,7 @@ class NetErrorParent extends JSWindowActorParent {
        this.browser.reload();
        break;
      case "Browser:OpenCaptivePortalPage":
        Services.obs.notifyObservers(null, "ensure-captive-portal-tab");
        this.browser.ownerGlobal.CaptivePortalWatcher.ensureCaptivePortalTab();
        break;
      case "Browser:PrimeMitm":
        this.primeMitm(this.browser);
+0 −5
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ var CaptivePortalWatcher = {
  },

  init() {
    Services.obs.addObserver(this, "ensure-captive-portal-tab");
    Services.obs.addObserver(this, "captive-portal-login");
    Services.obs.addObserver(this, "captive-portal-login-abort");
    Services.obs.addObserver(this, "captive-portal-login-success");
@@ -79,7 +78,6 @@ var CaptivePortalWatcher = {
  },

  uninit() {
    Services.obs.removeObserver(this, "ensure-captive-portal-tab");
    Services.obs.removeObserver(this, "captive-portal-login");
    Services.obs.removeObserver(this, "captive-portal-login-abort");
    Services.obs.removeObserver(this, "captive-portal-login-success");
@@ -96,9 +94,6 @@ var CaptivePortalWatcher = {

  observe(aSubject, aTopic, aData) {
    switch (aTopic) {
      case "ensure-captive-portal-tab":
        this.ensureCaptivePortalTab();
        break;
      case "captive-portal-login":
        this._captivePortalDetected();
        break;
+8 −2
Original line number Diff line number Diff line
@@ -28,10 +28,16 @@ async function checkCaptivePortalTabReference(evt, currState) {
    portalTab != portalTab2,
    "waitForNewTab in openCaptivePortalLoginTab should not have completed at this point if references were held to the old captive portal tab after login/abort."
  );

  gBrowser.removeTab(errorTab);
  gBrowser.removeTab(portalTab);
  gBrowser.removeTab(portalTab2);

  let errorTabReloaded = BrowserTestUtils.waitForErrorPage(
    errorTab.linkedBrowser
  );
  Services.obs.notifyObservers(null, "captive-portal-login-success");
  await errorTabReloaded;

  gBrowser.removeTab(errorTab);
}

add_task(async function setup() {
+22 −0
Original line number Diff line number Diff line
@@ -18,7 +18,17 @@ add_task(async function checkCaptivePortalCertErrorUI() {
    "Checking that the alternate cert error UI is shown when we are behind a captive portal"
  );

  // Open a second window in the background. Later, we'll check that
  // when we click the button to open the captive portal tab, the tab
  // only opens in the active window and not in the background one.
  let secondWindow = await openWindowAndWaitForFocus();
  await SimpleTest.promiseFocus(window);

  await portalDetected();

  // Check that we didn't open anything in the background window.
  ensureNoPortalTab(secondWindow);

  let tab = await openCaptivePortalErrorTab();
  let browser = tab.linkedBrowser;
  let portalTabPromise = BrowserTestUtils.waitForNewTab(
@@ -50,6 +60,9 @@ add_task(async function checkCaptivePortalCertErrorUI() {
    "Login page should be open in a new foreground tab."
  );

  // Check that we didn't open anything in the background window.
  ensureNoPortalTab(secondWindow);

  // Make sure clicking the "Open Login Page" button again focuses the existing portal tab.
  await BrowserTestUtils.switchTab(gBrowser, tab);
  // Passing an empty function to BrowserTestUtils.switchTab lets us wait for an arbitrary
@@ -67,6 +80,9 @@ add_task(async function checkCaptivePortalCertErrorUI() {
  let portalTab2 = await portalTabPromise;
  is(portalTab2, portalTab, "The existing portal tab should be focused.");

  // Check that we didn't open anything in the background window.
  ensureNoPortalTab(secondWindow);

  let portalTabClosing = BrowserTestUtils.waitForTabClosing(portalTab);
  let errorTabReloaded = BrowserTestUtils.waitForErrorPage(browser);

@@ -86,6 +102,7 @@ add_task(async function checkCaptivePortalCertErrorUI() {
  });

  await BrowserTestUtils.removeTab(tab);
  await BrowserTestUtils.closeWindow(secondWindow);
});

add_task(async function testCaptivePortalAdvancedPanel() {
@@ -142,5 +159,10 @@ add_task(async function testCaptivePortalAdvancedPanel() {
    "@mozilla.org/security/certoverride;1"
  ].getService(Ci.nsICertOverrideService);
  certOverrideService.clearValidityOverride("expired.example.com", -1, {});

  let errorTabReloaded = BrowserTestUtils.waitForErrorPage(browser);
  Services.obs.notifyObservers(null, "captive-portal-login-success");
  await errorTabReloaded;

  await BrowserTestUtils.removeTab(tab);
});