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
));
573 var javascriptoptions
= new Preferences('javascript.options.jit.');
576 javascriptoptions
.setBoolPref('content', true);
577 javascriptoptions
.setBoolPref('chrome', true);
581 javascriptoptions
.setBoolPref('content', false);
582 javascriptoptions
.setBoolPref('chrome', false);
588 function jsTestDriverBrowserInit()
590 if (typeof dump
!= 'function')
598 if (document
.location
.search
.indexOf('?') != 0)
600 // not called with a query string
604 var re
= /test=([^;]+);language=(language|type);([a-zA-Z0-9.=;\/]+)/;
605 var matches
= re
.exec(document
.location
.search
);
607 // testpath http://machine/path-to-suite/sub-suite/test.js
608 var testpath
= matches
[1];
609 var attribute
= matches
[2];
610 var value
= matches
[3];
614 testpath
= decodeURIComponent(testpath
);
615 gTestPath
= testpath
;
618 var ise4x
= /e4x\//.test(testpath
);
620 var gczealmatches
= /gczeal=([0-9]*)/.exec(document
.location
.search
);
624 var zeal
= Number(gczealmatches
[1]);
628 var jitmatches
= /;jit/.exec(document
.location
.search
);
635 var versionmatches
= /version=([.0-9]*)/.exec(value
);
639 value
= 'text/javascript;version=';
640 if (testpath
.match(/^js1_6/))
645 else if (testpath
.match(/^js1_7/))
650 else if (testpath
.match(/^js1_8/))
655 else if (testpath
.match(/^js1_8_1/))
668 gVersion
= 10*parseInt(versionmatches
[1].replace(/\./g, ''));
671 var testpathparts
= testpath
.split(/\//);
673 if (testpathparts
.length
< 3)
675 // must have at least suitepath/subsuite/testcase.js
678 var suitepath
= testpathparts
.slice(0,testpathparts
.length
-2).join('/');
679 var subsuite
= testpathparts
[testpathparts
.length
- 2];
680 var test
= testpathparts
[testpathparts
.length
- 1];
682 outputscripttag(suitepath
+ '/shell.js', attribute
, value
,
684 outputscripttag(suitepath
+ '/browser.js', attribute
, value
,
686 outputscripttag(suitepath
+ '/' + subsuite
+ '/shell.js', attribute
, value
,
688 outputscripttag(suitepath
+ '/' + subsuite
+ '/browser.js', attribute
, value
,
690 outputscripttag(suitepath
+ '/' + subsuite
+ '/' + test
, attribute
, value
,
693 document
.write('<title>' + suitepath
+ '/' + subsuite
+ '/' + test
+
696 outputscripttag('js-test-driver-end.js', attribute
, value
,
701 function outputscripttag(src
, attribute
, value
, ise4x
)
708 var s
= '<script src="' + src
+ '" ';
712 if (attribute
== 'type')
718 s
+= ' type="text/javascript';
721 s
+= ';version=' + gVersion
/100;
727 s
+= attribute
+ '="' + value
+ '"><\/script>';
732 function jsTestDriverEnd()
734 // gDelayTestDriverEnd is used to
735 // delay collection of the test result and
736 // signal to Spider so that tests can continue
737 // to run after page load has fired. They are
738 // responsible for setting gDelayTestDriverEnd = true
739 // then when completed, setting gDelayTestDriverEnd = false
740 // then calling jsTestDriverEnd()
742 if (gDelayTestDriverEnd
)
747 window
.onerror
= null;
751 var javascriptoptions
= new Preferences('javascript.options.');
752 javascriptoptions
.clearPref('gczeal');
757 dump('jsTestDriverEnd ' + ex
);
760 if (window
.opener
&& window
.opener
.runNextTest
)
762 if (window
.opener
.reportCallBack
)
764 window
.opener
.reportCallBack(window
.opener
.gWindow
);
766 setTimeout('window.opener.runNextTest()', 250);
770 for (var i
= 0; i
< gTestcases
.length
; i
++)
772 gTestcases
[i
].dump();
775 // tell Spider page is complete
776 gPageCompleted
= true;
780 jsTestDriverBrowserInit();