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 Ci = Components.interfaces; |
michael@0 | 6 | const Cr = Components.results; |
michael@0 | 7 | const Cc = Components.classes; |
michael@0 | 8 | const CC = Components.Constructor; |
michael@0 | 9 | |
michael@0 | 10 | var MutableArray = CC("@mozilla.org/array;1", "nsIMutableArray"); |
michael@0 | 11 | var SupportsString = CC("@mozilla.org/supports-string;1", "nsISupportsString"); |
michael@0 | 12 | |
michael@0 | 13 | function create_n_element_array(n) |
michael@0 | 14 | { |
michael@0 | 15 | var arr = new MutableArray(); |
michael@0 | 16 | for (let i=0; i<n; i++) { |
michael@0 | 17 | let str = new SupportsString(); |
michael@0 | 18 | str.data = "element " + i; |
michael@0 | 19 | arr.appendElement(str, false); |
michael@0 | 20 | } |
michael@0 | 21 | return arr; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function test_appending_null_actually_inserts() |
michael@0 | 25 | { |
michael@0 | 26 | var arr = new MutableArray(); |
michael@0 | 27 | do_check_eq(0, arr.length); |
michael@0 | 28 | arr.appendElement(null, false); |
michael@0 | 29 | do_check_eq(1, arr.length); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function test_object_gets_appended() |
michael@0 | 33 | { |
michael@0 | 34 | var arr = new MutableArray(); |
michael@0 | 35 | var str = new SupportsString(); |
michael@0 | 36 | str.data = "hello"; |
michael@0 | 37 | arr.appendElement(str, false); |
michael@0 | 38 | do_check_eq(1, arr.length); |
michael@0 | 39 | var obj = arr.queryElementAt(0, Ci.nsISupportsString); |
michael@0 | 40 | do_check_eq(str, obj); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function test_insert_at_beginning() |
michael@0 | 44 | { |
michael@0 | 45 | var arr = create_n_element_array(5); |
michael@0 | 46 | // just a sanity check |
michael@0 | 47 | do_check_eq(5, arr.length); |
michael@0 | 48 | var str = new SupportsString(); |
michael@0 | 49 | str.data = "hello"; |
michael@0 | 50 | arr.insertElementAt(str, 0, false); |
michael@0 | 51 | do_check_eq(6, arr.length); |
michael@0 | 52 | var obj = arr.queryElementAt(0, Ci.nsISupportsString); |
michael@0 | 53 | do_check_eq(str, obj); |
michael@0 | 54 | // check the data of all the other objects |
michael@0 | 55 | for (let i=1; i<arr.length; i++) { |
michael@0 | 56 | let obj = arr.queryElementAt(i, Ci.nsISupportsString); |
michael@0 | 57 | do_check_eq("element " + (i-1), obj.data); |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function test_replace_element() |
michael@0 | 62 | { |
michael@0 | 63 | var arr = create_n_element_array(5); |
michael@0 | 64 | // just a sanity check |
michael@0 | 65 | do_check_eq(5, arr.length); |
michael@0 | 66 | var str = new SupportsString(); |
michael@0 | 67 | str.data = "hello"; |
michael@0 | 68 | // replace first element |
michael@0 | 69 | arr.replaceElementAt(str, 0, false); |
michael@0 | 70 | do_check_eq(5, arr.length); |
michael@0 | 71 | var obj = arr.queryElementAt(0, Ci.nsISupportsString); |
michael@0 | 72 | do_check_eq(str, obj); |
michael@0 | 73 | // replace last element |
michael@0 | 74 | arr.replaceElementAt(str, arr.length - 1, false); |
michael@0 | 75 | do_check_eq(5, arr.length); |
michael@0 | 76 | obj = arr.queryElementAt(arr.length - 1, Ci.nsISupportsString); |
michael@0 | 77 | do_check_eq(str, obj); |
michael@0 | 78 | // replace after last element, should insert empty elements |
michael@0 | 79 | arr.replaceElementAt(str, 9, false); |
michael@0 | 80 | do_check_eq(10, arr.length); |
michael@0 | 81 | obj = arr.queryElementAt(9, Ci.nsISupportsString); |
michael@0 | 82 | do_check_eq(str, obj); |
michael@0 | 83 | // AFAIK there's no way to check the empty elements, since you can't QI them. |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function test_clear() |
michael@0 | 87 | { |
michael@0 | 88 | var arr = create_n_element_array(5); |
michael@0 | 89 | // just a sanity check |
michael@0 | 90 | do_check_eq(5, arr.length); |
michael@0 | 91 | arr.clear(); |
michael@0 | 92 | do_check_eq(0, arr.length); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | function test_enumerate() |
michael@0 | 96 | { |
michael@0 | 97 | var arr = create_n_element_array(5); |
michael@0 | 98 | do_check_eq(5, arr.length); |
michael@0 | 99 | var en = arr.enumerate(); |
michael@0 | 100 | var i = 0; |
michael@0 | 101 | while (en.hasMoreElements()) { |
michael@0 | 102 | let str = en.getNext(); |
michael@0 | 103 | do_check_true(str instanceof Ci.nsISupportsString); |
michael@0 | 104 | do_check_eq(str.data, "element " + i); |
michael@0 | 105 | i++; |
michael@0 | 106 | } |
michael@0 | 107 | do_check_eq(arr.length, i); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | var tests = [ |
michael@0 | 111 | test_appending_null_actually_inserts, |
michael@0 | 112 | test_object_gets_appended, |
michael@0 | 113 | test_insert_at_beginning, |
michael@0 | 114 | test_replace_element, |
michael@0 | 115 | test_clear, |
michael@0 | 116 | test_enumerate, |
michael@0 | 117 | ]; |
michael@0 | 118 | |
michael@0 | 119 | function run_test() { |
michael@0 | 120 | for (var i = 0; i < tests.length; i++) |
michael@0 | 121 | tests[i](); |
michael@0 | 122 | } |