Commit bedf80c3 authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Chromium LUCI CQ

Do not dismiss keyboard if Activity reports no active views.

This change prevents the NPE caused during keyboard hide if Activity
reported no active views.

Bug: 1165666
Change-Id: Id84248305b8d38a6c2f668e540ae08855822b1c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625813
Commit-Queue: Tomasz Wiszkowski <ender@google.com>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842800}
parent 7176f938
...@@ -9,6 +9,7 @@ import android.animation.AnimatorSet; ...@@ -9,6 +9,7 @@ import android.animation.AnimatorSet;
import android.app.Activity; import android.app.Activity;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.content.res.Resources; import android.content.res.Resources;
import android.view.View;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -120,8 +121,13 @@ class MenuButtonMediator implements AppMenuObserver { ...@@ -120,8 +121,13 @@ class MenuButtonMediator implements AppMenuObserver {
// Defocus here to avoid handling focus in multiple places, e.g., when the // Defocus here to avoid handling focus in multiple places, e.g., when the
// forward button is pressed. (see crbug.com/414219) // forward button is pressed. (see crbug.com/414219)
mSetUrlBarFocusFunction.setFocus(false, OmniboxFocusReason.UNFOCUS); mSetUrlBarFocusFunction.setFocus(false, OmniboxFocusReason.UNFOCUS);
// Dismiss keyboard in case the user was interacting with an input field on a website.
mKeyboardDelegate.hideKeyboard(mActivity.getCurrentFocus()); View view = mActivity.getCurrentFocus();
if (view != null) {
// Dismiss keyboard in case the user was interacting with an input field on a
// website.
mKeyboardDelegate.hideKeyboard(view);
}
if (!mIsInOverviewModeSupplier.get() && isShowingAppMenuUpdateBadge()) { if (!mIsInOverviewModeSupplier.get() && isShowingAppMenuUpdateBadge()) {
// The app menu badge should be removed the first time the menu is opened. // The app menu badge should be removed the first time the menu is opened.
......
...@@ -9,11 +9,13 @@ import static junit.framework.Assert.assertTrue; ...@@ -9,11 +9,13 @@ import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.anyObject; import static org.mockito.Mockito.anyObject;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.app.Activity; import android.app.Activity;
import android.content.res.Resources; import android.content.res.Resources;
import android.view.View;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -71,6 +73,8 @@ public class MenuButtonMediatorTest { ...@@ -71,6 +73,8 @@ public class MenuButtonMediatorTest {
private WindowAndroid mWindowAndroid; private WindowAndroid mWindowAndroid;
@Mock @Mock
private KeyboardVisibilityDelegate mKeyboardDelegate; private KeyboardVisibilityDelegate mKeyboardDelegate;
@Mock
private View mUtilityView;
private UpdateMenuItemHelper.MenuUiState mMenuUiState; private UpdateMenuItemHelper.MenuUiState mMenuUiState;
private OneshotSupplierImpl<AppMenuCoordinator> mAppMenuSupplier; private OneshotSupplierImpl<AppMenuCoordinator> mAppMenuSupplier;
...@@ -217,7 +221,15 @@ public class MenuButtonMediatorTest { ...@@ -217,7 +221,15 @@ public class MenuButtonMediatorTest {
@Test @Test
public void testKeyboardIsDismissedWhenMenuShows() { public void testKeyboardIsDismissedWhenMenuShows() {
doReturn(mUtilityView).when(mActivity).getCurrentFocus();
mMenuButtonMediator.onMenuVisibilityChanged(true);
verify(mKeyboardDelegate).hideKeyboard(eq(mUtilityView));
}
@Test
public void testKeyboardIsNotDismissedWhenMenuShowsWithNoFocusedViews() {
doReturn(null).when(mActivity).getCurrentFocus();
mMenuButtonMediator.onMenuVisibilityChanged(true); mMenuButtonMediator.onMenuVisibilityChanged(true);
verify(mKeyboardDelegate).hideKeyboard(anyObject()); verify(mKeyboardDelegate, never()).hideKeyboard(anyObject());
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment