Bug 933023 - UITour: Add preference to disable HTTPS check for testing/development. r=MattN
authorBlair McBride <bmcbride@mozilla.com>
Tue, 05 Nov 2013 15:23:25 +1300
changeset 153588 cf627f856f180d66924efb1c1e06e281370224d9
parent 153531 f0ccd1e58b7f870050c192ad6e3911d4b5e021db
child 153589 a0d5fe789379bcbed75fefbe26b722b25bd0c945
push id25595
push userryanvm@gmail.com
push dateTue, 05 Nov 2013 20:19:27 +0000
treeherdermozilla-central@2ada3a06d5e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs933023
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 933023 - UITour: Add preference to disable HTTPS check for testing/development. r=MattN
browser/app/profile/firefox.js
browser/modules/UITour.jsm
browser/modules/test/browser_UITour.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -239,16 +239,17 @@ pref("extensions.{972ce4c6-7e08-4474-a28
 
 pref("xpinstall.whitelist.add", "addons.mozilla.org");
 pref("xpinstall.whitelist.add.180", "marketplace.firefox.com");
 
 pref("lightweightThemes.update.enabled", true);
 
 // UI tour experience.
 pref("browser.uitour.enabled", true);
+pref("browser.uitour.requireSecure", true);
 pref("browser.uitour.themeOrigin", "https://addons.mozilla.org/%LOCALE%/firefox/themes/");
 pref("browser.uitour.pinnedTabUrl", "https://support.mozilla.org/%LOCALE%/kb/pinned-tabs-keep-favorite-websites-open");
 pref("browser.uitour.whitelist.add.260", "www.mozilla.org,support.mozilla.org");
 
 pref("keyword.enabled", true);
 
 pref("general.useragent.locale", "@AB_CD@");
 pref("general.skins.selectedSkin", "classic/1.0");
--- a/browser/modules/UITour.jsm
+++ b/browser/modules/UITour.jsm
@@ -250,17 +250,21 @@ this.UITour = {
     if (aDocument.defaultView.top != aDocument.defaultView)
       return false;
 
     let uri = aDocument.documentURIObject;
 
     if (uri.schemeIs("chrome"))
       return true;
 
-    if (!uri.schemeIs("https"))
+    let allowedSchemes = new Set(["https"]);
+    if (!Services.prefs.getBoolPref("browser.uitour.requireSecure"))
+      allowedSchemes.add("http");
+
+    if (!allowedSchemes.has(uri.scheme))
       return false;
 
     this.importPermissions();
     let permission = Services.perms.testPermission(uri, UITOUR_PERMISSION);
     return permission == Services.perms.ALLOW_ACTION;
   },
 
   getTarget: function(aWindow, aTargetName, aSticky = false) {
--- a/browser/modules/test/browser_UITour.js
+++ b/browser/modules/test/browser_UITour.js
@@ -27,49 +27,51 @@ function is_element_visible(element, msg
   ok(!is_hidden(element), msg);
 }
 
 function is_element_hidden(element, msg) {
   isnot(element, null, "Element should not be null, when checking visibility");
   ok(is_hidden(element), msg);
 }
 
-function loadTestPage(callback, untrustedHost = false) {
+function loadTestPage(callback, host = "https://example.com/") {
    if (gTestTab)
     gBrowser.removeTab(gTestTab);
 
   let url = getRootDirectory(gTestPath) + "uitour.html";
-  if (untrustedHost)
-    url = url.replace("chrome://mochitests/content/", "http://example.com/");
+  url = url.replace("chrome://mochitests/content/", host);
 
   gTestTab = gBrowser.addTab(url);
   gBrowser.selectedTab = gTestTab;
 
   gTestTab.linkedBrowser.addEventListener("load", function onLoad() {
     gTestTab.linkedBrowser.removeEventListener("load", onLoad);
 
     let contentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView);
     gContentAPI = contentWindow.Mozilla.UITour;
 
     waitForFocus(callback, contentWindow);
   }, true);
 }
 
 function test() {
   Services.prefs.setBoolPref("browser.uitour.enabled", true);
+  let testUri = Services.io.newURI("http://example.com", null, null);
+  Services.perms.add(testUri, "uitour", Services.perms.ALLOW_ACTION);
 
   waitForExplicitFinish();
 
   registerCleanupFunction(function() {
     delete window.UITour;
     delete window.gContentAPI;
     if (gTestTab)
       gBrowser.removeTab(gTestTab);
     delete window.gTestTab;
     Services.prefs.clearUserPref("browser.uitour.enabled", true);
+    Services.perms.remove("example.com", "uitour");
   });
 
   function done() {
     if (gTestTab)
       gBrowser.removeTab(gTestTab);
     gTestTab = null;
 
     let highlight = document.getElementById("UITourHighlight");
@@ -93,39 +95,63 @@ function test() {
     loadTestPage(function() {
       test(done);
     });
   }
   nextTest();
 }
 
 let tests = [
+  function test_untrusted_host(done) {
+    loadTestPage(function() {
+      let highlight = document.getElementById("UITourHighlight");
+      is_element_hidden(highlight, "Highlight should initially be hidden");
+
+      gContentAPI.showHighlight("urlbar");
+      is_element_hidden(highlight, "Highlight should not be shown on a untrusted host");
+
+      done();
+    }, "http://mochi.test:8888/");
+  },
+  function test_unsecure_host(done) {
+    loadTestPage(function() {
+      let highlight = document.getElementById("UITourHighlight");
+      is_element_hidden(highlight, "Highlight should initially be hidden");
+
+      gContentAPI.showHighlight("urlbar");
+      is_element_hidden(highlight, "Highlight should not be shown on a unsecure host");
+
+      done();
+    }, "http://example.com/");
+  },
+  function test_unsecure_host_override(done) {
+    Services.prefs.setBoolPref("browser.uitour.requireSecure", false);
+    loadTestPage(function() {
+      let highlight = document.getElementById("UITourHighlight");
+      is_element_hidden(highlight, "Highlight should initially be hidden");
+
+      gContentAPI.showHighlight("urlbar");
+      is_element_visible(highlight, "Highlight should be shown on a unsecure host when override pref is set");
+
+      Services.prefs.setBoolPref("browser.uitour.requireSecure", true);
+      done();
+    }, "http://example.com/");
+  },
   function test_disabled(done) {
     Services.prefs.setBoolPref("browser.uitour.enabled", false);
 
     let highlight = document.getElementById("UITourHighlight");
     is_element_hidden(highlight, "Highlight should initially be hidden");
 
     gContentAPI.showHighlight("urlbar");
     is_element_hidden(highlight, "Highlight should not be shown when feature is disabled");
 
     Services.prefs.setBoolPref("browser.uitour.enabled", true);
     done();
   },
-  function test_untrusted_host(done) {
-    loadTestPage(function() {
-      let highlight = document.getElementById("UITourHighlight");
-      is_element_hidden(highlight, "Highlight should initially be hidden");
-
-      gContentAPI.showHighlight("urlbar");
-      is_element_hidden(highlight, "Highlight should not be shown on a untrusted domain");
-
-      done();
-    }, true);
-  },
   function test_highlight(done) {
     let highlight = document.getElementById("UITourHighlight");
     is_element_hidden(highlight, "Highlight should initially be hidden");
 
     gContentAPI.showHighlight("urlbar");
     is_element_visible(highlight, "Highlight should be shown after showHighlight()");
 
     gContentAPI.hideHighlight();