Bug 1081772 - Add back a way to test UITour on origins not whitelisted by default. r=Unfocused
--- a/browser/modules/UITour.jsm
+++ b/browser/modules/UITour.jsm
@@ -21,16 +21,17 @@ XPCOMUtils.defineLazyModuleGetter(this,
"resource:///modules/CustomizableUI.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry",
"resource://gre/modules/UITelemetry.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITelemetry",
"resource:///modules/BrowserUITelemetry.jsm");
const UITOUR_PERMISSION = "uitour";
+const PREF_TEST_WHITELIST = "browser.uitour.testingOrigins";
const PREF_SEENPAGEIDS = "browser.uitour.seenPageIDs";
const MAX_BUTTONS = 4;
const BUCKET_NAME = "UITour";
const BUCKET_TIMESTEPS = [
1 * 60 * 1000, // Until 1 minute after tab is closed/inactive.
3 * 60 * 1000, // Until 3 minutes after tab is closed/inactive.
10 * 60 * 1000, // Until 10 minutes after tab is closed/inactive.
@@ -615,30 +616,52 @@ this.UITour = {
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.wrappedJSObject;
},
+ isTestingOrigin: function(aURI) {
+ if (Services.prefs.getPrefType(PREF_TEST_WHITELIST) != Services.prefs.PREF_STRING) {
+ return false;
+ }
+
+ // Add any testing origins (comma-seperated) to the whitelist for the session.
+ for (let origin of Services.prefs.getCharPref(PREF_TEST_WHITELIST).split(",")) {
+ try {
+ let testingURI = Services.io.newURI(origin, null, null);
+ if (aURI.prePath == testingURI.prePath) {
+ return true;
+ }
+ } catch (ex) {
+ Cu.reportError(ex);
+ }
+ }
+ return false;
+ },
+
ensureTrustedOrigin: function(aDocument) {
if (aDocument.defaultView.top != aDocument.defaultView)
return false;
let uri = aDocument.documentURIObject;
if (uri.schemeIs("chrome"))
return true;
if (!this.isSafeScheme(uri))
return false;
let permission = Services.perms.testPermission(uri, UITOUR_PERMISSION);
- return permission == Services.perms.ALLOW_ACTION;
+ if (permission == Services.perms.ALLOW_ACTION)
+ return true;
+
+ return this.isTestingOrigin(uri);
},
isSafeScheme: function(aURI) {
let allowedSchemes = new Set(["https", "about"]);
if (!Services.prefs.getBoolPref("browser.uitour.requireSecure"))
allowedSchemes.add("http");
if (!allowedSchemes.has(aURI.scheme))
--- a/browser/modules/test/browser_UITour.js
+++ b/browser/modules/test/browser_UITour.js
@@ -20,16 +20,33 @@ let tests = [
ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed");
gContentAPI.showMenu("bookmarks");
ise(bookmarksMenu.open, false, "Bookmark menu should not open on a untrusted host");
done();
}, "http://mochi.test:8888/");
},
+ function test_testing_host(done) {
+ // Add two testing origins intentionally surrounded by whitespace to be ignored.
+ Services.prefs.setCharPref("browser.uitour.testingOrigins",
+ "https://test1.example.com, https://test2.example.com:443 ");
+
+ registerCleanupFunction(() => {
+ Services.prefs.clearUserPref("browser.uitour.testingOrigins");
+ });
+ function callback(result) {
+ ok(result, "Callback should be called on a testing origin");
+ done();
+ }
+
+ loadUITourTestPage(function() {
+ gContentAPI.getConfiguration("appinfo", callback);
+ }, "https://test2.example.com/");
+ },
function test_unsecure_host(done) {
loadUITourTestPage(function() {
let bookmarksMenu = document.getElementById("bookmarks-menu-button");
ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed");
gContentAPI.showMenu("bookmarks");
ise(bookmarksMenu.open, false, "Bookmark menu should not open on a unsecure host");