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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 "gtest/gtest.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "gfxSkipChars.h" |
michael@0 | 9 | #include "mozilla/ArrayUtils.h" |
michael@0 | 10 | |
michael@0 | 11 | static bool |
michael@0 | 12 | TestConstructor() |
michael@0 | 13 | { |
michael@0 | 14 | gfxSkipChars skipChars; |
michael@0 | 15 | |
michael@0 | 16 | EXPECT_TRUE(skipChars.GetOriginalCharCount() == 0) << |
michael@0 | 17 | "[1] Make sure the gfxSkipChars was properly initialized with constructor"; |
michael@0 | 18 | |
michael@0 | 19 | return true; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | static bool |
michael@0 | 23 | TestLength() |
michael@0 | 24 | { |
michael@0 | 25 | gfxSkipChars skipChars; |
michael@0 | 26 | |
michael@0 | 27 | skipChars.KeepChars(100); |
michael@0 | 28 | |
michael@0 | 29 | EXPECT_TRUE(skipChars.GetOriginalCharCount() == 100) << |
michael@0 | 30 | "[1] Check length after keeping chars"; |
michael@0 | 31 | |
michael@0 | 32 | skipChars.SkipChars(50); |
michael@0 | 33 | |
michael@0 | 34 | EXPECT_TRUE(skipChars.GetOriginalCharCount() == 150) << |
michael@0 | 35 | "[2] Check length after skipping chars"; |
michael@0 | 36 | |
michael@0 | 37 | skipChars.SkipChars(50); |
michael@0 | 38 | |
michael@0 | 39 | EXPECT_TRUE(skipChars.GetOriginalCharCount() == 200) << |
michael@0 | 40 | "[3] Check length after skipping more chars"; |
michael@0 | 41 | |
michael@0 | 42 | skipChars.KeepChar(); |
michael@0 | 43 | |
michael@0 | 44 | EXPECT_TRUE(skipChars.GetOriginalCharCount() == 201) << |
michael@0 | 45 | "[4] Check length after keeping a final char"; |
michael@0 | 46 | |
michael@0 | 47 | return true; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | static bool |
michael@0 | 51 | TestIterator() |
michael@0 | 52 | { |
michael@0 | 53 | // Test a gfxSkipChars that starts with kept chars |
michael@0 | 54 | gfxSkipChars skipChars1; |
michael@0 | 55 | |
michael@0 | 56 | skipChars1.KeepChars(9); |
michael@0 | 57 | skipChars1.SkipChar(); |
michael@0 | 58 | skipChars1.KeepChars(9); |
michael@0 | 59 | skipChars1.SkipChar(); |
michael@0 | 60 | skipChars1.KeepChars(9); |
michael@0 | 61 | |
michael@0 | 62 | EXPECT_TRUE(skipChars1.GetOriginalCharCount() == 29) << |
michael@0 | 63 | "[1] Check length"; |
michael@0 | 64 | |
michael@0 | 65 | gfxSkipCharsIterator iter1(skipChars1); |
michael@0 | 66 | |
michael@0 | 67 | EXPECT_TRUE(iter1.GetOriginalOffset() == 0) << |
michael@0 | 68 | "[2] Check initial original offset"; |
michael@0 | 69 | EXPECT_TRUE(iter1.GetSkippedOffset() == 0) << |
michael@0 | 70 | "[3] Check initial skipped offset"; |
michael@0 | 71 | |
michael@0 | 72 | uint32_t expectSkipped1[] = |
michael@0 | 73 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
michael@0 | 74 | 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
michael@0 | 75 | 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 }; |
michael@0 | 76 | |
michael@0 | 77 | for (uint32_t i = 0; i < mozilla::ArrayLength(expectSkipped1); i++) { |
michael@0 | 78 | EXPECT_TRUE(iter1.ConvertOriginalToSkipped(i) == expectSkipped1[i]) << |
michael@0 | 79 | "[4] Check mapping of original to skipped for " << i; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | uint32_t expectOriginal1[] = |
michael@0 | 83 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, |
michael@0 | 84 | 10, 11, 12, 13, 14, 15, 16, 17, 18, |
michael@0 | 85 | 20, 21, 22, 23, 24, 25, 26, 27, 28 }; |
michael@0 | 86 | |
michael@0 | 87 | for (uint32_t i = 0; i < mozilla::ArrayLength(expectOriginal1); i++) { |
michael@0 | 88 | EXPECT_TRUE(iter1.ConvertSkippedToOriginal(i) == expectOriginal1[i]) << |
michael@0 | 89 | "[5] Check mapping of skipped to original for " << i; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | // Test a gfxSkipChars that starts with skipped chars |
michael@0 | 93 | gfxSkipChars skipChars2; |
michael@0 | 94 | |
michael@0 | 95 | skipChars2.SkipChars(9); |
michael@0 | 96 | skipChars2.KeepChar(); |
michael@0 | 97 | skipChars2.SkipChars(9); |
michael@0 | 98 | skipChars2.KeepChar(); |
michael@0 | 99 | skipChars2.SkipChars(9); |
michael@0 | 100 | |
michael@0 | 101 | EXPECT_TRUE(skipChars2.GetOriginalCharCount() == 29) << |
michael@0 | 102 | "[6] Check length"; |
michael@0 | 103 | |
michael@0 | 104 | gfxSkipCharsIterator iter2(skipChars2); |
michael@0 | 105 | |
michael@0 | 106 | EXPECT_TRUE(iter2.GetOriginalOffset() == 0) << |
michael@0 | 107 | "[7] Check initial original offset"; |
michael@0 | 108 | EXPECT_TRUE(iter2.GetSkippedOffset() == 0) << |
michael@0 | 109 | "[8] Check initial skipped offset"; |
michael@0 | 110 | |
michael@0 | 111 | uint32_t expectSkipped2[] = |
michael@0 | 112 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
michael@0 | 113 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
michael@0 | 114 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; |
michael@0 | 115 | |
michael@0 | 116 | for (uint32_t i = 0; i < mozilla::ArrayLength(expectSkipped2); i++) { |
michael@0 | 117 | EXPECT_TRUE(iter2.ConvertOriginalToSkipped(i) == expectSkipped2[i]) << |
michael@0 | 118 | "[9] Check mapping of original to skipped for " << i; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | uint32_t expectOriginal2[] = { 9, 19, 29 }; |
michael@0 | 122 | |
michael@0 | 123 | for (uint32_t i = 0; i < mozilla::ArrayLength(expectOriginal2); i++) { |
michael@0 | 124 | EXPECT_TRUE(iter2.ConvertSkippedToOriginal(i) == expectOriginal2[i]) << |
michael@0 | 125 | "[10] Check mapping of skipped to original for " << i; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | return true; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | TEST(Gfx, gfxSkipChars) { |
michael@0 | 132 | TestConstructor(); |
michael@0 | 133 | TestLength(); |
michael@0 | 134 | TestIterator(); |
michael@0 | 135 | } |