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 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const { dispatcher } = require("sdk/util/dispatcher"); |
michael@0 | 8 | |
michael@0 | 9 | exports["test dispatcher API"] = assert => { |
michael@0 | 10 | const dispatch = dispatcher(); |
michael@0 | 11 | |
michael@0 | 12 | assert.equal(typeof(dispatch), "function", |
michael@0 | 13 | "dispatch is a function"); |
michael@0 | 14 | |
michael@0 | 15 | assert.equal(typeof(dispatch.define), "function", |
michael@0 | 16 | "dispatch.define is a function"); |
michael@0 | 17 | |
michael@0 | 18 | assert.equal(typeof(dispatch.implement), "function", |
michael@0 | 19 | "dispatch.implement is a function"); |
michael@0 | 20 | |
michael@0 | 21 | assert.equal(typeof(dispatch.when), "function", |
michael@0 | 22 | "dispatch.when is a function"); |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | exports["test dispatcher"] = assert => { |
michael@0 | 26 | const isDuck = dispatcher(); |
michael@0 | 27 | |
michael@0 | 28 | const quacks = x => x && typeof(x.quack) === "function"; |
michael@0 | 29 | |
michael@0 | 30 | const Duck = function() {}; |
michael@0 | 31 | const Goose = function() {}; |
michael@0 | 32 | |
michael@0 | 33 | const True = _ => true; |
michael@0 | 34 | const False = _ => false; |
michael@0 | 35 | |
michael@0 | 36 | |
michael@0 | 37 | |
michael@0 | 38 | isDuck.define(Goose, False); |
michael@0 | 39 | isDuck.define(Duck, True); |
michael@0 | 40 | isDuck.when(quacks, True); |
michael@0 | 41 | |
michael@0 | 42 | assert.equal(isDuck(new Goose()), false, |
michael@0 | 43 | "Goose ain't duck"); |
michael@0 | 44 | |
michael@0 | 45 | assert.equal(isDuck(new Duck()), true, |
michael@0 | 46 | "Ducks are ducks"); |
michael@0 | 47 | |
michael@0 | 48 | assert.equal(isDuck({ quack: () => "Quaaaaaack!" }), true, |
michael@0 | 49 | "It's a duck if it quacks"); |
michael@0 | 50 | |
michael@0 | 51 | |
michael@0 | 52 | assert.throws(() => isDuck({}), /Type does not implements method/, "not implemneted"); |
michael@0 | 53 | |
michael@0 | 54 | isDuck.define(Object, False); |
michael@0 | 55 | |
michael@0 | 56 | assert.equal(isDuck({}), false, |
michael@0 | 57 | "Ain't duck if it does not quacks!"); |
michael@0 | 58 | }; |
michael@0 | 59 | |
michael@0 | 60 | exports["test redefining fails"] = assert => { |
michael@0 | 61 | const isPM = dispatcher(); |
michael@0 | 62 | const isAfternoon = time => time.getHours() > 12; |
michael@0 | 63 | |
michael@0 | 64 | isPM.when(isAfternoon, _ => true); |
michael@0 | 65 | |
michael@0 | 66 | assert.equal(isPM(new Date(Date.parse("Jan 23, 1985, 13:20:00"))), true, |
michael@0 | 67 | "yeap afternoon"); |
michael@0 | 68 | assert.equal(isPM({ getHours: _ => 17 }), true, |
michael@0 | 69 | "seems like afternoon"); |
michael@0 | 70 | |
michael@0 | 71 | assert.throws(() => isPM.when(isAfternoon, x => x > 12 && x < 24), |
michael@0 | 72 | /Already implemented for the given predicate/, |
michael@0 | 73 | "can't redefine on same predicate"); |
michael@0 | 74 | |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | require("sdk/test").run(exports); |