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

     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.
    14  */
    16 ////////////////////////////////////////////////////////////////////////////////
    17 //// Helpers
    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 };
    32 ////////////////////////////////////////////////////////////////////////////////
    33 //// Test Functions
    35 void
    36 test_service_initialization_on_background_thread()
    37 {
    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());
    49 }
    51 void (*gTests[])(void) = {
    52   test_service_initialization_on_background_thread,
    53 };
    55 const char *file = __FILE__;
    56 #define TEST_NAME "Background Thread Initialization"
    57 #define TEST_FILE file
    58 #include "storage_test_harness_tail.h"

mercurial