Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
1 /* -*- Mode: C++; tab-width: 2; 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 /*
7 * Ideally, this test would be in memory/test/. But I couldn't get it to build
8 * there (couldn't find TestHarness.h). I think memory/ is processed too early
9 * in the build. So it's here.
10 */
12 #include "TestHarness.h"
13 #include "mozmemory.h"
15 static inline bool
16 TestOne(size_t size)
17 {
18 size_t req = size;
19 size_t adv = malloc_good_size(req);
20 char* p = (char*)malloc(req);
21 size_t usable = moz_malloc_usable_size(p);
22 if (adv != usable) {
23 fail("malloc_good_size(%d) --> %d; "
24 "malloc_usable_size(%d) --> %d",
25 req, adv, req, usable);
26 return false;
27 }
28 free(p);
29 return true;
30 }
32 static inline bool
33 TestThree(size_t size)
34 {
35 return TestOne(size - 1) && TestOne(size) && TestOne(size + 1);
36 }
38 static nsresult
39 TestJemallocUsableSizeInAdvance()
40 {
41 #define K * 1024
42 #define M * 1024 * 1024
44 /*
45 * Test every size up to a certain point, then (N-1, N, N+1) triplets for a
46 * various sizes beyond that.
47 */
49 for (size_t n = 0; n < 16 K; n++)
50 if (!TestOne(n))
51 return NS_ERROR_UNEXPECTED;
53 for (size_t n = 16 K; n < 1 M; n += 4 K)
54 if (!TestThree(n))
55 return NS_ERROR_UNEXPECTED;
57 for (size_t n = 1 M; n < 8 M; n += 128 K)
58 if (!TestThree(n))
59 return NS_ERROR_UNEXPECTED;
61 passed("malloc_good_size");
63 return NS_OK;
64 }
66 int main(int argc, char** argv)
67 {
68 int rv = 0;
69 ScopedXPCOM xpcom("jemalloc");
70 if (xpcom.failed())
71 return 1;
73 if (NS_FAILED(TestJemallocUsableSizeInAdvance()))
74 rv = 1;
76 return rv;
77 }