testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial