2150 |
mathias |
1 |
<html>
|
|
|
2 |
<head>
|
|
|
3 |
<title>Parser Unit Test</title>
|
|
|
4 |
<style type="text/css">
|
|
|
5 |
@import "../resources/dojo.css";
|
|
|
6 |
</style>
|
|
|
7 |
<script type="text/javascript"
|
|
|
8 |
src="../dojo.js"
|
|
|
9 |
djConfig="isDebug: true, parseOnLoad: true"></script>
|
|
|
10 |
<script type="text/javascript">
|
|
|
11 |
dojo.require("dojo.parser");
|
|
|
12 |
dojo.require("doh.runner");
|
|
|
13 |
|
|
|
14 |
dojo.declare("tests.parser.Class1", null, {
|
|
|
15 |
constructor: function(args, node){ dojo.mixin(this, args); },
|
|
|
16 |
preambleTestProp: 1,
|
|
|
17 |
preamble: function(){
|
|
|
18 |
this.preambleTestProp++;
|
|
|
19 |
},
|
|
|
20 |
intProp: 1,
|
|
|
21 |
callCount: 0, // for connect testing
|
|
|
22 |
callInc: function(){ this.callCount++; },
|
|
|
23 |
callCount2: 0, // for assignment testing
|
|
|
24 |
strProp1: "original1",
|
|
|
25 |
strProp2: "original2",
|
|
|
26 |
arrProp: [],
|
|
|
27 |
boolProp1: false,
|
|
|
28 |
boolProp2: true,
|
|
|
29 |
boolProp3: false,
|
|
|
30 |
boolProp4: true,
|
|
|
31 |
dateProp1: dojo.date.stamp.fromISOString('2007-01-01'),
|
|
|
32 |
dateProp2: dojo.date.stamp.fromISOString('2007-01-01'),
|
|
|
33 |
dateProp3: dojo.date.stamp.fromISOString('2007-01-01'),
|
|
|
34 |
funcProp: function(){},
|
|
|
35 |
funcProp2: function(){},
|
|
|
36 |
funcProp3: function(){},
|
|
|
37 |
onclick: function(){ this.prototypeOnclick=true; }
|
|
|
38 |
// FIXME: have to test dates!!
|
|
|
39 |
// FIXME: need to test the args property!!
|
|
|
40 |
});
|
|
|
41 |
|
|
|
42 |
dojo.declare("tests.parser.Class2", null, {
|
|
|
43 |
constructor: function(){
|
|
|
44 |
this.fromMarkup = false;
|
|
|
45 |
},
|
|
|
46 |
fromMarkup: false,
|
|
|
47 |
markupFactory: function(args, node, classCtor){
|
|
|
48 |
var i = new tests.parser.Class2();
|
|
|
49 |
i.fromMarkup = true;
|
|
|
50 |
return i;
|
|
|
51 |
}
|
|
|
52 |
});
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
dojo.declare("tests.parser.Class3", tests.parser.Class2, {
|
|
|
56 |
fromMarkup: false,
|
|
|
57 |
markupFactory: function(args, node, classCtor){
|
|
|
58 |
var i = new classCtor();
|
|
|
59 |
i.classCtor = classCtor;
|
|
|
60 |
return i;
|
|
|
61 |
}
|
|
|
62 |
});
|
|
|
63 |
|
|
|
64 |
dojo.declare("tests.parser.inputClass", null, {
|
|
|
65 |
constructor: function(args, node){ dojo.mixin(this, args); },
|
|
|
66 |
// these attributes are special in HTML, they don't have a value specified
|
|
|
67 |
disabled: false,
|
|
|
68 |
checked: false
|
|
|
69 |
});
|
|
|
70 |
|
|
|
71 |
deepTestProp = {
|
|
|
72 |
blah: {
|
|
|
73 |
thinger: 1
|
|
|
74 |
}
|
|
|
75 |
};
|
|
|
76 |
|
|
|
77 |
dojo.addOnLoad(function(){
|
|
|
78 |
doh.register("t",
|
|
|
79 |
[
|
|
|
80 |
function testJsId(t){
|
|
|
81 |
// console.debug(obj);
|
|
|
82 |
t.t(typeof obj == "object");
|
|
|
83 |
},
|
|
|
84 |
|
|
|
85 |
// Attribute parsing tests
|
|
|
86 |
function testStrProp(t){
|
|
|
87 |
// normal string parameter
|
|
|
88 |
t.t(dojo.isString(obj.strProp1));
|
|
|
89 |
t.is("text", obj.strProp1);
|
|
|
90 |
|
|
|
91 |
// make sure that you override a string value like "foo" to a blank value
|
|
|
92 |
t.t(dojo.isString(obj.strProp2));
|
|
|
93 |
t.is("", obj.strProp2);
|
|
|
94 |
},
|
|
|
95 |
function testIntProp(t){
|
|
|
96 |
t.is("number", (typeof obj.intProp));
|
|
|
97 |
t.is(5, obj.intProp);
|
|
|
98 |
},
|
|
|
99 |
function testArrProp(t){
|
|
|
100 |
t.is(3, obj.arrProp.length);
|
|
|
101 |
t.is(3, obj.arrProp[1].length);
|
|
|
102 |
t.is(["foo", "bar", "baz"], obj.arrProp);
|
|
|
103 |
},
|
|
|
104 |
function testBoolProp(t){
|
|
|
105 |
// make sure that both true and false get read correctly,
|
|
|
106 |
// and that unspecified attributes' values don't change
|
|
|
107 |
|
|
|
108 |
// boolProp1 specified at true
|
|
|
109 |
t.is("boolean", (typeof obj.boolProp1));
|
|
|
110 |
t.t(obj.boolProp1);
|
|
|
111 |
|
|
|
112 |
// boolProp2 specified as false
|
|
|
113 |
t.is("boolean", (typeof obj.boolProp2));
|
|
|
114 |
t.f(obj.boolProp2);
|
|
|
115 |
|
|
|
116 |
// boolProp3 not specified (prototype says false)
|
|
|
117 |
t.is("boolean", (typeof obj.boolProp3));
|
|
|
118 |
t.f(obj.boolProp3);
|
|
|
119 |
|
|
|
120 |
// boolProp4 not specified (prototype says true)
|
|
|
121 |
t.is("boolean", (typeof obj.boolProp4));
|
|
|
122 |
t.t(obj.boolProp4);
|
|
|
123 |
},
|
|
|
124 |
function testDateProp(t){
|
|
|
125 |
// dateProp1 specified as 2006-1-1
|
|
|
126 |
t.is("2006-01-01", dojo.date.stamp.toISOString(obj.dateProp1, {selector: 'date'}));
|
|
|
127 |
|
|
|
128 |
// dateProp2="", should map to NaN (a blank value on DateTextBox)
|
|
|
129 |
t.t(isNaN(obj.dateProp2));
|
|
|
130 |
|
|
|
131 |
// dateProp3="now", should map to current date
|
|
|
132 |
t.is(dojo.date.stamp.toISOString(new Date(), {selector: 'date'}),
|
|
|
133 |
dojo.date.stamp.toISOString(obj.dateProp3, {selector: 'date'}));
|
|
|
134 |
},
|
|
|
135 |
function testDisabledFlag(t){
|
|
|
136 |
t.is("boolean", (typeof disabledObj.disabled));
|
|
|
137 |
t.t(disabledObj.disabled);
|
|
|
138 |
t.f(disabledObj.checked);
|
|
|
139 |
},
|
|
|
140 |
function testCheckedFlag(t){
|
|
|
141 |
t.is("boolean", (typeof checkedObj.checked));
|
|
|
142 |
t.f(checkedObj.disabled);
|
|
|
143 |
t.t(checkedObj.checked);
|
|
|
144 |
},
|
|
|
145 |
function testFunctionProp(t){
|
|
|
146 |
// make sure that unspecified functions (even with common names)
|
|
|
147 |
// don't get overridden (bug #3074)
|
|
|
148 |
obj.onclick();
|
|
|
149 |
t.t(obj.prototypeOnclick);
|
|
|
150 |
|
|
|
151 |
// funcProp2="foo"
|
|
|
152 |
obj.funcProp2();
|
|
|
153 |
t.t(obj.fooCalled);
|
|
|
154 |
|
|
|
155 |
// funcProp3="this.func3Called=true;"
|
|
|
156 |
obj.funcProp3();
|
|
|
157 |
t.t(obj.func3Called);
|
|
|
158 |
},
|
|
|
159 |
|
|
|
160 |
// test <script> tags inside innerHTML of source node
|
|
|
161 |
"t.is(4, obj.preambleTestProp);",
|
|
|
162 |
"t.is(deepTestProp, obj.deepProp);",
|
|
|
163 |
function testConnect(t){
|
|
|
164 |
obj.callInc();
|
|
|
165 |
t.is(2, obj.callCount);
|
|
|
166 |
},
|
|
|
167 |
function testFunctionAssignment(t){
|
|
|
168 |
obj.callInc2();
|
|
|
169 |
t.is(1, obj.callCount2);
|
|
|
170 |
},
|
|
|
171 |
function testSubNodeParse(t){
|
|
|
172 |
t.f(dojo.exists("obj2"));
|
|
|
173 |
var toParse = dojo.byId("toParse");
|
|
|
174 |
toParse.setAttribute("dojoType", toParse.getAttribute("type"));
|
|
|
175 |
dojo.parser.parse(toParse.parentNode);
|
|
|
176 |
t.t(dojo.exists("obj2"));
|
|
|
177 |
t.is("tests.parser.Class1", obj2.declaredClass);
|
|
|
178 |
},
|
|
|
179 |
function testMarkupFactory(t){
|
|
|
180 |
t.t(dojo.exists("obj3"));
|
|
|
181 |
t.t(obj3.fromMarkup);
|
|
|
182 |
},
|
|
|
183 |
function testMarkupFactoryClass(t){
|
|
|
184 |
t.t(dojo.exists("obj4"));
|
|
|
185 |
t.is(obj4.classCtor, tests.parser.Class3);
|
|
|
186 |
t.t(obj4 instanceof tests.parser.Class3);
|
|
|
187 |
t.t(obj4 instanceof tests.parser.Class2);
|
|
|
188 |
},
|
|
|
189 |
function testDisabledFlag(t){
|
|
|
190 |
t.t(disabledObj.disabled);
|
|
|
191 |
t.f(disabledObj.checked);
|
|
|
192 |
},
|
|
|
193 |
function testCheckedFlag(t){
|
|
|
194 |
t.f(checkedObj.disabled);
|
|
|
195 |
t.t(checkedObj.checked);
|
|
|
196 |
}
|
|
|
197 |
]
|
|
|
198 |
);
|
|
|
199 |
doh.run();
|
|
|
200 |
})
|
|
|
201 |
</script>
|
|
|
202 |
</head>
|
|
|
203 |
<body>
|
|
|
204 |
<h1>Parser Unit Test</h1>
|
|
|
205 |
<script>
|
|
|
206 |
function foo(){ this.fooCalled=true; }
|
|
|
207 |
</script>
|
|
|
208 |
<div dojoType="tests.parser.Class1" jsId="obj"
|
|
|
209 |
strProp1="text" strProp2=""
|
|
|
210 |
intProp="5"
|
|
|
211 |
arrProp="foo, bar, baz"
|
|
|
212 |
boolProp1="true" boolProp2="false"
|
|
|
213 |
dateProp1="2006-01-01" dateProp2="" dateProp3="now"
|
|
|
214 |
funcProp2="foo" funcProp3="this.func3Called=true;"
|
|
|
215 |
>
|
|
|
216 |
<script type="dojo/method" event="preamble">
|
|
|
217 |
this.preambleTestProp = 3;
|
|
|
218 |
</script>
|
|
|
219 |
<script type="dojo/method">
|
|
|
220 |
// this should be run immediately
|
|
|
221 |
this.deepProp = deepTestProp;
|
|
|
222 |
</script>
|
|
|
223 |
<script type="dojo/connect" event="callInc">
|
|
|
224 |
this.callCount++;
|
|
|
225 |
</script>
|
|
|
226 |
<script type="dojo/method" event="callInc2">
|
|
|
227 |
this.callCount2++;
|
|
|
228 |
</script>
|
|
|
229 |
</div>
|
|
|
230 |
<div>
|
|
|
231 |
<div type="tests.parser.Class1" jsId="obj2" id="toParse">
|
|
|
232 |
</div>
|
|
|
233 |
</div>
|
|
|
234 |
<div dojoType="tests.parser.Class2" jsId="obj3">
|
|
|
235 |
</div>
|
|
|
236 |
<div dojoType="tests.parser.Class3" jsId="obj4">
|
|
|
237 |
</div>
|
|
|
238 |
<input dojoType="tests.parser.inputClass" jsId="checkedObj" checked type="checkbox">
|
|
|
239 |
<button dojoType="tests.parser.inputClass" jsId="disabledObj" disabled>hi</button>
|
|
|
240 |
</body>
|
|
|
241 |
</html>
|