toolkit/mozapps/extensions/test/browser/browser_bug577990.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_bug577990.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     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 visible delay in showing the "Language" category occurs
     1.9 +// very minimally
    1.10 +
    1.11 +var gManagerWindow;
    1.12 +var gCategoryUtilities;
    1.13 +var gProvider;
    1.14 +var gInstall;
    1.15 +var gInstallProperties = [{
    1.16 +  name: "Locale Category Test",
    1.17 +  type: "locale"
    1.18 +}];
    1.19 +
    1.20 +function test() {
    1.21 +  try {
    1.22 +    if (Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).D2DEnabled) {
    1.23 +      requestLongerTimeout(2);
    1.24 +    }
    1.25 +  } catch(e) {}
    1.26 +  waitForExplicitFinish();
    1.27 +
    1.28 +  gProvider = new MockProvider();
    1.29 +
    1.30 +  open_manager("addons://list/extension", function(aWindow) {
    1.31 +    gManagerWindow = aWindow;
    1.32 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    1.33 +    run_next_test();
    1.34 +  });
    1.35 +}
    1.36 +
    1.37 +function end_test() {
    1.38 +  close_manager(gManagerWindow, finish);
    1.39 +}
    1.40 +
    1.41 +function install_locale(aCallback) {
    1.42 +  gInstall = gProvider.createInstalls(gInstallProperties)[0];
    1.43 +  gInstall.addTestListener({
    1.44 +    onInstallEnded: function(aInstall) {
    1.45 +      gInstall.removeTestListener(this);
    1.46 +      aCallback();
    1.47 +    }
    1.48 +  });
    1.49 +  gInstall.install();
    1.50 +}
    1.51 +
    1.52 +function check_hidden(aExpectedHidden) {
    1.53 +  var hidden = !gCategoryUtilities.isTypeVisible("locale");
    1.54 +  is(hidden, !!aExpectedHidden, "Should have correct hidden state");
    1.55 +}
    1.56 +
    1.57 +function run_open_test(aTestSetup, aLoadHidden, aInitializedHidden, aSelected) {
    1.58 +  function loadCallback(aManagerWindow) {
    1.59 +    gManagerWindow = aManagerWindow;
    1.60 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    1.61 +    check_hidden(aLoadHidden);
    1.62 +  }
    1.63 +
    1.64 +  function run() {
    1.65 +    open_manager(null, function() {
    1.66 +      check_hidden(aInitializedHidden);
    1.67 +      var selected = (gCategoryUtilities.selectedCategory == "locale");
    1.68 +      is(selected, !!aSelected, "Should have correct selected state");
    1.69 +
    1.70 +      run_next_test();
    1.71 +    }, loadCallback);
    1.72 +  }
    1.73 +
    1.74 +  close_manager(gManagerWindow, function() {
    1.75 +    // Allow for asynchronous functions to run before the manager opens
    1.76 +    aTestSetup ? aTestSetup(run) : run();
    1.77 +  });
    1.78 +}
    1.79 +
    1.80 +
    1.81 +// Tests that the locale category is hidden when there are no locales installed
    1.82 +add_test(function() {
    1.83 +  run_open_test(null, true, true);
    1.84 +});
    1.85 +
    1.86 +// Tests that installing a locale while the Add-on Manager is open shows the
    1.87 +// locale category
    1.88 +add_test(function() {
    1.89 +  check_hidden(true);
    1.90 +  install_locale(function() {
    1.91 +    check_hidden(false);
    1.92 +    run_next_test();
    1.93 +  });
    1.94 +});
    1.95 +
    1.96 +// Tests that the locale category is shown with no delay when restarting
    1.97 +// Add-on Manager
    1.98 +add_test(function() {
    1.99 +  run_open_test(null, false, false);
   1.100 +});
   1.101 +
   1.102 +// Tests that cancelling the locale install and restarting the Add-on Manager
   1.103 +// causes the locale category to be hidden with an acceptable delay
   1.104 +add_test(function() {
   1.105 +  gInstall.cancel();
   1.106 +  run_open_test(null, false, true)
   1.107 +});
   1.108 +
   1.109 +// Tests that the locale category is hidden with no delay when restarting
   1.110 +// Add-on Manager
   1.111 +add_test(function() {
   1.112 +  run_open_test(null, true, true);
   1.113 +});
   1.114 +
   1.115 +// Tests that installing a locale when the Add-on Manager is closed, and then
   1.116 +// opening the Add-on Manager causes the locale category to be shown with an
   1.117 +// acceptable delay
   1.118 +add_test(function() {
   1.119 +  run_open_test(install_locale, true, false);
   1.120 +});
   1.121 +
   1.122 +// Tests that selection of the locale category persists
   1.123 +add_test(function() {
   1.124 +  gCategoryUtilities.openType("locale", function() {
   1.125 +    run_open_test(null, false, false, true);
   1.126 +  });
   1.127 +});
   1.128 +
   1.129 +// Tests that cancelling the locale install and restarting the Add-on Manager
   1.130 +// causes the locale category to be hidden and not selected
   1.131 +add_test(function() {
   1.132 +  gInstall.cancel();
   1.133 +  run_open_test(null, false, true);
   1.134 +});
   1.135 +

mercurial