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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | // vim:cindent:ts=4:et:sw=4: |
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 |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsAutoRef.h" |
michael@0 | 8 | #include "TestHarness.h" |
michael@0 | 9 | |
michael@0 | 10 | #define TEST(aCondition, aMsg) \ |
michael@0 | 11 | if (!(aCondition)) { fail("TestAutoRef: "#aMsg); exit(1); } |
michael@0 | 12 | |
michael@0 | 13 | struct TestObjectA { |
michael@0 | 14 | public: |
michael@0 | 15 | TestObjectA() : mRefCnt(0) { |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | ~TestObjectA() { |
michael@0 | 19 | TEST(mRefCnt == 0, "mRefCnt in destructor"); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | public: |
michael@0 | 23 | int mRefCnt; |
michael@0 | 24 | }; |
michael@0 | 25 | |
michael@0 | 26 | template <> |
michael@0 | 27 | class nsAutoRefTraits<TestObjectA> : public nsPointerRefTraits<TestObjectA> |
michael@0 | 28 | { |
michael@0 | 29 | public: |
michael@0 | 30 | static int mTotalRefsCnt; |
michael@0 | 31 | |
michael@0 | 32 | static void Release(TestObjectA *ptr) { |
michael@0 | 33 | ptr->mRefCnt--; |
michael@0 | 34 | if (ptr->mRefCnt == 0) { |
michael@0 | 35 | delete ptr; |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | static void AddRef(TestObjectA *ptr) { |
michael@0 | 40 | ptr->mRefCnt++; |
michael@0 | 41 | } |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | int nsAutoRefTraits<TestObjectA>::mTotalRefsCnt = 0; |
michael@0 | 45 | |
michael@0 | 46 | int main() |
michael@0 | 47 | { |
michael@0 | 48 | { |
michael@0 | 49 | nsCountedRef<TestObjectA> a(new TestObjectA()); |
michael@0 | 50 | TEST(a->mRefCnt == 1, "nsCountedRef instantiation with valid RawRef"); |
michael@0 | 51 | |
michael@0 | 52 | nsCountedRef<TestObjectA> b; |
michael@0 | 53 | TEST(b.get() == nullptr, "nsCountedRef instantiation with invalid RawRef"); |
michael@0 | 54 | |
michael@0 | 55 | a.swap(b); |
michael@0 | 56 | TEST(b->mRefCnt, "nsAutoRef::swap() t1"); |
michael@0 | 57 | TEST(a.get() == nullptr, "nsAutoRef::swap() t2"); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | TEST(true, "All tests pass"); |
michael@0 | 61 | return 0; |
michael@0 | 62 | } |