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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // Tests that the visible delay in showing the "Language" category occurs
     6 // very minimally
     8 var gManagerWindow;
     9 var gCategoryUtilities;
    10 var gProvider;
    11 var gInstall;
    12 var gInstallProperties = [{
    13   name: "Locale Category Test",
    14   type: "locale"
    15 }];
    17 function test() {
    18   try {
    19     if (Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).D2DEnabled) {
    20       requestLongerTimeout(2);
    21     }
    22   } catch(e) {}
    23   waitForExplicitFinish();
    25   gProvider = new MockProvider();
    27   open_manager("addons://list/extension", function(aWindow) {
    28     gManagerWindow = aWindow;
    29     gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    30     run_next_test();
    31   });
    32 }
    34 function end_test() {
    35   close_manager(gManagerWindow, finish);
    36 }
    38 function install_locale(aCallback) {
    39   gInstall = gProvider.createInstalls(gInstallProperties)[0];
    40   gInstall.addTestListener({
    41     onInstallEnded: function(aInstall) {
    42       gInstall.removeTestListener(this);
    43       aCallback();
    44     }
    45   });
    46   gInstall.install();
    47 }
    49 function check_hidden(aExpectedHidden) {
    50   var hidden = !gCategoryUtilities.isTypeVisible("locale");
    51   is(hidden, !!aExpectedHidden, "Should have correct hidden state");
    52 }
    54 function run_open_test(aTestSetup, aLoadHidden, aInitializedHidden, aSelected) {
    55   function loadCallback(aManagerWindow) {
    56     gManagerWindow = aManagerWindow;
    57     gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    58     check_hidden(aLoadHidden);
    59   }
    61   function run() {
    62     open_manager(null, function() {
    63       check_hidden(aInitializedHidden);
    64       var selected = (gCategoryUtilities.selectedCategory == "locale");
    65       is(selected, !!aSelected, "Should have correct selected state");
    67       run_next_test();
    68     }, loadCallback);
    69   }
    71   close_manager(gManagerWindow, function() {
    72     // Allow for asynchronous functions to run before the manager opens
    73     aTestSetup ? aTestSetup(run) : run();
    74   });
    75 }
    78 // Tests that the locale category is hidden when there are no locales installed
    79 add_test(function() {
    80   run_open_test(null, true, true);
    81 });
    83 // Tests that installing a locale while the Add-on Manager is open shows the
    84 // locale category
    85 add_test(function() {
    86   check_hidden(true);
    87   install_locale(function() {
    88     check_hidden(false);
    89     run_next_test();
    90   });
    91 });
    93 // Tests that the locale category is shown with no delay when restarting
    94 // Add-on Manager
    95 add_test(function() {
    96   run_open_test(null, false, false);
    97 });
    99 // Tests that cancelling the locale install and restarting the Add-on Manager
   100 // causes the locale category to be hidden with an acceptable delay
   101 add_test(function() {
   102   gInstall.cancel();
   103   run_open_test(null, false, true)
   104 });
   106 // Tests that the locale category is hidden with no delay when restarting
   107 // Add-on Manager
   108 add_test(function() {
   109   run_open_test(null, true, true);
   110 });
   112 // Tests that installing a locale when the Add-on Manager is closed, and then
   113 // opening the Add-on Manager causes the locale category to be shown with an
   114 // acceptable delay
   115 add_test(function() {
   116   run_open_test(install_locale, true, false);
   117 });
   119 // Tests that selection of the locale category persists
   120 add_test(function() {
   121   gCategoryUtilities.openType("locale", function() {
   122     run_open_test(null, false, false, true);
   123   });
   124 });
   126 // Tests that cancelling the locale install and restarting the Add-on Manager
   127 // causes the locale category to be hidden and not selected
   128 add_test(function() {
   129   gInstall.cancel();
   130   run_open_test(null, false, true);
   131 });

mercurial