toolkit/mozapps/extensions/test/browser/browser_newaddon.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:1fedf6a3d47d
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5 // Tests the new add-on tab
6
7 var gProvider;
8
9 function loadPage(aURL, aCallback) {
10 gBrowser.selectedTab = gBrowser.addTab();
11 gBrowser.loadURI(aURL);
12 gBrowser.addEventListener("AddonDisplayed", function(event) {
13 gBrowser.removeEventListener("AddonDisplayed", arguments.callee, false);
14
15 aCallback(gBrowser.selectedTab);
16 });
17 }
18
19 function test() {
20 waitForExplicitFinish();
21
22 gProvider = new MockProvider();
23
24 gProvider.createAddons([{
25 id: "addon1@tests.mozilla.org",
26 name: "Test 1",
27 version: "5.3",
28 userDisabled: true,
29 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
30 }, {
31 id: "addon2@tests.mozilla.org",
32 name: "Test 2",
33 version: "7.1",
34 creator: "Dave Townsend",
35 userDisabled: true
36 }]);
37
38 run_next_test();
39 }
40
41 function end_test() {
42 finish();
43 }
44
45 // Tests that ignoring a restartless add-on works
46 add_test(function() {
47 loadPage("about:newaddon?id=addon1@tests.mozilla.org", function(aTab) {
48 var doc = aTab.linkedBrowser.contentDocument;
49 is(doc.getElementById("name").value, "Test 1 5.3", "Should say the right name");
50
51 is_element_hidden(doc.getElementById("author"), "Should be no author displayed");
52 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
53
54 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
55 "Should be showing the right buttons");
56
57 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
58 {}, aTab.linkedBrowser.contentWindow);
59
60 is(gBrowser.tabs.length, 1, "Page should have been closed");
61
62 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
63 ok(aAddon.userDisabled, "Add-on should not have been enabled");
64
65 ok(!aAddon.isActive, "Add-on should not be running");
66
67 run_next_test();
68 });
69 });
70 });
71
72 // Tests that enabling a restartless add-on works
73 add_test(function() {
74 loadPage("about:newaddon?id=addon1@tests.mozilla.org", function(aTab) {
75 var doc = aTab.linkedBrowser.contentDocument;
76 is(doc.getElementById("name").value, "Test 1 5.3", "Should say the right name");
77
78 is_element_hidden(doc.getElementById("author"), "Should be no author displayed");
79 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
80
81 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
82 "Should be showing the right buttons");
83
84 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
85 {}, aTab.linkedBrowser.contentWindow);
86
87 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
88 {}, aTab.linkedBrowser.contentWindow);
89
90 is(gBrowser.tabs.length, 1, "Page should have been closed");
91
92 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
93 ok(!aAddon.userDisabled, "Add-on should now have been enabled");
94
95 ok(aAddon.isActive, "Add-on should now be running");
96
97 run_next_test();
98 });
99 });
100 });
101
102 // Tests that ignoring a non-restartless add-on works
103 add_test(function() {
104 loadPage("about:newaddon?id=addon2@tests.mozilla.org", function(aTab) {
105 var doc = aTab.linkedBrowser.contentDocument;
106 is(doc.getElementById("name").value, "Test 2 7.1", "Should say the right name");
107
108 is_element_visible(doc.getElementById("author"), "Should be an author displayed");
109 is(doc.getElementById("author").value, "By Dave Townsend", "Should have the right author");
110 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
111
112 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
113 "Should be showing the right buttons");
114
115 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
116 {}, aTab.linkedBrowser.contentWindow);
117
118 is(gBrowser.tabs.length, 1, "Page should have been closed");
119
120 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
121 ok(aAddon.userDisabled, "Add-on should not have been enabled");
122
123 ok(!aAddon.isActive, "Add-on should not be running");
124
125 run_next_test();
126 });
127 });
128 });
129
130 // Tests that enabling a non-restartless add-on works
131 add_test(function() {
132 loadPage("about:newaddon?id=addon2@tests.mozilla.org", function(aTab) {
133 var doc = aTab.linkedBrowser.contentDocument;
134 is(doc.getElementById("name").value, "Test 2 7.1", "Should say the right name");
135
136 is_element_visible(doc.getElementById("author"), "Should be an author displayed");
137 is(doc.getElementById("author").value, "By Dave Townsend", "Should have the right author");
138 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
139
140 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
141 "Should be showing the right buttons");
142
143 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
144 {}, aTab.linkedBrowser.contentWindow);
145
146 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
147 {}, aTab.linkedBrowser.contentWindow);
148
149 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("restartPanel"),
150 "Should be showing the right buttons");
151
152 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
153 ok(!aAddon.userDisabled, "Add-on should now have been enabled");
154
155 ok(!aAddon.isActive, "Add-on should not be running");
156
157 ok(doc.getElementById("allow").disabled, "Should have disabled checkbox");
158
159 EventUtils.synthesizeMouseAtCenter(doc.getElementById("cancel-button"),
160 {}, aTab.linkedBrowser.contentWindow);
161
162 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
163 "Should be showing the right buttons");
164
165 ok(!doc.getElementById("allow").disabled, "Should have enabled checkbox");
166
167 ok(aAddon.userDisabled, "Add-on should not have been enabled");
168
169 ok(!aAddon.isActive, "Add-on should not be running");
170
171 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
172 {}, aTab.linkedBrowser.contentWindow);
173
174 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
175 {}, aTab.linkedBrowser.contentWindow);
176
177 ok(aAddon.userDisabled, "Add-on should not have been enabled");
178
179 ok(!aAddon.isActive, "Add-on should not be running");
180
181 is(gBrowser.tabs.length, 1, "Page should have been closed");
182
183 run_next_test();
184 });
185 });
186 });

mercurial