forked from geoext/geoext2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests.html
2409 lines (2322 loc) · 88.3 KB
/
run-tests.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title> Run the testsuite</title>
<noscript>Javascript is disabled in your browser. This page cannot be displayed correctly without Javascript. Sorry. <br/> If you want to view this page, please change your browser settings so that Javascript is enabled.</noscript>
<!--
Test.AnotherWay version 0.5
Copyright (c) 2005 Artem Khodush, http://straytree.org
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<style type="text/css">
* { padding: 0; margin: 0; }
html { height: 99%; }
body { height: 98%; font: normal normal 10pt sans-serif }
#col1 { float: left; width: 27em; margin: 0 0 0 1em; overflow: visible; }
#col2 { position: relative; height: 98%; margin: 0 0.5em 0 28em; }
#col1_header { margin-top: 0.5em; }
#scroller { height: 400px; overflow: auto;}
#testtable { margin: 0 0 2em 0; width: 97%; }
#run_buttons { margin-bottom: 4em; }
#right_header { padding-top: 0.8em; }
#results_count { float: left; }
.active_tab { float: right; padding: 0 1em 0.2em 1em; background: #0af; border: 1px solid #048; border-bottom: none; cursor: pointer; cursor: hand;
position: relative; top: -0.2em; }
.inactive_tab { float: right; padding: 0 1em 0 1em; background: #9bb; color: #444; border: 1px solid #9bb; border-bottom: none; cursor: pointer; cursor: hand; }
.inactive_mouseover_tab { float: right; padding: 0 1em 0 1em; background: #9bb; color: #062; border: 1px solid #062; border-bottom: none; cursor: pointer; cursor: hand; }
#right_frame { overflow: auto; position: relative; top: -0.2em; clear: right; height: 95%; border: 1px solid #048; }
#debug { display: none; }
#debug p { margin: 2px 0 0 5em; text-indent: -4.8em; }
#error { display: none; color: #c22; }
#results p { margin: 0 0 2px 0; }
/* cursor indicating that detailed results may be expanded/contracted */
#results p.badtest { cursor: text; }
#results p.ok, #results p.fail { cursor: pointer; cursor: hand; }
/* colored squares in the results window at the left of test page names */
#results p.ok .bullet { background: #6d6; }
#results p.fail .bullet { background: #d46; }
#results p.badtest .bullet { background: #ea3; }
#results p.loading .bullet { background: #48f; }
#results p.running .bullet { background: #26e; }
#results p.waiting .bullet { background: #04d; }
/* highlight in the results line */
#results p .warning { background: #ffc; }
/* layout of the detailed results */
.result_detail { padding-left: 3em; }
.result_exception_detail { padding-left: 4em; }
.result_exception_stack_detail { padding-left: 5em; }
.result_micro_detail { padding-left: 6em; }
/* colouring in the detailed results */
.result_detail .fail, .result_exception_detail .fail, .result_micro_detail .fail { background: #ffd8d8; }
/* "start recording" controls*/
#record_div { margin-top: 3em; }
#record_div p { margin-bottom: 0.5em; }
#record_select { width: 88%; }
#record_input { width: 53%; }
</style>
<script type="text/javascript">
<!--
if( typeof( Test )=="undefined" ) {
Test={};
}
Test.AnotherWay={};
Test.AnotherWay._g_test_iframe=null; // frame where to load test pages
Test.AnotherWay._g_test_frame_no_clear=false; // true - leave last page displayed after tests end
Test.AnotherWay._g_test_page_urls=[]; // array of: { url: url, convention: "anotherway" or "jsan" }
Test.AnotherWay._g_test_object_for_jsan=null; // test object for filling by tests that adhere to jsan Test.Simple calling convention
Test.AnotherWay._g_pages_to_run=null; // list of pages to run automatically after loading
Test.AnotherWay._g_run_on_main_load=false; // special handling for run_pages_to_run when it might be called before onload or before list of test pages is known.
Test.AnotherWay._g_run_on_list_load=false;
Test.AnotherWay._g_main_loaded=false;
Test.AnotherWay._run_pages_to_run=function( called_from_outside )
{
if( !Test.AnotherWay._g_main_loaded ) {
Test.AnotherWay._g_run_on_main_load=true;
}else {
var a_pages=Test.AnotherWay._g_pages_to_run;
if( a_pages=="all" ) {
for( var i=0; i<Test.AnotherWay._g_test_page_urls.length; ++i ) {
Test.AnotherWay._run_test_page( "test"+i );
}
}else if( a_pages!=null ) {
for( var run_i=0; run_i<a_pages.length; ++run_i ) {
var run_page=a_pages[run_i];
var found=false;
for( var all_i=0; all_i<Test.AnotherWay._g_test_page_urls.length; ++all_i ) {
if( run_page==Test.AnotherWay._g_test_page_urls[all_i].url ) {
Test.AnotherWay._run_test_page( "test"+all_i, called_from_outside );
found=true;
break;
}
}
if( !found ) {
Test.AnotherWay._show_error( "page specified to run is not found in the page list: "+run_page );
break;
}
}
}
}
}
Test.AnotherWay._add_test_page_url=function( test_url, convention )
{
var table=document.getElementById( "testtable" );
var record_select=document.getElementById( "record_select" );
var index=Test.AnotherWay._g_test_page_urls.length;
// trim spaces.
if( test_url.match( "^(\\s*)(.*\\S)(\\s*)$" ) ) {
test_url=RegExp.$2;
}
Test.AnotherWay._g_test_page_urls[index]={ url: test_url, convention: convention };
var row=table.insertRow( -1 );
var cell;
var cell_child;
cell=row.insertCell( -1 );
cell_child=document.createElement( "input" );
cell_child.type="checkbox";
cell_child.id="checkbox"+index;
cell_child.checked='checked';
cell_child.defaultChecked='checked';
cell.appendChild( cell_child );
cell=row.insertCell( -1 );
cell.setAttribute( "width", "75%" );
cell.appendChild( document.createTextNode( test_url ) );
cell=row.insertCell( -1 );
cell_child=document.createElement( "input" );
cell_child.type="button";
cell_child.id="test"+index;
cell_child.value=" run ";
cell_child.onclick=Test.AnotherWay._run_one_onclick;
cell.appendChild( cell_child );
cell=row.insertCell( -1 );
cell.setAttribute( "width", "8em" );
cell_child=document.createElement( "span" );
cell.appendChild( cell_child );
var option=document.createElement( "option" );
option.appendChild( document.createTextNode( test_url ) );
record_select.appendChild( option );
}
Test.AnotherWay._show_error=function( msg )
{
var error_div=document.getElementById( "error" );
error_div.innerHTML="";
error_div.appendChild( document.createTextNode( msg ) );
error_div.style.display="block";
}
// read urls from the list in the html file inside the list_iframe
// fill on-screen list with urls and "run" buttons, and fill the g_test_page_urls object.
Test.AnotherWay._list_iframe_onload=function()
{
if( window.frames.list_iframe!=null && window.frames.list_iframe.location!="" && window.frames.list_iframe.location!="about:blank" ) {
var list_doc=window.frames.list_iframe.document;
var list=list_doc.getElementById( "testlist" );
if( list!=null ) {
for( var i=0; i<list.childNodes.length; ++i ) {
var item=list.childNodes[i];
if( item.nodeName=="LI" || item.nodeName=="li" ) {
var convention="anotherway";
if( Test.AnotherWay._get_css_class( item )=="jsan" ) {
convention="jsan";
}
Test.AnotherWay._add_test_page_url( item.innerHTML, convention );
}
}
if( Test.AnotherWay._g_run_on_list_load ) {
Test.AnotherWay._g_run_on_list_load=false;
Test.AnotherWay._run_pages_to_run();
}
}else {
Test.AnotherWay._show_error( "no list with id 'testlist' in a list file "+window.frames.list_iframe.location );
}
}
}
Test.AnotherWay._map_checkboxes=function( f )
{
var table=document.getElementById( "testtable" );
var checks=table.getElementsByTagName( "INPUT" );
for( var i=0; i<checks.length; ++i ) {
if( checks[i].type=="checkbox" && checks[i].id.match( /^checkbox(\d+)$/ ) ) {
f( checks[i], RegExp.$1 );
}
}
}
Test.AnotherWay._run_all_onclick=function()
{
Test.AnotherWay._map_checkboxes( function( c, id ) { Test.AnotherWay._run_test_page( "test"+id ); } );
}
Test.AnotherWay._run_selected_onclick=function()
{
Test.AnotherWay._map_checkboxes( function( c, id ) { if( c.checked ) Test.AnotherWay._run_test_page( "test"+id ); } );
}
Test.AnotherWay._unselect_all_onclick=function()
{
Test.AnotherWay._map_checkboxes( function( c, id ) { c.checked=false; } );
}
Test.AnotherWay._run_one_onclick=function()
{
Test.AnotherWay._run_test_page( this.id );
}
// construct an object that will gather results of running one test function
Test.AnotherWay._test_object_t=function( fun_name )
{
this.name=fun_name; // name of the test function
this.n_plan=null; // planned number of assertions
this.n_ok=0; // # of ok assertions
this.n_fail=0; // # of failed assertions
this.exception=""; // if the function throwed an exception, it's its message
this.exception_stack=[]; // strings: function call stack from the exception
this.assertions=[]; // assertion results: array of { ok: 1 or 0, name: string }
this.wait_result_milliseconds=0; // how long to wait before collecting results from the test
this.second_wait_msg=null; // <p> status message (in addition to the page wait_msg)
this.delay_actions=[]; // array of actions to be perfomed after the test function returns
// action : { acton_kind: "call" | "window" | "replay"
// when "call": { call_fn call_delay_milliseconds } call_fn takes nothing
// when "window" : { wnd_url wnd_wnd wnd_fn wnd_timeout_milliseconds wnd_dont_close } wnd_fn takes wnd
// wnen "replay" : { replay_wnd replay_events replay_event_i replay_checkpoints } checkpoint_fn takes this, wnd
// }
this.delay_action_i=null; // index of delay action currently being performed
this.delay_prev_timer_time=0; // for counting time while performing delay_actions
this.delay_current_milliseconds_left=0; // time left before the next action, runs down
this.delay_total_milliseconds_left=0; // for indication: total estimated time for all actions, runs up and down
}
Test.AnotherWay._test_object_t.prototype.ok=function( cond, name )
{
if( cond ) {
++this.n_ok;
cond=1;
}else {
++this.n_fail;
cond=0;
}
this.assertions.push( { ok: cond, name: name } );
}
Test.AnotherWay._test_object_t.prototype.fail=function( name )
{
this.ok( false, name );
}
Test.AnotherWay._test_object_t.prototype.plan=function( n )
{
this.n_plan=n;
}
Test.AnotherWay._test_object_t.prototype.wait_result=function( seconds )
{
this.wait_result_milliseconds=1000*seconds;
}
Test.AnotherWay._eq_fail_msg=function( path, what, expected, got )
{
return "eq: "+path+" "+what+" differ: got "+got+", but expected "+expected;
}
Test.AnotherWay._array_eq=function( expected, got, path, msg )
{
if( expected.length!=got.length ) {
msg.msg=Test.AnotherWay._eq_fail_msg( path, "array length", expected.length, got.length );
return false;
}
for( var i=0; i<expected.length; ++i ) {
if( !Test.AnotherWay._thing_eq( expected[i], got[i], path+"["+i+"]", msg ) ) {
return false;
}
}
return true;
}
Test.AnotherWay._object_eq=function( expected, got, path, msg )
{
var v;
for( v in expected ) {
if( ! (v in got) ) {
msg.msg=Test.AnotherWay._eq_fail_msg( path+"."+v, "properties", expected[v], "undefined" );
return false;
}
if( !Test.AnotherWay._thing_eq( expected[v], got[v], path+"."+v, msg ) ) {
return false;
}
}
for( v in got ) {
if( ! (v in expected) ) {
msg.msg=Test.AnotherWay._eq_fail_msg( path+"."+v, "properties", "undefined", got[v] );
return false;
}
}
return true;
}
Test.AnotherWay._constructor_name=function( x )
{
if( x==null ) {
return "";
}
var s="unknown";
try {
s=typeof( x.constructor );
if( s!="unknown" ) {
s=x.constructor.toString();
}
}catch( e ) {
s="unknown";
}
if( s=="unknown" ) {
// hackish attempt to guess a type
var is_array=true;
var index=0;
for( i in x ) {
if( i!=index ) {
is_array=false;
}
++index;
}
return is_array ? "Array" : "Object"; // for empty arrays/objects, this will be wrong half the time
}else if( s.match( /^\s*function\s+(\w+)\s*\(/ ) ) {
return RegExp.$1;
}else {
var c = '';
switch(typeof x) {
case 'string':
c = 'String';
break;
case 'object':
c = 'Object';
break;
default:
c = '';
}
return c;
}
}
Test.AnotherWay._is_array=function( x )
{
return Test.AnotherWay._constructor_name( x )=="Array";
}
Test.AnotherWay._is_value_type=function( x )
{
cn=Test.AnotherWay._constructor_name( x );
return cn=="Number" || cn=="String" || cn=="Boolean" || cn=="Date";
}
Test.AnotherWay._thing_eq=function( expected, got, path, msg )
{
if( expected==null && got==null ) {
return true;
}else if( (expected==null && got!=null) || (expected!=null && got==null) ) {
msg.msg=Test.AnotherWay._eq_fail_msg( path, "values", expected, got );
return false;
}else {
var expected_cn=Test.AnotherWay._constructor_name( expected );
var got_cn=Test.AnotherWay._constructor_name( got );
if( expected_cn!=got_cn ) {
msg.msg=Test.AnotherWay._eq_fail_msg( path, "types", expected_cn, got_cn );
return false;
}else {
if( Test.AnotherWay._is_array( expected ) ) {
return Test.AnotherWay._array_eq( expected, got, path, msg );
}else if( Test.AnotherWay._is_value_type( expected ) ) {
if( expected!=got ) {
msg.msg=Test.AnotherWay._eq_fail_msg( path, "values", expected, got );
return false;
}else {
return true;
}
}else { // just a plain object
return Test.AnotherWay._object_eq( expected, got, path, msg );
}
}
}
}
Test.AnotherWay._test_object_t.prototype.eq=function( got, expected, name )
{
var msg={};
if( Test.AnotherWay._thing_eq( expected, got, "", msg ) ) {
this.ok( 1, name );
}else {
this.fail( name+". "+msg.msg );
}
}
Test.AnotherWay._test_object_t.prototype.like=function( got, expected, name )
{
if( got.match( expected )!=null ) {
this.ok( 1, name );
}else {
this.fail( name+": got "+got+", but expected it to match: "+expected );
}
}
Test.AnotherWay._g_html_eq_span=null;
Test.AnotherWay._html_eq_string_to_node=function( string_or_node, what, msg )
{
if( string_or_node.nodeType!=null ) {
string_or_node=Test.AnotherWay._html_eq_node_to_string( string_or_node ); // double trip - to make properties assigned in scripts available as html node attributes
}
if( Test.AnotherWay._g_html_eq_span==null ) {
Test.AnotherWay._g_html_eq_span=document.createElement( "span" );
}
Test.AnotherWay._g_html_eq_span.innerHTML=string_or_node;
if( Test.AnotherWay._g_html_eq_span.childNodes.length!=1 ) {
msg.msg="bad "+what+" html string given (should contain exactly one outermost element): "+string_or_node;
}
return Test.AnotherWay._g_html_eq_span.childNodes[0].cloneNode( true );
}
Test.AnotherWay._html_eq_node_to_string=function( node ) {
if( Test.AnotherWay._g_html_eq_span==null ) {
Test.AnotherWay._g_html_eq_span=document.createElement( "span" );
}
Test.AnotherWay._g_html_eq_span.innerHTML="";
if( node.outerHTML!=null ) {
Test.AnotherWay._g_html_eq_span.innerHTML=node.outerHTML;
}else {
var clone = node.cloneNode(true);
var node = Test.AnotherWay._g_html_eq_span;
if(node.ownerDocument && node.ownerDocument.importNode) {
if(node.ownerDocument != clone.ownerDocument) {
clone = node.ownerDocument.importNode(clone, true);
}
}
node.appendChild(clone);
}
return Test.AnotherWay._g_html_eq_span.innerHTML;
}
Test.AnotherWay._html_eq_path_msg=function( path )
{
var msg="";
for( var i=0; i<path.length; ++i ) {
msg+=" [node "+path[i].node;
if( path[i].id!=null && path[i].id!="" ) {
msg+=" id "+path[i].id;
}else if( path[i].index!=null ) {
msg+=" at index "+path[i].index;
}
msg+="] "
}
return msg;
}
Test.AnotherWay._html_eq_fail_msg=function( path, what, expected, got )
{
return Test.AnotherWay._html_eq_path_msg( path )+": "+what+" differ: got "+got+", but expected "+expected;
}
Test.AnotherWay._html_eq_remove_blank=function( text )
{
if( text==null ) {
return "";
}else if( text.match( "^(\\s*)(.*\\S)(\\s*)$" ) ) {
return RegExp.$2;
}else if( text.match( "\s*" ) ) {
return "";
}
return text;
}
Test.AnotherWay._html_eq_remove_blank_nodes=function( node )
{
var to_remove=[];
for( var child=node.firstChild; child!=null; child=child.nextSibling ) {
if( child.nodeType==3 ) {
var value=Test.AnotherWay._html_eq_remove_blank( child.nodeValue );
if( value=="" ) {
to_remove.push( child );
}else {
child.nodeValue=value;
}
}
}
for( var i=0; i<to_remove.length; ++i ) {
node.removeChild( to_remove[i] );
}
}
Test.AnotherWay._html_node_type_text=function( node_type )
{
if( node_type==1 ) {
return "1 (html element)";
}else if( node_type==3 ) {
return "3 (text)";
}else {
return node_type;
}
}
Test.AnotherWay._html_eq_node=function( expected, got, path, msg, expected_loc_base, got_loc_base )
{
if( expected.nodeType!=got.nodeType ) {
msg.msg=Test.AnotherWay._html_eq_fail_msg( path, "node types", Test.AnotherWay._html_node_type_text( expected.nodeType ), Test.AnotherWay._html_node_type_text( got.nodeType ) );
return false;
}else if( expected.nodeType==3 ) {
if( expected.nodeValue!=got.nodeValue ) {
msg.msg=Test.AnotherWay._html_eq_fail_msg( path, "text", expected.nodeValue, got.nodeValue );
return false;
}
}else if( expected.nodeType==1 ) {
if( expected.nodeName!=got.nodeName ) {
msg.msg=Test.AnotherWay._html_eq_fail_msg( path, "node names", expected.nodeName, got.nodeName );
return false;
}
// compare attributes
var expected_attrs={};
var got_attrs={};
var i;
var a;
for( i=0; i<expected.attributes.length; ++i ) {
a=expected.attributes[i];
if( a.specified ) {
expected_attrs[a.name]=1;
}
}
for( i=0; i<got.attributes.length; ++i ) {
a=got.attributes[i];
if( a.specified ) {
got_attrs[a.name]=1;
}
}
for( a in expected_attrs ) {
if( ! (a in got_attrs) ) {
msg.msg=Test.AnotherWay._html_eq_path_msg( path )+": attribute sets differ: expected attribute "+a+" is missing";
return false;
}
}
for( a in got_attrs ) {
if( ! (a in expected_attrs) ) {
msg.msg=Test.AnotherWay._html_eq_path_msg( path )+": attribute sets differ: got extra attribute "+a;
return false;
}
}
for( a in expected_attrs ) {
var expected_value=expected.getAttribute( a );
var got_value=got.getAttribute( a );
if( typeof( expected_value )=="string" && typeof( got_value )=="string" ) {
expected_value=Test.AnotherWay._html_eq_remove_blank( expected_value );
got_value=Test.AnotherWay._html_eq_remove_blank( got_value );
var ok=expected_value==got_value;
if( !ok && (a=="href" || a=="HREF" ) ) { // try relative hrefs
var expected_relative_value=expected_value;
if( expected_loc_base!=null && expected_value.substring( 0, expected_loc_base.length )==expected_loc_base ) {
expected_relative_value=expected_value.substring( expected_loc_base.length );
}
var got_relative_value=got_value;
if( got_loc_base!=null && got_value.substring( 0, got_loc_base.length )==got_loc_base ) {
got_relative_value=got_value.substring( got_loc_base.length );
}
ok=expected_relative_value==got_relative_value;
}
if( !ok ) {
msg.msg=Test.AnotherWay._html_eq_fail_msg( path, "attribute "+a+" values", expected_value, got_value );
return false;
}
}else if( typeof( expected_value )=="function" && typeof( got_value )=="function" ) {
expected_value=expected_value.toString();
got_value=got_value.toString();
if( expected_value!=got_value ) {
msg.msg=Test.AnotherWay._html_eq_fail_msg( path, "attribute "+a+" values", expected_value, got_value );
return false;
}
}else {
var value_msg={};
if( !Test.AnotherWay._thing_eq( expected_value, got_value, "", value_msg ) ) {
msg.msg=Test.AnotherWay._html_eq_path_msg( path )+": attribute "+a+" values differ: "+value_msg.msg;
return false;
}
}
}
// compare child nodes
Test.AnotherWay._html_eq_remove_blank_nodes( expected );
Test.AnotherWay._html_eq_remove_blank_nodes( got );
var expected_length=expected.childNodes.length;
var got_length=got.childNodes.length;
if( expected_length<got_length ) {
msg.msg=Test.AnotherWay._html_eq_path_msg( path )+": got "+(got_length-expected_length)+" extra child nodes";
return false;
}else if( expected_length>got_length ) {
msg.msg=Test.AnotherWay._html_eq_path_msg( path )+": expected "+(expected_length-got_length)+" more child nodes";
return false;
}else {
for( i=0; i<expected_length; ++i ) {
var expected_node=expected.childNodes[i];
path.push( { node: expected_node.nodeName, id: expected_node.id, index: i } );
var eq=Test.AnotherWay._html_eq_node( expected_node, got.childNodes[i], path, msg, expected_loc_base, got_loc_base );
path.pop();
if( !eq ) {
return false;
}
}
}
}
return true;
}
Test.AnotherWay._html_eq_get_loc_base=function( node )
{
var loc_base=document.location;
if( node.ownerDocument!=null ) {
loc_base=node.ownerDocument.location;
}
if( loc_base!=null ) {
loc_base=loc_base.href;
var slash_pos=loc_base.lastIndexOf( "/" );
if( slash_pos!=-1 ) {
loc_base=loc_base.substring( 0, slash_pos+1 );
}
}
return loc_base;
}
Test.AnotherWay._test_object_t.prototype.html_eq=function( got, expected, name )
{
var msg={};
var expected_node=Test.AnotherWay._html_eq_string_to_node( expected, "expected", msg );
if( msg.msg!=null ) {
this.fail( name+" html_eq: "+msg.msg );
}else {
var got_node=Test.AnotherWay._html_eq_string_to_node( got, "got", msg );
if( msg.msg!=null ) {
this.fail( name+" html_eq: "+msg.msg );
}else {
var expected_loc_base=Test.AnotherWay._html_eq_get_loc_base( expected );
var got_loc_base=Test.AnotherWay._html_eq_get_loc_base( got );
if( Test.AnotherWay._html_eq_node( expected_node, got_node, [], msg, expected_loc_base, got_loc_base ) ) {
this.ok( 1, name );
}else {
var msg=name+" html_eq "+msg.msg;
var expected_str=Test.AnotherWay._html_eq_node_to_string( expected_node );
var got_str=Test.AnotherWay._html_eq_node_to_string( got_node );
msg+=".\n got html: "+got_str;
msg+=".\n expected html: "+expected_str;
this.fail( msg );
}
}
}
}
Test.AnotherWay._debug_pane_print=function( msg )
{
var d=new Date();
var p=document.createElement( "p" );
p.appendChild( document.createTextNode( d.toLocaleTimeString()+" "+msg ) );
var debug_pane=document.getElementById( "debug" );
debug_pane.appendChild( p );
var debug_tab=document.getElementById( "debug_tab" );
var results_tab=document.getElementById( "results_tab" );
debug_tab.style.visibility="visible";
results_tab.style.visibility="visible";
}
Test.AnotherWay._test_object_t.prototype.debug_print=function( msg )
{
Test.AnotherWay._debug_pane_print( this.name+": "+msg );
}
Test.AnotherWay._test_object_t.prototype.delay_call=function()
{
var timeout_ms=200;
for( var i=0; i<arguments.length; ++i ) {
if( typeof( arguments[i] )!="function" ) {
timeout_ms=1000*arguments[i];
}else {
var action={ action_kind: "call", call_delay_milliseconds: timeout_ms, call_fn: arguments[i] };
this.delay_total_milliseconds_left+=Test.AnotherWay._action_estimate_milliseconds( action );
this.delay_actions.push( action );
}
}
}
Test.AnotherWay._test_object_t.prototype.open_window=function( url, fn, timeout_seconds )
{
if( timeout_seconds==null ) {
timeout_seconds=4;
}
var no_close=document.getElementById( "dont_close_test_windows" );
var action={ action_kind: "window", wnd_url: url.toString(), wnd_wnd: null, wnd_fn: fn, wnd_timeout_milliseconds: timeout_seconds*1000, wnd_no_close: no_close.checked };
this.delay_total_milliseconds_left+=Test.AnotherWay._action_estimate_milliseconds( action );
this.delay_actions.push( action );
}
Test.AnotherWay._test_object_t.prototype.replay_events=function( wnd, events )
{
if( Test.AnotherWay._g_no_record_msg!=null ) {
this.fail( "replay_events: "+Test.AnotherWay._g_no_record_msg );
}else {
var action={ action_kind: "replay", replay_wnd: wnd, replay_events: events.events, replay_event_i: null, replay_checkpoints: events.checkpoints };
this.delay_total_milliseconds_left+=Test.AnotherWay._action_estimate_milliseconds( action );
this.delay_actions.push( action );
}
}
Test.AnotherWay._action_estimate_milliseconds=function( action )
{
var ms=0;
if( action.action_kind=="call" ) {
ms=action.call_delay_milliseconds;
}else if( action.action_kind=="window" ) {
ms=0;
}else if( action.action_kind=="replay" ) {
ms=0;
for( var i=0; i<action.replay_events.length; ++i ) {
ms+=action.replay_events[i]["time"]-0;
}
}
return ms;
}
Test.AnotherWay._g_timeout_granularity=200;
Test.AnotherWay._g_tests_queue=[]; // vector of { url: string, test_objects : array of test_object_t, test_object_i: int, wait_msg: <p> object, loading_timeout_milliseconds: int, timeout_id: id }
// load one html page, schedule further processing
Test.AnotherWay._run_test_page=function( id, called_from_outside )
{
if( id.match( /^test(\d+)/ ) ) {
id=RegExp.$1;
Test.AnotherWay._g_tests_queue.push( {
url: Test.AnotherWay._g_test_page_urls[id].url,
convention: Test.AnotherWay._g_test_page_urls[id].convention,
test_objects: []
} );
if( Test.AnotherWay._g_tests_queue.length==1 ) {
if( !called_from_outside ) {
// Crap. Be careful stepping around.
// For Mozilla and Opera, when this file is included into the frameset page that is in another directory (and _g_outside_path_correction!=null)
// but the test pages are started from within it (by "run" buttons), then:
// depending on whether the page is the first one loaded into the test frame or not,
// the base url for relative test pages differs.
// Crap, like I said.
Test.AnotherWay._g_tests_queue[0].suppress_outside_path_correction=true;
}
Test.AnotherWay._start_loading_page();
}
}
}
Test.AnotherWay._load_next_page=function()
{
Test.AnotherWay._g_tests_queue.splice( 0, 1 );
if( Test.AnotherWay._g_tests_queue.length>0 ) {
Test.AnotherWay._start_loading_page();
}else {
if( !Test.AnotherWay._g_test_frame_no_clear ) {
Test.AnotherWay._g_test_iframe.location.replace( "about:blank" );
}
}
}
Test.AnotherWay._g_opera_path_correction=null; // ugly wart to support opera
Test.AnotherWay._g_outside_path_correction=null; // ugly wart to accomodate Opera and Mozilla, where relative url relates to the directory where the page that calls this function is located
Test.AnotherWay._set_iframe_location=function( iframe, loc, outside_path_correction )
{
// allow to load only locations with the same origin
var proto_end=loc.indexOf( "://" );
if( proto_end!=-1 ) { // otherwise, it's safe to assume (for Opera, Mozilla and IE ) that loc will be treated as relative
var main_loc=window.location.href;
var host_end=loc.substring( proto_end+3 ).indexOf( "/" );
var ok=false;
if( host_end!=-1 ) {
var loc_origin=loc.substring( 0, proto_end+3+host_end+1 );
if( main_loc.length>=loc_origin.length && main_loc.substring( 0, loc_origin.length )==loc_origin ) {
ok=true;
}
}
if( !ok ) {
return { msg: "test pages may have only urls with the same origin as "+main_loc };
}
}
// opera cannot handle urls relative to file:// without assistance
if( window.opera!=null && window.location.protocol=="file:" && loc.indexOf( ":" )==-1 ) {
var base=window.location.href;
var q_pos=base.indexOf( "?" );
if( q_pos!=-1 ) {
base=base.substring( 0, q_pos );
}
var slash_pos=base.lastIndexOf( "/" );
if( slash_pos!=-1 ) {
base=base.substring( 0, slash_pos+1 );
Test.AnotherWay._g_opera_path_correction=base;
loc=base+loc;
}
}
// if this function is called from another page, and if that page is in another directory, correction is needed
if( outside_path_correction!=null ) {
var pos=loc.indexOf( outside_path_correction );
if( pos==0 ) {
loc=loc.substring( outside_path_correction.length+1 );
}
}
if( iframe.location!=null ) {
iframe.location.replace( loc );
}else {
iframe.src=loc;
}
return {};
}
Test.AnotherWay._start_loading_page=function()
{
var test_page=Test.AnotherWay._g_tests_queue[0];
test_page.loading_timeout_milliseconds=12000;
test_page.timeout_id=setTimeout( Test.AnotherWay._loading_timeout, Test.AnotherWay._g_timeout_granularity );
test_page.wait_msg=Test.AnotherWay._print_counter_result( test_page.url, "loading...", test_page.loading_timeout_milliseconds, "loading" );
if( test_page.convention=="jsan" ) {
// the tests in that page will run when it's loading, so the test object must be ready
Test.AnotherWay._g_test_object_for_jsan=new Test.AnotherWay._test_object_t( test_page.url );
}
var outside_path_correction=null;
if( Test.AnotherWay._g_outside_path_correction!=null && !test_page.suppress_outside_path_correction ) {
outside_path_correction=Test.AnotherWay._g_outside_path_correction;
}
var result=Test.AnotherWay._set_iframe_location( Test.AnotherWay._g_test_iframe, test_page.url, outside_path_correction );
if( result.msg!=null ) {
Test.AnotherWay._unprint_result( test_page.wait_msg );
Test.AnotherWay._print_result( test_page.url, result.msg, "badtest", null );
Test.AnotherWay._load_next_page();
}
}
Test.AnotherWay._loading_timeout=function()
{
var test_page=Test.AnotherWay._g_tests_queue[0];
test_page.loading_timeout_milliseconds-=Test.AnotherWay._g_timeout_granularity;
if( test_page.loading_timeout_milliseconds>0 ) {
Test.AnotherWay._update_msg_counter( test_page.wait_msg, (test_page.loading_timeout_milliseconds/1000).toFixed() );
test_page.timeout_id=setTimeout( Test.AnotherWay._loading_timeout, Test.AnotherWay._g_timeout_granularity );
}else {
Test.AnotherWay._unprint_result( test_page.wait_msg );
Test.AnotherWay._print_result( test_page.url, "Unable to load test page. Timeout expired", "badtest", null );
Test.AnotherWay._load_next_page();
}
}
Test.AnotherWay._strip_query_and_hash=function( s )
{
var i=s.lastIndexOf( "#" );
if( i!=-1 ) {
s=s.substring( 0, i );
}
i=s.lastIndexOf( "?" );
if( i!=-1 ) {
s=s.substring( 0, i );
}
return s;
}
Test.AnotherWay._is_url_loaded=function( url, wnd )
{
var loaded=false;
if( wnd!=null && wnd.location!=null ) {
// after some popup blocker interference, location may behave strange..
var location_s="";
location_s+=wnd.location;
if( location_s!="" ) {
var pathname=wnd.location.pathname;
var expected_url=url;
var i=expected_url.lastIndexOf( "#" );
if( i!=-1 ) {
expected_url=expected_url.substring( 0, i );
}
i=expected_url.lastIndexOf( "?" );
if( i!=-1 ) {
expected_url=expected_url.substring( 0, i );
}
i=expected_url.lastIndexOf( "/" );
if( i!=-1 && i!=expected_url.length-1 ) {
expected_url=expected_url.substring( i+1 );
}
i=pathname.indexOf( expected_url )
if( wnd.location.href==url || (i!=-1 && i==pathname.length-expected_url.length) ) {
if( /*window.opera==null*/wnd.document.readyState==null || wnd.document.readyState=="complete" ) { // for opera (and IE?), getElementById does not work until..
loaded=true;
}
}
}
}
return loaded;
}
// find and run all test functions in the g_cur_page html page.
Test.AnotherWay._test_page_onload=function()
{
if( Test.AnotherWay._g_tests_queue.length==0 ) {
return;
}
var test_page=Test.AnotherWay._g_tests_queue[0];
if( !Test.AnotherWay._is_url_loaded( test_page.url, Test.AnotherWay._g_test_iframe ) ) {
return;
}
clearTimeout( test_page.timeout_id );
Test.AnotherWay._unprint_result( test_page.wait_msg );
if( test_page.convention=="anotherway" ) {
// get test function names (those beginning with "test")
if( typeof( Test.AnotherWay._g_test_iframe.document.scripts )!='undefined' ) { // IE
for( var i=0; i<Test.AnotherWay._g_test_iframe.document.scripts.length; ++i ) {
var script_text=Test.AnotherWay._g_test_iframe.document.scripts[i].text;
var fun_sig="function test";
var fun_start=script_text.indexOf( fun_sig );
while( fun_start!=-1 ) {
script_text=script_text.substring( fun_start, script_text.length );
var fun_end=script_text.indexOf( '(' );
var fun_name=script_text.substring( "function ".length, fun_end );
var whitespace = fun_name.indexOf( ' ' );
if (whitespace >= 0)
fun_name = fun_name.substring( 0, whitespace );
test_page.test_objects.push( new Test.AnotherWay._test_object_t( fun_name ) );
script_text=script_text.substring( fun_end, script_text.length );
fun_start=script_text.indexOf( fun_sig );
}
}
}else { // otherwise (not IE) it ought to work like this
for( var i in Test.AnotherWay._g_test_iframe) {
// Hack to prevent failure in FF3.0b1
if (i == "innerWidth" || i == "innerHeight") { continue; }
if( typeof( Test.AnotherWay._g_test_iframe[i] )=='function' ) {
if( i.substring( 0, 4 )=="test" ) {
test_page.test_objects.push( new Test.AnotherWay._test_object_t( i ) );
}
}
}
}
}else if( test_page.convention=="jsan" ) {
// the test object is already filled with results
test_page.test_objects.push( Test.AnotherWay._g_test_object_for_jsan );
}
if( test_page.test_objects.length==0 ) {
Test.AnotherWay._print_result( test_page.url, "No test functions defined in the page", "badtest", null );
Test.AnotherWay._load_next_page();
return;
}
test_page.wait_msg=Test.AnotherWay._print_result( test_page.url, "running tests..<span class=\"counter\">"+test_page.test_objects.length+"</span>", "running", null );
test_page.test_object_i=0;
Test.AnotherWay._run_more_tests();
}
Test.AnotherWay._handle_exception=function( o, e, title )
{
var s=title+": "+typeof( e )+": ";
if( e.message!=null ) {
s+=e.message;
}else if( e.description!=null ) {
s+=e.description;
}else {
s+=e.toString();
}
// if( e.location!=null ) { // XXX figure out how to display exception location if it's present (like in mozilla)
// s+=" location: "+e.location.toString();
// }
o.exception=s;
s=[];
if( e.stack ) {
var lines=e.stack.split( "\n" );
for( var i=0; i<lines.length; ++i ) {
// format of the line: func_name(args)@file_name:line_no
if( lines[i].match( /(\w*)\(([^\)]*)\)@(.*):([^:]*)$/ ) ) {
var func_name=RegExp.$1;
if( func_name.length==0 ) {
func_name="<anonymous>";
}
s.push( "in "+func_name+"( "+RegExp.$2+") at "+RegExp.$3+" line "+RegExp.$4+"\n" );
}
}
}
o.exception_stack=s;
}
Test.AnotherWay._run_more_tests=function()
{
var test_page=Test.AnotherWay._g_tests_queue[0];
while( test_page.test_object_i<test_page.test_objects.length ) {
Test.AnotherWay._update_msg_counter( test_page.wait_msg, (1+test_page.test_object_i)+"/"+test_page.test_objects.length );
var o=test_page.test_objects[test_page.test_object_i];
if( test_page.convention=="anotherway" ) {
try {
Test.AnotherWay._g_test_iframe[o.name]( o );
}catch( e ) {
Test.AnotherWay._handle_exception( o, e, "" );
}
} // for "jsan" convention, test has run already
if( o.delay_actions.length>0 || o.wait_result_milliseconds>0 ) {
o.delay_total_milliseconds_left+=o.wait_result_milliseconds;
Test.AnotherWay._delay_actions_timeout();
return;
}
++test_page.test_object_i;
}
Test.AnotherWay._unprint_result( test_page.wait_msg );
Test.AnotherWay._print_result( test_page.url, null, null, test_page.test_objects );
Test.AnotherWay._load_next_page();
}