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

mercurial