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