storage/test/test_service_init_background_thread.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/storage/test/test_service_init_background_thread.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim set:sw=2 ts=2 et lcs=trail\:.,tab\:>~ : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "storage_test_harness.h"
    1.11 +
    1.12 +#include "nsThreadUtils.h"
    1.13 +
    1.14 +/**
    1.15 + * This file tests that the storage service can be initialized off of the main
    1.16 + * thread without issue.
    1.17 + */
    1.18 +
    1.19 +////////////////////////////////////////////////////////////////////////////////
    1.20 +//// Helpers
    1.21 +
    1.22 +class ServiceInitializer : public nsRunnable
    1.23 +{
    1.24 +public:
    1.25 +  NS_IMETHOD Run()
    1.26 +  {
    1.27 +    // Use an explicit do_GetService instead of getService so that the check in
    1.28 +    // getService doesn't blow up.
    1.29 +    nsCOMPtr<mozIStorageService> service = do_GetService("@mozilla.org/storage/service;1");
    1.30 +    do_check_false(service);
    1.31 +    return NS_OK;
    1.32 +  }
    1.33 +};
    1.34 +
    1.35 +////////////////////////////////////////////////////////////////////////////////
    1.36 +//// Test Functions
    1.37 +
    1.38 +void
    1.39 +test_service_initialization_on_background_thread()
    1.40 +{
    1.41 +  nsCOMPtr<nsIRunnable> event = new ServiceInitializer();
    1.42 +  do_check_true(event);
    1.43 +
    1.44 +  nsCOMPtr<nsIThread> thread;
    1.45 +  do_check_success(NS_NewThread(getter_AddRefs(thread)));
    1.46 +
    1.47 +  do_check_success(thread->Dispatch(event, NS_DISPATCH_NORMAL));
    1.48 +
    1.49 +  // Shutting down the thread will spin the event loop until all work in its
    1.50 +  // event queue is completed.  This will act as our thread synchronization.
    1.51 +  do_check_success(thread->Shutdown());
    1.52 +}
    1.53 +
    1.54 +void (*gTests[])(void) = {
    1.55 +  test_service_initialization_on_background_thread,
    1.56 +};
    1.57 +
    1.58 +const char *file = __FILE__;
    1.59 +#define TEST_NAME "Background Thread Initialization"
    1.60 +#define TEST_FILE file
    1.61 +#include "storage_test_harness_tail.h"

mercurial