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.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // Tests the new add-on tab
7 var gProvider;
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);
15 aCallback(gBrowser.selectedTab);
16 });
17 }
19 function test() {
20 waitForExplicitFinish();
22 gProvider = new MockProvider();
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 }]);
38 run_next_test();
39 }
41 function end_test() {
42 finish();
43 }
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");
51 is_element_hidden(doc.getElementById("author"), "Should be no author displayed");
52 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
54 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
55 "Should be showing the right buttons");
57 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
58 {}, aTab.linkedBrowser.contentWindow);
60 is(gBrowser.tabs.length, 1, "Page should have been closed");
62 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
63 ok(aAddon.userDisabled, "Add-on should not have been enabled");
65 ok(!aAddon.isActive, "Add-on should not be running");
67 run_next_test();
68 });
69 });
70 });
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");
78 is_element_hidden(doc.getElementById("author"), "Should be no author displayed");
79 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
81 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
82 "Should be showing the right buttons");
84 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
85 {}, aTab.linkedBrowser.contentWindow);
87 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
88 {}, aTab.linkedBrowser.contentWindow);
90 is(gBrowser.tabs.length, 1, "Page should have been closed");
92 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
93 ok(!aAddon.userDisabled, "Add-on should now have been enabled");
95 ok(aAddon.isActive, "Add-on should now be running");
97 run_next_test();
98 });
99 });
100 });
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");
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");
112 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
113 "Should be showing the right buttons");
115 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
116 {}, aTab.linkedBrowser.contentWindow);
118 is(gBrowser.tabs.length, 1, "Page should have been closed");
120 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
121 ok(aAddon.userDisabled, "Add-on should not have been enabled");
123 ok(!aAddon.isActive, "Add-on should not be running");
125 run_next_test();
126 });
127 });
128 });
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");
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");
140 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
141 "Should be showing the right buttons");
143 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
144 {}, aTab.linkedBrowser.contentWindow);
146 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
147 {}, aTab.linkedBrowser.contentWindow);
149 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("restartPanel"),
150 "Should be showing the right buttons");
152 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
153 ok(!aAddon.userDisabled, "Add-on should now have been enabled");
155 ok(!aAddon.isActive, "Add-on should not be running");
157 ok(doc.getElementById("allow").disabled, "Should have disabled checkbox");
159 EventUtils.synthesizeMouseAtCenter(doc.getElementById("cancel-button"),
160 {}, aTab.linkedBrowser.contentWindow);
162 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
163 "Should be showing the right buttons");
165 ok(!doc.getElementById("allow").disabled, "Should have enabled checkbox");
167 ok(aAddon.userDisabled, "Add-on should not have been enabled");
169 ok(!aAddon.isActive, "Add-on should not be running");
171 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
172 {}, aTab.linkedBrowser.contentWindow);
174 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
175 {}, aTab.linkedBrowser.contentWindow);
177 ok(aAddon.userDisabled, "Add-on should not have been enabled");
179 ok(!aAddon.isActive, "Add-on should not be running");
181 is(gBrowser.tabs.length, 1, "Page should have been closed");
183 run_next_test();
184 });
185 });
186 });