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.Constructor; |
michael@0 | 8 | const Cc = Components.classes; |
michael@0 | 9 | |
michael@0 | 10 | // The string we use as data. |
michael@0 | 11 | const data = "0123456789"; |
michael@0 | 12 | // Number of streams in the multiplex stream. |
michael@0 | 13 | const count = 10; |
michael@0 | 14 | |
michael@0 | 15 | function test_multiplex_streams() { |
michael@0 | 16 | var MultiplexStream = CC("@mozilla.org/io/multiplex-input-stream;1", |
michael@0 | 17 | "nsIMultiplexInputStream"); |
michael@0 | 18 | do_check_eq(1, 1); |
michael@0 | 19 | |
michael@0 | 20 | var BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1", |
michael@0 | 21 | "nsIBinaryInputStream"); |
michael@0 | 22 | var BinaryOutputStream = Components.Constructor("@mozilla.org/binaryoutputstream;1", |
michael@0 | 23 | "nsIBinaryOutputStream", |
michael@0 | 24 | "setOutputStream"); |
michael@0 | 25 | var multiplex = new MultiplexStream(); |
michael@0 | 26 | for (var i = 0; i < count; ++i) { |
michael@0 | 27 | let s = Cc["@mozilla.org/io/string-input-stream;1"] |
michael@0 | 28 | .createInstance(Ci.nsIStringInputStream); |
michael@0 | 29 | s.setData(data, data.length); |
michael@0 | 30 | |
michael@0 | 31 | multiplex.appendStream(s); |
michael@0 | 32 | } |
michael@0 | 33 | var seekable = multiplex.QueryInterface(Ci.nsISeekableStream); |
michael@0 | 34 | var sis = Cc["@mozilla.org/scriptableinputstream;1"] |
michael@0 | 35 | .createInstance(Ci.nsIScriptableInputStream); |
michael@0 | 36 | sis.init(seekable); |
michael@0 | 37 | // Read some data. |
michael@0 | 38 | var readData = sis.read(20); |
michael@0 | 39 | do_check_eq(readData, data + data); |
michael@0 | 40 | // -- Tests for NS_SEEK_SET |
michael@0 | 41 | // Seek to a non-zero, non-stream-boundary offset. |
michael@0 | 42 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 2); |
michael@0 | 43 | do_check_eq(seekable.tell(), 2); |
michael@0 | 44 | do_check_eq(seekable.available(), 98); |
michael@0 | 45 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 9); |
michael@0 | 46 | do_check_eq(seekable.tell(), 9); |
michael@0 | 47 | do_check_eq(seekable.available(), 91); |
michael@0 | 48 | // Seek across stream boundary. |
michael@0 | 49 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 35); |
michael@0 | 50 | do_check_eq(seekable.tell(), 35); |
michael@0 | 51 | do_check_eq(seekable.available(), 65); |
michael@0 | 52 | readData = sis.read(5); |
michael@0 | 53 | do_check_eq(readData, data.slice(5)); |
michael@0 | 54 | do_check_eq(seekable.available(), 60); |
michael@0 | 55 | // Seek at stream boundaries. |
michael@0 | 56 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 40); |
michael@0 | 57 | do_check_eq(seekable.tell(), 40); |
michael@0 | 58 | do_check_eq(seekable.available(), 60); |
michael@0 | 59 | readData = sis.read(10); |
michael@0 | 60 | do_check_eq(readData, data); |
michael@0 | 61 | do_check_eq(seekable.tell(), 50); |
michael@0 | 62 | do_check_eq(seekable.available(), 50); |
michael@0 | 63 | // Rewind and read across streams. |
michael@0 | 64 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 39); |
michael@0 | 65 | do_check_eq(seekable.tell(), 39); |
michael@0 | 66 | do_check_eq(seekable.available(), 61); |
michael@0 | 67 | readData = sis.read(11); |
michael@0 | 68 | do_check_eq(readData, data.slice(9) + data); |
michael@0 | 69 | do_check_eq(seekable.tell(), 50); |
michael@0 | 70 | do_check_eq(seekable.available(), 50); |
michael@0 | 71 | // Rewind to the beginning. |
michael@0 | 72 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); |
michael@0 | 73 | do_check_eq(seekable.tell(), 0); |
michael@0 | 74 | do_check_eq(seekable.available(), 100); |
michael@0 | 75 | // Seek to some random location |
michael@0 | 76 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 50); |
michael@0 | 77 | // -- Tests for NS_SEEK_CUR |
michael@0 | 78 | // Positive seek. |
michael@0 | 79 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_CUR, 15); |
michael@0 | 80 | do_check_eq(seekable.tell(), 65); |
michael@0 | 81 | do_check_eq(seekable.available(), 35); |
michael@0 | 82 | readData = sis.read(10); |
michael@0 | 83 | do_check_eq(readData, data.slice(5) + data.slice(0, 5)); |
michael@0 | 84 | do_check_eq(seekable.tell(), 75); |
michael@0 | 85 | do_check_eq(seekable.available(), 25); |
michael@0 | 86 | // Negative seek. |
michael@0 | 87 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_CUR, -15); |
michael@0 | 88 | do_check_eq(seekable.tell(), 60); |
michael@0 | 89 | do_check_eq(seekable.available(), 40); |
michael@0 | 90 | readData = sis.read(10); |
michael@0 | 91 | do_check_eq(readData, data); |
michael@0 | 92 | do_check_eq(seekable.tell(), 70); |
michael@0 | 93 | do_check_eq(seekable.available(), 30); |
michael@0 | 94 | |
michael@0 | 95 | // -- Tests for NS_SEEK_END |
michael@0 | 96 | // Normal read. |
michael@0 | 97 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_END, -5); |
michael@0 | 98 | do_check_eq(seekable.tell(), data.length * count - 5); |
michael@0 | 99 | readData = sis.read(5); |
michael@0 | 100 | do_check_eq(readData, data.slice(5)); |
michael@0 | 101 | do_check_eq(seekable.tell(), data.length * count); |
michael@0 | 102 | // Read across streams. |
michael@0 | 103 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_END, -15); |
michael@0 | 104 | do_check_eq(seekable.tell(), data.length * count - 15); |
michael@0 | 105 | readData = sis.read(15); |
michael@0 | 106 | do_check_eq(readData, data.slice(5) + data); |
michael@0 | 107 | do_check_eq(seekable.tell(), data.length * count); |
michael@0 | 108 | |
michael@0 | 109 | // -- Try to do various edge cases |
michael@0 | 110 | // Forward seek from the end, should throw. |
michael@0 | 111 | var caught = false; |
michael@0 | 112 | try { |
michael@0 | 113 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_END, 15); |
michael@0 | 114 | } catch(e) { |
michael@0 | 115 | caught = true; |
michael@0 | 116 | } |
michael@0 | 117 | do_check_eq(caught, true); |
michael@0 | 118 | do_check_eq(seekable.tell(), data.length * count); |
michael@0 | 119 | // Backward seek from the beginning, should be clamped. |
michael@0 | 120 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); |
michael@0 | 121 | do_check_eq(seekable.tell(), 0); |
michael@0 | 122 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_CUR, -15); |
michael@0 | 123 | do_check_eq(seekable.tell(), 0); |
michael@0 | 124 | // Seek too far: should be clamped. |
michael@0 | 125 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); |
michael@0 | 126 | do_check_eq(seekable.tell(), 0); |
michael@0 | 127 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_CUR, 3 * data.length * count); |
michael@0 | 128 | do_check_eq(seekable.tell(), 100); |
michael@0 | 129 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, data.length * count); |
michael@0 | 130 | do_check_eq(seekable.tell(), 100); |
michael@0 | 131 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_CUR, -2 * data.length * count); |
michael@0 | 132 | do_check_eq(seekable.tell(), 0); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | function test_multiplex_bug797871() { |
michael@0 | 136 | |
michael@0 | 137 | var data = "1234567890123456789012345678901234567890"; |
michael@0 | 138 | |
michael@0 | 139 | var MultiplexStream = CC("@mozilla.org/io/multiplex-input-stream;1", |
michael@0 | 140 | "nsIMultiplexInputStream"); |
michael@0 | 141 | do_check_eq(1, 1); |
michael@0 | 142 | |
michael@0 | 143 | var BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1", |
michael@0 | 144 | "nsIBinaryInputStream"); |
michael@0 | 145 | var BinaryOutputStream = Components.Constructor("@mozilla.org/binaryoutputstream;1", |
michael@0 | 146 | "nsIBinaryOutputStream", |
michael@0 | 147 | "setOutputStream"); |
michael@0 | 148 | var multiplex = new MultiplexStream(); |
michael@0 | 149 | let s = Cc["@mozilla.org/io/string-input-stream;1"] |
michael@0 | 150 | .createInstance(Ci.nsIStringInputStream); |
michael@0 | 151 | s.setData(data, data.length); |
michael@0 | 152 | |
michael@0 | 153 | multiplex.appendStream(s); |
michael@0 | 154 | |
michael@0 | 155 | var seekable = multiplex.QueryInterface(Ci.nsISeekableStream); |
michael@0 | 156 | var sis = Cc["@mozilla.org/scriptableinputstream;1"] |
michael@0 | 157 | .createInstance(Ci.nsIScriptableInputStream); |
michael@0 | 158 | sis.init(seekable); |
michael@0 | 159 | |
michael@0 | 160 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 8); |
michael@0 | 161 | do_check_eq(seekable.tell(), 8); |
michael@0 | 162 | readData = sis.read(2); |
michael@0 | 163 | do_check_eq(seekable.tell(), 10); |
michael@0 | 164 | |
michael@0 | 165 | seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 20); |
michael@0 | 166 | do_check_eq(seekable.tell(), 20); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | function run_test() { |
michael@0 | 170 | test_multiplex_streams(); |
michael@0 | 171 | test_multiplex_bug797871(); |
michael@0 | 172 | } |
michael@0 | 173 |