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 | var timer = require("sdk/timers"); |
michael@0 | 6 | const { Loader } = require("sdk/test/loader"); |
michael@0 | 7 | |
michael@0 | 8 | exports.testSetTimeout = function(assert, end) { |
michael@0 | 9 | timer.setTimeout(function() { |
michael@0 | 10 | assert.pass("testSetTimeout passed"); |
michael@0 | 11 | end(); |
michael@0 | 12 | }, 1); |
michael@0 | 13 | }; |
michael@0 | 14 | |
michael@0 | 15 | exports.testParamedSetTimeout = function(assert, end) { |
michael@0 | 16 | let params = [1, 'foo', { bar: 'test' }, null, undefined]; |
michael@0 | 17 | timer.setTimeout.apply(null, [function() { |
michael@0 | 18 | assert.equal(arguments.length, params.length); |
michael@0 | 19 | for (let i = 0, ii = params.length; i < ii; i++) |
michael@0 | 20 | assert.equal(params[i], arguments[i]); |
michael@0 | 21 | end(); |
michael@0 | 22 | }, 1].concat(params)); |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | exports.testClearTimeout = function(assert, end) { |
michael@0 | 26 | var myFunc = function myFunc() { |
michael@0 | 27 | assert.fail("myFunc() should not be called in testClearTimeout"); |
michael@0 | 28 | }; |
michael@0 | 29 | var id = timer.setTimeout(myFunc, 1); |
michael@0 | 30 | timer.setTimeout(function() { |
michael@0 | 31 | assert.pass("testClearTimeout passed"); |
michael@0 | 32 | end(); |
michael@0 | 33 | }, 2); |
michael@0 | 34 | timer.clearTimeout(id); |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | exports.testParamedClearTimeout = function(assert, end) { |
michael@0 | 38 | let params = [1, 'foo', { bar: 'test' }, null, undefined]; |
michael@0 | 39 | var myFunc = function myFunc() { |
michael@0 | 40 | assert.fail("myFunc() should not be called in testClearTimeout"); |
michael@0 | 41 | }; |
michael@0 | 42 | var id = timer.setTimeout(myFunc, 1); |
michael@0 | 43 | timer.setTimeout.apply(null, [function() { |
michael@0 | 44 | assert.equal(arguments.length, params.length); |
michael@0 | 45 | for (let i = 0, ii = params.length; i < ii; i++) |
michael@0 | 46 | assert.equal(params[i], arguments[i]); |
michael@0 | 47 | end(); |
michael@0 | 48 | }, 1].concat(params)); |
michael@0 | 49 | timer.clearTimeout(id); |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | exports.testSetInterval = function (assert, end) { |
michael@0 | 53 | var count = 0; |
michael@0 | 54 | var id = timer.setInterval(function () { |
michael@0 | 55 | count++; |
michael@0 | 56 | if (count >= 5) { |
michael@0 | 57 | timer.clearInterval(id); |
michael@0 | 58 | assert.pass("testSetInterval passed"); |
michael@0 | 59 | end(); |
michael@0 | 60 | } |
michael@0 | 61 | }, 1); |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | exports.testParamedSetInerval = function(assert, end) { |
michael@0 | 65 | let params = [1, 'foo', { bar: 'test' }, null, undefined]; |
michael@0 | 66 | let count = 0; |
michael@0 | 67 | let id = timer.setInterval.apply(null, [function() { |
michael@0 | 68 | count ++; |
michael@0 | 69 | if (count < 5) { |
michael@0 | 70 | assert.equal(arguments.length, params.length); |
michael@0 | 71 | for (let i = 0, ii = params.length; i < ii; i++) |
michael@0 | 72 | assert.equal(params[i], arguments[i]); |
michael@0 | 73 | } else { |
michael@0 | 74 | timer.clearInterval(id); |
michael@0 | 75 | end(); |
michael@0 | 76 | } |
michael@0 | 77 | }, 1].concat(params)); |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | exports.testClearInterval = function (assert, end) { |
michael@0 | 81 | timer.clearInterval(timer.setInterval(function () { |
michael@0 | 82 | assert.fail("setInterval callback should not be called"); |
michael@0 | 83 | }, 1)); |
michael@0 | 84 | var id = timer.setInterval(function () { |
michael@0 | 85 | timer.clearInterval(id); |
michael@0 | 86 | assert.pass("testClearInterval passed"); |
michael@0 | 87 | end(); |
michael@0 | 88 | }, 2); |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | exports.testParamedClearInterval = function(assert, end) { |
michael@0 | 92 | timer.clearInterval(timer.setInterval(function () { |
michael@0 | 93 | assert.fail("setInterval callback should not be called"); |
michael@0 | 94 | }, 1, timer, {}, null)); |
michael@0 | 95 | |
michael@0 | 96 | let id = timer.setInterval(function() { |
michael@0 | 97 | timer.clearInterval(id); |
michael@0 | 98 | assert.equal(3, arguments.length); |
michael@0 | 99 | end(); |
michael@0 | 100 | }, 2, undefined, 'test', {}); |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | |
michael@0 | 104 | exports.testImmediate = function(assert, end) { |
michael@0 | 105 | let actual = []; |
michael@0 | 106 | let ticks = 0; |
michael@0 | 107 | timer.setImmediate(function(...params) { |
michael@0 | 108 | actual.push(params); |
michael@0 | 109 | assert.equal(ticks, 1, "is a next tick"); |
michael@0 | 110 | assert.deepEqual(actual, [["start", "immediates"]]); |
michael@0 | 111 | }, "start", "immediates"); |
michael@0 | 112 | |
michael@0 | 113 | timer.setImmediate(function(...params) { |
michael@0 | 114 | actual.push(params); |
michael@0 | 115 | assert.deepEqual(actual, [["start", "immediates"], |
michael@0 | 116 | ["added"]]); |
michael@0 | 117 | assert.equal(ticks, 1, "is a next tick"); |
michael@0 | 118 | timer.setImmediate(function(...params) { |
michael@0 | 119 | actual.push(params); |
michael@0 | 120 | assert.equal(ticks, 2, "is second tick"); |
michael@0 | 121 | assert.deepEqual(actual, [["start", "immediates"], |
michael@0 | 122 | ["added"], |
michael@0 | 123 | [], |
michael@0 | 124 | ["last", "immediate", "handler"], |
michael@0 | 125 | ["side-effect"]]); |
michael@0 | 126 | end(); |
michael@0 | 127 | }, "side-effect"); |
michael@0 | 128 | }, "added"); |
michael@0 | 129 | |
michael@0 | 130 | timer.setImmediate(function(...params) { |
michael@0 | 131 | actual.push(params); |
michael@0 | 132 | assert.equal(ticks, 1, "is a next tick"); |
michael@0 | 133 | assert.deepEqual(actual, [["start", "immediates"], |
michael@0 | 134 | ["added"], |
michael@0 | 135 | []]); |
michael@0 | 136 | timer.clearImmediate(removeID); |
michael@0 | 137 | }); |
michael@0 | 138 | |
michael@0 | 139 | function removed() { |
michael@0 | 140 | assert.fail("should be removed"); |
michael@0 | 141 | } |
michael@0 | 142 | let removeID = timer.setImmediate(removed); |
michael@0 | 143 | |
michael@0 | 144 | timer.setImmediate(function(...params) { |
michael@0 | 145 | actual.push(params); |
michael@0 | 146 | assert.equal(ticks, 1, "is a next tick"); |
michael@0 | 147 | assert.deepEqual(actual, [["start", "immediates"], |
michael@0 | 148 | ["added"], |
michael@0 | 149 | [], |
michael@0 | 150 | ["last", "immediate", "handler"]]); |
michael@0 | 151 | ticks = ticks + 1; |
michael@0 | 152 | }, "last", "immediate", "handler"); |
michael@0 | 153 | |
michael@0 | 154 | |
michael@0 | 155 | ticks = ticks + 1; |
michael@0 | 156 | }; |
michael@0 | 157 | |
michael@0 | 158 | exports.testUnload = function(assert, end) { |
michael@0 | 159 | var loader = Loader(module); |
michael@0 | 160 | var sbtimer = loader.require("sdk/timers"); |
michael@0 | 161 | |
michael@0 | 162 | var myFunc = function myFunc() { |
michael@0 | 163 | assert.fail("myFunc() should not be called in testUnload"); |
michael@0 | 164 | }; |
michael@0 | 165 | |
michael@0 | 166 | sbtimer.setTimeout(myFunc, 1); |
michael@0 | 167 | sbtimer.setTimeout(myFunc, 1, 'foo', 4, {}, undefined); |
michael@0 | 168 | sbtimer.setInterval(myFunc, 1); |
michael@0 | 169 | sbtimer.setInterval(myFunc, 1, {}, null, 'bar', undefined, 87); |
michael@0 | 170 | loader.unload(); |
michael@0 | 171 | timer.setTimeout(function() { |
michael@0 | 172 | assert.pass("timer testUnload passed"); |
michael@0 | 173 | end(); |
michael@0 | 174 | }, 2); |
michael@0 | 175 | }; |
michael@0 | 176 | |
michael@0 | 177 | require("test").run(exports); |