Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/TabsTest.java

Issue 2290133002: Make WebView keep keyboard when losing focus (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE;
8 8
9 import android.content.DialogInterface; 9 import android.content.DialogInterface;
10 import android.content.pm.ActivityInfo; 10 import android.content.pm.ActivityInfo;
11 import android.os.Debug; 11 import android.os.Debug;
12 import android.os.Environment; 12 import android.os.Environment;
13 import android.os.IBinder;
14 import android.os.ResultReceiver;
13 import android.os.SystemClock; 15 import android.os.SystemClock;
14 import android.test.suitebuilder.annotation.LargeTest; 16 import android.test.suitebuilder.annotation.LargeTest;
15 import android.test.suitebuilder.annotation.MediumTest; 17 import android.test.suitebuilder.annotation.MediumTest;
16 import android.test.suitebuilder.annotation.SmallTest; 18 import android.test.suitebuilder.annotation.SmallTest;
17 import android.test.suitebuilder.annotation.Smoke; 19 import android.test.suitebuilder.annotation.Smoke;
18 import android.util.DisplayMetrics; 20 import android.util.DisplayMetrics;
19 import android.util.Log; 21 import android.util.Log;
20 import android.view.View; 22 import android.view.View;
21 23
22 import org.chromium.base.ThreadUtils; 24 import org.chromium.base.ThreadUtils;
(...skipping 30 matching lines...) Expand all
53 import org.chromium.chrome.browser.tabmodel.TabbedModeTabPersistencePolicy; 55 import org.chromium.chrome.browser.tabmodel.TabbedModeTabPersistencePolicy;
54 import org.chromium.chrome.browser.toolbar.ToolbarPhone; 56 import org.chromium.chrome.browser.toolbar.ToolbarPhone;
55 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; 57 import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
56 import org.chromium.chrome.test.util.ApplicationTestUtils; 58 import org.chromium.chrome.test.util.ApplicationTestUtils;
57 import org.chromium.chrome.test.util.ChromeRestriction; 59 import org.chromium.chrome.test.util.ChromeRestriction;
58 import org.chromium.chrome.test.util.ChromeTabUtils; 60 import org.chromium.chrome.test.util.ChromeTabUtils;
59 import org.chromium.chrome.test.util.MenuUtils; 61 import org.chromium.chrome.test.util.MenuUtils;
60 import org.chromium.chrome.test.util.NewTabPageTestUtils; 62 import org.chromium.chrome.test.util.NewTabPageTestUtils;
61 import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher; 63 import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher;
62 import org.chromium.content.browser.ContentViewCore; 64 import org.chromium.content.browser.ContentViewCore;
65 import org.chromium.content.browser.input.ImeAdapter;
66 import org.chromium.content.browser.input.InputMethodManagerWrapper;
63 import org.chromium.content.browser.test.util.CallbackHelper; 67 import org.chromium.content.browser.test.util.CallbackHelper;
64 import org.chromium.content.browser.test.util.Criteria; 68 import org.chromium.content.browser.test.util.Criteria;
65 import org.chromium.content.browser.test.util.CriteriaHelper; 69 import org.chromium.content.browser.test.util.CriteriaHelper;
70 import org.chromium.content.browser.test.util.DOMUtils;
66 import org.chromium.content.browser.test.util.JavaScriptUtils; 71 import org.chromium.content.browser.test.util.JavaScriptUtils;
67 import org.chromium.content.browser.test.util.UiUtils; 72 import org.chromium.content.browser.test.util.UiUtils;
68 import org.chromium.content.common.ContentSwitches; 73 import org.chromium.content.common.ContentSwitches;
69 import org.chromium.content_public.browser.WebContents; 74 import org.chromium.content_public.browser.WebContents;
70 import org.chromium.content_public.browser.WebContentsObserver; 75 import org.chromium.content_public.browser.WebContentsObserver;
71 import org.chromium.net.test.EmbeddedTestServer; 76 import org.chromium.net.test.EmbeddedTestServer;
72 77
73 import java.io.File; 78 import java.io.File;
74 import java.util.Locale; 79 import java.util.Locale;
75 import java.util.concurrent.Callable; 80 import java.util.concurrent.Callable;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 279
275 ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity()); 280 ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity());
276 getInstrumentation().runOnMainSync(new Runnable() { 281 getInstrumentation().runOnMainSync(new Runnable() {
277 @Override 282 @Override
278 public void run() { 283 public void run() {
279 assertEquals(tabCount, getActivity().getCurrentTabModel().getCou nt()); 284 assertEquals(tabCount, getActivity().getCurrentTabModel().getCou nt());
280 } 285 }
281 }); 286 });
282 } 287 }
283 288
289 private void setInputMethodManagerWrapperForTest(
290 final CallbackHelper showSoftInputHelper, final CallbackHelper hideS oftInputHelper) {
291 ImeAdapter imeAdapter =
292 getActivity().getActivityTab().getContentViewCore().getImeAdapte rForTest();
293 imeAdapter.setInputMethodManagerWrapperForTest(
294 new InputMethodManagerWrapper(getInstrumentation().getContext()) {
295 @Override
296 public void showSoftInput(View view, int flags, ResultReceiv er resultReceiver) {
297 super.showSoftInput(view, flags, resultReceiver);
298 showSoftInputHelper.notifyCalled();
299 }
300
301 @Override
302 public boolean hideSoftInputFromWindow(
303 IBinder windowToken, int flags, ResultReceiver resul tReceiver) {
304 super.hideSoftInputFromWindow(windowToken, flags, result Receiver);
305 hideSoftInputHelper.notifyCalled();
306 return true;
307 }
308 });
309 }
310
311 /**
312 * Verify that opening a new tab, switching to an existing tab and closing c urrent tab hide
313 * keyboard.
314 */
315 @LargeTest
316 @Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET)
317 @Feature({"Android-TabSwitcher"})
318 @RetryOnFailure
319 public void testHideKeyboard() throws Exception {
320 mTestServer = EmbeddedTestServer.createAndStartFileServer(
321 getInstrumentation().getContext(), Environment.getExternalStorag eDirectory());
322
323 // Open a new tab(The 1st tab).
324 ChromeTabUtils.fullyLoadUrlInNewTab(
325 getInstrumentation(), getActivity(), mTestServer.getURL(TEST_FIL E_PATH), false);
326
327 final CallbackHelper showSoftInputHelper1 = new CallbackHelper();
Changwan Ryu 2016/10/19 05:10:21 How about naming these variables as showCallback1
328 final CallbackHelper hideSoftInputHelper1 = new CallbackHelper();
329 setInputMethodManagerWrapperForTest(showSoftInputHelper1, hideSoftInputH elper1);
330
331 // Click node in the 1st tab.
332 int callbackCount = showSoftInputHelper1.getCallCount();
333 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.
334 this, getActivity().getActivityTab().getContentViewCore(), "inpu t_text");
335 assertEquals("Failed to click node.", true, result);
336 showSoftInputHelper1.waitForCallback(callbackCount, 1);
337
338 // Open a new tab(the 2nd tab).
339 callbackCount = hideSoftInputHelper1.getCallCount();
340 ChromeTabUtils.fullyLoadUrlInNewTab(
341 getInstrumentation(), getActivity(), mTestServer.getURL(TEST_FIL E_PATH), false);
342 hideSoftInputHelper1.waitForCallback(callbackCount, 1);
343
344 final CallbackHelper showSoftInputHelper2 = new CallbackHelper();
345 final CallbackHelper hideSoftInputHelper2 = new CallbackHelper();
346 setInputMethodManagerWrapperForTest(showSoftInputHelper2, hideSoftInputH elper2);
347
348 // Click node in the 2nd tab.
349 callbackCount = showSoftInputHelper2.getCallCount();
350 DOMUtils.clickNode(this, getActivity().getActivityTab().getContentViewCo re(), "input_text");
351 showSoftInputHelper2.waitForCallback(callbackCount, 1);
352
353 // Switch to the 1st tab.
354 callbackCount = hideSoftInputHelper2.getCallCount();
355 ChromeTabUtils.switchTabInCurrentTabModel(getActivity(), 1);
356 hideSoftInputHelper2.waitForCallback(callbackCount, 1);
357
358 // Click node in the 1st tab.
359 callbackCount = showSoftInputHelper1.getCallCount();
360 DOMUtils.clickNode(this, getActivity().getActivityTab().getContentViewCo re(), "input_text");
361 showSoftInputHelper1.waitForCallback(callbackCount, 1);
362
363 // Closes current tab(the 1st tab).
364 callbackCount = hideSoftInputHelper1.getCallCount();
365 ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity());
366 hideSoftInputHelper1.waitForCallback(callbackCount, 1);
367 }
368
284 /** 369 /**
285 * Verify that opening a new tab and navigating immediately sets a size on t he newly created 370 * Verify that opening a new tab and navigating immediately sets a size on t he newly created
286 * renderer. https://crbug.com/434477. 371 * renderer. https://crbug.com/434477.
287 * @throws InterruptedException 372 * @throws InterruptedException
288 * @throws TimeoutException 373 * @throws TimeoutException
289 */ 374 */
290 @SmallTest 375 @SmallTest
291 @RetryOnFailure 376 @RetryOnFailure
292 public void testNewTabSetsContentViewSize() throws InterruptedException, Tim eoutException { 377 public void testNewTabSetsContentViewSize() throws InterruptedException, Tim eoutException {
293 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity()); 378 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity());
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 throws InterruptedException { 1812 throws InterruptedException {
1728 CriteriaHelper.pollInstrumentationThread( 1813 CriteriaHelper.pollInstrumentationThread(
1729 Criteria.equals(expected, new Callable<Boolean>() { 1814 Criteria.equals(expected, new Callable<Boolean>() {
1730 @Override 1815 @Override
1731 public Boolean call() { 1816 public Boolean call() {
1732 return fileToCheck.exists(); 1817 return fileToCheck.exists();
1733 } 1818 }
1734 })); 1819 }));
1735 } 1820 }
1736 } 1821 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698