2013-08-30 06:10:32 +04:00
<!DOCTYPE html>
< html >
< head >
< title > Testing ns*Event::Assign*EventData()< / title >
2013-12-08 19:51:16 +04:00
< script type = "text/javascript" src = "/tests/SimpleTest/SimpleTest.js" > < / script >
< script type = "text/javascript" src = "/tests/SimpleTest/EventUtils.js" > < / script >
< script type = "text/javascript" src = "/tests/SimpleTest/NativeKeyCodes.js" > < / script >
< link rel = "stylesheet" type = "text/css" href = "/tests/SimpleTest/test.css" >
2013-09-03 15:45:30 +04:00
< style >
#a {
background-color: transparent;
transition: background-color 0.1s linear;
}
#a:focus {
background-color: red;
}
2013-09-03 15:45:30 +04:00
.slidin {
border: green 1px solid;
width: 10px;
height: 10px;
animation-name: slidein;
animation-duration: 1s;
}
@keyframes slidein {
from {
margin-left: 100%;
}
to {
margin-left: 0;
}
}
2015-04-22 10:09:10 +03:00
#pointer-target {
border: 1px dashed red;
background: yellow;
margin: 0px 10px;
padding: 0px 10px;
}
#scrollable-div {
background: green;
overflow: auto;
width: 30px;
height: 30px;
}
#scrolled-div {
background: magenta;
width: 10px;
height: 10px;
}
#form {
background: silver;
padding: 0px 10px;
}
#animated-div {
background: cyan;
padding: 0px 10px;
}
2013-09-03 15:45:30 +04:00
< / style >
2013-08-30 06:10:32 +04:00
< / head >
< body >
< div id = "display" >
< input id = "input-text" >
< button id = "button" > button< / button >
2013-09-03 15:45:30 +04:00
< a id = "a" href = "about:blank" > hyper link< / a >
2015-04-22 10:09:10 +03:00
< span id = "pointer-target" > span< / span >
< div id = "scrollable-div" > < div id = "scrolled-div" > < / div > < / div >
< form id = "form" > form< / form >
< div id = "animated-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();
2015-04-22 10:09:10 +03:00
SimpleTest.expectAssertions(0, 34);
2013-08-30 06:10:32 +04:00
2018-02-26 12:30:29 +03:00
const kStrictKeyPressEvents =
SpecialPowers.getBoolPref("dom.keyboardevent.keypress.dispatch_non_printable_keys_only_system_group_in_content");
2013-08-30 06:10:32 +04:00
const kIsMac = (navigator.platform.indexOf("Mac") == 0);
const kIsWin = (navigator.platform.indexOf("Win") == 0);
2018-02-26 12:30:29 +03:00
var gDescription = "";
2013-08-30 06:10:32 +04:00
var gEvent = null;
var gCopiedEvent = [];
2013-09-03 15:45:28 +04:00
var gCallback = null;
2013-12-08 19:51:16 +04:00
var gCallPreventDefault = false;
2013-08-30 06:10:32 +04:00
function onEvent(aEvent)
{
2013-12-08 19:51:16 +04:00
if (gCallPreventDefault) {
aEvent.preventDefault();
}
2018-02-26 12:30:29 +03:00
ok(gEvent === null, gDescription + `: We should receive only one event to check per test: already got: ${gEvent ? gEvent.type : "null"}, got: ${aEvent.type}`);
2013-08-30 06:10:32 +04:00
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
}
2017-06-07 09:28:16 +03:00
function observeKeyUpOnContent(aKeyCode, aCallback)
{
document.addEventListener("keyup", function keyUp(ev) {
if (ev.keyCode == aKeyCode) {
document.removeEventListener("keyup", keyUp);
SimpleTest.executeSoon(aCallback);
}
});
}
2013-08-30 06:10:32 +04:00
const kTests = [
2013-10-29 08:14:43 +04:00
{ description: "InternalScrollPortEvent (overflow, vertical)",
2013-09-03 15:45:28 +04:00
targetID: "scrollable-div", eventType: "overflow",
dispatchEvent: function () {
document.getElementById("scrolled-div").style.height = "500px";
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalScrollPortEvent (overflow, horizontal)",
2013-09-03 15:45:28 +04:00
targetID: "scrollable-div", eventType: "overflow",
dispatchEvent: function () {
document.getElementById("scrolled-div").style.width = "500px";
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalScrollAreaEvent (MozScrolledAreaChanged, spreading)",
2013-09-03 15:45:28 +04:00
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: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalScrollAreaEvent (MozScrolledAreaChanged, shrinking)",
2013-09-03 15:45:28 +04:00
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-10-29 08:14:43 +04:00
{ description: "WidgetKeyboardEvent (keydown of 'a' key without modifiers)",
2013-09-03 15:45:28 +04:00
targetID: "input-text", eventType: "keydown",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
2013-12-08 19:51:16 +04:00
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_A : MAC_VK_ANSI_A,
{}, "a", "a");
2017-06-07 09:28:16 +03:00
observeKeyUpOnContent(KeyboardEvent.DOM_VK_A, runNextTest);
return true;
2013-09-03 15:45:28 +04:00
},
canRun: function () {
return (kIsMac || kIsWin);
},
2013-10-29 08:14:42 +04:00
todoMismatch: [],
2013-08-30 06:10:32 +04:00
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetKeyboardEvent (keyup of 'a' key without modifiers)",
2013-09-03 15:45:28 +04:00
targetID: "input-text", eventType: "keydown",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
2013-12-08 19:51:16 +04:00
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_A : MAC_VK_ANSI_A,
{}, "a", "a");
2017-06-07 09:28:16 +03:00
observeKeyUpOnContent(KeyboardEvent.DOM_VK_A, runNextTest);
return true;
2013-09-03 15:45:28 +04:00
},
canRun: function () {
return (kIsMac || kIsWin);
},
2013-10-29 08:14:42 +04:00
todoMismatch: [],
2013-08-30 06:10:32 +04:00
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetKeyboardEvent (keypress of 'b' key with Shift)",
2013-09-03 15:45:28 +04:00
targetID: "input-text", eventType: "keypress",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
2013-12-08 19:51:16 +04:00
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_B : MAC_VK_ANSI_B,
{ shiftKey: true }, "B", "B");
2018-02-26 12:30:29 +03:00
// On Windows, synthesizeNativeKey will also fire keyup for shiftKey.
// We have to wait for it to prevent the key event break the next test case.
let waitKeyCode = _EU_isWin(window) ? KeyboardEvent.DOM_VK_SHIFT :
KeyboardEvent.DOM_VK_B;
observeKeyUpOnContent(waitKeyCode, runNextTest);
2017-06-07 09:28:16 +03:00
return true;
2013-09-03 15:45:28 +04:00
},
canRun: function () {
return (kIsMac || kIsWin);
},
2013-12-08 19:51:16 +04:00
todoMismatch: [],
2013-08-30 06:10:32 +04:00
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetKeyboardEvent (keypress of 'c' key with Accel)",
2013-09-03 15:45:28 +04:00
targetID: "input-text", eventType: "keypress",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
2013-12-08 19:51:16 +04:00
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_C : MAC_VK_ANSI_C,
{ accelKey: true }, kIsWin ? "\u0003" : "c", "c");
2017-06-07 09:28:16 +03:00
// On Windows, synthesizeNativeKey will also fire keyup for accelKey
// (control key on Windows). We have to wait for it to prevent the key
// event break the next test case.
let waitKeyCode = _EU_isWin(window) ? KeyboardEvent.DOM_VK_CONTROL :
KeyboardEvent.DOM_VK_C;
observeKeyUpOnContent(waitKeyCode, runNextTest);
return true;
2013-09-03 15:45:28 +04:00
},
canRun: function () {
2018-02-26 12:30:29 +03:00
return !kStrictKeyPressEvents & & (kIsMac || kIsWin);
2013-09-03 15:45:28 +04:00
},
2013-12-08 19:51:16 +04:00
todoMismatch: [],
2013-08-30 06:10:32 +04:00
},
2014-04-10 11:11:37 +04:00
{ description: "WidgetKeyboardEvent (keyup during composition)",
targetID: "input-text", eventType: "keyup",
dispatchEvent: function () {
2016-03-11 03:56:13 +03:00
setAndObserveCompositionPref(true, () => {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
synthesizeCompositionChange({ "composition":
{ "string": "\u306D",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
]
},
"caret": { "start": 1, "length": 0 },
Bug 1446253 - Make EventUtils.synthesizeComposition() dispatch keydown and keyup event in default r=smaug
We'll start to dispatch keydown event and keyup event even during composition.
So, for testing those events won't break our UI, we should make
EventUtils.synhtesizeComposition() and EventUtils.synthesizeCompositionChange()
dispatch keydown event and keyup event even if callers don't specify keyboard
event explicitly.
Typically, "keydown" event is marked as "processed by IME", i.e., keyCode
value is set to DOM_VK_PROCESSKEY and key is set to "Process", with our
widget which handles native IME and key input. On the other hand, "keyup"
is NOT marked as so.
Therefore, this patch makes TextInputProcessor emulates this behavior without
any new special flags. And for making possible to emulate special cases,
this patch adds two flags to nsITextInputProcessor. One is
KEY_DONT_MARK_KEYDOWN_AS_PROCESSED. The other is KEY_MARK_KEYUP_AS_PROCESSED.
Unfortunately, those flags have opposite meaning but this must be better than
making necessary to one flag for emulating usual keydown/keyup events.
Finally, this makes some tests specify better keyboard information to
synthesizeComposition() and synthesizeCompositionChange() to emulate
actual keyboard events during composition.
MozReview-Commit-ID: ItYaXILkNQE
--HG--
extra : rebase_source : e50cc77c1efbc12686d7ea334d41926c7392b30d
2018-03-16 16:35:07 +03:00
"key": { key: "a" },
2016-03-11 03:56:13 +03:00
});
Bug 1446253 - Make EventUtils.synthesizeComposition() dispatch keydown and keyup event in default r=smaug
We'll start to dispatch keydown event and keyup event even during composition.
So, for testing those events won't break our UI, we should make
EventUtils.synhtesizeComposition() and EventUtils.synthesizeCompositionChange()
dispatch keydown event and keyup event even if callers don't specify keyboard
event explicitly.
Typically, "keydown" event is marked as "processed by IME", i.e., keyCode
value is set to DOM_VK_PROCESSKEY and key is set to "Process", with our
widget which handles native IME and key input. On the other hand, "keyup"
is NOT marked as so.
Therefore, this patch makes TextInputProcessor emulates this behavior without
any new special flags. And for making possible to emulate special cases,
this patch adds two flags to nsITextInputProcessor. One is
KEY_DONT_MARK_KEYDOWN_AS_PROCESSED. The other is KEY_MARK_KEYUP_AS_PROCESSED.
Unfortunately, those flags have opposite meaning but this must be better than
making necessary to one flag for emulating usual keydown/keyup events.
Finally, this makes some tests specify better keyboard information to
synthesizeComposition() and synthesizeCompositionChange() to emulate
actual keyboard events during composition.
MozReview-Commit-ID: ItYaXILkNQE
--HG--
extra : rebase_source : e50cc77c1efbc12686d7ea334d41926c7392b30d
2018-03-16 16:35:07 +03:00
synthesizeComposition({ type: "compositioncommitasis", key: {} });
2016-03-11 03:56:13 +03:00
setAndObserveCompositionPref(null, runNextTest);
2014-04-10 11:11:37 +04:00
});
2016-03-11 03:56:13 +03:00
return true;
2014-04-10 11:11:37 +04:00
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
{ description: "WidgetKeyboardEvent (keydown during composition)",
targetID: "input-text", eventType: "keydown",
dispatchEvent: function () {
2016-03-11 03:56:13 +03:00
setAndObserveCompositionPref(true, () => {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
synthesizeCompositionChange({ "composition":
{ "string": "\u306D",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
]
},
Bug 1446253 - Make EventUtils.synthesizeComposition() dispatch keydown and keyup event in default r=smaug
We'll start to dispatch keydown event and keyup event even during composition.
So, for testing those events won't break our UI, we should make
EventUtils.synhtesizeComposition() and EventUtils.synthesizeCompositionChange()
dispatch keydown event and keyup event even if callers don't specify keyboard
event explicitly.
Typically, "keydown" event is marked as "processed by IME", i.e., keyCode
value is set to DOM_VK_PROCESSKEY and key is set to "Process", with our
widget which handles native IME and key input. On the other hand, "keyup"
is NOT marked as so.
Therefore, this patch makes TextInputProcessor emulates this behavior without
any new special flags. And for making possible to emulate special cases,
this patch adds two flags to nsITextInputProcessor. One is
KEY_DONT_MARK_KEYDOWN_AS_PROCESSED. The other is KEY_MARK_KEYUP_AS_PROCESSED.
Unfortunately, those flags have opposite meaning but this must be better than
making necessary to one flag for emulating usual keydown/keyup events.
Finally, this makes some tests specify better keyboard information to
synthesizeComposition() and synthesizeCompositionChange() to emulate
actual keyboard events during composition.
MozReview-Commit-ID: ItYaXILkNQE
--HG--
extra : rebase_source : e50cc77c1efbc12686d7ea334d41926c7392b30d
2018-03-16 16:35:07 +03:00
"caret": { "start": 1, "length": 0 },
"key": {},
2016-03-11 03:56:13 +03:00
});
synthesizeComposition({ type: "compositioncommitasis",
Bug 1446253 - Make EventUtils.synthesizeComposition() dispatch keydown and keyup event in default r=smaug
We'll start to dispatch keydown event and keyup event even during composition.
So, for testing those events won't break our UI, we should make
EventUtils.synhtesizeComposition() and EventUtils.synthesizeCompositionChange()
dispatch keydown event and keyup event even if callers don't specify keyboard
event explicitly.
Typically, "keydown" event is marked as "processed by IME", i.e., keyCode
value is set to DOM_VK_PROCESSKEY and key is set to "Process", with our
widget which handles native IME and key input. On the other hand, "keyup"
is NOT marked as so.
Therefore, this patch makes TextInputProcessor emulates this behavior without
any new special flags. And for making possible to emulate special cases,
this patch adds two flags to nsITextInputProcessor. One is
KEY_DONT_MARK_KEYDOWN_AS_PROCESSED. The other is KEY_MARK_KEYUP_AS_PROCESSED.
Unfortunately, those flags have opposite meaning but this must be better than
making necessary to one flag for emulating usual keydown/keyup events.
Finally, this makes some tests specify better keyboard information to
synthesizeComposition() and synthesizeCompositionChange() to emulate
actual keyboard events during composition.
MozReview-Commit-ID: ItYaXILkNQE
--HG--
extra : rebase_source : e50cc77c1efbc12686d7ea334d41926c7392b30d
2018-03-16 16:35:07 +03:00
key: { key: "KEY_Enter" } });
2016-03-11 03:56:13 +03:00
setAndObserveCompositionPref(null, runNextTest);
2014-04-10 11:11:37 +04:00
});
2016-03-11 03:56:13 +03:00
return true;
2014-04-10 11:11:37 +04:00
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetMouseEvent (mousedown of left button without modifier)",
2013-09-03 15:45:28 +04:00
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-10-29 08:14:43 +04:00
{ description: "WidgetMouseEvent (click of middle button with Shift)",
2013-09-03 15:45:28 +04:00
// 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-10-29 08:14:43 +04:00
{ description: "WidgetMouseEvent (mouseup of right button with Alt)",
2013-09-03 15:45:28 +04:00
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-10-29 08:14:43 +04:00
{ description: "WidgetDragEvent",
2013-09-03 15:45:28 +04:00
targetID: "input-text", eventType: "dragstart",
dispatchEvent: function () {
return;
},
canRun: function () {
2013-10-29 08:14:43 +04:00
todo(false, "WidgetDragEvent isn't tested");
2013-09-03 15:45:28 +04:00
return false;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetTextEvent (text)",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "text",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
Bug 1446253 - Make EventUtils.synthesizeComposition() dispatch keydown and keyup event in default r=smaug
We'll start to dispatch keydown event and keyup event even during composition.
So, for testing those events won't break our UI, we should make
EventUtils.synhtesizeComposition() and EventUtils.synthesizeCompositionChange()
dispatch keydown event and keyup event even if callers don't specify keyboard
event explicitly.
Typically, "keydown" event is marked as "processed by IME", i.e., keyCode
value is set to DOM_VK_PROCESSKEY and key is set to "Process", with our
widget which handles native IME and key input. On the other hand, "keyup"
is NOT marked as so.
Therefore, this patch makes TextInputProcessor emulates this behavior without
any new special flags. And for making possible to emulate special cases,
this patch adds two flags to nsITextInputProcessor. One is
KEY_DONT_MARK_KEYDOWN_AS_PROCESSED. The other is KEY_MARK_KEYUP_AS_PROCESSED.
Unfortunately, those flags have opposite meaning but this must be better than
making necessary to one flag for emulating usual keydown/keyup events.
Finally, this makes some tests specify better keyboard information to
synthesizeComposition() and synthesizeCompositionChange() to emulate
actual keyboard events during composition.
MozReview-Commit-ID: ItYaXILkNQE
--HG--
extra : rebase_source : e50cc77c1efbc12686d7ea334d41926c7392b30d
2018-03-16 16:35:07 +03:00
synthesizeComposition({ type: "compositioncommit", data: "\u306D", key: { key: "," } });
2013-09-03 15:45:29 +04:00
},
canRun: function () {
2018-11-27 16:26:51 +03:00
return !SpecialPowers.getBoolPref("dom.compositionevent.text.dispatch_only_system_group_in_content");
2013-09-03 15:45:29 +04:00
},
todoMismatch: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetCompositionEvent (compositionupdate)",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "compositionupdate",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
Bug 1446253 - Make EventUtils.synthesizeComposition() dispatch keydown and keyup event in default r=smaug
We'll start to dispatch keydown event and keyup event even during composition.
So, for testing those events won't break our UI, we should make
EventUtils.synhtesizeComposition() and EventUtils.synthesizeCompositionChange()
dispatch keydown event and keyup event even if callers don't specify keyboard
event explicitly.
Typically, "keydown" event is marked as "processed by IME", i.e., keyCode
value is set to DOM_VK_PROCESSKEY and key is set to "Process", with our
widget which handles native IME and key input. On the other hand, "keyup"
is NOT marked as so.
Therefore, this patch makes TextInputProcessor emulates this behavior without
any new special flags. And for making possible to emulate special cases,
this patch adds two flags to nsITextInputProcessor. One is
KEY_DONT_MARK_KEYDOWN_AS_PROCESSED. The other is KEY_MARK_KEYUP_AS_PROCESSED.
Unfortunately, those flags have opposite meaning but this must be better than
making necessary to one flag for emulating usual keydown/keyup events.
Finally, this makes some tests specify better keyboard information to
synthesizeComposition() and synthesizeCompositionChange() to emulate
actual keyboard events during composition.
MozReview-Commit-ID: ItYaXILkNQE
--HG--
extra : rebase_source : e50cc77c1efbc12686d7ea334d41926c7392b30d
2018-03-16 16:35:07 +03:00
synthesizeComposition({ type: "compositioncommit", data: "\u30E9\u30FC\u30E1\u30F3", key: { key: "KEY_Enter" } });
2014-04-10 11:11:37 +04:00
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
{ description: "InternalEditorInputEvent (input at key input)",
targetID: "input-text", eventType: "input",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_B : MAC_VK_ANSI_B,
{ shiftKey: true }, "B", "B");
2017-06-07 09:28:16 +03:00
observeKeyUpOnContent(KeyboardEvent.DOM_VK_B, runNextTest);
return true;
2014-04-10 11:11:37 +04:00
},
canRun: function () {
return (kIsMac || kIsWin);
},
todoMismatch: [],
},
{ description: "InternalEditorInputEvent (input at composing)",
targetID: "input-text", eventType: "input",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
2014-10-07 14:01:50 +04:00
synthesizeCompositionChange({ "composition":
2014-04-10 11:11:37 +04:00
{ "string": "\u30E9\u30FC\u30E1\u30F3",
"clauses":
[
2015-01-28 09:27:33 +03:00
{ "length": 4, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
2014-04-10 11:11:37 +04:00
]
},
Bug 1446253 - Make EventUtils.synthesizeComposition() dispatch keydown and keyup event in default r=smaug
We'll start to dispatch keydown event and keyup event even during composition.
So, for testing those events won't break our UI, we should make
EventUtils.synhtesizeComposition() and EventUtils.synthesizeCompositionChange()
dispatch keydown event and keyup event even if callers don't specify keyboard
event explicitly.
Typically, "keydown" event is marked as "processed by IME", i.e., keyCode
value is set to DOM_VK_PROCESSKEY and key is set to "Process", with our
widget which handles native IME and key input. On the other hand, "keyup"
is NOT marked as so.
Therefore, this patch makes TextInputProcessor emulates this behavior without
any new special flags. And for making possible to emulate special cases,
this patch adds two flags to nsITextInputProcessor. One is
KEY_DONT_MARK_KEYDOWN_AS_PROCESSED. The other is KEY_MARK_KEYUP_AS_PROCESSED.
Unfortunately, those flags have opposite meaning but this must be better than
making necessary to one flag for emulating usual keydown/keyup events.
Finally, this makes some tests specify better keyboard information to
synthesizeComposition() and synthesizeCompositionChange() to emulate
actual keyboard events during composition.
MozReview-Commit-ID: ItYaXILkNQE
--HG--
extra : rebase_source : e50cc77c1efbc12686d7ea334d41926c7392b30d
2018-03-16 16:35:07 +03:00
"caret": { "start": 4, "length": 0 },
"key": { key: "y" },
2014-04-10 11:11:37 +04:00
});
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
{ description: "InternalEditorInputEvent (input at committing)",
targetID: "input-text", eventType: "input",
dispatchEvent: function () {
Bug 1446253 - Make EventUtils.synthesizeComposition() dispatch keydown and keyup event in default r=smaug
We'll start to dispatch keydown event and keyup event even during composition.
So, for testing those events won't break our UI, we should make
EventUtils.synhtesizeComposition() and EventUtils.synthesizeCompositionChange()
dispatch keydown event and keyup event even if callers don't specify keyboard
event explicitly.
Typically, "keydown" event is marked as "processed by IME", i.e., keyCode
value is set to DOM_VK_PROCESSKEY and key is set to "Process", with our
widget which handles native IME and key input. On the other hand, "keyup"
is NOT marked as so.
Therefore, this patch makes TextInputProcessor emulates this behavior without
any new special flags. And for making possible to emulate special cases,
this patch adds two flags to nsITextInputProcessor. One is
KEY_DONT_MARK_KEYDOWN_AS_PROCESSED. The other is KEY_MARK_KEYUP_AS_PROCESSED.
Unfortunately, those flags have opposite meaning but this must be better than
making necessary to one flag for emulating usual keydown/keyup events.
Finally, this makes some tests specify better keyboard information to
synthesizeComposition() and synthesizeCompositionChange() to emulate
actual keyboard events during composition.
MozReview-Commit-ID: ItYaXILkNQE
--HG--
extra : rebase_source : e50cc77c1efbc12686d7ea334d41926c7392b30d
2018-03-16 16:35:07 +03:00
synthesizeComposition({ type: "compositioncommitasis", key: { key: "KEY_Enter" } });
2013-09-03 15:45:29 +04:00
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetMouseScrollEvent (DOMMouseScroll, vertical)",
2013-09-03 15:45:29 +04:00
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: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetMouseScrollEvent (DOMMouseScroll, horizontal)",
2013-09-03 15:45:29 +04:00
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: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetMouseScrollEvent (MozMousePixelScroll, vertical)",
2013-09-03 15:45:29 +04:00
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: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetMouseScrollEvent (MozMousePixelScroll, horizontal)",
2013-09-03 15:45:29 +04:00
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-10-29 08:14:43 +04:00
{ description: "WidgetWheelEvent (wheel, vertical)",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "wheel",
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: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetWheelEvent (wheel, horizontal)",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "wheel",
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-10-29 08:14:43 +04:00
{ description: "WidgetWheelEvent (wheel, both)",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "wheel",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
synthesizeWheel(document.getElementById(this.targetID), 4, 5,
{ deltaX: 20, deltaY: 10,
lineOrPageDeltaX: 1, lineOrPageDeltaY: 1 });
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetTouchEvent (touchstart)",
2013-09-03 15:45:29 +04:00
target: function () { return document; }, eventType: "touchstart",
dispatchEvent: function () {
synthesizeTouchAtPoint(1, 2, { id: 10, rx: 4, ry: 3, angle: 0, force: 1, shiftKey: true});
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetTouchEvent (touchend)",
2013-09-03 15:45:29 +04:00
target: function () { return document; }, eventType: "touchend",
dispatchEvent: function () {
synthesizeTouchAtPoint(4, 6, { id: 5, rx: 1, ry: 2, angle: 0.5, force: 0.8, ctrlKey: true});
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalFormEvent (reset)",
2013-09-03 15:45:29 +04:00
targetID: "form", eventType: "reset",
dispatchEvent: function () {
document.getElementById("form").reset();
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetCommandEvent",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "",
dispatchEvent: function () {
return;
},
canRun: function () {
2013-10-29 08:14:43 +04:00
todo(false, "WidgetCommandEvent isn't tested");
2013-09-03 15:45:29 +04:00
return false;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalClipboardEvent (copy)",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "copy",
dispatchEvent: function () {
document.getElementById("input-text").value = "go to clipboard!";
document.getElementById("input-text").focus();
document.getElementById("input-text").select();
synthesizeKey("c", { accelKey: true });
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalUIEvent (DOMActivate)",
2013-09-03 15:45:29 +04:00
targetID: "button", eventType: "DOMActivate",
dispatchEvent: function () {
synthesizeMouseAtCenter(document.getElementById(this.targetID),
{ button: 0, shiftKey: true });
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalFocusEvent (focus)",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "focus",
dispatchEvent: function () {
document.getElementById(this.targetID).focus();
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalFocusEvent (blur)",
2013-09-03 15:45:29 +04:00
targetID: "input-text", eventType: "blur",
dispatchEvent: function () {
document.getElementById(this.targetID).blur();
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "WidgetSimpleGestureEvent",
2013-09-03 15:45:30 +04:00
targetID: "", eventType: "",
dispatchEvent: function () {
return;
},
canRun: function () {
// Simple gesture event may be handled before it comes content.
// So, we cannot test it in this test.
2013-10-29 08:14:43 +04:00
todo(false, "WidgetSimpleGestureEvent isn't tested");
2013-09-03 15:45:30 +04:00
return false;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalTransitionEvent (transitionend)",
2013-09-03 15:45:30 +04:00
targetID: "a", eventType: "transitionend",
dispatchEvent: function () {
document.getElementById(this.targetID).focus();
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalAnimationEvent (animationend)",
2013-09-03 15:45:30 +04:00
targetID: "animated-div", eventType: "animationend",
dispatchEvent: function () {
document.getElementById(this.targetID).className = "slidin";
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalMutationEvent (DOMAttrModified)",
2013-09-03 15:45:30 +04:00
targetID: "animated-div", eventType: "DOMAttrModified",
dispatchEvent: function () {
document.getElementById(this.targetID).setAttribute("x-data", "foo");
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalMutationEvent (DOMNodeInserted)",
2013-09-03 15:45:30 +04:00
targetID: "animated-div", eventType: "DOMNodeInserted",
dispatchEvent: function () {
var div = document.createElement("div");
div.id = "inserted-div";
document.getElementById("animated-div").appendChild(div);
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-10-29 08:14:43 +04:00
{ description: "InternalMutationEvent (DOMNodeRemoved)",
2013-09-03 15:45:30 +04:00
targetID: "animated-div", eventType: "DOMNodeRemoved",
dispatchEvent: function () {
document.getElementById("animated-div").removeChild(document.getElementById("inserted-div"));
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2015-04-22 10:09:10 +03:00
{ description: "PointerEvent (pointerdown)",
2017-11-24 02:50:12 +03:00
targetID: "pointer-target", eventType: "mousedown",
2015-04-22 10:09:10 +03:00
dispatchEvent: function () {
var elem = document.getElementById(this.targetID);
var rect = elem.getBoundingClientRect();
2017-11-24 02:50:12 +03:00
synthesizeMouse(elem, rect.width/2, rect.height/2,
{ type: this.eventType, button: 1, clickCount: 1, inputSource: 2, pressure: 0.25, isPrimary: true });
2015-04-22 10:09:10 +03:00
},
canRun: function () {
return true;
},
todoMismatch: [],
},
{ description: "PointerEvent (pointerup)",
2017-11-24 02:50:12 +03:00
targetID: "pointer-target", eventType: "mouseup",
2015-04-22 10:09:10 +03:00
dispatchEvent: function () {
var elem = document.getElementById(this.targetID);
var rect = elem.getBoundingClientRect();
2017-11-24 02:50:12 +03:00
synthesizeMouse(elem, rect.width/2, rect.height/2,
{ type: this.eventType, button: -1, ctrlKey: true, shiftKey: true, altKey: true, isSynthesized: false });
2015-04-22 10:09:10 +03:00
},
canRun: function () {
return true;
},
todoMismatch: [],
},
2013-08-30 06:10:32 +04:00
];
2016-03-11 03:56:13 +03:00
/**
* Sets or clears dom.keyboardevent.dispatch_during_composition and calls the
* given callback when the change is observed.
*
* @param aValue
* Pass null to clear the pref. Otherwise pass a bool.
* @param aCallback
* Called when the pref change is observed.
*/
function setAndObserveCompositionPref(aValue, aCallback) {
let pref = "dom.keyboardevent.dispatch_during_composition";
if (aValue === null) {
2017-03-01 23:29:30 +03:00
SpecialPowers.pushPrefEnv({"clear": [[pref]]}, aCallback);
2016-03-11 03:56:13 +03:00
} else {
2017-03-01 23:29:30 +03:00
SpecialPowers.pushPrefEnv({"set": [[pref, aValue]]}, aCallback);
2016-03-11 03:56:13 +03:00
}
}
2013-08-30 06:10:32 +04:00
function doTest(aTest)
{
if (!aTest.canRun()) {
SimpleTest.executeSoon(runNextTest);
return;
}
gEvent = null;
gCopiedEvent = [];
2018-02-26 12:30:29 +03:00
gDescription = aTest.description + " (gCallPreventDefault=" + gCallPreventDefault + ")";
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);
2018-02-26 12:30:29 +03:00
ok(gEvent !== null, gDescription + ": failed to get duplicated event");
ok(gCopiedEvent.length > 0, gDescription + ": count of attribute of the event must be larger than 0");
2013-08-30 06:10:32 +04:00
for (var i = 0; i < gCopiedEvent.length ; + + i ) {
var name = gCopiedEvent[i].name;
if (name == "rangeOffset") {
2018-02-26 12:30:29 +03:00
todo(false, gDescription + ": " + name + " attribute value is never reset (" + gEvent[name] + ")");
2013-08-30 06:10:32 +04:00
} else if (name == "eventPhase") {
2018-02-26 12:30:29 +03:00
is(gEvent[name], 0, gDescription + ": mismatch with fixed value (" + name + ")");
2013-08-30 06:10:32 +04:00
} else if (name == "rangeParent" || name == "currentTarget") {
2018-02-26 12:30:29 +03:00
is(gEvent[name], null, gDescription + ": mismatch with fixed value (" + name + ")");
2018-02-01 22:45:22 +03:00
} else if (aTest.todoMismatch.includes(name)) {
2018-02-26 12:30:29 +03:00
todo_is(gEvent[name], gCopiedEvent[i].value, gDescription + ": mismatch (" + name + ")");
2015-03-13 14:50:10 +03:00
} else if (name == "offsetX" || name == "offsetY") {
// do nothing; these are defined to return different values during event dispatch
// vs not during event dispatch
2013-08-30 06:10:32 +04:00
} else {
2018-02-26 12:30:29 +03:00
is(gEvent[name], gCopiedEvent[i].value, gDescription + ": mismatch (" + name + ")");
2013-08-30 06:10:32 +04:00
}
}
2016-03-11 03:56:13 +03:00
if (!testWillCallRunNextTest) {
runNextTest();
}
2013-09-03 15:45:28 +04:00
};
2016-03-11 03:56:13 +03:00
var testWillCallRunNextTest = aTest.dispatchEvent();
2013-08-30 06:10:32 +04:00
}
var gIndex = -1;
function runNextTest()
{
if (++gIndex == kTests.length) {
2013-12-08 19:51:16 +04:00
if (gCallPreventDefault) {
finish();
return;
}
// Test with a call of preventDefault() of the events.
gCallPreventDefault = true;
gIndex = -1;
// Restoring the initial state of all elements.
document.getElementById("scrollable-div").style.height = "30px";
document.getElementById("scrollable-div").style.width = "30px";
document.getElementById("scrolled-div").style.height = "10px";
document.getElementById("scrolled-div").style.width = "10px";
document.getElementById("input-text").value = "";
document.getElementById("animated-div").className = "";
document.getElementById("animated-div").removeAttribute("x-data");
if (document.activeElement) {
document.activeElement.blur();
}
window.requestAnimationFrame(function () {
setTimeout(runNextTest, 0);
});
2013-08-30 06:10:32 +04:00
return;
}
doTest(kTests[gIndex]);
}
function init()
{
2015-02-19 19:53:01 +03:00
SpecialPowers.pushPrefEnv({"set":[["middlemouse.contentLoadURL", false],
2015-04-22 10:09:10 +03:00
["middlemouse.paste", false],
2015-02-19 19:53:01 +03:00
["general.autoScroll", false],
2017-10-12 04:25:10 +03:00
["dom.w3c_pointer_events.enabled", true],
2015-02-19 19:53:01 +03:00
["mousewheel.default.action", 0],
["mousewheel.default.action.override_x", -1],
["mousewheel.with_shift.action", 0],
["mousewheel.with_shift.action.override_x", -1],
["mousewheel.with_control.action", 0],
["mousewheel.with_control.action.override_x", -1],
["mousewheel.with_alt.action", 0],
["mousewheel.with_alt.action.override_x", -1],
["mousewheel.with_meta.action", 0],
["mousewheel.with_meta.action.override_x", -1]]}, runNextTest);
2013-08-30 06:10:32 +04:00
}
function finish()
{
SimpleTest.finish();
}
SimpleTest.waitForFocus(init);
< / script >
< / body >