Commit bafaea18 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Android] Accessory hides infobars temporarily

This CL ensures that infobars are not pushed up while the keyboard
accessory sheet is open. Instead, their container is hidden until the
sheet is closed again.

(This solution is the less intrusive way. Ideally, the accessory will
communicate its state as if it was a keyboard.)

Bug: 876269
Change-Id: Ib33dacd7131b3d654e3ae418092d6af2f3a24a68
Reviewed-on: https://chromium-review.googlesource.com/1202162
Commit-Queue: Friedrich Horschig [CEST] <fhorschig@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588394}
parent 9ede1f92
......@@ -109,7 +109,7 @@ class ManualFillingMediator
@Override
public void onSceneStartShowing(Layout layout) {
// Includes events like side-swiping between tabs and triggering contextual search.
mKeyboardAccessory.dismiss();
pause();
}
@Override
......@@ -119,7 +119,7 @@ class ManualFillingMediator
private final TabObserver mTabObserver = new EmptyTabObserver() {
@Override
public void onHidden(Tab tab) {
mKeyboardAccessory.dismiss();
pause();
}
@Override
......@@ -130,7 +130,7 @@ class ManualFillingMediator
@Override
public void onEnterFullscreenMode(Tab tab, FullscreenOptions options) {
mKeyboardAccessory.dismiss();
pause();
}
};
......@@ -188,11 +188,13 @@ class ManualFillingMediator
mKeyboardAccessory.requestShowing();
mActivity.getFullscreenManager().setBottomControlsHeight(calculateAccessoryBarHeight());
mKeyboardAccessory.closeActiveTab();
updateInfobarState(true);
mKeyboardAccessory.setBottomOffset(0);
mAccessorySheet.hide();
} else {
mKeyboardAccessory.close();
onBottomControlSpaceChanged();
updateInfobarState(/* shouldBeHidden= */ mKeyboardAccessory.hasActiveTab());
if (mKeyboardAccessory.hasActiveTab()) {
mAccessorySheet.show();
}
......@@ -223,7 +225,7 @@ class ManualFillingMediator
boolean handleBackPress() {
if (isInitialized() && mAccessorySheet.isShown()) {
mKeyboardAccessory.dismiss();
pause();
return true;
}
return false;
......@@ -231,7 +233,7 @@ class ManualFillingMediator
void dismiss() {
if (!isInitialized()) return;
mKeyboardAccessory.dismiss();
pause();
if (getContentView() != null) UiUtils.hideKeyboard(getContentView());
}
......@@ -242,6 +244,7 @@ class ManualFillingMediator
public void pause() {
if (!isInitialized()) return;
mKeyboardAccessory.dismiss();
updateInfobarState(false);
}
void resume() {
......@@ -269,6 +272,7 @@ class ManualFillingMediator
}
mActivity.getFullscreenManager().setBottomControlsHeight(mPreviousControlHeight);
mKeyboardAccessory.closeActiveTab();
updateInfobarState(false);
mKeyboardAccessory.setBottomOffset(0);
mAccessorySheet.hide();
}
......@@ -325,7 +329,7 @@ class ManualFillingMediator
}
private void restoreCachedState(Tab browserTab) {
mKeyboardAccessory.dismiss();
pause();
clearTabs();
if (browserTab == null) return; // If there is no tab, exit after cleaning everything.
AccessoryState state = getOrCreateAccessoryState(browserTab);
......@@ -354,6 +358,18 @@ class ManualFillingMediator
org.chromium.chrome.R.dimen.keyboard_accessory_suggestion_height);
}
// TODO(fhorschig): Remove when accessory sheet acts as keyboard.
/**
* Sets the infobar state to the given value. Does nothing if there is no active tab with an
* {@link org.chromium.chrome.browser.infobar.InfoBarContainer}.
* @param shouldBeHidden If true, info bars can be shown. They are suppressed on false.
*/
private void updateInfobarState(boolean shouldBeHidden) {
if (mActiveBrowserTab == null) return;
if (mActiveBrowserTab.getInfoBarContainer() == null) return;
mActiveBrowserTab.getInfoBarContainer().setHidden(shouldBeHidden);
}
@VisibleForTesting
void addTab(KeyboardAccessoryData.Tab tab) {
if (!isInitialized()) return;
......
......@@ -10,8 +10,10 @@ import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertNotNull;
import static org.chromium.chrome.browser.autofill.keyboard_accessory.ManualFillingTestHelper.selectTabAtPosition;
......@@ -33,8 +35,12 @@ import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.autofill.AutofillTestHelper;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.ui.DropdownPopupWindowInterface;
......@@ -300,4 +306,61 @@ public class ManualFillingIntegrationTest {
mHelper.waitToBeHidden(withId(R.id.keyboard_accessory_sheet));
mHelper.waitToBeHidden(withId(R.id.keyboard_accessory));
}
@Test
@SmallTest
public void testInfobarStaysHiddenWhenOpeningSheet()
throws InterruptedException, TimeoutException {
mHelper.loadTestPage(false);
// TODO Create an infobar
InfoBarContainer container =
mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer();
InfoBarTestAnimationListener mListener = new InfoBarTestAnimationListener();
container.addAnimationListener(mListener);
final SimpleConfirmInfoBarBuilder.Listener testListener =
new SimpleConfirmInfoBarBuilder.Listener() {
@Override
public void onInfoBarDismissed() {}
@Override
public boolean onInfoBarButtonClicked(boolean isPrimary) {
return false;
}
};
final String kInfoBarText = "SomeInfoBar";
ThreadUtils.runOnUiThread(() -> {
SimpleConfirmInfoBarBuilder.create(mActivityTestRule.getActivity().getActivityTab(),
testListener, InfoBarIdentifier.DUPLICATE_DOWNLOAD_INFOBAR_DELEGATE_ANDROID, 0,
kInfoBarText, null, null, false);
});
mListener.addInfoBarAnimationFinished("InfoBar not added.");
mHelper.createTestTab();
whenDisplayed(withText(kInfoBarText));
// Focus the field to bring up the accessory.
mHelper.clickPasswordField();
mHelper.waitForKeyboard();
assertThat(mActivityTestRule.getActivity()
.getActivityTab()
.getInfoBarContainer()
.getVisibility(),
is(not(View.VISIBLE)));
// Click the tab to show the sheet and hide the keyboard.
whenDisplayed(withId(R.id.tabs)).perform(selectTabAtPosition(0));
mHelper.waitForKeyboardToDisappear();
whenDisplayed(withId(R.id.keyboard_accessory_sheet));
assertThat(mActivityTestRule.getActivity()
.getActivityTab()
.getInfoBarContainer()
.getVisibility(),
is(not(View.VISIBLE)));
Espresso.pressBack();
mHelper.waitToBeHidden(withId(R.id.keyboard_accessory_sheet));
mHelper.waitToBeHidden(withId(R.id.keyboard_accessory));
whenDisplayed(withText(kInfoBarText));
}
}
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