Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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"