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