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 | // Test that SavedFrame.prototype.parent gives the next older frame whose |
michael@0 | 2 | // principals are subsumed by the caller's principals. |
michael@0 | 3 | |
michael@0 | 4 | // Given a string of letters |expected|, say "abc", assert that the stack |
michael@0 | 5 | // contains calls to a series of functions named by the next letter from |
michael@0 | 6 | // the string, say a, b, and then c. Younger frames appear earlier in |
michael@0 | 7 | // |expected| than older frames. |
michael@0 | 8 | function check(expected, stack) { |
michael@0 | 9 | print("check(" + uneval(expected) + ") against:\n" + stack); |
michael@0 | 10 | count++; |
michael@0 | 11 | |
michael@0 | 12 | while (stack.length && expected.length) { |
michael@0 | 13 | assertEq(stack.shift(), expected[0]); |
michael@0 | 14 | expected = expected.slice(1); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | if (expected.length > 0) { |
michael@0 | 18 | throw new Error("Missing frames for: " + expected); |
michael@0 | 19 | } |
michael@0 | 20 | if (stack.length > 0 && !stack.every(s => s === null)) { |
michael@0 | 21 | throw new Error("Unexpected extra frame(s):\n" + stack); |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | // Go from a SavedFrame linked list to an array of function display names. |
michael@0 | 26 | function extract(stack) { |
michael@0 | 27 | const results = []; |
michael@0 | 28 | while (stack) { |
michael@0 | 29 | results.push(stack.functionDisplayName); |
michael@0 | 30 | stack = stack.parent; |
michael@0 | 31 | } |
michael@0 | 32 | return results; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | const low = newGlobal({ principal: 0 }); |
michael@0 | 36 | const mid = newGlobal({ principal: 0xffff }); |
michael@0 | 37 | const high = newGlobal({ principal: 0xfffff }); |
michael@0 | 38 | |
michael@0 | 39 | var count = 0; |
michael@0 | 40 | |
michael@0 | 41 | eval('function a() { check("a", extract(saveStack())); b(); }'); |
michael@0 | 42 | low .eval('function b() { check("b", extract(saveStack())); c(); }'); |
michael@0 | 43 | mid .eval('function c() { check("cba", extract(saveStack())); d(); }'); |
michael@0 | 44 | high.eval('function d() { check("dcba", extract(saveStack())); e(); }'); |
michael@0 | 45 | eval('function e() { check("edcba", extract(saveStack())); f(); }'); // no principal, so checks skipped |
michael@0 | 46 | low .eval('function f() { check("fb", extract(saveStack())); g(); }'); |
michael@0 | 47 | mid .eval('function g() { check("gfecba", extract(saveStack())); h(); }'); |
michael@0 | 48 | high.eval('function h() { check("hgfedcba", extract(saveStack())); }'); |
michael@0 | 49 | |
michael@0 | 50 | // Make everyone's functions visible to each other, as needed. |
michael@0 | 51 | b = low .b; |
michael@0 | 52 | low .c = mid .c; |
michael@0 | 53 | mid .d = high.d; |
michael@0 | 54 | high.e = e; |
michael@0 | 55 | f = low .f; |
michael@0 | 56 | low .g = mid .g; |
michael@0 | 57 | mid .h = high.h; |
michael@0 | 58 | |
michael@0 | 59 | low.check = mid.check = high.check = check; |
michael@0 | 60 | |
michael@0 | 61 | // They each must have their own extract so that CCWs don't mess up the |
michael@0 | 62 | // principals when we ask for the parent property. |
michael@0 | 63 | low. eval("" + extract); |
michael@0 | 64 | mid. eval("" + extract); |
michael@0 | 65 | high.eval("" + extract); |
michael@0 | 66 | |
michael@0 | 67 | // Kick the whole process off. |
michael@0 | 68 | a(); |
michael@0 | 69 | |
michael@0 | 70 | assertEq(count, 8); |