summaryrefslogtreecommitdiffstats
path: root/dom/inputmethod/mochitest/test_basic.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/inputmethod/mochitest/test_basic.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/inputmethod/mochitest/test_basic.html')
-rw-r--r--dom/inputmethod/mochitest/test_basic.html212
1 files changed, 212 insertions, 0 deletions
diff --git a/dom/inputmethod/mochitest/test_basic.html b/dom/inputmethod/mochitest/test_basic.html
new file mode 100644
index 000000000..bf22e99dd
--- /dev/null
+++ b/dom/inputmethod/mochitest/test_basic.html
@@ -0,0 +1,212 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=932145
+-->
+<head>
+ <title>Basic test for InputMethod API.</title>
+ <script type="application/javascript;version=1.7" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript;version=1.7" src="inputmethod_common.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=932145">Mozilla Bug 932145</a>
+<p id="display"></p>
+<pre id="test">
+<script class="testbody" type="application/javascript;version=1.7">
+
+SimpleTest.requestFlakyTimeout("untriaged");
+
+// The input context.
+var gContext = null;
+
+inputmethod_setup(function() {
+ runTest();
+});
+
+function runTest() {
+ let im = navigator.mozInputMethod;
+
+ im.oninputcontextchange = function() {
+ ok(true, 'inputcontextchange event was fired.');
+ im.oninputcontextchange = null;
+
+ gContext = im.inputcontext;
+ if (!gContext) {
+ ok(false, 'Should have a non-null inputcontext.');
+ inputmethod_cleanup();
+ return;
+ }
+
+ is(gContext.type, 'input', 'The input context type should match.');
+ is(gContext.inputType, 'text', 'The inputType should match.');
+ is(gContext.inputMode, 'verbatim', 'The inputMode should match.');
+ is(gContext.lang, 'zh', 'The language should match.');
+ is(gContext.text, 'Yuan', 'Should get the text.');
+ is(gContext.textBeforeCursor + gContext.textAfterCursor, 'Yuan',
+ 'Should get the text around the cursor.');
+
+ test_setSelectionRange();
+ };
+
+ // Set current page as an input method.
+ SpecialPowers.wrap(im).setActive(true);
+
+ let iframe = document.createElement('iframe');
+ iframe.src = 'file_test_app.html';
+ iframe.setAttribute('mozbrowser', true);
+ document.body.appendChild(iframe);
+}
+
+function test_setSelectionRange() {
+ // Move cursor position to 2.
+ gContext.setSelectionRange(2, 0).then(function() {
+ is(gContext.selectionStart, 2, 'selectionStart was set successfully.');
+ is(gContext.selectionEnd, 2, 'selectionEnd was set successfully.');
+ test_sendKey();
+ }, function(e) {
+ ok(false, 'setSelectionRange failed:' + e.name);
+ console.error(e);
+ inputmethod_cleanup();
+ });
+}
+
+function test_sendKey() {
+ // Add '-' to current cursor posistion and move the cursor position to 3.
+ gContext.sendKey(0, '-'.charCodeAt(0), 0).then(function() {
+ is(gContext.text, 'Yu-an',
+ 'sendKey should changed the input field correctly.');
+ is(gContext.textBeforeCursor + gContext.textAfterCursor, 'Yu-an',
+ 'sendKey should changed the input field correctly.');
+ test_deleteSurroundingText();
+ }, function(e) {
+ ok(false, 'sendKey failed:' + e.name);
+ inputmethod_cleanup();
+ });
+}
+
+function test_deleteSurroundingText() {
+ // Remove one character before current cursor position and move the cursor
+ // position back to 2.
+ gContext.deleteSurroundingText(-1, 1).then(function() {
+ ok(true, 'deleteSurroundingText finished');
+ is(gContext.text, 'Yuan',
+ 'deleteSurroundingText should changed the input field correctly.');
+ is(gContext.textBeforeCursor + gContext.textAfterCursor, 'Yuan',
+ 'deleteSurroundingText should changed the input field correctly.');
+ test_replaceSurroundingText();
+ }, function(e) {
+ ok(false, 'deleteSurroundingText failed:' + e.name);
+ inputmethod_cleanup();
+ });
+}
+
+function test_replaceSurroundingText() {
+ // Replace 'Yuan' with 'Xulei'.
+ gContext.replaceSurroundingText('Xulei', -2, 4).then(function() {
+ ok(true, 'replaceSurroundingText finished');
+ is(gContext.text, 'Xulei',
+ 'replaceSurroundingText changed the input field correctly.');
+ is(gContext.textBeforeCursor + gContext.textAfterCursor, 'Xulei',
+ 'replaceSurroundingText changed the input field correctly.');
+ test_setComposition();
+ }, function(e) {
+ ok(false, 'replaceSurroundingText failed: ' + e.name);
+ inputmethod_cleanup();
+ });
+}
+
+function test_setComposition() {
+ gContext.setComposition('XXX').then(function() {
+ ok(true, 'setComposition finished');
+ test_endComposition();
+ }, function(e) {
+ ok(false, 'setComposition failed: ' + e.name);
+ inputmethod_cleanup();
+ });
+}
+
+function test_endComposition() {
+ gContext.endComposition('2013').then(function() {
+ is(gContext.text, 'Xulei2013',
+ 'endComposition changed the input field correctly.');
+ is(gContext.textBeforeCursor + gContext.textAfterCursor, 'Xulei2013',
+ 'endComposition changed the input field correctly.');
+ test_onSelectionChange();
+ }, function (e) {
+ ok(false, 'endComposition failed: ' + e.name);
+ inputmethod_cleanup();
+ });
+}
+
+function test_onSelectionChange() {
+ var sccTimeout = setTimeout(function() {
+ ok(false, 'selectionchange event not fired');
+ cleanup(true);
+ }, 3000);
+
+ function cleanup(failed) {
+ gContext.onselectionchange = null;
+ clearTimeout(sccTimeout);
+ if (failed) {
+ inputmethod_cleanup();
+ }
+ else {
+ test_onSurroundingTextChange();
+ }
+ }
+
+ gContext.onselectionchange = function(evt) {
+ ok(true, 'onselectionchange fired');
+ is(evt.detail.selectionStart, 10);
+ is(evt.detail.selectionEnd, 10);
+ ok(evt.detail.ownAction);
+ };
+
+ gContext.sendKey(0, 'j'.charCodeAt(0), 0).then(function() {
+ cleanup();
+ }, function(e) {
+ ok(false, 'sendKey failed: ' + e.name);
+ cleanup(true);
+ });
+}
+
+function test_onSurroundingTextChange() {
+ var sccTimeout = setTimeout(function() {
+ ok(false, 'surroundingtextchange event not fired');
+ cleanup(true);
+ }, 3000);
+
+ function cleanup(failed) {
+ gContext.onsurroundingtextchange = null;
+ clearTimeout(sccTimeout);
+ if (failed) {
+ inputmethod_cleanup();
+ }
+ else {
+ // in case we want more tests leave this
+ inputmethod_cleanup();
+ }
+ }
+
+ gContext.onsurroundingtextchange = function(evt) {
+ ok(true, 'onsurroundingtextchange fired');
+ is(evt.detail.text, 'Xulei2013jj');
+ is(evt.detail.textBeforeCursor, 'Xulei2013jj');
+ is(evt.detail.textAfterCursor, '');
+ ok(evt.detail.ownAction);
+ };
+
+ gContext.sendKey(0, 'j'.charCodeAt(0), 0).then(function() {
+ cleanup();
+ }, function(e) {
+ ok(false, 'sendKey failed: ' + e.name);
+ cleanup(true);
+ });
+}
+
+</script>
+</pre>
+</body>
+</html>
+