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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * Date: 14 April 2001
8 *
9 * SUMMARY: Testing obj.__defineSetter__(), obj.__defineGetter__()
10 * Note: this is a non-ECMA language extension
11 */
12 //-----------------------------------------------------------------------------
13 var UBound = 0;
14 var BUGNUMBER = '(none)';
15 var summary = 'Testing obj.__defineSetter__(), obj.__defineGetter__()';
16 var statprefix = 'Status: ';
17 var status = '';
18 var statusitems = [ ];
19 var actual = '';
20 var actualvalues = [ ];
21 var expect= '';
22 var expectedvalues = [ ];
23 var cnDEFAULT = 'default name';
24 var cnFRED = 'Fred';
25 var obj = {};
26 var obj2 = {};
27 var s = '';
30 // SECTION1: define getter/setter directly on an object (not its prototype)
31 obj = new Object();
32 obj.nameSETS = 0;
33 obj.nameGETS = 0;
34 obj.__defineSetter__('name', function(newValue) {this._name=newValue; this.nameSETS++;});
35 obj.__defineGetter__('name', function() {this.nameGETS++; return this._name;});
37 status = 'In SECTION1 of test after 0 sets, 0 gets';
38 actual = [obj.nameSETS,obj.nameGETS];
39 expect = [0,0];
40 addThis();
42 s = obj.name;
43 status = 'In SECTION1 of test after 0 sets, 1 get';
44 actual = [obj.nameSETS,obj.nameGETS];
45 expect = [0,1];
46 addThis();
48 obj.name = cnFRED;
49 status = 'In SECTION1 of test after 1 set, 1 get';
50 actual = [obj.nameSETS,obj.nameGETS];
51 expect = [1,1];
52 addThis();
54 obj.name = obj.name;
55 status = 'In SECTION1 of test after 2 sets, 2 gets';
56 actual = [obj.nameSETS,obj.nameGETS];
57 expect = [2,2];
58 addThis();
61 // SECTION2: define getter/setter in Object.prototype
62 Object.prototype.nameSETS = 0;
63 Object.prototype.nameGETS = 0;
64 Object.prototype.__defineSetter__('name', function(newValue) {this._name=newValue; this.nameSETS++;});
65 Object.prototype.__defineGetter__('name', function() {this.nameGETS++; return this._name;});
67 obj = new Object();
68 status = 'In SECTION2 of test after 0 sets, 0 gets';
69 actual = [obj.nameSETS,obj.nameGETS];
70 expect = [0,0];
71 addThis();
73 s = obj.name;
74 status = 'In SECTION2 of test after 0 sets, 1 get';
75 actual = [obj.nameSETS,obj.nameGETS];
76 expect = [0,1];
77 addThis();
79 obj.name = cnFRED;
80 status = 'In SECTION2 of test after 1 set, 1 get';
81 actual = [obj.nameSETS,obj.nameGETS];
82 expect = [1,1];
83 addThis();
85 obj.name = obj.name;
86 status = 'In SECTION2 of test after 2 sets, 2 gets';
87 actual = [obj.nameSETS,obj.nameGETS];
88 expect = [2,2];
89 addThis();
92 // SECTION 3: define getter/setter in prototype of user-defined constructor
93 function TestObject()
94 {
95 }
96 TestObject.prototype.nameSETS = 0;
97 TestObject.prototype.nameGETS = 0;
98 TestObject.prototype.__defineSetter__('name', function(newValue) {this._name=newValue; this.nameSETS++;});
99 TestObject.prototype.__defineGetter__('name', function() {this.nameGETS++; return this._name;});
100 TestObject.prototype.name = cnDEFAULT;
102 obj = new TestObject();
103 status = 'In SECTION3 of test after 1 set, 0 gets'; // (we set a default value in the prototype)
104 actual = [obj.nameSETS,obj.nameGETS];
105 expect = [1,0];
106 addThis();
108 s = obj.name;
109 status = 'In SECTION3 of test after 1 set, 1 get';
110 actual = [obj.nameSETS,obj.nameGETS];
111 expect = [1,1];
112 addThis();
114 obj.name = cnFRED;
115 status = 'In SECTION3 of test after 2 sets, 1 get';
116 actual = [obj.nameSETS,obj.nameGETS];
117 expect = [2,1];
118 addThis();
120 obj.name = obj.name;
121 status = 'In SECTION3 of test after 3 sets, 2 gets';
122 actual = [obj.nameSETS,obj.nameGETS];
123 expect = [3,2];
124 addThis();
126 obj2 = new TestObject();
127 status = 'obj2 = new TestObject() after 1 set, 0 gets';
128 actual = [obj2.nameSETS,obj2.nameGETS];
129 expect = [1,0]; // we set a default value in the prototype -
130 addThis();
132 // Use both obj and obj2 -
133 obj2.name = obj.name + obj2.name;
134 status = 'obj2 = new TestObject() after 2 sets, 1 get';
135 actual = [obj2.nameSETS,obj2.nameGETS];
136 expect = [2,1];
137 addThis();
139 status = 'In SECTION3 of test after 3 sets, 3 gets';
140 actual = [obj.nameSETS,obj.nameGETS];
141 expect = [3,3]; // we left off at [3,2] above -
142 addThis();
145 //---------------------------------------------------------------------------------
146 test();
147 //---------------------------------------------------------------------------------
150 function addThis()
151 {
152 statusitems[UBound] = status;
153 actualvalues[UBound] = actual.toString();
154 expectedvalues[UBound] = expect.toString();
155 UBound++;
156 }
159 function test()
160 {
161 enterFunc ('test');
162 printBugNumber(BUGNUMBER);
163 printStatus (summary);
165 for (var i = 0; i < UBound; i++)
166 {
167 reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
168 }
170 exitFunc ('test');
171 }
174 function getStatus(i)
175 {
176 return statprefix + statusitems[i];
177 }