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.

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

mercurial