michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/"; michael@0: michael@0: var tempScope = {}; michael@0: Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope); michael@0: var LightweightThemeManager = tempScope.LightweightThemeManager; michael@0: michael@0: function wait_for_notification(aCallback) { michael@0: PopupNotifications.panel.addEventListener("popupshown", function() { michael@0: PopupNotifications.panel.removeEventListener("popupshown", arguments.callee, false); michael@0: aCallback(PopupNotifications.panel); michael@0: }, false); michael@0: } michael@0: michael@0: var TESTS = [ michael@0: function test_install_lwtheme() { michael@0: is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected"); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/bug592338.html"); michael@0: gBrowser.selectedBrowser.addEventListener("pageshow", function() { michael@0: if (gBrowser.contentDocument.location.href == "about:blank") michael@0: return; michael@0: michael@0: gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false); michael@0: michael@0: executeSoon(function() { michael@0: var link = gBrowser.contentDocument.getElementById("theme-install"); michael@0: EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow); michael@0: michael@0: is(LightweightThemeManager.currentTheme.id, "test", "Should have installed the test theme"); michael@0: michael@0: LightweightThemeManager.currentTheme = null; michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: michael@0: runNextTest(); michael@0: }); michael@0: }, false); michael@0: }, michael@0: michael@0: function test_lwtheme_switch_theme() { michael@0: is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected"); michael@0: michael@0: AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { michael@0: aAddon.userDisabled = false; michael@0: ok(aAddon.isActive, "Theme should have immediately enabled"); michael@0: Services.prefs.setBoolPref("extensions.dss.enabled", false); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/bug592338.html"); michael@0: gBrowser.selectedBrowser.addEventListener("pageshow", function() { michael@0: if (gBrowser.contentDocument.location.href == "about:blank") michael@0: return; michael@0: michael@0: gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false); michael@0: michael@0: executeSoon(function() { michael@0: var link = gBrowser.contentDocument.getElementById("theme-install"); michael@0: wait_for_notification(function(aPanel) { michael@0: is(LightweightThemeManager.currentTheme, null, "Should not have installed the test lwtheme"); michael@0: ok(aAddon.isActive, "Test theme should still be active"); michael@0: michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.button.label, "Restart Now", "Should have seen the right button"); michael@0: michael@0: ok(aAddon.userDisabled, "Should be waiting to disable the test theme"); michael@0: aAddon.userDisabled = false; michael@0: Services.prefs.setBoolPref("extensions.dss.enabled", true); michael@0: michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: michael@0: runNextTest(); michael@0: }); michael@0: EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow); michael@0: }); michael@0: }, false); michael@0: }); michael@0: } michael@0: ]; michael@0: michael@0: function runNextTest() { michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 0, "Should be no active installs"); michael@0: michael@0: if (TESTS.length == 0) { michael@0: AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { michael@0: aAddon.uninstall(); michael@0: michael@0: Services.prefs.setBoolPref("extensions.logging.enabled", false); michael@0: Services.prefs.setBoolPref("extensions.dss.enabled", false); michael@0: michael@0: finish(); michael@0: }); michael@0: return; michael@0: } michael@0: michael@0: info("Running " + TESTS[0].name); michael@0: TESTS.shift()(); michael@0: }); michael@0: }; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: Services.prefs.setBoolPref("extensions.logging.enabled", true); michael@0: michael@0: AddonManager.getInstallForURL(TESTROOT + "theme.xpi", function(aInstall) { michael@0: aInstall.addListener({ michael@0: onInstallEnded: function(aInstall, aAddon) { michael@0: AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { michael@0: isnot(aAddon, null, "Should have installed the test theme."); michael@0: michael@0: // In order to switch themes while the test is running we turn on dynamic michael@0: // theme switching. This means the test isn't exactly correct but should michael@0: // do some good michael@0: Services.prefs.setBoolPref("extensions.dss.enabled", true); michael@0: michael@0: runNextTest(); michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: aInstall.install(); michael@0: }, "application/x-xpinstall"); michael@0: }