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 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * Date: 14 April 2001 |
michael@0 | 8 | * |
michael@0 | 9 | * SUMMARY: Testing obj.__lookupGetter__(), obj.__lookupSetter__() |
michael@0 | 10 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=71992 |
michael@0 | 11 | * |
michael@0 | 12 | * Brendan: "I see no need to provide more than the minimum: |
michael@0 | 13 | * o.__lookupGetter__('p') returns the getter function for o.p, |
michael@0 | 14 | * or undefined if o.p has no getter. Users can wrap and layer." |
michael@0 | 15 | */ |
michael@0 | 16 | //----------------------------------------------------------------------------- |
michael@0 | 17 | var UBound = 0; |
michael@0 | 18 | var BUGNUMBER = 71992; |
michael@0 | 19 | var summary = 'Testing obj.__lookupGetter__(), obj.__lookupSetter__()'; |
michael@0 | 20 | var statprefix = 'Status: '; |
michael@0 | 21 | var status = ''; |
michael@0 | 22 | var statusitems = [ ]; |
michael@0 | 23 | var actual = ''; |
michael@0 | 24 | var actualvalues = [ ]; |
michael@0 | 25 | var expect= ''; |
michael@0 | 26 | var expectedvalues = [ ]; |
michael@0 | 27 | var cnName = 'name'; |
michael@0 | 28 | var cnColor = 'color'; |
michael@0 | 29 | var cnNonExistingProp = 'ASDF_#_$%'; |
michael@0 | 30 | var cnDEFAULT = 'default name'; |
michael@0 | 31 | var cnFRED = 'Fred'; |
michael@0 | 32 | var cnRED = 'red'; |
michael@0 | 33 | var obj = {}; |
michael@0 | 34 | var obj2 = {}; |
michael@0 | 35 | var s; |
michael@0 | 36 | |
michael@0 | 37 | |
michael@0 | 38 | // The only setter and getter functions we'll use in the three sections below - |
michael@0 | 39 | var cnNameSetter = function(newValue) {this._name=newValue; this.nameSETS++;}; |
michael@0 | 40 | var cnNameGetter = function() {this.nameGETS++; return this._name;}; |
michael@0 | 41 | |
michael@0 | 42 | |
michael@0 | 43 | |
michael@0 | 44 | // SECTION1: define getter/setter directly on an object (not its prototype) |
michael@0 | 45 | obj = new Object(); |
michael@0 | 46 | obj.nameSETS = 0; |
michael@0 | 47 | obj.nameGETS = 0; |
michael@0 | 48 | obj.__defineSetter__(cnName, cnNameSetter); |
michael@0 | 49 | obj.__defineGetter__(cnName, cnNameGetter); |
michael@0 | 50 | obj.name = cnFRED; |
michael@0 | 51 | obj.color = cnRED; |
michael@0 | 52 | |
michael@0 | 53 | status ='In SECTION1 of test; looking up extant getter/setter'; |
michael@0 | 54 | actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)]; |
michael@0 | 55 | expect = [cnNameSetter, cnNameGetter]; |
michael@0 | 56 | addThis(); |
michael@0 | 57 | |
michael@0 | 58 | status = 'In SECTION1 of test; looking up nonexistent getter/setter'; |
michael@0 | 59 | actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)]; |
michael@0 | 60 | expect = [undefined, undefined]; |
michael@0 | 61 | addThis(); |
michael@0 | 62 | |
michael@0 | 63 | status = 'In SECTION1 of test; looking up getter/setter on nonexistent property'; |
michael@0 | 64 | actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)]; |
michael@0 | 65 | expect = [undefined, undefined]; |
michael@0 | 66 | addThis(); |
michael@0 | 67 | |
michael@0 | 68 | |
michael@0 | 69 | |
michael@0 | 70 | // SECTION2: define getter/setter in Object.prototype |
michael@0 | 71 | Object.prototype.nameSETS = 0; |
michael@0 | 72 | Object.prototype.nameGETS = 0; |
michael@0 | 73 | Object.prototype.__defineSetter__(cnName, cnNameSetter); |
michael@0 | 74 | Object.prototype.__defineGetter__(cnName, cnNameGetter); |
michael@0 | 75 | |
michael@0 | 76 | obj = new Object(); |
michael@0 | 77 | obj.name = cnFRED; |
michael@0 | 78 | obj.color = cnRED; |
michael@0 | 79 | |
michael@0 | 80 | status = 'In SECTION2 of test looking up extant getter/setter'; |
michael@0 | 81 | actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)]; |
michael@0 | 82 | expect = [cnNameSetter, cnNameGetter]; |
michael@0 | 83 | addThis(); |
michael@0 | 84 | |
michael@0 | 85 | status = 'In SECTION2 of test; looking up nonexistent getter/setter'; |
michael@0 | 86 | actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)]; |
michael@0 | 87 | expect = [undefined, undefined]; |
michael@0 | 88 | addThis(); |
michael@0 | 89 | |
michael@0 | 90 | status = 'In SECTION2 of test; looking up getter/setter on nonexistent property'; |
michael@0 | 91 | actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)]; |
michael@0 | 92 | expect = [undefined, undefined]; |
michael@0 | 93 | addThis(); |
michael@0 | 94 | |
michael@0 | 95 | |
michael@0 | 96 | |
michael@0 | 97 | // SECTION 3: define getter/setter in prototype of user-defined constructor |
michael@0 | 98 | function TestObject() |
michael@0 | 99 | { |
michael@0 | 100 | } |
michael@0 | 101 | TestObject.prototype.nameSETS = 0; |
michael@0 | 102 | TestObject.prototype.nameGETS = 0; |
michael@0 | 103 | TestObject.prototype.__defineSetter__(cnName, cnNameSetter); |
michael@0 | 104 | TestObject.prototype.__defineGetter__(cnName, cnNameGetter); |
michael@0 | 105 | TestObject.prototype.name = cnDEFAULT; |
michael@0 | 106 | |
michael@0 | 107 | obj = new TestObject(); |
michael@0 | 108 | obj.name = cnFRED; |
michael@0 | 109 | obj.color = cnRED; |
michael@0 | 110 | |
michael@0 | 111 | status = 'In SECTION3 of test looking up extant getter/setter'; |
michael@0 | 112 | actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)]; |
michael@0 | 113 | expect = [cnNameSetter, cnNameGetter]; |
michael@0 | 114 | addThis(); |
michael@0 | 115 | |
michael@0 | 116 | status = 'In SECTION3 of test; looking up nonexistent getter/setter'; |
michael@0 | 117 | actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)]; |
michael@0 | 118 | expect = [undefined, undefined]; |
michael@0 | 119 | addThis(); |
michael@0 | 120 | |
michael@0 | 121 | status = 'In SECTION3 of test; looking up getter/setter on nonexistent property'; |
michael@0 | 122 | actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)]; |
michael@0 | 123 | expect = [undefined, undefined]; |
michael@0 | 124 | addThis(); |
michael@0 | 125 | |
michael@0 | 126 | |
michael@0 | 127 | |
michael@0 | 128 | //--------------------------------------------------------------------------------- |
michael@0 | 129 | test(); |
michael@0 | 130 | //--------------------------------------------------------------------------------- |
michael@0 | 131 | |
michael@0 | 132 | |
michael@0 | 133 | function addThis() |
michael@0 | 134 | { |
michael@0 | 135 | statusitems[UBound] = status; |
michael@0 | 136 | actualvalues[UBound] = actual.toString(); |
michael@0 | 137 | expectedvalues[UBound] = expect.toString(); |
michael@0 | 138 | UBound++; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | |
michael@0 | 142 | function test() |
michael@0 | 143 | { |
michael@0 | 144 | enterFunc ('test'); |
michael@0 | 145 | printBugNumber(BUGNUMBER); |
michael@0 | 146 | printStatus (summary); |
michael@0 | 147 | |
michael@0 | 148 | for (var i = 0; i < UBound; i++) |
michael@0 | 149 | { |
michael@0 | 150 | reportCompare(expectedvalues[i], actualvalues[i], getStatus(i)); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | exitFunc ('test'); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | |
michael@0 | 157 | function getStatus(i) |
michael@0 | 158 | { |
michael@0 | 159 | return statprefix + statusitems[i]; |
michael@0 | 160 | } |