Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Tests that the discovery view loads properly |
michael@0 | 6 | |
michael@0 | 7 | const MAIN_URL = "https://example.com/" + RELATIVE_DIR + "discovery.html"; |
michael@0 | 8 | |
michael@0 | 9 | var gManagerWindow; |
michael@0 | 10 | var gCategoryUtilities; |
michael@0 | 11 | var gProvider; |
michael@0 | 12 | |
michael@0 | 13 | var gLoadCompleteCallback = null; |
michael@0 | 14 | |
michael@0 | 15 | var gProgressListener = { |
michael@0 | 16 | onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) { |
michael@0 | 17 | // Only care about the network stop status events |
michael@0 | 18 | if (!(aStateFlags & (Ci.nsIWebProgressListener.STATE_IS_NETWORK)) || |
michael@0 | 19 | !(aStateFlags & (Ci.nsIWebProgressListener.STATE_STOP))) |
michael@0 | 20 | return; |
michael@0 | 21 | |
michael@0 | 22 | if (gLoadCompleteCallback) |
michael@0 | 23 | executeSoon(gLoadCompleteCallback); |
michael@0 | 24 | gLoadCompleteCallback = null; |
michael@0 | 25 | }, |
michael@0 | 26 | |
michael@0 | 27 | onLocationChange: function() { }, |
michael@0 | 28 | onSecurityChange: function() { }, |
michael@0 | 29 | onProgressChange: function() { }, |
michael@0 | 30 | onStatusChange: function() { }, |
michael@0 | 31 | |
michael@0 | 32 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, |
michael@0 | 33 | Ci.nsISupportsWeakReference]), |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | function test() { |
michael@0 | 37 | // Switch to a known url |
michael@0 | 38 | Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL); |
michael@0 | 39 | // Temporarily enable caching |
michael@0 | 40 | Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); |
michael@0 | 41 | |
michael@0 | 42 | waitForExplicitFinish(); |
michael@0 | 43 | |
michael@0 | 44 | gProvider = new MockProvider(); |
michael@0 | 45 | |
michael@0 | 46 | gProvider.createAddons([{ |
michael@0 | 47 | id: "addon1@tests.mozilla.org", |
michael@0 | 48 | name: "Test add-on 1", |
michael@0 | 49 | type: "extension", |
michael@0 | 50 | version: "2.2", |
michael@0 | 51 | isCompatible: false, |
michael@0 | 52 | blocklistState: Ci.nsIBlocklistService.STATE_SOFTBLOCKED, |
michael@0 | 53 | userDisabled: false |
michael@0 | 54 | }, { |
michael@0 | 55 | id: "addon2@tests.mozilla.org", |
michael@0 | 56 | name: "Test add-on 2", |
michael@0 | 57 | type: "plugin", |
michael@0 | 58 | version: "3.1.5", |
michael@0 | 59 | isCompatible: true, |
michael@0 | 60 | blocklistState: Ci.nsIBlocklistService.STATE_NOT_BLOCKED, |
michael@0 | 61 | userDisabled: false |
michael@0 | 62 | }, { |
michael@0 | 63 | id: "addon3@tests.mozilla.org", |
michael@0 | 64 | name: "Test add-on 3", |
michael@0 | 65 | type: "theme", |
michael@0 | 66 | version: "1.2b1", |
michael@0 | 67 | isCompatible: false, |
michael@0 | 68 | blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED, |
michael@0 | 69 | userDisabled: true |
michael@0 | 70 | }]); |
michael@0 | 71 | |
michael@0 | 72 | run_next_test(); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function end_test() { |
michael@0 | 76 | finish(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function getURL(aBrowser) { |
michael@0 | 80 | if (gManagerWindow.document.getElementById("discover-view").selectedPanel != |
michael@0 | 81 | aBrowser) |
michael@0 | 82 | return null; |
michael@0 | 83 | |
michael@0 | 84 | var url = aBrowser.currentURI.spec; |
michael@0 | 85 | var pos = url.indexOf("#"); |
michael@0 | 86 | if (pos != -1) |
michael@0 | 87 | return url.substring(0, pos); |
michael@0 | 88 | return url; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function getHash(aBrowser) { |
michael@0 | 92 | if (gManagerWindow.document.getElementById("discover-view").selectedPanel != |
michael@0 | 93 | aBrowser) |
michael@0 | 94 | return null; |
michael@0 | 95 | |
michael@0 | 96 | var url = aBrowser.currentURI.spec; |
michael@0 | 97 | var pos = url.indexOf("#"); |
michael@0 | 98 | if (pos != -1) |
michael@0 | 99 | return decodeURIComponent(url.substring(pos + 1)); |
michael@0 | 100 | return null; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function testHash(aBrowser, aTestAddonVisible, aCallback) { |
michael@0 | 104 | var hash = getHash(aBrowser); |
michael@0 | 105 | isnot(hash, null, "There should be a hash"); |
michael@0 | 106 | try { |
michael@0 | 107 | var data = JSON.parse(hash); |
michael@0 | 108 | } |
michael@0 | 109 | catch (e) { |
michael@0 | 110 | ok(false, "Hash should have been valid JSON: " + e); |
michael@0 | 111 | aCallback(); |
michael@0 | 112 | return; |
michael@0 | 113 | } |
michael@0 | 114 | is(typeof data, "object", "Hash should be a JS object"); |
michael@0 | 115 | |
michael@0 | 116 | // Ensure that at least the test add-ons are present |
michael@0 | 117 | if (aTestAddonVisible[0]) |
michael@0 | 118 | ok("addon1@tests.mozilla.org" in data, "Test add-on 1 should be listed"); |
michael@0 | 119 | else |
michael@0 | 120 | ok(!("addon1@tests.mozilla.org" in data), "Test add-on 1 should not be listed"); |
michael@0 | 121 | if (aTestAddonVisible[1]) |
michael@0 | 122 | ok("addon2@tests.mozilla.org" in data, "Test add-on 2 should be listed"); |
michael@0 | 123 | else |
michael@0 | 124 | ok(!("addon2@tests.mozilla.org" in data), "Test add-on 2 should not be listed"); |
michael@0 | 125 | if (aTestAddonVisible[2]) |
michael@0 | 126 | ok("addon3@tests.mozilla.org" in data, "Test add-on 3 should be listed"); |
michael@0 | 127 | else |
michael@0 | 128 | ok(!("addon3@tests.mozilla.org" in data), "Test add-on 3 should not be listed"); |
michael@0 | 129 | |
michael@0 | 130 | // Test against all the add-ons the manager knows about since plugins and |
michael@0 | 131 | // app extensions may exist |
michael@0 | 132 | AddonManager.getAllAddons(function(aAddons) { |
michael@0 | 133 | for (let addon of aAddons) { |
michael@0 | 134 | if (!(addon.id in data)) { |
michael@0 | 135 | // Test add-ons will have shown an error if necessary above |
michael@0 | 136 | if (addon.id.substring(6) != "@tests.mozilla.org") |
michael@0 | 137 | ok(false, "Add-on " + addon.id + " was not included in the data"); |
michael@0 | 138 | continue; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | info("Testing data for add-on " + addon.id); |
michael@0 | 142 | var addonData = data[addon.id]; |
michael@0 | 143 | is(addonData.name, addon.name, "Name should be correct"); |
michael@0 | 144 | is(addonData.version, addon.version, "Version should be correct"); |
michael@0 | 145 | is(addonData.type, addon.type, "Type should be correct"); |
michael@0 | 146 | is(addonData.userDisabled, addon.userDisabled, "userDisabled should be correct"); |
michael@0 | 147 | is(addonData.isBlocklisted, addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED, "blocklisted should be correct"); |
michael@0 | 148 | is(addonData.isCompatible, addon.isCompatible, "isCompatible should be correct"); |
michael@0 | 149 | } |
michael@0 | 150 | aCallback(); |
michael@0 | 151 | }); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | function isLoading() { |
michael@0 | 155 | var loading = gManagerWindow.document.getElementById("discover-view").selectedPanel == |
michael@0 | 156 | gManagerWindow.document.getElementById("discover-loading"); |
michael@0 | 157 | if (loading) { |
michael@0 | 158 | is_element_visible(gManagerWindow.document.querySelector("#discover-loading .loading"), |
michael@0 | 159 | "Loading message should be visible when its panel is the selected panel"); |
michael@0 | 160 | } |
michael@0 | 161 | return loading; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | function isError() { |
michael@0 | 165 | return gManagerWindow.document.getElementById("discover-view").selectedPanel == |
michael@0 | 166 | gManagerWindow.document.getElementById("discover-error"); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | function clickLink(aId, aCallback) { |
michael@0 | 170 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 171 | browser.addProgressListener(gProgressListener); |
michael@0 | 172 | |
michael@0 | 173 | gLoadCompleteCallback = function() { |
michael@0 | 174 | browser.removeProgressListener(gProgressListener); |
michael@0 | 175 | aCallback(); |
michael@0 | 176 | }; |
michael@0 | 177 | |
michael@0 | 178 | var link = browser.contentDocument.getElementById(aId); |
michael@0 | 179 | EventUtils.sendMouseEvent({type: "click"}, link); |
michael@0 | 180 | |
michael@0 | 181 | executeSoon(function() { |
michael@0 | 182 | ok(isLoading(), "Clicking a link should show the loading pane"); |
michael@0 | 183 | }); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | // Tests that switching to the discovery view displays the right url |
michael@0 | 187 | add_test(function() { |
michael@0 | 188 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 189 | gManagerWindow = aWindow; |
michael@0 | 190 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 191 | |
michael@0 | 192 | gCategoryUtilities.openType("discover", function() { |
michael@0 | 193 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 194 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 195 | |
michael@0 | 196 | testHash(browser, [true, true, true], function() { |
michael@0 | 197 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 198 | }); |
michael@0 | 199 | }); |
michael@0 | 200 | |
michael@0 | 201 | ok(isLoading(), "Should be loading at first"); |
michael@0 | 202 | }); |
michael@0 | 203 | }); |
michael@0 | 204 | |
michael@0 | 205 | // Tests that loading the add-ons manager with the discovery view as the last |
michael@0 | 206 | // selected view displays the right url |
michael@0 | 207 | add_test(function() { |
michael@0 | 208 | // Hide one of the test add-ons |
michael@0 | 209 | Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false); |
michael@0 | 210 | Services.prefs.setBoolPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled", true); |
michael@0 | 211 | |
michael@0 | 212 | open_manager(null, function(aWindow) { |
michael@0 | 213 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 214 | is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view"); |
michael@0 | 215 | |
michael@0 | 216 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 217 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 218 | |
michael@0 | 219 | testHash(browser, [true, false, true], function() { |
michael@0 | 220 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 221 | }); |
michael@0 | 222 | }, function(aWindow) { |
michael@0 | 223 | gManagerWindow = aWindow; |
michael@0 | 224 | ok(isLoading(), "Should be loading at first"); |
michael@0 | 225 | }); |
michael@0 | 226 | }); |
michael@0 | 227 | |
michael@0 | 228 | // Tests that loading the add-ons manager with the discovery view as the initial |
michael@0 | 229 | // view displays the right url |
michael@0 | 230 | add_test(function() { |
michael@0 | 231 | Services.prefs.clearUserPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled"); |
michael@0 | 232 | Services.prefs.setBoolPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled", false); |
michael@0 | 233 | |
michael@0 | 234 | open_manager(null, function(aWindow) { |
michael@0 | 235 | gManagerWindow = aWindow; |
michael@0 | 236 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 237 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 238 | close_manager(gManagerWindow, function() { |
michael@0 | 239 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 240 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 241 | is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view"); |
michael@0 | 242 | |
michael@0 | 243 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 244 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 245 | |
michael@0 | 246 | testHash(browser, [true, true, false], function() { |
michael@0 | 247 | Services.prefs.clearUserPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled"); |
michael@0 | 248 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 249 | }); |
michael@0 | 250 | }, function(aWindow) { |
michael@0 | 251 | gManagerWindow = aWindow; |
michael@0 | 252 | ok(isLoading(), "Should be loading at first"); |
michael@0 | 253 | }); |
michael@0 | 254 | }); |
michael@0 | 255 | }); |
michael@0 | 256 | }); |
michael@0 | 257 | }); |
michael@0 | 258 | |
michael@0 | 259 | // Tests that switching to the discovery view displays the right url |
michael@0 | 260 | add_test(function() { |
michael@0 | 261 | Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false); |
michael@0 | 262 | |
michael@0 | 263 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 264 | gManagerWindow = aWindow; |
michael@0 | 265 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 266 | |
michael@0 | 267 | gCategoryUtilities.openType("discover", function() { |
michael@0 | 268 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 269 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 270 | |
michael@0 | 271 | is(getHash(browser), null, "Hash should not have been passed"); |
michael@0 | 272 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 273 | }); |
michael@0 | 274 | }); |
michael@0 | 275 | }); |
michael@0 | 276 | |
michael@0 | 277 | // Tests that loading the add-ons manager with the discovery view as the last |
michael@0 | 278 | // selected view displays the right url |
michael@0 | 279 | add_test(function() { |
michael@0 | 280 | open_manager(null, function(aWindow) { |
michael@0 | 281 | gManagerWindow = aWindow; |
michael@0 | 282 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 283 | is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view"); |
michael@0 | 284 | |
michael@0 | 285 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 286 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 287 | |
michael@0 | 288 | is(getHash(browser), null, "Hash should not have been passed"); |
michael@0 | 289 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 290 | }); |
michael@0 | 291 | }); |
michael@0 | 292 | |
michael@0 | 293 | // Tests that loading the add-ons manager with the discovery view as the initial |
michael@0 | 294 | // view displays the right url |
michael@0 | 295 | add_test(function() { |
michael@0 | 296 | open_manager(null, function(aWindow) { |
michael@0 | 297 | gManagerWindow = aWindow; |
michael@0 | 298 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 299 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 300 | close_manager(gManagerWindow, function() { |
michael@0 | 301 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 302 | gManagerWindow = aWindow; |
michael@0 | 303 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 304 | is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view"); |
michael@0 | 305 | |
michael@0 | 306 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 307 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 308 | |
michael@0 | 309 | is(getHash(browser), null, "Hash should not have been passed"); |
michael@0 | 310 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 311 | }); |
michael@0 | 312 | }); |
michael@0 | 313 | }); |
michael@0 | 314 | }); |
michael@0 | 315 | }); |
michael@0 | 316 | |
michael@0 | 317 | // Tests that navigating to an insecure page fails |
michael@0 | 318 | add_test(function() { |
michael@0 | 319 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 320 | gManagerWindow = aWindow; |
michael@0 | 321 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 322 | |
michael@0 | 323 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 324 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 325 | |
michael@0 | 326 | clickLink("link-http", function() { |
michael@0 | 327 | ok(isError(), "Should have shown the error page"); |
michael@0 | 328 | |
michael@0 | 329 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 330 | gCategoryUtilities.openType("discover", function() { |
michael@0 | 331 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 332 | |
michael@0 | 333 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 334 | }); |
michael@0 | 335 | ok(isLoading(), "Should start loading again"); |
michael@0 | 336 | }); |
michael@0 | 337 | }); |
michael@0 | 338 | }); |
michael@0 | 339 | }); |
michael@0 | 340 | |
michael@0 | 341 | // Tests that navigating to a different domain fails |
michael@0 | 342 | add_test(function() { |
michael@0 | 343 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 344 | gManagerWindow = aWindow; |
michael@0 | 345 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 346 | |
michael@0 | 347 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 348 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 349 | |
michael@0 | 350 | clickLink("link-domain", function() { |
michael@0 | 351 | ok(isError(), "Should have shown the error page"); |
michael@0 | 352 | |
michael@0 | 353 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 354 | gCategoryUtilities.openType("discover", function() { |
michael@0 | 355 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 356 | |
michael@0 | 357 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 358 | }); |
michael@0 | 359 | ok(isLoading(), "Should start loading again"); |
michael@0 | 360 | }); |
michael@0 | 361 | }); |
michael@0 | 362 | }); |
michael@0 | 363 | }); |
michael@0 | 364 | |
michael@0 | 365 | // Tests that navigating to a missing page fails |
michael@0 | 366 | add_test(function() { |
michael@0 | 367 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 368 | gManagerWindow = aWindow; |
michael@0 | 369 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 370 | |
michael@0 | 371 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 372 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 373 | |
michael@0 | 374 | clickLink("link-bad", function() { |
michael@0 | 375 | ok(isError(), "Should have shown the error page"); |
michael@0 | 376 | |
michael@0 | 377 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 378 | gCategoryUtilities.openType("discover", function() { |
michael@0 | 379 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 380 | |
michael@0 | 381 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 382 | }); |
michael@0 | 383 | ok(isLoading(), "Should start loading again"); |
michael@0 | 384 | }); |
michael@0 | 385 | }); |
michael@0 | 386 | }); |
michael@0 | 387 | }); |
michael@0 | 388 | |
michael@0 | 389 | // Tests that navigating to a page on the same domain works |
michael@0 | 390 | add_test(function() { |
michael@0 | 391 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 392 | gManagerWindow = aWindow; |
michael@0 | 393 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 394 | |
michael@0 | 395 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 396 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 397 | |
michael@0 | 398 | clickLink("link-good", function() { |
michael@0 | 399 | is(getURL(browser), "https://example.com/" + RELATIVE_DIR + "releaseNotes.xhtml", "Should have loaded the right url"); |
michael@0 | 400 | |
michael@0 | 401 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 402 | gCategoryUtilities.openType("discover", function() { |
michael@0 | 403 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 404 | |
michael@0 | 405 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 406 | }); |
michael@0 | 407 | }); |
michael@0 | 408 | }); |
michael@0 | 409 | }); |
michael@0 | 410 | }); |
michael@0 | 411 | |
michael@0 | 412 | // Tests repeated navigation to the same page followed by a navigation to a |
michael@0 | 413 | // different domain |
michael@0 | 414 | add_test(function() { |
michael@0 | 415 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 416 | gManagerWindow = aWindow; |
michael@0 | 417 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 418 | |
michael@0 | 419 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 420 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 421 | |
michael@0 | 422 | var count = 10; |
michael@0 | 423 | function clickAgain(aCallback) { |
michael@0 | 424 | if (count-- == 0) |
michael@0 | 425 | aCallback(); |
michael@0 | 426 | else |
michael@0 | 427 | clickLink("link-normal", clickAgain.bind(null, aCallback)); |
michael@0 | 428 | } |
michael@0 | 429 | |
michael@0 | 430 | clickAgain(function() { |
michael@0 | 431 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 432 | |
michael@0 | 433 | clickLink("link-domain", function() { |
michael@0 | 434 | ok(isError(), "Should have shown the error page"); |
michael@0 | 435 | |
michael@0 | 436 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 437 | gCategoryUtilities.openType("discover", function() { |
michael@0 | 438 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 439 | |
michael@0 | 440 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 441 | }); |
michael@0 | 442 | ok(isLoading(), "Should start loading again"); |
michael@0 | 443 | }); |
michael@0 | 444 | }); |
michael@0 | 445 | }); |
michael@0 | 446 | }); |
michael@0 | 447 | }); |
michael@0 | 448 | |
michael@0 | 449 | // Loading an insecure main page should work if that is what the prefs say, should |
michael@0 | 450 | // also be able to navigate to a https page and back again |
michael@0 | 451 | add_test(function() { |
michael@0 | 452 | Services.prefs.setCharPref(PREF_DISCOVERURL, TESTROOT + "discovery.html"); |
michael@0 | 453 | |
michael@0 | 454 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 455 | gManagerWindow = aWindow; |
michael@0 | 456 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 457 | |
michael@0 | 458 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 459 | is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url"); |
michael@0 | 460 | |
michael@0 | 461 | clickLink("link-normal", function() { |
michael@0 | 462 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 463 | |
michael@0 | 464 | clickLink("link-http", function() { |
michael@0 | 465 | is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url"); |
michael@0 | 466 | |
michael@0 | 467 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 468 | }); |
michael@0 | 469 | }); |
michael@0 | 470 | }); |
michael@0 | 471 | }); |
michael@0 | 472 | |
michael@0 | 473 | // Stopping the initial load should display the error page and then correctly |
michael@0 | 474 | // reload when switching away and back again |
michael@0 | 475 | add_test(function() { |
michael@0 | 476 | Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL); |
michael@0 | 477 | |
michael@0 | 478 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 479 | gManagerWindow = aWindow; |
michael@0 | 480 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 481 | |
michael@0 | 482 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 483 | |
michael@0 | 484 | EventUtils.synthesizeMouse(gCategoryUtilities.get("discover"), 2, 2, { }, gManagerWindow); |
michael@0 | 485 | |
michael@0 | 486 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 487 | ok(isError(), "Should have shown the error page"); |
michael@0 | 488 | |
michael@0 | 489 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 490 | EventUtils.synthesizeMouse(gCategoryUtilities.get("discover"), 2, 2, { }, gManagerWindow); |
michael@0 | 491 | |
michael@0 | 492 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 493 | ok(isError(), "Should have shown the error page"); |
michael@0 | 494 | |
michael@0 | 495 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 496 | gCategoryUtilities.openType("discover", function() { |
michael@0 | 497 | is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
michael@0 | 498 | |
michael@0 | 499 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 500 | }); |
michael@0 | 501 | }); |
michael@0 | 502 | }); |
michael@0 | 503 | |
michael@0 | 504 | ok(isLoading(), "Should be loading"); |
michael@0 | 505 | // This will stop the real page load |
michael@0 | 506 | browser.stop(); |
michael@0 | 507 | }); |
michael@0 | 508 | }); |
michael@0 | 509 | |
michael@0 | 510 | ok(isLoading(), "Should be loading"); |
michael@0 | 511 | // This will actually stop the about:blank load |
michael@0 | 512 | browser.stop(); |
michael@0 | 513 | }); |
michael@0 | 514 | }); |
michael@0 | 515 | |
michael@0 | 516 | // Test for Bug 703929 - Loading the discover view from a chrome XUL file fails when |
michael@0 | 517 | // the add-on manager is reopened. |
michael@0 | 518 | add_test(function() { |
michael@0 | 519 | const url = "chrome://mochitests/content/" + RELATIVE_DIR + "addon_about.xul"; |
michael@0 | 520 | Services.prefs.setCharPref(PREF_DISCOVERURL, url); |
michael@0 | 521 | |
michael@0 | 522 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 523 | gManagerWindow = aWindow; |
michael@0 | 524 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 525 | |
michael@0 | 526 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 527 | is(getURL(browser), url, "Loading a chrome XUL file should work"); |
michael@0 | 528 | |
michael@0 | 529 | restart_manager(gManagerWindow, "addons://discover/", function(aWindow) { |
michael@0 | 530 | gManagerWindow = aWindow; |
michael@0 | 531 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 532 | |
michael@0 | 533 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 534 | is(getURL(browser), url, "Should be able to load the chrome XUL file a second time"); |
michael@0 | 535 | |
michael@0 | 536 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 537 | }); |
michael@0 | 538 | }); |
michael@0 | 539 | }); |
michael@0 | 540 | |
michael@0 | 541 | // Bug 711693 - Send the compatibility mode when loading the Discovery pane |
michael@0 | 542 | add_test(function() { |
michael@0 | 543 | info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'normal'"); |
michael@0 | 544 | Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL + "?mode=%COMPATIBILITY_MODE%"); |
michael@0 | 545 | Services.prefs.setBoolPref(PREF_STRICT_COMPAT, false); |
michael@0 | 546 | |
michael@0 | 547 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 548 | gManagerWindow = aWindow; |
michael@0 | 549 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 550 | is(getURL(browser), MAIN_URL + "?mode=normal", "Should have loaded the right url"); |
michael@0 | 551 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 552 | }); |
michael@0 | 553 | }); |
michael@0 | 554 | |
michael@0 | 555 | add_test(function() { |
michael@0 | 556 | info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'strict'"); |
michael@0 | 557 | Services.prefs.setBoolPref(PREF_STRICT_COMPAT, true); |
michael@0 | 558 | |
michael@0 | 559 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 560 | gManagerWindow = aWindow; |
michael@0 | 561 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 562 | is(getURL(browser), MAIN_URL + "?mode=strict", "Should have loaded the right url"); |
michael@0 | 563 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 564 | }); |
michael@0 | 565 | }); |
michael@0 | 566 | |
michael@0 | 567 | add_test(function() { |
michael@0 | 568 | info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'ignore'"); |
michael@0 | 569 | Services.prefs.setBoolPref(PREF_CHECK_COMPATIBILITY, false); |
michael@0 | 570 | |
michael@0 | 571 | open_manager("addons://discover/", function(aWindow) { |
michael@0 | 572 | gManagerWindow = aWindow; |
michael@0 | 573 | var browser = gManagerWindow.document.getElementById("discover-browser"); |
michael@0 | 574 | is(getURL(browser), MAIN_URL + "?mode=ignore", "Should have loaded the right url"); |
michael@0 | 575 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 576 | }); |
michael@0 | 577 | }); |
michael@0 | 578 | |
michael@0 | 579 | // Test for Bug 601442 - extensions.getAddons.showPane need to be update |
michael@0 | 580 | // for the new addon manager. |
michael@0 | 581 | function bug_601442_test_elements(visible) { |
michael@0 | 582 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 583 | gManagerWindow = aWindow; |
michael@0 | 584 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 585 | if(visible) |
michael@0 | 586 | ok(gCategoryUtilities.isTypeVisible("discover"), "Discover category should be visible"); |
michael@0 | 587 | else |
michael@0 | 588 | ok(!gCategoryUtilities.isTypeVisible("discover"), "Discover category should not be visible"); |
michael@0 | 589 | |
michael@0 | 590 | gManagerWindow.loadView("addons://list/dictionary"); |
michael@0 | 591 | wait_for_view_load(gManagerWindow, function(aManager) { |
michael@0 | 592 | var button = aManager.document.getElementById("discover-button-install"); |
michael@0 | 593 | if(visible) |
michael@0 | 594 | ok(!is_hidden(button), "Discover button should be visible!"); |
michael@0 | 595 | else |
michael@0 | 596 | ok(is_hidden(button), "Discover button should not be visible!"); |
michael@0 | 597 | |
michael@0 | 598 | close_manager(gManagerWindow, run_next_test); |
michael@0 | 599 | }); |
michael@0 | 600 | }); |
michael@0 | 601 | } |
michael@0 | 602 | |
michael@0 | 603 | add_test(function() { |
michael@0 | 604 | Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, false); |
michael@0 | 605 | Services.prefs.setBoolPref(PREF_XPI_ENABLED, true); |
michael@0 | 606 | bug_601442_test_elements(false); |
michael@0 | 607 | }); |
michael@0 | 608 | add_test(function() { |
michael@0 | 609 | Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, true); |
michael@0 | 610 | Services.prefs.setBoolPref(PREF_XPI_ENABLED, false); |
michael@0 | 611 | bug_601442_test_elements(false); |
michael@0 | 612 | }); |
michael@0 | 613 | add_test(function() { |
michael@0 | 614 | Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, false); |
michael@0 | 615 | Services.prefs.setBoolPref(PREF_XPI_ENABLED, false); |
michael@0 | 616 | bug_601442_test_elements(false); |
michael@0 | 617 | }); |
michael@0 | 618 | add_test(function() { |
michael@0 | 619 | Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, true); |
michael@0 | 620 | Services.prefs.setBoolPref(PREF_XPI_ENABLED, true); |
michael@0 | 621 | bug_601442_test_elements(true); |
michael@0 | 622 | }); |