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