Home | History | Annotate | Download | only in js1_4
      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 function startTest() {
     40     if ( BUGNUMBER ) {
     41         writeLineToLog ("BUGNUMBER: " + BUGNUMBER );
     42     }
     43 
     44     testcases = new Array();
     45     tc = 0;
     46 }
     47 
     48 function writeLineToLog( string ) {
     49     document.write( string + "<br>\n");
     50 }
     51 function writeHeaderToLog( string ) {
     52     document.write( "<h2>" + string + "</h2>" );
     53 }
     54 function stopTest() {
     55     var gc;
     56     if ( gc != undefined ) {
     57         gc();
     58     }
     59     document.write( "<hr>" );
     60 }
     61 function writeFormattedResult( expect, actual, string, passed ) {
     62     var s = "<tt>"+ string ;
     63     s += "<b>" ;
     64     s += ( passed ) ? "<font color=#009900> &nbsp;" + PASSED
     65                     : "<font color=#aa0000>&nbsp;" +  FAILED + expect + "</tt>";
     66     writeLineToLog( s + "</font></b></tt>" );
     67     return passed;
     68 }
     69 function err( msg, page, line ) {
     70     writeLineToLog( "Test failed with the message: " + msg );
     71 
     72     testcases[tc].actual = "error";
     73     testcases[tc].reason = msg;
     74     writeTestCaseResult( testcases[tc].expect,
     75                          testcases[tc].actual,
     76                          testcases[tc].description +" = "+ testcases[tc].actual +
     77                          ": " + testcases[tc].reason );
     78     stopTest();
     79     return true;
     80 }
     81