19
19
import android .view .accessibility .AccessibilityEvent ;
20
20
import android .view .inputmethod .EditorInfo ;
21
21
import android .view .inputmethod .InputConnection ;
22
+ import android .widget .LinearLayout ;
22
23
23
24
import org .junit .Before ;
24
25
import org .junit .Rule ;
@@ -60,6 +61,8 @@ public class AutocompleteEditTextTest {
60
61
61
62
private InOrder mInOrder ;
62
63
private TestAutocompleteEditText mAutocomplete ;
64
+ private LinearLayout mFocusPlaceHolder ;
65
+
63
66
private Context mContext ;
64
67
private InputConnection mInputConnection ;
65
68
private Verifier mVerifier ;
@@ -160,13 +163,16 @@ public void setUp() throws Exception {
160
163
161
164
mVerifier = spy (new Verifier ());
162
165
mAutocomplete = new TestAutocompleteEditText (mContext , null );
166
+ mFocusPlaceHolder = new LinearLayout (mContext );
167
+ mFocusPlaceHolder .setFocusable (true );
168
+ mFocusPlaceHolder .addView (mAutocomplete );
163
169
assertNotNull (mAutocomplete );
164
170
165
171
// Pretend that the view is shown in the activity hierarchy, which is for accessibility
166
172
// testing.
167
173
Activity activity = Robolectric .buildActivity (Activity .class ).create ().get ();
168
- activity .setContentView (mAutocomplete );
169
- assertNotNull (mAutocomplete .getParent ());
174
+ activity .setContentView (mFocusPlaceHolder );
175
+ assertNotNull (mFocusPlaceHolder .getParent ());
170
176
mIsShown = true ;
171
177
assertTrue (mAutocomplete .isShown ());
172
178
@@ -181,7 +187,7 @@ public void setUp() throws Exception {
181
187
mInOrder = inOrder (mVerifier );
182
188
assertTrue (mAutocomplete .requestFocus ());
183
189
verifyOnPopulateAccessibilityEvent (
184
- AccessibilityEvent .TYPE_VIEW_FOCUSED , "" , "" , 1 , -1 , -1 , -1 , -1 );
190
+ AccessibilityEvent .TYPE_VIEW_FOCUSED , "" , "" , 2 , -1 , -1 , -1 , -1 );
185
191
assertNotNull (mAutocomplete .onCreateInputConnection (new EditorInfo ()));
186
192
mInputConnection = mAutocomplete .getInputConnection ();
187
193
assertNotNull (mInputConnection );
@@ -1104,4 +1110,61 @@ public void testOnSaveInstanceStateDoesNotCrash() {
1104
1110
// should not crash.
1105
1111
new SpannableString (mAutocomplete .getText ());
1106
1112
}
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
+ }
1107
1170
}
0 commit comments