Bug 989197 - Add tests for alternate cert error UI when behind a captive portal. r=Gijs
authorNihanth Subramanya <nhnt11@gmail.com>
Tue, 29 Nov 2016 15:39:14 -0800
changeset 448575 c13180ad5ce6dbad2feb7f736db8b8c2b92e7e5f
parent 448574 cb2996e6170978047df36274a65ba0454ebc9e8f
child 448577 64a6f4f15808969321adbe575cb56d999439dca0
child 448578 befac89673c1f0f57743a00257e7dba1855c2d01
child 448622 1627dd9be98db223c0445740e6a0e5fd52dcd35b
push id38361
push usernhnt11@gmail.com
push dateSat, 10 Dec 2016 21:36:44 +0000
reviewersGijs
bugs989197
milestone53.0a1
Bug 989197 - Add tests for alternate cert error UI when behind a captive portal. r=Gijs MozReview-Commit-ID: EZuHGrmHx7d
browser/base/content/test/captivePortal/browser.ini
browser/base/content/test/captivePortal/browser_captivePortal_certErrorUI.js
browser/base/content/test/captivePortal/head.js
browser/base/moz.build
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/captivePortal/browser.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+support-files =
+  head.js
+
+[browser_captivePortal_certErrorUI.js]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/captivePortal/browser_captivePortal_certErrorUI.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const BAD_CERT_PAGE = "https://expired.example.com/";
+
+const CANONICAL_CONTENT = "success";
+const CANONICAL_URL = "data:text/plain;charset=utf-8," + CANONICAL_CONTENT;
+
+// This tests the alternate cert error UI when we are behind a captive portal.
+
+add_task(function* checkCaptivePortalCertErrorUI() {
+  yield SpecialPowers.pushPrefEnv({
+    set: [["captivedetect.canonicalURL", CANONICAL_URL],
+          ["captivedetect.canonicalContent", CANONICAL_CONTENT]],
+  });
+
+  let captivePortalStatePropagated = TestUtils.topicObserved("ipc:network:captive-portal-set-state");
+
+  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 propagated to the content process.");
+  yield captivePortalStatePropagated;
+
+  // Open a page with a cert error.
+  let browser;
+  let certErrorLoaded;
+  let errorTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, () => {
+    let tab = gBrowser.addTab(BAD_CERT_PAGE);
+    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.");
+
+  let portalTabRemoved = BrowserTestUtils.removeTab(portalTab, {dontRemove: true});
+  let errorTabReloaded = waitForCertErrorLoad(browser);
+
+  Services.obs.notifyObservers(null, "captive-portal-login-success", null);
+  yield portalTabRemoved;
+
+  info("Waiting for error tab to be reloaded after the captive portal was freed.");
+  yield errorTabReloaded;
+  yield ContentTask.spawn(browser, null, () => {
+    let doc = content.document;
+    ok(!doc.body.classList.contains("captiveportal"),
+       "Captive portal error page UI is not visible.");
+  });
+
+  yield BrowserTestUtils.removeTab(errorTab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/captivePortal/head.js
@@ -0,0 +1,9 @@
+function waitForCertErrorLoad(browser) {
+  return new Promise(resolve => {
+    info("Waiting for DOMContentLoaded event");
+    browser.addEventListener("DOMContentLoaded", function load() {
+      browser.removeEventListener("DOMContentLoaded", load, false, true);
+      resolve();
+    }, false, true);
+  });
+}
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -11,16 +11,17 @@ MOCHITEST_MANIFESTS += [
 ]
 
 MOCHITEST_CHROME_MANIFESTS += [
     'content/test/chrome/chrome.ini',
 ]
 
 BROWSER_CHROME_MANIFESTS += [
     'content/test/alerts/browser.ini',
+    'content/test/captivePortal/browser.ini',
     'content/test/general/browser.ini',
     'content/test/newtab/browser.ini',
     'content/test/plugins/browser.ini',
     'content/test/popupNotifications/browser.ini',
     'content/test/referrer/browser.ini',
     'content/test/social/browser.ini',
     'content/test/tabcrashed/browser.ini',
     'content/test/tabPrompts/browser.ini',