michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim set:sw=2 ts=2 et lcs=trail\:.,tab\:>~ : */ 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: #include "storage_test_harness.h" michael@0: michael@0: #include "nsThreadUtils.h" michael@0: michael@0: /** michael@0: * This file tests that the storage service can be initialized off of the main michael@0: * thread without issue. michael@0: */ michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Helpers michael@0: michael@0: class ServiceInitializer : public nsRunnable michael@0: { michael@0: public: michael@0: NS_IMETHOD Run() michael@0: { michael@0: // Use an explicit do_GetService instead of getService so that the check in michael@0: // getService doesn't blow up. michael@0: nsCOMPtr service = do_GetService("@mozilla.org/storage/service;1"); michael@0: do_check_false(service); michael@0: return NS_OK; michael@0: } michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Test Functions michael@0: michael@0: void michael@0: test_service_initialization_on_background_thread() michael@0: { michael@0: nsCOMPtr event = new ServiceInitializer(); michael@0: do_check_true(event); michael@0: michael@0: nsCOMPtr thread; michael@0: do_check_success(NS_NewThread(getter_AddRefs(thread))); michael@0: michael@0: do_check_success(thread->Dispatch(event, NS_DISPATCH_NORMAL)); michael@0: michael@0: // Shutting down the thread will spin the event loop until all work in its michael@0: // event queue is completed. This will act as our thread synchronization. michael@0: do_check_success(thread->Shutdown()); michael@0: } michael@0: michael@0: void (*gTests[])(void) = { michael@0: test_service_initialization_on_background_thread, michael@0: }; michael@0: michael@0: const char *file = __FILE__; michael@0: #define TEST_NAME "Background Thread Initialization" michael@0: #define TEST_FILE file michael@0: #include "storage_test_harness_tail.h"