js/src/tests/js1_4/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 var completed = false;
michael@0 2 var testcases;
michael@0 3
michael@0 4 var BUGNUMBER="";
michael@0 5 var EXCLUDE = "";
michael@0 6
michael@0 7 var TT = "";
michael@0 8 var TT_ = "";
michael@0 9 var BR = "";
michael@0 10 var NBSP = " ";
michael@0 11 var CR = "\n";
michael@0 12 var FONT = "";
michael@0 13 var FONT_ = "";
michael@0 14 var FONT_RED = "";
michael@0 15 var FONT_GREEN = "";
michael@0 16 var B = "";
michael@0 17 var B_ = ""
michael@0 18 var H2 = "";
michael@0 19 var H2_ = "";
michael@0 20 var HR = "";
michael@0 21
michael@0 22 var PASSED = " PASSED!"
michael@0 23 var FAILED = " FAILED! expected: ";
michael@0 24
michael@0 25 version( 140 );
michael@0 26 function test() {
michael@0 27 for ( tc=0; tc < testcases.length; tc++ ) {
michael@0 28 testcases[tc].passed = writeTestCaseResult(
michael@0 29 testcases[tc].expect,
michael@0 30 testcases[tc].actual,
michael@0 31 testcases[tc].description +" = "+
michael@0 32 testcases[tc].actual );
michael@0 33
michael@0 34 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
michael@0 35 }
michael@0 36 stopTest();
michael@0 37 return ( testcases );
michael@0 38 }
michael@0 39 function TestCase( n, d, e, a ) {
michael@0 40 this.name = n;
michael@0 41 this.description = d;
michael@0 42 this.expect = e;
michael@0 43 this.actual = a;
michael@0 44 this.passed = true;
michael@0 45 this.reason = "";
michael@0 46 this.bugnumber = BUGNUMBER;
michael@0 47
michael@0 48 this.passed = getTestCaseResult( this.expect, this.actual );
michael@0 49 }
michael@0 50 function startTest() {
michael@0 51 /*
michael@0 52 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
michael@0 53 if ( VERSION == "ECMA_1" ) {
michael@0 54 version ( "130" );
michael@0 55 }
michael@0 56 if ( VERSION == "JS_1.3" ) {
michael@0 57 version ( "130" );
michael@0 58 }
michael@0 59 if ( VERSION == "JS_1.2" ) {
michael@0 60 version ( "120" );
michael@0 61 }
michael@0 62 if ( VERSION == "JS_1.1" ) {
michael@0 63 version ( "110" );
michael@0 64 }
michael@0 65 // for ecma version 2.0, we will leave the javascript version to
michael@0 66 // the default ( for now ).
michael@0 67 */
michael@0 68 }
michael@0 69 function getTestCaseResult( expect, actual ) {
michael@0 70 // because ( NaN == NaN ) always returns false, need to do
michael@0 71 // a special compare to see if we got the right result.
michael@0 72 if ( actual != actual ) {
michael@0 73 if ( typeof actual == "object" ) {
michael@0 74 actual = "NaN object";
michael@0 75 } else {
michael@0 76 actual = "NaN number";
michael@0 77 }
michael@0 78 }
michael@0 79 if ( expect != expect ) {
michael@0 80 if ( typeof expect == "object" ) {
michael@0 81 expect = "NaN object";
michael@0 82 } else {
michael@0 83 expect = "NaN number";
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 var passed = ( expect == actual ) ? true : false;
michael@0 88
michael@0 89 // if both objects are numbers, give a little leeway for rounding.
michael@0 90 if ( !passed
michael@0 91 && typeof(actual) == "number"
michael@0 92 && typeof(expect) == "number"
michael@0 93 ) {
michael@0 94 if ( Math.abs(actual-expect) < 0.0000001 ) {
michael@0 95 passed = true;
michael@0 96 }
michael@0 97 }
michael@0 98
michael@0 99 // verify type is the same
michael@0 100 if ( typeof(expect) != typeof(actual) ) {
michael@0 101 passed = false;
michael@0 102 }
michael@0 103
michael@0 104 return passed;
michael@0 105 }
michael@0 106 function writeTestCaseResult( expect, actual, string ) {
michael@0 107 var passed = getTestCaseResult( expect, actual );
michael@0 108 writeFormattedResult( expect, actual, string, passed );
michael@0 109 return passed;
michael@0 110 }
michael@0 111 function writeFormattedResult( expect, actual, string, passed ) {
michael@0 112 var s = TT + string ;
michael@0 113
michael@0 114 for ( k = 0;
michael@0 115 k < (60 - string.length >= 0 ? 60 - string.length : 5) ;
michael@0 116 k++ ) {
michael@0 117 // s += NBSP;
michael@0 118 }
michael@0 119
michael@0 120 s += B ;
michael@0 121 s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ;
michael@0 122
michael@0 123 print( s + FONT_ + B_ + TT_ );
michael@0 124
michael@0 125 return passed;
michael@0 126 }
michael@0 127
michael@0 128 function writeHeaderToLog( string ) {
michael@0 129 print( H2 + string + H2_ );
michael@0 130 }
michael@0 131 function stopTest() {
michael@0 132 var sizeTag = "<#TEST CASES SIZE>";
michael@0 133 var doneTag = "<#TEST CASES DONE>";
michael@0 134 var beginTag = "<#TEST CASE ";
michael@0 135 var endTag = ">";
michael@0 136
michael@0 137 print(sizeTag);
michael@0 138 print(testcases.length);
michael@0 139 for (tc = 0; tc < testcases.length; tc++)
michael@0 140 {
michael@0 141 print(beginTag + 'PASSED' + endTag);
michael@0 142 print(testcases[tc].passed);
michael@0 143 print(beginTag + 'NAME' + endTag);
michael@0 144 print(testcases[tc].name);
michael@0 145 print(beginTag + 'EXPECTED' + endTag);
michael@0 146 print(testcases[tc].expect);
michael@0 147 print(beginTag + 'ACTUAL' + endTag);
michael@0 148 print(testcases[tc].actual);
michael@0 149 print(beginTag + 'DESCRIPTION' + endTag);
michael@0 150 print(testcases[tc].description);
michael@0 151 print(beginTag + 'REASON' + endTag);
michael@0 152 print(( testcases[tc].passed ) ? "" : "wrong value ");
michael@0 153 print(beginTag + 'BUGNUMBER' + endTag);
michael@0 154 print( BUGNUMBER );
michael@0 155
michael@0 156 }
michael@0 157 print(doneTag);
michael@0 158 gc();
michael@0 159 }
michael@0 160 function getFailedCases() {
michael@0 161 for ( var i = 0; i < testcases.length; i++ ) {
michael@0 162 if ( ! testcases[i].passed ) {
michael@0 163 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
michael@0 164 }
michael@0 165 }
michael@0 166 }

mercurial