2013-08-30 06:10:32 +04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Testing ns*Event::Assign*EventData()</title>
|
|
|
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
|
|
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
|
|
|
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="display">
|
|
|
|
<input id="input-text">
|
|
|
|
<button id="button">button</button>
|
2013-09-03 15:45:28 +04:00
|
|
|
<div id="scrollable-div" style="overflow: auto; width: 30px; height: 30px;"><div id="scrolled-div" style="width: 10px; height: 10px;"></div></div>
|
2013-08-30 06:10:32 +04:00
|
|
|
</div>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<script class="testbody" type="application/javascript">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
var gUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
|
|
|
|
const kIsMac = (navigator.platform.indexOf("Mac") == 0);
|
|
|
|
const kIsWin = (navigator.platform.indexOf("Win") == 0);
|
|
|
|
|
|
|
|
var gEvent = null;
|
|
|
|
var gCopiedEvent = [];
|
2013-09-03 15:45:28 +04:00
|
|
|
var gCallback = null;
|
2013-08-30 06:10:32 +04:00
|
|
|
|
|
|
|
function onEvent(aEvent)
|
|
|
|
{
|
|
|
|
gEvent = aEvent;
|
|
|
|
for (var attr in aEvent) {
|
|
|
|
if (!attr.match(/^[A-Z0-9_]+$/) && // ignore const attributes
|
|
|
|
attr != "multipleActionsPrevented" && // multipleActionsPrevented isn't defined in any DOM event specs.
|
|
|
|
typeof(aEvent[attr]) != "function") {
|
|
|
|
gCopiedEvent.push({ name: attr, value: aEvent[attr]});
|
|
|
|
}
|
|
|
|
}
|
2013-09-03 15:45:28 +04:00
|
|
|
setTimeout(gCallback, 0);
|
2013-08-30 06:10:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const WIN_KL_US = 0x409;
|
|
|
|
const MAC_KL_US = 0;
|
|
|
|
|
|
|
|
const NATIVE_SHIFT_LEFT = 0x0100;
|
|
|
|
const NATIVE_CONTROL_RIGHT = 0x0800;
|
|
|
|
const NATIVE_META_RIGHT = 0x8000;
|
|
|
|
|
|
|
|
const kTests = [
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsScriptErrorEvent",
|
|
|
|
targetID: "input-text", eventType: "error",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
todo(false, "nsScriptErrorEvent isn't tested");
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsScrollPortEvent (overflow, vertical)",
|
|
|
|
targetID: "scrollable-div", eventType: "overflow",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById("scrolled-div").style.height = "500px";
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
|
|
|
},
|
|
|
|
{ description: "nsScrollPortEvent (overflow, horizontal)",
|
|
|
|
targetID: "scrollable-div", eventType: "overflow",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById("scrolled-div").style.width = "500px";
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsScrollAreaEvent (MozScrolledAreaChanged, spreading)",
|
|
|
|
target: function () { return document; }, eventType: "MozScrolledAreaChanged",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById("scrollable-div").style.width = "50000px";
|
|
|
|
document.getElementById("scrollable-div").style.height = "50000px";
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
|
|
|
},
|
|
|
|
{ description: "nsScrollAreaEvent (MozScrolledAreaChanged, shrinking)",
|
|
|
|
target: function () { return document; }, eventType: "MozScrolledAreaChanged",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById("scrollable-div").style.width = "30px";
|
|
|
|
document.getElementById("scrollable-div").style.height = "30px";
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsKeyEvent (keydown of 'a' key without modifiers)",
|
|
|
|
targetID: "input-text", eventType: "keydown",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
document.getElementById(this.targetID).focus();
|
|
|
|
if (kIsWin) {
|
|
|
|
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_A, 0, "a", "a");
|
|
|
|
} else if (kIsMac) {
|
|
|
|
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_A, 0, "a", "a");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return (kIsMac || kIsWin);
|
|
|
|
},
|
|
|
|
todoMismatch: [ "key" ],
|
2013-08-30 06:10:32 +04:00
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsKeyEvent (keyup of 'a' key without modifiers)",
|
|
|
|
targetID: "input-text", eventType: "keydown",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
document.getElementById(this.targetID).focus();
|
|
|
|
if (kIsWin) {
|
|
|
|
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_A, 0, "a", "a");
|
|
|
|
} else if (kIsMac) {
|
|
|
|
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_A, 0, "a", "a");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return (kIsMac || kIsWin);
|
|
|
|
},
|
|
|
|
todoMismatch: [ "key" ],
|
2013-08-30 06:10:32 +04:00
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsKeyEvent (keypress of 'b' key with Shift)",
|
|
|
|
targetID: "input-text", eventType: "keypress",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
document.getElementById(this.targetID).focus();
|
|
|
|
if (kIsWin) {
|
|
|
|
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_B, NATIVE_SHIFT_LEFT, "B", "B");
|
|
|
|
} else if (kIsMac) {
|
|
|
|
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_B, NATIVE_SHIFT_LEFT, "B", "B");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return (kIsMac || kIsWin);
|
|
|
|
},
|
|
|
|
// "defaultPrevented" becomes true because the editor consumes the keypress event.
|
|
|
|
todoMismatch: [ "key", "defaultPrevented" ],
|
2013-08-30 06:10:32 +04:00
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsKeyEvent (keypress of 'c' key with Accel)",
|
|
|
|
targetID: "input-text", eventType: "keypress",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
document.getElementById(this.targetID).focus();
|
|
|
|
if (kIsWin) {
|
|
|
|
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_C, NATIVE_CONTROL_RIGHT, "\u0003", "c");
|
|
|
|
} else if (kIsMac) {
|
|
|
|
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_C, NATIVE_META_RIGHT, "c", "c");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return (kIsMac || kIsWin);
|
|
|
|
},
|
|
|
|
// "defaultPrevented" becomes true because the editor consumes the keypress event.
|
|
|
|
todoMismatch: [ "key", "defaultPrevented" ],
|
2013-08-30 06:10:32 +04:00
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsMouseEvent (mousedown of left button without modifier)",
|
|
|
|
targetID: "button", eventType: "mousedown",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
synthesizeMouseAtCenter(document.getElementById(this.targetID),
|
|
|
|
{ button: 0 });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
2013-08-30 06:10:32 +04:00
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsMouseEvent (click of middle button with Shift)",
|
|
|
|
// XXX I'm not sure why middle click event isn't fired on button element.
|
|
|
|
targetID: "input-text", eventType: "click",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
synthesizeMouseAtCenter(document.getElementById(this.targetID),
|
|
|
|
{ button: 1, shiftKey: true, pressure: 0.5 });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
2013-08-30 06:10:32 +04:00
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsMouseEvent (mouseup of right button with Alt)",
|
|
|
|
targetID: "button", eventType: "mouseup",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
synthesizeMouseAtCenter(document.getElementById(this.targetID),
|
|
|
|
{ button: 2, altKey: true });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
2013-08-30 06:10:32 +04:00
|
|
|
},
|
2013-09-03 15:45:28 +04:00
|
|
|
{ description: "nsDragEvent",
|
|
|
|
targetID: "input-text", eventType: "dragstart",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
todo(false, "nsDragEvent isn't tested");
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
todoMismatch: [],
|
|
|
|
},
|
2013-09-03 15:45:29 +04:00
|
|
|
{ description: "nsTextEvent (text)",
|
|
|
|
targetID: "input-text", eventType: "text",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
document.getElementById(this.targetID).focus();
|
|
|
|
synthesizeComposition({ type: "compositionstart" });
|
|
|
|
synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
|
|
|
|
synthesizeText({ "composition":
|
|
|
|
{ "string": "\u306D",
|
|
|
|
"clauses":
|
|
|
|
[
|
|
|
|
{ "length": 0, "attr": 0 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"caret": { "start": 1, "length": 0 }
|
|
|
|
});
|
|
|
|
synthesizeComposition({ type: "compositionend", data: "\u732B" });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [ ],
|
|
|
|
},
|
2013-09-03 15:45:29 +04:00
|
|
|
{ description: "nsCompositionEvent (compositionupdate)",
|
|
|
|
targetID: "input-text", eventType: "compositionupdate",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
document.getElementById(this.targetID).focus();
|
|
|
|
synthesizeComposition({ type: "compositionstart" });
|
|
|
|
synthesizeComposition({ type: "compositionupdate", data: "\u30E9\u30FC\u30E1\u30F3" });
|
|
|
|
synthesizeText({ "composition":
|
|
|
|
{ "string": "\u30E9\u30FC\u30E1\u30F3",
|
|
|
|
"clauses":
|
|
|
|
[
|
|
|
|
{ "length": 0, "attr": 0 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"caret": { "start": 4, "length": 0 }
|
|
|
|
});
|
|
|
|
synthesizeComposition({ type: "compositionend", data: "\u30E9\u30FC\u30E1\u30F3" });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [ ],
|
|
|
|
},
|
2013-09-03 15:45:29 +04:00
|
|
|
{ description: "nsMouseScrollEvent (DOMMouseScroll, vertical)",
|
|
|
|
targetID: "input-text", eventType: "DOMMouseScroll",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
synthesizeWheel(document.getElementById(this.targetID), 3, 4,
|
|
|
|
{ deltaY: 30, lineOrPageDeltaY: 2 });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [ ],
|
|
|
|
},
|
|
|
|
{ description: "nsMouseScrollEvent (DOMMouseScroll, horizontal)",
|
|
|
|
targetID: "input-text", eventType: "DOMMouseScroll",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
synthesizeWheel(document.getElementById(this.targetID), 4, 5,
|
|
|
|
{ deltaX: 30, lineOrPageDeltaX: 2, shiftKey: true });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [ ],
|
|
|
|
},
|
|
|
|
{ description: "nsMouseScrollEvent (MozMousePixelScroll, vertical)",
|
|
|
|
targetID: "input-text", eventType: "MozMousePixelScroll",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
synthesizeWheel(document.getElementById(this.targetID), 3, 4,
|
|
|
|
{ deltaY: 20, lineOrPageDeltaY: 1, altKey: true });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [ ],
|
|
|
|
},
|
|
|
|
{ description: "nsMouseScrollEvent (MozMousePixelScroll, horizontal)",
|
|
|
|
targetID: "input-text", eventType: "MozMousePixelScroll",
|
|
|
|
dispatchEvent: function () {
|
|
|
|
document.getElementById(this.targetID).value = "";
|
|
|
|
synthesizeWheel(document.getElementById(this.targetID), 4, 5,
|
|
|
|
{ deltaX: 20, lineOrPageDeltaX: 1, ctrlKey: true });
|
|
|
|
},
|
|
|
|
canRun: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
todoMismatch: [ ],
|
|
|
|
},
|
2013-08-30 06:10:32 +04:00
|
|
|
];
|
|
|
|
|
|
|
|
function doTest(aTest)
|
|
|
|
{
|
|
|
|
if (!aTest.canRun()) {
|
|
|
|
SimpleTest.executeSoon(runNextTest);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gEvent = null;
|
|
|
|
gCopiedEvent = [];
|
2013-09-03 15:45:28 +04:00
|
|
|
var target = aTest.target ? aTest.target() : document.getElementById(aTest.targetID);
|
2013-08-30 06:10:32 +04:00
|
|
|
target.addEventListener(aTest.eventType, onEvent, true);
|
2013-09-03 15:45:28 +04:00
|
|
|
gCallback = function () {
|
2013-08-30 06:10:32 +04:00
|
|
|
target.removeEventListener(aTest.eventType, onEvent, true);
|
|
|
|
ok(gEvent !== null, aTest.description + ": failed to get duplicated event");
|
|
|
|
ok(gCopiedEvent.length > 0, aTest.description + ": count of attribute of the event must be larger than 0");
|
|
|
|
for (var i = 0; i < gCopiedEvent.length; ++i) {
|
|
|
|
var name = gCopiedEvent[i].name;
|
|
|
|
if (name == "rangeOffset") {
|
|
|
|
todo(false, aTest.description + ": " + name + " attribute value is never reset (" + gEvent[name] + ")");
|
|
|
|
} else if (name == "eventPhase") {
|
|
|
|
is(gEvent[name], 0, aTest.description + ": mismatch with fixed value (" + name + ")");
|
|
|
|
} else if (name == "rangeParent" || name == "currentTarget") {
|
|
|
|
is(gEvent[name], null, aTest.description + ": mismatch with fixed value (" + name + ")");
|
|
|
|
} else if (aTest.todoMismatch.indexOf(name) >= 0) {
|
|
|
|
todo_is(gEvent[name], gCopiedEvent[i].value, aTest.description + ": mismatch (" + name + ")");
|
|
|
|
} else {
|
|
|
|
is(gEvent[name], gCopiedEvent[i].value, aTest.description + ": mismatch (" + name + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
runNextTest();
|
2013-09-03 15:45:28 +04:00
|
|
|
};
|
2013-08-30 06:10:32 +04:00
|
|
|
aTest.dispatchEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
var gIndex = -1;
|
|
|
|
function runNextTest()
|
|
|
|
{
|
|
|
|
if (++gIndex == kTests.length) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
doTest(kTests[gIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function init()
|
|
|
|
{
|
|
|
|
SpecialPowers.setBoolPref("middlemouse.contentLoadURL", false);
|
|
|
|
SpecialPowers.setBoolPref("middlemouse.paste", false);
|
|
|
|
SpecialPowers.setBoolPref("general.autoScroll", false);
|
2013-09-03 15:45:29 +04:00
|
|
|
SpecialPowers.setIntPref("mousewheel.default.action", 0);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.default.action.override_x", -1);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.with_shift.action", 0);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.with_shift.action.override_x", -1);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.with_control.action", 0);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.with_control.action.override_x", -1);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.with_alt.action", 0);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.with_alt.action.override_x", -1);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.with_meta.action", 0);
|
|
|
|
SpecialPowers.setIntPref("mousewheel.with_meta.action.override_x", -1);
|
2013-08-30 06:10:32 +04:00
|
|
|
|
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function finish()
|
|
|
|
{
|
|
|
|
SpecialPowers.clearUserPref("middlemouse.contentLoadURL");
|
|
|
|
SpecialPowers.clearUserPref("middlemouse.paste");
|
|
|
|
SpecialPowers.clearUserPref("general.autoScroll");
|
2013-09-03 15:45:29 +04:00
|
|
|
SpecialPowers.clearUserPref("mousewheel.default.action");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.default.action.override_x");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.with_shift.action");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.with_shift.action.override_x");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.with_control.action");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.with_control.action.override_x");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.with_alt.action");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.with_alt.action.override_x");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.with_meta.action");
|
|
|
|
SpecialPowers.clearUserPref("mousewheel.with_meta.action.override_x");
|
|
|
|
|
2013-08-30 06:10:32 +04:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForFocus(init);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|