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