michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * Test nsSearchService with with the following initialization scenario: michael@0: * - launch asynchronous initialization several times; michael@0: * - all asynchronous initializations must complete. michael@0: * michael@0: * Test case comes from test_645970.js michael@0: */ michael@0: function run_test() { michael@0: do_print("Setting up test"); michael@0: michael@0: do_test_pending(); michael@0: updateAppInfo(); michael@0: michael@0: do_print("Test starting"); michael@0: let numberOfInitializers = 4; michael@0: let pending = []; michael@0: let numberPending = numberOfInitializers; michael@0: michael@0: // Start asynchronous initializations michael@0: for (let i = 0; i < numberOfInitializers; ++i) { michael@0: let me = i; michael@0: pending[me] = true; michael@0: Services.search.init(function search_initialized_0(aStatus) { michael@0: do_check_true(Components.isSuccessCode(aStatus)); michael@0: init_complete(me); michael@0: }); michael@0: } michael@0: michael@0: // Wait until all initializers have completed michael@0: let init_complete = function init_complete(i) { michael@0: do_check_true(pending[i]); michael@0: pending[i] = false; michael@0: numberPending--; michael@0: do_check_true(numberPending >= 0); michael@0: do_check_true(Services.search.isInitialized); michael@0: if (numberPending == 0) { michael@0: // Just check that we can access a list of engines. michael@0: let engines = Services.search.getEngines(); michael@0: do_check_neq(engines, null); michael@0: michael@0: // Wait a little before quitting: if some initializer is michael@0: // triggered twice, we want to catch that error. michael@0: do_timeout(1000, function() { michael@0: do_test_finished(); michael@0: }); michael@0: } michael@0: }; michael@0: } michael@0: