1 /* 2 * The contents of this file are subject to the Netscape Public 3 * License Version 1.1 (the "License"); you may not use this file 4 * except in compliance with the License. You may obtain a copy of 5 * the License at http://www.mozilla.org/NPL/ 6 * 7 * Software distributed under the License is distributed on an "AS 8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 9 * implied. See the License for the specific language governing 10 * rights and limitations under the License. 11 * 12 * The Original Code is mozilla.org code. 13 * 14 * The Initial Developer of the Original Code is Netscape 15 * Communications Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 */ 21 22 /* 23 * JavaScript test library shared functions file for running the tests 24 * in the browser. Overrides the shell's print function with document.write 25 * and make everything HTML pretty. 26 * 27 * To run the tests in the browser, use the mkhtml.pl script to generate 28 * html pages that include the shell.js, browser.js (this file), and the 29 * test js file in script tags. 30 * 31 * The source of the page that is generated should look something like this: 32 * <script src="./../shell.js"></script> 33 * <script src="./../browser.js"></script> 34 * <script src="./mytest.js"></script> 35 */ 36 37 onerror = err; 38 39 var GLOBAL = "[object Window]"; 40 41 function startTest() { 42 writeHeaderToLog( SECTION + " "+ TITLE); 43 if ( BUGNUMBER ) { 44 writeLineToLog ("BUGNUMBER: " + BUGNUMBER ); 45 } 46 47 testcases = new Array(); 48 tc = 0; 49 } 50 51 function writeLineToLog( string ) { 52 document.write( string + "<br>\n"); 53 } 54 function writeHeaderToLog( string ) { 55 document.write( "<h2>" + string + "</h2>" ); 56 } 57 function stopTest() { 58 var gc; 59 if ( gc != undefined ) { 60 gc(); 61 } 62 document.write( "<hr>" ); 63 } 64 function writeFormattedResult( expect, actual, string, passed ) { 65 var s = "<tt>"+ string ; 66 s += "<b>" ; 67 s += ( passed ) ? "<font color=#009900> " + PASSED 68 : "<font color=#aa0000> " + FAILED + expect + "</tt>"; 69 writeLineToLog( s + "</font></b></tt>" ); 70 return passed; 71 } 72 function err( msg, page, line ) { 73 writeLineToLog( "Test failed on line " + line + " with the message: " + msg ); 74 75 testcases[tc].actual = "error"; 76 testcases[tc].reason = msg; 77 writeTestCaseResult( testcases[tc].expect, 78 testcases[tc].actual, 79 testcases[tc].description +" = "+ testcases[tc].actual + 80 ": " + testcases[tc].reason ); 81 stopTest(); 82 return true; 83 } 84