Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/ImeTest.java

Issue 12093068: Adding missing UpdateTextInputState calls after each ime event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding an Android IME test Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.test.suitebuilder.annotation.MediumTest; 7 import android.test.suitebuilder.annotation.MediumTest;
8 import android.test.suitebuilder.annotation.SmallTest;
9 import android.view.View;
8 import android.view.inputmethod.EditorInfo; 10 import android.view.inputmethod.EditorInfo;
9 11
10 import org.chromium.base.test.util.Feature; 12 import org.chromium.base.test.util.Feature;
13 import org.chromium.content.browser.ImeAdapter.AdapterInputConnection;
14 import org.chromium.content.browser.ImeAdapter.AdapterInputConnectionFactory;
11 import org.chromium.content.browser.test.util.Criteria; 15 import org.chromium.content.browser.test.util.Criteria;
12 import org.chromium.content.browser.test.util.CriteriaHelper; 16 import org.chromium.content.browser.test.util.CriteriaHelper;
13 import org.chromium.content.browser.test.util.DOMUtils; 17 import org.chromium.content.browser.test.util.DOMUtils;
14 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; 18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
15 import org.chromium.content.browser.test.util.UiUtils; 19 import org.chromium.content.browser.test.util.UiUtils;
16 import org.chromium.content_shell.ContentShellTestBase; 20 import org.chromium.content_shell.ContentShellTestBase;
17 21
18 public class ImeTest extends ContentShellTestBase { 22 public class ImeTest extends ContentShellTestBase {
19 23
20 private static final String DATA_URL = 24 private static final String DATA_URL =
21 "data:text/html;utf-8,<html><body>" + 25 "data:text/html;utf-8,<html><body>" +
22 "<input id=\"input_text\" type=\"text\" />" + 26 "<input id=\"input_text\" type=\"text\" />" +
23 "</body></html>"; 27 "</body></html>";
24 28
25 @MediumTest 29 @MediumTest
26 @Feature({"TextInput", "Main"}) 30 @Feature({"TextInput", "Main"})
27 public void testKeyboardDismissedAfterClickingGo() throws Throwable { 31 public void testKeyboardDismissedAfterClickingGo() throws Throwable {
28 launchContentShellWithUrl(DATA_URL); 32 launchContentShellWithUrl(DATA_URL);
29 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); 33 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
30 34
31 final ContentView view = getActivity().getActiveContentView(); 35 final ContentView view = getActivity().getActiveContentView();
32 final TestCallbackHelperContainer viewClient = 36 final TestCallbackHelperContainer viewClient =
33 new TestCallbackHelperContainer(view); 37 new TestCallbackHelperContainer(view);
34 DOMUtils.clickNode(this, view, viewClient, "input_text"); 38 DOMUtils.clickNode(this, view, viewClient, "input_text");
35 assertWaitForKeyboardStatus(true); 39 assertWaitForKeyboardStatus(true);
36 40
37 getAdapterInputConnection().setComposingText("hello", 5); 41 getAdapterInputConnection().setComposingText("hello", 1);
38 getAdapterInputConnection().performEditorAction(EditorInfo.IME_ACTION_GO ); 42 getAdapterInputConnection().performEditorAction(EditorInfo.IME_ACTION_GO );
39 43
40 // Since hiding the keyboard is an asynchronous task, it might take an a rbitrary amount 44 // Since hiding the keyboard is an asynchronous task, it might take an a rbitrary amount
41 // of time. settleDownUI will wait for one second and hopefully allowing the keyboard to 45 // of time. settleDownUI will wait for one second and hopefully allowing the keyboard to
42 // get to it's final state. 46 // get to it's final state.
43 UiUtils.settleDownUI(getInstrumentation()); 47 UiUtils.settleDownUI(getInstrumentation());
44 assertWaitForKeyboardStatus(false); 48 assertWaitForKeyboardStatus(false);
45 } 49 }
46 50
51 @SmallTest
52 @Feature({"TextInput", "Main"})
53 public void testGetTextUpdatesAfterEnteringText() throws Throwable {
54 launchContentShellWithUrl(DATA_URL);
55 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
56
57 getContentViewCore().setAdapterInputConnectionFactory(
58 new TestAdapterInputConnectionFactory());
59
60 final ContentView view = getActivity().getActiveContentView();
61 final TestCallbackHelperContainer viewClient =
62 new TestCallbackHelperContainer(view);
63 DOMUtils.clickNode(this, view, viewClient, "input_text");
64 assertWaitForKeyboardStatus(true);
65
66 TestAdapterInputConnection connection =
67 (TestAdapterInputConnection) getAdapterInputConnection();
68 ImeAdapter adapter = getImeAdapter();
69
70 assertWaitForSetEditableCallback(1, connection);
71 assertEquals("", connection.mText);
72 assertEquals(0, connection.mSelectionStart);
73 assertEquals(0, connection.mSelectionEnd);
74 assertEquals(-1, connection.mCompositionStart);
75 assertEquals(-1, connection.mCompositionEnd);
76
77 adapter.checkCompositionQueueAndCallNative("h", 1, false);
78 assertWaitForSetEditableCallback(2, connection);
79 assertEquals("h", connection.mText);
80 assertEquals(1, connection.mSelectionStart);
81 assertEquals(1, connection.mSelectionEnd);
82 assertEquals(0, connection.mCompositionStart);
83 assertEquals(1, connection.mCompositionEnd);
84
85 adapter.checkCompositionQueueAndCallNative("he", 1, false);
86 assertWaitForSetEditableCallback(3, connection);
87 assertEquals("he", connection.mText);
88 assertEquals(2, connection.mSelectionStart);
89 assertEquals(2, connection.mSelectionEnd);
90 assertEquals(0, connection.mCompositionStart);
91 assertEquals(2, connection.mCompositionEnd);
92
93 adapter.checkCompositionQueueAndCallNative("hel", 1, false);
94 assertWaitForSetEditableCallback(4, connection);
95 assertEquals("hel", connection.mText);
96 assertEquals(3, connection.mSelectionStart);
97 assertEquals(3, connection.mSelectionEnd);
98 assertEquals(0, connection.mCompositionStart);
99 assertEquals(3, connection.mCompositionEnd);
100
101 adapter.checkCompositionQueueAndCallNative("hel", 1, true);
102 assertWaitForSetEditableCallback(5, connection);
103 assertEquals("hel", connection.mText);
104 assertEquals(3, connection.mSelectionStart);
105 assertEquals(3, connection.mSelectionEnd);
106 assertEquals(-1, connection.mCompositionStart);
107 assertEquals(-1, connection.mCompositionEnd);
108 }
109
47 private void assertWaitForKeyboardStatus(final boolean show) throws Throwabl e { 110 private void assertWaitForKeyboardStatus(final boolean show) throws Throwabl e {
48 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { 111 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
49 @Override 112 @Override
50 public boolean isSatisfied() { 113 public boolean isSatisfied() {
51 return show == getImeAdapter().mIsShowWithoutHideOutstanding; 114 return show == getImeAdapter().mIsShowWithoutHideOutstanding;
52 } 115 }
53 })); 116 }));
54 } 117 }
55 118
119 private void assertWaitForSetEditableCallback(final int callbackNumber,
120 final TestAdapterInputConnection connection) throws Throwable {
121 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
122 @Override
123 public boolean isSatisfied() {
124 return callbackNumber == connection.mSetEditableTextCallCounter;
125 }
126 }));
127 }
128
56 private ImeAdapter getImeAdapter() { 129 private ImeAdapter getImeAdapter() {
57 return getContentViewCore().getImeAdapterForTest(); 130 return getContentViewCore().getImeAdapterForTest();
58 } 131 }
59 132
60 private ImeAdapter.AdapterInputConnection getAdapterInputConnection() { 133 private ImeAdapter.AdapterInputConnection getAdapterInputConnection() {
61 return getContentViewCore().getInputConnectionForTest(); 134 return getContentViewCore().getInputConnectionForTest();
62 } 135 }
136
137 static public class TestAdapterInputConnectionFactory extends
Ted C 2013/02/06 00:59:00 public before static....and these should probably
aurimas (slooooooooow) 2013/02/06 02:25:44 Done.
138 ImeAdapter.AdapterInputConnectionFactory {
Ted C 2013/02/06 00:59:00 indent +4
aurimas (slooooooooow) 2013/02/06 02:25:44 Done.
139 @Override
140 public AdapterInputConnection get(View view, ImeAdapter imeAdapter,
141 EditorInfo outAttrs) {
142 return new TestAdapterInputConnection(view, imeAdapter, outAttrs);
143 }
144 }
145
146 static public class TestAdapterInputConnection extends ImeAdapter.AdapterInp utConnection {
Ted C 2013/02/06 00:59:00 same comment as above
aurimas (slooooooooow) 2013/02/06 02:25:44 Done.
147 public int mSetEditableTextCallCounter;
Ted C 2013/02/06 00:59:00 I would make all these protected.
aurimas (slooooooooow) 2013/02/06 02:25:44 Done.
148
149 public String mText;
150 public int mSelectionStart;
151 public int mSelectionEnd;
152 public int mCompositionStart;
153 public int mCompositionEnd;
154
155 public TestAdapterInputConnection(View view, ImeAdapter imeAdapter, Edit orInfo outAttrs) {
156 super(view, imeAdapter, outAttrs);
157 mSetEditableTextCallCounter = 0;
158 }
159
160 @Override
161 public void setEditableText(String text, int selectionStart, int selecti onEnd,
162 int compositionStart, int compositionEnd) {
163 mText = text;
164 mSelectionStart = selectionStart;
165 mSelectionEnd = selectionEnd;
166 mCompositionStart = compositionStart;
167 mCompositionEnd = compositionEnd;
168 mSetEditableTextCallCounter++;
169 }
170 }
63 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698