gecko-dev/dom/events/test/test_text_event_in_content.html
Masayuki Nakano 7bd2c26c2c Bug 1288640 - Make TextComposition not dispatch eCompositionChange events (DOM "text" event) in the default group of web content r=smaug
The usage of our specific "text" event is enough low (0.0003%).  So, let's
stop dispatching the event in the default group of web content.  Once we
release this new behavior, we can get rid of dispatching the event even in
chrome.  Then, we can optimize the event order for new specs.

Differential Revision: https://phabricator.services.mozilla.com/D13034

--HG--
extra : moz-landing-system : lando
2018-11-27 13:26:51 +00:00

72 lines
2.6 KiB
HTML

<!doctype html>
<html>
<head>
<title>Not dispatching DOM "text" event on web apps</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<input id="input">
<textarea id="textarea"></textarea>
<div contenteditable id="editor"><p><br></p></div>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async function doTests() {
await SpecialPowers.pushPrefEnv({set: [
["dom.compositionevent.text.dispatch_only_system_group_in_content", true],
]});
for (let editorId of ["input", "textarea", "editor"]) {
let editor = document.getElementById(editorId);
editor.focus();
let fired = false;
function onText() {
fired = true;
}
editor.addEventListener("text", onText);
fired = false;
synthesizeCompositionChange({
composition: {string: "abc",
clauses: [{length: 3, attr: COMPOSITION_ATTR_RAW_CLAUSE}]},
caret: {start: 3, length: 0},
});
ok(!fired, `Starting composition shouldn't fire DOM "text" event in ${editorId}`);
fired = false;
synthesizeComposition({type: "compositioncommitasis", key: {key: "KEY_Enter"}});
ok(!fired, `Committing composition with the latest string shouldn't fire DOM "text" event in ${editorId}`);
fired = false;
synthesizeCompositionChange({
composition: {string: "def",
clauses: [{length: 3, attr: COMPOSITION_ATTR_RAW_CLAUSE}]},
caret: {start: 3, length: 0},
});
ok(!fired, `Restarting composition shouldn't fire DOM "text" event in ${editorId}`);
fired = false;
synthesizeComposition({type: "compositioncommit", data: "", key: {key: "KEY_Escape"}});
ok(!fired, `Committing composition with empty string shouldn't fire DOM "text" event in ${editorId}`);
fired = false;
synthesizeCompositionChange({
composition: {string: "de",
clauses: [{length: 2, attr: COMPOSITION_ATTR_RAW_CLAUSE}]},
caret: {start: 2, length: 0},
});
ok(!fired, `Restarting composition shouldn't fire DOM "text" event in ${editorId}`);
fired = false;
synthesizeComposition({type: "compositioncommit", data: "def", key: {key: "KEY_Escape"}});
ok(!fired, `Committing composition with new string shouldn't fire DOM "text" event in ${editorId}`);
fired = false;
synthesizeComposition({type: "compositioncommit", data: "ghi"});
ok(!fired, `Inserting string shouldn't fire DOM "text" event in ${editorId}`);
editor.removeEventListener("text", onText);
}
SimpleTest.finish();
});
</script>
</body>
</html>