1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_sorting.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,372 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Tests that sorting of add-ons works correctly 1.9 +// (this test uses the list view, even though it no longer has sort buttons - see bug 623207) 1.10 + 1.11 +var gManagerWindow; 1.12 +var gProvider; 1.13 + 1.14 +function test() { 1.15 + waitForExplicitFinish(); 1.16 + 1.17 + gProvider = new MockProvider(); 1.18 + gProvider.createAddons([{ 1.19 + // enabledInstalled group 1.20 + // * Enabled 1.21 + // * Incompatible but enabled because compatibility checking is off 1.22 + // * Waiting to be installed 1.23 + // * Waiting to be enabled 1.24 + id: "test1@tests.mozilla.org", 1.25 + name: "Test add-on", 1.26 + description: "foo", 1.27 + updateDate: new Date(2010, 04, 02, 00, 00, 00), 1.28 + size: 1, 1.29 + pendingOperations: AddonManager.PENDING_NONE, 1.30 + }, { 1.31 + id: "test2@tests.mozilla.org", 1.32 + name: "a first add-on", 1.33 + description: "foo", 1.34 + updateDate: new Date(2010, 04, 01, 23, 59, 59), 1.35 + size: 0265, 1.36 + pendingOperations: AddonManager.PENDING_UPGRADE, 1.37 + isActive: true, 1.38 + isCompatible: false, 1.39 + }, { 1.40 + id: "test3@tests.mozilla.org", 1.41 + name: "\u010Cesk\u00FD slovn\u00EDk", // Český slovník 1.42 + description: "foo", 1.43 + updateDate: new Date(2010, 04, 02, 00, 00, 01), 1.44 + size: 12, 1.45 + pendingOperations: AddonManager.PENDING_INSTALL, 1.46 + isActive: false, 1.47 + }, { 1.48 + id: "test4@tests.mozilla.org", 1.49 + name: "canadian dictionary", 1.50 + updateDate: new Date(1970, 0, 01, 00, 00, 00), 1.51 + description: "foo", 1.52 + isActive: true, 1.53 + }, { 1.54 + id: "test5@tests.mozilla.org", 1.55 + name: "croatian dictionary", 1.56 + description: "foo", 1.57 + updateDate: new Date(2012, 12, 12, 00, 00, 00), 1.58 + size: 5, 1.59 + pendingOperations: AddonManager.PENDING_ENABLE, 1.60 + isActive: false, 1.61 + }, { 1.62 + // pendingDisable group 1.63 + // * Waiting to be disabled 1.64 + id: "test6@tests.mozilla.org", 1.65 + name: "orange Add-on", 1.66 + description: "foo", 1.67 + updateDate: new Date(2010, 04, 02, 00, 00, 00), 1.68 + size: 142, 1.69 + isCompatible: false, 1.70 + isActive: true, 1.71 + pendingOperations: AddonManager.PENDING_DISABLE, 1.72 + }, { 1.73 + id: "test7@tests.mozilla.org", 1.74 + name: "Blue Add-on", 1.75 + description: "foo", 1.76 + updateDate: new Date(2010, 04, 01, 23, 59, 59), 1.77 + size: 65, 1.78 + isActive: true, 1.79 + pendingOperations: AddonManager.PENDING_DISABLE, 1.80 + }, { 1.81 + id: "test8@tests.mozilla.org", 1.82 + name: "Green Add-on", 1.83 + description: "foo", 1.84 + updateDate: new Date(2010, 04, 03, 00, 00, 01), 1.85 + size: 125, 1.86 + pendingOperations: AddonManager.PENDING_DISABLE, 1.87 + }, { 1.88 + id: "test9@tests.mozilla.org", 1.89 + name: "red Add-on", 1.90 + updateDate: new Date(2011, 04, 01, 00, 00, 00), 1.91 + description: "foo", 1.92 + isCompatible: false, 1.93 + pendingOperations: AddonManager.PENDING_DISABLE, 1.94 + }, { 1.95 + id: "test10@tests.mozilla.org", 1.96 + name: "Purple Add-on", 1.97 + description: "foo", 1.98 + updateDate: new Date(2012, 12, 12, 00, 00, 00), 1.99 + size: 56, 1.100 + isCompatible: false, 1.101 + pendingOperations: AddonManager.PENDING_DISABLE, 1.102 + }, { 1.103 + // pendingUninstall group 1.104 + // * Waiting to be removed 1.105 + id: "test11@tests.mozilla.org", 1.106 + name: "amber Add-on", 1.107 + description: "foo", 1.108 + updateDate: new Date(1978, 04, 02, 00, 00, 00), 1.109 + size: 142, 1.110 + isActive: false, 1.111 + appDisabled: true, 1.112 + pendingOperations: AddonManager.PENDING_UNINSTALL, 1.113 + }, { 1.114 + id: "test12@tests.mozilla.org", 1.115 + name: "Salmon Add-on - pending disable", 1.116 + description: "foo", 1.117 + updateDate: new Date(2054, 04, 01, 23, 59, 59), 1.118 + size: 65, 1.119 + isActive: true, 1.120 + pendingOperations: AddonManager.PENDING_UNINSTALL, 1.121 + }, { 1.122 + id: "test13@tests.mozilla.org", 1.123 + name: "rose Add-on", 1.124 + description: "foo", 1.125 + updateDate: new Date(2010, 04, 02, 00, 00, 01), 1.126 + size: 125, 1.127 + isActive: false, 1.128 + userDisabled: true, 1.129 + pendingOperations: AddonManager.PENDING_UNINSTALL, 1.130 + }, { 1.131 + id: "test14@tests.mozilla.org", 1.132 + name: "Violet Add-on", 1.133 + updateDate: new Date(2010, 05, 01, 00, 00, 00), 1.134 + description: "foo", 1.135 + isActive: false, 1.136 + appDisabled: true, 1.137 + pendingOperations: AddonManager.PENDING_UNINSTALL, 1.138 + }, { 1.139 + id: "test15@tests.mozilla.org", 1.140 + name: "white Add-on", 1.141 + description: "foo", 1.142 + updateDate: new Date(2010, 04, 12, 00, 00, 00), 1.143 + size: 56, 1.144 + isActive: false, 1.145 + userDisabled: true, 1.146 + pendingOperations: AddonManager.PENDING_UNINSTALL, 1.147 + }, { 1.148 + // disabledIncompatibleBlocked group 1.149 + // * Disabled 1.150 + // * Incompatible 1.151 + // * Blocklisted 1.152 + id: "test16@tests.mozilla.org", 1.153 + name: "grimsby Add-on", 1.154 + description: "foo", 1.155 + updateDate: new Date(2010, 04, 01, 00, 00, 00), 1.156 + size: 142, 1.157 + isActive: false, 1.158 + appDisabled: true, 1.159 + }, { 1.160 + id: "test17@tests.mozilla.org", 1.161 + name: "beamsville Add-on", 1.162 + description: "foo", 1.163 + updateDate: new Date(2010, 04, 8, 23, 59, 59), 1.164 + size: 65, 1.165 + isActive: false, 1.166 + userDisabled: true, 1.167 + }, { 1.168 + id: "test18@tests.mozilla.org", 1.169 + name: "smithville Add-on", 1.170 + description: "foo", 1.171 + updateDate: new Date(2010, 04, 03, 00, 00, 01), 1.172 + size: 125, 1.173 + isActive: false, 1.174 + userDisabled: true, 1.175 + blocklistState: Ci.nsIBlocklistService.STATE_OUTDATED, 1.176 + }, { 1.177 + id: "test19@tests.mozilla.org", 1.178 + name: "dunnville Add-on", 1.179 + updateDate: new Date(2010, 04, 02, 00, 00, 00), 1.180 + description: "foo", 1.181 + isActive: false, 1.182 + appDisabled: true, 1.183 + isCompatible: false, 1.184 + blocklistState: Ci.nsIBlocklistService.STATE_NOT_BLOCKED, 1.185 + }, { 1.186 + id: "test20@tests.mozilla.org", 1.187 + name: "silverdale Add-on", 1.188 + description: "foo", 1.189 + updateDate: new Date(2010, 04, 12, 00, 00, 00), 1.190 + size: 56, 1.191 + isActive: false, 1.192 + appDisabled: true, 1.193 + blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED, 1.194 + }]); 1.195 + 1.196 + 1.197 + open_manager("addons://list/extension", function(aWindow) { 1.198 + gManagerWindow = aWindow; 1.199 + run_next_test(); 1.200 + }); 1.201 +} 1.202 + 1.203 +function end_test() { 1.204 + close_manager(gManagerWindow, function() { 1.205 + finish(); 1.206 + }); 1.207 +} 1.208 + 1.209 +function set_order(aSortBy, aAscending) { 1.210 + var list = gManagerWindow.document.getElementById("addon-list"); 1.211 + var elements = []; 1.212 + var node = list.firstChild; 1.213 + while (node) { 1.214 + elements.push(node); 1.215 + node = node.nextSibling; 1.216 + } 1.217 + gManagerWindow.sortElements(elements, ["uiState", aSortBy], aAscending); 1.218 + for (let element of elements) 1.219 + list.appendChild(element); 1.220 +} 1.221 + 1.222 +function check_order(aExpectedOrder) { 1.223 + var order = []; 1.224 + var list = gManagerWindow.document.getElementById("addon-list"); 1.225 + var node = list.firstChild; 1.226 + while (node) { 1.227 + var id = node.getAttribute("value"); 1.228 + if (id && id.substring(id.length - 18) == "@tests.mozilla.org") 1.229 + order.push(node.getAttribute("value")); 1.230 + node = node.nextSibling; 1.231 + } 1.232 + 1.233 + is(order.toSource(), aExpectedOrder.toSource(), "Should have seen the right order"); 1.234 +} 1.235 + 1.236 +// Tests that ascending name ordering was the default 1.237 +add_test(function() { 1.238 + 1.239 + check_order([ 1.240 + "test2@tests.mozilla.org", 1.241 + "test4@tests.mozilla.org", 1.242 + "test3@tests.mozilla.org", 1.243 + "test5@tests.mozilla.org", 1.244 + "test1@tests.mozilla.org", 1.245 + "test7@tests.mozilla.org", 1.246 + "test8@tests.mozilla.org", 1.247 + "test6@tests.mozilla.org", 1.248 + "test10@tests.mozilla.org", 1.249 + "test9@tests.mozilla.org", 1.250 + "test11@tests.mozilla.org", 1.251 + "test13@tests.mozilla.org", 1.252 + "test12@tests.mozilla.org", 1.253 + "test14@tests.mozilla.org", 1.254 + "test15@tests.mozilla.org", 1.255 + "test17@tests.mozilla.org", 1.256 + "test19@tests.mozilla.org", 1.257 + "test16@tests.mozilla.org", 1.258 + "test20@tests.mozilla.org", 1.259 + "test18@tests.mozilla.org", 1.260 + ]); 1.261 + run_next_test(); 1.262 +}); 1.263 + 1.264 +// Tests that switching to date ordering works 1.265 +add_test(function() { 1.266 + set_order("updateDate", false); 1.267 + 1.268 + // When we're ascending with updateDate, it's from newest 1.269 + // to oldest. 1.270 + 1.271 + check_order([ 1.272 + "test5@tests.mozilla.org", 1.273 + "test3@tests.mozilla.org", 1.274 + "test1@tests.mozilla.org", 1.275 + "test2@tests.mozilla.org", 1.276 + "test4@tests.mozilla.org", 1.277 + "test10@tests.mozilla.org", 1.278 + "test9@tests.mozilla.org", 1.279 + "test8@tests.mozilla.org", 1.280 + "test6@tests.mozilla.org", 1.281 + "test7@tests.mozilla.org", 1.282 + "test12@tests.mozilla.org", 1.283 + "test14@tests.mozilla.org", 1.284 + "test15@tests.mozilla.org", 1.285 + "test13@tests.mozilla.org", 1.286 + "test11@tests.mozilla.org", 1.287 + "test20@tests.mozilla.org", 1.288 + "test17@tests.mozilla.org", 1.289 + "test18@tests.mozilla.org", 1.290 + "test19@tests.mozilla.org", 1.291 + "test16@tests.mozilla.org", 1.292 + ]); 1.293 + 1.294 + set_order("updateDate", true); 1.295 + 1.296 + check_order([ 1.297 + "test4@tests.mozilla.org", 1.298 + "test2@tests.mozilla.org", 1.299 + "test1@tests.mozilla.org", 1.300 + "test3@tests.mozilla.org", 1.301 + "test5@tests.mozilla.org", 1.302 + "test7@tests.mozilla.org", 1.303 + "test6@tests.mozilla.org", 1.304 + "test8@tests.mozilla.org", 1.305 + "test9@tests.mozilla.org", 1.306 + "test10@tests.mozilla.org", 1.307 + "test11@tests.mozilla.org", 1.308 + "test13@tests.mozilla.org", 1.309 + "test15@tests.mozilla.org", 1.310 + "test14@tests.mozilla.org", 1.311 + "test12@tests.mozilla.org", 1.312 + "test16@tests.mozilla.org", 1.313 + "test19@tests.mozilla.org", 1.314 + "test18@tests.mozilla.org", 1.315 + "test17@tests.mozilla.org", 1.316 + "test20@tests.mozilla.org", 1.317 + ]); 1.318 + 1.319 + run_next_test(); 1.320 +}); 1.321 + 1.322 +// Tests that switching to name ordering works 1.323 +add_test(function() { 1.324 + set_order("name", true); 1.325 + 1.326 + check_order([ 1.327 + "test2@tests.mozilla.org", 1.328 + "test4@tests.mozilla.org", 1.329 + "test3@tests.mozilla.org", 1.330 + "test5@tests.mozilla.org", 1.331 + "test1@tests.mozilla.org", 1.332 + "test7@tests.mozilla.org", 1.333 + "test8@tests.mozilla.org", 1.334 + "test6@tests.mozilla.org", 1.335 + "test10@tests.mozilla.org", 1.336 + "test9@tests.mozilla.org", 1.337 + "test11@tests.mozilla.org", 1.338 + "test13@tests.mozilla.org", 1.339 + "test12@tests.mozilla.org", 1.340 + "test14@tests.mozilla.org", 1.341 + "test15@tests.mozilla.org", 1.342 + "test17@tests.mozilla.org", 1.343 + "test19@tests.mozilla.org", 1.344 + "test16@tests.mozilla.org", 1.345 + "test20@tests.mozilla.org", 1.346 + "test18@tests.mozilla.org", 1.347 + ]); 1.348 + 1.349 + set_order("name", false); 1.350 + 1.351 + check_order([ 1.352 + "test1@tests.mozilla.org", 1.353 + "test5@tests.mozilla.org", 1.354 + "test3@tests.mozilla.org", 1.355 + "test4@tests.mozilla.org", 1.356 + "test2@tests.mozilla.org", 1.357 + "test9@tests.mozilla.org", 1.358 + "test10@tests.mozilla.org", 1.359 + "test6@tests.mozilla.org", 1.360 + "test8@tests.mozilla.org", 1.361 + "test7@tests.mozilla.org", 1.362 + "test15@tests.mozilla.org", 1.363 + "test14@tests.mozilla.org", 1.364 + "test12@tests.mozilla.org", 1.365 + "test13@tests.mozilla.org", 1.366 + "test11@tests.mozilla.org", 1.367 + "test18@tests.mozilla.org", 1.368 + "test20@tests.mozilla.org", 1.369 + "test16@tests.mozilla.org", 1.370 + "test19@tests.mozilla.org", 1.371 + "test17@tests.mozilla.org", 1.372 + ]); 1.373 + 1.374 + run_next_test(); 1.375 +});