media/mtransport/test/TestSyncRunnable.cpp

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.

     1 /* -*- Mode: C++; tab-width: 12; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsThreadUtils.h"
     7 #include "mozilla/SyncRunnable.h"
     9 #include "gtest/gtest.h"
    11 using namespace mozilla;
    13 nsIThread *gThread = nullptr;
    15 class TestRunnable : public nsRunnable {
    16 public:
    17   TestRunnable() : ran_(false) {}
    19   NS_IMETHOD Run()
    20   {
    21     ran_ = true;
    23     return NS_OK;
    24   }
    26   bool ran() const { return ran_; }
    28 private:
    29   bool ran_;
    30 };
    32 class TestSyncRunnable : public ::testing::Test {
    33 public:
    34   static void SetUpTestCase()
    35   {
    36     nsresult rv = NS_NewNamedThread("thread", &gThread);
    37     ASSERT_TRUE(NS_SUCCEEDED(rv));
    38   }
    40   static void TearDownTestCase()
    41   {
    42     if (gThread)
    43       gThread->Shutdown();
    44   }
    45 };
    47 TEST_F(TestSyncRunnable, TestDispatch)
    48 {
    49   nsRefPtr<TestRunnable> r(new TestRunnable());
    50   nsRefPtr<SyncRunnable> s(new SyncRunnable(r));
    51   s->DispatchToThread(gThread);
    53   ASSERT_TRUE(r->ran());
    54 }
    56 TEST_F(TestSyncRunnable, TestDispatchStatic)
    57 {
    58   nsRefPtr<TestRunnable> r(new TestRunnable());
    59   SyncRunnable::DispatchToThread(gThread, r);
    60   ASSERT_TRUE(r->ran());
    61 }
    64 #include "mtransport_test_utils.h"
    65 MtransportTestUtils *test_utils;
    67 int main(int argc, char **argv)
    68 {
    69   test_utils = new MtransportTestUtils();
    70   // Start the tests
    71   ::testing::InitGoogleTest(&argc, argv);
    73   int rv = RUN_ALL_TESTS();
    75   delete test_utils;
    76   return rv;
    77 }

mercurial