forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
file_bug416317.xhtml
1442 lines (1219 loc) · 65.2 KB
/
file_bug416317.xhtml
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg"
xml:lang="en" lang="en" dir="ltr" id="html" class="unitTest" title=":root selector">
<head>
<title>selectorTest</title>
<!-- (c) Disruptive Innovations 2008 -->
<style type="text/css">
/* TEST 0 : BASIC TESTS */
/* element type selector */
body { background-color: red; margin: 10px; padding: 10px; color: red; font-family: sans-serif }
div { background-color: red; color: red; }
div.header { background-color: #e0e0e0; color: black; padding: 10px; margin-bottom: 10px;}
/* class selector */
.unitTest { width: 10px; background-color: red; color: red; margin: 0px; margin-right: 2px; float: left; }
.test { margin-bottom: 2px; background-color: green; color: green; }
/* group of selectors */
.unitTest, .test { height: 10px; }
.UI > * { float: left }
.UI { clear: both; height: auto; padding-top: 6px;}
.tilda { clear: both; height: auto; padding-top: 6px;}
.plus { clear: both; height: auto; padding-top: 6px;}
h1, p { width: 500px; color: #000; }
a { color: #000; }
#results { background: #FFF; width: 600px; padding: 10px 40px; color: #000; font-size: 11px; line-height: 1.3em; }
#root, #root2, #root3 { display: none; }
/* init */
.blox16 { background-color: red; }
.blox17 { background-color: red; }
.lastChild > p { background-color: red; }
.firstOfType > p { background-color: red }
.lastOfType > p { background-color: red }
.empty > .isEmpty { color: red; }
html { background-color: red; }
</style>
<span type="text/test" id="test"><![CDATA[
/* :target selector */
.target :target { background-color: lime; }
/* test 1 : childhood selector */
html > body { background-color: green; }
.test > .blox1 { background-color: lime; }
/* test 2 : attribute existence selector */
/* attribute with a value */
.blox2[align] { background-color: lime; }
/* attribute with empty value */
.blox3[align] { background-color: lime; }
/* attribute with almost similar name */
.blox4, .blox5 { background-color: lime }
.blox4[align], .blox5[align] { background-color: red; }
/* test3 : attribute value selector */
.blox6[align="center"] { background-color: lime; }
.blox6[align="c"] { background-color: red; }
.blox6[align="centera"] { background-color: red; }
.blox6[foo="\e9"] { background-color: lime; }
.blox6[\_foo="\e9"] { background-color: lime; }
/* test 4 : [~=] */
.blox7[class~="foo"] { background-color: lime; }
.blox8, .blox9, .blox10 { background-color: lime; }
.blox8[class~=""] { background-color: red; }
.blox9[foo~=""] { background-color: red; }
.blox10[foo~="foo"] { background-color: red; }
/* test5 [^=] */
.attrStart > .t3 { background-color: lime; }
.attrStart > .t1[class^="unit"] { background-color: lime; }
.attrStart > .t2 { background-color: lime; }
.attrStart > .t2[class^="nit"] { background-color: red; }
.attrStart > .t3[align^=""] { background-color: red; }
.attrStart > .t4[foo^="\e9"] { background-color: lime; }
/* test6 [$=] */
.attrEnd > .t3 { background-color: lime; }
.attrEnd > .t1[class$="t1"] { background-color: lime; }
.attrEnd > .t2 { background-color: lime; }
.attrEnd > .t2[class$="unit"] { background-color: red; }
.attrEnd > .t3[align$=""] { background-color: red; }
.attrEnd > .t4[foo$="\e9"] { background-color: lime; }
/* test7 [*=] */
.attrMiddle > .t3 { background-color: lime; }
.attrMiddle > .t1[class*="t t"] { background-color: lime; }
.attrMiddle > .t2 { background-color: lime; }
.attrMiddle > .t2[class*="a"] { background-color: red; }
.attrMiddle > .t3[align*=""] { background-color: red; }
.attrMiddle > .t4[foo*="\e9"] { background-color: lime; }
/* :first-child tests */
.firstChild .unitTest:first-child { background-color: lime; }
.blox12:first-child { background-color: red; }
.blox13:first-child { background-color: red; }
.blox12, .blox13 { background-color: lime }
/* :root tests */
:root { background-color: green; }
/* :nth-child(n) tests */
.nthchild1 > :nth-last-child(odd) { background-color: lime; }
.nthchild1 > :nth-child(odd) { background-color: lime; }
.nthchild2 > :nth-last-child(even) { background-color: lime; }
.nthchild2 > :nth-child(even) { background-color: lime; }
.nthchild3 > :nth-child(3n+2) { background-color: lime; }
.nthchild3 > :nth-last-child(3n+1) { background-color: lime; }
.nthchild3 > :nth-last-child(3n+3) { background-color: lime; }
.nthoftype1 > div:nth-of-type(odd) { background-color: lime; }
.nthoftype1 > div:nth-last-of-type(odd) { background-color: lime; }
.nthoftype1 > p { background-color: green; }
.nthoftype2 > div:nth-of-type(even) { background-color: lime; }
.nthoftype2 > div:nth-last-of-type(even) { background-color: lime; }
.nthoftype2 > p { background-color: green; }
.nthoftype3 > div:nth-of-type(3n+1) { background-color: lime; }
.nthoftype3 > div:nth-last-of-type(3n+1) { background-color: lime; }
.nthoftype3 > div:nth-last-of-type(3n+2) { background-color: lime; }
.nthoftype3 > p { background-color: green; }
/* :not() tests */
.blox14:not(span) { background-color: lime; }
.blox15:not([foo="blox14"]) { background-color: lime; }
.blox16:not(.blox15) { background-color: lime; }
/* :only-of-type tests */
.blox17:only-of-type { background-color: lime; }
.blox18:only-of-type { background-color: red; }
.blox18:not(:only-of-type) { background-color: lime; }
/* :last-child tests */
.lastChild > :last-child { background-color: lime }
.lastChild > :not(:last-child) { background-color: lime }
/* :first-of-type tests */
.firstOfType > *:first-of-type { background-color: lime; }
*.firstOfType > :not(:first-of-type) { background-color: lime; }
/* :last-of-type tests */
.lastOfType > *:last-of-type { background-color: lime; }
*.lastOfType > :not(:last-of-type) { background-color: lime; }
/* :only-child tests */
.onlyChild > *:not(:only-child) { background-color: lime; }
.onlyChild > .unitTest > *:only-child { background-color: lime; }
/* :only-of-type tests */
.onlyOfType *:only-of-type { background-color: lime; }
.onlyOfType *:not(:only-of-type) { background-color: lime; }
/* :empty tests */
.empty > *.isEmpty:empty { background-color: lime; color: lime; }
.empty > .isNotEmpty { background-color: blue; color: blue; }
.empty > .isNotEmpty:empty { background-color: red; color: red; }
.empty > .isNotEmpty:not(:empty) { background-color: lime; color: lime; }
/* :lang() tests */
.lang :lang(en) { background-color: lime; }
.lang :lang(fr) { background-color: lime; }
.lang .t1 { background-color: blue; }
.lang .t1:lang(es) { background-color: lime; }
.lang :lang(es-AR) { background-color: red; }
/* [|=] tests */
.attrLang .t1 { background-color: lime; }
.attrLang .t1[lang|="en"] { background-color: red; }
.attrLang [lang|="fr"] { background-color: lime; }
.attrLang .t2[lang|="en"] { background-color: lime; }
.attrLang .t3 { background-color: blue; }
.attrLang .t3[lang|="es"] { background-color: lime; }
.attrLang [lang|="es-AR"] { background-color: red; }
/* UI tests */
.UI .t1:enabled > .unitTest { background-color: lime; }
.UI .t2:disabled > .unitTest { background-color: lime; }
.UI .t3:checked + div { background-color: lime; }
.UI .t4:not(:checked) + div { background-color: lime; }
/* ~ combinator tests */
.tilda .t1 { background-color: white; }
.tilda .t1 ~ .unitTest { background-color: lime; }
.tilda .t1:hover ~ .unitTest { background-color: red; }
/* ~ combinator tests */
.plus .t1, .plus .t2 { background-color: white; }
.plus .t1 + .unitTest + .unitTest { background-color: lime; }
.plus .t1:hover + .unitTest + .unitTest { background-color: red; }
]]></span>
<span type="text/test" id="error">
.blox16:not(.blox15[foo="blox14"]) { background-color: red; }
/* Tests from http://www.w3.org/Style/CSS/Test/CSS3/Selectors/20060307/html/index.html */
div:not(:not(div)) { background-color : red }
div, { background: red; }
.5cm { background: red; }
foo & address, p { background: red; }
[*=test] { background: red; }
[*|*=test] { background: red; }
div:subject { background: red; }
:canvas { background: red; }
:viewport { background: red; }
:window { background: red; }
:menu { background: red; }
:table { background: red; }
:select { background: red; }
::canvas { background: red; }
::viewport { background: red; }
::window { background: red; }
::menu { background: red; }
::table { background: red; }
::select { background: red; }
..test { background: red; color: yellow; }
.foo..quux { background: red; color: yellow; }
.bar. { background: red; color: yellow; }
</span>
<script><![CDATA[
window.onload = function(){
if ( window.location.hash.indexOf("target") == -1 )
window.location.hash = "#target";
var root = document.getElementById("root");
var root2 = document.getElementById("root2");
var root3 = document.getElementById("root3");
var results = [];
var tests = 0, passed = 0;
var cache = {};
var css = document.getElementById("test").firstChild.nodeValue.split("\n");
for ( var i = 0; i < css.length; i++ ) {
css[i] = css[i].replace(/\/\*.*?\*\//g, "")
.replace(/^\s*|\s*$/g, "").split(/\s*{/);
}
var ecss = document.getElementById("error").firstChild.nodeValue.split("\n");
for ( var i = 0; i < ecss.length; i++ ) {
ecss[i] = ecss[i].replace(/\/\*.*?\*\//g, "")
.replace(/^\s*|\s*$/g, "").split(/\s*{/);
}
var namespaceCheck = {};
var badNamespace = [
{},
null,
undefined,
];
interfaceCheck(root, "Element");
runTest( css, "Element", root, true );
check( "Inside Element", root, true, false );
cacheCheck( "Element", root );
check( "Outside Element", root2, passed === 0 ? "autofail" : false, false );
runTest( ecss, "SyntaxError: Element", root, false );
jqTests("Element", root3, "querySelectorAll");
var root4 = root2.cloneNode(true);
interfaceCheck(root4, "Disconnected Element");
runTest( css, "Disconnected Element", root4, true );
check( "Disconnected Element", root4, true, true );
cacheCheck( "Disconnected Element", root4 );
runTest( ecss, "SyntaxError: Disconnected Element", root4, false );
jqTests("Disconnected Element", root3.cloneNode(true), "querySelectorAll");
var fragment = document.createDocumentFragment();
fragment.appendChild( root2.cloneNode(true) );
interfaceCheck(fragment, "Fragment");
runTest( css, "Fragment", fragment, true );
check( "Fragment", fragment, true, true );
runTest( ecss, "SyntaxError: Fragment", fragment, false );
cacheCheck( "Fragment", fragment );
root.parentNode.removeChild( root );
interfaceCheck(document, "Document");
runTest( css, "Document", document, true );
check( "Document", document, true, false );
runTest( ecss, "SyntaxError: Document", document, false );
jqTests("Document", document, "querySelectorAll");
cacheCheck( "Document", document );
done();
function interfaceCheck(obj, type){
var q = typeof obj.querySelector === "function";
assert( q, type + " supports querySelector" );
var qa = typeof obj.querySelectorAll === "function";
assert( qa, type + " supports querySelectorAll" );
return q && qa;
}
function done(){
if (window.parent && window.parent.SimpleTest) {
window.parent.SimpleTest.finish();
} else {
var r = document.getElementById("results");
var li = document.createElement("li");
var b = document.createElement("b");
b.appendChild( document.createTextNode( ((passed / tests) * 100).toFixed(1) + "%" ) );
li.appendChild( b );
li.appendChild( document.createTextNode( ": " + passed + " passed, " + (tests - passed) + " failed" ) );
r.appendChild( li );
for ( var i = 0; i < results.length; i++ ) {
var li = document.createElement("li");
var span = document.createElement("span");
span.style.color = (results[i][0] === "FAIL" ? "red" : "green");
span.appendChild( document.createTextNode( results[i][0] ) );
li.appendChild( span );
li.appendChild( document.createTextNode( " " + results[i][1] ) );
r.appendChild( li );
}
}
}
function cacheCheck( type, root ) {
try {
var pre = root.querySelectorAll( "div" ), preLength = pre.length;
var div = document.createElement("div");
(root.body || root).appendChild( div );
var post = root.querySelectorAll( "div" ), postLength = post.length;
assert( pre.length == preLength, type + ": StaticNodeList" );
assert( post.length != pre.length, type + ": StaticNodeList" );
} catch(e) {
assert( false, type + ": StaticNodeList" );
assert( false, type + ": StaticNodeList" );
}
if ( div )
(root.body || root).removeChild( div );
}
function runTest( css, type, root, expect ) {
var pass = false;
try {
root.querySelectorAll("");
} catch(e){ pass = e.code == DOMException.SYNTAX_ERR; }
assert( pass, type + ".querySelectorAll Empty String" );
pass = false;
try {
pass = root.querySelectorAll(null).length === 0;
} catch(e){ pass = false; }
assert( pass, type + ".querySelectorAll null" );
pass = false;
try {
pass = root.querySelectorAll(undefined).length === 0;
} catch(e){ pass = false; }
assert( pass, type + ".querySelectorAll undefined" );
pass = false;
try {
if ( root.querySelectorAll )
root.querySelectorAll();
} catch(e){ pass = true; }
assert( pass, type + ".querySelectorAll no value" );
pass = false;
try {
root.querySelector("");
} catch(e){ pass = e.code == DOMException.SYNTAX_ERR; }
assert( pass, type + ".querySelector Empty String" );
pass = false;
try {
pass = root.querySelector(null) === null;
} catch(e){ pass = false; }
assert( pass, type + ".querySelector null" );
pass = false;
try {
pass = root.querySelector(undefined) === null;
} catch(e){ pass = false; }
assert( pass, type + ".querySelector undefined" );
pass = false;
try {
if ( root.querySelector )
root.querySelector();
} catch(e){ pass = true; }
assert( pass, type + ".querySelector no value" );
for ( var i = 0; i < css.length; i++ ) {
var test = css[i];
if ( test.length == 2 ) {
var query = test[0], color = test[1].match(/: ([^\s;]+)/)[1];
try {
var found = root.querySelectorAll(query);
for ( var f = 0; f < found.length; f++ ) {
found[f].style.backgroundColor = color;
}
var pass = color != "red" || found.length === 0;
assert(expect && pass, type + ".querySelectorAll: " + query);
} catch(e){
var pass = !expect && e.code == DOMException.SYNTAX_ERR || false;
assert(pass, type + ".querySelectorAll: " + query);
}
if ( expect ) {
var pass = false;
try {
var found2 = root.querySelectorAll( " \t\r\n " + query + " \t\r\n " );
pass = found2.length == found.length;
} catch(e) {}
assert(pass, type + ".querySelectorAll Whitespace Trim: " + query);
}
try {
var single = root.querySelector(query);
var pass = found.length == 0 && single === null ||
found.length && found[0] == single;
assert(expect, type + ".querySelector: " + query);
} catch(e){
var pass = !expect && e.code == DOMException.SYNTAX_ERR || false;
assert(pass, type + ".querySelector: " + query);
}
}
}
}
function check( type, root, expect, fragment ){
var walker = document.createTreeWalker( root, NodeFilter.SHOW_ELEMENT, { acceptNode: function(){ return 1; } }, false );
while ( walker.nextNode() ) {
var div = walker.currentNode;
if ( (div.getAttribute("class") || "").toString().indexOf("unitTest") > -1 &&
(!fragment || div.getAttribute("id") !== "nofragment") ) {
// If we're display:none, we need to toggle that when doing computed
// style.
var needToggle =
(window.frameElement &&
window.frameElement.style.display == "none");
if (needToggle) {
if ((div.getAttribute("class") || "").toString().indexOf("skipWhenToggling") > -1) {
continue;
}
window.frameElement.style.display = "";
// make sure it kicks in immediately
document.body.offsetWidth;
}
var view = document.defaultView.getComputedStyle(div, null);
var bg = view.getPropertyValue("background-color") || div.style.backgroundColor;
if (needToggle) {
window.frameElement.style.display = "none";
// make sure it kicks in immediately
document.body.offsetWidth;
}
var pass = bg && bg.indexOf("(255, 0, 0") == -1 && bg.indexOf("#ff0000") == -1 && bg.indexOf("red") == -1;
//var pass = bg && bg.indexOf("(255, 0, 0") == -1 && bg.indexOf("#ff0000") == -1;
assert(pass === expect, type + ": " + (div.title || div.parentNode.title));
}
}
}
function assert(pass, title) {
// Update |passed| no matter what: some tests depend on this
passed += (pass ? 1 : 0);
if (window.parent && window.parent.SimpleTest) {
window.parent.SimpleTest.ok(pass, title);
} else {
results.push([ (!pass ? "FAIL" : "PASS"), title ]);
tests++;
}
}
function jqTests(type, root, select) {
function query(q, resolver){
try {
return root[select](q, resolver);
} catch(e){
if ( e.message.indexOf("ERR") > -1 || e.code == DOMException.NAMESPACE_ERR ||
e.code == DOMException.SYNTAX_ERR)
throw e;
}
}
var all = query("*");
function checkMatchesSelector(results, q) {
var key = +new Date + ":" + Math.random();
function report(item, shouldMatch) {
assert( item.mozMatchesSelector(q) === shouldMatch,
item + (shouldMatch ? "does not match" : "matches")
+ " selector '" + q + "'" );
}
for (var i = 0; i < results.length; i++) {
var item = results.item(i);
item[key] = true;
report( item, true );
}
for (var stride = 15, // reduce test spam
i = Math.round(Math.random() * stride);
i < all.length; i += stride)
{
var item = all.item(i),
shouldMatch = !!item[key];
report( item, shouldMatch );
}
for (var i = 0; i < results.length; i++)
delete results.item(i)[key];
}
function t( name, q, ids, restrict, ids2 ) {
var pass = true;
if ( restrict === false && root != document )
return;
var namespaced = /\|[^=]/.test( q );
var prepend = namespaced ? "xHTML|*#root3 " : "#root3 ";
q = (restrict === false || restrict === ":root" ? "" : prepend) + q.replace(/,/g, ", " + prepend);
var nq = q.replace(/>/g, ">").replace(/</g, "<");
if ( namespaced ) {
for ( var i = 0; i < badNamespace.length; i++ ) {
var resolver = badNamespace[i], pass = false, results = null;
try {
results = query(q, resolver);
} catch(e) {
pass = (e.message === "bad ERROR" || e.code == DOMException.NAMESPACE_ERR);
}
assert( pass, type + ": " + name + " Bad Resolver #" + (i+1) + " (" + nq + ")" +
(pass ? "" : " Expected: " + extra(ids) + " Received: " + extra(results)) );
}
} else {
var pass = false;
try {
var results = query(q);
pass = hasPassed( results, ids );
} catch(e) {
pass = e.code == DOMException.SYNTAX_ERR;
}
assert( pass, type + ": " + name + " (" + nq + ")" +
(pass ? "" : " Expected: " + extra(ids) + " Received: " + extra(results)) );
if (results)
checkMatchesSelector( results, q );
}
function hasPassed(results, ids){
var pass = (results && results.length == ids.length) || (!results && !ids);
if ( ids && results ) {
for ( var i = 0; ids && i < ids.length; i++ ) {
if ( ids[i] !== results[i].getAttribute("id") ) {
pass = false;
}
}
} else {
pass = false;
}
return pass;
}
function extra(results){
var extra = " [";
if ( results ) {
for ( var i = 0; i < results.length; i++ ) {
extra += (extra.length > 2 ? "," : "") + "'" + (results[i].id || results[i]) + "'";
}
}
extra += "]";
return extra;
}
}
t( "SVG", "*|svg", ["svg1","svg2","svg3"] );
t( "SVG", "svg|svg", ["svg2","svg3"] );
t( "SVG", "svg|svg *|circle", ["circle2","circle3"] );
t( "SVG", "svg|svg svg|circle", ["circle2","circle3"] );
t( "SVG", "xHTML|div *|svg", ["svg1","svg2","svg3"] );
t( "SVG", "div svg|svg", ["svg2","svg3"] );
t( "SVG", "xHTML|div svg|svg", ["svg2","svg3"] );
t( "SVG", "xHTML|div svg|svg *|circle", ["circle2","circle3"] );
t( "SVG", "xHTML|div svg *|circle", ["circle1","circle2","circle3"], true, ["circle1"] );
t( "SVG", "xHTML|div svg|svg svg|circle", ["circle2","circle3"] );
t( "Element Selector", "xHTML|p", ["firstp","ap","sndp","en","sap","first"] );
t( "Parent Element", "xHTML|div p", ["firstp","ap","sndp","en","sap","first"] );
t( "Parent Element", "xHTML|div xHTML|p", ["firstp","ap","sndp","en","sap","first"] );
t( "Parent Element", "*|div xHTML|p", ["firstp","ap","sndp","en","sap","first"] );
t( "Parent Element", "*|div *|p", ["firstp","ap","sndp","en","sap","first"] );
t( "Child", "xHTML|p > xHTML|a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Adjacent", "xHTML|a + xHTML|a", ["groups"] );
t( "Adjacent", "xHTML|a + a", ["groups"] );
t( "Nth-child", "xHTML|*#form xHTML|*#select1 xHTML|option:nth-child(3)", ["option1c"] );
assert( all && all.length > 30, type + ": Select all" );
var good = all && all.length;
for ( var i = 0; all && i < all.length; i++ )
if ( all[i].nodeType != 1 )
good = false;
assert( good, type + ": Select all elements, no comment nodes" );
if ( root == document ) {
t( ":root Selector", ":root", ["html"], false );
} else {
t( ":root Selector", ":root", [], ":root" );
if ( !root.parentNode ) {
t( ":root All Selector", ":root *", [], ":root" );
}
}
if ( root.parentNode || root == document ) {
assert( query(":root *").length == query("*").length - (root == document ? 1 : 0), type + ": :root All Selector" );
}
t( "Element Selector", "p", ["firstp","ap","sndp","en","sap","first"] );
t( "Element Selector", "body", ["body"], false );
t( "Element Selector", "html", ["html"], false );
t( "Parent Element", "div p", ["firstp","ap","sndp","en","sap","first"] );
var param = query("#object1 param");
assert( param && param.length == 2, type + ": Object/param as context" );
var l = query("#length");
assert( l && l.length, type + ': <input name="length"> cannot be found under IE' );
var lin = query("#lengthtest input");
assert( lin && lin.length, type + ': <input name="length"> cannot be found under IE' );
t( "Broken Selector", "[" );
t( "Broken Selector", "(" );
t( "Broken Selector", "{" );
t( "Broken Selector", "<" );
t( "Broken Selector", "()" );
t( "Broken Selector", "<>" );
t( "Broken Selector", "{}" );
t( "ID Selector", "#body", ["body"], false );
t( "ID Selector w/ Element", "body#body", ["body"], false );
t( "ID Selector w/ Element", "ul#first", [] );
t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] );
t( "ID selector with nonexistent descendant", "#firstp #foobar", [] );
t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] );
t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] );
t( "Descendant ID selector using UTF8", "div #台北", ["台北"] );
t( "Child ID selector using UTF8", "form > #台北", ["台北"] );
t( "Escaped ID", "#foo\\:bar", ["foo:bar"] );
t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] );
t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] );
t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267
t( "ID Selector, not an ancestor ID", "#form #first", [] );
t( "ID Selector, not a child ID", "#form > #option1a", [] );
t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] );
t( "All Children of ID with no children", "#firstUL > *", [] );
t( "ID selector with nonexistent ancestor", "#asdfasdf #foobar", [] ); // bug #986
//t( "body div#form", [], "ID selector within the context of another element" );
t( "Class Selector", ".blog", ["mark","simon"] );
t( "Class Selector", ".blog.link", ["simon"] );
t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
t( "Parent Class Selector", "p .blog", ["mark","simon"] );
t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] );
t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] );
t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] );
t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] );
t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] );
t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] );
t( "Escaped Class", ".foo\\:bar", ["foo:bar"] );
t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "Descendant scaped Class", "div .foo\\:bar", ["foo:bar"] );
t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] );
t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "Comma Support", "a.blog, p", ['firstp','ap','mark','sndp','en','sap','simon','first'] );
t( "Comma Support", "a.blog , p", ['firstp','ap','mark','sndp','en','sap','simon','first'] );
t( "Comma Support", "a.blog ,p", ['firstp','ap','mark','sndp','en','sap','simon','first'] );
t( "Comma Support", "a.blog,p", ['firstp','ap','mark','sndp','en','sap','simon','first'] );
t( "Outer Whitespace", " a.blog,p", ['firstp','ap','mark','sndp','en','sap','simon','first'] );
t( "Outer Whitespace", "a.blog,p ", ['firstp','ap','mark','sndp','en','sap','simon','first'] );
t( "Outer Whitespace", " p,a.blog", ['firstp','ap','mark','sndp','en','sap','simon','first'] );
t( "Outer Whitespace", "p,a.blog ", ['firstp','ap','mark','sndp','en','sap','simon','first'] );
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
t( "All Children", "code > *", ["anchor1","anchor2"] );
t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
t( "Adjacent", "a + a", ["groups"] );
t( "Adjacent", "a +a", ["groups"] );
t( "Adjacent", "a+ a", ["groups"] );
t( "Adjacent", "a+a", ["groups"] );
t( "Adjacent", "p + p", ["ap","en","sap"] );
t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
t( "First Child", "p:first-child", ["firstp","sndp"] );
t( "Nth Child", "p:nth-child(1)", ["firstp","sndp"] );
t( "Last Child", "p:last-child", ["sap"] );
t( "Last Child", "a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon"] );
t( "Nth-child", "#main form#form > *:nth-child(2)", ["text2"] );
t( "Nth-child", "#main form#form > :nth-child(2)", ["text2"] );
t( "Nth-child", "#form #select1 option:nth-child(3)", ["option1c"] );
t( "Nth-child", "#form #select1 option:nth-child(0n+3)", ["option1c"] );
t( "Nth-child", "#form #select1 option:nth-child(1n+0)", ["option1a", "option1b", "option1c", "option1d"] );
t( "Nth-child", "#form #select1 option:nth-child(1n)", ["option1a", "option1b", "option1c", "option1d"] );
t( "Nth-child", "#form #select1 option:nth-child(n)", ["option1a", "option1b", "option1c", "option1d"] );
t( "Nth-child", "#form #select1 option:nth-child(even)", ["option1b", "option1d"] );
t( "Nth-child", "#form #select1 option:nth-child(odd)", ["option1a", "option1c"] );
t( "Nth-child", "#form #select1 option:nth-child(2n)", ["option1b", "option1d"] );
t( "Nth-child", "#form #select1 option:nth-child(2n+1)", ["option1a", "option1c"] );
t( "Nth-child", "#form #select1 option:nth-child(3n)", ["option1c"] );
t( "Nth-child", "#form #select1 option:nth-child(3n+1)", ["option1a", "option1d"] );
t( "Nth-child", "#form #select1 option:nth-child(3n+2)", ["option1b"] );
t( "Nth-child", "#form #select1 option:nth-child(3n+3)", ["option1c"] );
t( "Nth-child", "#form #select1 option:nth-child(3n-1)", ["option1b"] );
t( "Nth-child", "#form #select1 option:nth-child(3n-2)", ["option1a", "option1d"] );
t( "Nth-child", "#form #select1 option:nth-child(3n-3)", ["option1c"] );
t( "Nth-child", "#form #select1 option:nth-child(3n+0)", ["option1c"] );
t( "Nth-child", "#form #select1 option:nth-child(-n+3)", ["option1a", "option1b", "option1c"] );
t( "Attribute Exists", "a[title]", ["google"] );
t( "Attribute Exists", "*[title]", ["google"] );
t( "Attribute Exists", "[title]", ["google"] );
t( "Attribute Equals", "a[rel='bookmark']", ["simon1"] );
t( "Attribute Equals", 'a[rel="bookmark"]', ["simon1"] );
t( "Attribute Equals", "a[rel=bookmark]", ["simon1"] );
t( "Multiple Attribute Equals", "#form input[type='hidden'],#form input[type='radio']", ['radio1','radio2','hidden1'] );
t( "Multiple Attribute Equals", "#form input[type=\"hidden\"],#form input[type='radio']", ['radio1','radio2','hidden1'] );
t( "Multiple Attribute Equals", "#form input[type=hidden],#form input[type=radio]", ['radio1','radio2','hidden1'] );
t( "Attribute selector using UTF8", "span[lang=中文]", ["台北"] );
t( "Attribute Begins With", "a[href ^= 'http://www']", ["google","yahoo"] );
t( "Attribute Ends With", "a[href $= 'org/']", ["mark"] );
t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] );
// t("Select options via [selected]", "#select1 option[selected]", ["option1a"] );
t("Select options via [selected]", "#select1 option[selected]", [] );
t("Select options via [selected]", "#select2 option[selected]", ["option2d"] );
t("Select options via [selected]", "#select3 option[selected]", ["option3b", "option3c"] );
t( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] );
t( ":not() Existing attribute", "#form select:not([multiple])", ["select1", "select2"]);
t( ":not() Equals attribute", "#form select:not([name=select1])", ["select2", "select3"]);
t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", ["select2", "select3"]);
t( "First Child", "p:first-child", ["firstp","sndp"] );
t( "Last Child", "p:last-child", ["sap"] );
t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
t( "Empty", "ul:empty", ["firstUL"] );
//t( "Enabled UI Element", "#form input:enabled", ["text1","radio1","radio2","check1","check2","hidden2","name"] );
t( "Disabled UI Element", "#form input:disabled", ["text2"] );
t( "Checked UI Element", "#form input:checked", ["radio2","check1"] );
t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] );
t( "Not", "a.blog:not(.link)", ["mark"] );
}
};
]]></script>
</head>
<body id="body" class="unitTest" title="childhood and element type selectors">
<h1><a href="http://www.w3.org/TR/selectors-api/">Selectors API</a> Test Suite</h1>
<p>Testrunner by <a href="http://ejohn.org/">John Resig</a>, tests by <a href="http://ejohn.org/">John Resig</a>, <a href="http://disruptive-innovations.com/zoo/css3tests/selectorTest.html">Disruptive Innovations</a>, <a href="http://www.w3.org/Style/CSS/Test/CSS3/Selectors/20060307/html/index.html">W3C CSS Working Group</a>, <a href="http://jquery.com/test/">jQuery JavaScript Library</a>.</p>
<div id="root">
<div class="header">
<h3>CSS 3 Selectors tests</h3>
<p>(c) <a href="http://www.disruptive-innovations.com">Disruptive Innovations</a> 2008<br/>
Last update: 2008-06-06</p>
</div>
<div class="test target">
<div class="unitTest skipWhenToggling" id="target" title=":target selector"></div>
</div>
<div class="test">
<div class="blox1 unitTest" title="childhood selector"></div>
</div>
<div class="test attributeExistence">
<div class="blox2 unitTest" align="center" title="attribute existence selector"></div>
<div class="blox3 unitTest" align="" title="attribute existence selector with empty string value"></div>
<div class="blox4 unitTest" valign="center" title="attribute existence selector with almost identical attribute"></div>
<div class="blox5 unitTest" alignv="center" title="attribute existence selector with almost identical attribute"></div>
</div>
<div class="test attributeValue">
<div class="blox6 unitTest" align="center" title="attribute value selector"></div>
<div class="blox6 unitTest" foo="é" title="attribute value selector with an entity in the attribute and an escaped value in the selector"></div>
<div class="blox6 unitTest" _foo="é" title="attribute value selector with an entity in the attribute, an escaped value in the selector, and a leading underscore in the attribute name"></div>
</div>
<div class="test attributeSpaceSeparatedValues">
<div class="blox7 foo unitTest" title="[~=] attribute selector"></div>
<div class="blox8 unitTest" title="[~=] attribute selector looking for empty string"></div>
<div class="blox9 unitTest" foo="" title="[~=] attribute selector looking for empty string in empty attribute"></div>
<div class="blox10 unitTest" foo="foobar" title="[~=] attribute selector looking for 'foo' in 'foobar'"></div>
</div>
<div class="test attrStart">
<div class="unitTest t1" title="[^=] attribute selector"></div>
<div class="unitTest t2" title="[^=] attribute selector"></div>
<div class="unitTest t3" align="center" title="[^=] attribute selector looking for empty string"></div>
<div class="unitTest t4" foo="étagada" title="[^=] attribute selector looking for é"></div>
</div>
<div class="test attrEnd">
<div class="unitTest t1" title="[$=] attribute selector"></div>
<div class="unitTest t2" title="[$=] attribute selector"></div>
<div class="unitTest t3" align="center" title="[$=] attribute selector looking for empty string"></div>
<div class="unitTest t4" foo="tagadaé" title="[$=] attribute selector looking for é"></div>
</div>
<div class="test attrMiddle">
<div class="unitTest t1" title="[*=] attribute selector"></div>
<div class="unitTest t2" title="[*=] attribute selector"></div>
<div class="unitTest t3" align="center" title="[*=] attribute selector looking for empty string"></div>
<div class="unitTest t4" foo="tagadaéfoo" title="[*=] attribute selector looking for é"></div>
</div>
<div class="test firstChild">
<div class="unitTest" title=":first-child selector"></div>
<div class="blox12 unitTest" title=":first-child selector should not match non first child"></div>
<div class="blox13 unitTest" title=":first-child selector should not match non first child"></div>
</div>
<div class="test not">
<div class="blox14 unitTest" title="negation pseudo-class with argument being an element type selector"></div>
<div class="blox15 unitTest" foo="blox15" title="negation pseudo-class with argument being an attribute selector"></div>
<div class="blox16 unitTest" foo="blox15" title="negation pseudo-class accepts only simple selectors for argument"></div>
</div>
<div class="test onlyOfType">
<div class="blox17 unitTest" title=":only-of-type selector"></div>
<p class="blox18 unitTest" title="negated :only-of-type selector"></p>
<p class="blox18 unitTest" title="negated :only-of-type selector"></p>
</div>
<div class="test nthchild1">
<div class="unitTest" title=":nth-child(odd) selector"></div>
<div class="unitTest" title=":nth-last-child(odd) selector"></div>
<div class="unitTest" title=":nth-child(odd) selector"></div>
<div class="unitTest" title=":nth-last-child(odd) selector"></div>
<div class="unitTest" title=":nth-child(odd) selector"></div>
<div class="unitTest" title=":nth-last-child(odd) selector"></div>
</div>
<div class="test nthchild2">
<div class="unitTest" title=":nth-last-child(even) selector"></div>
<div class="unitTest" title=":nth-child(even) selector"></div>
<div class="unitTest" title=":nth-last-child(even) selector"></div>
<div class="unitTest" title=":nth-child(even) selector"></div>
<div class="unitTest" title=":nth-last-child(even) selector"></div>
<div class="unitTest" title=":nth-child(even) selector"></div>
</div>
<div class="test nthchild3">
<div class="unitTest no" title=":nth-last-child(3n+3) selector"></div>
<div class="unitTest" title=":nth-child(3n+2) selector"></div>
<div class="unitTest no" title=":nth-last-child(3n+1) selector"></div>
<div class="unitTest no" title=":nth-last-child(3n+3) selector"></div>
<div class="unitTest" title=":nth-child(3n+2) selector"></div>
<div class="unitTest no" title=":nth-last-child(3n+1) selector"></div>
</div>
<div class="test nthoftype1">
<div class="unitTest" title=":nth-of-type(odd) selector"></div>
<p class="unitTest" title=":nth-* selector"></p>
<p class="unitTest" title=":nth-* selector"></p>
<div class="unitTest" title=":nth-last-of-type(odd) selector"></div>
<p class="unitTest" title=":nth-* selector"></p>
<div class="unitTest" title=":nth-of-type(odd) selector"></div>
<div class="unitTest" title=":nth-last-of-type(odd) selector"></div>
</div>
<div class="test nthoftype2">
<div class="unitTest" title=":nth-last-of-type(even) selector"></div>
<p class="unitTest" title=":nth-* selector"></p>
<p class="unitTest" title=":nth-* selector"></p>
<div class="unitTest" title=":nth-of-type(even) selector"></div>
<p class="unitTest" title=":nth-* selector"></p>
<div class="unitTest" title=":nth-last-of-type(even) selector"></div>
<div class="unitTest" title=":nth-of-type(even) selector"></div>
</div>
<div class="test nthoftype3">
<div class="unitTest" title=":nth-of-type(3n+1) selector"></div>
<p class="unitTest" title=":nth-* selector"></p>
<p class="unitTest" title=":nth-* selector"></p>
<div class="unitTest" title=":nth-last-of-type(3n+2) selector"></div>
<p class="unitTest" title=":nth-* selector"></p>
<div class="unitTest" title=":nth-last-of-type(3n+1) selector"></div>
<div class="unitTest" title=":nth-of-type(3n+1) selector"></div>
<p class="unitTest" title=":nth-* selector"></p>
<div class="unitTest" title=":nth-last-of-type(3n+2) selector"></div>
<div class="unitTest" title=":nth-last-of-type(3n+1) selector"></div>
</div>
<div class="test lastChild">
<p class="unitTest" title=":not(:last-child) selector"></p>
<div class="unitTest" title=":last-child selector"></div>
</div>
<div class="test firstOfType">
<p class="unitTest" title=":first-of-type selector"></p>
<div class="unitTest" title=":first-of-type selector"></div>
<p class="unitTest" title=":not(:first-of-type)"></p>
<div class="unitTest" title=":not(:first-of-type)"></div>
</div>
<div class="test lastOfType">
<p class="unitTest" title=":not(:last-of-type)"></p>
<div class="unitTest" title=":not(:last-of-type)"></div>
<p class="unitTest" title=":last-of-type selector"></p>
<div class="unitTest" title=":last-of-type selector"></div>
</div>
<div class="test onlyChild">
<div class="unitTest" title=":only-child where the element is NOT the only child"></div>
<div class="unitTest" title=":only-child where the element is the only child">
<div class="unitTest" title=":only-child where the element is the only child"></div>
</div>
</div>
<div class="test onlyOfType">
<p class="unitTest" title=":only-of-type"></p>
<div class="unitTest" title=":only-of-type">
<div class="unitTest" title=":only-of-type"></div>
</div>
<div class="unitTest" title=":not(only-of-type)"></div>
</div>
<div class="test empty">
<div class="unitTest isEmpty" title=":empty with empty element"></div>
<div class="unitTest isNotEmpty" title=":empty but element contains a whitespace"> </div>
<div class="unitTest isEmpty" title=":empty and element contains an SGML comment"><!-- foo --></div>
<div class="unitTest isNotEmpty" title=":empty but element contains a SPAN element"><span></span></div>
<div class="unitTest isNotEmpty" title=":empty but element contains an entity reference"> </div>
</div>
<div class="test lang">
<div id="nofragment" class="unitTest" title=":lang() where language comes from the document"></div>
<div class="unitTest" lang="fr" title=":lang() where language comes from the element"></div>
<div class="unitTest" lang="en-US" title=":lang() where language comes from the element but is a dialect of the language queried"></div>
<div class="unitTest t1" lang="es" title=":lang() where language comes from the element but the language queried is a dialect of the element's one so it should not match"></div>
</div>
<div class="test attrLang">
<div class="unitTest t1" title="[|=] where language comes from the document"></div>
<div class="unitTest" lang="fr" title="[|=] where language comes from the element"></div>
<div class="unitTest t2" lang="en-US" title="[|=] where language comes from the element but is a dialect of the language queried"></div>
<div class="unitTest t3" lang="es" title="[|=] where language comes from the element but the language queried is a dialect of the element's one so it should not match"></div>
</div>
<div class="test UI">
<button name="submit" type="submit" value="submit" class="t1" title=":enabled pseudo-class"><div class="unitTest"></div></button>
<button name="submit" type="submit" value="submit" class="t2" disabled="true" title=":enabled pseudo-class"><div class="unitTest"></div></button>
</div>
<div class="test UI">
<input class="t3" type="checkbox" checked="true"/><div class="unitTest" title=":checked"></div>
the previous square should be green when the checkbox is checked and become red when you uncheck it