Skip to content

Commit af3eed8

Browse files
author
Changwan Ryu
committed
Stop notifying autocomplete text state change on selection change
Selection change at focus gain triggers onAutocompleteTextStateChanged() and this causes LocationBarLayout and AutocompleteController to stop generating omnibox suggestions. BUG=759876 (cherry picked from commit bc99b84) Change-Id: I96fd12e5ef116862ee44f082b9234a9f4b9c11bd Reviewed-on: https://chromium-review.googlesource.com/651572 Reviewed-by: Ted Choc <[email protected]> Commit-Queue: Changwan Ryu <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#500052} Reviewed-on: https://chromium-review.googlesource.com/656533 Reviewed-by: Changwan Ryu <[email protected]> Cr-Commit-Position: refs/branch-heads/3202@{#73} Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
1 parent 11fcec9 commit af3eed8

File tree

3 files changed

+72
-12
lines changed

3 files changed

+72
-12
lines changed

chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteState.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ public void commitAutocompleteText() {
143143
mAutocompleteText = "";
144144
}
145145

146-
public boolean equalsExceptAutocompleteText(AutocompleteState a) {
147-
return mUserText.equals(a.mUserText) && mSelStart == a.mSelStart && mSelEnd == a.mSelEnd;
148-
}
149-
150146
@Override
151147
public boolean equals(Object o) {
152148
if (!(o instanceof AutocompleteState)) return false;

chrome/android/java/src/org/chromium/chrome/browser/omnibox/SpannableAutocompleteEditTextModel.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,12 @@ private void notifyAutocompleteTextStateChanged() {
182182
if (mBatchEditNestCount > 0) return;
183183
if (mCurrentState.equals(mPreviouslyNotifiedState)) return;
184184
notifyAccessibilityService();
185-
// Nothing has changed except that autocomplete text has been set or modified.
186-
if (mCurrentState.equalsExceptAutocompleteText(mPreviouslyNotifiedState)
187-
&& mCurrentState.hasAutocompleteText()) {
188-
// Autocomplete text is set by the controller, we should not notify the controller with
189-
// the same information.
185+
if (mCurrentState.getUserText().equals(mPreviouslyNotifiedState.getUserText())
186+
&& (mCurrentState.hasAutocompleteText()
187+
|| !mPreviouslyNotifiedState.hasAutocompleteText())) {
188+
// Nothing has changed except that autocomplete text has been set or modified. Or
189+
// selection change did not affect autocomplete text. Autocomplete text is set by the
190+
// controller, so only text change or deletion of autocomplete text should be notified.
190191
mPreviouslyNotifiedState.copyFrom(mCurrentState);
191192
return;
192193
}

chrome/android/junit/src/org/chromium/chrome/browser/omnibox/AutocompleteEditTextTest.java

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.view.accessibility.AccessibilityEvent;
2020
import android.view.inputmethod.EditorInfo;
2121
import android.view.inputmethod.InputConnection;
22+
import android.widget.LinearLayout;
2223

2324
import org.junit.Before;
2425
import org.junit.Rule;
@@ -60,6 +61,8 @@ public class AutocompleteEditTextTest {
6061

6162
private InOrder mInOrder;
6263
private TestAutocompleteEditText mAutocomplete;
64+
private LinearLayout mFocusPlaceHolder;
65+
6366
private Context mContext;
6467
private InputConnection mInputConnection;
6568
private Verifier mVerifier;
@@ -160,13 +163,16 @@ public void setUp() throws Exception {
160163

161164
mVerifier = spy(new Verifier());
162165
mAutocomplete = new TestAutocompleteEditText(mContext, null);
166+
mFocusPlaceHolder = new LinearLayout(mContext);
167+
mFocusPlaceHolder.setFocusable(true);
168+
mFocusPlaceHolder.addView(mAutocomplete);
163169
assertNotNull(mAutocomplete);
164170

165171
// Pretend that the view is shown in the activity hierarchy, which is for accessibility
166172
// testing.
167173
Activity activity = Robolectric.buildActivity(Activity.class).create().get();
168-
activity.setContentView(mAutocomplete);
169-
assertNotNull(mAutocomplete.getParent());
174+
activity.setContentView(mFocusPlaceHolder);
175+
assertNotNull(mFocusPlaceHolder.getParent());
170176
mIsShown = true;
171177
assertTrue(mAutocomplete.isShown());
172178

@@ -181,7 +187,7 @@ public void setUp() throws Exception {
181187
mInOrder = inOrder(mVerifier);
182188
assertTrue(mAutocomplete.requestFocus());
183189
verifyOnPopulateAccessibilityEvent(
184-
AccessibilityEvent.TYPE_VIEW_FOCUSED, "", "", 1, -1, -1, -1, -1);
190+
AccessibilityEvent.TYPE_VIEW_FOCUSED, "", "", 2, -1, -1, -1, -1);
185191
assertNotNull(mAutocomplete.onCreateInputConnection(new EditorInfo()));
186192
mInputConnection = mAutocomplete.getInputConnection();
187193
assertNotNull(mInputConnection);
@@ -1104,4 +1110,61 @@ public void testOnSaveInstanceStateDoesNotCrash() {
11041110
// should not crash.
11051111
new SpannableString(mAutocomplete.getText());
11061112
}
1113+
1114+
// crbug.com/759876
1115+
@Test
1116+
@Features(@Features.Register(
1117+
value = ChromeFeatureList.SPANNABLE_INLINE_AUTOCOMPLETE, enabled = true))
1118+
public void testFocusInAndSelectAllWithSpannableModel() {
1119+
internalTestFocusInAndSelectAll();
1120+
}
1121+
1122+
// crbug.com/759876
1123+
@Test
1124+
@Features(@Features.Register(
1125+
value = ChromeFeatureList.SPANNABLE_INLINE_AUTOCOMPLETE, enabled = false))
1126+
public void testFocusInAndSelectAllWithoutSpannableModel() {
1127+
internalTestFocusInAndSelectAll();
1128+
}
1129+
1130+
private void internalTestFocusInAndSelectAll() {
1131+
final String url = "https://google.com";
1132+
final int len = url.length();
1133+
mAutocomplete.setIgnoreTextChangesForAutocomplete(true);
1134+
mAutocomplete.setText(url);
1135+
mAutocomplete.setIgnoreTextChangesForAutocomplete(false);
1136+
1137+
mInOrder.verifyNoMoreInteractions();
1138+
assertVerifierCallCounts(0, 0);
1139+
1140+
assertTrue(mFocusPlaceHolder.requestFocus());
1141+
1142+
mInOrder.verifyNoMoreInteractions();
1143+
assertVerifierCallCounts(0, 0);
1144+
1145+
// LocationBarLayout does this.
1146+
mAutocomplete.setSelectAllOnFocus(true);
1147+
1148+
assertTrue(mAutocomplete.requestFocus());
1149+
1150+
if (isUsingSpannableModel()) {
1151+
verifyOnPopulateAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED,
1152+
url, "", 18, 18, 18, -1, -1);
1153+
}
1154+
mInOrder.verify(mVerifier).onUpdateSelection(len, len);
1155+
verifyOnPopulateAccessibilityEvent(
1156+
AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED, url, "", 18, 18, 18, -1, -1);
1157+
mInOrder.verify(mVerifier).onUpdateSelection(0, len);
1158+
verifyOnPopulateAccessibilityEvent(
1159+
AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED, url, "", 18, 0, 18, -1, -1);
1160+
verifyOnPopulateAccessibilityEvent(
1161+
AccessibilityEvent.TYPE_VIEW_FOCUSED, url, "", 2, -1, -1, -1, -1);
1162+
1163+
if (isUsingSpannableModel()) {
1164+
assertVerifierCallCounts(2, 4);
1165+
} else {
1166+
assertVerifierCallCounts(2, 3);
1167+
}
1168+
mInOrder.verifyNoMoreInteractions();
1169+
}
11071170
}

0 commit comments

Comments
 (0)