Debian Codegraph @

dijit/tests/editor/robot/Editor_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 <html>
4 <head>
5 <title>robot Editor Mouse Test</title>
6
7 <style>
8 @import "../../../../util/doh/robot/robot.css";
9 </style>
10
11 <script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="async: true"></script>
12
13 <script type="text/javascript">
14 require([
15 "doh/runner", "dojo/robotx",
16 "dojo/dom-class", "dojo/keys", "dojo/query", "dojo/sniff",
17 "dijit/tests/helpers", "dojo/domReady!"
18 ], function(doh, robot, domClass, keys, query, has, helpers){
19
20 function normalize(str){
21 // try to do some normalization to make all browsers look
22 // the same. Would be nice if we didn't need this, the normalization should
23 // probably happen as pre and post filters on the editor
24 return str.
25 replace(/\s*\/>/g, "/>").
26 replace(/<br\/>$/, ''). // FF. Because of EnterKeyHandling plugin?
27 replace(/^<p>/, '').replace(/<\/p>$/, ''). // Safari. Because of EnterKeyHandling plugin?
28 replace(new RegExp(String.fromCharCode(160), "g"), " "); // Safari: nbsp (char code 160) to normal space (char code 32)
29 }
30
31 robot.initRobot('../test_Editor.html');
32
33 // For some reason the meta key (meta-a for selection, meta-b for bold, etc) isn't working
34 // on mac... use ctrl- instead, just like on windows. (#9553)
35 var metaKey = {ctrl: true};
36
37 var editor0, editor1;
38
39 doh.register("setup", [
40 {
41 name: "wait for editors to load",
42 timeout: 5000,
43 runTest: helpers.waitForLoad
44 },
45 function setVars(){
46 registry = robot.window.require("dijit/registry");
47 editor0 = registry.byId("editor0");
48 doh.t(!!editor0, "editor0");
49 editor1 = registry.byId("editor1");
50 doh.t(!!editor1, "editor1");
51 }
52 ]);
53
54 doh.register("toolbar buttons", [
55 {
56 name: "bold/italic",
57 timeout: 20000,
58 runTest: function(){
59 var d = new doh.Deferred();
60
61 var toolbar = editor1.toolbar,
62 boldButton = toolbar.getChildren()[7],
63 italicButton = toolbar.getChildren()[8];
64
65 // Focus the editor
66 robot.mouseMoveAt(editor1.editNode, 500, 1);
67 robot.mouseClick({left: true}, 500);
68
69 // select all and erase, by typing something new
70 robot.keyPress("a", 500, metaKey);
71 robot.typeKeys("hello ", 1000, 1000);
72
73 // turn on bold
74 robot.mouseMoveAt(boldButton.domNode, 500, 1);
75 robot.mouseClick({left: true}, 500);
76
77 robot.typeKeys("world", 1000, 1000);
78
79 // turn off bold
80 robot.mouseMoveAt(boldButton.domNode, 500, 1);
81 robot.mouseClick({left: true}, 500);
82
83 robot.typeKeys(". ", 1000, 400);
84
85 // turn on italic
86 robot.mouseMoveAt(italicButton.domNode, 500, 1);
87 robot.mouseClick({left: true}, 500);
88
89 robot.typeKeys("how are you", 1000, 2000);
90
91 // turn off italic
92 robot.mouseMoveAt(italicButton.domNode, 500, 1);
93 robot.mouseClick({left: true}, 500);
94
95 robot.typeKeys("?", 1000, 200);
96
97 robot.sequence(d.getTestCallback(function(){
98 // Get the value and try to do some normalization to make all browsers look
99 // the same. Would be nice if we didn't need this, the normalization should
100 // probably happen as pre and post filters on the editor
101 var val = normalize(editor1.get("value"));
102 doh.is("hello <b>world</b>. <i>how are you</i>?", val);
103 }), 1000);
104
105 return d;
106 }
107 },
108 {
109 name: "delete bold tag",
110 timeout: 5000,
111 runTest: function(){
112 var d = new doh.Deferred();
113
114 // Find the bolded "world" word in the editor
115 var bold = query('b', editor1.editNode);
116 if(!bold.length){
117 bold = query('strong', editor1.editNode)
118 }
119
120 // Double-click "world" to select it
121 robot.mouseMoveAt(bold[0], 500, 1, 5, 5);
122 robot.mouseClick({left: true}, 500);
123 robot.mouseClick({left: true}, 50);
124
125 // Delete "world" and the space before it
126 robot.keyPress(keys.DELETE, 500);
127 if(!has("safari") && !(has("chrome") && has("mac"))){
128 // they delete the space too?
129 robot.keyPress(keys.BACKSPACE, 500);
130 }
131
132 robot.sequence(d.getTestCallback(function(){
133 doh.is("hello. <i>how are you</i>?", normalize(editor1.get("value")));
134 }), 500);
135
136 return d;
137 }
138 }
139 ]);
140
141 doh.register("selection", [
142 {
143 name: "mouseup but no click event",
144 timeout: 10000,
145 runTest: function(){
146 var cutButton = editor1.toolbar.getChildren()[3].domNode;
147 doh.t(domClass.contains(cutButton, "dijitButtonDisabled"), "Cut should be disabled " + cutButton.className);
148
149 var d = new doh.Deferred();
150
151 robot.mouseMoveAt(editor1.editNode, 500, 1);
152 robot.mousePress({left: true}, 500);
153 robot.mouseMoveAt(editor1.editNode, 500, 500, -10, 0); // move off of editNode
154 robot.mouseRelease({left: true}, 500);
155 robot.sequence(d.getTestCallback(function(){
156 doh.f(domClass.contains(cutButton, "dijitButtonDisabled"), "Cut should not be disabled " + cutButton.className);
157 }), 1000);
158
159 return d;
160 }
161 }
162 ]);
163
164 doh.run();
165 });
166
167
168 </script>
169 </head>
170 </html>