| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 | 8 |
| 9 import android.annotation.SuppressLint; | 9 import android.annotation.SuppressLint; |
| 10 import android.content.ClipData; | 10 import android.content.ClipData; |
| 11 import android.content.ClipboardManager; | 11 import android.content.ClipboardManager; |
| 12 import android.content.Context; | 12 import android.content.Context; |
| 13 import android.content.Intent; | 13 import android.content.Intent; |
| 14 import android.support.test.InstrumentationRegistry; |
| 14 import android.support.test.filters.SmallTest; | 15 import android.support.test.filters.SmallTest; |
| 15 import android.text.Editable; | 16 import android.text.Editable; |
| 16 import android.text.TextUtils; | 17 import android.text.TextUtils; |
| 17 import android.view.KeyEvent; | 18 import android.view.KeyEvent; |
| 18 import android.view.inputmethod.BaseInputConnection; | 19 import android.view.inputmethod.BaseInputConnection; |
| 19 | 20 |
| 21 import org.junit.Assert; |
| 22 import org.junit.Before; |
| 23 import org.junit.Rule; |
| 24 import org.junit.Test; |
| 25 import org.junit.runner.RunWith; |
| 26 |
| 20 import org.chromium.base.ThreadUtils; | 27 import org.chromium.base.ThreadUtils; |
| 21 import org.chromium.base.test.util.CallbackHelper; | 28 import org.chromium.base.test.util.CallbackHelper; |
| 29 import org.chromium.base.test.util.CommandLineFlags; |
| 22 import org.chromium.base.test.util.Feature; | 30 import org.chromium.base.test.util.Feature; |
| 23 import org.chromium.base.test.util.Restriction; | 31 import org.chromium.base.test.util.Restriction; |
| 24 import org.chromium.base.test.util.RetryOnFailure; | 32 import org.chromium.base.test.util.RetryOnFailure; |
| 25 import org.chromium.chrome.R; | 33 import org.chromium.chrome.R; |
| 26 import org.chromium.chrome.browser.ChromeActivity; | 34 import org.chromium.chrome.browser.ChromeActivity; |
| 35 import org.chromium.chrome.browser.ChromeSwitches; |
| 27 import org.chromium.chrome.browser.profiles.Profile; | 36 import org.chromium.chrome.browser.profiles.Profile; |
| 28 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 37 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 38 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 29 import org.chromium.chrome.test.util.OmniboxTestUtils; | 39 import org.chromium.chrome.test.util.OmniboxTestUtils; |
| 30 import org.chromium.chrome.test.util.OmniboxTestUtils.StubAutocompleteController
; | 40 import org.chromium.chrome.test.util.OmniboxTestUtils.StubAutocompleteController
; |
| 31 import org.chromium.content.browser.test.util.Criteria; | 41 import org.chromium.content.browser.test.util.Criteria; |
| 32 import org.chromium.content.browser.test.util.CriteriaHelper; | 42 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 33 import org.chromium.content.browser.test.util.KeyUtils; | 43 import org.chromium.content.browser.test.util.KeyUtils; |
| 34 | 44 |
| 35 import java.util.concurrent.Callable; | 45 import java.util.concurrent.Callable; |
| 36 import java.util.concurrent.ExecutionException; | 46 import java.util.concurrent.ExecutionException; |
| 37 import java.util.concurrent.TimeoutException; | 47 import java.util.concurrent.TimeoutException; |
| 38 import java.util.concurrent.atomic.AtomicBoolean; | 48 import java.util.concurrent.atomic.AtomicBoolean; |
| 39 import java.util.concurrent.atomic.AtomicReference; | 49 import java.util.concurrent.atomic.AtomicReference; |
| 40 | 50 |
| 41 /** | 51 /** |
| 42 * Tests for the URL bar UI component. | 52 * Tests for the URL bar UI component. |
| 43 */ | 53 */ |
| 44 public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> { | 54 @RunWith(ChromeJUnit4ClassRunner.class) |
| 55 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 56 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| 57 public class UrlBarTest { |
| 58 // 9000+ chars of goodness |
| 45 | 59 |
| 46 // 9000+ chars of goodness | 60 @Rule |
| 61 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| 62 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 63 |
| 47 private static final String HUGE_URL = | 64 private static final String HUGE_URL = |
| 48 "data:text/plain,H" | 65 "data:text/plain,H" |
| 49 + new String(new char[9000]).replace('\0', 'u') | 66 + new String(new char[9000]).replace('\0', 'u') |
| 50 + "ge!"; | 67 + "ge!"; |
| 51 | 68 |
| 52 public UrlBarTest() { | |
| 53 super(ChromeActivity.class); | |
| 54 } | |
| 55 | |
| 56 private UrlBar getUrlBar() { | 69 private UrlBar getUrlBar() { |
| 57 return (UrlBar) getActivity().findViewById(R.id.url_bar); | 70 return (UrlBar) mActivityTestRule.getActivity().findViewById(R.id.url_ba
r); |
| 58 } | 71 } |
| 59 | 72 |
| 60 private void stubLocationBarAutocomplete() { | 73 private void stubLocationBarAutocomplete() { |
| 61 setAutocompleteController(new StubAutocompleteController()); | 74 setAutocompleteController(new StubAutocompleteController()); |
| 62 } | 75 } |
| 63 | 76 |
| 64 private void setAutocompleteController(final AutocompleteController controll
er) { | 77 private void setAutocompleteController(final AutocompleteController controll
er) { |
| 65 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 78 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 66 @Override | 79 @Override |
| 67 public void run() { | 80 public void run() { |
| 68 LocationBarLayout locationBar = | 81 LocationBarLayout locationBar = |
| 69 (LocationBarLayout) getActivity().findViewById(R.id.loca
tion_bar); | 82 (LocationBarLayout) mActivityTestRule.getActivity().find
ViewById( |
| 83 R.id.location_bar); |
| 70 locationBar.cancelPendingAutocompleteStart(); | 84 locationBar.cancelPendingAutocompleteStart(); |
| 71 locationBar.setAutocompleteController(controller); | 85 locationBar.setAutocompleteController(controller); |
| 72 } | 86 } |
| 73 }); | 87 }); |
| 74 } | 88 } |
| 75 | 89 |
| 76 private static class AutocompleteState { | 90 private static class AutocompleteState { |
| 77 public final boolean hasAutocomplete; | 91 public final boolean hasAutocomplete; |
| 78 public final String textWithoutAutocomplete; | 92 public final String textWithoutAutocomplete; |
| 79 public final String textWithAutocomplete; | 93 public final String textWithAutocomplete; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 131 } |
| 118 | 132 |
| 119 private void setTextAndVerifyNoAutocomplete(final UrlBar urlBar, final Strin
g text) { | 133 private void setTextAndVerifyNoAutocomplete(final UrlBar urlBar, final Strin
g text) { |
| 120 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { | 134 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { |
| 121 @Override | 135 @Override |
| 122 public void run() { | 136 public void run() { |
| 123 urlBar.setText(text); | 137 urlBar.setText(text); |
| 124 } | 138 } |
| 125 }); | 139 }); |
| 126 | 140 |
| 127 assertEquals(text, state.textWithoutAutocomplete); | 141 Assert.assertEquals(text, state.textWithoutAutocomplete); |
| 128 assertEquals(text, state.textWithAutocomplete); | 142 Assert.assertEquals(text, state.textWithAutocomplete); |
| 129 assertFalse(state.hasAutocomplete); | 143 Assert.assertFalse(state.hasAutocomplete); |
| 130 } | 144 } |
| 131 | 145 |
| 132 private void setAutocomplete(final UrlBar urlBar, | 146 private void setAutocomplete(final UrlBar urlBar, |
| 133 final String userText, final String autocompleteText) { | 147 final String userText, final String autocompleteText) { |
| 134 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { | 148 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { |
| 135 @Override | 149 @Override |
| 136 public void run() { | 150 public void run() { |
| 137 urlBar.setAutocompleteText(userText, autocompleteText); | 151 urlBar.setAutocompleteText(userText, autocompleteText); |
| 138 } | 152 } |
| 139 }); | 153 }); |
| 140 | 154 |
| 141 assertEquals(userText, state.textWithoutAutocomplete); | 155 Assert.assertEquals(userText, state.textWithoutAutocomplete); |
| 142 assertEquals(userText + autocompleteText, state.textWithAutocomplete); | 156 Assert.assertEquals(userText + autocompleteText, state.textWithAutocompl
ete); |
| 143 assertTrue(state.hasAutocomplete); | 157 Assert.assertTrue(state.hasAutocomplete); |
| 144 } | 158 } |
| 145 | 159 |
| 146 private AutocompleteState setSelection( | 160 private AutocompleteState setSelection( |
| 147 final UrlBar urlBar, final int selectionStart, final int selectionEn
d) { | 161 final UrlBar urlBar, final int selectionStart, final int selectionEn
d) { |
| 148 return getAutocompleteState(urlBar, new Runnable() { | 162 return getAutocompleteState(urlBar, new Runnable() { |
| 149 @Override | 163 @Override |
| 150 public void run() { | 164 public void run() { |
| 151 urlBar.setSelection(selectionStart, selectionEnd); | 165 urlBar.setSelection(selectionStart, selectionEnd); |
| 152 } | 166 } |
| 153 }); | 167 }); |
| 154 } | 168 } |
| 155 | 169 |
| 170 @Test |
| 156 @SmallTest | 171 @SmallTest |
| 157 @Feature({"Omnibox"}) | 172 @Feature({"Omnibox"}) |
| 158 @RetryOnFailure | 173 @RetryOnFailure |
| 159 public void testRefocusing() throws InterruptedException { | 174 public void testRefocusing() throws InterruptedException { |
| 160 startMainActivityOnBlankPage(); | 175 mActivityTestRule.startMainActivityOnBlankPage(); |
| 161 UrlBar urlBar = getUrlBar(); | 176 UrlBar urlBar = getUrlBar(); |
| 162 assertFalse(OmniboxTestUtils.doesUrlBarHaveFocus(urlBar)); | 177 Assert.assertFalse(OmniboxTestUtils.doesUrlBarHaveFocus(urlBar)); |
| 163 OmniboxTestUtils.checkUrlBarRefocus(urlBar, 5); | 178 OmniboxTestUtils.checkUrlBarRefocus(urlBar, 5); |
| 164 } | 179 } |
| 165 | 180 |
| 181 @Test |
| 166 @SmallTest | 182 @SmallTest |
| 167 @Feature({"Omnibox"}) | 183 @Feature({"Omnibox"}) |
| 168 @RetryOnFailure | 184 @RetryOnFailure |
| 169 public void testAutocompleteUpdatedOnSetText() throws InterruptedException { | 185 public void testAutocompleteUpdatedOnSetText() throws InterruptedException { |
| 170 startMainActivityOnBlankPage(); | 186 mActivityTestRule.startMainActivityOnBlankPage(); |
| 171 stubLocationBarAutocomplete(); | 187 stubLocationBarAutocomplete(); |
| 172 final UrlBar urlBar = getUrlBar(); | 188 final UrlBar urlBar = getUrlBar(); |
| 173 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 189 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 174 | 190 |
| 175 // Verify that setting a new string will clear the autocomplete. | 191 // Verify that setting a new string will clear the autocomplete. |
| 176 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 192 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 177 setAutocomplete(urlBar, "test", "ing is fun"); | 193 setAutocomplete(urlBar, "test", "ing is fun"); |
| 178 setTextAndVerifyNoAutocomplete(urlBar, "new string"); | 194 setTextAndVerifyNoAutocomplete(urlBar, "new string"); |
| 179 | 195 |
| 180 // Replace part of the non-autocomplete text and see that the autocomple
te is cleared. | 196 // Replace part of the non-autocomplete text and see that the autocomple
te is cleared. |
| 181 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 197 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 182 setAutocomplete(urlBar, "test", "ing is fun"); | 198 setAutocomplete(urlBar, "test", "ing is fun"); |
| 183 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { | 199 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { |
| 184 @Override | 200 @Override |
| 185 public void run() { | 201 public void run() { |
| 186 urlBar.setText(urlBar.getText().replace(1, 2, "a")); | 202 urlBar.setText(urlBar.getText().replace(1, 2, "a")); |
| 187 } | 203 } |
| 188 }); | 204 }); |
| 189 assertFalse(state.hasAutocomplete); | 205 Assert.assertFalse(state.hasAutocomplete); |
| 190 assertEquals("tasting is fun", state.textWithoutAutocomplete); | 206 Assert.assertEquals("tasting is fun", state.textWithoutAutocomplete); |
| 191 assertEquals("tasting is fun", state.textWithAutocomplete); | 207 Assert.assertEquals("tasting is fun", state.textWithAutocomplete); |
| 192 | 208 |
| 193 // Replace part of the autocomplete text and see that the autocomplete i
s cleared. | 209 // Replace part of the autocomplete text and see that the autocomplete i
s cleared. |
| 194 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 210 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 195 setAutocomplete(urlBar, "test", "ing is fun"); | 211 setAutocomplete(urlBar, "test", "ing is fun"); |
| 196 state = getAutocompleteState(urlBar, new Runnable() { | 212 state = getAutocompleteState(urlBar, new Runnable() { |
| 197 @Override | 213 @Override |
| 198 public void run() { | 214 public void run() { |
| 199 urlBar.setText(urlBar.getText().replace(8, 10, "no")); | 215 urlBar.setText(urlBar.getText().replace(8, 10, "no")); |
| 200 } | 216 } |
| 201 }); | 217 }); |
| 202 assertFalse(state.hasAutocomplete); | 218 Assert.assertFalse(state.hasAutocomplete); |
| 203 assertEquals("testing no fun", state.textWithoutAutocomplete); | 219 Assert.assertEquals("testing no fun", state.textWithoutAutocomplete); |
| 204 assertEquals("testing no fun", state.textWithAutocomplete); | 220 Assert.assertEquals("testing no fun", state.textWithAutocomplete); |
| 205 } | 221 } |
| 206 | 222 |
| 207 private void verifySelectionState( | 223 private void verifySelectionState( |
| 208 String text, String inlineAutocomplete, int selectionStart, int sele
ctionEnd, | 224 String text, String inlineAutocomplete, int selectionStart, int sele
ctionEnd, |
| 209 boolean expectedHasAutocomplete, String expectedTextWithoutAutocompl
ete, | 225 boolean expectedHasAutocomplete, String expectedTextWithoutAutocompl
ete, |
| 210 String expectedTextWithAutocomplete, boolean expectedPreventInline, | 226 String expectedTextWithAutocomplete, boolean expectedPreventInline, |
| 211 String expectedRequestedAutocompleteText) | 227 String expectedRequestedAutocompleteText) |
| 212 throws InterruptedException, TimeoutException { | 228 throws InterruptedException, TimeoutException { |
| 213 final UrlBar urlBar = getUrlBar(); | 229 final UrlBar urlBar = getUrlBar(); |
| 214 | 230 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 226 if (autocompleteHelper.getCallCount() != 0) return; | 242 if (autocompleteHelper.getCallCount() != 0) return; |
| 227 | 243 |
| 228 requestedAutocompleteText.set(text); | 244 requestedAutocompleteText.set(text); |
| 229 didPreventInlineAutocomplete.set(preventInlineAutocomplete); | 245 didPreventInlineAutocomplete.set(preventInlineAutocomplete); |
| 230 autocompleteHelper.notifyCalled(); | 246 autocompleteHelper.notifyCalled(); |
| 231 } | 247 } |
| 232 }; | 248 }; |
| 233 setAutocompleteController(controller); | 249 setAutocompleteController(controller); |
| 234 | 250 |
| 235 AutocompleteState state = setSelection(urlBar, selectionStart, selection
End); | 251 AutocompleteState state = setSelection(urlBar, selectionStart, selection
End); |
| 236 assertEquals("Has autocomplete", expectedHasAutocomplete, state.hasAutoc
omplete); | 252 Assert.assertEquals("Has autocomplete", expectedHasAutocomplete, state.h
asAutocomplete); |
| 237 assertEquals("Text w/o Autocomplete", | 253 Assert.assertEquals("Text w/o Autocomplete", expectedTextWithoutAutocomp
lete, |
| 238 expectedTextWithoutAutocomplete, state.textWithoutAutocomplete); | 254 state.textWithoutAutocomplete); |
| 239 assertEquals("Text w/ Autocomplete", | 255 Assert.assertEquals( |
| 240 expectedTextWithAutocomplete, state.textWithAutocomplete); | 256 "Text w/ Autocomplete", expectedTextWithAutocomplete, state.text
WithAutocomplete); |
| 241 | 257 |
| 242 autocompleteHelper.waitForCallback(0); | 258 autocompleteHelper.waitForCallback(0); |
| 243 assertEquals("Prevent inline autocomplete", | 259 Assert.assertEquals("Prevent inline autocomplete", expectedPreventInline
, |
| 244 expectedPreventInline, didPreventInlineAutocomplete.get()); | 260 didPreventInlineAutocomplete.get()); |
| 245 assertEquals("Requested autocomplete text", | 261 Assert.assertEquals("Requested autocomplete text", expectedRequestedAuto
completeText, |
| 246 expectedRequestedAutocompleteText, requestedAutocompleteText.get
()); | 262 requestedAutocompleteText.get()); |
| 247 } | 263 } |
| 248 | 264 |
| 265 @Test |
| 249 @SmallTest | 266 @SmallTest |
| 250 @Feature({"Omnibox"}) | 267 @Feature({"Omnibox"}) |
| 251 @RetryOnFailure | 268 @RetryOnFailure |
| 252 public void testAutocompleteUpdatedOnSelection() | 269 public void testAutocompleteUpdatedOnSelection() throws InterruptedException
, TimeoutException { |
| 253 throws InterruptedException, TimeoutException { | 270 mActivityTestRule.startMainActivityOnBlankPage(); |
| 254 startMainActivityOnBlankPage(); | |
| 255 stubLocationBarAutocomplete(); | 271 stubLocationBarAutocomplete(); |
| 256 | 272 |
| 257 final UrlBar urlBar = getUrlBar(); | 273 final UrlBar urlBar = getUrlBar(); |
| 258 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 274 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 259 | 275 |
| 260 // Verify that setting a selection before the autocomplete clears it. | 276 // Verify that setting a selection before the autocomplete clears it. |
| 261 verifySelectionState("test", "ing is fun", 1, 1, false, "test", "test",
true, "test"); | 277 verifySelectionState("test", "ing is fun", 1, 1, false, "test", "test",
true, "test"); |
| 262 | 278 |
| 263 // Verify that setting a selection range before the autocomplete clears
it. | 279 // Verify that setting a selection range before the autocomplete clears
it. |
| 264 verifySelectionState("test", "ing is fun", 0, 4, false, "test", "test",
true, "test"); | 280 verifySelectionState("test", "ing is fun", 0, 4, false, "test", "test",
true, "test"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 291 verifySelectionState("test", "ing is fun", 8, 11, | 307 verifySelectionState("test", "ing is fun", 8, 11, |
| 292 false, "testing is fun", "testing is fun", true, "testing is fun
"); | 308 false, "testing is fun", "testing is fun", true, "testing is fun
"); |
| 293 | 309 |
| 294 // Verify that setting the same selection does not clear the autocomplet
e text. | 310 // Verify that setting the same selection does not clear the autocomplet
e text. |
| 295 // As we do not expect the suggestions to be refreshed, we test this sli
ghtly differently | 311 // As we do not expect the suggestions to be refreshed, we test this sli
ghtly differently |
| 296 // than the other cases. | 312 // than the other cases. |
| 297 stubLocationBarAutocomplete(); | 313 stubLocationBarAutocomplete(); |
| 298 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 314 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 299 setAutocomplete(urlBar, "test", "ing is fun"); | 315 setAutocomplete(urlBar, "test", "ing is fun"); |
| 300 AutocompleteState state = setSelection(urlBar, 4, 14); | 316 AutocompleteState state = setSelection(urlBar, 4, 14); |
| 301 assertEquals("Has autocomplete", true, state.hasAutocomplete); | 317 Assert.assertEquals("Has autocomplete", true, state.hasAutocomplete); |
| 302 assertEquals("Text w/o Autocomplete", "test", state.textWithoutAutocompl
ete); | 318 Assert.assertEquals("Text w/o Autocomplete", "test", state.textWithoutAu
tocomplete); |
| 303 assertEquals("Text w/ Autocomplete", "testing is fun", state.textWithAut
ocomplete); | 319 Assert.assertEquals("Text w/ Autocomplete", "testing is fun", state.text
WithAutocomplete); |
| 304 } | 320 } |
| 305 | 321 |
| 306 /** | 322 /** |
| 307 * Ensure that we allow inline autocomplete when the text gets shorter but i
s not an explicit | 323 * Ensure that we allow inline autocomplete when the text gets shorter but i
s not an explicit |
| 308 * delete action by the user. | 324 * delete action by the user. |
| 309 * | 325 * |
| 310 * If you focus the omnibox and there is the selected text "[about:blank]",
then typing new text | 326 * If you focus the omnibox and there is the selected text "[about:blank]",
then typing new text |
| 311 * should clear that entirely and allow autocomplete on the newly entered te
xt. | 327 * should clear that entirely and allow autocomplete on the newly entered te
xt. |
| 312 * | 328 * |
| 313 * If we assume deletes happen any time the text gets shorter, then this wou
ld be prevented. | 329 * If we assume deletes happen any time the text gets shorter, then this wou
ld be prevented. |
| 314 */ | 330 */ |
| 331 @Test |
| 315 @SmallTest | 332 @SmallTest |
| 316 @Feature({"Omnibox"}) | 333 @Feature({"Omnibox"}) |
| 317 @RetryOnFailure | 334 @RetryOnFailure |
| 318 public void testAutocompleteAllowedWhenReplacingText() | 335 public void testAutocompleteAllowedWhenReplacingText() |
| 319 throws InterruptedException, TimeoutException { | 336 throws InterruptedException, TimeoutException { |
| 320 startMainActivityOnBlankPage(); | 337 mActivityTestRule.startMainActivityOnBlankPage(); |
| 321 | 338 |
| 322 final String textToBeEntered = "c"; | 339 final String textToBeEntered = "c"; |
| 323 | 340 |
| 324 final CallbackHelper autocompleteHelper = new CallbackHelper(); | 341 final CallbackHelper autocompleteHelper = new CallbackHelper(); |
| 325 final AtomicBoolean didPreventInlineAutocomplete = new AtomicBoolean(); | 342 final AtomicBoolean didPreventInlineAutocomplete = new AtomicBoolean(); |
| 326 final StubAutocompleteController controller = new StubAutocompleteContro
ller() { | 343 final StubAutocompleteController controller = new StubAutocompleteContro
ller() { |
| 327 @Override | 344 @Override |
| 328 public void start(Profile profile, String url, String text, int curs
orPosition, | 345 public void start(Profile profile, String url, String text, int curs
orPosition, |
| 329 boolean preventInlineAutocomplete) { | 346 boolean preventInlineAutocomplete) { |
| 330 if (!TextUtils.equals(textToBeEntered, text)) return; | 347 if (!TextUtils.equals(textToBeEntered, text)) return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 342 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 359 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 343 @Override | 360 @Override |
| 344 public void run() { | 361 public void run() { |
| 345 urlBar.beginBatchEdit(); | 362 urlBar.beginBatchEdit(); |
| 346 urlBar.setText(textToBeEntered); | 363 urlBar.setText(textToBeEntered); |
| 347 urlBar.setSelection(textToBeEntered.length()); | 364 urlBar.setSelection(textToBeEntered.length()); |
| 348 urlBar.endBatchEdit(); | 365 urlBar.endBatchEdit(); |
| 349 } | 366 } |
| 350 }); | 367 }); |
| 351 autocompleteHelper.waitForCallback(0); | 368 autocompleteHelper.waitForCallback(0); |
| 352 assertFalse("Inline autocomplete incorrectly prevented.", | 369 Assert.assertFalse( |
| 353 didPreventInlineAutocomplete.get()); | 370 "Inline autocomplete incorrectly prevented.", didPreventInlineAu
tocomplete.get()); |
| 354 } | 371 } |
| 355 | 372 |
| 356 /** | 373 /** |
| 357 * Ensure that if the user deletes just the inlined autocomplete text that t
he suggestions are | 374 * Ensure that if the user deletes just the inlined autocomplete text that t
he suggestions are |
| 358 * regenerated. | 375 * regenerated. |
| 359 */ | 376 */ |
| 377 @Test |
| 360 @SmallTest | 378 @SmallTest |
| 361 @Feature({"Omnibox"}) | 379 @Feature({"Omnibox"}) |
| 362 @RetryOnFailure | 380 @RetryOnFailure |
| 363 public void testSuggestionsUpdatedWhenDeletingInlineAutocomplete() | 381 public void testSuggestionsUpdatedWhenDeletingInlineAutocomplete() |
| 364 throws InterruptedException, TimeoutException { | 382 throws InterruptedException, TimeoutException { |
| 365 startMainActivityOnBlankPage(); | 383 mActivityTestRule.startMainActivityOnBlankPage(); |
| 366 | 384 |
| 367 stubLocationBarAutocomplete(); | 385 stubLocationBarAutocomplete(); |
| 368 final UrlBar urlBar = getUrlBar(); | 386 final UrlBar urlBar = getUrlBar(); |
| 369 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 387 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 370 | 388 |
| 371 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 389 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 372 setAutocomplete(urlBar, "test", "ing"); | 390 setAutocomplete(urlBar, "test", "ing"); |
| 373 | 391 |
| 374 final CallbackHelper autocompleteHelper = new CallbackHelper(); | 392 final CallbackHelper autocompleteHelper = new CallbackHelper(); |
| 375 final AtomicBoolean didPreventInlineAutocomplete = new AtomicBoolean(); | 393 final AtomicBoolean didPreventInlineAutocomplete = new AtomicBoolean(); |
| 376 final StubAutocompleteController controller = new StubAutocompleteContro
ller() { | 394 final StubAutocompleteController controller = new StubAutocompleteContro
ller() { |
| 377 @Override | 395 @Override |
| 378 public void start(Profile profile, String url, String text, int curs
orPosition, | 396 public void start(Profile profile, String url, String text, int curs
orPosition, |
| 379 boolean preventInlineAutocomplete) { | 397 boolean preventInlineAutocomplete) { |
| 380 if (!TextUtils.equals("test", text)) return; | 398 if (!TextUtils.equals("test", text)) return; |
| 381 if (autocompleteHelper.getCallCount() != 0) return; | 399 if (autocompleteHelper.getCallCount() != 0) return; |
| 382 | 400 |
| 383 didPreventInlineAutocomplete.set(preventInlineAutocomplete); | 401 didPreventInlineAutocomplete.set(preventInlineAutocomplete); |
| 384 autocompleteHelper.notifyCalled(); | 402 autocompleteHelper.notifyCalled(); |
| 385 } | 403 } |
| 386 }; | 404 }; |
| 387 setAutocompleteController(controller); | 405 setAutocompleteController(controller); |
| 388 | 406 |
| 389 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEvent.KEYCO
DE_DEL); | 407 KeyUtils.singleKeyEventView( |
| 408 InstrumentationRegistry.getInstrumentation(), urlBar, KeyEvent.K
EYCODE_DEL); |
| 390 | 409 |
| 391 CriteriaHelper.pollUiThread(Criteria.equals("test", new Callable<String>
() { | 410 CriteriaHelper.pollUiThread(Criteria.equals("test", new Callable<String>
() { |
| 392 @Override | 411 @Override |
| 393 public String call() throws Exception { | 412 public String call() throws Exception { |
| 394 return urlBar.getText().toString(); | 413 return urlBar.getText().toString(); |
| 395 } | 414 } |
| 396 })); | 415 })); |
| 397 | 416 |
| 398 autocompleteHelper.waitForCallback(0); | 417 autocompleteHelper.waitForCallback(0); |
| 399 assertTrue("Inline autocomplete incorrectly allowed after delete.", | 418 Assert.assertTrue("Inline autocomplete incorrectly allowed after delete.
", |
| 400 didPreventInlineAutocomplete.get()); | 419 didPreventInlineAutocomplete.get()); |
| 401 } | 420 } |
| 402 | 421 |
| 422 @Test |
| 403 @SmallTest | 423 @SmallTest |
| 404 @Feature({"Omnibox"}) | 424 @Feature({"Omnibox"}) |
| 405 @RetryOnFailure | 425 @RetryOnFailure |
| 406 public void testSelectionChangesIgnoredInBatchMode() throws InterruptedExcep
tion { | 426 public void testSelectionChangesIgnoredInBatchMode() throws InterruptedExcep
tion { |
| 407 startMainActivityOnBlankPage(); | 427 mActivityTestRule.startMainActivityOnBlankPage(); |
| 408 stubLocationBarAutocomplete(); | 428 stubLocationBarAutocomplete(); |
| 409 final UrlBar urlBar = getUrlBar(); | 429 final UrlBar urlBar = getUrlBar(); |
| 410 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 430 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 411 | 431 |
| 412 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 432 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 413 setAutocomplete(urlBar, "test", "ing is fun"); | 433 setAutocomplete(urlBar, "test", "ing is fun"); |
| 414 | 434 |
| 415 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 435 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 416 @Override | 436 @Override |
| 417 public void run() { | 437 public void run() { |
| 418 urlBar.beginBatchEdit(); | 438 urlBar.beginBatchEdit(); |
| 419 } | 439 } |
| 420 }); | 440 }); |
| 421 // Ensure the autocomplete is not modified if in batch mode. | 441 // Ensure the autocomplete is not modified if in batch mode. |
| 422 AutocompleteState state = setSelection(urlBar, 1, 1); | 442 AutocompleteState state = setSelection(urlBar, 1, 1); |
| 423 assertTrue(state.hasAutocomplete); | 443 Assert.assertTrue(state.hasAutocomplete); |
| 424 assertEquals("test", state.textWithoutAutocomplete); | 444 Assert.assertEquals("test", state.textWithoutAutocomplete); |
| 425 assertEquals("testing is fun", state.textWithAutocomplete); | 445 Assert.assertEquals("testing is fun", state.textWithAutocomplete); |
| 426 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 446 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 427 @Override | 447 @Override |
| 428 public void run() { | 448 public void run() { |
| 429 urlBar.endBatchEdit(); | 449 urlBar.endBatchEdit(); |
| 430 } | 450 } |
| 431 }); | 451 }); |
| 432 | 452 |
| 433 // Ensure that after batch mode has ended that the autocomplete is clear
ed due to the | 453 // Ensure that after batch mode has ended that the autocomplete is clear
ed due to the |
| 434 // invalid selection range. | 454 // invalid selection range. |
| 435 state = getAutocompleteState(urlBar, null); | 455 state = getAutocompleteState(urlBar, null); |
| 436 assertFalse(state.hasAutocomplete); | 456 Assert.assertFalse(state.hasAutocomplete); |
| 437 assertEquals("test", state.textWithoutAutocomplete); | 457 Assert.assertEquals("test", state.textWithoutAutocomplete); |
| 438 assertEquals("test", state.textWithAutocomplete); | 458 Assert.assertEquals("test", state.textWithAutocomplete); |
| 439 } | 459 } |
| 440 | 460 |
| 461 @Test |
| 441 @SmallTest | 462 @SmallTest |
| 442 @Feature({"Omnibox"}) | 463 @Feature({"Omnibox"}) |
| 443 @RetryOnFailure | 464 @RetryOnFailure |
| 444 public void testBatchModeChangesTriggerCorrectSuggestions() throws Interrupt
edException { | 465 public void testBatchModeChangesTriggerCorrectSuggestions() throws Interrupt
edException { |
| 445 startMainActivityOnBlankPage(); | 466 mActivityTestRule.startMainActivityOnBlankPage(); |
| 446 | 467 |
| 447 final AtomicReference<String> requestedAutocompleteText = new AtomicRefe
rence<String>(); | 468 final AtomicReference<String> requestedAutocompleteText = new AtomicRefe
rence<String>(); |
| 448 final StubAutocompleteController controller = new StubAutocompleteContro
ller() { | 469 final StubAutocompleteController controller = new StubAutocompleteContro
ller() { |
| 449 @Override | 470 @Override |
| 450 public void start(Profile profile, String url, String text, int curs
orPosition, | 471 public void start(Profile profile, String url, String text, int curs
orPosition, |
| 451 boolean preventInlineAutocomplete) { | 472 boolean preventInlineAutocomplete) { |
| 452 requestedAutocompleteText.set(text); | 473 requestedAutocompleteText.set(text); |
| 453 } | 474 } |
| 454 }; | 475 }; |
| 455 | 476 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 481 }); | 502 }); |
| 482 | 503 |
| 483 CriteriaHelper.pollUiThread(Criteria.equals("testy", new Callable<String
>() { | 504 CriteriaHelper.pollUiThread(Criteria.equals("testy", new Callable<String
>() { |
| 484 @Override | 505 @Override |
| 485 public String call() { | 506 public String call() { |
| 486 return requestedAutocompleteText.get(); | 507 return requestedAutocompleteText.get(); |
| 487 } | 508 } |
| 488 })); | 509 })); |
| 489 } | 510 } |
| 490 | 511 |
| 512 @Test |
| 491 @SmallTest | 513 @SmallTest |
| 492 @Feature("Omnibox") | 514 @Feature("Omnibox") |
| 493 @RetryOnFailure | 515 @RetryOnFailure |
| 494 public void testAutocompleteCorrectlyPerservedOnBatchMode() throws Interrupt
edException { | 516 public void testAutocompleteCorrectlyPerservedOnBatchMode() throws Interrupt
edException { |
| 495 startMainActivityOnBlankPage(); | 517 mActivityTestRule.startMainActivityOnBlankPage(); |
| 496 stubLocationBarAutocomplete(); | 518 stubLocationBarAutocomplete(); |
| 497 | 519 |
| 498 final UrlBar urlBar = getUrlBar(); | 520 final UrlBar urlBar = getUrlBar(); |
| 499 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 521 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 500 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); | 522 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); |
| 501 | 523 |
| 502 // Valid case (cursor at the end of text, single character, matches prev
ious autocomplete). | 524 // Valid case (cursor at the end of text, single character, matches prev
ious autocomplete). |
| 503 setAutocomplete(urlBar, "g", "oogle.com"); | 525 setAutocomplete(urlBar, "g", "oogle.com"); |
| 504 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { | 526 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { |
| 505 @Override | 527 @Override |
| 506 // TODO(crbug.com/635567): Fix this properly. | 528 // TODO(crbug.com/635567): Fix this properly. |
| 507 @SuppressLint("SetTextI18n") | 529 @SuppressLint("SetTextI18n") |
| 508 public void run() { | 530 public void run() { |
| 509 urlBar.beginBatchEdit(); | 531 urlBar.beginBatchEdit(); |
| 510 urlBar.setText("go"); | 532 urlBar.setText("go"); |
| 511 urlBar.setSelection(2); | 533 urlBar.setSelection(2); |
| 512 urlBar.endBatchEdit(); | 534 urlBar.endBatchEdit(); |
| 513 } | 535 } |
| 514 }); | 536 }); |
| 515 assertTrue(state.hasAutocomplete); | 537 Assert.assertTrue(state.hasAutocomplete); |
| 516 assertEquals("google.com", state.textWithAutocomplete); | 538 Assert.assertEquals("google.com", state.textWithAutocomplete); |
| 517 assertEquals("go", state.textWithoutAutocomplete); | 539 Assert.assertEquals("go", state.textWithoutAutocomplete); |
| 518 | 540 |
| 519 // Invalid case (cursor not at the end of the text) | 541 // Invalid case (cursor not at the end of the text) |
| 520 setAutocomplete(urlBar, "g", "oogle.com"); | 542 setAutocomplete(urlBar, "g", "oogle.com"); |
| 521 state = getAutocompleteState(urlBar, new Runnable() { | 543 state = getAutocompleteState(urlBar, new Runnable() { |
| 522 @Override | 544 @Override |
| 523 // TODO(crbug.com/635567): Fix this properly. | 545 // TODO(crbug.com/635567): Fix this properly. |
| 524 @SuppressLint("SetTextI18n") | 546 @SuppressLint("SetTextI18n") |
| 525 public void run() { | 547 public void run() { |
| 526 urlBar.beginBatchEdit(); | 548 urlBar.beginBatchEdit(); |
| 527 urlBar.setText("go"); | 549 urlBar.setText("go"); |
| 528 urlBar.setSelection(0); | 550 urlBar.setSelection(0); |
| 529 urlBar.endBatchEdit(); | 551 urlBar.endBatchEdit(); |
| 530 } | 552 } |
| 531 }); | 553 }); |
| 532 assertFalse(state.hasAutocomplete); | 554 Assert.assertFalse(state.hasAutocomplete); |
| 533 | 555 |
| 534 // Invalid case (next character did not match previous autocomplete) | 556 // Invalid case (next character did not match previous autocomplete) |
| 535 setAutocomplete(urlBar, "g", "oogle.com"); | 557 setAutocomplete(urlBar, "g", "oogle.com"); |
| 536 state = getAutocompleteState(urlBar, new Runnable() { | 558 state = getAutocompleteState(urlBar, new Runnable() { |
| 537 @Override | 559 @Override |
| 538 // TODO(crbug.com/635567): Fix this properly. | 560 // TODO(crbug.com/635567): Fix this properly. |
| 539 @SuppressLint("SetTextI18n") | 561 @SuppressLint("SetTextI18n") |
| 540 public void run() { | 562 public void run() { |
| 541 urlBar.beginBatchEdit(); | 563 urlBar.beginBatchEdit(); |
| 542 urlBar.setText("ga"); | 564 urlBar.setText("ga"); |
| 543 urlBar.setSelection(2); | 565 urlBar.setSelection(2); |
| 544 urlBar.endBatchEdit(); | 566 urlBar.endBatchEdit(); |
| 545 } | 567 } |
| 546 }); | 568 }); |
| 547 assertFalse(state.hasAutocomplete); | 569 Assert.assertFalse(state.hasAutocomplete); |
| 548 | 570 |
| 549 // Invalid case (multiple characters entered instead of 1) | 571 // Invalid case (multiple characters entered instead of 1) |
| 550 setAutocomplete(urlBar, "g", "oogle.com"); | 572 setAutocomplete(urlBar, "g", "oogle.com"); |
| 551 state = getAutocompleteState(urlBar, new Runnable() { | 573 state = getAutocompleteState(urlBar, new Runnable() { |
| 552 @Override | 574 @Override |
| 553 // TODO(crbug.com/635567): Fix this properly. | 575 // TODO(crbug.com/635567): Fix this properly. |
| 554 @SuppressLint("SetTextI18n") | 576 @SuppressLint("SetTextI18n") |
| 555 public void run() { | 577 public void run() { |
| 556 urlBar.beginBatchEdit(); | 578 urlBar.beginBatchEdit(); |
| 557 urlBar.setText("googl"); | 579 urlBar.setText("googl"); |
| 558 urlBar.setSelection(5); | 580 urlBar.setSelection(5); |
| 559 urlBar.endBatchEdit(); | 581 urlBar.endBatchEdit(); |
| 560 } | 582 } |
| 561 }); | 583 }); |
| 562 assertFalse(state.hasAutocomplete); | 584 Assert.assertFalse(state.hasAutocomplete); |
| 563 } | 585 } |
| 564 | 586 |
| 587 @Test |
| 565 @SmallTest | 588 @SmallTest |
| 566 @Feature("Omnibox") | 589 @Feature("Omnibox") |
| 567 @RetryOnFailure | 590 @RetryOnFailure |
| 568 public void testAutocompleteSpanClearedOnNonMatchingCommitText() throws Inte
rruptedException { | 591 public void testAutocompleteSpanClearedOnNonMatchingCommitText() throws Inte
rruptedException { |
| 569 startMainActivityOnBlankPage(); | 592 mActivityTestRule.startMainActivityOnBlankPage(); |
| 570 | 593 |
| 571 stubLocationBarAutocomplete(); | 594 stubLocationBarAutocomplete(); |
| 572 | 595 |
| 573 final UrlBar urlBar = getUrlBar(); | 596 final UrlBar urlBar = getUrlBar(); |
| 574 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 597 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 575 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); | 598 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); |
| 576 | 599 |
| 577 setTextAndVerifyNoAutocomplete(urlBar, "a"); | 600 setTextAndVerifyNoAutocomplete(urlBar, "a"); |
| 578 setAutocomplete(urlBar, "a", "mazon.com"); | 601 setAutocomplete(urlBar, "a", "mazon.com"); |
| 579 | 602 |
| 580 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 603 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 581 @Override | 604 @Override |
| 582 public void run() { | 605 public void run() { |
| 583 urlBar.mInputConnection.beginBatchEdit(); | 606 urlBar.mInputConnection.beginBatchEdit(); |
| 584 urlBar.mInputConnection.commitText("l", 1); | 607 urlBar.mInputConnection.commitText("l", 1); |
| 585 urlBar.mInputConnection.setComposingText("", 1); | 608 urlBar.mInputConnection.setComposingText("", 1); |
| 586 urlBar.mInputConnection.endBatchEdit(); | 609 urlBar.mInputConnection.endBatchEdit(); |
| 587 } | 610 } |
| 588 }); | 611 }); |
| 589 | 612 |
| 590 CriteriaHelper.pollUiThread(Criteria.equals("al", new Callable<String>()
{ | 613 CriteriaHelper.pollUiThread(Criteria.equals("al", new Callable<String>()
{ |
| 591 @Override | 614 @Override |
| 592 public String call() { | 615 public String call() { |
| 593 return urlBar.getText().toString(); | 616 return urlBar.getText().toString(); |
| 594 } | 617 } |
| 595 })); | 618 })); |
| 596 } | 619 } |
| 597 | 620 |
| 621 @Test |
| 598 @SmallTest | 622 @SmallTest |
| 599 @Feature({"Omnibox"}) | 623 @Feature({"Omnibox"}) |
| 600 @RetryOnFailure | 624 @RetryOnFailure |
| 601 public void testAutocompleteUpdatedOnDefocus() throws InterruptedException { | 625 public void testAutocompleteUpdatedOnDefocus() throws InterruptedException { |
| 602 startMainActivityOnBlankPage(); | 626 mActivityTestRule.startMainActivityOnBlankPage(); |
| 603 stubLocationBarAutocomplete(); | 627 stubLocationBarAutocomplete(); |
| 604 final UrlBar urlBar = getUrlBar(); | 628 final UrlBar urlBar = getUrlBar(); |
| 605 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 629 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 606 | 630 |
| 607 // Verify that defocusing the UrlBar clears the autocomplete. | 631 // Verify that defocusing the UrlBar clears the autocomplete. |
| 608 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 632 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 609 setAutocomplete(urlBar, "test", "ing is fun"); | 633 setAutocomplete(urlBar, "test", "ing is fun"); |
| 610 OmniboxTestUtils.toggleUrlBarFocus(urlBar, false); | 634 OmniboxTestUtils.toggleUrlBarFocus(urlBar, false); |
| 611 AutocompleteState state = getAutocompleteState(urlBar, null); | 635 AutocompleteState state = getAutocompleteState(urlBar, null); |
| 612 assertFalse(state.hasAutocomplete); | 636 Assert.assertFalse(state.hasAutocomplete); |
| 613 } | 637 } |
| 614 | 638 |
| 639 @Test |
| 615 @SmallTest | 640 @SmallTest |
| 616 @Feature({"Omnibox"}) | 641 @Feature({"Omnibox"}) |
| 617 @RetryOnFailure | 642 @RetryOnFailure |
| 618 public void testAutocompleteClearedOnComposition() | 643 public void testAutocompleteClearedOnComposition() |
| 619 throws InterruptedException, ExecutionException { | 644 throws InterruptedException, ExecutionException { |
| 620 startMainActivityOnBlankPage(); | 645 mActivityTestRule.startMainActivityOnBlankPage(); |
| 621 stubLocationBarAutocomplete(); | 646 stubLocationBarAutocomplete(); |
| 622 final UrlBar urlBar = getUrlBar(); | 647 final UrlBar urlBar = getUrlBar(); |
| 623 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 648 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 624 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); | 649 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); |
| 625 | 650 |
| 626 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 651 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 627 setAutocomplete(urlBar, "test", "ing is fun"); | 652 setAutocomplete(urlBar, "test", "ing is fun"); |
| 628 | 653 |
| 629 assertNotNull(urlBar.mInputConnection); | 654 Assert.assertNotNull(urlBar.mInputConnection); |
| 630 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { | 655 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { |
| 631 @Override | 656 @Override |
| 632 public void run() { | 657 public void run() { |
| 633 urlBar.mInputConnection.setComposingText("ing compose", 4); | 658 urlBar.mInputConnection.setComposingText("ing compose", 4); |
| 634 } | 659 } |
| 635 }); | 660 }); |
| 636 assertFalse(state.hasAutocomplete); | 661 Assert.assertFalse(state.hasAutocomplete); |
| 637 | 662 |
| 638 Editable urlText = getUrlBarText(urlBar); | 663 Editable urlText = getUrlBarText(urlBar); |
| 639 assertEquals("testing compose", urlText.toString()); | 664 Assert.assertEquals("testing compose", urlText.toString()); |
| 640 // TODO(tedchoc): Investigate why this fails on x86. | 665 // TODO(tedchoc): Investigate why this fails on x86. |
| 641 //assertEquals(4, BaseInputConnection.getComposingSpanStart(urlText)); | 666 //assertEquals(4, BaseInputConnection.getComposingSpanStart(urlText)); |
| 642 //assertEquals(15, BaseInputConnection.getComposingSpanEnd(urlText)); | 667 //assertEquals(15, BaseInputConnection.getComposingSpanEnd(urlText)); |
| 643 } | 668 } |
| 644 | 669 |
| 670 @Test |
| 645 @SmallTest | 671 @SmallTest |
| 646 @Feature("Omnibox") | 672 @Feature("Omnibox") |
| 647 @RetryOnFailure | 673 @RetryOnFailure |
| 648 @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) // crbug.com/635714 | 674 @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) // crbug.com/635714 |
| 649 public void testDelayedCompositionCorrectedWithAutocomplete() | 675 public void testDelayedCompositionCorrectedWithAutocomplete() |
| 650 throws InterruptedException, ExecutionException { | 676 throws InterruptedException, ExecutionException { |
| 651 startMainActivityOnBlankPage(); | 677 mActivityTestRule.startMainActivityOnBlankPage(); |
| 652 stubLocationBarAutocomplete(); | 678 stubLocationBarAutocomplete(); |
| 653 | 679 |
| 654 final UrlBar urlBar = getUrlBar(); | 680 final UrlBar urlBar = getUrlBar(); |
| 655 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 681 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 656 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); | 682 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); |
| 657 | 683 |
| 658 assertNotNull(urlBar.mInputConnection); | 684 Assert.assertNotNull(urlBar.mInputConnection); |
| 659 | 685 |
| 660 // Test with a single autocomplete | 686 // Test with a single autocomplete |
| 661 | 687 |
| 662 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); | 688 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); |
| 663 setAutocomplete(urlBar, "chrome://f", "lags"); | 689 setAutocomplete(urlBar, "chrome://f", "lags"); |
| 664 | 690 |
| 665 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { | 691 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { |
| 666 @Override | 692 @Override |
| 667 public void run() { | 693 public void run() { |
| 668 urlBar.mInputConnection.setComposingRegion(13, 14); | 694 urlBar.mInputConnection.setComposingRegion(13, 14); |
| 669 urlBar.mInputConnection.setComposingText("f", 1); | 695 urlBar.mInputConnection.setComposingText("f", 1); |
| 670 } | 696 } |
| 671 }); | 697 }); |
| 672 assertFalse(state.hasAutocomplete); | 698 Assert.assertFalse(state.hasAutocomplete); |
| 673 | 699 |
| 674 Editable urlText = getUrlBarText(urlBar); | 700 Editable urlText = getUrlBarText(urlBar); |
| 675 assertEquals("chrome://f", urlText.toString()); | 701 Assert.assertEquals("chrome://f", urlText.toString()); |
| 676 assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 9); | 702 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
9); |
| 677 assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10); | 703 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10
); |
| 678 | 704 |
| 679 // Test with > 1 characters in composition. | 705 // Test with > 1 characters in composition. |
| 680 | 706 |
| 681 setTextAndVerifyNoAutocomplete(urlBar, "chrome://fl"); | 707 setTextAndVerifyNoAutocomplete(urlBar, "chrome://fl"); |
| 682 setAutocomplete(urlBar, "chrome://fl", "ags"); | 708 setAutocomplete(urlBar, "chrome://fl", "ags"); |
| 683 | 709 |
| 684 state = getAutocompleteState(urlBar, new Runnable() { | 710 state = getAutocompleteState(urlBar, new Runnable() { |
| 685 @Override | 711 @Override |
| 686 public void run() { | 712 public void run() { |
| 687 urlBar.mInputConnection.setComposingRegion(12, 14); | 713 urlBar.mInputConnection.setComposingRegion(12, 14); |
| 688 urlBar.mInputConnection.setComposingText("fl", 1); | 714 urlBar.mInputConnection.setComposingText("fl", 1); |
| 689 } | 715 } |
| 690 }); | 716 }); |
| 691 assertFalse(state.hasAutocomplete); | 717 Assert.assertFalse(state.hasAutocomplete); |
| 692 | 718 |
| 693 urlText = getUrlBarText(urlBar); | 719 urlText = getUrlBarText(urlBar); |
| 694 assertEquals("chrome://fl", urlText.toString()); | 720 Assert.assertEquals("chrome://fl", urlText.toString()); |
| 695 assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 9); | 721 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
9); |
| 696 assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11); | 722 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11
); |
| 697 | 723 |
| 698 // Test with non-matching composition. Should just append to the URL te
xt. | 724 // Test with non-matching composition. Should just append to the URL te
xt. |
| 699 | 725 |
| 700 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); | 726 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); |
| 701 setAutocomplete(urlBar, "chrome://f", "lags"); | 727 setAutocomplete(urlBar, "chrome://f", "lags"); |
| 702 | 728 |
| 703 state = getAutocompleteState(urlBar, new Runnable() { | 729 state = getAutocompleteState(urlBar, new Runnable() { |
| 704 @Override | 730 @Override |
| 705 public void run() { | 731 public void run() { |
| 706 urlBar.mInputConnection.setComposingRegion(13, 14); | 732 urlBar.mInputConnection.setComposingRegion(13, 14); |
| 707 urlBar.mInputConnection.setComposingText("g", 1); | 733 urlBar.mInputConnection.setComposingText("g", 1); |
| 708 } | 734 } |
| 709 }); | 735 }); |
| 710 assertFalse(state.hasAutocomplete); | 736 Assert.assertFalse(state.hasAutocomplete); |
| 711 | 737 |
| 712 urlText = getUrlBarText(urlBar); | 738 urlText = getUrlBarText(urlBar); |
| 713 assertEquals("chrome://fg", urlText.toString()); | 739 Assert.assertEquals("chrome://fg", urlText.toString()); |
| 714 assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 10); | 740 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
10); |
| 715 assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11); | 741 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11
); |
| 716 | 742 |
| 717 // Test with composition text that matches the entire text w/o autocompl
ete. | 743 // Test with composition text that matches the entire text w/o autocompl
ete. |
| 718 | 744 |
| 719 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); | 745 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); |
| 720 setAutocomplete(urlBar, "chrome://f", "lags"); | 746 setAutocomplete(urlBar, "chrome://f", "lags"); |
| 721 | 747 |
| 722 state = getAutocompleteState(urlBar, new Runnable() { | 748 state = getAutocompleteState(urlBar, new Runnable() { |
| 723 @Override | 749 @Override |
| 724 public void run() { | 750 public void run() { |
| 725 urlBar.mInputConnection.setComposingRegion(13, 14); | 751 urlBar.mInputConnection.setComposingRegion(13, 14); |
| 726 urlBar.mInputConnection.setComposingText("chrome://f", 1); | 752 urlBar.mInputConnection.setComposingText("chrome://f", 1); |
| 727 } | 753 } |
| 728 }); | 754 }); |
| 729 assertFalse(state.hasAutocomplete); | 755 Assert.assertFalse(state.hasAutocomplete); |
| 730 | 756 |
| 731 urlText = getUrlBarText(urlBar); | 757 urlText = getUrlBarText(urlBar); |
| 732 assertEquals("chrome://f", urlText.toString()); | 758 Assert.assertEquals("chrome://f", urlText.toString()); |
| 733 assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 0); | 759 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
0); |
| 734 assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10); | 760 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10
); |
| 735 | 761 |
| 736 // Test with composition text longer than the URL text. Shouldn't crash
and should | 762 // Test with composition text longer than the URL text. Shouldn't crash
and should |
| 737 // just append text. | 763 // just append text. |
| 738 | 764 |
| 739 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); | 765 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); |
| 740 setAutocomplete(urlBar, "chrome://f", "lags"); | 766 setAutocomplete(urlBar, "chrome://f", "lags"); |
| 741 | 767 |
| 742 state = getAutocompleteState(urlBar, new Runnable() { | 768 state = getAutocompleteState(urlBar, new Runnable() { |
| 743 @Override | 769 @Override |
| 744 public void run() { | 770 public void run() { |
| 745 urlBar.mInputConnection.setComposingRegion(13, 14); | 771 urlBar.mInputConnection.setComposingRegion(13, 14); |
| 746 urlBar.mInputConnection.setComposingText("blahblahblah", 1); | 772 urlBar.mInputConnection.setComposingText("blahblahblah", 1); |
| 747 } | 773 } |
| 748 }); | 774 }); |
| 749 assertFalse(state.hasAutocomplete); | 775 Assert.assertFalse(state.hasAutocomplete); |
| 750 | 776 |
| 751 urlText = getUrlBarText(urlBar); | 777 urlText = getUrlBarText(urlBar); |
| 752 assertEquals("chrome://fblahblahblah", urlText.toString()); | 778 Assert.assertEquals("chrome://fblahblahblah", urlText.toString()); |
| 753 assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 10); | 779 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
10); |
| 754 assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 22); | 780 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 22
); |
| 755 } | 781 } |
| 756 | 782 |
| 757 /** | 783 /** |
| 758 * Test to verify the omnibox can take focus during startup before native li
braries have | 784 * Test to verify the omnibox can take focus during startup before native li
braries have |
| 759 * loaded. | 785 * loaded. |
| 760 */ | 786 */ |
| 787 @Test |
| 761 @SmallTest | 788 @SmallTest |
| 762 @Feature({"Omnibox"}) | 789 @Feature({"Omnibox"}) |
| 763 @RetryOnFailure | 790 @RetryOnFailure |
| 764 public void testFocusingOnStartup() throws InterruptedException { | 791 public void testFocusingOnStartup() { |
| 765 Intent intent = new Intent(Intent.ACTION_MAIN); | 792 Intent intent = new Intent(Intent.ACTION_MAIN); |
| 766 intent.addCategory(Intent.CATEGORY_LAUNCHER); | 793 intent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 767 prepareUrlIntent(intent, "about:blank"); | 794 mActivityTestRule.prepareUrlIntent(intent, "about:blank"); |
| 768 startActivityCompletely(intent); | 795 mActivityTestRule.startActivityCompletely(intent); |
| 769 | 796 |
| 770 UrlBar urlBar = getUrlBar(); | 797 UrlBar urlBar = getUrlBar(); |
| 771 assertNotNull(urlBar); | 798 Assert.assertNotNull(urlBar); |
| 772 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 799 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 773 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); | 800 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); |
| 774 } | 801 } |
| 775 | 802 |
| 803 @Test |
| 776 @SmallTest | 804 @SmallTest |
| 777 @Feature({"Omnibox"}) | 805 @Feature({"Omnibox"}) |
| 778 @RetryOnFailure | 806 @RetryOnFailure |
| 779 public void testCopyHuge() throws InterruptedException { | 807 public void testCopyHuge() throws InterruptedException { |
| 780 startMainActivityWithURL(HUGE_URL); | 808 mActivityTestRule.startMainActivityWithURL(HUGE_URL); |
| 781 OmniboxTestUtils.toggleUrlBarFocus(getUrlBar(), true); | 809 OmniboxTestUtils.toggleUrlBarFocus(getUrlBar(), true); |
| 782 assertEquals(HUGE_URL, copyUrlToClipboard(android.R.id.copy)); | 810 Assert.assertEquals(HUGE_URL, copyUrlToClipboard(android.R.id.copy)); |
| 783 } | 811 } |
| 784 | 812 |
| 813 @Test |
| 785 @SmallTest | 814 @SmallTest |
| 786 @Feature({"Omnibox"}) | 815 @Feature({"Omnibox"}) |
| 787 @RetryOnFailure | 816 @RetryOnFailure |
| 788 public void testCutHuge() throws InterruptedException { | 817 public void testCutHuge() throws InterruptedException { |
| 789 startMainActivityWithURL(HUGE_URL); | 818 mActivityTestRule.startMainActivityWithURL(HUGE_URL); |
| 790 OmniboxTestUtils.toggleUrlBarFocus(getUrlBar(), true); | 819 OmniboxTestUtils.toggleUrlBarFocus(getUrlBar(), true); |
| 791 assertEquals(HUGE_URL, copyUrlToClipboard(android.R.id.cut)); | 820 Assert.assertEquals(HUGE_URL, copyUrlToClipboard(android.R.id.cut)); |
| 792 } | 821 } |
| 793 | 822 |
| 794 /** | 823 /** |
| 795 * Clears the clipboard, executes specified action on the omnibox and | 824 * Clears the clipboard, executes specified action on the omnibox and |
| 796 * returns clipboard's content. Action can be either android.R.id.copy | 825 * returns clipboard's content. Action can be either android.R.id.copy |
| 797 * or android.R.id.cut. | 826 * or android.R.id.cut. |
| 798 */ | 827 */ |
| 799 private String copyUrlToClipboard(final int action) { | 828 private String copyUrlToClipboard(final int action) { |
| 800 ClipboardManager clipboardManager = (ClipboardManager) | 829 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<String>
() { |
| 801 getActivity().getSystemService(Context.CLIPBOARD_SERVICE); | 830 @Override |
| 831 public String call() { |
| 832 ClipboardManager clipboardManager = |
| 833 (ClipboardManager) mActivityTestRule.getActivity().getSy
stemService( |
| 834 Context.CLIPBOARD_SERVICE); |
| 802 | 835 |
| 803 clipboardManager.setPrimaryClip(ClipData.newPlainText(null, "")); | 836 clipboardManager.setPrimaryClip(ClipData.newPlainText(null, ""))
; |
| 804 | 837 |
| 805 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 838 |
| 806 @Override | 839 Assert.assertTrue(getUrlBar().onTextContextMenuItem(action)); |
| 807 public void run() { | 840 ClipData clip = clipboardManager.getPrimaryClip(); |
| 808 assertTrue(getUrlBar().onTextContextMenuItem(action)); | 841 CharSequence text = (clip != null && clip.getItemCount() != 0) |
| 842 ? clip.getItemAt(0).getText() : null; |
| 843 return text != null ? text.toString() : null; |
| 844 |
| 809 } | 845 } |
| 810 }); | 846 }); |
| 811 | 847 |
| 812 ClipData clip = clipboardManager.getPrimaryClip(); | |
| 813 CharSequence text = (clip != null && clip.getItemCount() != 0) | |
| 814 ? clip.getItemAt(0).getText() : null; | |
| 815 return text != null ? text.toString() : null; | |
| 816 } | 848 } |
| 817 | 849 |
| 818 @Override | 850 @Before |
| 819 public void startMainActivity() throws InterruptedException { | 851 public void setUp() throws InterruptedException { |
| 820 // Each test will start the activity. | 852 // Each test will start the activity. |
| 821 } | 853 } |
| 822 } | 854 } |
| OLD | NEW |