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

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

Issue 1278593004: Introduce ThreadedInputConnection behind a switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: handles render crash and navigation Created 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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.input; 5 package org.chromium.content.browser.input;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.Handler;
8 import android.os.IBinder; 9 import android.os.IBinder;
10 import android.os.Looper;
9 import android.os.ResultReceiver; 11 import android.os.ResultReceiver;
10 import android.test.suitebuilder.annotation.MediumTest; 12 import android.test.suitebuilder.annotation.MediumTest;
11 import android.test.suitebuilder.annotation.SmallTest; 13 import android.test.suitebuilder.annotation.SmallTest;
14 import android.text.Editable;
12 import android.view.View; 15 import android.view.View;
13 import android.view.inputmethod.EditorInfo; 16 import android.view.inputmethod.EditorInfo;
14 17
15 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
16 import org.chromium.content.browser.input.AdapterInputConnection.ImeState; 19 import org.chromium.content.browser.input.ChromiumBaseInputConnection.ThreadMana ger;
20 import org.chromium.content.browser.input.ReplicaInputConnection.ImeState;
17 import org.chromium.content_shell_apk.ContentShellTestBase; 21 import org.chromium.content_shell_apk.ContentShellTestBase;
22 import org.chromium.ui.base.ime.TextInputType;
18 23
19 import java.util.ArrayList; 24 import java.util.ArrayList;
20 25
21 /** 26 /**
22 * Tests AdapterInputConnection class and its callbacks to ImeAdapter. 27 * Tests AdapterInputConnection class and its callbacks to ImeAdapter.
23 */ 28 */
24 public class AdapterInputConnectionTest extends ContentShellTestBase { 29 public class ReplicaInputConnectionTest extends ContentShellTestBase {
25 30
26 private AdapterInputConnection mConnection; 31 private ReplicaInputConnection mConnection;
27 private TestInputMethodManagerWrapper mWrapper; 32 private TestInputMethodManagerWrapper mWrapper;
28 private TestImeAdapter mImeAdapter; 33 private TestImeAdapter mImeAdapter;
29 34
30 @Override 35 @Override
31 public void setUp() throws Exception { 36 public void setUp() throws Exception {
32 super.setUp(); 37 super.setUp();
33 launchContentShellWithUrl("about:blank"); 38 launchContentShellWithUrl("about:blank");
34 waitForActiveShellToBeDoneLoading(); 39 waitForActiveShellToBeDoneLoading();
35 mWrapper = new TestInputMethodManagerWrapper(getActivity()); 40 mWrapper = new TestInputMethodManagerWrapper(getActivity());
36 TestImeAdapterDelegate imeAdapterDelegate = 41 TestImeAdapterDelegate imeAdapterDelegate =
37 new TestImeAdapterDelegate(getContentViewCore().getContainerView ()); 42 new TestImeAdapterDelegate(getContentViewCore().getContainerView ());
38 mImeAdapter = new TestImeAdapter(mWrapper, imeAdapterDelegate); 43 mImeAdapter = new TestImeAdapter(mWrapper, imeAdapterDelegate);
39 mConnection = new AdapterInputConnection( 44 Editable editable = Editable.Factory.getInstance().newEditable("");
40 getContentViewCore().getContainerView(), mImeAdapter, 0, 0, new EditorInfo()); 45 ThreadManager threadManager = new ChromiumBaseInputConnection.ThreadMana ger(
46 new Handler(Looper.getMainLooper()));
47
48 mConnection = new ReplicaInputConnection(getContentViewCore().getContain erView(),
49 mImeAdapter, threadManager, editable, TextInputType.TEXT, 0, new EditorInfo());
41 } 50 }
42 51
43 @SmallTest 52 @SmallTest
44 @Feature({"TextInput", "Main"}) 53 @Feature({"TextInput", "Main"})
45 public void testAdjustLengthBeforeAndAfterSelection() throws Throwable { 54 public void testAdjustLengthBeforeAndAfterSelection() throws Throwable {
46 final String ga = "\uAC00"; 55 final String ga = "\uAC00";
47 final String smiley = "\uD83D\uDE0A"; // multi character codepoint 56 final String smiley = "\uD83D\uDE0A"; // multi character codepoint
48 57
49 // No need to adjust length. 58 // No need to adjust length.
50 assertFalse(AdapterInputConnection.isIndexBetweenUtf16SurrogatePair("a", 0)); 59 assertFalse(ReplicaInputConnection.isIndexBetweenUtf16SurrogatePair("a", 0));
51 assertFalse(AdapterInputConnection.isIndexBetweenUtf16SurrogatePair(ga, 0)); 60 assertFalse(ReplicaInputConnection.isIndexBetweenUtf16SurrogatePair(ga, 0));
52 assertFalse(AdapterInputConnection.isIndexBetweenUtf16SurrogatePair("aa" , 1)); 61 assertFalse(ReplicaInputConnection.isIndexBetweenUtf16SurrogatePair("aa" , 1));
53 assertFalse(AdapterInputConnection.isIndexBetweenUtf16SurrogatePair("a" + smiley + "a", 1)); 62 assertFalse(ReplicaInputConnection.isIndexBetweenUtf16SurrogatePair("a" + smiley + "a", 1));
54 63
55 // Needs to adjust length. 64 // Needs to adjust length.
56 assertTrue(AdapterInputConnection.isIndexBetweenUtf16SurrogatePair(smile y, 1)); 65 assertTrue(ReplicaInputConnection.isIndexBetweenUtf16SurrogatePair(smile y, 1));
57 assertTrue(AdapterInputConnection.isIndexBetweenUtf16SurrogatePair(smile y + "a", 1)); 66 assertTrue(ReplicaInputConnection.isIndexBetweenUtf16SurrogatePair(smile y + "a", 1));
58 } 67 }
59 68
60 @MediumTest 69 @MediumTest
61 @Feature({"TextInput", "Main"}) 70 @Feature({"TextInput", "Main"})
62 @RerunWithUpdatedContainerView
63 public void testSetComposingText() throws Throwable { 71 public void testSetComposingText() throws Throwable {
72 assertEquals(0, mWrapper.getUpdateSelectionCallCount());
73
64 mConnection.setComposingText("t", 1); 74 mConnection.setComposingText("t", 1);
65 assertCorrectState("t", 1, 1, 0, 1, mConnection.getImeStateForTesting()) ; 75 assertCorrectState("t", 1, 1, 0, 1, mConnection.getImeStateForTesting()) ;
66 mWrapper.verifyUpdateSelectionCall(0, 1, 1, 0, 1); 76 mWrapper.verifyUpdateSelectionCall(0, 1, 1, 0, 1);
77 // BaseInputConnection calls updateSelection() one more time because get Editable() does
78 // not return a correct value here.
79 mWrapper.verifyUpdateSelectionCall(1, 1, 1, 0, 1);
80 assertEquals(2, mWrapper.getUpdateSelectionCallCount());
67 81
68 mConnection.setComposingText("te", 1); 82 mConnection.setComposingText("te", 1);
69 assertCorrectState("te", 2, 2, 0, 2, mConnection.getImeStateForTesting() ); 83 assertCorrectState("te", 2, 2, 0, 2, mConnection.getImeStateForTesting() );
70 mWrapper.verifyUpdateSelectionCall(1, 2, 2, 0, 2); 84 mWrapper.verifyUpdateSelectionCall(2, 2, 2, 0, 2);
85 mWrapper.verifyUpdateSelectionCall(3, 2, 2, 0, 2);
71 86
72 mConnection.setComposingText("tes", 1); 87 mConnection.setComposingText("tes", 1);
73 assertCorrectState("tes", 3, 3, 0, 3, mConnection.getImeStateForTesting( )); 88 assertCorrectState("tes", 3, 3, 0, 3, mConnection.getImeStateForTesting( ));
74 mWrapper.verifyUpdateSelectionCall(2, 3, 3, 0, 3); 89 mWrapper.verifyUpdateSelectionCall(4, 3, 3, 0, 3);
90 mWrapper.verifyUpdateSelectionCall(5, 3, 3, 0, 3);
75 91
76 mConnection.setComposingText("test", 1); 92 mConnection.setComposingText("test", 1);
77 assertCorrectState("test", 4, 4, 0, 4, mConnection.getImeStateForTesting ()); 93 assertCorrectState("test", 4, 4, 0, 4, mConnection.getImeStateForTesting ());
78 mWrapper.verifyUpdateSelectionCall(3, 4, 4, 0, 4); 94 mWrapper.verifyUpdateSelectionCall(6, 4, 4, 0, 4);
95 mWrapper.verifyUpdateSelectionCall(7, 4, 4, 0, 4);
79 } 96 }
80 97
81 @MediumTest 98 @MediumTest
82 @Feature({"TextInput", "Main"}) 99 @Feature({"TextInput", "Main"})
83 public void testSelectionUpdatesDuringBatch() throws Throwable { 100 public void testSelectionUpdatesDuringBatch() throws Throwable {
84 mConnection.beginBatchEdit(); 101 mConnection.beginBatchEdit();
85 mConnection.setComposingText("t", 1); 102 mConnection.setComposingText("t", 1);
86 assertEquals(0, mWrapper.getUpdateSelectionCallCount()); 103 assertEquals(0, mWrapper.getUpdateSelectionCallCount());
87 mConnection.setComposingText("te", 1); 104 mConnection.setComposingText("te", 1);
88 assertEquals(0, mWrapper.getUpdateSelectionCallCount()); 105 assertEquals(0, mWrapper.getUpdateSelectionCallCount());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 174
158 private static void assertCorrectState(String text, int selectionStart, int selectionEnd, 175 private static void assertCorrectState(String text, int selectionStart, int selectionEnd,
159 int compositionStart, int compositionEnd, ImeState actual) { 176 int compositionStart, int compositionEnd, ImeState actual) {
160 assertEquals("Text did not match", text, actual.text); 177 assertEquals("Text did not match", text, actual.text);
161 assertEquals("Selection start did not match", selectionStart, actual.sel ectionStart); 178 assertEquals("Selection start did not match", selectionStart, actual.sel ectionStart);
162 assertEquals("Selection end did not match", selectionEnd, actual.selecti onEnd); 179 assertEquals("Selection end did not match", selectionEnd, actual.selecti onEnd);
163 assertEquals("Composition start did not match", compositionStart, actual .compositionStart); 180 assertEquals("Composition start did not match", compositionStart, actual .compositionStart);
164 assertEquals("Composition end did not match", compositionEnd, actual.com positionEnd); 181 assertEquals("Composition end did not match", compositionEnd, actual.com positionEnd);
165 } 182 }
166 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698