|
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/. */ |
|
6 |
|
7 #include "storage_test_harness.h" |
|
8 |
|
9 #include "nsThreadUtils.h" |
|
10 |
|
11 /** |
|
12 * This file tests that the storage service can be initialized off of the main |
|
13 * thread without issue. |
|
14 */ |
|
15 |
|
16 //////////////////////////////////////////////////////////////////////////////// |
|
17 //// Helpers |
|
18 |
|
19 class ServiceInitializer : public nsRunnable |
|
20 { |
|
21 public: |
|
22 NS_IMETHOD Run() |
|
23 { |
|
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; |
|
29 } |
|
30 }; |
|
31 |
|
32 //////////////////////////////////////////////////////////////////////////////// |
|
33 //// Test Functions |
|
34 |
|
35 void |
|
36 test_service_initialization_on_background_thread() |
|
37 { |
|
38 nsCOMPtr<nsIRunnable> event = new ServiceInitializer(); |
|
39 do_check_true(event); |
|
40 |
|
41 nsCOMPtr<nsIThread> thread; |
|
42 do_check_success(NS_NewThread(getter_AddRefs(thread))); |
|
43 |
|
44 do_check_success(thread->Dispatch(event, NS_DISPATCH_NORMAL)); |
|
45 |
|
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()); |
|
49 } |
|
50 |
|
51 void (*gTests[])(void) = { |
|
52 test_service_initialization_on_background_thread, |
|
53 }; |
|
54 |
|
55 const char *file = __FILE__; |
|
56 #define TEST_NAME "Background Thread Initialization" |
|
57 #define TEST_FILE file |
|
58 #include "storage_test_harness_tail.h" |