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: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Utilities to wrap gtest, based on libjingle's gunit
9 // Some sections of this code are under the following license:
11 /*
12 * libjingle
13 * Copyright 2004--2008, Google Inc.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions are met:
17 *
18 * 1. Redistributions of source code must retain the above copyright notice,
19 * this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright notice,
21 * this list of conditions and the following disclaimer in the documentation
22 * and/or other materials provided with the distribution.
23 * 3. The name of the author may not be used to endorse or promote products
24 * derived from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
29 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
38 // Original author: ekr@rtfm.com
39 #ifndef gtest_utils_h__
40 #define gtest_utils_h__
42 #include <iostream>
44 #include "nspr.h"
45 #include "prinrval.h"
46 #include "prthread.h"
48 #define GTEST_HAS_RTTI 0
49 #include "gtest/gtest.h"
51 // Wait up to timeout seconds for expression to be true
52 #define WAIT(expression, timeout) \
53 do { \
54 for (PRIntervalTime start = PR_IntervalNow(); !(expression) && \
55 ! ((PR_IntervalNow() - start) > PR_MillisecondsToInterval(timeout));) \
56 PR_Sleep(10); \
57 } while(0)
59 // Same as GTEST_WAIT, but stores the result in res. Used when
60 // you also want the result of expression but wish to avoid
61 // double evaluation.
62 #define WAIT_(expression, timeout, res) \
63 do { \
64 for (PRIntervalTime start = PR_IntervalNow(); !(res = (expression)) && \
65 ! ((PR_IntervalNow() - start) > PR_MillisecondsToInterval(timeout));) \
66 PR_Sleep(10); \
67 } while(0)
69 #define ASSERT_TRUE_WAIT(expression, timeout) \
70 do { \
71 bool res; \
72 WAIT_(expression, timeout, res); \
73 ASSERT_TRUE(res); \
74 } while(0);
76 #define EXPECT_TRUE_WAIT(expression, timeout) \
77 do { \
78 bool res; \
79 WAIT_(expression, timeout, res); \
80 EXPECT_TRUE(res); \
81 } while(0);
83 #endif