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 that upgrading bootstrapped add-ons behaves correctly while the
6 // manager is open
8 var gManagerWindow;
9 var gCategoryUtilities;
11 function test() {
12 waitForExplicitFinish();
14 open_manager("addons://list/extension", function(aWindow) {
15 gManagerWindow = aWindow;
16 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
17 run_next_test();
18 });
19 }
21 function end_test() {
22 close_manager(gManagerWindow, finish);
23 }
25 function get_list_item_count() {
26 return get_test_items_in_list(gManagerWindow).length;
27 }
29 function get_node(parent, anonid) {
30 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
31 }
33 function get_class_node(parent, cls) {
34 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "class", cls);
35 }
37 function install_addon(aXpi, aCallback) {
38 AddonManager.getInstallForURL(TESTROOT + "addons/" + aXpi + ".xpi",
39 function(aInstall) {
40 aInstall.addListener({
41 onInstallEnded: function(aInstall) {
42 executeSoon(aCallback);
43 }
44 });
45 aInstall.install();
46 }, "application/x-xpinstall");
47 }
49 function check_addon(aAddon, version) {
50 is(get_list_item_count(), 1, "Should be one item in the list");
51 is(aAddon.version, version, "Add-on should have the right version");
53 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
54 ok(!!item, "Should see the add-on in the list");
56 // Force XBL to apply
57 item.clientTop;
59 is(get_node(item, "version").value, version, "Version should be correct");
61 if (aAddon.userDisabled)
62 is_element_visible(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
63 else
64 is_element_hidden(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
65 }
67 // Install version 1 then upgrade to version 2 with the manager open
68 add_test(function() {
69 install_addon("browser_bug596336_1", function() {
70 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
71 check_addon(aAddon, "1.0");
72 ok(!aAddon.userDisabled, "Add-on should not be disabled");
74 install_addon("browser_bug596336_2", function() {
75 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
76 check_addon(aAddon, "2.0");
77 ok(!aAddon.userDisabled, "Add-on should not be disabled");
79 aAddon.uninstall();
81 is(get_list_item_count(), 0, "Should be no items in the list");
83 run_next_test();
84 });
85 });
86 });
87 });
88 });
90 // Install version 1 mark it as disabled then upgrade to version 2 with the
91 // manager open
92 add_test(function() {
93 install_addon("browser_bug596336_1", function() {
94 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
95 aAddon.userDisabled = true;
96 check_addon(aAddon, "1.0");
97 ok(aAddon.userDisabled, "Add-on should be disabled");
99 install_addon("browser_bug596336_2", function() {
100 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
101 check_addon(aAddon, "2.0");
102 ok(aAddon.userDisabled, "Add-on should be disabled");
104 aAddon.uninstall();
106 is(get_list_item_count(), 0, "Should be no items in the list");
108 run_next_test();
109 });
110 });
111 });
112 });
113 });
115 // Install version 1 click the remove button and then upgrade to version 2 with
116 // the manager open
117 add_test(function() {
118 install_addon("browser_bug596336_1", function() {
119 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
120 check_addon(aAddon, "1.0");
121 ok(!aAddon.userDisabled, "Add-on should not be disabled");
123 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
124 EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
126 // Force XBL to apply
127 item.clientTop;
129 ok(aAddon.userDisabled, "Add-on should be disabled");
130 ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall");
131 is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");
133 install_addon("browser_bug596336_2", function() {
134 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
135 check_addon(aAddon, "2.0");
136 ok(!aAddon.userDisabled, "Add-on should not be disabled");
138 aAddon.uninstall();
140 is(get_list_item_count(), 0, "Should be no items in the list");
142 run_next_test();
143 });
144 });
145 });
146 });
147 });
149 // Install version 1, disable it, click the remove button and then upgrade to
150 // version 2 with the manager open
151 add_test(function() {
152 install_addon("browser_bug596336_1", function() {
153 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
154 aAddon.userDisabled = true;
155 check_addon(aAddon, "1.0");
156 ok(aAddon.userDisabled, "Add-on should be disabled");
158 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
159 EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
161 // Force XBL to apply
162 item.clientTop;
164 ok(aAddon.userDisabled, "Add-on should be disabled");
165 ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall");
166 is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");
168 install_addon("browser_bug596336_2", function() {
169 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
170 check_addon(aAddon, "2.0");
171 ok(aAddon.userDisabled, "Add-on should be disabled");
173 aAddon.uninstall();
175 is(get_list_item_count(), 0, "Should be no items in the list");
177 run_next_test();
178 });
179 });
180 });
181 });
182 });