Commit 22c27291 authored by Patrick Noland's avatar Patrick Noland Committed by Chromium LUCI CQ

[ToolbarMVC] Move url focus logic to LBMediator

This change moves setUrlFocusChangeInProgress, onUrlFocusChange, and
finishUrlFocusChange to LocationBarMediator, consolidating phone- and
tablet-specific logic as appropriate. Moving these together allows
us to move several pieces of state into LocationBarMediator together,
e.g. mUrlFocusedWithoutAnimations and mUrlFocusChangeListeners.
Unit and instrumentation tests covering the migrated logic are also
included, and some on-focus triggered accessibility logic has been moved
to UrlBarCoordinator.

Bug: 1147581

Change-Id: I4cab5b32402b86a953d22418eb94f375a21b9cc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2598036Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Patrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845273}
parent b8c095a7
......@@ -127,7 +127,7 @@ public final class LocationBarCoordinator implements LocationBar, NativeInitObse
mLocationBarLayout, locationBarDataProvider, profileObservableSupplier,
PrivacyPreferencesManagerImpl.getInstance(), overrideUrlLoadingDelegate,
LocaleManager.getInstance(), mTemplateUrlServiceSupplier, backKeyBehavior,
windowAndroid);
windowAndroid, isTablet());
mUrlCoordinator =
new UrlBarCoordinator((UrlBar) mUrlBar, windowDelegate, actionModeCallback,
mCallbackController.makeCancelable(mLocationBarMediator::onUrlFocusChange),
......@@ -138,17 +138,21 @@ public final class LocationBarCoordinator implements LocationBar, NativeInitObse
StatusView statusView = mLocationBarLayout.findViewById(R.id.location_bar_status);
mStatusCoordinator = new StatusCoordinator(isTablet(), statusView, mUrlCoordinator,
incognitoStateProvider, modalDialogManagerSupplier, locationBarDataProvider);
mLocationBarMediator.setCoordinators(
mUrlCoordinator, mAutocompleteCoordinator, mStatusCoordinator);
mUrlBar.setOnKeyListener(mLocationBarMediator);
mLocationBarMediator.addUrlFocusChangeListener(mAutocompleteCoordinator);
mLocationBarMediator.addUrlFocusChangeListener(mUrlCoordinator);
mDeleteButton = mLocationBarLayout.findViewById(R.id.delete_button);
mMicButton = mLocationBarLayout.findViewById(R.id.mic_button);
mDeleteButton.setOnClickListener(mLocationBarMediator::deleteButtonClicked);
mMicButton = mLocationBarLayout.findViewById(R.id.mic_button);
mMicButton.setOnClickListener(mLocationBarMediator::micButtonClicked);
mUrlBar.setOnKeyListener(mLocationBarMediator);
mUrlCoordinator.addUrlTextChangeListener(mAutocompleteCoordinator);
// The LocationBar's direction is tied to the UrlBar's text direction. Icons inside the
// location bar, e.g. lock, refresh, X, should be reversed if UrlBar's text is RTL.
mUrlCoordinator.setUrlDirectionListener(
......@@ -158,8 +162,6 @@ public final class LocationBarCoordinator implements LocationBar, NativeInitObse
}));
mLocationBarLayout.getContext().registerComponentCallbacks(mLocationBarMediator);
mLocationBarLayout.addUrlFocusChangeListener(mAutocompleteCoordinator);
mLocationBarLayout.addUrlFocusChangeListener(mUrlCoordinator);
mLocationBarLayout.initialize(mAutocompleteCoordinator, mUrlCoordinator, mStatusCoordinator,
locationBarDataProvider);
......@@ -176,28 +178,40 @@ public final class LocationBarCoordinator implements LocationBar, NativeInitObse
public void destroy() {
mActivityLifecycleDispatcher.unregister(this);
mActivityLifecycleDispatcher = null;
if (mSubCoordinator != null) {
mSubCoordinator.destroy();
mSubCoordinator = null;
}
mUrlBar.setOnKeyListener(null);
mUrlBar = null;
mDeleteButton.setOnClickListener(null);
mDeleteButton = null;
mMicButton.setOnClickListener(null);
mMicButton = null;
mLocationBarMediator.removeUrlFocusChangeListener(mUrlCoordinator);
mUrlCoordinator.destroy();
mUrlCoordinator = null;
mLocationBarLayout.getContext().unregisterComponentCallbacks(mLocationBarMediator);
mLocationBarLayout.removeUrlFocusChangeListener(mAutocompleteCoordinator);
mLocationBarMediator.removeUrlFocusChangeListener(mAutocompleteCoordinator);
mAutocompleteCoordinator.destroy();
mAutocompleteCoordinator = null;
mStatusCoordinator.destroy();
mStatusCoordinator = null;
mLocationBarLayout.destroy();
mLocationBarLayout = null;
mCallbackController.destroy();
mCallbackController = null;
mLocationBarMediator.destroy();
mLocationBarMediator = null;
}
......@@ -251,7 +265,7 @@ public final class LocationBarCoordinator implements LocationBar, NativeInitObse
@Override
public View getContainerView() {
return mLocationBarLayout.getContainerView();
return mLocationBarLayout;
}
@Override
......@@ -431,6 +445,25 @@ public final class LocationBarCoordinator implements LocationBar, NativeInitObse
mLocationBarMediator.setUrlFocusChangeInProgress(inProgress);
}
/**
* Handles any actions to be performed after all other actions triggered by the URL focus
* change. This will be called after any animations are performed to transition from one
* focus state to the other.
*
* @param hasFocus Whether the URL field has gained focus.
* @param shouldShowKeyboard Whether the keyboard should be shown. This value should be the same
* as hasFocus by default.
* @param shouldShowInOverviewMode Whether the location bar should be shown when in overview
* mode.
*/
public void finishUrlFocusChange(
boolean hasFocus, boolean shouldShowKeyboard, boolean shouldShowInOverviewMode) {
mLocationBarMediator.finishUrlFocusChange(hasFocus, shouldShowKeyboard);
if (shouldShowInOverviewMode) {
mStatusCoordinator.onSecurityStateChanged();
}
}
public void setVoiceRecognitionHandlerForTesting(
VoiceRecognitionHandler voiceRecognitionHandler) {
mLocationBarMediator.setVoiceRecognitionHandlerForTesting(voiceRecognitionHandler);
......
......@@ -70,25 +70,6 @@ public class LocationBarCoordinatorPhone implements LocationBarCoordinator.SubCo
}
}
/**
* Handles any actions to be performed after all other actions triggered by the URL focus
* change. This will be called after any animations are performed to transition from one
* focus state to the other.
*
* @param hasFocus Whether the URL field has gained focus.
* @param shouldShowKeyboard Whether the keyboard should be shown. This value should be the same
* as hasFocus by default.
* @param shouldShowInOverviewMode Whether the location bar should be shown when in overview
* mode.
*/
public void finishUrlFocusChange(
boolean hasFocus, boolean shouldShowKeyboard, boolean shouldShowInOverviewMode) {
mLocationBarPhone.finishUrlFocusChange(hasFocus, shouldShowKeyboard);
if (shouldShowInOverviewMode) {
mStatusCoordinator.onSecurityStateChanged();
}
}
/**
* Returns {@link FrameLayout.LayoutParams} of the LocationBar view.
*
......
......@@ -109,19 +109,6 @@ class LocationBarPhone extends LocationBarLayout {
mStatusCoordinator.setUrlFocusChangePercent(fraction);
}
@Override
public void onUrlFocusChange(boolean hasFocus) {
if (hasFocus) {
// Remove the focus of this view once the URL field has taken focus as this view no
// longer needs it.
setFocusable(false);
setFocusableInTouchMode(false);
}
setUrlFocusChangeInProgress(true);
updateShouldAnimateIconChanges();
super.onUrlFocusChange(hasFocus);
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean needsCanvasRestore = false;
......@@ -146,26 +133,12 @@ class LocationBarPhone extends LocationBarLayout {
return retVal;
}
@Override
public void finishUrlFocusChange(boolean hasFocus, boolean shouldShowKeyboard) {
super.finishUrlFocusChange(hasFocus, shouldShowKeyboard);
if (!hasFocus) {
mUrlActionContainer.setVisibility(GONE);
}
mStatusCoordinator.onUrlAnimationFinished(hasFocus);
}
@Override
protected void updateButtonVisibility() {
super.updateButtonVisibility();
updateMicButtonVisibility();
}
@Override
public void updateShouldAnimateIconChanges() {
notifyShouldAnimateIconChanges(isUrlBarFocused() || isUrlFocusChangeInProgress());
}
@Override
public void setShowIconsWhenUrlFocused(boolean showIcon) {
super.setShowIconsWhenUrlFocused(showIcon);
......
......@@ -22,7 +22,6 @@ import org.chromium.chrome.browser.omnibox.status.StatusCoordinator;
import org.chromium.chrome.browser.omnibox.suggestions.AutocompleteCoordinator;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.top.ToolbarTablet;
import org.chromium.components.browser_ui.widget.animation.CancelAwareAnimatorListener;
import org.chromium.ui.base.LocalizationUtils;
import org.chromium.ui.interpolators.BakedBezierInterpolator;
......@@ -33,26 +32,11 @@ import java.util.List;
* Location bar for tablet form factors.
*/
class LocationBarTablet extends LocationBarLayout {
private static final long MAX_NTP_KEYBOARD_FOCUS_DURATION_MS = 200;
private static final int ICON_FADE_ANIMATION_DURATION_MS = 150;
private static final int ICON_FADE_ANIMATION_DELAY_MS = 75;
private static final int WIDTH_CHANGE_ANIMATION_DURATION_MS = 225;
private static final int WIDTH_CHANGE_ANIMATION_DELAY_MS = 75;
private final Property<LocationBarTablet, Float> mUrlFocusChangeFractionProperty =
new Property<LocationBarTablet, Float>(Float.class, "") {
@Override
public Float get(LocationBarTablet object) {
return object.mUrlFocusChangeFraction;
}
@Override
public void set(LocationBarTablet object, Float value) {
setUrlFocusChangeFraction(value);
}
};
private final Property<LocationBarTablet, Float> mWidthChangeFractionProperty =
new Property<LocationBarTablet, Float>(Float.class, "") {
@Override
......@@ -69,7 +53,6 @@ class LocationBarTablet extends LocationBarLayout {
private View mLocationBarIcon;
private View mBookmarkButton;
private View mSaveOfflineButton;
private Animator mUrlFocusChangeAnimator;
private View[] mTargets;
private final Rect mCachedTargetBounds = new Rect();
......@@ -155,43 +138,6 @@ class LocationBarTablet extends LocationBarLayout {
return selectedTarget.onTouchEvent(event);
}
@Override
public void handleUrlFocusAnimation(final boolean hasFocus) {
super.handleUrlFocusAnimation(hasFocus);
if (mUrlFocusChangeAnimator != null && mUrlFocusChangeAnimator.isRunning()) {
mUrlFocusChangeAnimator.cancel();
mUrlFocusChangeAnimator = null;
}
if (mLocationBarDataProvider.getNewTabPageDelegate().isCurrentlyVisible()) {
finishUrlFocusChange(hasFocus, /* shouldShowKeyboard= */ hasFocus);
return;
}
Rect rootViewBounds = new Rect();
getRootView().getLocalVisibleRect(rootViewBounds);
float screenSizeRatio = (rootViewBounds.height()
/ (float) (Math.max(rootViewBounds.height(), rootViewBounds.width())));
mUrlFocusChangeAnimator =
ObjectAnimator.ofFloat(this, mUrlFocusChangeFractionProperty, hasFocus ? 1f : 0f);
mUrlFocusChangeAnimator.setDuration(
(long) (MAX_NTP_KEYBOARD_FOCUS_DURATION_MS * screenSizeRatio));
mUrlFocusChangeAnimator.addListener(new CancelAwareAnimatorListener() {
@Override
public void onEnd(Animator animator) {
finishUrlFocusChange(hasFocus, /* shouldShowKeyboard= */ hasFocus);
}
@Override
public void onCancel(Animator animator) {
setUrlFocusChangeInProgress(false);
}
});
setUrlFocusChangeInProgress(true);
mUrlFocusChangeAnimator.start();
}
/**
* Updates progress of current the URL focus change animation.
*
......
......@@ -4,9 +4,11 @@
package org.chromium.chrome.browser.omnibox;
import android.content.Context;
import android.text.TextWatcher;
import android.view.ActionMode;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
......@@ -50,6 +52,7 @@ public class UrlBarCoordinator implements UrlBarEditingTextStateProvider, UrlFoc
private WindowDelegate mWindowDelegate;
private Runnable mKeyboardResizeModeTask = NO_OP_RUNNABLE;
private Runnable mKeyboardHideTask = NO_OP_RUNNABLE;
private Callback<Boolean> mFocusChangeCallback;
/**
* Constructs a coordinator for the given UrlBar view.
......@@ -71,6 +74,7 @@ public class UrlBarCoordinator implements UrlBarEditingTextStateProvider, UrlFoc
mUrlBar = urlBar;
mKeyboardVisibilityDelegate = keyboardVisibilityDelegate;
mWindowDelegate = windowDelegate;
mFocusChangeCallback = focusChangeCallback;
PropertyModel model =
new PropertyModel.Builder(UrlBarProperties.ALL_KEYS)
......@@ -80,7 +84,7 @@ public class UrlBarCoordinator implements UrlBarEditingTextStateProvider, UrlFoc
.build();
PropertyModelChangeProcessor.create(model, urlBar, UrlBarViewBinder::bind);
mMediator = new UrlBarMediator(model, focusChangeCallback);
mMediator = new UrlBarMediator(model, this::onUrlFocusChangeInternal);
}
public void destroy() {
......@@ -90,6 +94,7 @@ public class UrlBarCoordinator implements UrlBarEditingTextStateProvider, UrlFoc
mUrlBar.removeCallbacks(mKeyboardHideTask);
mUrlBar.destroy();
mUrlBar = null;
mFocusChangeCallback = null;
}
/** @see UrlBarMediator#addUrlTextChangeListener(UrlTextChangeListener) */
......@@ -235,4 +240,25 @@ public class UrlBarCoordinator implements UrlBarEditingTextStateProvider, UrlFoc
mWindowDelegate.setWindowSoftInputMode(softInputMode);
}
}
private void onUrlFocusChangeInternal(boolean hasFocus) {
InputMethodManager imm = (InputMethodManager) mUrlBar.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
if (hasFocus) {
// Explicitly tell InputMethodManager that the url bar is focused before any callbacks
// so that it updates the active view accordingly. Otherwise, it may fail to update
// the correct active view if ViewGroup.addView() or ViewGroup.removeView() is called
// to update a view that accepts text input.
imm.viewClicked(mUrlBar);
} else {
// Moving focus away from UrlBar(EditText) to a non-editable focus holder, such as
// ToolbarPhone, won't automatically hide keyboard app, but restart it with TYPE_NULL,
// which will result in a visual glitch. Also, currently, we do not allow moving focus
// directly from omnibox to web content's form field. Therefore, we hide keyboard on
// focus blur indiscriminately here. Note that hiding keyboard may lower FPS of other
// animation effects, but we found it tolerable in an experiment.
if (imm.isActive(mUrlBar)) setKeyboardVisibility(false, false);
}
mFocusChangeCallback.onResult(hasFocus);
}
}
......@@ -286,9 +286,7 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver {
// focused, but hide it when unfocused.
void setUrlAnimationFinished(boolean urlHasFocus) {
// On tablets, the status icon should always be shown so the following logic doesn't apply.
assert !mIsTablet : "This logic shouldn't be called on tablets";
if (!mDelegate.shouldShowSearchEngineLogo(mIsIncognito)) {
if (mIsTablet || !mDelegate.shouldShowSearchEngineLogo(mIsIncognito)) {
return;
}
......
......@@ -2137,8 +2137,7 @@ public class ToolbarPhone extends ToolbarLayout implements OnClickListener, TabC
mLayoutLocationBarInFocusedMode = false;
requestLayout();
}
mLocationBar.getPhoneCoordinator().finishUrlFocusChange(hasFocus,
shouldShowKeyboard,
mLocationBar.finishUrlFocusChange(hasFocus, shouldShowKeyboard,
getToolbarDataProvider().shouldShowLocationBarInOverviewMode());
mUrlFocusChangeInProgress = false;
}
......
......@@ -505,7 +505,7 @@ public class LocationBarLayoutTest {
true, SEARCH_TERMS_URL, OmniboxFocusReason.FAKE_BOX_LONG_PRESS);
});
Assert.assertTrue(locationBar.isUrlBarFocused());
Assert.assertTrue(locationBar.didFocusUrlFromFakebox());
Assert.assertTrue(getLocationBarMediator().didFocusUrlFromFakebox());
Assert.assertEquals(SEARCH_TERMS_URL, getUrlText(getUrlBar()));
Assert.assertEquals(
1, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
......@@ -514,7 +514,7 @@ public class LocationBarLayoutTest {
locationBarMediator.setUrlBarFocus(true, SEARCH_TERMS, OmniboxFocusReason.SEARCH_QUERY);
});
Assert.assertTrue(locationBar.isUrlBarFocused());
Assert.assertTrue(locationBar.didFocusUrlFromFakebox());
Assert.assertTrue(getLocationBarMediator().didFocusUrlFromFakebox());
Assert.assertEquals(SEARCH_TERMS, getUrlText(getUrlBar()));
Assert.assertEquals(
1, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
......@@ -523,7 +523,7 @@ public class LocationBarLayoutTest {
locationBarMediator.setUrlBarFocus(false, null, OmniboxFocusReason.UNFOCUS);
});
Assert.assertFalse(locationBar.isUrlBarFocused());
Assert.assertFalse(locationBar.didFocusUrlFromFakebox());
Assert.assertFalse(getLocationBarMediator().didFocusUrlFromFakebox());
Assert.assertEquals(
1, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
......@@ -531,7 +531,7 @@ public class LocationBarLayoutTest {
locationBarMediator.setUrlBarFocus(true, null, OmniboxFocusReason.OMNIBOX_TAP);
});
Assert.assertTrue(locationBar.isUrlBarFocused());
Assert.assertFalse(locationBar.didFocusUrlFromFakebox());
Assert.assertFalse(getLocationBarMediator().didFocusUrlFromFakebox());
Assert.assertEquals(
2, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
}
......
......@@ -4,11 +4,19 @@
package org.chromium.chrome.browser.omnibox;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.CoreMatchers.allOf;
import static org.mockito.Mockito.doReturn;
import android.content.Intent;
import android.content.res.Configuration;
import androidx.lifecycle.Lifecycle;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.filters.MediumTest;
import org.junit.After;
......@@ -23,9 +31,8 @@ import org.mockito.junit.MockitoRule;
import org.chromium.base.CommandLine;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Criteria;
import org.chromium.base.test.util.CriteriaHelper;
import org.chromium.base.test.util.Matchers;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.app.ChromeActivity;
......@@ -36,11 +43,14 @@ import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.OmniboxTestUtils;
import org.chromium.chrome.test.util.ViewUtils;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.search_engines.TemplateUrlService;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.common.ContentSwitches;
import org.chromium.ui.test.util.UiRestriction;
import java.util.Arrays;
import java.util.List;
......@@ -147,11 +157,7 @@ public class LocationBarTest {
Assert.assertTrue(mLocationBarMediator.isUrlBarFocused());
});
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(
mActivityTestRule.getKeyboardDelegate().isKeyboardShowing(mActivity, mUrlBar),
Matchers.is(true));
});
OmniboxTestUtils.waitForFocusAndKeyboardActive(mUrlBar, true);
}
@Test
......@@ -168,11 +174,7 @@ public class LocationBarTest {
Assert.assertTrue(mLocationBarMediator.isUrlBarFocused());
});
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(
mActivityTestRule.getKeyboardDelegate().isKeyboardShowing(mActivity, mUrlBar),
Matchers.is(true));
});
OmniboxTestUtils.waitForFocusAndKeyboardActive(mUrlBar, true);
}
@Test
......@@ -254,12 +256,16 @@ public class LocationBarTest {
@MediumTest
public void testPostDestroyFocusLogic() {
startActivityNormally();
LocationBarLayout locationBarLayout =
mActivity.findViewById(org.chromium.chrome.R.id.location_bar);
TestThreadUtils.runOnUiThreadBlocking(() -> { mActivity.finish(); });
CriteriaHelper.pollUiThread(
() -> mActivity.getLifecycle().getCurrentState().equals(Lifecycle.State.DESTROYED));
TestThreadUtils.runOnUiThreadBlocking(() -> {
LocationBarLayout locationBarLayout =
mActivity.findViewById(org.chromium.chrome.R.id.location_bar);
locationBarLayout.destroy();
locationBarLayout.finishUrlFocusChange(true, true);
locationBarLayout.setUrlFocusChangeInProgress(false);
mLocationBarMediator.finishUrlFocusChange(true, true);
});
}
......@@ -281,4 +287,100 @@ public class LocationBarTest {
Assert.assertEquals(url.length(), mUrlBar.getSelectionEnd());
});
}
@Test
@MediumTest
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public void testFocusLogic_buttonVisibilityPhone() {
startActivityNormally();
String url = mActivityTestRule.getEmbeddedTestServerRule().getServer().getURLWithHostName(
HOSTNAME, "/");
mActivityTestRule.loadUrl(url);
onView(withId(R.id.url_action_container))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
onView(withId(R.id.mic_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
onView(withId(R.id.delete_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
TestThreadUtils.runOnUiThreadBlocking(() -> { mUrlBar.requestFocus(); });
ViewUtils.waitForView(allOf(withId(R.id.url_action_container),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.mic_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.delete_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
TestThreadUtils.runOnUiThreadBlocking(
() -> { mLocationBarCoordinator.setOmniboxEditingText(url); });
onView(withId(R.id.mic_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
onView(withId(R.id.delete_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
TestThreadUtils.runOnUiThreadBlocking(() -> { mUrlBar.clearFocus(); });
ViewUtils.waitForView(allOf(withId(R.id.url_action_container),
withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
}
@Test
@MediumTest
@Restriction(UiRestriction.RESTRICTION_TYPE_TABLET)
public void testFocusLogic_buttonVisibilityTablet() {
startActivityNormally();
String url = mActivityTestRule.getEmbeddedTestServerRule().getServer().getURLWithHostName(
HOSTNAME, "/");
mActivityTestRule.loadUrl(url);
onView(withId(R.id.url_action_container))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.mic_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
onView(withId(R.id.delete_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
onView(withId(R.id.bookmark_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.save_offline_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
TestThreadUtils.runOnUiThreadBlocking(() -> { mUrlBar.requestFocus(); });
onView(withId(R.id.mic_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.delete_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
TestThreadUtils.runOnUiThreadBlocking(
() -> { mLocationBarCoordinator.setOmniboxEditingText(url); });
onView(withId(R.id.mic_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.delete_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
TestThreadUtils.runOnUiThreadBlocking(() -> { mUrlBar.clearFocus(); });
mLocationBarCoordinator.getTabletCoordinator().setShouldShowButtonsWhenUnfocused(false);
onView(withId(R.id.bookmark_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
onView(withId(R.id.save_offline_button))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
}
@Test
@MediumTest
public void testFocusLogic_keyboardVisibility() {
startActivityNormally();
OmniboxTestUtils.waitForFocusAndKeyboardActive(mUrlBar, false);
TestThreadUtils.runOnUiThreadBlocking(() -> { mUrlBar.requestFocus(); });
OmniboxTestUtils.waitForFocusAndKeyboardActive(mUrlBar, true);
TestThreadUtils.runOnUiThreadBlocking(() -> { mUrlBar.clearFocus(); });
OmniboxTestUtils.waitForFocusAndKeyboardActive(mUrlBar, false);
}
}
include_rules = [
"+chrome/browser/ui/android/toolbar/java/src/org/chromium/chrome/browser/toolbar",
]
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