1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.content.browser;
7 import android.test.suitebuilder.annotation.SmallTest;
8 import android.view.inputmethod.EditorInfo;
10 import org.chromium.content.browser.input.AdapterInputConnection;
11 import org.chromium.content.browser.input.ImeAdapter;
12 import org.chromium.content.browser.input.InputMethodManagerWrapper;
13 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
14 import org.chromium.content_shell_apk.ContentShellTestBase;
17 * Tests that when InputConnection is recreated, the text is still retained.
19 public class ContentViewCoreInputConnectionTest extends ContentShellTestBase {
20 private ContentViewCore mContentViewCore;
21 private TestImeAdapter mImeAdapter;
22 private TestInputMethodManagerWrapper mInputMethodManagerWrapper;
24 private static class TestImeAdapter extends ImeAdapter {
25 public TestImeAdapter(InputMethodManagerWrapper immw) {
29 public boolean hasTextInputType() {
35 public void setUp() throws Exception {
37 mContentViewCore = new ContentViewCore(getActivity());
38 mInputMethodManagerWrapper = new TestInputMethodManagerWrapper(mContentViewCore);
39 mImeAdapter = new TestImeAdapter(mInputMethodManagerWrapper);
40 mImeAdapter.setInputMethodManagerWrapper(new TestInputMethodManagerWrapper(
42 mContentViewCore.setImeAdapterForTest(mImeAdapter);
43 mContentViewCore.createContentViewAndroidDelegate();
44 mContentViewCore.setContainerView(getActivity().getActiveShell().getContentView());
48 * When creating a new InputConnection (e.g. after switching software keyboard), make sure the
49 * text content in the Editable is not lost.
52 @RerunWithUpdatedContainerView
53 public void testRecreateInputConnection() throws Exception {
54 EditorInfo info = new EditorInfo();
56 mContentViewCore.onCreateInputConnection(info);
57 AdapterInputConnection adapter = mContentViewCore.getAdapterInputConnectionForTest();
58 adapter.updateState("Is this text restored?", 0, 0, 0, 0, true);
60 String text = mContentViewCore.getEditableForTest().toString();
61 assertEquals("Check if the initial text is stored.", "Is this text restored?", text);
63 // Create a new InputConnection.
64 EditorInfo info2 = new EditorInfo();
65 mContentViewCore.onCreateInputConnection(info2);
67 String newtext = mContentViewCore.getEditableForTest().toString();
68 assertEquals("Check if the string is restored.", "Is this text restored?", newtext);