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..2b195c78faf012ac39e7d15a418e1c4253e6f02c 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; |
@@ -95,6 +100,8 @@ public class TabsTest extends ChromeTabbedActivityTestBase { |
private boolean mNotifyChangedCalled; |
+ public boolean mKeyboardShown = false; |
+ |
private static final int SWIPE_TO_RIGHT_DIRECTION = 1; |
private static final int SWIPE_TO_LEFT_DIRECTION = -1; |
@@ -228,7 +235,8 @@ public class TabsTest extends ChromeTabbedActivityTestBase { |
* @Feature({"Android-TabSwitcher"}) |
* @Restriction(RESTRICTION_TYPE_PHONE) |
*/ |
- @DisabledTest |
+ // @DisabledTest |
+ @LargeTest |
public void testOpenAndCloseNewTabButton() throws InterruptedException { |
mTestServer = EmbeddedTestServer.createAndStartFileServer( |
getInstrumentation().getContext(), Environment.getExternalStorageDirectory()); |
@@ -281,6 +289,58 @@ public class TabsTest extends ChromeTabbedActivityTestBase { |
}); |
} |
+ private void setInputMethodManagerWrapperForTest(final CallbackHelper callbackHelper) { |
+ ImeAdapter imeAdapter = |
Changwan Ryu
2016/10/12 12:15:49
So the flakiness we talked about was caused becaus
Changwan Ryu
2016/10/12 12:19:45
How about listening to TabModelObserver#didSelectT
yabinh
2016/10/13 03:13:45
Actually we use "onViewDetachedFromWindow()" inste
|
+ 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); |
+ mKeyboardShown = true; |
+ callbackHelper.notifyCalled(); |
+ } |
+ |
+ @Override |
+ public boolean hideSoftInputFromWindow( |
+ IBinder windowToken, int flags, ResultReceiver resultReceiver) { |
+ super.hideSoftInputFromWindow(windowToken, flags, resultReceiver); |
+ mKeyboardShown = false; |
+ callbackHelper.notifyCalled(); |
+ return true; |
+ } |
+ }); |
+ } |
+ /** |
+ * Verify that opening a new tab, switching to an existing tab and closing current tab hide |
+ * keyboard. |
+ */ |
+ @LargeTest |
+ public void testHideKeyboard() throws Exception { |
+ mTestServer = EmbeddedTestServer.createAndStartFileServer( |
+ getInstrumentation().getContext(), Environment.getExternalStorageDirectory()); |
+ |
+ // Failed 100% at this step. It didn't happen before. Also, I tried |
+ // testOpenAndCloseNewTabButton(), it's flaky at this step, but failure rate is not 100%. |
+ startMainActivityWithURL(mTestServer.getURL(TEST_FILE_PATH)); |
+ |
+ final CallbackHelper callbackHelper = new CallbackHelper(); |
+ int curCallCount = callbackHelper.getCallCount(); |
+ setInputMethodManagerWrapperForTest(callbackHelper); |
+ |
+ DOMUtils.clickNode(this, getActivity().getActivityTab().getContentViewCore(), "input_text"); |
+ callbackHelper.waitForCallback(curCallCount, 1); |
+ assertTrue(mKeyboardShown); |
+ |
+ // Opens a new tab. |
+ curCallCount = callbackHelper.getCallCount(); |
+ startMainActivityWithURL(mTestServer.getURL(TEST_FILE_PATH)); |
+ callbackHelper.waitForCallback(curCallCount, 1); // Flaky at this step. |
+ assertFalse(mKeyboardShown); |
+ |
+ // TODO: closes a tab, switches to an existing tab. |
+ } |
+ |
/** |
* Verify that opening a new tab and navigating immediately sets a size on the newly created |
* renderer. https://crbug.com/434477. |