aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojo/tests/_base/query.html
blob: 5c92221191a0c3f33c3fda14914a9e1bf1a55dcf (plain)
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
<html>
	<head>
		<title>testing dojo.query()</title>
		<style type="text/css">
			@import "../../resources/dojo.css";
		</style>
		<script type="text/javascript" src="../../dojo.js" 
			djConfig="isDebug: true, debugAtAllCosts: false, noFirebugLite: true"></script>
		<script type="text/javascript" src="../../../util/doh/runner.js"></script>
		<script type="text/javascript">
			dojo.require("doh.runner");
			dojo.require("dojox.data.dom");
			dojo.addOnLoad(function(){
				doh.register("t", 
					[
						// basic sanity checks
						"doh.is(4, (dojo.query('h3')).length);",
						"doh.is(1, (dojo.query('h1:first-child')).length);",
						"doh.is(2, (dojo.query('h3:first-child')).length);",
						"doh.is(1, (dojo.query('#t')).length);",
						"doh.is(1, (dojo.query('#bug')).length);",
						"doh.is(4, (dojo.query('#t h3')).length);",
						"doh.is(1, (dojo.query('div#t')).length);",
						"doh.is(4, (dojo.query('div#t h3')).length);",
						"doh.is(0, (dojo.query('span#t')).length);",
						"doh.is(1, (dojo.query('#t div > h3')).length);",
						"doh.is(2, (dojo.query('.foo')).length);",
						"doh.is(1, (dojo.query('.foo.bar')).length);",
						"doh.is(2, (dojo.query('.baz')).length);",
						"doh.is(3, (dojo.query('#t > h3')).length);",
						// syntactic equivalents
						"doh.is(12, (dojo.query('#t > *')).length);",
						"doh.is(12, (dojo.query('#t >')).length);",
						"doh.is(3, (dojo.query('.foo >')).length);",
						"doh.is(3, (dojo.query('.foo > *')).length);",
						// with a root, by ID
						"doh.is(3, (dojo.query('> *', 'container')).length);",
						"doh.is(3, (dojo.query('> h3', 't')).length);",
						// compound queries
						"doh.is(2, (dojo.query('.foo, .bar')).length);",
						"doh.is(2, (dojo.query('.foo,.bar')).length);",
						// multiple class attribute
						"doh.is(1, (dojo.query('.foo.bar')).length);",
						"doh.is(2, (dojo.query('.foo')).length);",
						"doh.is(2, (dojo.query('.baz')).length);",
						// case sensitivity
						"doh.is(1, (dojo.query('span.baz')).length);",
						"doh.is(1, (dojo.query('sPaN.baz')).length);",
						"doh.is(1, (dojo.query('SPAN.baz')).length);",
						"doh.is(1, (dojo.query('[class = \"foo bar\"]')).length);",
						"doh.is(2, (dojo.query('[foo~=\"bar\"]')).length);",
						"doh.is(2, (dojo.query('[ foo ~= \"bar\" ]')).length);",
						// "t.is(0, (dojo.query('[ foo ~= \"\\'bar\\'\" ]')).length);",
						"doh.is(3, (dojo.query('[foo]')).length);",
						"doh.is(1, (dojo.query('[foo$=\"thud\"]')).length);",
						"doh.is(1, (dojo.query('[foo$=thud]')).length);",
						"doh.is(1, (dojo.query('[foo$=\"thudish\"]')).length);",
						"doh.is(1, (dojo.query('#t [foo$=thud]')).length);",
						"doh.is(1, (dojo.query('#t [ title $= thud ]')).length);",
						"doh.is(0, (dojo.query('#t span[ title $= thud ]')).length);",
						"doh.is(1, (dojo.query('[foo|=\"bar\"]')).length);",
						"doh.is(1, (dojo.query('[foo|=\"bar-baz\"]')).length);",
						"doh.is(0, (dojo.query('[foo|=\"baz\"]')).length);",
						"doh.is(dojo.byId('_foo'), dojo.query('.foo:nth-child(2)')[0]);",
						"doh.is(dojo.query('style')[0], dojo.query(':nth-child(2)')[0]);",
						// descendant selectors
						"doh.is(3, dojo.query('>', 'container').length);",
						"doh.is(3, dojo.query('> *', 'container').length);",
						"doh.is(2, dojo.query('> [qux]', 'container').length);",
						"doh.is('child1', dojo.query('> [qux]', 'container')[0].id);",
						"doh.is('child3', dojo.query('> [qux]', 'container')[1].id);",
						"doh.is(3, dojo.query('>', 'container').length);",
						"doh.is(3, dojo.query('> *', 'container').length);",
						"doh.is('passed', dojo.query('#bug')[0].value);",
						// sibling selectors
						"doh.is(1, dojo.query('+', 'container').length);",
						"doh.is(3, dojo.query('~', 'container').length);",
						"doh.is(1, (dojo.query('.foo + span')).length);",
						"doh.is(4, (dojo.query('.foo ~ span')).length);",
						"doh.is(1, (dojo.query('#foo ~ *')).length);",
						"doh.is(1, (dojo.query('#foo ~')).length);",
						// sub-selector parsing
						"doh.is(1, dojo.query('#t span.foo:not(span:first-child)').length);",
						"doh.is(1, dojo.query('#t span.foo:not(:first-child)').length);",

						// nth-child tests
						"doh.is(2, dojo.query('#t > h3:nth-child(odd)').length);",
						"doh.is(3, dojo.query('#t h3:nth-child(odd)').length);",
						"doh.is(3, dojo.query('#t h3:nth-child(2n+1)').length);",
						"doh.is(1, dojo.query('#t h3:nth-child(even)').length);",
						"doh.is(1, dojo.query('#t h3:nth-child(2n)').length);",
						"doh.is(0, dojo.query('#t h3:nth-child(2n+3)').length);",
						"doh.is(2, dojo.query('#t h3:nth-child(1)').length);",
						"doh.is(1, dojo.query('#t > h3:nth-child(1)').length);",
						"doh.is(3, dojo.query('#t :nth-child(3)').length);",
						"doh.is(0, dojo.query('#t > div:nth-child(1)').length);",
						"doh.is(7, dojo.query('#t span').length);",
						// :empty pseudo-selector
						"doh.is(4, dojo.query('#t > span:empty').length);",
						"doh.is(6, dojo.query('#t span:empty').length);",
						"doh.is(0, dojo.query('h3 span:empty').length);",
						"doh.is(1, dojo.query('h3 :not(:empty)').length);",
						// escaping of ":" chars inside an ID
						function silly_IDs1(){
							doh.t(document.getElementById("silly:id::with:colons"));
							doh.is(1, dojo.query("#silly\\:id\\:\\:with\\:colons").length);
						},
						function NodeList_identity(){
							var foo = new dojo.NodeList([dojo.byId("container")]);
							doh.is(foo, dojo.query(foo));
						},
						function xml(){
							try{
								var doc = dojox.data.dom.createDocument("<ResultSet><Result>One</Result><Result>Two</Result></ResultSet>");
								console.debug(doc);
								console.debug(dojox.data.dom.innerXML(doc.documentElement));
								console.debug(dojo.query("Result", doc.documentElement).length);
							}catch(e){ console.debug(e); }
						}
					]
				);
				doh.run();
			});
		</script>
	</head>
	<body>
		<h1>testing dojo.query()</h1>
		<div id="t">
			<h3>h3 <span>span</span> endh3 </h3>
			<!-- comment to throw things off -->
			<div class="foo bar" id="_foo">
				<h3>h3</h3>
				<span id="foo"></span>
				<span></span>
			</div>
			<h3>h3</h3>
			<h3 class="baz" title="thud">h3</h3>
			<span class="foobar baz foo"></span>
			<span foo="bar"></span>
			<span foo="baz bar thud"></span>
			<!-- FIXME: should foo="bar-baz-thud" match? [foo$=thud] ??? -->
			<span foo="bar-baz-thudish" id="silly:id::with:colons"></span>
			<div id="container">
				<div id="child1" qux="true"></div>
				<div id="child2"></div>
				<div id="child3" qux="true"></div>
			</div>
			<div qux="true"></div>
			<input id="notbug" name="bug" type="hidden" value="failed" /> 
			<input id="bug" type="hidden" value="passed" /> 
		</div>
	</body>
</html>