Index: chrome/android/javatests/src/org/chromium/chrome/browser/TabsTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/TabsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/TabsTest.java |
index 9330492c1965f277c8f3d59c752e818cd3f9cec1..0d626a13e8b338b4ee015a81150fba4eb7d0a1b6 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/TabsTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/TabsTest.java |
@@ -10,6 +10,8 @@ import android.content.DialogInterface; |
import android.content.pm.ActivityInfo; |
import android.os.Debug; |
import android.os.Environment; |
+import android.os.IBinder; |
+import android.os.ResultReceiver; |
import android.os.SystemClock; |
import android.test.suitebuilder.annotation.LargeTest; |
import android.test.suitebuilder.annotation.MediumTest; |
@@ -60,9 +62,12 @@ import org.chromium.chrome.test.util.MenuUtils; |
import org.chromium.chrome.test.util.NewTabPageTestUtils; |
import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher; |
import org.chromium.content.browser.ContentViewCore; |
+import org.chromium.content.browser.input.ImeAdapter; |
+import org.chromium.content.browser.input.InputMethodManagerWrapper; |
import org.chromium.content.browser.test.util.CallbackHelper; |
import org.chromium.content.browser.test.util.Criteria; |
import org.chromium.content.browser.test.util.CriteriaHelper; |
+import org.chromium.content.browser.test.util.DOMUtils; |
import org.chromium.content.browser.test.util.JavaScriptUtils; |
import org.chromium.content.browser.test.util.UiUtils; |
import org.chromium.content.common.ContentSwitches; |
@@ -281,6 +286,86 @@ public class TabsTest extends ChromeTabbedActivityTestBase { |
}); |
} |
+ private void setInputMethodManagerWrapperForTest( |
+ final CallbackHelper showSoftInputHelper, final CallbackHelper hideSoftInputHelper) { |
+ ImeAdapter imeAdapter = |
+ getActivity().getActivityTab().getContentViewCore().getImeAdapterForTest(); |
+ imeAdapter.setInputMethodManagerWrapperForTest( |
+ new InputMethodManagerWrapper(getInstrumentation().getContext()) { |
+ @Override |
+ public void showSoftInput(View view, int flags, ResultReceiver resultReceiver) { |
+ super.showSoftInput(view, flags, resultReceiver); |
+ showSoftInputHelper.notifyCalled(); |
+ } |
+ |
+ @Override |
+ public boolean hideSoftInputFromWindow( |
+ IBinder windowToken, int flags, ResultReceiver resultReceiver) { |
+ super.hideSoftInputFromWindow(windowToken, flags, resultReceiver); |
+ hideSoftInputHelper.notifyCalled(); |
+ return true; |
+ } |
+ }); |
+ } |
+ |
+ /** |
+ * Verify that opening a new tab, switching to an existing tab and closing current tab hide |
+ * keyboard. |
+ */ |
+ @LargeTest |
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET) |
+ @Feature({"Android-TabSwitcher"}) |
+ @RetryOnFailure |
+ public void testHideKeyboard() throws Exception { |
+ mTestServer = EmbeddedTestServer.createAndStartFileServer( |
+ getInstrumentation().getContext(), Environment.getExternalStorageDirectory()); |
+ |
+ // Open a new tab(The 1st tab). |
+ ChromeTabUtils.fullyLoadUrlInNewTab( |
+ getInstrumentation(), getActivity(), mTestServer.getURL(TEST_FILE_PATH), false); |
+ |
+ final CallbackHelper showSoftInputHelper1 = new CallbackHelper(); |
Changwan Ryu
2016/10/19 05:10:21
How about naming these variables as showCallback1
|
+ final CallbackHelper hideSoftInputHelper1 = new CallbackHelper(); |
+ setInputMethodManagerWrapperForTest(showSoftInputHelper1, hideSoftInputHelper1); |
+ |
+ // Click node in the 1st tab. |
+ int callbackCount = showSoftInputHelper1.getCallCount(); |
+ boolean result = DOMUtils.clickNode( |
Changwan Ryu
2016/10/19 05:10:21
Could you make the two lines into one?
assertTrue
yabinh
2016/10/24 01:40:57
Done.
|
+ this, getActivity().getActivityTab().getContentViewCore(), "input_text"); |
+ assertEquals("Failed to click node.", true, result); |
+ showSoftInputHelper1.waitForCallback(callbackCount, 1); |
+ |
+ // Open a new tab(the 2nd tab). |
+ callbackCount = hideSoftInputHelper1.getCallCount(); |
+ ChromeTabUtils.fullyLoadUrlInNewTab( |
+ getInstrumentation(), getActivity(), mTestServer.getURL(TEST_FILE_PATH), false); |
+ hideSoftInputHelper1.waitForCallback(callbackCount, 1); |
+ |
+ final CallbackHelper showSoftInputHelper2 = new CallbackHelper(); |
+ final CallbackHelper hideSoftInputHelper2 = new CallbackHelper(); |
+ setInputMethodManagerWrapperForTest(showSoftInputHelper2, hideSoftInputHelper2); |
+ |
+ // Click node in the 2nd tab. |
+ callbackCount = showSoftInputHelper2.getCallCount(); |
+ DOMUtils.clickNode(this, getActivity().getActivityTab().getContentViewCore(), "input_text"); |
+ showSoftInputHelper2.waitForCallback(callbackCount, 1); |
+ |
+ // Switch to the 1st tab. |
+ callbackCount = hideSoftInputHelper2.getCallCount(); |
+ ChromeTabUtils.switchTabInCurrentTabModel(getActivity(), 1); |
+ hideSoftInputHelper2.waitForCallback(callbackCount, 1); |
+ |
+ // Click node in the 1st tab. |
+ callbackCount = showSoftInputHelper1.getCallCount(); |
+ DOMUtils.clickNode(this, getActivity().getActivityTab().getContentViewCore(), "input_text"); |
+ showSoftInputHelper1.waitForCallback(callbackCount, 1); |
+ |
+ // Closes current tab(the 1st tab). |
+ callbackCount = hideSoftInputHelper1.getCallCount(); |
+ ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity()); |
+ hideSoftInputHelper1.waitForCallback(callbackCount, 1); |
+ } |
+ |
/** |
* Verify that opening a new tab and navigating immediately sets a size on the newly created |
* renderer. https://crbug.com/434477. |