toolkit/components/search/tests/xpcshell/test_init_async_multiple.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:88fa3c1ce7c2
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/. */
6
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");
16
17 do_test_pending();
18 updateAppInfo();
19
20 do_print("Test starting");
21 let numberOfInitializers = 4;
22 let pending = [];
23 let numberPending = numberOfInitializers;
24
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 }
34
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);
46
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 }
55

mercurial