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: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "TestHarness.h"
7 #include "nsILoadContextInfo.h"
8 #include "../cache2/CacheFileUtils.h"
10 int
11 main(int32_t argc, char *argv[])
12 {
13 nsCOMPtr<nsILoadContextInfo> info;
14 nsAutoCString key, enh;
16 #define CHECK(a) MOZ_ASSERT(a)
18 info = ParseKey(NS_LITERAL_CSTRING(""));
19 CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
20 info = ParseKey(NS_LITERAL_CSTRING(":"));
21 CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
22 info = ParseKey(NS_LITERAL_CSTRING("a,"));
23 CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
24 info = ParseKey(NS_LITERAL_CSTRING("a,:"));
25 CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
26 info = ParseKey(NS_LITERAL_CSTRING("a,:xxx"), &enh, &key);
27 CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
28 CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
29 info = ParseKey(NS_LITERAL_CSTRING("b,:xxx"));
30 CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0);
31 info = ParseKey(NS_LITERAL_CSTRING("a,b,:xxx"), &enh, &key);
32 CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0);
33 CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
34 CHECK(enh.IsEmpty());
35 info = ParseKey(NS_LITERAL_CSTRING("a,b,i123,:xxx"));
36 CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
37 info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,:xxx"), &enh, &key);
38 CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
39 CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
40 info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,~enh,:xxx"), &enh, &key);
41 CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
42 CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
43 CHECK(NS_LITERAL_CSTRING("enh").Equals(enh));
44 info = ParseKey(NS_LITERAL_CSTRING("0x,1,a,b,i123,:xxx"));
45 CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
47 nsAutoCString test;
48 AppendTagWithValue(test, '~', NS_LITERAL_CSTRING("e,nh,"));
49 info = ParseKey(test, &enh, &key);
50 CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
51 CHECK(NS_LITERAL_CSTRING("e,nh,").Equals(enh));
53 info = ParseKey(NS_LITERAL_CSTRING("a,i123,b,:xxx"));
54 CHECK(!info);
55 info = ParseKey(NS_LITERAL_CSTRING("a"));
56 CHECK(!info);
57 info = ParseKey(NS_LITERAL_CSTRING("a:"));
58 CHECK(!info);
59 info = ParseKey(NS_LITERAL_CSTRING("a:xxx"));
60 CHECK(!info);
61 info = ParseKey(NS_LITERAL_CSTRING("i123"));
62 CHECK(!info);
63 info = ParseKey(NS_LITERAL_CSTRING("i123:"));
64 CHECK(!info);
65 info = ParseKey(NS_LITERAL_CSTRING("i123:xxx"));
66 CHECK(!info);
67 info = ParseKey(NS_LITERAL_CSTRING("i123,x:"));
68 CHECK(!info);
69 info = ParseKey(NS_LITERAL_CSTRING("i,x,:"));
70 CHECK(!info);
71 info = ParseKey(NS_LITERAL_CSTRING("i:"));
72 CHECK(!info);
74 #undef CHECK
76 passed("ok");
77 return 0;
78 }