Debian Codegraph @

dijit/tests/robot/ColorPalette.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <title>robot ColorPalette Test</title>
6
7 <style>
8 @import "../../../util/doh/robot/robot.css";
9 </style>
10
11 <!-- required: dojo.js -->
12 <script type="text/javascript" src="../../../dojo/dojo.js"
13 data-dojo-config="isDebug: true"></script>
14
15 <script type="text/javascript">
16 require([
17 "doh/runner", "dojo/robotx",
18 "dojo/dom", "dojo/dom-class", "dojo/keys", "dojo/_base/lang", "dojo/query", "dojo/sniff",
19 "dojo/domReady!"
20 ], function(doh, robot, dom, domClass, keys, lang, query, has){
21
22 robot.initRobot('../test_ColorPalette.html');
23
24 var big, small, prog;
25
26 // log of calls to onChange handler
27 var changes = [];
28
29 doh.register(function setup(){
30 // get pointer to registry in the iframe
31 registry = robot.window.require("dijit/registry");
32 dfocus = robot.window.require("dijit/focus");
33
34 // refs to ColorPalette widgets
35 big = registry.byId("big");
36 small = registry.byId("small");
37 prog = registry.byId("prog");
38
39 // setup onChange handler to monitor onChange calls
40 big.on("change", function(val){
41 console.log('onchange w/value: ', val);
42 changes.push(val);
43 });
44 });
45
46 doh.register("dijit.ColorPalette tests", [
47 {
48 name: "initial conditions",
49 runTest: function(){
50 doh.f(big.get('value'), "no value for big");
51 doh.f(small.get('value'), "no value for small");
52 doh.f(prog.get('value'), "no value for prog");
53 }
54 },
55 {
56 name: "accessibility roles and attributes",
57 runTest: function(){
58 doh.is(big.domNode.getAttribute("role"), "grid", "domNode role is grid");
59
60 var result = big.domNode.getAttribute("aria-label");
61 doh.t(!!result, "aria-label for big");
62
63 var table = query("table", big.domNode)[0];
64 doh.is(table.getAttribute("role"), "presentation", "table should be presentation");
65
66 var row = query("tr", table)[0];
67 doh.is(row.getAttribute("role"), "row", "tr should be role=row since domNode role=grid");
68
69 var td = query("td", row)[0];
70 doh.is(td.getAttribute("role"), "gridcell", "td role should be gridcell");
71 }
72 },
73
74 // TODO: when attr() is implemented as a setter, add tests like big.set("value", "#ffc0cb")
75
76 {
77 name: "focus",
78 timeout: 10000,
79 runTest: function(){
80 var d = new doh.Deferred();
81
82 big.focus();
83
84 robot.sequence(d.getTestCallback(function(){
85 doh.is(0, changes.length, "no onchange events yet");
86
87 // test that focus is on top left cell
88 var focus = dfocus.curNode;
89 doh.t(focus, "something is focused");
90 var imgNode = focus.getElementsByTagName("img")[0];
91 doh.t(imgNode, "found image node");
92
93 var dye = big._getDye(focus);
94 doh.is("#ffffff", dye.getValue(), "focused on white");
95 }), 500);
96
97 return d;
98 }
99 },
100
101 {
102 name: "arrow navigation",
103 timeout: 10000,
104 runTest: function(){
105 var d = new doh.Deferred(),
106 enterPressed = false;
107
108 // Move around some
109 robot.keyPress(keys.RIGHT_ARROW, 500, {});
110 robot.keyPress(keys.RIGHT_ARROW, 500, {});
111 robot.keyPress(keys.DOWN_ARROW, 500, {});
112 robot.keyPress(keys.LEFT_ARROW, 500, {});
113
114 // Focus should follow the current position for the benefit of screen readers.
115 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
116 var focus = dfocus.curNode;
117 doh.t(focus, "something is focused");
118
119 var imgNode = focus.getElementsByTagName("img")[0];
120 doh.t(imgNode, "found image node");
121
122 var dye = big._getDye(focus);
123 doh.is("#ffc0cb", dye.getValue(), "focused on right color");
124 })), 1000);
125
126 // Setup handler to catch onChange event from ENTER keypress below
127 handle = big.on("change", d.getTestCallback(lang.hitch(this, function(val){
128 handle.remove();
129 handle = null;
130
131 doh.is("#ffc0cb", val, "onChange() argument");
132 doh.is("#ffc0cb", big.get("value"), "get('value')");
133
134 doh.is(1, changes.length, 'just one onchange event');
135 doh.t(enterPressed, "onChange event didn't come until enter key was pressed");
136
137 big.set('value', null);
138 doh.is(big.get('value'), null, "value has been cleared");
139 })));
140
141 // Select the current value
142 robot.sequence(function(){
143 enterPressed = true;
144 }, 0);
145 robot.keyPress(keys.ENTER, 500, {});
146
147 return d;
148 },
149 tearDown: function(){
150 if(handle){
151 handle.remove();
152 }
153 }
154 },
155
156 {
157 name: "tab stops",
158 timeout: 10000,
159 runTest: function(){
160 // After the navigation above, make sure that there's (still) exactly one
161 // tab stop associated w/the color picker
162 var d = new doh.Deferred();
163
164 dom.byId("beforeBig").focus();
165 robot.keyPress(keys.TAB, 500, {});
166 robot.sequence(d.getTestErrback(function(){
167 doh.is("pink", dfocus.curNode.title, "tab into colorpalette, focus goes to pink (last focused cell)")
168 }), 1000);
169
170 robot.keyPress(keys.TAB, 500, {});
171 robot.sequence(d.getTestErrback(function(){
172 doh.is("afterBig", dfocus.curNode.id, "another tab, went to input after ColorPalette")
173 }), 1000);
174
175 robot.keyPress(keys.TAB, 500, {shift: true});
176 robot.sequence(d.getTestErrback(function(){
177 doh.is("pink", dfocus.curNode.title, "shift-tab back into colorpalette")
178 }), 1000);
179
180 robot.keyPress(keys.TAB, 500, {shift: true});
181 robot.sequence(d.getTestCallback(function(){
182 doh.is("beforeBig", dfocus.curNode.id, "another shift-tab, to input before ColorPalette")
183 }), 1000);
184
185 return d;
186 }
187 },
188 {
189 name: "small palette (keyboard)",
190 timeout: 10000,
191 runTest: function(){
192 var d = new doh.Deferred();
193
194 // go to small colorpalette
195 dom.byId("beforeSmall").focus();
196 robot.keyPress(keys.TAB, 500, {});
197
198 // select a value
199 robot.keyPress(keys.DOWN_ARROW, 500, {});
200 robot.keyPress(keys.RIGHT_ARROW, 500, {});
201 robot.keyPress(keys.SPACE, 500, {});
202
203 robot.sequence(d.getTestCallback(function(){
204 var value = small.get('value');
205 doh.is("#ffff00", value);
206 }), 1000);
207
208 return d;
209 }
210 },
211
212 {
213 name: "small palette (mouse)",
214 timeout: 10000,
215 runTest: function(){
216 var d = new doh.Deferred();
217
218 // Testing nls too...
219 var red = query("td[title=rojo]", small.domNode);
220 doh.is(1, red.length, "found rojo (red)");
221
222 robot.mouseMoveAt(red[0], 500);
223 robot.mouseClick({left: true}, 500);
224 if(has("mozilla")){
225 // workaround robot bug where first mouse click doesn't happen occasionally :-(
226 robot.mouseClick({left: true}, 500);
227 }
228
229 var green = query("td[title=verde]", small.domNode);
230 doh.is(1, green.length, "found verde (green)");
231
232 // Make sure <img> alt and title are translated. Not sure why they are being set at all though.
233 var greenImg = query("img", green[0]);
234 doh.is(1, greenImg.length, "found <img> inside of <td>");
235 doh.is("verde", greenImg[0].getAttribute("alt"), "img.alt");
236 doh.is("verde", greenImg[0].getAttribute("title"), "img.title");
237
238 robot.mouseMoveAt(green[0], 500);
239 robot.mouseClick({left: true}, 500);
240 if(has("mozilla")){
241 // workaround robot bug where first mouse click doesn't happen occasionally :-(
242 robot.mouseClick({left: true}, 500);
243 }
244
245 robot.sequence(d.getTestCallback(function(){
246 // test that value set
247 var value = small.get('value');
248 doh.is("#008000", value, "value");
249
250 // test that focus also got set
251 var focus = dfocus.curNode;
252 doh.t(focus, "something is focused");
253 var imgNode = focus.getElementsByTagName("img")[0];
254 doh.t(imgNode, "found image node");
255 var dye = small._getDye(focus);
256 doh.is("#008000", dye.getValue(), "focused");
257
258 // test that selected style was removed from previously selected cell and added to new selection
259 doh.f(domClass.contains(red[0], "dijitPaletteCellSelected"),
260 "Red swatch should not have selected class, actual class is: " + red[0].className);
261 doh.t(domClass.contains(green[0], "dijitPaletteCellSelected"),
262 "Green swatch should have selected class, actual class is: " + green[0].className);
263 }), 1000);
264
265
266 return d;
267 }
268 },
269 function valuePreselected(){
270 var cp = registry.byId("valuePreselected");
271 doh.is("#0000ff", cp.get("value"), "get('value')");
272 doh.is("blue", query(".dijitPaletteCellSelected img", cp.domNode)[0].alt, "marked");
273 }
274 ]);
275
276 doh.run();
277 });
278 </script>
279 </head>
280 </html>