browser/base/content/test/general/browser_bug592338.js

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

mercurial