Bug 993234 part.2 Add tests for KeyboardEvent.isComposing r=smaug

This commit is contained in:
Masayuki Nakano 2014-04-10 16:11:37 +09:00
parent 5364d05213
commit a61102d9f0
2 changed files with 142 additions and 0 deletions

View File

@ -48,6 +48,7 @@
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.expectAssertions(0, 16);
const kIsMac = (navigator.platform.indexOf("Mac") == 0);
const kIsWin = (navigator.platform.indexOf("Win") == 0);
@ -168,6 +169,76 @@ const kTests = [
},
todoMismatch: [],
},
{ description: "WidgetKeyboardEvent (keyup during composition)",
targetID: "input-text", eventType: "keyup",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
synthesizeKey("a", { type: "keydown" });
synthesizeComposition({ type: "compositionstart" });
synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
synthesizeText({ "composition":
{ "string": "\u306D",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeKey("a", { type: "keyup" });
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: [ ],
},
{ description: "WidgetKeyboardEvent (keydown during composition)",
targetID: "input-text", eventType: "keydown",
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": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeKey("VK_RETURN", { type: "keydown" });
synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
synthesizeText({ "composition":
{ "string": "\u306D",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeComposition({ type: "compositionend", data: "\u732B" });
synthesizeKey("VK_RETURN", { type: "keyup" });
},
canRun: function () {
return true;
},
todoMismatch: [ ],
},
{ description: "WidgetMouseEvent (mousedown of left button without modifier)",
targetID: "button", eventType: "mousedown",
dispatchEvent: function () {

View File

@ -2791,6 +2791,76 @@ function runBug811755Test()
return queryContent.text == textContent.text;
}
function runIsComposingTest()
{
var expectedIsComposing = false;
var descriptionBase = "runIsComposingTest: ";
var description = "";
function eventHandler(aEvent)
{
is(aEvent.isComposing, expectedIsComposing,
"runIsComposingTest: " + description + " (type=" + aEvent.type + ", key=" + aEvent.key + ")");
}
textarea.addEventListener("keydown", eventHandler, true);
textarea.addEventListener("keypress", eventHandler, true);
textarea.addEventListener("keyup", eventHandler, true);
textarea.focus();
textarea.value = "";
// XXX These cases shouldn't occur in actual native key events because we
// don't dispatch key events while composition (bug 354358).
expectedIsComposing = false;
description = "events before dispatching compositionstart";
synthesizeKey("VK_LEFT", {});
synthesizeKey("a", { type: "keydown" });
synthesizeComposition({ type: "compositionstart" });
expectedIsComposing = true;
description = "events after dispatching compositionstart";
synthesizeComposition({ type: "compositionupdate", data: "\u3042" });
synthesizeText(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeKey("a", { type: "keyup" });
// Although, firing keypress event during composition is a bug.
synthesizeKey("VK_INSERT", {});
description = "events for committing composition string";
synthesizeKey("VK_RETURN", { type: "keydown" });
synthesizeText(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeComposition({ type: "compositionend" });
expectedIsComposing = false;
description = "events after dispatching compositionend";
synthesizeKey("VK_RETURN", { type: "keyup" });
textarea.removeEventListener("keydown", eventHandler, true);
textarea.removeEventListener("keypress", eventHandler, true);
textarea.removeEventListener("keyup", eventHandler, true);
textarea.value = "";
}
function runRemoveContentTest(aCallback)
{
var events = [];
@ -3378,6 +3448,7 @@ function runTest()
runBug722639Test();
runForceCommitTest();
runBug811755Test();
runIsComposingTest();
runRemoveContentTest(function () {
runFrameTest();
runPanelTest();