js/src/tests/js1_5/extensions/getset-004.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 /* -*- 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.__defineSetter__(), obj.__defineGetter__()
michael@0 10 * Note: this is a non-ECMA language extension
michael@0 11 */
michael@0 12 //-----------------------------------------------------------------------------
michael@0 13 var UBound = 0;
michael@0 14 var BUGNUMBER = '(none)';
michael@0 15 var summary = 'Testing obj.__defineSetter__(), obj.__defineGetter__()';
michael@0 16 var statprefix = 'Status: ';
michael@0 17 var status = '';
michael@0 18 var statusitems = [ ];
michael@0 19 var actual = '';
michael@0 20 var actualvalues = [ ];
michael@0 21 var expect= '';
michael@0 22 var expectedvalues = [ ];
michael@0 23 var cnDEFAULT = 'default name';
michael@0 24 var cnFRED = 'Fred';
michael@0 25 var obj = {};
michael@0 26 var obj2 = {};
michael@0 27 var s = '';
michael@0 28
michael@0 29
michael@0 30 // SECTION1: define getter/setter directly on an object (not its prototype)
michael@0 31 obj = new Object();
michael@0 32 obj.nameSETS = 0;
michael@0 33 obj.nameGETS = 0;
michael@0 34 obj.__defineSetter__('name', function(newValue) {this._name=newValue; this.nameSETS++;});
michael@0 35 obj.__defineGetter__('name', function() {this.nameGETS++; return this._name;});
michael@0 36
michael@0 37 status = 'In SECTION1 of test after 0 sets, 0 gets';
michael@0 38 actual = [obj.nameSETS,obj.nameGETS];
michael@0 39 expect = [0,0];
michael@0 40 addThis();
michael@0 41
michael@0 42 s = obj.name;
michael@0 43 status = 'In SECTION1 of test after 0 sets, 1 get';
michael@0 44 actual = [obj.nameSETS,obj.nameGETS];
michael@0 45 expect = [0,1];
michael@0 46 addThis();
michael@0 47
michael@0 48 obj.name = cnFRED;
michael@0 49 status = 'In SECTION1 of test after 1 set, 1 get';
michael@0 50 actual = [obj.nameSETS,obj.nameGETS];
michael@0 51 expect = [1,1];
michael@0 52 addThis();
michael@0 53
michael@0 54 obj.name = obj.name;
michael@0 55 status = 'In SECTION1 of test after 2 sets, 2 gets';
michael@0 56 actual = [obj.nameSETS,obj.nameGETS];
michael@0 57 expect = [2,2];
michael@0 58 addThis();
michael@0 59
michael@0 60
michael@0 61 // SECTION2: define getter/setter in Object.prototype
michael@0 62 Object.prototype.nameSETS = 0;
michael@0 63 Object.prototype.nameGETS = 0;
michael@0 64 Object.prototype.__defineSetter__('name', function(newValue) {this._name=newValue; this.nameSETS++;});
michael@0 65 Object.prototype.__defineGetter__('name', function() {this.nameGETS++; return this._name;});
michael@0 66
michael@0 67 obj = new Object();
michael@0 68 status = 'In SECTION2 of test after 0 sets, 0 gets';
michael@0 69 actual = [obj.nameSETS,obj.nameGETS];
michael@0 70 expect = [0,0];
michael@0 71 addThis();
michael@0 72
michael@0 73 s = obj.name;
michael@0 74 status = 'In SECTION2 of test after 0 sets, 1 get';
michael@0 75 actual = [obj.nameSETS,obj.nameGETS];
michael@0 76 expect = [0,1];
michael@0 77 addThis();
michael@0 78
michael@0 79 obj.name = cnFRED;
michael@0 80 status = 'In SECTION2 of test after 1 set, 1 get';
michael@0 81 actual = [obj.nameSETS,obj.nameGETS];
michael@0 82 expect = [1,1];
michael@0 83 addThis();
michael@0 84
michael@0 85 obj.name = obj.name;
michael@0 86 status = 'In SECTION2 of test after 2 sets, 2 gets';
michael@0 87 actual = [obj.nameSETS,obj.nameGETS];
michael@0 88 expect = [2,2];
michael@0 89 addThis();
michael@0 90
michael@0 91
michael@0 92 // SECTION 3: define getter/setter in prototype of user-defined constructor
michael@0 93 function TestObject()
michael@0 94 {
michael@0 95 }
michael@0 96 TestObject.prototype.nameSETS = 0;
michael@0 97 TestObject.prototype.nameGETS = 0;
michael@0 98 TestObject.prototype.__defineSetter__('name', function(newValue) {this._name=newValue; this.nameSETS++;});
michael@0 99 TestObject.prototype.__defineGetter__('name', function() {this.nameGETS++; return this._name;});
michael@0 100 TestObject.prototype.name = cnDEFAULT;
michael@0 101
michael@0 102 obj = new TestObject();
michael@0 103 status = 'In SECTION3 of test after 1 set, 0 gets'; // (we set a default value in the prototype)
michael@0 104 actual = [obj.nameSETS,obj.nameGETS];
michael@0 105 expect = [1,0];
michael@0 106 addThis();
michael@0 107
michael@0 108 s = obj.name;
michael@0 109 status = 'In SECTION3 of test after 1 set, 1 get';
michael@0 110 actual = [obj.nameSETS,obj.nameGETS];
michael@0 111 expect = [1,1];
michael@0 112 addThis();
michael@0 113
michael@0 114 obj.name = cnFRED;
michael@0 115 status = 'In SECTION3 of test after 2 sets, 1 get';
michael@0 116 actual = [obj.nameSETS,obj.nameGETS];
michael@0 117 expect = [2,1];
michael@0 118 addThis();
michael@0 119
michael@0 120 obj.name = obj.name;
michael@0 121 status = 'In SECTION3 of test after 3 sets, 2 gets';
michael@0 122 actual = [obj.nameSETS,obj.nameGETS];
michael@0 123 expect = [3,2];
michael@0 124 addThis();
michael@0 125
michael@0 126 obj2 = new TestObject();
michael@0 127 status = 'obj2 = new TestObject() after 1 set, 0 gets';
michael@0 128 actual = [obj2.nameSETS,obj2.nameGETS];
michael@0 129 expect = [1,0]; // we set a default value in the prototype -
michael@0 130 addThis();
michael@0 131
michael@0 132 // Use both obj and obj2 -
michael@0 133 obj2.name = obj.name + obj2.name;
michael@0 134 status = 'obj2 = new TestObject() after 2 sets, 1 get';
michael@0 135 actual = [obj2.nameSETS,obj2.nameGETS];
michael@0 136 expect = [2,1];
michael@0 137 addThis();
michael@0 138
michael@0 139 status = 'In SECTION3 of test after 3 sets, 3 gets';
michael@0 140 actual = [obj.nameSETS,obj.nameGETS];
michael@0 141 expect = [3,3]; // we left off at [3,2] above -
michael@0 142 addThis();
michael@0 143
michael@0 144
michael@0 145 //---------------------------------------------------------------------------------
michael@0 146 test();
michael@0 147 //---------------------------------------------------------------------------------
michael@0 148
michael@0 149
michael@0 150 function addThis()
michael@0 151 {
michael@0 152 statusitems[UBound] = status;
michael@0 153 actualvalues[UBound] = actual.toString();
michael@0 154 expectedvalues[UBound] = expect.toString();
michael@0 155 UBound++;
michael@0 156 }
michael@0 157
michael@0 158
michael@0 159 function test()
michael@0 160 {
michael@0 161 enterFunc ('test');
michael@0 162 printBugNumber(BUGNUMBER);
michael@0 163 printStatus (summary);
michael@0 164
michael@0 165 for (var i = 0; i < UBound; i++)
michael@0 166 {
michael@0 167 reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
michael@0 168 }
michael@0 169
michael@0 170 exitFunc ('test');
michael@0 171 }
michael@0 172
michael@0 173
michael@0 174 function getStatus(i)
michael@0 175 {
michael@0 176 return statprefix + statusitems[i];
michael@0 177 }

mercurial