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: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "TestHarness.h" |
michael@0 | 7 | #include "nsILoadContextInfo.h" |
michael@0 | 8 | #include "../cache2/CacheFileUtils.h" |
michael@0 | 9 | |
michael@0 | 10 | int |
michael@0 | 11 | main(int32_t argc, char *argv[]) |
michael@0 | 12 | { |
michael@0 | 13 | nsCOMPtr<nsILoadContextInfo> info; |
michael@0 | 14 | nsAutoCString key, enh; |
michael@0 | 15 | |
michael@0 | 16 | #define CHECK(a) MOZ_ASSERT(a) |
michael@0 | 17 | |
michael@0 | 18 | info = ParseKey(NS_LITERAL_CSTRING("")); |
michael@0 | 19 | CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); |
michael@0 | 20 | info = ParseKey(NS_LITERAL_CSTRING(":")); |
michael@0 | 21 | CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); |
michael@0 | 22 | info = ParseKey(NS_LITERAL_CSTRING("a,")); |
michael@0 | 23 | CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); |
michael@0 | 24 | info = ParseKey(NS_LITERAL_CSTRING("a,:")); |
michael@0 | 25 | CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); |
michael@0 | 26 | info = ParseKey(NS_LITERAL_CSTRING("a,:xxx"), &enh, &key); |
michael@0 | 27 | CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); |
michael@0 | 28 | CHECK(NS_LITERAL_CSTRING("xxx").Equals(key)); |
michael@0 | 29 | info = ParseKey(NS_LITERAL_CSTRING("b,:xxx")); |
michael@0 | 30 | CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0); |
michael@0 | 31 | info = ParseKey(NS_LITERAL_CSTRING("a,b,:xxx"), &enh, &key); |
michael@0 | 32 | CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0); |
michael@0 | 33 | CHECK(NS_LITERAL_CSTRING("xxx").Equals(key)); |
michael@0 | 34 | CHECK(enh.IsEmpty()); |
michael@0 | 35 | info = ParseKey(NS_LITERAL_CSTRING("a,b,i123,:xxx")); |
michael@0 | 36 | CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123); |
michael@0 | 37 | info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,:xxx"), &enh, &key); |
michael@0 | 38 | CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123); |
michael@0 | 39 | CHECK(NS_LITERAL_CSTRING("xxx").Equals(key)); |
michael@0 | 40 | info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,~enh,:xxx"), &enh, &key); |
michael@0 | 41 | CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123); |
michael@0 | 42 | CHECK(NS_LITERAL_CSTRING("xxx").Equals(key)); |
michael@0 | 43 | CHECK(NS_LITERAL_CSTRING("enh").Equals(enh)); |
michael@0 | 44 | info = ParseKey(NS_LITERAL_CSTRING("0x,1,a,b,i123,:xxx")); |
michael@0 | 45 | CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123); |
michael@0 | 46 | |
michael@0 | 47 | nsAutoCString test; |
michael@0 | 48 | AppendTagWithValue(test, '~', NS_LITERAL_CSTRING("e,nh,")); |
michael@0 | 49 | info = ParseKey(test, &enh, &key); |
michael@0 | 50 | CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); |
michael@0 | 51 | CHECK(NS_LITERAL_CSTRING("e,nh,").Equals(enh)); |
michael@0 | 52 | |
michael@0 | 53 | info = ParseKey(NS_LITERAL_CSTRING("a,i123,b,:xxx")); |
michael@0 | 54 | CHECK(!info); |
michael@0 | 55 | info = ParseKey(NS_LITERAL_CSTRING("a")); |
michael@0 | 56 | CHECK(!info); |
michael@0 | 57 | info = ParseKey(NS_LITERAL_CSTRING("a:")); |
michael@0 | 58 | CHECK(!info); |
michael@0 | 59 | info = ParseKey(NS_LITERAL_CSTRING("a:xxx")); |
michael@0 | 60 | CHECK(!info); |
michael@0 | 61 | info = ParseKey(NS_LITERAL_CSTRING("i123")); |
michael@0 | 62 | CHECK(!info); |
michael@0 | 63 | info = ParseKey(NS_LITERAL_CSTRING("i123:")); |
michael@0 | 64 | CHECK(!info); |
michael@0 | 65 | info = ParseKey(NS_LITERAL_CSTRING("i123:xxx")); |
michael@0 | 66 | CHECK(!info); |
michael@0 | 67 | info = ParseKey(NS_LITERAL_CSTRING("i123,x:")); |
michael@0 | 68 | CHECK(!info); |
michael@0 | 69 | info = ParseKey(NS_LITERAL_CSTRING("i,x,:")); |
michael@0 | 70 | CHECK(!info); |
michael@0 | 71 | info = ParseKey(NS_LITERAL_CSTRING("i:")); |
michael@0 | 72 | CHECK(!info); |
michael@0 | 73 | |
michael@0 | 74 | #undef CHECK |
michael@0 | 75 | |
michael@0 | 76 | passed("ok"); |
michael@0 | 77 | return 0; |
michael@0 | 78 | } |