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: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
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 | /* |
michael@0 | 7 | * |
michael@0 | 8 | * This file is #included directly by gfxFontSelectionTest.cpp, and as |
michael@0 | 9 | * such does not need any #include files or similar. (However, should |
michael@0 | 10 | * any extra ones be required, it should be ok to do so, as well as |
michael@0 | 11 | * defining new functions, etc. |
michael@0 | 12 | * |
michael@0 | 13 | * To add a new test, call AddTest with the following arguments: the |
michael@0 | 14 | * CSS font-family string, the gfxFontStyle, an enum (either S_ASCII |
michael@0 | 15 | * or S_UTF8) indicating the string type, and then the text string |
michael@0 | 16 | * itself as a string literal. Unfortunately there is no good way to |
michael@0 | 17 | * embed UTF8 directly into C code, so hex literals will need to be |
michael@0 | 18 | * placed in the string. Because of the way \x is parsed things like |
michael@0 | 19 | * "\xabcd" won't work -- you have to do "\xab""cd". "\xab\x01\x03" |
michael@0 | 20 | * will work fine, though. |
michael@0 | 21 | * |
michael@0 | 22 | * The result of AddTest should be assigned to the variable t; after |
michael@0 | 23 | * AddTest, one or more calls to t->Expect() should be added to define |
michael@0 | 24 | * the expected result. Multiple Expect() calls in a row for the same |
michael@0 | 25 | * platform mean that the resulting glyph/font selection items needs |
michael@0 | 26 | * to have as many items as there are Expect() calls. (See below for |
michael@0 | 27 | * examples.) |
michael@0 | 28 | * |
michael@0 | 29 | * The arguments to Expect are: |
michael@0 | 30 | * |
michael@0 | 31 | * platform - a string identifying the platform. |
michael@0 | 32 | * Valid strings are "win32", "macosx", and "gtk2-pango". |
michael@0 | 33 | * font - a string (UTF8) giving the unique name of the font. |
michael@0 | 34 | * See below for how the unique name is constructed. |
michael@0 | 35 | * glyphs - a set of glyph IDs that are expected. |
michael@0 | 36 | * This array is constructed using a GLYPHS() macro. |
michael@0 | 37 | * |
michael@0 | 38 | * GLYPHS() is just a #define for LiteralArray, which is defined |
michael@0 | 39 | * in gfxFontSelectionTest.cpp -- if you need more array elements |
michael@0 | 40 | * than available, just extend LiteralArray with a new constructor |
michael@0 | 41 | * with the required number of unsigned longs. |
michael@0 | 42 | * |
michael@0 | 43 | * The unique font name is a platform-specific constructed string for |
michael@0 | 44 | * (mostly) identifying a font. On Mac, it's created by taking the |
michael@0 | 45 | * Postscript name of the font. On Windows, it's created by taking |
michael@0 | 46 | * the family name, and then appending attributes such as ":Bold", |
michael@0 | 47 | * ":Italic", etc. |
michael@0 | 48 | * |
michael@0 | 49 | * The easiest way to create a test is to add a call to AddTest, and |
michael@0 | 50 | * then run the test. The output will include a list like: |
michael@0 | 51 | * |
michael@0 | 52 | * ==== Test 1 |
michael@0 | 53 | * expected: |
michael@0 | 54 | * Run[ 0]: 'Verdana' 73 82 82 |
michael@0 | 55 | * Run[ 1]: 'MS UI Gothic' 19401 |
michael@0 | 56 | * Run[ 2]: 'Verdana' 69 68 85 |
michael@0 | 57 | * Test 1 failed |
michael@0 | 58 | * |
michael@0 | 59 | * This gives you the information needed for the calls to Expect() -- |
michael@0 | 60 | * the unique name, and the glyphs. Appropriate calls to expect for |
michael@0 | 61 | * the above would be: |
michael@0 | 62 | * |
michael@0 | 63 | * t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82)); |
michael@0 | 64 | * t->Expect ("win32", "MS UI Gothic", GLYPHS(19401)); |
michael@0 | 65 | * t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85)); |
michael@0 | 66 | * |
michael@0 | 67 | */ |
michael@0 | 68 | |
michael@0 | 69 | |
michael@0 | 70 | void |
michael@0 | 71 | SetupTests(nsTArray<TestEntry>& testList) |
michael@0 | 72 | { |
michael@0 | 73 | TestEntry *t; |
michael@0 | 74 | |
michael@0 | 75 | /* some common styles */ |
michael@0 | 76 | gfxFontStyle style_western_normal_16 (mozilla::gfx::FontStyle::NORMAL, |
michael@0 | 77 | 400, |
michael@0 | 78 | 0, |
michael@0 | 79 | 16.0, |
michael@0 | 80 | NS_NewPermanentAtom(NS_LITERAL_STRING("en")), |
michael@0 | 81 | 0.0, |
michael@0 | 82 | false, false, |
michael@0 | 83 | NS_LITERAL_STRING("")); |
michael@0 | 84 | |
michael@0 | 85 | gfxFontStyle style_western_bold_16 (mozilla::gfx::FontStyle::NORMAL, |
michael@0 | 86 | 700, |
michael@0 | 87 | 0, |
michael@0 | 88 | 16.0, |
michael@0 | 89 | NS_NewPermanentAtom(NS_LITERAL_STRING("en")), |
michael@0 | 90 | 0.0, |
michael@0 | 91 | false, false, |
michael@0 | 92 | NS_LITERAL_STRING("")); |
michael@0 | 93 | |
michael@0 | 94 | /* Test 0 */ |
michael@0 | 95 | t = AddTest (testList, "sans-serif", |
michael@0 | 96 | style_western_normal_16, |
michael@0 | 97 | S_ASCII, |
michael@0 | 98 | "ABCD"); |
michael@0 | 99 | |
michael@0 | 100 | t->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39)); |
michael@0 | 101 | t->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39)); |
michael@0 | 102 | t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39)); |
michael@0 | 103 | |
michael@0 | 104 | /* Test 1 */ |
michael@0 | 105 | t = AddTest (testList, "verdana,sans-serif", |
michael@0 | 106 | style_western_normal_16, |
michael@0 | 107 | S_UTF8, |
michael@0 | 108 | "foo\xe2\x80\x91""bar"); |
michael@0 | 109 | |
michael@0 | 110 | t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82)); |
michael@0 | 111 | t->Expect ("win32", "Arial Unicode MS", GLYPHS(3236)); |
michael@0 | 112 | t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85)); |
michael@0 | 113 | |
michael@0 | 114 | t->Expect ("macosx", "Verdana", GLYPHS(73, 82, 82)); |
michael@0 | 115 | t->Expect ("macosx", "Helvetica", GLYPHS(587)); |
michael@0 | 116 | t->Expect ("macosx", "Verdana", GLYPHS(69, 68, 85)); |
michael@0 | 117 | |
michael@0 | 118 | /* Test 2 */ |
michael@0 | 119 | t = AddTest (testList, "sans-serif", |
michael@0 | 120 | style_western_bold_16, |
michael@0 | 121 | S_ASCII, |
michael@0 | 122 | "ABCD"); |
michael@0 | 123 | |
michael@0 | 124 | t->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39)); |
michael@0 | 125 | t->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39)); |
michael@0 | 126 | t->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39)); |
michael@0 | 127 | |
michael@0 | 128 | /* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */ |
michael@0 | 129 | t = AddTest (testList, "sans-serif", |
michael@0 | 130 | style_western_normal_16, |
michael@0 | 131 | S_UTF8, |
michael@0 | 132 | " \xd8\xaa\xd9\x85 "); |
michael@0 | 133 | t->SetRTL(); |
michael@0 | 134 | t->Expect ("macosx", "Helvetica", GLYPHS(3)); |
michael@0 | 135 | t->Expect ("macosx", "ArialMT", GLYPHS(919, 993)); |
michael@0 | 136 | t->Expect ("macosx", "Helvetica", GLYPHS(3)); |
michael@0 | 137 | t->Expect ("win32", "Arial", GLYPHS(3, 919, 994, 3)); |
michael@0 | 138 | |
michael@0 | 139 | /* Test 4: LTR Arabic with leading and trailing whitespace */ |
michael@0 | 140 | t = AddTest (testList, "sans-serif", |
michael@0 | 141 | style_western_normal_16, |
michael@0 | 142 | S_UTF8, |
michael@0 | 143 | " \xd9\x85\xd8\xaa "); |
michael@0 | 144 | t->Expect ("macosx", "Helvetica", GLYPHS(3)); |
michael@0 | 145 | t->Expect ("macosx", "ArialMT", GLYPHS(993, 919)); |
michael@0 | 146 | t->Expect ("macosx", "Helvetica", GLYPHS(3)); |
michael@0 | 147 | t->Expect ("win32", "Arial", GLYPHS(3, 994, 919, 3)); |
michael@0 | 148 | |
michael@0 | 149 | /* Test 5: RTL ASCII with leading whitespace */ |
michael@0 | 150 | t = AddTest (testList, "sans-serif", |
michael@0 | 151 | style_western_normal_16, |
michael@0 | 152 | S_ASCII, |
michael@0 | 153 | " ab"); |
michael@0 | 154 | t->SetRTL(); |
michael@0 | 155 | t->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69)); |
michael@0 | 156 | t->Expect ("win32", "Arial", GLYPHS(3, 68, 69)); |
michael@0 | 157 | t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69)); |
michael@0 | 158 | |
michael@0 | 159 | /* Test 6: RTL ASCII with trailing whitespace */ |
michael@0 | 160 | t = AddTest (testList, "sans-serif", |
michael@0 | 161 | style_western_normal_16, |
michael@0 | 162 | S_ASCII, |
michael@0 | 163 | "ab "); |
michael@0 | 164 | t->SetRTL(); |
michael@0 | 165 | t->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3)); |
michael@0 | 166 | t->Expect ("win32", "Arial", GLYPHS(68, 69, 3)); |
michael@0 | 167 | t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3)); |
michael@0 | 168 | |
michael@0 | 169 | /* Test 7: Simple ASCII ligature */ |
michael@0 | 170 | /* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */ |
michael@0 | 171 | t = AddTest (testList, "sans-serif", |
michael@0 | 172 | style_western_normal_16, |
michael@0 | 173 | S_ASCII, |
michael@0 | 174 | "fi"); |
michael@0 | 175 | t->Expect ("macosx", "Helvetica", GLYPHS(192)); |
michael@0 | 176 | t->Expect ("win32", "Arial", GLYPHS(73, 76)); |
michael@0 | 177 | |
michael@0 | 178 | /* Test 8: DEVANAGARI VOWEL I reordering */ |
michael@0 | 179 | /* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */ |
michael@0 | 180 | t = AddTest (testList, "sans-serif", |
michael@0 | 181 | style_western_normal_16, |
michael@0 | 182 | S_UTF8, |
michael@0 | 183 | "\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319 |
michael@0 | 184 | t->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60)); |
michael@0 | 185 | t->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102)); |
michael@0 | 186 | |
michael@0 | 187 | // Disabled Test 9 & 10 because these appear to vary on mac |
michael@0 | 188 | |
michael@0 | 189 | /* Test 9: NWJ test */ |
michael@0 | 190 | //t = AddTest (testList, "Kartika", |
michael@0 | 191 | // style_western_normal_16, |
michael@0 | 192 | // S_UTF8, |
michael@0 | 193 | // "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d"); |
michael@0 | 194 | //t->Expect ("macosx", "MalayalamMN", GLYPHS(360)); |
michael@0 | 195 | //t->Expect ("win32", "Kartika", GLYPHS(332)); |
michael@0 | 196 | |
michael@0 | 197 | /* Test 10: NWJ fallback test */ |
michael@0 | 198 | /* it isn't clear what we should actually do in this case. Ideally |
michael@0 | 199 | we would have the same results as the previous test, but because |
michael@0 | 200 | we use sans-serif (i.e. Arial) CSS says we should should really |
michael@0 | 201 | use Arial for U+200D. |
michael@0 | 202 | */ |
michael@0 | 203 | //t = AddTest (testList, "sans-serif", |
michael@0 | 204 | // style_western_normal_16, |
michael@0 | 205 | // S_UTF8, |
michael@0 | 206 | // "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d"); |
michael@0 | 207 | // Disabled because these appear to vary |
michael@0 | 208 | //t->Expect ("macosx", "MalayalamMN", GLYPHS(360)); |
michael@0 | 209 | //t->Expect ("win32", "Kartika", GLYPHS(332)); |
michael@0 | 210 | } |