Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Profiling test suite for EventUtils</title>
5 <script type="text/javascript">
6 var start = new Date();
7 </script>
8 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
9 <script type="text/javascript">
10 var loadTime = new Date();
11 </script>
12 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
13 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
14 </head>
15 <body onload="starttest()">
16 <input type="radio" id="radioTarget1" name="group">Radio Target 1</input>
17 <input id="textBoxA">
18 <input id="textBoxB">
19 <input id="testMouseEvent" type="button" value="click">
20 <input id="testKeyEvent" >
21 <input id="testStrEvent" >
22 <div id="scrollB" style="width: 190px;height: 250px;overflow:auto">
23 <p>blah blah blah blah</p>
24 <p>blah blah blah blah</p>
25 <p>blah blah blah blah</p>
26 <p>blah blah blah blah</p>
27 <p>blah blah blah blah</p>
28 <p>blah blah blah blah</p>
29 <p>blah blah blah blah</p>
30 <p>blah blah blah blah</p>
31 </div>
32 <script class="testbody" type="text/javascript">
33 info("\nProfile::EventUtilsLoadTime: " + (loadTime - start) + "\n");
34 function starttest() {
35 SimpleTest.waitForFocus(
36 function () {
37 SimpleTest.waitForExplicitFinish();
38 var startTime = new Date();
39 var check = false;
41 /* test send* functions */
42 $("testMouseEvent").addEventListener("click", function() { check=true; }, false);
43 sendMouseEvent({type:'click'}, "testMouseEvent");
44 is(check, true, 'sendMouseEvent should dispatch click event');
46 check = false;
47 $("testKeyEvent").addEventListener("keypress", function() { check = true; }, false);
48 $("testKeyEvent").focus();
49 sendChar("x");
50 is($("testKeyEvent").value, "x", "sendChar should work");
51 is(check, true, "sendChar should dispatch keyPress");
52 $("testKeyEvent").value = "";
54 $("testStrEvent").focus();
55 sendString("string");
56 is($("testStrEvent").value, "string", "sendString should work");
57 $("testStrEvent").value = "";
59 check = false;
60 $("testKeyEvent").focus();
61 sendKey("DOWN");
62 is(check, true, "sendKey should dispatch keyPress");
64 /* test synthesizeMouse* */
65 //focus trick enables us to run this in iframes
66 $("radioTarget1").addEventListener('focus', function (aEvent) {
67 $("radioTarget1").removeEventListener('focus', arguments.callee, false);
68 synthesizeMouse($("radioTarget1"), 1, 1, {});
69 is($("radioTarget1").checked, true, "synthesizeMouse should work")
70 $("radioTarget1").checked = false;
71 disableNonTestMouseEvents(true);
72 synthesizeMouse($("radioTarget1"), 1, 1, {});
73 is($("radioTarget1").checked, true, "synthesizeMouse should still work with non-test mouse events disabled");
74 $("radioTarget1").checked = false;
75 disableNonTestMouseEvents(false);
76 });
77 $("radioTarget1").focus();
79 //focus trick enables us to run this in iframes
80 $("textBoxA").addEventListener("focus", function (aEvent) {
81 $("textBoxA").removeEventListener("focus", arguments.callee, false);
82 check = false;
83 $("textBoxA").addEventListener("click", function() { check = true; }, false);
84 synthesizeMouseAtCenter($("textBoxA"), {});
85 is(check, true, 'synthesizeMouse should dispatch mouse event');
87 check = false;
88 synthesizeMouseExpectEvent($("textBoxA"), 1, 1, {}, $("textBoxA"), "click", "synthesizeMouseExpectEvent should fire click event");
89 is(check, true, 'synthesizeMouse should dispatch mouse event');
90 });
91 $("textBoxA").focus();
93 /**
94 * TODO: testing synthesizeWheel requires a setTimeout
95 * since there is delay between the scroll event and a check, so for now just test
96 * that we can successfully call it to avoid having setTimeout vary the runtime metric.
97 * Testing of this method is currently done here:
98 * toolkit/content/tests/chrome/test_mousescroll.xul
99 */
100 synthesizeWheel($("scrollB"), 5, 5, {'deltaY': 10.0, deltaMode: WheelEvent.DOM_DELTA_LINE});
102 /* test synthesizeKey* */
103 check = false;
104 $("testKeyEvent").addEventListener("keypress", function() { check = true; }, false);
105 $("testKeyEvent").focus();
106 synthesizeKey("a", {});
107 is($("testKeyEvent").value, "a", "synthesizeKey should work");
108 is(check, true, "synthesizeKey should dispatch keyPress");
109 $("testKeyEvent").value = "";
111 check = false;
112 synthesizeKeyExpectEvent("a", {}, $("testKeyEvent"), "keypress");
113 is($("testKeyEvent").value, "a", "synthesizeKey should work");
114 is(check, true, "synthesizeKey should dispatch keyPress");
115 $("testKeyEvent").value = "";
117 /* test synthesizeComposition */
118 $("textBoxB").focus();
119 check = false;
120 window.addEventListener("compositionstart", function() { check = true; }, false);
121 synthesizeComposition({ type: "compositionstart" });
122 is(check, true, 'synthesizeComposition() should dispatch compositionstart');
124 check = false;
125 window.addEventListener("compositionupdate", function() { check = true; }, false);
126 synthesizeComposition({ type: "compositionupdate", data: "a" });
127 is(check, true, 'synthesizeComposition() should dispatch compositionupdate');
129 check = false;
130 window.addEventListener("text", function() { check = true; }, false);
131 synthesizeText(
132 { "composition":
133 { "string": "a",
134 "clauses":
135 [
136 { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
137 ]
138 },
139 "caret": { "start": 1, "length": 0 }
140 }
141 );
142 is(check, true, "synthesizeText should dispatch text event");
144 synthesizeText(
145 { "composition":
146 { "string": "a",
147 "clauses":
148 [
149 { "length": 0, "attr": 0 }
150 ]
151 },
152 "caret": { "start": 1, "length": 0 }
153 }
154 );
156 check = false;
157 window.addEventListener("compositionend", function() { check = true; }, false);
158 synthesizeComposition({ type: "compositionend", data: "a" });
159 is(check, true, 'synthesizeComposition() should dispatch compositionend');
161 var querySelectedText = synthesizeQuerySelectedText();
162 ok(querySelectedText, "query selected text event result is null");
163 ok(querySelectedText.succeeded, "query selected text event failed");
164 is(querySelectedText.offset, 1,
165 "query selected text event returns wrong offset");
166 is(querySelectedText.text, "",
167 "query selected text event returns wrong selected text");
168 $("textBoxB").value = "";
170 querySelectedText = synthesizeQuerySelectedText();
171 ok(querySelectedText, "query selected text event result is null");
172 ok(querySelectedText.succeeded, "query selected text event failed");
173 is(querySelectedText.offset, 0,
174 "query selected text event returns wrong offset");
175 is(querySelectedText.text, "",
176 "query selected text event returns wrong selected text");
177 var endTime = new Date();
178 info("\nProfile::EventUtilsRunTime: " + (endTime-startTime) + "\n");
179 SimpleTest.finish();
180 }
181 );
182 };
183 </script>
184 </body>
185 </html>