1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 var GLOBAL
= this + '';
41 function htmlesc(str
) {
51 function DocumentWrite(s
)
55 var msgDiv
= document
.createElement('div');
57 document
.body
.appendChild(msgDiv
);
62 document
.write(s
+ '<br>\n');
69 for (var i
= 0; i
< arguments
.length
; i
++)
75 if (typeof dump
== 'function')
80 s
= s
.replace(/[<>&]/g, htmlesc
);
85 function writeHeaderToLog( string
) {
86 string
= String(string
);
88 if (typeof dump
== 'function')
93 string
= string
.replace(/[<>&]/g, htmlesc
);
95 DocumentWrite( "<h2>" + string
+ "</h2>" );
98 function writeFormattedResult( expect
, actual
, string
, passed
) {
99 string
= String(string
);
101 if (typeof dump
== 'function')
103 dump( string
+ '\n');
106 string
= string
.replace(/[<>&]/g, htmlesc
);
108 var s
= "<tt>"+ string
;
110 s
+= ( passed
) ? "<font color=#009900> " + PASSED
111 : "<font color=#aa0000> " + FAILED
+ expect
+ "</tt>";
113 DocumentWrite( s
+ "</font></b></tt><br>" );
117 window
.onerror = function (msg
, page
, line
)
121 if (typeof DESCRIPTION
== 'undefined')
123 DESCRIPTION
= 'Unknown';
125 if (typeof EXPECTED
== 'undefined')
127 EXPECTED
= 'Unknown';
130 var testcase
= new TestCase(gTestfile
, DESCRIPTION
, EXPECTED
, "error");
132 if (document
.location
.href
.indexOf('-n.js') != -1)
135 testcase
.passed
= true;
138 testcase
.reason
= page
+ ':' + line
+ ': ' + msg
;
147 // Thanks to igor.bukanov@gmail.com
148 for (var i
= 0; i
!= 4e6
; ++i
)
159 netscape
.security
.PrivilegeManager
.enablePrivilege('UniversalXPConnect');
160 var jsdIDebuggerService
= Components
.interfaces
.jsdIDebuggerService
;
161 var service
= Components
.classes
['@mozilla.org/js/jsd/debugger-service;1'].
162 getService(jsdIDebuggerService
);
175 function Preferences(aPrefRoot
)
180 this.privs
= 'UniversalXPConnect UniversalPreferencesRead ' +
181 'UniversalPreferencesWrite';
183 if (typeof netscape
!= 'undefined' &&
184 'security' in netscape
&&
185 'PrivilegeManager' in netscape
.security
&&
186 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
188 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
190 var nsIPrefService
= Components
.interfaces
.nsIPrefService
;
191 var nsIPrefBranch
= Components
.interfaces
.nsIPrefBranch
;
192 var nsPrefService_CONTRACTID
= "@mozilla.org/preferences-service;1";
194 this.prefRoot
= aPrefRoot
;
195 this.prefService
= Components
.classes
[nsPrefService_CONTRACTID
].
196 getService(nsIPrefService
);
197 this.prefBranch
= this.prefService
.getBranch(aPrefRoot
).
198 QueryInterface(Components
.interfaces
.nsIPrefBranch2
);
207 function Preferences_getPrefRoot()
213 if (typeof netscape
!= 'undefined' &&
214 'security' in netscape
&&
215 'PrivilegeManager' in netscape
.security
&&
216 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
218 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
221 root
= this.prefBranch
.root
;
229 function Preferences_getPref(aPrefName
)
234 if (typeof netscape
!= 'undefined' &&
235 'security' in netscape
&&
236 'PrivilegeManager' in netscape
.security
&&
237 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
239 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
240 value
= this.prefBranch
.getBoolPref(aPrefName
);
249 function Preferences_getBoolPref(aPrefName
)
254 if (typeof netscape
!= 'undefined' &&
255 'security' in netscape
&&
256 'PrivilegeManager' in netscape
.security
&&
257 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
259 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
260 value
= this.prefBranch
.getBoolPref(aPrefName
);
269 function Preferences_getIntPref(aPrefName
)
274 if (typeof netscape
!= 'undefined' &&
275 'security' in netscape
&&
276 'PrivilegeManager' in netscape
.security
&&
277 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
279 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
280 value
= this.prefBranch
.getIntPref(aPrefName
);
289 function Preferences_getCharPref(aPrefName
)
294 if (typeof netscape
!= 'undefined' &&
295 'security' in netscape
&&
296 'PrivilegeManager' in netscape
.security
&&
297 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
299 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
300 value
= this.prefBranch
.getCharPref(aPrefName
);
309 function Preferences_setPref(aPrefName
, aPrefValue
)
315 if (typeof netscape
!= 'undefined' &&
316 'security' in netscape
&&
317 'PrivilegeManager' in netscape
.security
&&
318 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
320 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
322 if (typeof this.orig
[aPrefName
] == 'undefined')
324 this.orig
[aPrefName
] = this.getPref(aPrefName
);
327 value
= this.prefBranch
.setBoolPref(aPrefName
, Boolean(aPrefValue
));
335 function Preferences_setBoolPref(aPrefName
, aPrefValue
)
341 if (typeof netscape
!= 'undefined' &&
342 'security' in netscape
&&
343 'PrivilegeManager' in netscape
.security
&&
344 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
346 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
348 if (typeof this.orig
[aPrefName
] == 'undefined')
350 this.orig
[aPrefName
] = this.getBoolPref(aPrefName
);
353 value
= this.prefBranch
.setBoolPref(aPrefName
, Boolean(aPrefValue
));
361 function Preferences_setIntPref(aPrefName
, aPrefValue
)
367 if (typeof netscape
!= 'undefined' &&
368 'security' in netscape
&&
369 'PrivilegeManager' in netscape
.security
&&
370 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
372 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
374 if (typeof this.orig
[aPrefName
] == 'undefined')
376 this.orig
[aPrefName
] = this.getIntPref(aPrefName
);
379 value
= this.prefBranch
.setIntPref(aPrefName
, Number(aPrefValue
));
387 function Preferences_setCharPref(aPrefName
, aPrefValue
)
393 if (typeof netscape
!= 'undefined' &&
394 'security' in netscape
&&
395 'PrivilegeManager' in netscape
.security
&&
396 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
398 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
400 if (typeof this.orig
[aPrefName
] == 'undefined')
402 this.orig
[aPrefName
] = this.getCharPref(aPrefName
);
405 value
= this.prefBranch
.setCharPref(aPrefName
, String(aPrefValue
));
413 function Preferences_resetPref(aPrefName
)
417 if (typeof netscape
!= 'undefined' &&
418 'security' in netscape
&&
419 'PrivilegeManager' in netscape
.security
&&
420 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
422 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
424 if (aPrefName
in this.orig
)
426 if (typeof this.orig
[aPrefName
] == 'undefined')
428 this.clearPref(aPrefName
);
432 this.setPref(aPrefName
, this.orig
[aPrefName
]);
442 function Preferences_resetAllPrefs()
449 if (typeof netscape
!= 'undefined' &&
450 'security' in netscape
&&
451 'PrivilegeManager' in netscape
.security
&&
452 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
454 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
455 for (prefName
in this.orig
)
457 this.setPref(prefName
, this.orig
[prefName
]);
466 function Preferences_clearPref(aPrefName
)
470 if (typeof netscape
!= 'undefined' &&
471 'security' in netscape
&&
472 'PrivilegeManager' in netscape
.security
&&
473 'enablePrivilege' in netscape
.security
.PrivilegeManager
)
475 netscape
.security
.PrivilegeManager
.enablePrivilege(this.privs
);
476 this.prefBranch
.clearUserPref(aPrefName
);
484 Preferences
.prototype.getPrefRoot
= Preferences_getPrefRoot
;
485 Preferences
.prototype.getPref
= Preferences_getPref
;
486 Preferences
.prototype.getBoolPref
= Preferences_getBoolPref
;
487 Preferences
.prototype.getIntPref
= Preferences_getIntPref
;
488 Preferences
.prototype.getCharPref
= Preferences_getCharPref
;
489 Preferences
.prototype.setPref
= Preferences_setPref
;
490 Preferences
.prototype.setBoolPref
= Preferences_setBoolPref
;
491 Preferences
.prototype.setIntPref
= Preferences_setIntPref
;
492 Preferences
.prototype.setCharPref
= Preferences_setCharPref
;
493 Preferences
.prototype.resetAllPrefs
= Preferences_resetAllPrefs
;
494 Preferences
.prototype.resetPref
= Preferences_resetPref
;
495 Preferences
.prototype.clearPref
= Preferences_clearPref
;
497 function options(aOptionName
)
499 // return value of options() is a comma delimited list
500 // of the previously set values
503 for (var optionName
in options
.currvalues
)
505 value
+= optionName
+ ',';
509 value
= value
.substring(0, value
.length
-1);
514 if (options
.currvalues
[aOptionName
])
516 // option is set, toggle it to unset
517 delete options
.currvalues
[aOptionName
];
518 options
.preferences
.setPref(aOptionName
, false);
522 // option is not set, toggle it to set
523 options
.currvalues
[aOptionName
] = true;
524 options
.preferences
.setPref(aOptionName
, true);
531 function optionsInit() {
533 // hash containing the set options
534 options
.currvalues
= {strict
: '',
542 // record initial values to support resetting
543 // options to their initial values
544 options
.initvalues
= {};
546 // record values in a stack to support pushing
547 // and popping options
548 options
.stackvalues
= [];
550 options
.preferences
= new Preferences('javascript.options.');
552 for (var optionName
in options
.currvalues
)
554 if (!options
.preferences
.getPref(optionName
))
556 delete options
.currvalues
[optionName
];
560 options
.initvalues
[optionName
] = '';
567 var javascriptoptions
= new Preferences('javascript.options.');
568 javascriptoptions
.setIntPref('gczeal', Number(z
));
571 var gJit
= { content
: undefined, chrome
: undefined };
575 var jitoptions
= new Preferences('javascript.options.jit.');
577 if (typeof gJit
.content
== 'undefined')
579 gJit
.content
= jitoptions
.getBoolPref('content');
580 gJit
.chrome
= jitoptions
.getBoolPref('chrome');
585 jitoptions
.setBoolPref('content', true);
586 jitoptions
.setBoolPref('chrome', false);
590 jitoptions
.setBoolPref('content', false);
591 jitoptions
.setBoolPref('chrome', false);
597 function jsTestDriverBrowserInit()
599 if (typeof dump
!= 'function')
607 if (document
.location
.search
.indexOf('?') != 0)
609 // not called with a query string
613 var re
= /test=([^;]+);language=(language|type);([a-zA-Z0-9.=;\/]+)/;
614 var matches
= re
.exec(document
.location
.search
);
616 // testpath http://machine/path-to-suite/sub-suite/test.js
617 var testpath
= matches
[1];
618 var attribute
= matches
[2];
619 var value
= matches
[3];
623 testpath
= decodeURIComponent(testpath
);
624 gTestPath
= testpath
;
627 var ise4x
= /e4x\//.test(testpath
);
629 var gczealmatches
= /gczeal=([0-9]*)/.exec(document
.location
.search
);
633 var zeal
= Number(gczealmatches
[1]);
638 * since the default setting of jit changed from false to true
639 * in http://hg.mozilla.org/tracemonkey/rev/685e00e68be9
640 * bisections which depend upon jit settings can be thrown off.
641 * default jit(false) to make bisections depending upon jit settings
642 * consistent over time. This is not needed in shell tests as the default
643 * jit setting has not changed there.
646 var jitmatches
= /;jit/.exec(document
.location
.search
);
659 if (attribute
== 'type')
661 versionmatches
= /version=([.0-9]+)/.exec(value
);
665 versionmatches
= /javascript([.0-9]+)/.exec(value
);
670 gVersion
= 10*parseInt(versionmatches
[1].replace(/\./g, ''));
672 else if (navigator
.userAgent
.indexOf('Gecko/') != -1)
674 // If the version is not specified, and the browser is Gecko,
675 // adjust the version to match the suite version.
676 if (attribute
== 'type')
678 value
= 'text/javascript;version=';
682 value
= 'javascript';
685 if (testpath
.match(/^js1_6/))
690 else if (testpath
.match(/^js1_7/))
695 else if (testpath
.match(/^js1_8/))
700 else if (testpath
.match(/^js1_8_1/))
712 var testpathparts
= testpath
.split(/\//);
714 if (testpathparts
.length
< 3)
716 // must have at least suitepath/subsuite/testcase.js
719 var suitepath
= testpathparts
.slice(0,testpathparts
.length
-2).join('/');
720 var subsuite
= testpathparts
[testpathparts
.length
- 2];
721 var test
= testpathparts
[testpathparts
.length
- 1];
723 outputscripttag(suitepath
+ '/shell.js', attribute
, value
,
725 outputscripttag(suitepath
+ '/browser.js', attribute
, value
,
727 outputscripttag(suitepath
+ '/' + subsuite
+ '/shell.js', attribute
, value
,
729 outputscripttag(suitepath
+ '/' + subsuite
+ '/browser.js', attribute
, value
,
731 outputscripttag(suitepath
+ '/' + subsuite
+ '/' + test
, attribute
, value
,
734 document
.write('<title>' + suitepath
+ '/' + subsuite
+ '/' + test
+
737 outputscripttag('js-test-driver-end.js', attribute
, value
,
742 function outputscripttag(src
, attribute
, value
, ise4x
)
749 var s
= '<script src="' + src
+ '" ';
753 if (attribute
== 'type')
759 s
+= ' type="text/javascript';
762 s
+= ';version=' + gVersion
/100;
768 s
+= attribute
+ '="' + value
+ '"><\/script>';
773 function jsTestDriverEnd()
775 // gDelayTestDriverEnd is used to
776 // delay collection of the test result and
777 // signal to Spider so that tests can continue
778 // to run after page load has fired. They are
779 // responsible for setting gDelayTestDriverEnd = true
780 // then when completed, setting gDelayTestDriverEnd = false
781 // then calling jsTestDriverEnd()
783 if (gDelayTestDriverEnd
)
788 window
.onerror
= null;
792 var javascriptoptions
= new Preferences('javascript.options.');
793 javascriptoptions
.clearPref('gczeal');
795 var jitoptions
= new Preferences('javascript.options.jit.');
796 if (typeof gJit
.content
!= 'undefined')
798 jitoptions
.setBoolPref('content', gJit
.content
);
801 if (typeof gJit
.chrome
!= 'undefined')
803 jitoptions
.setBoolPref('chrome', gJit
.chrome
);
810 dump('jsTestDriverEnd ' + ex
);
813 if (window
.opener
&& window
.opener
.runNextTest
)
815 if (window
.opener
.reportCallBack
)
817 window
.opener
.reportCallBack(window
.opener
.gWindow
);
819 setTimeout('window.opener.runNextTest()', 250);
823 for (var i
= 0; i
< gTestcases
.length
; i
++)
825 gTestcases
[i
].dump();
828 // tell Spider page is complete
829 gPageCompleted
= true;
833 jsTestDriverBrowserInit();