Commit 30c4010d authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Switch StatusCoordinator/Mediator to using TextWatcher

Events aren't getting through when they should when using
UrlBar.UrlTextChangeListener. Using a combination of TextWatcher and
UrlBarCoordinator triggers more frequently.

Bug: 1008474
Change-Id: I60252e7f2bca878089667cc29f79f82e18884789
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1835101
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704849}
parent 3f3f4ee8
...@@ -217,11 +217,11 @@ public class LocationBarLayout extends FrameLayout ...@@ -217,11 +217,11 @@ public class LocationBarLayout extends FrameLayout
StatusView statusView = findViewById(R.id.location_bar_status); StatusView statusView = findViewById(R.id.location_bar_status);
statusView.setCompositeTouchDelegate(mCompositeTouchDelegate); statusView.setCompositeTouchDelegate(mCompositeTouchDelegate);
mStatusViewCoordinator = new StatusViewCoordinator(mIsTablet, statusView); mStatusViewCoordinator = new StatusViewCoordinator(mIsTablet, statusView, mUrlCoordinator);
mUrlCoordinator.addTextChangedListener(mStatusViewCoordinator);
updateShouldAnimateIconChanges(); updateShouldAnimateIconChanges();
mUrlBar.setOnKeyListener(new UrlBarKeyListener()); mUrlBar.setOnKeyListener(new UrlBarKeyListener());
mUrlCoordinator.addUrlTextChangeListener(mStatusViewCoordinator);
// mLocationBar's direction is tied to this UrlBar's text direction. Icons inside the // mLocationBar's direction is tied to this UrlBar's text direction. Icons inside the
// location bar, e.g. lock, refresh, X, should be reversed if UrlBar's text is RTL. // location bar, e.g. lock, refresh, X, should be reversed if UrlBar's text is RTL.
...@@ -1118,6 +1118,5 @@ public class LocationBarLayout extends FrameLayout ...@@ -1118,6 +1118,5 @@ public class LocationBarLayout extends FrameLayout
String textWithoutAutocomplete = mUrlCoordinator.getTextWithoutAutocomplete(); String textWithoutAutocomplete = mUrlCoordinator.getTextWithoutAutocomplete();
String textWithAutocomplete = mUrlCoordinator.getTextWithAutocomplete(); String textWithAutocomplete = mUrlCoordinator.getTextWithAutocomplete();
mAutocompleteCoordinator.onTextChanged(textWithoutAutocomplete, textWithAutocomplete); mAutocompleteCoordinator.onTextChanged(textWithoutAutocomplete, textWithAutocomplete);
mStatusViewCoordinator.onTextChanged(textWithoutAutocomplete, textWithAutocomplete);
} }
} }
...@@ -13,12 +13,14 @@ import android.os.StrictMode; ...@@ -13,12 +13,14 @@ import android.os.StrictMode;
import android.provider.Settings; import android.provider.Settings;
import android.support.v13.view.inputmethod.EditorInfoCompat; import android.support.v13.view.inputmethod.EditorInfoCompat;
import android.support.v4.text.BidiFormatter; import android.support.v4.text.BidiFormatter;
import android.support.v4.util.ObjectsCompat;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.Layout; import android.text.Layout;
import android.text.Selection; import android.text.Selection;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ReplacementSpan; import android.text.style.ReplacementSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.GestureDetector; import android.view.GestureDetector;
...@@ -97,7 +99,8 @@ public abstract class UrlBar extends AutocompleteEditText { ...@@ -97,7 +99,8 @@ public abstract class UrlBar extends AutocompleteEditText {
private int mUrlDirection; private int mUrlDirection;
private UrlBarDelegate mUrlBarDelegate; private UrlBarDelegate mUrlBarDelegate;
private UrlTextChangeListener mTextChangeListener; private UrlTextChangeListener mUrlTextChangeListener;
private TextWatcher mTextChangedListener;
private UrlBarTextContextMenuDelegate mTextContextMenuDelegate; private UrlBarTextContextMenuDelegate mTextContextMenuDelegate;
private UrlDirectionListener mUrlDirectionListener; private UrlDirectionListener mUrlDirectionListener;
...@@ -590,7 +593,22 @@ public abstract class UrlBar extends AutocompleteEditText { ...@@ -590,7 +593,22 @@ public abstract class UrlBar extends AutocompleteEditText {
* @param listener The listener to be notified. * @param listener The listener to be notified.
*/ */
public void setUrlTextChangeListener(UrlTextChangeListener listener) { public void setUrlTextChangeListener(UrlTextChangeListener listener) {
mTextChangeListener = listener; mUrlTextChangeListener = listener;
}
/**
* Set the listener to be notified when the view's text has changed.
* @param textChangedListener The listener to be notified.
*/
public void setTextChangedListener(TextWatcher textChangedListener) {
if (ObjectsCompat.equals(mTextChangedListener, textChangedListener)) {
return;
} else if (mTextChangedListener != null) {
removeTextChangedListener(mTextChangedListener);
}
mTextChangedListener = textChangedListener;
addTextChangedListener(mTextChangedListener);
} }
/** /**
...@@ -950,12 +968,13 @@ public abstract class UrlBar extends AutocompleteEditText { ...@@ -950,12 +968,13 @@ public abstract class UrlBar extends AutocompleteEditText {
if (DEBUG) { if (DEBUG) {
Log.i(TAG, "onAutocompleteTextStateChanged: DIS[%b]", updateDisplay); Log.i(TAG, "onAutocompleteTextStateChanged: DIS[%b]", updateDisplay);
} }
if (mTextChangeListener == null) return; if (mUrlTextChangeListener == null) return;
if (updateDisplay) limitDisplayableLength(); if (updateDisplay) limitDisplayableLength();
// crbug.com/764749 // crbug.com/764749
Log.w(TAG, "Text change observed, triggering autocomplete."); Log.w(TAG, "Text change observed, triggering autocomplete.");
mTextChangeListener.onTextChanged(getTextWithoutAutocomplete(), getTextWithAutocomplete()); mUrlTextChangeListener.onTextChanged(
getTextWithoutAutocomplete(), getTextWithAutocomplete());
} }
/** /**
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.omnibox; package org.chromium.chrome.browser.omnibox;
import android.text.TextWatcher;
import android.view.ActionMode; import android.view.ActionMode;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
...@@ -60,6 +61,11 @@ public class UrlBarCoordinator implements UrlBarEditingTextStateProvider { ...@@ -60,6 +61,11 @@ public class UrlBarCoordinator implements UrlBarEditingTextStateProvider {
mMediator.addUrlTextChangeListener(listener); mMediator.addUrlTextChangeListener(listener);
} }
/** @see TextWatcher */
public void addTextChangedListener(TextWatcher textWatcher) {
mMediator.addTextChangedListener(textWatcher);
}
/** @see UrlBarMediator#setUrlBarData(UrlBarData, int, int) */ /** @see UrlBarMediator#setUrlBarData(UrlBarData, int, int) */
public boolean setUrlBarData( public boolean setUrlBarData(
UrlBarData data, @ScrollType int scrollType, @SelectionState int state) { UrlBarData data, @ScrollType int scrollType, @SelectionState int state) {
......
...@@ -8,8 +8,10 @@ import android.content.ClipData; ...@@ -8,8 +8,10 @@ import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.text.Editable;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.ActionMode; import android.view.ActionMode;
...@@ -41,7 +43,8 @@ import java.util.List; ...@@ -41,7 +43,8 @@ import java.util.List;
/** /**
* Handles collecting and pushing state information to the UrlBar model. * Handles collecting and pushing state information to the UrlBar model.
*/ */
class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.UrlTextChangeListener { class UrlBarMediator
implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.UrlTextChangeListener, TextWatcher {
private final PropertyModel mModel; private final PropertyModel mModel;
private Callback<Boolean> mOnFocusChangeCallback; private Callback<Boolean> mOnFocusChangeCallback;
...@@ -58,6 +61,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url ...@@ -58,6 +61,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url
private static final int NUM_OF_BUCKETS = 100; private static final int NUM_OF_BUCKETS = 100;
private final List<UrlTextChangeListener> mUrlTextChangeListeners = new ArrayList<>(); private final List<UrlTextChangeListener> mUrlTextChangeListeners = new ArrayList<>();
private final List<TextWatcher> mTextChangedListeners = new ArrayList<>();
public UrlBarMediator(PropertyModel model) { public UrlBarMediator(PropertyModel model) {
mModel = model; mModel = model;
...@@ -66,6 +70,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url ...@@ -66,6 +70,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url
mModel.set(UrlBarProperties.SHOW_CURSOR, false); mModel.set(UrlBarProperties.SHOW_CURSOR, false);
mModel.set(UrlBarProperties.TEXT_CONTEXT_MENU_DELEGATE, this); mModel.set(UrlBarProperties.TEXT_CONTEXT_MENU_DELEGATE, this);
mModel.set(UrlBarProperties.URL_TEXT_CHANGE_LISTENER, this); mModel.set(UrlBarProperties.URL_TEXT_CHANGE_LISTENER, this);
mModel.set(UrlBarProperties.TEXT_CHANGED_LISTENER, this);
setUseDarkTextColors(true); setUseDarkTextColors(true);
} }
...@@ -81,6 +86,11 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url ...@@ -81,6 +86,11 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url
mUrlTextChangeListeners.add(listener); mUrlTextChangeListeners.add(listener);
} }
/** @see android.widget.TextView#addTextChangedListener */
public void addTextChangedListener(TextWatcher textWatcher) {
mTextChangedListeners.add(textWatcher);
}
/** /**
* Updates the text content of the UrlBar. * Updates the text content of the UrlBar.
* *
...@@ -355,6 +365,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url ...@@ -355,6 +365,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url
return url.substring(0, pathIndex); return url.substring(0, pathIndex);
} }
/** @see UrlTextChangeListener */
@Override @Override
public void onTextChanged(String textWithoutAutocomplete, String textWithAutocomplete) { public void onTextChanged(String textWithoutAutocomplete, String textWithAutocomplete) {
for (int i = 0; i < mUrlTextChangeListeners.size(); i++) { for (int i = 0; i < mUrlTextChangeListeners.size(); i++) {
...@@ -363,6 +374,30 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url ...@@ -363,6 +374,30 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate, UrlBar.Url
} }
} }
/** @see TextWatcher */
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
for (int i = 0; i < mTextChangedListeners.size(); i++) {
mTextChangedListeners.get(i).beforeTextChanged(s, start, count, after);
}
}
/** @see TextWatcher */
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
for (int i = 0; i < mTextChangedListeners.size(); i++) {
mTextChangedListeners.get(i).onTextChanged(s, start, before, count);
}
}
/** @see TextWatcher */
@Override
public void afterTextChanged(Editable editable) {
for (int i = 0; i < mTextChangedListeners.size(); i++) {
mTextChangedListeners.get(i).afterTextChanged(editable);
}
}
private void recordPasteMetrics(String text) { private void recordPasteMetrics(String text) {
boolean isUrl = BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) boolean isUrl = BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
.isFullBrowserStarted() .isFullBrowserStarted()
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.omnibox; package org.chromium.chrome.browser.omnibox;
import android.text.TextWatcher;
import android.view.ActionMode; import android.view.ActionMode;
import org.chromium.base.Callback; import org.chromium.base.Callback;
...@@ -115,10 +116,14 @@ class UrlBarProperties { ...@@ -115,10 +116,14 @@ class UrlBarProperties {
public static final WritableObjectPropertyKey<UrlDirectionListener> URL_DIRECTION_LISTENER = public static final WritableObjectPropertyKey<UrlDirectionListener> URL_DIRECTION_LISTENER =
new WritableObjectPropertyKey<>(); new WritableObjectPropertyKey<>();
/** The callback to be notified on text changes. */ /** The callback to be notified on url text changes. @see UrlTextChangeListener. */
public static final WritableObjectPropertyKey<UrlTextChangeListener> URL_TEXT_CHANGE_LISTENER = public static final WritableObjectPropertyKey<UrlTextChangeListener> URL_TEXT_CHANGE_LISTENER =
new WritableObjectPropertyKey<>(); new WritableObjectPropertyKey<>();
/** The callback to be notified on text changes. @see TextWatcher. */
public static final WritableObjectPropertyKey<TextWatcher> TEXT_CHANGED_LISTENER =
new WritableObjectPropertyKey<>();
/** Specifies whether dark text colors should be used in the view. */ /** Specifies whether dark text colors should be used in the view. */
public static final WritableBooleanPropertyKey USE_DARK_TEXT_COLORS = public static final WritableBooleanPropertyKey USE_DARK_TEXT_COLORS =
new WritableBooleanPropertyKey(); new WritableBooleanPropertyKey();
...@@ -130,5 +135,5 @@ class UrlBarProperties { ...@@ -130,5 +135,5 @@ class UrlBarProperties {
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ACTION_MODE_CALLBACK, public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ACTION_MODE_CALLBACK,
ALLOW_FOCUS, AUTOCOMPLETE_TEXT, DELEGATE, FOCUS_CHANGE_CALLBACK, SHOW_CURSOR, ALLOW_FOCUS, AUTOCOMPLETE_TEXT, DELEGATE, FOCUS_CHANGE_CALLBACK, SHOW_CURSOR,
TEXT_CONTEXT_MENU_DELEGATE, TEXT_STATE, URL_DIRECTION_LISTENER, TEXT_CONTEXT_MENU_DELEGATE, TEXT_STATE, URL_DIRECTION_LISTENER,
URL_TEXT_CHANGE_LISTENER, USE_DARK_TEXT_COLORS, WINDOW_DELEGATE}; URL_TEXT_CHANGE_LISTENER, TEXT_CHANGED_LISTENER, USE_DARK_TEXT_COLORS, WINDOW_DELEGATE};
} }
...@@ -73,6 +73,8 @@ class UrlBarViewBinder { ...@@ -73,6 +73,8 @@ class UrlBarViewBinder {
view.setUrlDirectionListener(model.get(UrlBarProperties.URL_DIRECTION_LISTENER)); view.setUrlDirectionListener(model.get(UrlBarProperties.URL_DIRECTION_LISTENER));
} else if (UrlBarProperties.URL_TEXT_CHANGE_LISTENER.equals(propertyKey)) { } else if (UrlBarProperties.URL_TEXT_CHANGE_LISTENER.equals(propertyKey)) {
view.setUrlTextChangeListener(model.get(UrlBarProperties.URL_TEXT_CHANGE_LISTENER)); view.setUrlTextChangeListener(model.get(UrlBarProperties.URL_TEXT_CHANGE_LISTENER));
} else if (UrlBarProperties.TEXT_CHANGED_LISTENER.equals(propertyKey)) {
view.setTextChangedListener(model.get(UrlBarProperties.TEXT_CHANGED_LISTENER));
} else if (UrlBarProperties.WINDOW_DELEGATE.equals(propertyKey)) { } else if (UrlBarProperties.WINDOW_DELEGATE.equals(propertyKey)) {
view.setWindowDelegate(model.get(UrlBarProperties.WINDOW_DELEGATE)); view.setWindowDelegate(model.get(UrlBarProperties.WINDOW_DELEGATE));
} }
......
...@@ -18,7 +18,7 @@ import org.chromium.base.VisibleForTesting; ...@@ -18,7 +18,7 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.omnibox.SearchEngineLogoUtils; import org.chromium.chrome.browser.omnibox.SearchEngineLogoUtils;
import org.chromium.chrome.browser.omnibox.UrlBar; import org.chromium.chrome.browser.omnibox.UrlBarEditingTextStateProvider;
import org.chromium.chrome.browser.omnibox.suggestions.AutocompleteCoordinatorFactory; import org.chromium.chrome.browser.omnibox.suggestions.AutocompleteCoordinatorFactory;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.toolbar.ToolbarCommonPropertiesModel; import org.chromium.chrome.browser.toolbar.ToolbarCommonPropertiesModel;
...@@ -89,15 +89,18 @@ class StatusMediator { ...@@ -89,15 +89,18 @@ class StatusMediator {
private StatusMediatorDelegate mDelegate; private StatusMediatorDelegate mDelegate;
private Resources mResources; private Resources mResources;
private ToolbarCommonPropertiesModel mToolbarCommonPropertiesModel; private ToolbarCommonPropertiesModel mToolbarCommonPropertiesModel;
private UrlBarEditingTextStateProvider mUrlBarEditingTextStateProvider;
private String mUrlBarTextWithAutocomplete = ""; private String mUrlBarTextWithAutocomplete = "";
private boolean mUrlBarTextIsValidUrl; private boolean mUrlBarTextIsValidUrl;
StatusMediator(PropertyModel model, Resources resources) { StatusMediator(PropertyModel model, Resources resources,
UrlBarEditingTextStateProvider urlBarEditingTextStateProvider) {
mModel = model; mModel = model;
mDelegate = new StatusMediatorDelegate(); mDelegate = new StatusMediatorDelegate();
updateColorTheme(); updateColorTheme();
mResources = resources; mResources = resources;
mUrlBarEditingTextStateProvider = urlBarEditingTextStateProvider;
} }
/** /**
...@@ -497,8 +500,13 @@ class StatusMediator { ...@@ -497,8 +500,13 @@ class StatusMediator {
return 0; return 0;
} }
/** @see {@link UrlBar.UrlTextChangeListener} */ /** @see android.text.TextWatcher#onTextChanged */
void onTextChanged(String urlTextWithoutAutocomplete, String urlTextWithAutocomplete) { void onTextChanged(CharSequence charSequence) {
// TODO (crbug.com/1012870): This is a workaround for the linked bug. Once the bug is fixed,
// it should be removed.
String urlTextWithAutocomplete = TextUtils.isEmpty(charSequence)
? ""
: mUrlBarEditingTextStateProvider.getTextWithAutocomplete();
if (TextUtils.equals(mUrlBarTextWithAutocomplete, urlTextWithAutocomplete)) { if (TextUtils.equals(mUrlBarTextWithAutocomplete, urlTextWithAutocomplete)) {
return; return;
} }
......
...@@ -5,13 +5,15 @@ ...@@ -5,13 +5,15 @@
package org.chromium.chrome.browser.omnibox.status; package org.chromium.chrome.browser.omnibox.status;
import android.content.res.Resources; import android.content.res.Resources;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View; import android.view.View;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.omnibox.UrlBar; import org.chromium.chrome.browser.omnibox.UrlBarEditingTextStateProvider;
import org.chromium.chrome.browser.page_info.PageInfoController; import org.chromium.chrome.browser.page_info.PageInfoController;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider; import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -21,7 +23,7 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor; ...@@ -21,7 +23,7 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
* A component for displaying a status icon (e.g. security icon or navigation icon) and optional * A component for displaying a status icon (e.g. security icon or navigation icon) and optional
* verbose status text. * verbose status text.
*/ */
public class StatusViewCoordinator implements View.OnClickListener, UrlBar.UrlTextChangeListener { public class StatusViewCoordinator implements View.OnClickListener, TextWatcher {
private final StatusView mStatusView; private final StatusView mStatusView;
private final StatusMediator mMediator; private final StatusMediator mMediator;
private final PropertyModel mModel; private final PropertyModel mModel;
...@@ -34,8 +36,10 @@ public class StatusViewCoordinator implements View.OnClickListener, UrlBar.UrlTe ...@@ -34,8 +36,10 @@ public class StatusViewCoordinator implements View.OnClickListener, UrlBar.UrlTe
* Creates a new StatusViewCoordinator. * Creates a new StatusViewCoordinator.
* @param isTablet Whether the UI is shown on a tablet. * @param isTablet Whether the UI is shown on a tablet.
* @param statusView The status view, used to supply and manipulate child views. * @param statusView The status view, used to supply and manipulate child views.
* @param urlBarEditingTextStateProvider The url coordinator.
*/ */
public StatusViewCoordinator(boolean isTablet, StatusView statusView) { public StatusViewCoordinator(boolean isTablet, StatusView statusView,
UrlBarEditingTextStateProvider urlBarEditingTextStateProvider) {
mIsTablet = isTablet; mIsTablet = isTablet;
mStatusView = statusView; mStatusView = statusView;
...@@ -44,7 +48,8 @@ public class StatusViewCoordinator implements View.OnClickListener, UrlBar.UrlTe ...@@ -44,7 +48,8 @@ public class StatusViewCoordinator implements View.OnClickListener, UrlBar.UrlTe
.build(); .build();
PropertyModelChangeProcessor.create(mModel, mStatusView, new StatusViewBinder()); PropertyModelChangeProcessor.create(mModel, mStatusView, new StatusViewBinder());
mMediator = new StatusMediator(mModel, mStatusView.getResources()); mMediator = new StatusMediator(
mModel, mStatusView.getResources(), urlBarEditingTextStateProvider);
Resources res = mStatusView.getResources(); Resources res = mStatusView.getResources();
mMediator.setUrlMinWidth(res.getDimensionPixelSize(R.dimen.location_bar_min_url_width) mMediator.setUrlMinWidth(res.getDimensionPixelSize(R.dimen.location_bar_min_url_width)
...@@ -216,7 +221,13 @@ public class StatusViewCoordinator implements View.OnClickListener, UrlBar.UrlTe ...@@ -216,7 +221,13 @@ public class StatusViewCoordinator implements View.OnClickListener, UrlBar.UrlTe
} }
@Override @Override
public void onTextChanged(String textWithoutAutocomplete, String textWithAutocomplete) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
mMediator.onTextChanged(textWithoutAutocomplete, textWithAutocomplete);
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
mMediator.onTextChanged(charSequence);
} }
@Override
public void afterTextChanged(Editable editable) {}
} }
...@@ -25,6 +25,7 @@ import org.chromium.base.Callback; ...@@ -25,6 +25,7 @@ import org.chromium.base.Callback;
import org.chromium.base.test.BaseRobolectricTestRunner; import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.omnibox.UrlBarEditingTextStateProvider;
import org.chromium.chrome.browser.toolbar.ToolbarCommonPropertiesModel; import org.chromium.chrome.browser.toolbar.ToolbarCommonPropertiesModel;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -42,6 +43,8 @@ public final class StatusMediatorUnitTest { ...@@ -42,6 +43,8 @@ public final class StatusMediatorUnitTest {
@Mock @Mock
ToolbarCommonPropertiesModel mToolbarCommonPropertiesModel; ToolbarCommonPropertiesModel mToolbarCommonPropertiesModel;
@Mock @Mock
UrlBarEditingTextStateProvider mUrlBarEditingTextStateProvider;
@Mock
StatusMediator.StatusMediatorDelegate mDelegate; StatusMediator.StatusMediatorDelegate mDelegate;
@Mock @Mock
Bitmap mBitmap; Bitmap mBitmap;
...@@ -56,7 +59,7 @@ public final class StatusMediatorUnitTest { ...@@ -56,7 +59,7 @@ public final class StatusMediatorUnitTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mModel = new PropertyModel(StatusProperties.ALL_KEYS); mModel = new PropertyModel(StatusProperties.ALL_KEYS);
mMediator = new StatusMediator(mModel, mResources); mMediator = new StatusMediator(mModel, mResources, mUrlBarEditingTextStateProvider);
mMediator.setToolbarCommonPropertiesModel(mToolbarCommonPropertiesModel); mMediator.setToolbarCommonPropertiesModel(mToolbarCommonPropertiesModel);
mMediator.setDelegateForTesting(mDelegate); mMediator.setDelegateForTesting(mDelegate);
} }
...@@ -123,7 +126,7 @@ public final class StatusMediatorUnitTest { ...@@ -123,7 +126,7 @@ public final class StatusMediatorUnitTest {
mMediator.setUrlHasFocus(true); mMediator.setUrlHasFocus(true);
mMediator.setShowIconsWhenUrlFocused(true); mMediator.setShowIconsWhenUrlFocused(true);
mMediator.onTextChanged("", "testing"); mMediator.onTextChanged(TEST_SEARCH_URL);
Assert.assertEquals(R.drawable.ic_globe_24dp, mModel.get(StatusProperties.STATUS_ICON_RES)); Assert.assertEquals(R.drawable.ic_globe_24dp, mModel.get(StatusProperties.STATUS_ICON_RES));
} }
......
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