1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/search/tests/xpcshell/test_init_async_multiple.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/** 1.11 + * Test nsSearchService with with the following initialization scenario: 1.12 + * - launch asynchronous initialization several times; 1.13 + * - all asynchronous initializations must complete. 1.14 + * 1.15 + * Test case comes from test_645970.js 1.16 + */ 1.17 +function run_test() { 1.18 + do_print("Setting up test"); 1.19 + 1.20 + do_test_pending(); 1.21 + updateAppInfo(); 1.22 + 1.23 + do_print("Test starting"); 1.24 + let numberOfInitializers = 4; 1.25 + let pending = []; 1.26 + let numberPending = numberOfInitializers; 1.27 + 1.28 + // Start asynchronous initializations 1.29 + for (let i = 0; i < numberOfInitializers; ++i) { 1.30 + let me = i; 1.31 + pending[me] = true; 1.32 + Services.search.init(function search_initialized_0(aStatus) { 1.33 + do_check_true(Components.isSuccessCode(aStatus)); 1.34 + init_complete(me); 1.35 + }); 1.36 + } 1.37 + 1.38 + // Wait until all initializers have completed 1.39 + let init_complete = function init_complete(i) { 1.40 + do_check_true(pending[i]); 1.41 + pending[i] = false; 1.42 + numberPending--; 1.43 + do_check_true(numberPending >= 0); 1.44 + do_check_true(Services.search.isInitialized); 1.45 + if (numberPending == 0) { 1.46 + // Just check that we can access a list of engines. 1.47 + let engines = Services.search.getEngines(); 1.48 + do_check_neq(engines, null); 1.49 + 1.50 + // Wait a little before quitting: if some initializer is 1.51 + // triggered twice, we want to catch that error. 1.52 + do_timeout(1000, function() { 1.53 + do_test_finished(); 1.54 + }); 1.55 + } 1.56 + }; 1.57 +} 1.58 +