addon-sdk/source/test/traits/inheritance-tests.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 var Trait = require("sdk/deprecated/light-traits").Trait;
michael@0 8
michael@0 9 exports["test custom constructor and inherited toString"] = function(assert) {
michael@0 10 function Type() {
michael@0 11 return Object.create(Type.prototype);
michael@0 12 }
michael@0 13 Type.prototype = Trait({
michael@0 14 method: function method() {
michael@0 15 return 2;
michael@0 16 }
michael@0 17 }).create(Object.freeze(Type.prototype));
michael@0 18
michael@0 19 var fixture = Type();
michael@0 20
michael@0 21 assert.equal(fixture.constructor, Type, "must override constructor");
michael@0 22 assert.equal(fixture.toString(), "[object Type]", "must inherit toString");
michael@0 23 };
michael@0 24
michael@0 25 exports["test custom toString and inherited constructor"] = function(assert) {
michael@0 26 function Type() {
michael@0 27 return Object.create(Type.prototype);
michael@0 28 }
michael@0 29 Type.prototype = Trait({
michael@0 30 toString: function toString() {
michael@0 31 return "<toString>";
michael@0 32 }
michael@0 33 }).create();
michael@0 34
michael@0 35 var fixture = Type();
michael@0 36
michael@0 37 assert.equal(fixture.constructor, Trait, "must inherit constructor Trait");
michael@0 38 assert.equal(fixture.toString(), "<toString>", "Must override toString");
michael@0 39 };
michael@0 40
michael@0 41 exports["test custom toString and constructor"] = function(assert) {
michael@0 42 function Type() {
michael@0 43 return TypeTrait.create(Type.prototype);
michael@0 44 }
michael@0 45 Object.freeze(Type.prototype);
michael@0 46 var TypeTrait = Trait({
michael@0 47 toString: function toString() {
michael@0 48 return "<toString>";
michael@0 49 }
michael@0 50 });
michael@0 51
michael@0 52 var fixture = Type();
michael@0 53
michael@0 54 assert.equal(fixture.constructor, Type, "constructor is provided to create");
michael@0 55 assert.equal(fixture.toString(), "<toString>", "toString was overridden");
michael@0 56 };
michael@0 57
michael@0 58 exports["test resolve constructor"] = function (assert) {
michael@0 59 function Type() {}
michael@0 60 var T1 = Trait({ constructor: Type }).resolve({ constructor: '_foo' });
michael@0 61 var f1 = T1.create();
michael@0 62
michael@0 63 assert.equal(f1._foo, Type, "constructor was resolved");
michael@0 64 assert.equal(f1.constructor, Trait, "constructor of prototype is inherited");
michael@0 65 assert.equal(f1.toString(), "[object Trait]", "toString is inherited");
michael@0 66 };
michael@0 67
michael@0 68 exports["test compose read-only"] = function (assert) {
michael@0 69 function Type() {}
michael@0 70 Type.prototype = Trait.compose(Trait({}), {
michael@0 71 constructor: { value: Type },
michael@0 72 a: { value: "b", enumerable: true }
michael@0 73 }).resolve({ a: "b" }).create({ a: "a" });
michael@0 74
michael@0 75 var f1 = new Type();
michael@0 76
michael@0 77 assert.equal(Object.getPrototypeOf(f1), Type.prototype, "inherits correctly");
michael@0 78 assert.equal(f1.constructor, Type, "constructor was overridden");
michael@0 79 assert.equal(f1.toString(), "[object Type]", "toString was inherited");
michael@0 80 assert.equal(f1.a, "a", "property a was resolved");
michael@0 81 assert.equal(f1.b, "b", "property a was renamed to b");
michael@0 82 assert.ok(!Object.getOwnPropertyDescriptor(Type.prototype, "a"),
michael@0 83 "a is not on the prototype of the instance");
michael@0 84
michael@0 85 var proto = Object.getPrototypeOf(Type.prototype);
michael@0 86 var dc = Object.getOwnPropertyDescriptor(Type.prototype, "constructor");
michael@0 87 var db = Object.getOwnPropertyDescriptor(Type.prototype, "b");
michael@0 88 var da = Object.getOwnPropertyDescriptor(proto, "a");
michael@0 89
michael@0 90 assert.ok(!dc.writable, "constructor is not writable");
michael@0 91 assert.ok(!dc.enumerable, "constructor is not enumerable");
michael@0 92 assert.ok(dc.configurable, "constructor inherits configurability");
michael@0 93
michael@0 94 assert.ok(!db.writable, "a -> b is not writable");
michael@0 95 assert.ok(db.enumerable, "a -> b is enumerable");
michael@0 96 assert.ok(!db.configurable, "a -> b is not configurable");
michael@0 97
michael@0 98 assert.ok(da.writable, "a is writable");
michael@0 99 assert.ok(da.enumerable, "a is enumerable");
michael@0 100 assert.ok(da.configurable, "a is configurable");
michael@0 101 };
michael@0 102
michael@0 103 if (require.main == module)
michael@0 104 require("test").run(exports);

mercurial