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 gTestsubsuite='JSON';
3 function testJSON(str, expectSyntaxError)
4 {
5 // Leading and trailing whitespace never affect parsing, so test the string
6 // multiple times with and without whitespace around it as it's easy and can
7 // potentially detect bugs.
9 // Try the provided string
10 try
11 {
12 JSON.parse(str);
13 reportCompare(false, expectSyntaxError,
14 "string <" + str + "> " +
15 "should" + (expectSyntaxError ? "n't" : "") + " " +
16 "have parsed as JSON");
17 }
18 catch (e)
19 {
20 if (!(e instanceof SyntaxError))
21 {
22 reportCompare(true, false,
23 "parsing string <" + str + "> threw a non-SyntaxError " +
24 "exception: " + e);
25 }
26 else
27 {
28 reportCompare(true, expectSyntaxError,
29 "string <" + str + "> " +
30 "should" + (expectSyntaxError ? "n't" : "") + " " +
31 "have parsed as JSON, exception: " + e);
32 }
33 }
35 // Now try the provided string with trailing whitespace
36 try
37 {
38 JSON.parse(str + " ");
39 reportCompare(false, expectSyntaxError,
40 "string <" + str + " > " +
41 "should" + (expectSyntaxError ? "n't" : "") + " " +
42 "have parsed as JSON");
43 }
44 catch (e)
45 {
46 if (!(e instanceof SyntaxError))
47 {
48 reportCompare(true, false,
49 "parsing string <" + str + " > threw a non-SyntaxError " +
50 "exception: " + e);
51 }
52 else
53 {
54 reportCompare(true, expectSyntaxError,
55 "string <" + str + " > " +
56 "should" + (expectSyntaxError ? "n't" : "") + " " +
57 "have parsed as JSON, exception: " + e);
58 }
59 }
61 // Now try the provided string with leading whitespace
62 try
63 {
64 JSON.parse(" " + str);
65 reportCompare(false, expectSyntaxError,
66 "string < " + str + "> " +
67 "should" + (expectSyntaxError ? "n't" : "") + " " +
68 "have parsed as JSON");
69 }
70 catch (e)
71 {
72 if (!(e instanceof SyntaxError))
73 {
74 reportCompare(true, false,
75 "parsing string < " + str + "> threw a non-SyntaxError " +
76 "exception: " + e);
77 }
78 else
79 {
80 reportCompare(true, expectSyntaxError,
81 "string < " + str + "> " +
82 "should" + (expectSyntaxError ? "n't" : "") + " " +
83 "have parsed as JSON, exception: " + e);
84 }
85 }
87 // Now try the provided string with whitespace surrounding it
88 try
89 {
90 JSON.parse(" " + str + " ");
91 reportCompare(false, expectSyntaxError,
92 "string < " + str + " > " +
93 "should" + (expectSyntaxError ? "n't" : "") + " " +
94 "have parsed as JSON");
95 }
96 catch (e)
97 {
98 if (!(e instanceof SyntaxError))
99 {
100 reportCompare(true, false,
101 "parsing string < " + str + " > threw a non-SyntaxError " +
102 "exception: " + e);
103 }
104 else
105 {
106 reportCompare(true, expectSyntaxError,
107 "string < " + str + " > " +
108 "should" + (expectSyntaxError ? "n't" : "") + " " +
109 "have parsed as JSON, exception: " + e);
110 }
111 }
112 }