media/mtransport/test/mtransport_test_utils.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
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 file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 // Original author: ekr@rtfm.com
michael@0 8
michael@0 9 #ifndef mtransport_test_utils_h__
michael@0 10 #define mtransport_test_utils_h__
michael@0 11
michael@0 12 #include <iostream>
michael@0 13
michael@0 14 #include "nspr.h"
michael@0 15 #include "nsCOMPtr.h"
michael@0 16 #include "nsNetCID.h"
michael@0 17 #include "nsXPCOMGlue.h"
michael@0 18 #include "nsXPCOM.h"
michael@0 19
michael@0 20 #include "nsIComponentManager.h"
michael@0 21 #include "nsIComponentRegistrar.h"
michael@0 22 #include "nsNetUtil.h"
michael@0 23 #include "nsIIOService.h"
michael@0 24 #include "nsIServiceManager.h"
michael@0 25 #include "nsISocketTransportService.h"
michael@0 26 #include "nsDirectoryServiceUtils.h"
michael@0 27 #include "nsDirectoryServiceDefs.h"
michael@0 28 #ifdef MOZ_CRASHREPORTER
michael@0 29 #include "nsICrashReporter.h"
michael@0 30 #endif
michael@0 31 #include "nsPISocketTransportService.h"
michael@0 32 #include "nsServiceManagerUtils.h"
michael@0 33 #include "TestHarness.h"
michael@0 34
michael@0 35 class MtransportTestUtils {
michael@0 36 public:
michael@0 37 MtransportTestUtils() : xpcom_("") {
michael@0 38 if (!sts_) {
michael@0 39 InitServices();
michael@0 40 }
michael@0 41 }
michael@0 42
michael@0 43 ~MtransportTestUtils() {
michael@0 44 sts_->Shutdown();
michael@0 45 }
michael@0 46
michael@0 47 void InitServices() {
michael@0 48 nsresult rv;
michael@0 49 ioservice_ = do_GetIOService(&rv);
michael@0 50 MOZ_ASSERT(NS_SUCCEEDED(rv));
michael@0 51 sts_target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
michael@0 52 MOZ_ASSERT(NS_SUCCEEDED(rv));
michael@0 53 sts_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
michael@0 54 MOZ_ASSERT(NS_SUCCEEDED(rv));
michael@0 55
michael@0 56 #ifdef MOZ_CRASHREPORTER
michael@0 57 char *crashreporter = PR_GetEnv("MOZ_CRASHREPORTER");
michael@0 58 if (crashreporter && !strcmp(crashreporter, "1")) {
michael@0 59 //TODO: move this to an even-more-common location to use in all
michael@0 60 // C++ unittests
michael@0 61 crashreporter_ = do_GetService("@mozilla.org/toolkit/crash-reporter;1");
michael@0 62 if (crashreporter_) {
michael@0 63 std::cerr << "Setting up crash reporting" << std::endl;
michael@0 64
michael@0 65 nsCOMPtr<nsIProperties> dirsvc =
michael@0 66 do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
michael@0 67 nsCOMPtr<nsIFile> cwd;
michael@0 68 rv = dirsvc->Get(NS_OS_CURRENT_WORKING_DIR,
michael@0 69 NS_GET_IID(nsIFile),
michael@0 70 getter_AddRefs(cwd));
michael@0 71 MOZ_ASSERT(NS_SUCCEEDED(rv));
michael@0 72 crashreporter_->SetEnabled(true);
michael@0 73 crashreporter_->SetMinidumpPath(cwd);
michael@0 74 }
michael@0 75 }
michael@0 76 #endif
michael@0 77 }
michael@0 78
michael@0 79 nsCOMPtr<nsIEventTarget> sts_target() { return sts_target_; }
michael@0 80
michael@0 81 private:
michael@0 82 ScopedXPCOM xpcom_;
michael@0 83 nsCOMPtr<nsIIOService> ioservice_;
michael@0 84 nsCOMPtr<nsIEventTarget> sts_target_;
michael@0 85 nsCOMPtr<nsPISocketTransportService> sts_;
michael@0 86 #ifdef MOZ_CRASHREPORTER
michael@0 87 nsCOMPtr<nsICrashReporter> crashreporter_;
michael@0 88 #endif
michael@0 89 };
michael@0 90
michael@0 91
michael@0 92 MtransportTestUtils *mtransport_test_utils;
michael@0 93
michael@0 94 #define SETUP_MTRANSPORT_TEST_UTILS() \
michael@0 95 MtransportTestUtils utils_; mtransport_test_utils = &utils_
michael@0 96
michael@0 97 #define CHECK_ENVIRONMENT_FLAG(envname) \
michael@0 98 char *test_flag = getenv(envname); \
michael@0 99 if (!test_flag || strcmp(test_flag, "1")) { \
michael@0 100 printf("To run this test set %s=1 in your environment\n", envname); \
michael@0 101 exit(0); \
michael@0 102 } \
michael@0 103
michael@0 104
michael@0 105 #endif
michael@0 106

mercurial