js/src/tests/js1_2/jsref.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 var completed = false;
michael@0 5 var testcases;
michael@0 6 var tc = 0;
michael@0 7
michael@0 8 SECTION = "";
michael@0 9 VERSION = "";
michael@0 10 BUGNUMBER = "";
michael@0 11 EXCLUDE = "";
michael@0 12
michael@0 13 /*
michael@0 14 * constant strings
michael@0 15 */
michael@0 16 var GLOBAL = "[object global]";
michael@0 17 var PASSED = " PASSED!"
michael@0 18 var FAILED = " FAILED! expected: ";
michael@0 19
michael@0 20 var DEBUG = false;
michael@0 21
michael@0 22 version("120");
michael@0 23 /*
michael@0 24 * change this for date tests if you're not in PST
michael@0 25 */
michael@0 26
michael@0 27 TZ_DIFF = -8;
michael@0 28 /* wrapper for test cas constructor that doesn't require the SECTION
michael@0 29 * argument.
michael@0 30 */
michael@0 31
michael@0 32 function AddTestCase( description, expect, actual ) {
michael@0 33 testcases[tc++] = new TestCase( SECTION, description, expect, actual );
michael@0 34 }
michael@0 35 function TestCase( n, d, e, a ) {
michael@0 36 this.name = n;
michael@0 37 this.description = d;
michael@0 38 this.expect = e;
michael@0 39 this.actual = a;
michael@0 40 this.passed = true;
michael@0 41 this.reason = "";
michael@0 42 this.bugnumber = BUGNUMBER;
michael@0 43
michael@0 44 this.passed = getTestCaseResult( this.expect, this.actual );
michael@0 45 }
michael@0 46 function startTest() {
michael@0 47 version(120);
michael@0 48
michael@0 49 // for ecma version 2.0, we will leave the javascript version to
michael@0 50 // the default ( for now ).
michael@0 51 // print out bugnumber
michael@0 52
michael@0 53 if ( BUGNUMBER ) {
michael@0 54 print ("BUGNUMBER: " + BUGNUMBER );
michael@0 55 }
michael@0 56
michael@0 57 testcases = new Array();
michael@0 58 tc = 0;
michael@0 59
michael@0 60 }
michael@0 61 function test() {
michael@0 62 for ( tc=0; tc < testcases.length; tc++ ) {
michael@0 63 testcases[tc].passed = writeTestCaseResult(
michael@0 64 testcases[tc].expect,
michael@0 65 testcases[tc].actual,
michael@0 66 testcases[tc].description +" = "+
michael@0 67 testcases[tc].actual );
michael@0 68
michael@0 69 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
michael@0 70 }
michael@0 71 stopTest();
michael@0 72 return ( testcases );
michael@0 73 }
michael@0 74 function getTestCaseResult( expect, actual ) {
michael@0 75 // because ( NaN == NaN ) always returns false, need to do
michael@0 76 // a special compare to see if we got the right result.
michael@0 77 if ( actual != actual ) {
michael@0 78 if ( typeof actual == "object" ) {
michael@0 79 actual = "NaN object";
michael@0 80 } else {
michael@0 81 actual = "NaN number";
michael@0 82 }
michael@0 83 }
michael@0 84 if ( expect != expect ) {
michael@0 85 if ( typeof expect == "object" ) {
michael@0 86 expect = "NaN object";
michael@0 87 } else {
michael@0 88 expect = "NaN number";
michael@0 89 }
michael@0 90 }
michael@0 91
michael@0 92 var passed = ( expect == actual ) ? true : false;
michael@0 93
michael@0 94 // if both objects are numbers, give a little leeway for rounding.
michael@0 95 if ( !passed
michael@0 96 && typeof(actual) == "number"
michael@0 97 && typeof(expect) == "number"
michael@0 98 ) {
michael@0 99 if ( Math.abs(actual-expect) < 0.0000001 ) {
michael@0 100 passed = true;
michael@0 101 }
michael@0 102 }
michael@0 103
michael@0 104 // verify type is the same
michael@0 105 if ( typeof(expect) != typeof(actual) ) {
michael@0 106 passed = false;
michael@0 107 }
michael@0 108
michael@0 109 return passed;
michael@0 110 }
michael@0 111 /*
michael@0 112 * Begin printing functions. These functions use the shell's
michael@0 113 * print function. When running tests in the browser, these
michael@0 114 * functions, override these functions with functions that use
michael@0 115 * document.write.
michael@0 116 */
michael@0 117
michael@0 118 function writeTestCaseResult( expect, actual, string ) {
michael@0 119 var passed = getTestCaseResult( expect, actual );
michael@0 120 writeFormattedResult( expect, actual, string, passed );
michael@0 121 return passed;
michael@0 122 }
michael@0 123 function writeFormattedResult( expect, actual, string, passed ) {
michael@0 124 var s = string ;
michael@0 125 s += ( passed ) ? PASSED : FAILED + expect;
michael@0 126 print( s);
michael@0 127 return passed;
michael@0 128 }
michael@0 129
michael@0 130 function writeHeaderToLog( string ) {
michael@0 131 print( string );
michael@0 132 }
michael@0 133 /* end of print functions */
michael@0 134
michael@0 135
michael@0 136 function stopTest() {
michael@0 137 var sizeTag = "<#TEST CASES SIZE>";
michael@0 138 var doneTag = "<#TEST CASES DONE>";
michael@0 139 var beginTag = "<#TEST CASE ";
michael@0 140 var endTag = ">";
michael@0 141
michael@0 142 print(sizeTag);
michael@0 143 print(testcases.length);
michael@0 144 for (tc = 0; tc < testcases.length; tc++)
michael@0 145 {
michael@0 146 print(beginTag + 'PASSED' + endTag);
michael@0 147 print(testcases[tc].passed);
michael@0 148 print(beginTag + 'NAME' + endTag);
michael@0 149 print(testcases[tc].name);
michael@0 150 print(beginTag + 'EXPECTED' + endTag);
michael@0 151 print(testcases[tc].expect);
michael@0 152 print(beginTag + 'ACTUAL' + endTag);
michael@0 153 print(testcases[tc].actual);
michael@0 154 print(beginTag + 'DESCRIPTION' + endTag);
michael@0 155 print(testcases[tc].description);
michael@0 156 print(beginTag + 'REASON' + endTag);
michael@0 157 print(( testcases[tc].passed ) ? "" : "wrong value ");
michael@0 158 print(beginTag + 'BUGNUMBER' + endTag);
michael@0 159 print( BUGNUMBER );
michael@0 160 }
michael@0 161 print(doneTag);
michael@0 162 gc();
michael@0 163 }
michael@0 164
michael@0 165 function getFailedCases() {
michael@0 166 for ( var i = 0; i < testcases.length; i++ ) {
michael@0 167 if ( ! testcases[i].passed ) {
michael@0 168 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
michael@0 169 }
michael@0 170 }
michael@0 171 }
michael@0 172 function err( msg, page, line ) {
michael@0 173 testcases[tc].actual = "error";
michael@0 174 testcases[tc].reason = msg;
michael@0 175 writeTestCaseResult( testcases[tc].expect,
michael@0 176 testcases[tc].actual,
michael@0 177 testcases[tc].description +" = "+ testcases[tc].actual +
michael@0 178 ": " + testcases[tc].reason );
michael@0 179 stopTest();
michael@0 180 return true;
michael@0 181 }
michael@0 182 function Enumerate ( o ) {
michael@0 183 var p;
michael@0 184 for ( p in o ) {
michael@0 185 print( p +": " + o[p] );
michael@0 186 }
michael@0 187 }
michael@0 188 function GetContext() {
michael@0 189 return Packages.com.netscape.javascript.Context.getCurrentContext();
michael@0 190 }
michael@0 191 function OptLevel( i ) {
michael@0 192 i = Number(i);
michael@0 193 var cx = GetContext();
michael@0 194 cx.setOptimizationLevel(i);
michael@0 195 }

mercurial