OLD | NEW |
(Empty) | |
| 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. |
| 4 // |
| 5 package org.chromium.content.browser; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.test.suitebuilder.annotation.SmallTest; |
| 9 import android.view.KeyEvent; |
| 10 |
| 11 import org.chromium.content.browser.input.ImeAdapter; |
| 12 import org.chromium.content_shell_apk.ContentShellTestBase; |
| 13 |
| 14 /** |
| 15 * Tests that ContentViewCore responds to DPAD key events correctly |
| 16 */ |
| 17 public class ContentViewCoreDpadTest extends ContentShellTestBase { |
| 18 TestContentViewCore mContentViewCore; |
| 19 private static class TestImeAdapter extends ImeAdapter { |
| 20 public TestImeAdapter() { |
| 21 super(null, null); |
| 22 } |
| 23 |
| 24 @Override |
| 25 public boolean dispatchKeyEvent(KeyEvent event) { |
| 26 return true; |
| 27 } |
| 28 } |
| 29 |
| 30 private static class TestContentViewCore extends ContentViewCore { |
| 31 private boolean mIsShowImeIfNeededCalled = false; |
| 32 public TestContentViewCore(Context context) { |
| 33 super(context); |
| 34 } |
| 35 |
| 36 public boolean isShowImeIfNeededCalled() { |
| 37 return mIsShowImeIfNeededCalled; |
| 38 } |
| 39 |
| 40 @Override |
| 41 public void showImeIfNeeded() { |
| 42 mIsShowImeIfNeededCalled = true; |
| 43 } |
| 44 } |
| 45 |
| 46 public void setUp() throws Exception { |
| 47 super.setUp(); |
| 48 mContentViewCore = new TestContentViewCore(getActivity()); |
| 49 mContentViewCore.setImeAdapterForTest(new TestImeAdapter()); |
| 50 } |
| 51 |
| 52 @SmallTest |
| 53 // Test KEYCODE_DPAD_CENTER keyevent will bring up the IME, if needed |
| 54 public void testDpadCenterBringsUpIme() throws Exception { |
| 55 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPA
D_CENTER); |
| 56 |
| 57 mContentViewCore.dispatchKeyEvent(event); |
| 58 |
| 59 // Just assert showImeIfNeeded is called. Software keyboard may not show
if a QWERTY |
| 60 // keyboard is connected or if the focused object is not editable. |
| 61 assertTrue(mContentViewCore.isShowImeIfNeededCalled()); |
| 62 } |
| 63 } |
OLD | NEW |