1
<body onload=onlfunc() onunload=onunlfunc()>
2
<script language="JavaScript">
3
/* This is the javascript regression test for edbrowse.
4
It attempts to exercise all the implemented features of javascript,
5
which is, by the way, not all the features of javascript by any means.
6
Run this program after every software change,
7
and certainly before each release.
8
If a test fails, we give you the test number and abort.
9
Fix the bug and rerun, until all tests pass.
10
Warning: these tests are in no particular order, except if you rearrange
11
them they will fail, because some depend on variables that were
12
set by others. Yeah, it's ugly. */
14
var udef = "undefined";
15
function fail(n) { alert("failed "+n); close(); }
17
var popwin = new Window("http://www.moreAndMoreCrap.com/BuyNow.html", "obnoxious_ad", "width=72");
20
// for loop with break and continue
21
for(n=0, j=1; j<=20; ++j) {
23
if(j%7 == 0) continue;
27
if(n != 2093) fail(1);
29
// while loop with break and continue
34
if(j >= 3 && j <= 5) continue;
38
if(n != 2237) fail(2);
42
if(n == 29) n = 282; else n = 321;
43
if(n-1 != 320) fail(3);
63
case 777: j = 7; break;
67
var bt = true; // a boolean value
68
var f = 6.25; // a perfectly representable floating value
69
if("cat" + 15 + "dog" + f + bt != "cat15dog6.25true") fail(7);
70
if(Math.sqrt(f) != 2.5) fail(8);
72
// silly braces and semis, and optional semis
81
if(Math.pow(11,4) != 14641) fail(10);
83
var alpha = "abc\144\x65fghijklmnopqrstuvwxyz\r\n";
84
if(alpha.substring(2,7) != "cdefg") fail(11);
85
if(alpha.length != 28) fail(12);
86
if(alpha.charAt(10) != 'k') fail(13);
87
if(alpha.indexOf("rrr") != -1) fail(15);
88
if(alpha.lastIndexOf("quack") != -1) fail(16);
89
if(alpha.indexOf("def") != 3) fail(17);
91
if(alpha.lastIndexOf("bc") != 29) fail(18);
93
var a = alpha.split('b');
94
if(a.length != 3) fail(20);
95
if(a[0] != 'a') fail(21);
96
if(a[2] != "cxyz") fail(22);
97
if(a.join("--") != "a--cdefghijklmnopqrstuvwxyz\r\nu--cxyz") fail(23);
99
a = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"];
100
if(a.length != 7) fail(30);
103
if(a[3] + a[4][0] != 108) fail(32);
104
a.length = 6; // lop off violet
105
if(typeof(a[8]) != udef || a.length != 6) fail(33);
106
if(a[5]+a[0] != "indigored") fail(34);
109
alpha = "This 3rd-line is �me!";
110
if(unescape(escape(alpha)) != alpha) fail(36);
112
// function with a static variable
113
function mult$sv(x,y)
116
return mult$sv.counter*x*y;
119
if(mult$sv(17,3) != 51) fail(40);
120
if(mult$sv(19,5) != 190) fail(41);
121
if(mult$sv.counter != 2) fail(42);
123
// A recursive function with func.x references
124
function factorial(n)
128
return n*factorial(n-1);
130
if(factorial(6) != 720) fail(44);
131
var bang = factorial;
132
if(bang(8) != 40320) fail(45);
133
if(bang != factorial) fail(46);
134
if(typeof factorial.n != udef || typeof factorial.y != udef) fail(47);
137
var domax = function() {
138
if(arguments.length != 7) fail(50);
139
var max = -Number.MAX_VALUE;
140
for(var j=0; j<arguments.length; ++j) {
141
var k = arguments[j];
146
if(domax(7, 2.5, 12, -3, -955.5, 76, 19) != 76) fail(51);
148
/*********************************************************************
150
function g(z) { return z*z*z; }
154
if(caller != fc1) fail(52);
155
return y*y + caller.g(3);
157
if(fc1(8) != 84) fail(53);
158
if(fc1.g(5) != 125) fail(54);
159
*********************************************************************/
161
var mysqrt = Math.sqrt;
162
if(mysqrt(1089) != 33) fail(55);
165
if((10&7) != 2) fail(60);
166
if((10|7) != 15) fail(61);
167
if((10^7) != 13) fail(62);
168
if(~10 != -11) fail(63);
169
if(10<<2 != 40) fail(64);
170
if(10>>2 != 2) fail(66);
171
if(-15 >> 2 != -4) fail(67);
172
if(-1 >>> 16 != 65535) fail(68);
174
// a little bit of oo stuff
175
// Let's make methods both ways.
179
if(arguments.length == 1) this.r = arguments[0];
180
this.c = function() { return this.r*Math.PI*2; }
183
function CircleArea() { return this.r*this.r*Math.PI; }
184
var c1 = new Circle();
185
var c2 = new Circle(23);
186
// also test the with construct
188
if(c1.r != 1 || c2.r != 23) fail(70);
190
if(c2.a() != 100*PI) fail(72);
194
if(n != "rca") fail(73);
197
a = new Array("red", "orange", "yellow", "green", "blue", "indigo", "violet");
198
function acmp(x,y) { return x > y ? 1 : -1; }
200
if(a.join(':') != "blue:green:indigo:orange:red:violet:yellow") fail(74);
201
if(a.length != 7) fail(75);
202
if(a[5] != "violet") fail(76);
205
if(typeof oo != "object") fail(77);
206
oo.p = 61, oo.q = 67;
208
for(j in oo) n += j+oo[j];
209
if(n != "p61q67") fail(78);
210
if(c2.constructor != Circle || oo.constructor != Object) fail(79);
213
var d = new Date(2003,11,25,17,55,9);
214
d.setYear(d.getYear()-1);
215
if(d.getMonth() != 11 || d.getDate() != 25) fail(81);
216
if(d.getHours() != 17 || d.getMinutes() != 55 || d.getSeconds() != 9) fail(82);
217
if(d.constructor != Date || a.constructor != Array) fail(84);
220
function topthis() { this.topprop = 887; }
222
if(topprop != 887) fail(88);
224
// A couple functions, and the first couple lines of the input form.
225
function calc(thisform)
227
var l = thisform.body.value.length;
228
thisform.result.value = l;
230
alert("You cant go over Limit of 2000 Characters!");
233
document.writeln("<form method=POST \
235
onsubmit='return submitFunction(questionnaire)' \
236
onreset='return resetFunction()' \
237
onload=formLoad(this.name) onunload=formUnload(this.name)>");
238
// The rest of the form you'll see in straight html
239
// Let javascript generate another javascript tag
240
document.writeln("<script language=JavaScript>document.writeln('Subject: ');</" + "script>");
244
<input type='hidden' name='id' value='eklhad'>
245
<input type='hidden' name='password' value='secret'>
246
<input type='text' name='subject' size='50' maxlength='80'>
248
<select name=state onchange=newSelect(this)>
249
<option selected value=-->
272
Federated States Of Micronesia
330
Northern Mariana Islands
372
<input type=number maxlength=5 name="zip code" readonly value="88888">
373
<span id=almond></span>
374
<table><tr></tr><tr id=pecan></tr></table>
375
<br>My favorite colors are:
376
<select name=colors multiple>
380
<option selected> green
384
<option selected> white
389
<input type=radio name=money value=0>
391
<input type=radio name=money value=1 checked>
393
<input type=radio name=money value=2>
395
<input type=radio name=money value=3>
397
dog <input type=checkbox name=dog id=hound checked onclick=alert('rover')>
398
cat <input type=checkbox name=cat onclick="alert('fluffy'); if(this.checked&&questionnaire.dog.checked) alert('chased by dog');" value=meow>
399
bird <input type=checkbox name=bird>
400
rabbit <input type=checkbox name=rabbit>
402
<textarea name='body' rows='6' cols='50'>
403
Type your brilliant thoughts here.
404
We'll get back to you if we like what you have to say.
407
<input type=button name=b value=calc onclick=calc(this.form)>
408
<input type='text' readonly name='result' size='4'>
409
<input type='reset' value='Reset' name='b0'>
410
<input type='submit' value='Send Message' name='b1'
411
onclick="alert('rock and roll')">
413
<bgsound src=whatever.mid>
415
<script language="JavaScript">
416
// I'll push the button for you
417
document.questionnaire.b.onclick();
418
if(document.questionnaire.result.value != 90) fail(85);
419
if(document.questionnaire.id.value != "eklhad") fail(86);
420
if(document.forms[0].elements[1].value != "secret") fail(87);
422
// prototype objects, use the Circle model
423
Circle.prototype.q = 97;
424
Circle.prototype.m = function(z) { return z*z*z; };
425
c2.q = 84; // hide 97
426
if(c1.q != 97) fail(90);
427
if(c2.q != 84) fail(91);
428
if(c1["m"](9) != 729) fail(92);
430
if(q != 97) fail(93);
431
if(m(7) != 343) fail(94);
434
// prototype an implicite class
435
String.prototype.xy = function() {
436
return this.replace(/x/g, 'y');
439
if(n.xy() != "siyty") fail(95);
440
if("fix my fox".xy() != "fiy my foy") fail(96);
441
Array.prototype.firstLast = function() {
443
var l = this.length-1;
449
if(a.join('zz') != "25zz21zz17") fail(97);
451
// check some of the element tags
452
with(document.questionnaire) {
453
if(!(dog.checked && dog.defaultChecked)) fail(100);
454
if(cat.checked || cat.defaultChecked) fail(101);
455
if(dog.type != "checkbox" || money.type != "radio" || money.length != 4) fail(102);
456
if(id.type != "hidden" || subject.type != "text") fail(103);
457
if(b0.type != "reset" || b1.type != "submit") fail(104);
458
if(body.type != "textarea" || b.type != "button") fail(105);
459
if(state.type != "select-one" || colors.type != "select-multiple") fail(106);
460
if(id.defaultValue != "eklhad") fail(107);
461
if(body.value.substring(10,19) != "brilliant") fail(108);
462
// focus and blur are ignored
469
// for(var i in document.idMaster) alert(i);
470
if(document.getElementById("hound").name != "dog") fail(110);
471
if(document.getElementById("almond") != document.spans[0]) fail(111);
472
// I'm not sure of any of this table row stuff
473
if(document.getElementById("pecan") != document.tables[0].rows[1]) fail(112);
474
if(document.all.tags("FORM")[0] != document.questionnaire) fail(113);
475
if(document.all.tags("span").length != 1) fail(114);
480
if(j.length > 1) continue;
483
if(n != 299) fail(119);
486
var ilo = {a:document.questionnaire, b:9+5*3};
487
if(typeof ilo.a != "object") fail(120);
488
if(ilo.b != 24) fail(121);
489
if(ilo.a.id.value != "eklhad") fail(122);
491
function submitFunction(me) {
492
if(document.questionnaire != me) fail(123);
493
var where = prompt("Enter m for mail, w for web, a to autosubmit, x to abort.", "x");
495
(where == 'm' ? "mailto:karl@eklhad.net" : "http://localhost:1200/foobar");
496
if(where == 'a') me.submit();
497
if(where != 'm' && where != 'w') return false;
501
function resetFunction() {
502
return confirm("All that hard work, are you sure you want to reset?");
505
function newSelect(e) {
506
alert(e.name + " in " + e.form.name + " has become " +
507
e.options[e.selectedIndex].value);
511
alert("page loading");
513
function onunlfunc() {
514
if(confirm("Care to visit MathReference.com"))
515
new Window("http://www.mathreference.com");
516
else alert("ok, never mind");
518
function formLoad(name) { onlv++; alert("form " + name + " loading"); }
519
function formUnload(name) { alert("form " + name + " unloading"); }
522
setTimeout("joker()", 750);
526
document.writeln("<P>Some extra html in another buffer.");