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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:af565d168080
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5 // Tests that upgrading bootstrapped add-ons behaves correctly while the
6 // manager is open
7
8 var gManagerWindow;
9 var gCategoryUtilities;
10
11 function test() {
12 waitForExplicitFinish();
13
14 open_manager("addons://list/extension", function(aWindow) {
15 gManagerWindow = aWindow;
16 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
17 run_next_test();
18 });
19 }
20
21 function end_test() {
22 close_manager(gManagerWindow, finish);
23 }
24
25 function get_list_item_count() {
26 return get_test_items_in_list(gManagerWindow).length;
27 }
28
29 function get_node(parent, anonid) {
30 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
31 }
32
33 function get_class_node(parent, cls) {
34 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "class", cls);
35 }
36
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 }
48
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");
52
53 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
54 ok(!!item, "Should see the add-on in the list");
55
56 // Force XBL to apply
57 item.clientTop;
58
59 is(get_node(item, "version").value, version, "Version should be correct");
60
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 }
66
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");
73
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");
78
79 aAddon.uninstall();
80
81 is(get_list_item_count(), 0, "Should be no items in the list");
82
83 run_next_test();
84 });
85 });
86 });
87 });
88 });
89
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");
98
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");
103
104 aAddon.uninstall();
105
106 is(get_list_item_count(), 0, "Should be no items in the list");
107
108 run_next_test();
109 });
110 });
111 });
112 });
113 });
114
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");
122
123 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
124 EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
125
126 // Force XBL to apply
127 item.clientTop;
128
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");
132
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");
137
138 aAddon.uninstall();
139
140 is(get_list_item_count(), 0, "Should be no items in the list");
141
142 run_next_test();
143 });
144 });
145 });
146 });
147 });
148
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");
157
158 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
159 EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
160
161 // Force XBL to apply
162 item.clientTop;
163
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");
167
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");
172
173 aAddon.uninstall();
174
175 is(get_list_item_count(), 0, "Should be no items in the list");
176
177 run_next_test();
178 });
179 });
180 });
181 });
182 });

mercurial