storage/test/test_service_init_background_thread.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim set:sw=2 ts=2 et lcs=trail\:.,tab\:>~ : */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "storage_test_harness.h"
michael@0 8
michael@0 9 #include "nsThreadUtils.h"
michael@0 10
michael@0 11 /**
michael@0 12 * This file tests that the storage service can be initialized off of the main
michael@0 13 * thread without issue.
michael@0 14 */
michael@0 15
michael@0 16 ////////////////////////////////////////////////////////////////////////////////
michael@0 17 //// Helpers
michael@0 18
michael@0 19 class ServiceInitializer : public nsRunnable
michael@0 20 {
michael@0 21 public:
michael@0 22 NS_IMETHOD Run()
michael@0 23 {
michael@0 24 // Use an explicit do_GetService instead of getService so that the check in
michael@0 25 // getService doesn't blow up.
michael@0 26 nsCOMPtr<mozIStorageService> service = do_GetService("@mozilla.org/storage/service;1");
michael@0 27 do_check_false(service);
michael@0 28 return NS_OK;
michael@0 29 }
michael@0 30 };
michael@0 31
michael@0 32 ////////////////////////////////////////////////////////////////////////////////
michael@0 33 //// Test Functions
michael@0 34
michael@0 35 void
michael@0 36 test_service_initialization_on_background_thread()
michael@0 37 {
michael@0 38 nsCOMPtr<nsIRunnable> event = new ServiceInitializer();
michael@0 39 do_check_true(event);
michael@0 40
michael@0 41 nsCOMPtr<nsIThread> thread;
michael@0 42 do_check_success(NS_NewThread(getter_AddRefs(thread)));
michael@0 43
michael@0 44 do_check_success(thread->Dispatch(event, NS_DISPATCH_NORMAL));
michael@0 45
michael@0 46 // Shutting down the thread will spin the event loop until all work in its
michael@0 47 // event queue is completed. This will act as our thread synchronization.
michael@0 48 do_check_success(thread->Shutdown());
michael@0 49 }
michael@0 50
michael@0 51 void (*gTests[])(void) = {
michael@0 52 test_service_initialization_on_background_thread,
michael@0 53 };
michael@0 54
michael@0 55 const char *file = __FILE__;
michael@0 56 #define TEST_NAME "Background Thread Initialization"
michael@0 57 #define TEST_FILE file
michael@0 58 #include "storage_test_harness_tail.h"

mercurial