Debian Codegraph @

dijit/tests/_base/robot/focus_mouse.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3
4 <!-- Remove in 2.0, replaced by dijit/tests/focus.html -->
5
6 <html>
7 <head>
8 <title>Dijit focus manager DOH Robot test</title>
9
10 <style>
11 @import "../../../../util/doh/robot/robot.css";
12 </style>
13
14 <!-- required: dojo.js -->
15 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
16
17 <script type="text/javascript">
18 dojo.require("dijit.robotx");
19
20 dojo.ready(function(){
21 doh.robot.initRobot('../test_focusWidget.html?animate=false');
22
23 // These are objects used to track calls to _onFocus and _onBlur in various widgets
24 function resetEvents(){
25 focusEvents = {};
26 blurEvents = {};
27 focusedState = {};
28 focusedWatchLog = {};
29 }
30 resetEvents();
31
32 doh.register("Dijit focus manager tests", [
33
34 function setUp(){
35 dojo.forEach(["form", "fieldset1", "fieldset2", "select", "spinner"], function(id){
36 var w = dijit.byId(id);
37
38 // old API is to connect to onFocus/onBlur (remove in 2.0)
39 dojo.connect(w, "onFocus", function(){
40 focusEvents[id] = true;
41 });
42 dojo.connect(w, "onBlur", function(){
43 blurEvents[id] = true;
44 });
45
46 // new API is to watch "focused" attribute
47 w.watch("focused", function(name, oldValue, newValue){
48 // keep track of current state
49 focusedState[name] = newValue;
50
51 // keep log of every watch notification
52 var nvs = newValue ? "focused" : "blurred";
53 focusedWatchLog[w.id] = !focusedWatchLog[w.id] ? nvs : focusedWatchLog[w.id] + ", " + nvs;
54 });
55 });
56 },
57
58 {
59 name: "focus simple input",
60 timeout: 4000,
61 setUp: function(){
62 resetEvents();
63 },
64 runTest: function(){
65 var d = new doh.Deferred();
66
67 // Focus the simple input
68 //dojo.byId("first").focus();
69 doh.robot.mouseMoveAt("first");
70 doh.robot.mouseClick({left: true}, 500);
71
72 doh.robot.sequence(d.getTestCallback(function(){
73 // Make sure that focus manager caught the focus event
74 doh.is(dojo.byId("first"), dojo.global.dijit.focus.curNode);
75
76 // And that the dijit.form.Form widget is marked as
77 // being "in focus"
78 doh.t(focusEvents["form"], "form focused");
79
80 // And that it got one watch event
81 doh.is("focused", focusedWatchLog["form"], "watch callback");
82 }), 500);
83
84 return d;
85 }
86 },
87 {
88 name: "focus combobox",
89 timeout: 4000,
90 setUp: function(){
91 resetEvents();
92 },
93 runTest: function(){
94 var d = new doh.Deferred();
95 handle = dojo.connect(dijit.byId("select").focusNode, "onfocus", d.getTestCallback(function(){
96 // Focus goes to an <input> node deep inside of select.domNode,
97 // but that <input> node has the id of the widget
98 doh.is(dojo.byId("select"), dojo.global.dijit.focus.curNode);
99
100 // The focus stack should show the ComboBox plus all parent widgets
101 var stack = dojo.global.dijit._activeStack;
102 doh.is("form, fieldset1, select", stack.join(", "), "combobox stack");
103
104 // _onFocus()/_onBlur was called appropriately
105 doh.f(focusEvents["form"], "form was already focused, no duplicate event");
106 doh.f(blurEvents["form"], "form wasn't blurred");
107 doh.t(focusEvents["fieldset1"], "fieldset1 focused");
108 doh.t(focusEvents["select"], "select focused");
109
110 doh.f(focusedWatchLog["form"], "form watch callback (no new notification)");
111 doh.is("focused", focusedWatchLog["fieldset1"], "fieldset watch callback");
112 doh.is("focused", focusedWatchLog["select"], "select watch callback");
113 }));
114 dijit.byId("select").focus();
115
116 return d;
117 },
118 tearDown: function(){
119 dojo.disconnect(handle);
120 }
121 },
122
123 // clicking spinner buttons should activate the spinner, even
124 // though there's no actual DOM focus event
125 {
126 name: "spinner",
127 timeout: 8000,
128 runTest: function(){
129 var d = new doh.Deferred();
130
131 var upArrow = dojo.query(".dijitSpinner .dijitUpArrowButton")[0];
132 doh.t(upArrow, "found the up arrow");
133
134 doh.robot.mouseMoveAt(upArrow, 500);
135 doh.robot.mouseClick({left: true}, 500);
136
137 doh.robot.sequence(d.getTestCallback(function(){
138 // The focus stack should show the Spinner plus all parent widgets
139 var stack = dojo.global.dijit._activeStack;
140 doh.is("form, fieldset2, spinner", stack.join(", "), "spinner stack");
141
142 // check watch callbacks
143 doh.f(focusedWatchLog["form"], "grandparent of spinner stayed focused, so no new watch event (watch)");
144 doh.is("focused", focusedWatchLog["fieldset2"], "parent of spinner (watch)");
145 doh.is("focused", focusedWatchLog["spinner"], "spinner (watch)");
146 }), 1000);
147
148 return d;
149 }
150 }/*,
151 // FIXME: this test is invalid because focus is not designed to change on mouse click to the first item in the menu
152 {
153 name: "combo button menu",
154 timeout: 4000,
155 runTest: function(){
156 var d = new doh.Deferred();
157
158 var button = dijit.byId('button').focusNode;
159 doh.t(button, "found drop down button");
160
161 doh.robot.mouseMoveAt(button);
162 doh.robot.mouseClick({left: true}, 500);
163
164 doh.robot.sequence(d.getTestCallback(function(){
165 // Focus goes to an first item in the drop down menu
166 doh.is(dojo.byId("mi1").id, dojo.global.dijit.focus.curNode.id);
167
168 // The focus stack should show the ComboBox plus all parent widgets
169 var stack = dojo.global.dijit._activeStack;
170 console.log("menu stack is ", stack);
171 doh.is("form, fieldset2, button, menu, mi1", stack.join(", "), "menuitem stack");
172 }), 500);
173
174 return d;
175 },
176 tearDown: function(){
177 dojo.disconnect(handle);
178 }
179 }*/
180
181 /*
182 // Commented out because
183 // in order to allow dijit.popup's getTopPopup() to work,a sub menu's popupParent
184 // points to the parent Menu, bypassing the parent MenuItem... thus the
185 // MenuItem is not in the chain of active widgets
186 {
187 name: "nested menu",
188 timeout: 4000,
189 runTest: function(){
190 var d = new doh.Deferred();
191
192 doh.robot.mouseMoveAt("popupMenuItem");
193
194 doh.robot.sequence(d.getTestCallback(function(){
195 // Focus goes to an first item in the sub menu
196 doh.is(dojo.byId("smi1"), dojo.global.dijit.focus.curNode);
197
198 // The focus stack should show the two submenus and then upwards
199 // to the ComboButton, and the rest
200 var stack = dojo.global.dijit._activeStack;
201 console.log("menu stack is ", stack);
202 doh.is("form, fieldset2, button, menu, mi1, submenu, smi1", stack.join(", "),
203 "submenuitem stack");
204 }), 1000);
205
206 return d;
207 }
208 }
209 */
210 ]);
211
212 doh.run();
213 });
214 </script>
215 </head>
216 </html>