toolkit/components/search/tests/xpcshell/test_init_async_multiple.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 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8  * Test nsSearchService with with the following initialization scenario:
     9  * - launch asynchronous initialization several times;
    10  * - all asynchronous initializations must complete.
    11  *
    12  * Test case comes from test_645970.js
    13  */
    14 function run_test() {
    15   do_print("Setting up test");
    17   do_test_pending();
    18   updateAppInfo();
    20   do_print("Test starting");
    21   let numberOfInitializers = 4;
    22   let pending = [];
    23   let numberPending = numberOfInitializers;
    25   // Start asynchronous initializations
    26   for (let i = 0; i < numberOfInitializers; ++i) {
    27     let me = i;
    28     pending[me] = true;
    29     Services.search.init(function search_initialized_0(aStatus) {
    30       do_check_true(Components.isSuccessCode(aStatus));
    31       init_complete(me);
    32     });
    33   }
    35   // Wait until all initializers have completed
    36   let init_complete = function init_complete(i) {
    37     do_check_true(pending[i]);
    38     pending[i] = false;
    39     numberPending--;
    40     do_check_true(numberPending >= 0);
    41     do_check_true(Services.search.isInitialized);
    42     if (numberPending == 0) {
    43       // Just check that we can access a list of engines.
    44       let engines = Services.search.getEngines();
    45       do_check_neq(engines, null);
    47       // Wait a little before quitting: if some initializer is
    48       // triggered twice, we want to catch that error.
    49       do_timeout(1000, function() {
    50         do_test_finished();
    51       });
    52     }
    53   };
    54 }

mercurial