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

mercurial