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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const Cc = Components.classes; |
michael@0 | 6 | const Ci = Components.interfaces; |
michael@0 | 7 | |
michael@0 | 8 | function run_test() { |
michael@0 | 9 | |
michael@0 | 10 | // Load the component manifest containing our test interface implementations. |
michael@0 | 11 | Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest')); |
michael@0 | 12 | |
michael@0 | 13 | // Shortcut the interfaces we're using. |
michael@0 | 14 | var ifs = { |
michael@0 | 15 | a: Ci['nsIXPCTestInterfaceA'], |
michael@0 | 16 | b: Ci['nsIXPCTestInterfaceB'], |
michael@0 | 17 | c: Ci['nsIXPCTestInterfaceC'] |
michael@0 | 18 | }; |
michael@0 | 19 | |
michael@0 | 20 | // Shortcut the class we're instantiating. This implements all three interfaces. |
michael@0 | 21 | var cls = Cc["@mozilla.org/js/xpc/test/js/TestInterfaceAll;1"]; |
michael@0 | 22 | |
michael@0 | 23 | // Run through the logic a few times. |
michael@0 | 24 | for (i = 0; i < 2; ++i) |
michael@0 | 25 | play_with_tearoffs(ifs, cls); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function play_with_tearoffs(ifs, cls) { |
michael@0 | 29 | |
michael@0 | 30 | // Allocate a bunch of objects, QI-ed to B. |
michael@0 | 31 | var instances = []; |
michael@0 | 32 | for (var i = 0; i < 300; ++i) |
michael@0 | 33 | instances.push(cls.createInstance(ifs.b)); |
michael@0 | 34 | |
michael@0 | 35 | // Nothing to collect. |
michael@0 | 36 | gc(); |
michael@0 | 37 | |
michael@0 | 38 | // QI them to A. |
michael@0 | 39 | instances.forEach(function(v, i, a) { v.QueryInterface(ifs.a); }); |
michael@0 | 40 | |
michael@0 | 41 | // QI them to C. |
michael@0 | 42 | instances.forEach(function(v, i, a) { v.QueryInterface(ifs.c); }); |
michael@0 | 43 | |
michael@0 | 44 | // Check |
michael@0 | 45 | do_check_true('name' in instances[10], 'Have the prop from A/B'); |
michael@0 | 46 | do_check_true('someInteger' in instances[10], 'Have the prop from C'); |
michael@0 | 47 | |
michael@0 | 48 | // Grab tearoff reflections for a and b. |
michael@0 | 49 | var aTearOffs = instances.map(function(v, i, a) { return v.nsIXPCTestInterfaceA; } ); |
michael@0 | 50 | var bTearOffs = instances.map(function(v, i, a) { return v.nsIXPCTestInterfaceB; } ); |
michael@0 | 51 | |
michael@0 | 52 | // Check |
michael@0 | 53 | do_check_true('name' in aTearOffs[1], 'Have the prop from A'); |
michael@0 | 54 | do_check_true(!('someInteger' in aTearOffs[1]), 'Dont have the prop from C'); |
michael@0 | 55 | |
michael@0 | 56 | // Nothing to collect. |
michael@0 | 57 | gc(); |
michael@0 | 58 | |
michael@0 | 59 | // Null out every even instance pointer. |
michael@0 | 60 | for (var i = 0; i < instances.length; ++i) |
michael@0 | 61 | if (i % 2 == 0) |
michael@0 | 62 | instances[i] = null; |
michael@0 | 63 | |
michael@0 | 64 | // Nothing to collect, since we still have the A and B tearoff reflections. |
michael@0 | 65 | gc(); |
michael@0 | 66 | |
michael@0 | 67 | // Null out A tearoff reflections that are a multiple of 3. |
michael@0 | 68 | for (var i = 0; i < aTearOffs.length; ++i) |
michael@0 | 69 | if (i % 3 == 0) |
michael@0 | 70 | aTearOffs[i] = null; |
michael@0 | 71 | |
michael@0 | 72 | // Nothing to collect, since we still have the B tearoff reflections. |
michael@0 | 73 | gc(); |
michael@0 | 74 | |
michael@0 | 75 | // Null out B tearoff reflections that are a multiple of 5. |
michael@0 | 76 | for (var i = 0; i < bTearOffs.length; ++i) |
michael@0 | 77 | if (i % 5 == 0) |
michael@0 | 78 | bTearOffs[i] = null; |
michael@0 | 79 | |
michael@0 | 80 | // This should collect every 30th object (indices that are multiples of 2, 3, and 5). |
michael@0 | 81 | gc(); |
michael@0 | 82 | |
michael@0 | 83 | // Kill the b tearoffs entirely. |
michael@0 | 84 | bTearOffs = 0; |
michael@0 | 85 | |
michael@0 | 86 | // Collect more. |
michael@0 | 87 | gc(); |
michael@0 | 88 | |
michael@0 | 89 | // Get C tearoffs. |
michael@0 | 90 | var cTearOffs = instances.map(function(v, i, a) { return v ? v.nsIXPCTestInterfaceC : null; } ); |
michael@0 | 91 | |
michael@0 | 92 | // Check. |
michael@0 | 93 | do_check_true(!('name' in cTearOffs[1]), 'Dont have the prop from A'); |
michael@0 | 94 | do_check_true('someInteger' in cTearOffs[1], 'have the prop from C'); |
michael@0 | 95 | |
michael@0 | 96 | // Null out the a tearoffs. |
michael@0 | 97 | aTearOffs = null; |
michael@0 | 98 | |
michael@0 | 99 | // Collect all even indices. |
michael@0 | 100 | gc(); |
michael@0 | 101 | |
michael@0 | 102 | // Collect all indices. |
michael@0 | 103 | instances = null; |
michael@0 | 104 | gc(); |
michael@0 | 105 | |
michael@0 | 106 | // Give ourselves a pat on the back. :-) |
michael@0 | 107 | do_check_true(true, "Got all the way through without crashing!"); |
michael@0 | 108 | } |