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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_discovery.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,622 @@
     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 the discovery view loads properly
     1.9 +
    1.10 +const MAIN_URL = "https://example.com/" + RELATIVE_DIR + "discovery.html";
    1.11 +
    1.12 +var gManagerWindow;
    1.13 +var gCategoryUtilities;
    1.14 +var gProvider;
    1.15 +
    1.16 +var gLoadCompleteCallback = null;
    1.17 +
    1.18 +var gProgressListener = {
    1.19 +  onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
    1.20 +    // Only care about the network stop status events
    1.21 +    if (!(aStateFlags & (Ci.nsIWebProgressListener.STATE_IS_NETWORK)) ||
    1.22 +        !(aStateFlags & (Ci.nsIWebProgressListener.STATE_STOP)))
    1.23 +      return;
    1.24 +
    1.25 +    if (gLoadCompleteCallback)
    1.26 +      executeSoon(gLoadCompleteCallback);
    1.27 +    gLoadCompleteCallback = null;
    1.28 +  },
    1.29 +
    1.30 +  onLocationChange: function() { },
    1.31 +  onSecurityChange: function() { },
    1.32 +  onProgressChange: function() { },
    1.33 +  onStatusChange: function() { },
    1.34 +
    1.35 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
    1.36 +                                         Ci.nsISupportsWeakReference]),
    1.37 +};
    1.38 +
    1.39 +function test() {
    1.40 +  // Switch to a known url
    1.41 +  Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL);
    1.42 +  // Temporarily enable caching
    1.43 +  Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
    1.44 +
    1.45 +  waitForExplicitFinish();
    1.46 +
    1.47 +  gProvider = new MockProvider();
    1.48 +
    1.49 +  gProvider.createAddons([{
    1.50 +    id: "addon1@tests.mozilla.org",
    1.51 +    name: "Test add-on 1",
    1.52 +    type: "extension",
    1.53 +    version: "2.2",
    1.54 +    isCompatible: false,
    1.55 +    blocklistState: Ci.nsIBlocklistService.STATE_SOFTBLOCKED,
    1.56 +    userDisabled: false
    1.57 +  }, {
    1.58 +    id: "addon2@tests.mozilla.org",
    1.59 +    name: "Test add-on 2",
    1.60 +    type: "plugin",
    1.61 +    version: "3.1.5",
    1.62 +    isCompatible: true,
    1.63 +    blocklistState: Ci.nsIBlocklistService.STATE_NOT_BLOCKED,
    1.64 +    userDisabled: false
    1.65 +  }, {
    1.66 +    id: "addon3@tests.mozilla.org",
    1.67 +    name: "Test add-on 3",
    1.68 +    type: "theme",
    1.69 +    version: "1.2b1",
    1.70 +    isCompatible: false,
    1.71 +    blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED,
    1.72 +    userDisabled: true
    1.73 +  }]);
    1.74 +
    1.75 +  run_next_test();
    1.76 +}
    1.77 +
    1.78 +function end_test() {
    1.79 +  finish();
    1.80 +}
    1.81 +
    1.82 +function getURL(aBrowser) {
    1.83 +  if (gManagerWindow.document.getElementById("discover-view").selectedPanel !=
    1.84 +      aBrowser)
    1.85 +    return null;
    1.86 +
    1.87 +  var url = aBrowser.currentURI.spec;
    1.88 +  var pos = url.indexOf("#");
    1.89 +  if (pos != -1)
    1.90 +    return url.substring(0, pos);
    1.91 +  return url;
    1.92 +}
    1.93 +
    1.94 +function getHash(aBrowser) {
    1.95 +  if (gManagerWindow.document.getElementById("discover-view").selectedPanel !=
    1.96 +      aBrowser)
    1.97 +    return null;
    1.98 +
    1.99 +  var url = aBrowser.currentURI.spec;
   1.100 +  var pos = url.indexOf("#");
   1.101 +  if (pos != -1)
   1.102 +    return decodeURIComponent(url.substring(pos + 1));
   1.103 +  return null;
   1.104 +}
   1.105 +
   1.106 +function testHash(aBrowser, aTestAddonVisible, aCallback) {
   1.107 +  var hash = getHash(aBrowser);
   1.108 +  isnot(hash, null, "There should be a hash");
   1.109 +  try {
   1.110 +    var data = JSON.parse(hash);
   1.111 +  }
   1.112 +  catch (e) {
   1.113 +    ok(false, "Hash should have been valid JSON: " + e);
   1.114 +    aCallback();
   1.115 +    return;
   1.116 +  }
   1.117 +  is(typeof data, "object", "Hash should be a JS object");
   1.118 +
   1.119 +  // Ensure that at least the test add-ons are present
   1.120 +  if (aTestAddonVisible[0])
   1.121 +    ok("addon1@tests.mozilla.org" in data, "Test add-on 1 should be listed");
   1.122 +  else
   1.123 +    ok(!("addon1@tests.mozilla.org" in data), "Test add-on 1 should not be listed");
   1.124 +  if (aTestAddonVisible[1])
   1.125 +    ok("addon2@tests.mozilla.org" in data, "Test add-on 2 should be listed");
   1.126 +  else
   1.127 +    ok(!("addon2@tests.mozilla.org" in data), "Test add-on 2 should not be listed");
   1.128 +  if (aTestAddonVisible[2])
   1.129 +    ok("addon3@tests.mozilla.org" in data, "Test add-on 3 should be listed");
   1.130 +  else
   1.131 +    ok(!("addon3@tests.mozilla.org" in data), "Test add-on 3 should not be listed");
   1.132 +
   1.133 +  // Test against all the add-ons the manager knows about since plugins and
   1.134 +  // app extensions may exist
   1.135 +  AddonManager.getAllAddons(function(aAddons) {
   1.136 +    for (let addon of aAddons) {
   1.137 +      if (!(addon.id in data)) {
   1.138 +        // Test add-ons will have shown an error if necessary above
   1.139 +        if (addon.id.substring(6) != "@tests.mozilla.org")
   1.140 +          ok(false, "Add-on " + addon.id + " was not included in the data");
   1.141 +        continue;
   1.142 +      }
   1.143 +
   1.144 +      info("Testing data for add-on " + addon.id);
   1.145 +      var addonData = data[addon.id];
   1.146 +      is(addonData.name, addon.name, "Name should be correct");
   1.147 +      is(addonData.version, addon.version, "Version should be correct");
   1.148 +      is(addonData.type, addon.type, "Type should be correct");
   1.149 +      is(addonData.userDisabled, addon.userDisabled, "userDisabled should be correct");
   1.150 +      is(addonData.isBlocklisted, addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED, "blocklisted should be correct");
   1.151 +      is(addonData.isCompatible, addon.isCompatible, "isCompatible should be correct");
   1.152 +    }
   1.153 +    aCallback();
   1.154 +  });
   1.155 +}
   1.156 +
   1.157 +function isLoading() {
   1.158 +  var loading = gManagerWindow.document.getElementById("discover-view").selectedPanel ==
   1.159 +                gManagerWindow.document.getElementById("discover-loading");
   1.160 +  if (loading) {
   1.161 +    is_element_visible(gManagerWindow.document.querySelector("#discover-loading .loading"),
   1.162 +                       "Loading message should be visible when its panel is the selected panel");
   1.163 +  }
   1.164 +  return loading;
   1.165 +}
   1.166 +
   1.167 +function isError() {
   1.168 +  return gManagerWindow.document.getElementById("discover-view").selectedPanel ==
   1.169 +         gManagerWindow.document.getElementById("discover-error");
   1.170 +}
   1.171 +
   1.172 +function clickLink(aId, aCallback) {
   1.173 +  var browser = gManagerWindow.document.getElementById("discover-browser");
   1.174 +  browser.addProgressListener(gProgressListener);
   1.175 +
   1.176 +  gLoadCompleteCallback = function() {
   1.177 +    browser.removeProgressListener(gProgressListener);
   1.178 +    aCallback();
   1.179 +  };
   1.180 +
   1.181 +  var link = browser.contentDocument.getElementById(aId);
   1.182 +  EventUtils.sendMouseEvent({type: "click"}, link);
   1.183 +
   1.184 +  executeSoon(function() {
   1.185 +    ok(isLoading(), "Clicking a link should show the loading pane");
   1.186 +  });
   1.187 +}
   1.188 +
   1.189 +// Tests that switching to the discovery view displays the right url
   1.190 +add_test(function() {
   1.191 +  open_manager("addons://list/extension", function(aWindow) {
   1.192 +    gManagerWindow = aWindow;
   1.193 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.194 +
   1.195 +    gCategoryUtilities.openType("discover", function() {
   1.196 +      var browser = gManagerWindow.document.getElementById("discover-browser");
   1.197 +      is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.198 +
   1.199 +      testHash(browser, [true, true, true], function() {
   1.200 +        close_manager(gManagerWindow, run_next_test);
   1.201 +      });
   1.202 +    });
   1.203 +
   1.204 +    ok(isLoading(), "Should be loading at first");
   1.205 +  });
   1.206 +});
   1.207 +
   1.208 +// Tests that loading the add-ons manager with the discovery view as the last
   1.209 +// selected view displays the right url
   1.210 +add_test(function() {
   1.211 +  // Hide one of the test add-ons
   1.212 +  Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false);
   1.213 +  Services.prefs.setBoolPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled", true);
   1.214 +
   1.215 +  open_manager(null, function(aWindow) {
   1.216 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.217 +    is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view");
   1.218 +
   1.219 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.220 +    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.221 +
   1.222 +    testHash(browser, [true, false, true], function() {
   1.223 +      close_manager(gManagerWindow, run_next_test);
   1.224 +    });
   1.225 +  }, function(aWindow) {
   1.226 +    gManagerWindow = aWindow;
   1.227 +    ok(isLoading(), "Should be loading at first");
   1.228 +  });
   1.229 +});
   1.230 +
   1.231 +// Tests that loading the add-ons manager with the discovery view as the initial
   1.232 +// view displays the right url
   1.233 +add_test(function() {
   1.234 +  Services.prefs.clearUserPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled");
   1.235 +  Services.prefs.setBoolPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled", false);
   1.236 +
   1.237 +  open_manager(null, function(aWindow) {
   1.238 +    gManagerWindow = aWindow;
   1.239 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.240 +    gCategoryUtilities.openType("extension", function() {
   1.241 +      close_manager(gManagerWindow, function() {
   1.242 +        open_manager("addons://discover/", function(aWindow) {
   1.243 +          gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.244 +          is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view");
   1.245 +
   1.246 +          var browser = gManagerWindow.document.getElementById("discover-browser");
   1.247 +          is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.248 +
   1.249 +          testHash(browser, [true, true, false], function() {
   1.250 +            Services.prefs.clearUserPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled");
   1.251 +            close_manager(gManagerWindow, run_next_test);
   1.252 +          });
   1.253 +        }, function(aWindow) {
   1.254 +          gManagerWindow = aWindow;
   1.255 +          ok(isLoading(), "Should be loading at first");
   1.256 +        });
   1.257 +      });
   1.258 +    });
   1.259 +  });
   1.260 +});
   1.261 +
   1.262 +// Tests that switching to the discovery view displays the right url
   1.263 +add_test(function() {
   1.264 +  Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false);
   1.265 +
   1.266 +  open_manager("addons://list/extension", function(aWindow) {
   1.267 +    gManagerWindow = aWindow;
   1.268 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.269 +
   1.270 +    gCategoryUtilities.openType("discover", function() {
   1.271 +      var browser = gManagerWindow.document.getElementById("discover-browser");
   1.272 +      is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.273 +
   1.274 +      is(getHash(browser), null, "Hash should not have been passed");
   1.275 +      close_manager(gManagerWindow, run_next_test);
   1.276 +    });
   1.277 +  });
   1.278 +});
   1.279 +
   1.280 +// Tests that loading the add-ons manager with the discovery view as the last
   1.281 +// selected view displays the right url
   1.282 +add_test(function() {
   1.283 +  open_manager(null, function(aWindow) {
   1.284 +    gManagerWindow = aWindow;
   1.285 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.286 +    is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view");
   1.287 +
   1.288 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.289 +    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.290 +
   1.291 +    is(getHash(browser), null, "Hash should not have been passed");
   1.292 +    close_manager(gManagerWindow, run_next_test);
   1.293 +  });
   1.294 +});
   1.295 +
   1.296 +// Tests that loading the add-ons manager with the discovery view as the initial
   1.297 +// view displays the right url
   1.298 +add_test(function() {
   1.299 +  open_manager(null, function(aWindow) {
   1.300 +    gManagerWindow = aWindow;
   1.301 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.302 +    gCategoryUtilities.openType("extension", function() {
   1.303 +      close_manager(gManagerWindow, function() {
   1.304 +        open_manager("addons://discover/", function(aWindow) {
   1.305 +          gManagerWindow = aWindow;
   1.306 +          gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.307 +          is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view");
   1.308 +
   1.309 +          var browser = gManagerWindow.document.getElementById("discover-browser");
   1.310 +          is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.311 +
   1.312 +          is(getHash(browser), null, "Hash should not have been passed");
   1.313 +          close_manager(gManagerWindow, run_next_test);
   1.314 +        });
   1.315 +      });
   1.316 +    });
   1.317 +  });
   1.318 +});
   1.319 +
   1.320 +// Tests that navigating to an insecure page fails
   1.321 +add_test(function() {
   1.322 +  open_manager("addons://discover/", function(aWindow) {
   1.323 +    gManagerWindow = aWindow;
   1.324 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.325 +
   1.326 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.327 +    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.328 +
   1.329 +    clickLink("link-http", function() {
   1.330 +      ok(isError(), "Should have shown the error page");
   1.331 +
   1.332 +      gCategoryUtilities.openType("extension", function() {
   1.333 +        gCategoryUtilities.openType("discover", function() {
   1.334 +          is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.335 +
   1.336 +          close_manager(gManagerWindow, run_next_test);
   1.337 +        });
   1.338 +        ok(isLoading(), "Should start loading again");
   1.339 +      });
   1.340 +    });
   1.341 +  });
   1.342 +});
   1.343 +
   1.344 +// Tests that navigating to a different domain fails
   1.345 +add_test(function() {
   1.346 +  open_manager("addons://discover/", function(aWindow) {
   1.347 +    gManagerWindow = aWindow;
   1.348 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.349 +
   1.350 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.351 +    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.352 +
   1.353 +    clickLink("link-domain", function() {
   1.354 +      ok(isError(), "Should have shown the error page");
   1.355 +
   1.356 +      gCategoryUtilities.openType("extension", function() {
   1.357 +        gCategoryUtilities.openType("discover", function() {
   1.358 +          is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.359 +
   1.360 +          close_manager(gManagerWindow, run_next_test);
   1.361 +        });
   1.362 +        ok(isLoading(), "Should start loading again");
   1.363 +      });
   1.364 +    });
   1.365 +  });
   1.366 +});
   1.367 +
   1.368 +// Tests that navigating to a missing page fails
   1.369 +add_test(function() {
   1.370 +  open_manager("addons://discover/", function(aWindow) {
   1.371 +    gManagerWindow = aWindow;
   1.372 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.373 +
   1.374 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.375 +    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.376 +
   1.377 +    clickLink("link-bad", function() {
   1.378 +      ok(isError(), "Should have shown the error page");
   1.379 +
   1.380 +      gCategoryUtilities.openType("extension", function() {
   1.381 +        gCategoryUtilities.openType("discover", function() {
   1.382 +          is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.383 +
   1.384 +          close_manager(gManagerWindow, run_next_test);
   1.385 +        });
   1.386 +        ok(isLoading(), "Should start loading again");
   1.387 +      });
   1.388 +    });
   1.389 +  });
   1.390 +});
   1.391 +
   1.392 +// Tests that navigating to a page on the same domain works
   1.393 +add_test(function() {
   1.394 +  open_manager("addons://discover/", function(aWindow) {
   1.395 +    gManagerWindow = aWindow;
   1.396 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.397 +
   1.398 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.399 +    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.400 +
   1.401 +    clickLink("link-good", function() {
   1.402 +      is(getURL(browser), "https://example.com/" + RELATIVE_DIR + "releaseNotes.xhtml", "Should have loaded the right url");
   1.403 +
   1.404 +      gCategoryUtilities.openType("extension", function() {
   1.405 +        gCategoryUtilities.openType("discover", function() {
   1.406 +          is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.407 +
   1.408 +          close_manager(gManagerWindow, run_next_test);
   1.409 +        });
   1.410 +      });
   1.411 +    });
   1.412 +  });
   1.413 +});
   1.414 +
   1.415 +// Tests repeated navigation to the same page followed by a navigation to a
   1.416 +// different domain
   1.417 +add_test(function() {
   1.418 +  open_manager("addons://discover/", function(aWindow) {
   1.419 +    gManagerWindow = aWindow;
   1.420 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.421 +
   1.422 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.423 +    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.424 +
   1.425 +    var count = 10;
   1.426 +    function clickAgain(aCallback) {
   1.427 +      if (count-- == 0)
   1.428 +        aCallback();
   1.429 +      else
   1.430 +        clickLink("link-normal", clickAgain.bind(null, aCallback));
   1.431 +    }
   1.432 +
   1.433 +    clickAgain(function() {
   1.434 +      is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.435 +
   1.436 +      clickLink("link-domain", function() {
   1.437 +        ok(isError(), "Should have shown the error page");
   1.438 +
   1.439 +        gCategoryUtilities.openType("extension", function() {
   1.440 +          gCategoryUtilities.openType("discover", function() {
   1.441 +            is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.442 +
   1.443 +            close_manager(gManagerWindow, run_next_test);
   1.444 +          });
   1.445 +          ok(isLoading(), "Should start loading again");
   1.446 +        });
   1.447 +      });
   1.448 +    });
   1.449 +  });
   1.450 +});
   1.451 +
   1.452 +// Loading an insecure main page should work if that is what the prefs say, should
   1.453 +// also be able to navigate to a https page and back again
   1.454 +add_test(function() {
   1.455 +  Services.prefs.setCharPref(PREF_DISCOVERURL, TESTROOT + "discovery.html");
   1.456 +
   1.457 +  open_manager("addons://discover/", function(aWindow) {
   1.458 +    gManagerWindow = aWindow;
   1.459 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.460 +
   1.461 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.462 +    is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url");
   1.463 +
   1.464 +    clickLink("link-normal", function() {
   1.465 +      is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.466 +
   1.467 +      clickLink("link-http", function() {
   1.468 +        is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url");
   1.469 +
   1.470 +        close_manager(gManagerWindow, run_next_test);
   1.471 +      });
   1.472 +    });
   1.473 +  });
   1.474 +});
   1.475 +
   1.476 +// Stopping the initial load should display the error page and then correctly
   1.477 +// reload when switching away and back again
   1.478 +add_test(function() {
   1.479 +  Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL);
   1.480 +
   1.481 +  open_manager("addons://list/extension", function(aWindow) {
   1.482 +    gManagerWindow = aWindow;
   1.483 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.484 +
   1.485 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.486 +
   1.487 +    EventUtils.synthesizeMouse(gCategoryUtilities.get("discover"), 2, 2, { }, gManagerWindow);
   1.488 +
   1.489 +    wait_for_view_load(gManagerWindow, function() {
   1.490 +      ok(isError(), "Should have shown the error page");
   1.491 +
   1.492 +      gCategoryUtilities.openType("extension", function() {
   1.493 +        EventUtils.synthesizeMouse(gCategoryUtilities.get("discover"), 2, 2, { }, gManagerWindow);
   1.494 +
   1.495 +        wait_for_view_load(gManagerWindow, function() {
   1.496 +          ok(isError(), "Should have shown the error page");
   1.497 +
   1.498 +          gCategoryUtilities.openType("extension", function() {
   1.499 +            gCategoryUtilities.openType("discover", function() {
   1.500 +              is(getURL(browser), MAIN_URL, "Should have loaded the right url");
   1.501 +
   1.502 +              close_manager(gManagerWindow, run_next_test);
   1.503 +            });
   1.504 +          });
   1.505 +        });
   1.506 +
   1.507 +        ok(isLoading(), "Should be loading");
   1.508 +        // This will stop the real page load
   1.509 +        browser.stop();
   1.510 +      });
   1.511 +    });
   1.512 +
   1.513 +    ok(isLoading(), "Should be loading");
   1.514 +    // This will actually stop the about:blank load
   1.515 +    browser.stop();
   1.516 +  });
   1.517 +});
   1.518 +
   1.519 +// Test for Bug 703929 - Loading the discover view from a chrome XUL file fails when
   1.520 +// the add-on manager is reopened.
   1.521 +add_test(function() {
   1.522 +  const url = "chrome://mochitests/content/" +  RELATIVE_DIR + "addon_about.xul";
   1.523 +  Services.prefs.setCharPref(PREF_DISCOVERURL, url);
   1.524 +
   1.525 +  open_manager("addons://discover/", function(aWindow) {
   1.526 +    gManagerWindow = aWindow;
   1.527 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.528 +
   1.529 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.530 +    is(getURL(browser), url, "Loading a chrome XUL file should work");
   1.531 +
   1.532 +    restart_manager(gManagerWindow, "addons://discover/", function(aWindow) {
   1.533 +      gManagerWindow = aWindow;
   1.534 +      gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.535 +
   1.536 +      var browser = gManagerWindow.document.getElementById("discover-browser");
   1.537 +      is(getURL(browser), url, "Should be able to load the chrome XUL file a second time");
   1.538 +
   1.539 +      close_manager(gManagerWindow, run_next_test);
   1.540 +    });
   1.541 +  });
   1.542 +});
   1.543 +
   1.544 +// Bug 711693 - Send the compatibility mode when loading the Discovery pane
   1.545 +add_test(function() {
   1.546 +  info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'normal'");
   1.547 +  Services.prefs.setCharPref(PREF_DISCOVERURL,  MAIN_URL + "?mode=%COMPATIBILITY_MODE%");
   1.548 +  Services.prefs.setBoolPref(PREF_STRICT_COMPAT, false);
   1.549 +
   1.550 +  open_manager("addons://discover/", function(aWindow) {
   1.551 +    gManagerWindow = aWindow;
   1.552 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.553 +    is(getURL(browser), MAIN_URL + "?mode=normal", "Should have loaded the right url");
   1.554 +    close_manager(gManagerWindow, run_next_test);
   1.555 +  });
   1.556 +});
   1.557 +
   1.558 +add_test(function() {
   1.559 +  info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'strict'");
   1.560 +  Services.prefs.setBoolPref(PREF_STRICT_COMPAT, true);
   1.561 +
   1.562 +  open_manager("addons://discover/", function(aWindow) {
   1.563 +    gManagerWindow = aWindow;
   1.564 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.565 +    is(getURL(browser), MAIN_URL + "?mode=strict", "Should have loaded the right url");
   1.566 +    close_manager(gManagerWindow, run_next_test);
   1.567 +  });
   1.568 +});
   1.569 +
   1.570 +add_test(function() {
   1.571 +  info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'ignore'");
   1.572 +  Services.prefs.setBoolPref(PREF_CHECK_COMPATIBILITY, false);
   1.573 +
   1.574 +  open_manager("addons://discover/", function(aWindow) {
   1.575 +    gManagerWindow = aWindow;
   1.576 +    var browser = gManagerWindow.document.getElementById("discover-browser");
   1.577 +    is(getURL(browser), MAIN_URL + "?mode=ignore", "Should have loaded the right url");
   1.578 +    close_manager(gManagerWindow, run_next_test);
   1.579 +  });
   1.580 +});
   1.581 +
   1.582 +// Test for Bug 601442 - extensions.getAddons.showPane need to be update 
   1.583 +// for the new addon manager.
   1.584 +function bug_601442_test_elements(visible) {
   1.585 +  open_manager("addons://list/extension", function(aWindow) {
   1.586 +    gManagerWindow = aWindow;
   1.587 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.588 +    if(visible)
   1.589 +      ok(gCategoryUtilities.isTypeVisible("discover"), "Discover category should be visible");
   1.590 +    else
   1.591 +      ok(!gCategoryUtilities.isTypeVisible("discover"), "Discover category should not be visible");
   1.592 +
   1.593 +    gManagerWindow.loadView("addons://list/dictionary");
   1.594 +    wait_for_view_load(gManagerWindow, function(aManager) {
   1.595 +      var button = aManager.document.getElementById("discover-button-install");
   1.596 +      if(visible)
   1.597 +        ok(!is_hidden(button), "Discover button should be visible!");
   1.598 +      else
   1.599 +        ok(is_hidden(button), "Discover button should not be visible!");
   1.600 +
   1.601 +      close_manager(gManagerWindow, run_next_test);
   1.602 +    });
   1.603 +  });
   1.604 +}
   1.605 +
   1.606 +add_test(function() {
   1.607 +  Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, false);
   1.608 +  Services.prefs.setBoolPref(PREF_XPI_ENABLED, true);
   1.609 +  bug_601442_test_elements(false);
   1.610 +});
   1.611 +add_test(function() {
   1.612 +  Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, true);
   1.613 +  Services.prefs.setBoolPref(PREF_XPI_ENABLED, false);
   1.614 +  bug_601442_test_elements(false);
   1.615 +});
   1.616 +add_test(function() {
   1.617 +  Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, false);
   1.618 +  Services.prefs.setBoolPref(PREF_XPI_ENABLED, false);
   1.619 +  bug_601442_test_elements(false);
   1.620 +});
   1.621 +add_test(function() {
   1.622 +  Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, true);
   1.623 +  Services.prefs.setBoolPref(PREF_XPI_ENABLED, true);
   1.624 +  bug_601442_test_elements(true);
   1.625 +});

mercurial