Bumping manifests a=b2g-bump
[gecko.git] / storage / test / test_service_init_background_thread.cpp
blob566c59ebf3e02e51f231b1de728c455127f97707
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim set:sw=2 ts=2 et lcs=trail\:.,tab\:>~ : */
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/. */
7 #include "storage_test_harness.h"
9 #include "nsThreadUtils.h"
11 /**
12 * This file tests that the storage service can be initialized off of the main
13 * thread without issue.
16 ////////////////////////////////////////////////////////////////////////////////
17 //// Helpers
19 class ServiceInitializer : public nsRunnable
21 public:
22 NS_IMETHOD Run()
24 // Use an explicit do_GetService instead of getService so that the check in
25 // getService doesn't blow up.
26 nsCOMPtr<mozIStorageService> service = do_GetService("@mozilla.org/storage/service;1");
27 do_check_false(service);
28 return NS_OK;
32 ////////////////////////////////////////////////////////////////////////////////
33 //// Test Functions
35 void
36 test_service_initialization_on_background_thread()
38 nsCOMPtr<nsIRunnable> event = new ServiceInitializer();
39 do_check_true(event);
41 nsCOMPtr<nsIThread> thread;
42 do_check_success(NS_NewThread(getter_AddRefs(thread)));
44 do_check_success(thread->Dispatch(event, NS_DISPATCH_NORMAL));
46 // Shutting down the thread will spin the event loop until all work in its
47 // event queue is completed. This will act as our thread synchronization.
48 do_check_success(thread->Shutdown());
51 void (*gTests[])(void) = {
52 test_service_initialization_on_background_thread,
55 const char *file = __FILE__;
56 #define TEST_NAME "Background Thread Initialization"
57 #define TEST_FILE file
58 #include "storage_test_harness_tail.h"