Bug 1057898 - Add a test for tapping between two inputs. r=yxl
☠☠ backed out by 9b3fbc370631 ☠ ☠
authorTim Chien <timdream@gmail.com>
Wed, 27 Aug 2014 03:21:00 -0400
changeset 223987 de5cefa8e52e34a979b5fef169b55f5fa8dd027b
parent 223986 5f66ff9f11f2c5e2c6a8b35c9b234c0e51659e07
child 223988 afaa2a2dd1cf08af8fbcaa306fc98f61ba609724
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyxl
bugs1057898
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1057898 - Add a test for tapping between two inputs. r=yxl
dom/inputmethod/mochitest/mochitest.ini
dom/inputmethod/mochitest/test_delete_focused_element.html
dom/inputmethod/mochitest/test_two_inputs.html
--- a/dom/inputmethod/mochitest/mochitest.ini
+++ b/dom/inputmethod/mochitest/mochitest.ini
@@ -14,8 +14,9 @@ support-files =
 [test_bug949059.html]
 [test_bug953044.html]
 [test_bug960946.html]
 [test_bug978918.html]
 [test_bug1026997.html]
 [test_bug1043828.html]
 [test_delete_focused_element.html]
 [test_sendkey_cancel.html]
+[test_two_inputs.html]
--- a/dom/inputmethod/mochitest/test_delete_focused_element.html
+++ b/dom/inputmethod/mochitest/test_delete_focused_element.html
@@ -29,17 +29,20 @@ function appFrameScript() {
   content.document.body.appendChild(textarea);
 
   textarea.onfocus = function() {
     textarea.parentNode.removeChild(textarea);
     sendAsyncMessage('test:InputMethod:finished', {});
   };
 
   content.setTimeout(function() {
-    textarea.focus();
+    content.setTimeout(function() {
+      textarea.focus();
+    }, 10);
+
     input.parentNode.removeChild(input);
   }, 0);
 }
 
 function runTest() {
   var timeoutId = null;
 
   // Create an app frame to recieve keyboard inputs.
new file mode 100644
--- /dev/null
+++ b/dom/inputmethod/mochitest/test_two_inputs.html
@@ -0,0 +1,106 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1057898
+-->
+<head>
+  <title>Test switching between two inputs</title>
+  <script type="application/javascript;version=1.7" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript;version=1.7" src="inputmethod_common.js"></script>
+  <link rel="stylesheet" type="text/css" href="/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">
+
+// The input context.
+var gContext = null;
+
+inputmethod_setup(function() {
+  runTest();
+});
+
+let appFrameScript = function appFrameScript() {
+  let input1 = content.document.body.firstElementChild;
+  let input2 = content.document.body.children[1];
+
+  let i = 0;
+
+  input1.focus();
+
+  addMessageListener('test:next', function() {
+    i++;
+    switch (i) {
+      case 1:
+        input2.focus();
+
+        break;
+
+      case 2:
+        input2.blur();
+
+        break;
+    }
+  });
+};
+
+function runTest() {
+  let im = navigator.mozInputMethod;
+
+  let i = 0;
+  im.oninputcontextchange = function(evt) {
+    var inputcontext = navigator.mozInputMethod.inputcontext;
+
+    i++;
+    switch (i) {
+      case 1:
+        ok(!!inputcontext, 'Receving the first input context');
+        is(inputcontext.textAfterCursor, 'First');
+
+        mm.sendAsyncMessage('test:next');
+        break;
+
+      case 2:
+        ok(!!inputcontext, 'Receving the second input context');
+        is(inputcontext.textAfterCursor, 'Second');
+
+
+        mm.sendAsyncMessage('test:next');
+        break;
+
+      case 3:
+        is(inputcontext, null, 'Receving null inputcontext');
+
+        inputmethod_cleanup();
+        break;
+
+      default:
+        ok(false, 'Receving extra inputcontextchange calls');
+        inputmethod_cleanup();
+
+        break;
+    }
+  };
+
+  // Set current page as an input method.
+  SpecialPowers.wrap(im).setActive(true);
+
+  let iframe = document.createElement('iframe');
+  iframe.src = 'data:text/html,<html><body><input value="First"><input value="Second"></body></html>';
+  iframe.setAttribute('mozbrowser', true);
+  document.body.appendChild(iframe);
+
+  let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
+
+  iframe.addEventListener('mozbrowserloadend', function() {
+    mm.loadFrameScript('data:,(' + encodeURIComponent(appFrameScript.toString()) + ')();', false);
+  });
+}
+
+</script>
+</pre>
+</body>
+</html>
+