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.content.Context;
8 import android.os.IBinder;
9 import android.os.ResultReceiver;
10 import android.test.UiThreadTest;
11 import android.test.suitebuilder.annotation.SmallTest;
12 import android.view.View;
13 import android.widget.EditText;
15 import org.chromium.content.browser.input.InputMethodManagerWrapper;
16 import org.chromium.content_shell.R;
17 import org.chromium.content_shell_apk.ContentShellTestBase;
20 * Test that content view core responds to focus changes correctly.
22 public class ContentViewCoreFocusTest extends ContentShellTestBase {
23 private static class TestInputMethodManagerWrapper extends InputMethodManagerWrapper {
24 private boolean mHidden = false;
25 public TestInputMethodManagerWrapper(Context context) {
30 public void showSoftInput(View view, int flags, ResultReceiver resultReceiver) {
35 public boolean hideSoftInputFromWindow(IBinder windowToken, int flags,
36 ResultReceiver resultReceiver) {
42 public boolean isActive(View view) {
46 public boolean isHidden() {
52 @RerunWithUpdatedContainerView
54 public void testHideImeOnLosingFocus() throws Throwable {
55 // Test the IME window is hidden from the content view when the content
56 // view loses its focus
57 final ContentViewCore contentViewCore = getContentViewCore();
58 final View view = contentViewCore.getContainerView();
59 final TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(getActivity());
60 assertTrue(view.requestFocus());
62 contentViewCore.setInputMethodManagerWrapperForTest(immw);
64 immw.showSoftInput(view, 0, null);
65 assertFalse(immw.isHidden());
67 final EditText urlBox = (EditText) getActivity().findViewById(R.id.url);
69 assertTrue(urlBox.requestFocus());
71 // Now another view has taken focus. The original view loses its focus
72 // and the input method window should be hidden
73 assertTrue(immw.isHidden());