2011-09-19 22:52:06 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Profiling test suite for EventUtils</title>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var start = new Date();
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var loadTime = new Date();
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body onload="starttest()">
|
|
|
|
<input type="radio" id="radioTarget1" name="group">Radio Target 1</input>
|
|
|
|
<input id="textBoxA">
|
|
|
|
<input id="textBoxB">
|
|
|
|
<input id="testMouseEvent" type="button" value="click">
|
|
|
|
<input id="testKeyEvent" >
|
|
|
|
<input id="testStrEvent" >
|
|
|
|
<div id="scrollB" style="width: 190px;height: 250px;overflow:auto">
|
|
|
|
<p>blah blah blah blah</p>
|
|
|
|
<p>blah blah blah blah</p>
|
|
|
|
<p>blah blah blah blah</p>
|
|
|
|
<p>blah blah blah blah</p>
|
|
|
|
<p>blah blah blah blah</p>
|
|
|
|
<p>blah blah blah blah</p>
|
|
|
|
<p>blah blah blah blah</p>
|
|
|
|
<p>blah blah blah blah</p>
|
|
|
|
</div>
|
|
|
|
<script class="testbody" type="text/javascript">
|
2012-02-01 22:11:53 +04:00
|
|
|
info("\nProfile::EventUtilsLoadTime: " + (loadTime - start) + "\n");
|
2011-09-19 22:52:06 +04:00
|
|
|
function starttest() {
|
|
|
|
SimpleTest.waitForFocus(
|
|
|
|
function () {
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
var startTime = new Date();
|
|
|
|
var check = false;
|
|
|
|
|
|
|
|
/* test send* functions */
|
|
|
|
$("testMouseEvent").addEventListener("click", function() { check=true; }, false);
|
|
|
|
sendMouseEvent({type:'click'}, "testMouseEvent");
|
|
|
|
is(check, true, 'sendMouseEvent should dispatch click event');
|
|
|
|
|
|
|
|
check = false;
|
|
|
|
$("testKeyEvent").addEventListener("keypress", function() { check = true; }, false);
|
|
|
|
$("testKeyEvent").focus();
|
2011-12-16 17:38:45 +04:00
|
|
|
sendChar("x");
|
2011-09-19 22:52:06 +04:00
|
|
|
is($("testKeyEvent").value, "x", "sendChar should work");
|
|
|
|
is(check, true, "sendChar should dispatch keyPress");
|
|
|
|
$("testKeyEvent").value = "";
|
|
|
|
|
2011-12-16 17:38:45 +04:00
|
|
|
$("testStrEvent").focus();
|
|
|
|
sendString("string");
|
2011-09-19 22:52:06 +04:00
|
|
|
is($("testStrEvent").value, "string", "sendString should work");
|
|
|
|
$("testStrEvent").value = "";
|
|
|
|
|
|
|
|
check = false;
|
2011-12-16 17:38:45 +04:00
|
|
|
$("testKeyEvent").focus();
|
|
|
|
sendKey("DOWN");
|
2011-09-19 22:52:06 +04:00
|
|
|
is(check, true, "sendKey should dispatch keyPress");
|
|
|
|
|
|
|
|
/* test synthesizeMouse* */
|
|
|
|
//focus trick enables us to run this in iframes
|
|
|
|
$("radioTarget1").addEventListener('focus', function (aEvent) {
|
|
|
|
$("radioTarget1").removeEventListener('focus', arguments.callee, false);
|
|
|
|
synthesizeMouse($("radioTarget1"), 1, 1, {});
|
|
|
|
is($("radioTarget1").checked, true, "synthesizeMouse should work")
|
|
|
|
$("radioTarget1").checked = false;
|
|
|
|
disableNonTestMouseEvents(true);
|
|
|
|
synthesizeMouse($("radioTarget1"), 1, 1, {});
|
|
|
|
is($("radioTarget1").checked, true, "synthesizeMouse should still work with non-test mouse events disabled");
|
|
|
|
$("radioTarget1").checked = false;
|
|
|
|
disableNonTestMouseEvents(false);
|
|
|
|
});
|
|
|
|
$("radioTarget1").focus();
|
|
|
|
|
|
|
|
//focus trick enables us to run this in iframes
|
|
|
|
$("textBoxA").addEventListener("focus", function (aEvent) {
|
|
|
|
$("textBoxA").removeEventListener("focus", arguments.callee, false);
|
|
|
|
check = false;
|
|
|
|
$("textBoxA").addEventListener("click", function() { check = true; }, false);
|
|
|
|
synthesizeMouseAtCenter($("textBoxA"), {});
|
|
|
|
is(check, true, 'synthesizeMouse should dispatch mouse event');
|
|
|
|
|
|
|
|
check = false;
|
|
|
|
synthesizeMouseExpectEvent($("textBoxA"), 1, 1, {}, $("textBoxA"), "click", "synthesizeMouseExpectEvent should fire click event");
|
|
|
|
is(check, true, 'synthesizeMouse should dispatch mouse event');
|
|
|
|
});
|
|
|
|
$("textBoxA").focus();
|
|
|
|
|
|
|
|
/**
|
2012-08-12 05:42:36 +04:00
|
|
|
* TODO: testing synthesizeWheel requires a setTimeout
|
2011-09-19 22:52:06 +04:00
|
|
|
* since there is delay between the scroll event and a check, so for now just test
|
|
|
|
* that we can successfully call it to avoid having setTimeout vary the runtime metric.
|
|
|
|
* Testing of this method is currently done here:
|
|
|
|
* toolkit/content/tests/chrome/test_mousescroll.xul
|
|
|
|
*/
|
2012-08-12 05:42:36 +04:00
|
|
|
synthesizeWheel($("scrollB"), 5, 5, {'deltaY': 10.0, deltaMode: WheelEvent.DOM_DELTA_LINE});
|
2011-09-19 22:52:06 +04:00
|
|
|
|
|
|
|
/* test synthesizeKey* */
|
|
|
|
check = false;
|
|
|
|
$("testKeyEvent").addEventListener("keypress", function() { check = true; }, false);
|
|
|
|
$("testKeyEvent").focus();
|
|
|
|
synthesizeKey("a", {});
|
|
|
|
is($("testKeyEvent").value, "a", "synthesizeKey should work");
|
|
|
|
is(check, true, "synthesizeKey should dispatch keyPress");
|
|
|
|
$("testKeyEvent").value = "";
|
|
|
|
|
|
|
|
check = false;
|
|
|
|
synthesizeKeyExpectEvent("a", {}, $("testKeyEvent"), "keypress");
|
|
|
|
is($("testKeyEvent").value, "a", "synthesizeKey should work");
|
|
|
|
is(check, true, "synthesizeKey should dispatch keyPress");
|
|
|
|
$("testKeyEvent").value = "";
|
|
|
|
|
|
|
|
/* test synthesizeComposition */
|
|
|
|
check = false;
|
|
|
|
window.addEventListener("compositionstart", function() { check = true; }, false);
|
2011-09-22 13:17:41 +04:00
|
|
|
synthesizeComposition({ type: "compositionstart" });
|
|
|
|
is(check, true, 'synthesizeComposition() should dispatch compositionstart');
|
|
|
|
|
|
|
|
check = false;
|
|
|
|
window.addEventListener("compositionupdate", function() { check = true; }, false);
|
|
|
|
synthesizeComposition({ type: "compositionupdate" });
|
|
|
|
is(check, true, 'synthesizeComposition() should dispatch compositionupdate');
|
2011-09-19 22:52:06 +04:00
|
|
|
|
|
|
|
check = false;
|
|
|
|
window.addEventListener("compositionend", function() { check = true; }, false);
|
2011-09-22 13:17:41 +04:00
|
|
|
synthesizeComposition({ type: "compositionend" });
|
2011-09-19 22:52:06 +04:00
|
|
|
is(check, true, 'synthesizeComposition() should dispatch compositionend');
|
|
|
|
check = false;
|
|
|
|
|
|
|
|
$("textBoxB").focus();
|
2012-09-24 16:46:28 +04:00
|
|
|
const nsIDOMWindowUtils = SpecialPowers.Ci.nsIDOMWindowUtils;
|
2011-09-19 22:52:06 +04:00
|
|
|
synthesizeText(
|
|
|
|
{ "composition":
|
|
|
|
{ "string": "a",
|
|
|
|
"clauses":
|
|
|
|
[
|
|
|
|
{ "length": 1, "attr": nsIDOMWindowUtils.COMPOSITION_ATTR_RAWINPUT }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"caret": { "start": 1, "length": 0 }
|
|
|
|
}
|
|
|
|
);
|
|
|
|
is(check, false, "synthesizeText shouldn't start or end composition");
|
|
|
|
is($("textBoxB").value, "a", "synthesizeText should send text");
|
|
|
|
var querySelectedText = synthesizeQuerySelectedText();
|
|
|
|
ok(querySelectedText, "query selected text event result is null");
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); //get permission to check members of querySelectedText
|
|
|
|
ok(querySelectedText.succeeded, "query selected text event failed");
|
|
|
|
is(querySelectedText.offset, 1,
|
|
|
|
"query selected text event returns wrong offset");
|
|
|
|
is(querySelectedText.text, "",
|
|
|
|
"query selected text event returns wrong selected text");
|
|
|
|
$("textBoxB").value = "";
|
|
|
|
|
|
|
|
querySelectedText = synthesizeQuerySelectedText();
|
|
|
|
ok(querySelectedText, "query selected text event result is null");
|
|
|
|
ok(querySelectedText.succeeded, "query selected text event failed");
|
|
|
|
is(querySelectedText.offset, 0,
|
|
|
|
"query selected text event returns wrong offset");
|
|
|
|
is(querySelectedText.text, "",
|
|
|
|
"query selected text event returns wrong selected text");
|
|
|
|
var endTime = new Date();
|
2012-02-01 22:11:53 +04:00
|
|
|
info("\nProfile::EventUtilsRunTime: " + (endTime-startTime) + "\n");
|
2011-09-19 22:52:06 +04:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|