Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/"; |
michael@0 | 6 | |
michael@0 | 7 | var tempScope = {}; |
michael@0 | 8 | Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope); |
michael@0 | 9 | var LightweightThemeManager = tempScope.LightweightThemeManager; |
michael@0 | 10 | |
michael@0 | 11 | function wait_for_notification(aCallback) { |
michael@0 | 12 | PopupNotifications.panel.addEventListener("popupshown", function() { |
michael@0 | 13 | PopupNotifications.panel.removeEventListener("popupshown", arguments.callee, false); |
michael@0 | 14 | aCallback(PopupNotifications.panel); |
michael@0 | 15 | }, false); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | var TESTS = [ |
michael@0 | 19 | function test_install_lwtheme() { |
michael@0 | 20 | is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected"); |
michael@0 | 21 | |
michael@0 | 22 | var pm = Services.perms; |
michael@0 | 23 | pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
michael@0 | 24 | |
michael@0 | 25 | gBrowser.selectedTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/bug592338.html"); |
michael@0 | 26 | gBrowser.selectedBrowser.addEventListener("pageshow", function() { |
michael@0 | 27 | if (gBrowser.contentDocument.location.href == "about:blank") |
michael@0 | 28 | return; |
michael@0 | 29 | |
michael@0 | 30 | gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false); |
michael@0 | 31 | |
michael@0 | 32 | executeSoon(function() { |
michael@0 | 33 | var link = gBrowser.contentDocument.getElementById("theme-install"); |
michael@0 | 34 | EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow); |
michael@0 | 35 | |
michael@0 | 36 | is(LightweightThemeManager.currentTheme.id, "test", "Should have installed the test theme"); |
michael@0 | 37 | |
michael@0 | 38 | LightweightThemeManager.currentTheme = null; |
michael@0 | 39 | gBrowser.removeTab(gBrowser.selectedTab); |
michael@0 | 40 | |
michael@0 | 41 | Services.perms.remove("example.com", "install"); |
michael@0 | 42 | |
michael@0 | 43 | runNextTest(); |
michael@0 | 44 | }); |
michael@0 | 45 | }, false); |
michael@0 | 46 | }, |
michael@0 | 47 | |
michael@0 | 48 | function test_lwtheme_switch_theme() { |
michael@0 | 49 | is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected"); |
michael@0 | 50 | |
michael@0 | 51 | AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { |
michael@0 | 52 | aAddon.userDisabled = false; |
michael@0 | 53 | ok(aAddon.isActive, "Theme should have immediately enabled"); |
michael@0 | 54 | Services.prefs.setBoolPref("extensions.dss.enabled", false); |
michael@0 | 55 | |
michael@0 | 56 | var pm = Services.perms; |
michael@0 | 57 | pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
michael@0 | 58 | |
michael@0 | 59 | gBrowser.selectedTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/bug592338.html"); |
michael@0 | 60 | gBrowser.selectedBrowser.addEventListener("pageshow", function() { |
michael@0 | 61 | if (gBrowser.contentDocument.location.href == "about:blank") |
michael@0 | 62 | return; |
michael@0 | 63 | |
michael@0 | 64 | gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false); |
michael@0 | 65 | |
michael@0 | 66 | executeSoon(function() { |
michael@0 | 67 | var link = gBrowser.contentDocument.getElementById("theme-install"); |
michael@0 | 68 | wait_for_notification(function(aPanel) { |
michael@0 | 69 | is(LightweightThemeManager.currentTheme, null, "Should not have installed the test lwtheme"); |
michael@0 | 70 | ok(aAddon.isActive, "Test theme should still be active"); |
michael@0 | 71 | |
michael@0 | 72 | let notification = aPanel.childNodes[0]; |
michael@0 | 73 | is(notification.button.label, "Restart Now", "Should have seen the right button"); |
michael@0 | 74 | |
michael@0 | 75 | ok(aAddon.userDisabled, "Should be waiting to disable the test theme"); |
michael@0 | 76 | aAddon.userDisabled = false; |
michael@0 | 77 | Services.prefs.setBoolPref("extensions.dss.enabled", true); |
michael@0 | 78 | |
michael@0 | 79 | gBrowser.removeTab(gBrowser.selectedTab); |
michael@0 | 80 | |
michael@0 | 81 | Services.perms.remove("example.com", "install"); |
michael@0 | 82 | |
michael@0 | 83 | runNextTest(); |
michael@0 | 84 | }); |
michael@0 | 85 | EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow); |
michael@0 | 86 | }); |
michael@0 | 87 | }, false); |
michael@0 | 88 | }); |
michael@0 | 89 | } |
michael@0 | 90 | ]; |
michael@0 | 91 | |
michael@0 | 92 | function runNextTest() { |
michael@0 | 93 | AddonManager.getAllInstalls(function(aInstalls) { |
michael@0 | 94 | is(aInstalls.length, 0, "Should be no active installs"); |
michael@0 | 95 | |
michael@0 | 96 | if (TESTS.length == 0) { |
michael@0 | 97 | AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { |
michael@0 | 98 | aAddon.uninstall(); |
michael@0 | 99 | |
michael@0 | 100 | Services.prefs.setBoolPref("extensions.logging.enabled", false); |
michael@0 | 101 | Services.prefs.setBoolPref("extensions.dss.enabled", false); |
michael@0 | 102 | |
michael@0 | 103 | finish(); |
michael@0 | 104 | }); |
michael@0 | 105 | return; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | info("Running " + TESTS[0].name); |
michael@0 | 109 | TESTS.shift()(); |
michael@0 | 110 | }); |
michael@0 | 111 | }; |
michael@0 | 112 | |
michael@0 | 113 | function test() { |
michael@0 | 114 | waitForExplicitFinish(); |
michael@0 | 115 | |
michael@0 | 116 | Services.prefs.setBoolPref("extensions.logging.enabled", true); |
michael@0 | 117 | |
michael@0 | 118 | AddonManager.getInstallForURL(TESTROOT + "theme.xpi", function(aInstall) { |
michael@0 | 119 | aInstall.addListener({ |
michael@0 | 120 | onInstallEnded: function(aInstall, aAddon) { |
michael@0 | 121 | AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { |
michael@0 | 122 | isnot(aAddon, null, "Should have installed the test theme."); |
michael@0 | 123 | |
michael@0 | 124 | // In order to switch themes while the test is running we turn on dynamic |
michael@0 | 125 | // theme switching. This means the test isn't exactly correct but should |
michael@0 | 126 | // do some good |
michael@0 | 127 | Services.prefs.setBoolPref("extensions.dss.enabled", true); |
michael@0 | 128 | |
michael@0 | 129 | runNextTest(); |
michael@0 | 130 | }); |
michael@0 | 131 | } |
michael@0 | 132 | }); |
michael@0 | 133 | |
michael@0 | 134 | aInstall.install(); |
michael@0 | 135 | }, "application/x-xpinstall"); |
michael@0 | 136 | } |