diff --git a/browser/modules/UITour.jsm b/browser/modules/UITour.jsm index ee8e931add1e..df7cd4b90cc6 100644 --- a/browser/modules/UITour.jsm +++ b/browser/modules/UITour.jsm @@ -235,6 +235,15 @@ this.UITour = { this.endUrlbarCapture(window); break; } + + case "getConfiguration": { + if (typeof data.configuration != "string") { + return false; + } + + this.getConfiguration(contentDocument, data.configuration, data.callbackID); + break; + } } let tab = window.gBrowser._getTabForContentWindow(contentDocument.defaultView); @@ -732,6 +741,21 @@ this.UITour = { }); aWindow.gBrowser.selectedTab = tab; }, + + getConfiguration: function(aContentDocument, aConfiguration, aCallbackId) { + let config = null; + switch (aConfiguration) { + case "sync": + config = { + setup: Services.prefs.prefHasUserValue("services.sync.username"), + }; + break; + default: + Cu.reportError("getConfiguration: Unknown configuration requested: " + aConfiguration); + break; + } + this.sendPageCallback(aContentDocument, aCallbackId, config); + }, }; function _isElementVisible(aElement) { diff --git a/browser/modules/test/browser.ini b/browser/modules/test/browser.ini index 974821c6ba4d..d3b96583567d 100644 --- a/browser/modules/test/browser.ini +++ b/browser/modules/test/browser.ini @@ -10,5 +10,6 @@ support-files = skip-if = os == "linux" # Intermittent failures, bug 951965 [browser_UITour2.js] [browser_UITour3.js] +[browser_UITour_sync.js] [browser_taskbar_preview.js] run-if = os == "win" diff --git a/browser/modules/test/browser_UITour_sync.js b/browser/modules/test/browser_UITour_sync.js new file mode 100644 index 000000000000..c022b873663d --- /dev/null +++ b/browser/modules/test/browser_UITour_sync.js @@ -0,0 +1,102 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let gTestTab; +let gContentAPI; +let gContentWindow; + +Components.utils.import("resource:///modules/UITour.jsm"); + +function loadTestPage(callback, host = "https://example.com/") { + if (gTestTab) + gBrowser.removeTab(gTestTab); + + let url = getRootDirectory(gTestPath) + "uitour.html"; + 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); + + gContentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView); + gContentAPI = gContentWindow.Mozilla.UITour; + + waitForFocus(callback, gContentWindow); + }, 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.gContentWindow; + delete window.gContentAPI; + if (gTestTab) + gBrowser.removeTab(gTestTab); + delete window.gTestTab; + Services.prefs.clearUserPref("browser.uitour.enabled", true); + Services.prefs.clearUserPref("services.sync.username"); + Services.perms.remove("example.com", "uitour"); + }); + + function done() { + executeSoon(() => { + if (gTestTab) + gBrowser.removeTab(gTestTab); + gTestTab = null; + + let highlight = document.getElementById("UITourHighlightContainer"); + is_element_hidden(highlight, "Highlight should be closed/hidden after UITour tab is closed"); + + let tooltip = document.getElementById("UITourTooltip"); + is_element_hidden(tooltip, "Tooltip should be closed/hidden after UITour tab is closed"); + + is(UITour.pinnedTabs.get(window), null, "Any pinned tab should be closed after UITour tab is closed"); + + executeSoon(nextTest); + }); + } + + function nextTest() { + if (tests.length == 0) { + finish(); + return; + } + let test = tests.shift(); + info("Starting " + test.name); + loadTestPage(function() { + test(done); + }); + } + nextTest(); +} + +let tests = [ + function test_checkSyncSetup_disabled(done) { + function callback(result) { + is(result.setup, false, "Sync shouldn't be setup by default"); + done(); + } + + gContentAPI.getSyncConfiguration(callback); + }, + + function test_checkSyncSetup_enabled(done) { + function callback(result) { + is(result.setup, true, "Sync should be setup"); + done(); + } + + Services.prefs.setCharPref("services.sync.username", "uitour@tests.mozilla.org"); + gContentAPI.getSyncConfiguration(callback); + }, +]; diff --git a/browser/modules/test/uitour.js b/browser/modules/test/uitour.js index 4c861ae75431..0b10d00f5f56 100644 --- a/browser/modules/test/uitour.js +++ b/browser/modules/test/uitour.js @@ -152,4 +152,11 @@ if (typeof Mozilla == 'undefined') { name: name }); }; + + Mozilla.UITour.getSyncConfiguration = function(callback) { + _sendEvent('getConfiguration', { + callbackID: _waitForCallback(callback), + configuration: "sync", + }); + }; })();