Bug 1077345 part.7 Use synthesizeComposition({"compositioncommit") in the tests r=smaug

This commit is contained in:
Masayuki Nakano 2014-11-25 14:02:32 +09:00
parent 9fa4fa61de
commit f6d9749945
6 changed files with 231 additions and 124 deletions

View File

@ -134,11 +134,7 @@ function doCompositionTest(aElement, aElementDescription, aCallback)
hitEventLoop(function () {
isnot(aElement.scrollTop, 0,
aElementDescription + " was not scrolled by composition");
synthesizeCompositionChange({
composition: { string: "", clauses: [ { length: 0, attr: 0 } ] },
caret: { start: 0, length: 0 }
});
synthesizeComposition({ type: "compositionend", data: "" });
synthesizeComposition({ type: "compositioncommit", data: "" });
hitEventLoop(function () {
is(aElement.scrollTop, 0,
aElementDescription + " was not scrolled back to the top by canceling composition");

View File

@ -156,6 +156,9 @@ function starttest() {
check = false;
window.addEventListener("compositionend", function() { check = true; }, false);
synthesizeComposition({ type: "compositionend", data: "a" });
is(check, false, 'synthesizeComposition() should not dispatch compositionend');
synthesizeComposition({ type: "compositioncommit", data: "a" });
is(check, true, 'synthesizeComposition() should dispatch compositionend');
var querySelectedText = synthesizeQuerySelectedText();

View File

@ -214,17 +214,7 @@ nsDoTestsForAutoCompleteWithComposition.prototype = {
{ description: "cancled compositionend should reopen the popup",
completeDefaultIndex: false,
execute: function (aWindow) {
synthesizeCompositionChange(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
}, aWindow);
synthesizeComposition({ type: "compositionend", data: "" }, aWindow);
synthesizeComposition({ type: "compositioncommit", data: "" }, aWindow);
synthesizeKey("VK_ESCAPE", { type: "keyup" }, aWindow);
}, popup: true, value: "Mozi", searchString: "Mozi"
},

View File

@ -270,16 +270,7 @@ const kTests = [
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
synthesizeComposition({ type: "compositionstart" });
synthesizeCompositionChange({ "composition":
{ "string": "\u306D",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeComposition({ type: "compositionend", data: "\u732B" });
synthesizeComposition({ type: "compositioncommit", data: "\u306D" });
},
canRun: function () {
return true;
@ -292,16 +283,7 @@ const kTests = [
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
synthesizeComposition({ type: "compositionstart" });
synthesizeCompositionChange({ "composition":
{ "string": "\u30E9\u30FC\u30E1\u30F3",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 4, "length": 0 }
});
synthesizeComposition({ type: "compositionend", data: "\u30E9\u30FC\u30E1\u30F3" });
synthesizeComposition({ type: "compositioncommit", data: "\u30E9\u30FC\u30E1\u30F3" });
},
canRun: function () {
return true;

View File

@ -1266,18 +1266,7 @@ function runEditorFlagChangeTests()
description + "#3 IME isn't enabled on HTML editor");
// cancel the composition
synthesizeCompositionChange(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
synthesizeComposition({ type: "compositionend", data: "" });
synthesizeComposition({ type: "compositioncommit", data: "" });
container.removeAttribute("contenteditable");
}

View File

@ -248,19 +248,7 @@ function runUndoRedoTest()
});
// cancel the composition
synthesizeCompositionChange(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
// end composition
synthesizeComposition({ type: "compositionend", data: "" });
synthesizeComposition({ type: "compositioncommit", data: "" });
// start composition
synthesizeComposition({ type: "compositionstart" });
@ -698,6 +686,223 @@ function runCompositionCommitAsIsTest()
textarea.removeEventListener("text", handler, true);
}
function runCompositionCommitTest()
{
textarea.focus();
var result = {};
function clearResult()
{
result = { compositionupdate: false, compositionend: false, text: false, input: false }
}
function handler(aEvent)
{
result[aEvent.type] = true;
}
textarea.addEventListener("compositionupdate", handler, true);
textarea.addEventListener("compositionend", handler, true);
textarea.addEventListener("input", handler, true);
textarea.addEventListener("text", handler, true);
// compositioncommit with different composing string.
textarea.value = "";
synthesizeComposition({ type: "compositionstart" });
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea doesn't have composition string #1");
clearResult();
synthesizeComposition({ type: "compositioncommit", data: "\u3043" });
is(result.compositionupdate, true, "runCompositionCommitTest: compositionupdate should be fired after dispatching compositioncommit #1");
is(result.compositionend, true, "runCompositionCommitTest: compositionend should be fired after dispatching compositioncommit #1");
is(result.text, true, "runCompositionCommitTest: text should be fired after dispatching compositioncommit because it's dispatched when there is compoing string #1");
is(result.input, true, "runCompositionCommitTest: input should be fired after dispatching compositioncommit #1");
is(textarea.value, "\u3043", "runCompositionCommitTest: textarea doesn't have committed string #1");
// compositioncommit with different committed string when there is already committed string
textarea.value = "";
synthesizeComposition({ type: "compositionstart" });
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea doesn't have composition string #2");
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea doesn't have committed string #2");
clearResult();
synthesizeComposition({ type: "compositioncommit", data: "\u3043" });
is(result.compositionupdate, true, "runCompositionCommitTest: compositionupdate should be fired after dispatching compositioncommit #2");
is(result.compositionend, true, "runCompositionCommitTest: compositionend should be fired after dispatching compositioncommit #2");
is(result.text, true, "runCompositionCommitTest: text should be fired after dispatching compositioncommit #2");
is(result.input, true, "runCompositionCommitTest: input should be fired after dispatching compositioncommit #2");
is(textarea.value, "\u3043", "runCompositionCommitTest: textarea doesn't have committed string #2");
// compositioncommit with empty composition string.
textarea.value = "";
synthesizeComposition({ type: "compositionstart" });
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea doesn't have composition string #3");
synthesizeCompositionChange(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
is(textarea.value, "", "runCompositionCommitTest: textarea has non-empty composition string #3");
clearResult();
synthesizeComposition({ type: "compositioncommit", data: "\u3043" });
is(result.compositionupdate, true, "runCompositionCommitTest: compositionupdate should be fired after dispatching compositioncommit #3");
is(result.compositionend, true, "runCompositionCommitTest: compositionend should be fired after dispatching compositioncommit #3");
is(result.text, true, "runCompositionCommitTest: text should be fired after dispatching compositioncommit #3");
is(result.input, true, "runCompositionCommitTest: input should be fired after dispatching compositioncommit #3");
is(textarea.value, "\u3043", "runCompositionCommitTest: textarea doesn't have committed string #3");
// compositioncommit with non-empty composition string.
textarea.value = "";
synthesizeComposition({ type: "compositionstart" });
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea doesn't have composition string #4");
clearResult();
synthesizeComposition({ type: "compositioncommit", data: "" });
is(result.compositionupdate, true, "runCompositionCommitTest: compositionupdate should be fired after dispatching compositioncommit #4");
is(result.compositionend, true, "runCompositionCommitTest: compositionend should be fired after dispatching compositioncommit #4");
is(result.text, true, "runCompositionCommitTest: text should be fired after dispatching compositioncommit #4");
is(result.input, true, "runCompositionCommitTest: input should be fired after dispatching compositioncommit #4");
is(textarea.value, "", "runCompositionCommitTest: textarea should be empty #4");
// compositioncommit immediately after compositionstart
textarea.value = "";
synthesizeComposition({ type: "compositionstart" });
clearResult();
synthesizeComposition({ type: "compositioncommit", data: "\u3042" });
is(result.compositionupdate, true, "runCompositionCommitTest: compositionupdate should be fired after dispatching compositioncommit #5");
is(result.compositionend, true, "runCompositionCommitTest: compositionend should be fired after dispatching compositioncommit #5");
is(result.text, true, "runCompositionCommitTest: text should be fired after dispatching compositioncommit #5");
is(result.input, true, "runCompositionCommitTest: input should be fired after dispatching compositioncommit #5");
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea should be empty #5");
// compositioncommit with same composition string.
textarea.value = "";
synthesizeComposition({ type: "compositionstart" });
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea doesn't have composition string #5");
clearResult();
synthesizeComposition({ type: "compositioncommit", data: "\u3042" });
is(result.compositionupdate, false, "runCompositionCommitTest: compositionupdate shouldn't be fired after dispatching compositioncommit #5");
is(result.compositionend, true, "runCompositionCommitTest: compositionend should be fired after dispatching compositioncommit #5");
is(result.text, true, "runCompositionCommitTest: text should be fired after dispatching compositioncommit because there was composition string #5");
is(result.input, true, "runCompositionCommitTest: input should be fired after dispatching compositioncommit #5");
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea should have committed string #5");
// compositioncommit with same composition string when there is committed string
textarea.value = "";
synthesizeComposition({ type: "compositionstart" });
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea doesn't have composition string #6");
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3042",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea doesn't have composition string #6");
clearResult();
synthesizeComposition({ type: "compositioncommit", data: "\u3042" });
is(result.compositionupdate, false, "runCompositionCommitTest: compositionupdate shouldn't be fired after dispatching compositioncommit #6");
is(result.compositionend, true, "runCompositionCommitTest: compositionend should be fired after dispatching compositioncommit #6");
is(result.text, false, "runCompositionCommitTest: text shouldn't be fired after dispatching compositioncommit because there was already committed string #6");
is(result.input, true, "runCompositionCommitTest: input should be fired after dispatching compositioncommit #6");
is(textarea.value, "\u3042", "runCompositionCommitTest: textarea should have committed string #6");
textarea.removeEventListener("compositionupdate", handler, true);
textarea.removeEventListener("compositionend", handler, true);
textarea.removeEventListener("input", handler, true);
textarea.removeEventListener("text", handler, true);
}
function runCompositionTest()
{
textarea.value = "";
@ -1229,18 +1434,7 @@ function runCompositionTest()
}
// cancel the composition
synthesizeCompositionChange(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
synthesizeComposition({ type: "compositionend", data: "" });
synthesizeComposition({ type: "compositioncommit", data: "" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#3-5") ||
@ -1287,31 +1481,13 @@ function runCompositionTest()
return;
}
synthesizeCompositionChange(
{ "composition":
{ "string": "\u6700",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeComposition({ type: "compositioncommit", data: "\u6700" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#4-3") ||
!checkSelection(5, "", "runCompositionTest", "#4-3")) {
return;
}
synthesizeComposition({ type: "compositionend", data: "\u6700" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#4-4") ||
!checkSelection(5, "", "runCompositionTest", "#4-4")) {
return;
}
// testing the canceling case
synthesizeComposition({ type: "compositionstart" });
@ -1362,31 +1538,13 @@ function runCompositionTest()
return;
}
synthesizeCompositionChange(
{ "composition":
{ "string": "\u9AD8",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeComposition({ type: "compositioncommit", data: "\u9AD8" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u9AD8",
"runCompositionTest", "#4-9") ||
!checkSelection(5, "", "runCompositionTest", "#4-9")) {
return;
}
synthesizeComposition({ type: "compositionend", data: "\u9AD8" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u9AD8",
"runCompositionTest", "#4-10") ||
!checkSelection(5, "", "runCompositionTest", "#4-10")) {
return;
}
synthesizeKey("VK_BACK_SPACE", {});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#4-11") ||
@ -3259,24 +3417,12 @@ function runMaxLengthTest()
}
// commit the composition string
synthesizeCompositionChange(
{ "composition":
{ "string": "\u3058",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
synthesizeComposition({ type: "compositioncommit", data: "\u3058" });
if (!checkContent("\u30E9", kDesc, "#2-2") ||
!checkSelection(1 + 0, "", kDesc, "#2-2")) {
return;
}
synthesizeComposition({ type: "compositionend", data: "\u3058" });
// Undo
synthesizeKey("Z", {accelKey: true});
@ -3377,6 +3523,7 @@ function runTest()
runUndoRedoTest();
runCompositionCommitAsIsTest();
runCompositionCommitTest();
runCompositionTest();
runCompositionEventTest();
runCharAtPointTest(textarea, "textarea in the document");