Bug 989197 - Add tests for alternate cert error UI when behind a captive portal. r=Gijs draft
authorNihanth Subramanya <nhnt11@gmail.com>
Tue, 29 Nov 2016 15:39:14 -0800
changeset 445688 30035465d15e5491684e5be85f0cd2abeab6449f
parent 445687 e3485534505150471c5ebeb6f0387c6e9267f193
child 538589 ed8b8e38dbfa5d328de868133de0ccc528f2daf1
push id37584
push usernhnt11@gmail.com
push dateWed, 30 Nov 2016 03:34:50 +0000
reviewersGijs
bugs989197
milestone53.0a1
Bug 989197 - Add tests for alternate cert error UI when behind a captive portal. r=Gijs MozReview-Commit-ID: HvXSFJW9bhT
browser/base/content/test/general/browser_aboutCertError.js
--- a/browser/base/content/test/general/browser_aboutCertError.js
+++ b/browser/base/content/test/general/browser_aboutCertError.js
@@ -7,16 +7,73 @@
 
 const GOOD_PAGE = "https://example.com/";
 const BAD_CERT = "https://expired.example.com/";
 const UNKNOWN_ISSUER = "https://self-signed.example.com ";
 const BAD_STS_CERT = "https://badchain.include-subdomains.pinning.example.com:443";
 const {TabStateFlusher} = Cu.import("resource:///modules/sessionstore/TabStateFlusher.jsm", {});
 const ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
 
+const CANONICAL_CONTENT = "success";
+const CANONICAL_URL = "data:text/plain;charset=utf-8," + CANONICAL_CONTENT;
+
+add_task(function* setup() {
+  yield SpecialPowers.pushPrefEnv({
+    set: [["captivedetect.canonicalURL", CANONICAL_URL],
+          ["captivedetect.canonicalContent", CANONICAL_CONTENT]],
+  });
+});
+
+add_task(function* checkCaptivePortalUI() {
+  info("Checking that the alternate about:certerror UI is shown when we are behind a captive portal.");
+  Services.obs.notifyObservers(null, "captive-portal-login", null);
+
+  info("Waiting for captive portal state to be correct in the content process.");
+  yield BrowserTestUtils.waitForCondition(function*() {
+    return ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+      let cps = Components.classes["@mozilla.org/network/captive-portal-service;1"]
+                          .getService(Components.interfaces.nsICaptivePortalService);
+      return cps.state == cps.LOCKED_PORTAL;
+    });
+  });
+
+  // Open a page with a cert error.
+  let browser;
+  let certErrorLoaded;
+  let errorTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, () => {
+    let tab = gBrowser.addTab(UNKNOWN_ISSUER);
+    gBrowser.selectedTab = tab;
+    browser = gBrowser.selectedBrowser;
+    certErrorLoaded = waitForCertErrorLoad(browser);
+    return tab;
+  }, false);
+
+  info("Waiting for cert error page to load.")
+  yield certErrorLoaded;
+
+  let portalTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, CANONICAL_URL);
+
+  yield ContentTask.spawn(browser, null, () => {
+    let doc = content.document;
+    ok(doc.body.classList.contains("captiveportal"),
+       "Captive portal error page UI is visible.");
+
+    info("Clicking the Open Login Page button.");
+    doc.getElementById("openPortalLoginPageButton").click();
+  });
+
+  let portalTab = yield portalTabPromise;
+  is(gBrowser.selectedTab, portalTab, "Login page should be open in a new foreground tab.");
+
+  // Clean up.
+  gBrowser.removeTab(portalTab);
+  gBrowser.removeTab(errorTab);
+  Services.obs.notifyObservers(null, "captive-portal-login-abort", null);
+});
+
 add_task(function* checkReturnToAboutHome() {
   info("Loading a bad cert page directly and making sure 'return to previous page' goes to about:home");
   let browser;
   let certErrorLoaded;
   let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, () => {
     gBrowser.selectedTab = gBrowser.addTab(BAD_CERT);
     browser = gBrowser.selectedBrowser;
     certErrorLoaded = waitForCertErrorLoad(browser);