OLD | NEW |
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.app.Activity; | 7 import android.app.Activity; |
8 import android.content.ClipData; | 8 import android.content.ClipData; |
9 import android.content.ClipboardManager; | 9 import android.content.ClipboardManager; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.res.Configuration; | 11 import android.content.res.Configuration; |
12 import android.os.Handler; | 12 import android.os.Handler; |
13 import android.os.Looper; | 13 import android.os.Looper; |
14 import android.test.suitebuilder.annotation.MediumTest; | 14 import android.test.suitebuilder.annotation.MediumTest; |
15 import android.test.suitebuilder.annotation.SmallTest; | 15 import android.test.suitebuilder.annotation.SmallTest; |
16 import android.text.InputType; | 16 import android.text.InputType; |
17 import android.text.TextUtils; | 17 import android.text.TextUtils; |
18 import android.util.Pair; | 18 import android.util.Pair; |
19 import android.view.KeyEvent; | 19 import android.view.KeyEvent; |
20 import android.view.View; | 20 import android.view.View; |
21 import android.view.inputmethod.BaseInputConnection; | 21 import android.view.inputmethod.BaseInputConnection; |
22 import android.view.inputmethod.EditorInfo; | 22 import android.view.inputmethod.EditorInfo; |
23 import android.view.inputmethod.InputConnection; | 23 import android.view.inputmethod.InputConnection; |
24 | 24 |
25 import org.chromium.base.ThreadUtils; | 25 import org.chromium.base.ThreadUtils; |
26 import org.chromium.base.test.util.CommandLineFlags; | 26 import org.chromium.base.test.util.CommandLineFlags; |
27 import org.chromium.base.test.util.DisabledTest; | 27 import org.chromium.base.test.util.DisabledTest; |
28 import org.chromium.base.test.util.Feature; | 28 import org.chromium.base.test.util.Feature; |
29 import org.chromium.base.test.util.RetryOnFailure; | 29 import org.chromium.base.test.util.RetryOnFailure; |
| 30 import org.chromium.base.test.util.UrlUtils; |
30 import org.chromium.base.test.util.parameter.Parameter; | 31 import org.chromium.base.test.util.parameter.Parameter; |
31 import org.chromium.base.test.util.parameter.ParameterizedTest; | 32 import org.chromium.base.test.util.parameter.ParameterizedTest; |
32 import org.chromium.content.browser.ContentViewCore; | 33 import org.chromium.content.browser.ContentViewCore; |
33 import org.chromium.content.browser.test.util.Criteria; | 34 import org.chromium.content.browser.test.util.Criteria; |
34 import org.chromium.content.browser.test.util.CriteriaHelper; | 35 import org.chromium.content.browser.test.util.CriteriaHelper; |
35 import org.chromium.content.browser.test.util.DOMUtils; | 36 import org.chromium.content.browser.test.util.DOMUtils; |
36 import org.chromium.content.browser.test.util.JavaScriptUtils; | 37 import org.chromium.content.browser.test.util.JavaScriptUtils; |
37 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 38 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
38 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; | 39 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; |
39 import org.chromium.content_public.browser.WebContents; | 40 import org.chromium.content_public.browser.WebContents; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 waitForKeyboardStates(1, 0, 1, new Integer[] {TextInputType.TEXT}); | 112 waitForKeyboardStates(1, 0, 1, new Integer[] {TextInputType.TEXT}); |
112 assertEquals(0, mConnectionFactory.getOutAttrs().initialSelStart); | 113 assertEquals(0, mConnectionFactory.getOutAttrs().initialSelStart); |
113 assertEquals(0, mConnectionFactory.getOutAttrs().initialSelEnd); | 114 assertEquals(0, mConnectionFactory.getOutAttrs().initialSelEnd); |
114 | 115 |
115 waitForEventLogs("selectionchange"); | 116 waitForEventLogs("selectionchange"); |
116 clearEventLogs(); | 117 clearEventLogs(); |
117 | 118 |
118 resetAllStates(); | 119 resetAllStates(); |
119 } | 120 } |
120 | 121 |
| 122 private void fullyLoadUrl(final String url) throws Throwable { |
| 123 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 124 @Override |
| 125 public void run() { |
| 126 getActivity().getActiveShell().loadUrl(url); |
| 127 } |
| 128 }); |
| 129 waitForActiveShellToBeDoneLoading(); |
| 130 } |
| 131 |
| 132 @MediumTest |
| 133 @Feature({"TextInput", "Main"}) |
| 134 @RetryOnFailure |
| 135 public void testKeyboardDismissedWhenNavigating() throws Throwable { |
| 136 assertWaitForKeyboardStatus(true); |
| 137 |
| 138 // Hide keyboard when loading a new Url. |
| 139 fullyLoadUrl(UrlUtils.getIsolatedTestFileUrl(INPUT_FORM_HTML)); |
| 140 assertWaitForKeyboardStatus(false); |
| 141 |
| 142 DOMUtils.clickNode(this, mContentViewCore, "input_text"); |
| 143 assertWaitForKeyboardStatus(true); |
| 144 |
| 145 // Hide keyboard when navigating. |
| 146 final String code = "document.getElementById(\"link\").click()"; |
| 147 JavaScriptUtils.executeJavaScriptAndWaitForResult( |
| 148 getContentViewCore().getWebContents(), code); |
| 149 assertWaitForKeyboardStatus(false); |
| 150 } |
| 151 |
121 @MediumTest | 152 @MediumTest |
122 @Feature({"TextInput", "Main"}) | 153 @Feature({"TextInput", "Main"}) |
123 public void testKeyboardDismissedAfterClickingGo() throws Throwable { | 154 public void testKeyboardDismissedAfterClickingGo() throws Throwable { |
124 setComposingText("hello", 1); | 155 setComposingText("hello", 1); |
125 waitAndVerifyUpdateSelection(0, 5, 5, 0, 5); | 156 waitAndVerifyUpdateSelection(0, 5, 5, 0, 5); |
126 | 157 |
127 performGo(mCallbackContainer); | 158 performGo(mCallbackContainer); |
128 | 159 |
129 assertWaitForKeyboardStatus(false); | 160 assertWaitForKeyboardStatus(false); |
130 } | 161 } |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 | 660 |
630 private void onConfigurationChanged(final Configuration config) { | 661 private void onConfigurationChanged(final Configuration config) { |
631 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 662 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
632 @Override | 663 @Override |
633 public void run() { | 664 public void run() { |
634 mContentViewCore.onConfigurationChanged(config); | 665 mContentViewCore.onConfigurationChanged(config); |
635 } | 666 } |
636 }); | 667 }); |
637 } | 668 } |
638 | 669 |
639 private void reloadPage() { | 670 private void reloadPage() throws Throwable { |
640 // Reload the page, then focus will be lost and keyboard should be hidde
n. | 671 // Reload the page, then focus will be lost and keyboard should be hidde
n. |
641 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 672 fullyLoadUrl(getContentViewCore().getWebContents().getUrl()); |
642 @Override | |
643 public void run() { | |
644 final String currentUrl = getContentViewCore().getWebContents().
getUrl(); | |
645 getActivity().getActiveShell().loadUrl(currentUrl); | |
646 } | |
647 }); | |
648 } | 673 } |
649 | 674 |
650 @SmallTest | 675 @SmallTest |
651 @Feature({"TextInput"}) | 676 @Feature({"TextInput"}) |
652 @RetryOnFailure | 677 @RetryOnFailure |
653 public void testPhysicalKeyboard_AttachDetach() throws Exception { | 678 public void testPhysicalKeyboard_AttachDetach() throws Throwable { |
654 attachPhysicalKeyboard(); | 679 attachPhysicalKeyboard(); |
655 // We still call showSoftKeyboard, which will be ignored by physical key
board. | 680 // We still call showSoftKeyboard, which will be ignored by physical key
board. |
656 waitForKeyboardStates(1, 0, 1, new Integer[] {TextInputType.TEXT}); | 681 waitForKeyboardStates(1, 0, 1, new Integer[] {TextInputType.TEXT}); |
657 setComposingText("a", 1); | 682 setComposingText("a", 1); |
658 waitForKeyboardStates(1, 0, 1, new Integer[] {TextInputType.TEXT}); | 683 waitForKeyboardStates(1, 0, 1, new Integer[] {TextInputType.TEXT}); |
659 detachPhysicalKeyboard(); | 684 detachPhysicalKeyboard(); |
660 assertWaitForKeyboardStatus(true); | 685 assertWaitForKeyboardStatus(true); |
661 // Now we really show soft keyboard. We also call restartInput when conf
iguration changes. | 686 // Now we really show soft keyboard. We also call restartInput when conf
iguration changes. |
662 waitForKeyboardStates(2, 0, 2, new Integer[] {TextInputType.TEXT, TextIn
putType.TEXT}); | 687 waitForKeyboardStates(2, 0, 2, new Integer[] {TextInputType.TEXT, TextIn
putType.TEXT}); |
663 | 688 |
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 public void onViewAttachedToWindow() { | 2002 public void onViewAttachedToWindow() { |
1978 mFactory.onViewAttachedToWindow(); | 2003 mFactory.onViewAttachedToWindow(); |
1979 } | 2004 } |
1980 | 2005 |
1981 @Override | 2006 @Override |
1982 public void onViewDetachedFromWindow() { | 2007 public void onViewDetachedFromWindow() { |
1983 mFactory.onViewDetachedFromWindow(); | 2008 mFactory.onViewDetachedFromWindow(); |
1984 } | 2009 } |
1985 } | 2010 } |
1986 } | 2011 } |
OLD | NEW |