1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,185 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Profiling test suite for EventUtils</title> 1.8 + <script type="text/javascript"> 1.9 + var start = new Date(); 1.10 + </script> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.12 + <script type="text/javascript"> 1.13 + var loadTime = new Date(); 1.14 + </script> 1.15 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.16 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.17 +</head> 1.18 +<body onload="starttest()"> 1.19 +<input type="radio" id="radioTarget1" name="group">Radio Target 1</input> 1.20 +<input id="textBoxA"> 1.21 +<input id="textBoxB"> 1.22 +<input id="testMouseEvent" type="button" value="click"> 1.23 +<input id="testKeyEvent" > 1.24 +<input id="testStrEvent" > 1.25 +<div id="scrollB" style="width: 190px;height: 250px;overflow:auto"> 1.26 +<p>blah blah blah blah</p> 1.27 +<p>blah blah blah blah</p> 1.28 +<p>blah blah blah blah</p> 1.29 +<p>blah blah blah blah</p> 1.30 +<p>blah blah blah blah</p> 1.31 +<p>blah blah blah blah</p> 1.32 +<p>blah blah blah blah</p> 1.33 +<p>blah blah blah blah</p> 1.34 +</div> 1.35 +<script class="testbody" type="text/javascript"> 1.36 +info("\nProfile::EventUtilsLoadTime: " + (loadTime - start) + "\n"); 1.37 +function starttest() { 1.38 + SimpleTest.waitForFocus( 1.39 + function () { 1.40 + SimpleTest.waitForExplicitFinish(); 1.41 + var startTime = new Date(); 1.42 + var check = false; 1.43 + 1.44 + /* test send* functions */ 1.45 + $("testMouseEvent").addEventListener("click", function() { check=true; }, false); 1.46 + sendMouseEvent({type:'click'}, "testMouseEvent"); 1.47 + is(check, true, 'sendMouseEvent should dispatch click event'); 1.48 + 1.49 + check = false; 1.50 + $("testKeyEvent").addEventListener("keypress", function() { check = true; }, false); 1.51 + $("testKeyEvent").focus(); 1.52 + sendChar("x"); 1.53 + is($("testKeyEvent").value, "x", "sendChar should work"); 1.54 + is(check, true, "sendChar should dispatch keyPress"); 1.55 + $("testKeyEvent").value = ""; 1.56 + 1.57 + $("testStrEvent").focus(); 1.58 + sendString("string"); 1.59 + is($("testStrEvent").value, "string", "sendString should work"); 1.60 + $("testStrEvent").value = ""; 1.61 + 1.62 + check = false; 1.63 + $("testKeyEvent").focus(); 1.64 + sendKey("DOWN"); 1.65 + is(check, true, "sendKey should dispatch keyPress"); 1.66 + 1.67 + /* test synthesizeMouse* */ 1.68 + //focus trick enables us to run this in iframes 1.69 + $("radioTarget1").addEventListener('focus', function (aEvent) { 1.70 + $("radioTarget1").removeEventListener('focus', arguments.callee, false); 1.71 + synthesizeMouse($("radioTarget1"), 1, 1, {}); 1.72 + is($("radioTarget1").checked, true, "synthesizeMouse should work") 1.73 + $("radioTarget1").checked = false; 1.74 + disableNonTestMouseEvents(true); 1.75 + synthesizeMouse($("radioTarget1"), 1, 1, {}); 1.76 + is($("radioTarget1").checked, true, "synthesizeMouse should still work with non-test mouse events disabled"); 1.77 + $("radioTarget1").checked = false; 1.78 + disableNonTestMouseEvents(false); 1.79 + }); 1.80 + $("radioTarget1").focus(); 1.81 + 1.82 + //focus trick enables us to run this in iframes 1.83 + $("textBoxA").addEventListener("focus", function (aEvent) { 1.84 + $("textBoxA").removeEventListener("focus", arguments.callee, false); 1.85 + check = false; 1.86 + $("textBoxA").addEventListener("click", function() { check = true; }, false); 1.87 + synthesizeMouseAtCenter($("textBoxA"), {}); 1.88 + is(check, true, 'synthesizeMouse should dispatch mouse event'); 1.89 + 1.90 + check = false; 1.91 + synthesizeMouseExpectEvent($("textBoxA"), 1, 1, {}, $("textBoxA"), "click", "synthesizeMouseExpectEvent should fire click event"); 1.92 + is(check, true, 'synthesizeMouse should dispatch mouse event'); 1.93 + }); 1.94 + $("textBoxA").focus(); 1.95 + 1.96 + /** 1.97 + * TODO: testing synthesizeWheel requires a setTimeout 1.98 + * since there is delay between the scroll event and a check, so for now just test 1.99 + * that we can successfully call it to avoid having setTimeout vary the runtime metric. 1.100 + * Testing of this method is currently done here: 1.101 + * toolkit/content/tests/chrome/test_mousescroll.xul 1.102 + */ 1.103 + synthesizeWheel($("scrollB"), 5, 5, {'deltaY': 10.0, deltaMode: WheelEvent.DOM_DELTA_LINE}); 1.104 + 1.105 + /* test synthesizeKey* */ 1.106 + check = false; 1.107 + $("testKeyEvent").addEventListener("keypress", function() { check = true; }, false); 1.108 + $("testKeyEvent").focus(); 1.109 + synthesizeKey("a", {}); 1.110 + is($("testKeyEvent").value, "a", "synthesizeKey should work"); 1.111 + is(check, true, "synthesizeKey should dispatch keyPress"); 1.112 + $("testKeyEvent").value = ""; 1.113 + 1.114 + check = false; 1.115 + synthesizeKeyExpectEvent("a", {}, $("testKeyEvent"), "keypress"); 1.116 + is($("testKeyEvent").value, "a", "synthesizeKey should work"); 1.117 + is(check, true, "synthesizeKey should dispatch keyPress"); 1.118 + $("testKeyEvent").value = ""; 1.119 + 1.120 + /* test synthesizeComposition */ 1.121 + $("textBoxB").focus(); 1.122 + check = false; 1.123 + window.addEventListener("compositionstart", function() { check = true; }, false); 1.124 + synthesizeComposition({ type: "compositionstart" }); 1.125 + is(check, true, 'synthesizeComposition() should dispatch compositionstart'); 1.126 + 1.127 + check = false; 1.128 + window.addEventListener("compositionupdate", function() { check = true; }, false); 1.129 + synthesizeComposition({ type: "compositionupdate", data: "a" }); 1.130 + is(check, true, 'synthesizeComposition() should dispatch compositionupdate'); 1.131 + 1.132 + check = false; 1.133 + window.addEventListener("text", function() { check = true; }, false); 1.134 + synthesizeText( 1.135 + { "composition": 1.136 + { "string": "a", 1.137 + "clauses": 1.138 + [ 1.139 + { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT } 1.140 + ] 1.141 + }, 1.142 + "caret": { "start": 1, "length": 0 } 1.143 + } 1.144 + ); 1.145 + is(check, true, "synthesizeText should dispatch text event"); 1.146 + 1.147 + synthesizeText( 1.148 + { "composition": 1.149 + { "string": "a", 1.150 + "clauses": 1.151 + [ 1.152 + { "length": 0, "attr": 0 } 1.153 + ] 1.154 + }, 1.155 + "caret": { "start": 1, "length": 0 } 1.156 + } 1.157 + ); 1.158 + 1.159 + check = false; 1.160 + window.addEventListener("compositionend", function() { check = true; }, false); 1.161 + synthesizeComposition({ type: "compositionend", data: "a" }); 1.162 + is(check, true, 'synthesizeComposition() should dispatch compositionend'); 1.163 + 1.164 + var querySelectedText = synthesizeQuerySelectedText(); 1.165 + ok(querySelectedText, "query selected text event result is null"); 1.166 + ok(querySelectedText.succeeded, "query selected text event failed"); 1.167 + is(querySelectedText.offset, 1, 1.168 + "query selected text event returns wrong offset"); 1.169 + is(querySelectedText.text, "", 1.170 + "query selected text event returns wrong selected text"); 1.171 + $("textBoxB").value = ""; 1.172 + 1.173 + querySelectedText = synthesizeQuerySelectedText(); 1.174 + ok(querySelectedText, "query selected text event result is null"); 1.175 + ok(querySelectedText.succeeded, "query selected text event failed"); 1.176 + is(querySelectedText.offset, 0, 1.177 + "query selected text event returns wrong offset"); 1.178 + is(querySelectedText.text, "", 1.179 + "query selected text event returns wrong selected text"); 1.180 + var endTime = new Date(); 1.181 + info("\nProfile::EventUtilsRunTime: " + (endTime-startTime) + "\n"); 1.182 + SimpleTest.finish(); 1.183 + } 1.184 + ); 1.185 +}; 1.186 +</script> 1.187 +</body> 1.188 +</html>