OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.omnibox; |
| 6 |
| 7 import static org.chromium.chrome.test.util.OmniboxTestUtils.buildSuggestionMap; |
| 8 |
| 9 import android.os.SystemClock; |
| 10 import android.test.FlakyTest; |
| 11 import android.test.suitebuilder.annotation.MediumTest; |
| 12 import android.test.suitebuilder.annotation.SmallTest; |
| 13 import android.text.Selection; |
| 14 import android.util.Pair; |
| 15 import android.view.KeyEvent; |
| 16 import android.view.WindowManager; |
| 17 import android.widget.ImageButton; |
| 18 import android.widget.ImageView; |
| 19 import android.widget.TextView; |
| 20 |
| 21 import com.google.android.apps.chrome.R; |
| 22 |
| 23 import org.chromium.base.ThreadUtils; |
| 24 import org.chromium.base.test.util.EnormousTest; |
| 25 import org.chromium.base.test.util.Feature; |
| 26 import org.chromium.base.test.util.ScalableTimeout; |
| 27 import org.chromium.chrome.browser.ChromeActivity; |
| 28 import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsR
eceivedListener; |
| 29 import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.Type; |
| 30 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 31 import org.chromium.chrome.test.util.ChromeTabUtils; |
| 32 import org.chromium.chrome.test.util.OmniboxTestUtils; |
| 33 import org.chromium.chrome.test.util.OmniboxTestUtils.SuggestionsResult; |
| 34 import org.chromium.chrome.test.util.OmniboxTestUtils.SuggestionsResultBuilder; |
| 35 import org.chromium.chrome.test.util.OmniboxTestUtils.TestAutocompleteController
; |
| 36 import org.chromium.chrome.test.util.OmniboxTestUtils.TestSuggestionResultsBuild
er; |
| 37 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 38 import org.chromium.content.browser.test.util.Criteria; |
| 39 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 40 import org.chromium.content.browser.test.util.KeyUtils; |
| 41 import org.chromium.content.browser.test.util.UiUtils; |
| 42 import org.chromium.ui.base.DeviceFormFactor; |
| 43 |
| 44 import java.util.HashMap; |
| 45 import java.util.List; |
| 46 import java.util.Map; |
| 47 import java.util.concurrent.Callable; |
| 48 import java.util.concurrent.ExecutionException; |
| 49 import java.util.concurrent.atomic.AtomicInteger; |
| 50 |
| 51 /** |
| 52 * Tests of the Omnibox. |
| 53 */ |
| 54 public class OmniboxTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
| 55 |
| 56 public OmniboxTest() { |
| 57 super(ChromeActivity.class); |
| 58 } |
| 59 |
| 60 private void clearUrlBar() { |
| 61 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); |
| 62 assertNotNull(urlBar); |
| 63 |
| 64 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 65 @Override |
| 66 public void run() { |
| 67 urlBar.setText(""); |
| 68 } |
| 69 }); |
| 70 } |
| 71 |
| 72 /** |
| 73 * Sanity check of Omnibox. The problem in http://b/5021723 would |
| 74 * cause this to fail (hang or crash). |
| 75 */ |
| 76 @EnormousTest |
| 77 @Feature({"Omnibox"}) |
| 78 public void testSimpleUse() throws InterruptedException { |
| 79 typeInOmnibox("aaaaaaa", false); |
| 80 |
| 81 final LocationBarLayout locationBar = |
| 82 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); |
| 83 OmniboxTestUtils.waitForOmniboxSuggestions(locationBar); |
| 84 |
| 85 ChromeTabUtils.waitForTabPageLoadStart(getActivity().getActivityTab(), n
ew Runnable() { |
| 86 @Override |
| 87 public void run() { |
| 88 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.u
rl_bar); |
| 89 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEve
nt.KEYCODE_ENTER); |
| 90 } |
| 91 }, ScalableTimeout.scaleTimeout(20)); |
| 92 } |
| 93 |
| 94 /** |
| 95 * Test for checking whether soft input model switches with focus. |
| 96 */ |
| 97 @MediumTest |
| 98 @Feature({"Omnibox"}) |
| 99 public void testFocusChangingSoftInputMode() throws InterruptedException { |
| 100 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); |
| 101 |
| 102 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 103 assertTrue("Soft input mode failed to switch on focus", |
| 104 CriteriaHelper.pollForCriteria(new Criteria() { |
| 105 @Override |
| 106 public boolean isSatisfied() { |
| 107 return getActivity().getWindow().getAttributes().softInp
utMode |
| 108 == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_
PAN; |
| 109 } |
| 110 })); |
| 111 |
| 112 OmniboxTestUtils.toggleUrlBarFocus(urlBar, false); |
| 113 assertTrue("Soft input mode failed to switch on unfocus", |
| 114 CriteriaHelper.pollForCriteria(new Criteria() { |
| 115 @Override |
| 116 public boolean isSatisfied() { |
| 117 return getActivity().getWindow().getAttributes().softInp
utMode |
| 118 == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_
RESIZE; |
| 119 } |
| 120 })); |
| 121 } |
| 122 |
| 123 /** |
| 124 * Tests that focusing a url bar starts a zero suggest request. |
| 125 */ |
| 126 @MediumTest |
| 127 @Feature({"Omnibox"}) |
| 128 public void testRequestZeroSuggestOnFocus() throws Exception { |
| 129 final LocationBarLayout locationBar = |
| 130 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); |
| 131 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); |
| 132 |
| 133 final TestAutocompleteController controller = new TestAutocompleteContro
ller( |
| 134 locationBar, null, null); |
| 135 |
| 136 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 137 @Override |
| 138 public void run() { |
| 139 locationBar.setAutocompleteController(controller); |
| 140 } |
| 141 }); |
| 142 assertEquals("Should not have any zero suggest requests yet", 0, |
| 143 controller.numZeroSuggestRequests()); |
| 144 |
| 145 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 146 |
| 147 assertTrue("Should have requested zero suggest on focusing", |
| 148 CriteriaHelper.pollForCriteria(new Criteria() { |
| 149 @Override |
| 150 public boolean isSatisfied() { |
| 151 return controller.numZeroSuggestRequests() == 1; |
| 152 } |
| 153 })); |
| 154 } |
| 155 |
| 156 /** |
| 157 * Tests that focusing a url bar starts a zero suggest request. |
| 158 */ |
| 159 @MediumTest |
| 160 @Feature({"Omnibox"}) |
| 161 public void testRequestZeroSuggestAfterDelete() throws InterruptedException
{ |
| 162 final LocationBarLayout locationBar = |
| 163 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); |
| 164 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); |
| 165 final ImageButton deleteButton = (ImageButton) getActivity().findViewByI
d( |
| 166 R.id.delete_button); |
| 167 |
| 168 final OnSuggestionsReceivedListener emptySuggestionListener = |
| 169 new OnSuggestionsReceivedListener() { |
| 170 @Override |
| 171 public void onSuggestionsReceived( |
| 172 List<OmniboxSuggestion> suggestions, String inlineAu
tocompleteText) { |
| 173 } |
| 174 }; |
| 175 |
| 176 final TestAutocompleteController controller = new TestAutocompleteContro
ller( |
| 177 locationBar, emptySuggestionListener, |
| 178 new HashMap<String, List<SuggestionsResult>>()); |
| 179 |
| 180 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 181 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 182 @Override |
| 183 public void run() { |
| 184 locationBar.setAutocompleteController(controller); |
| 185 urlBar.setText("g"); |
| 186 } |
| 187 }); |
| 188 |
| 189 assertTrue("Should have drawn the delete button", |
| 190 CriteriaHelper.pollForCriteria(new Criteria() { |
| 191 @Override |
| 192 public boolean isSatisfied() { |
| 193 return deleteButton.getWidth() > 0; |
| 194 } |
| 195 })); |
| 196 |
| 197 // The click view below ends up clicking on the menu button underneath t
he delete button |
| 198 // for some time after the delete button appears. Wait for UI to settle
down before |
| 199 // clicking. |
| 200 UiUtils.settleDownUI(getInstrumentation()); |
| 201 |
| 202 singleClickView(deleteButton, deleteButton.getWidth() / 2, deleteButton.
getHeight() / 2); |
| 203 |
| 204 assertTrue("Should have requested zero suggest results on url bar empty"
, |
| 205 CriteriaHelper.pollForCriteria(new Criteria() { |
| 206 @Override |
| 207 public boolean isSatisfied() { |
| 208 return controller.numZeroSuggestRequests() == 1; |
| 209 } |
| 210 })); |
| 211 } |
| 212 |
| 213 @MediumTest |
| 214 @Feature({"Omnibox"}) |
| 215 public void testRequestZeroSuggestTypeAndBackspace() throws InterruptedExcep
tion { |
| 216 final LocationBarLayout locationBar = |
| 217 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); |
| 218 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); |
| 219 |
| 220 final OnSuggestionsReceivedListener emptySuggestionListener = |
| 221 new OnSuggestionsReceivedListener() { |
| 222 @Override |
| 223 public void onSuggestionsReceived(List<OmniboxSuggestion> su
ggestions, |
| 224 String inlineAutocompleteText) { |
| 225 } |
| 226 }; |
| 227 |
| 228 final TestAutocompleteController controller = new TestAutocompleteContro
ller( |
| 229 locationBar, emptySuggestionListener, |
| 230 new HashMap<String, List<SuggestionsResult>>()); |
| 231 |
| 232 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 233 |
| 234 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 235 @Override |
| 236 public void run() { |
| 237 locationBar.setAutocompleteController(controller); |
| 238 urlBar.setText("g"); |
| 239 urlBar.setSelection(1); |
| 240 } |
| 241 }); |
| 242 |
| 243 assertEquals("No calls to zero suggest yet", 0, controller.numZeroSugges
tRequests()); |
| 244 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEvent.KEYCO
DE_DEL); |
| 245 assertTrue("Should have requested zero suggest results on url bar empty"
, |
| 246 CriteriaHelper.pollForCriteria(new Criteria() { |
| 247 @Override |
| 248 public boolean isSatisfied() { |
| 249 return controller.numZeroSuggestRequests() == 1; |
| 250 } |
| 251 })); |
| 252 } |
| 253 |
| 254 // Sanity check that no text is displayed in the omnibox when on the NTP pag
e and that the hint |
| 255 // text is correct. |
| 256 @MediumTest |
| 257 @Feature({"Omnibox"}) |
| 258 public void testDefaultText() throws InterruptedException { |
| 259 startMainActivityFromLauncher(); |
| 260 |
| 261 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); |
| 262 |
| 263 // Omnibox on NTP shows the hint text. |
| 264 assertNotNull(urlBar); |
| 265 assertEquals("Location bar has text.", "", urlBar.getText().toString()); |
| 266 assertEquals("Location bar has incorrect hint.", |
| 267 getActivity().getResources().getString(R.string.search_or_type_u
rl), |
| 268 urlBar.getHint().toString()); |
| 269 |
| 270 // Type something in the omnibox. |
| 271 // Note that the TextView does not provide a way to test if the hint is
showing, the API |
| 272 // documentation simply says it shows when the text is empty. |
| 273 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 274 @Override |
| 275 public void run() { |
| 276 urlBar.requestFocus(); |
| 277 urlBar.setText("G"); |
| 278 } |
| 279 }); |
| 280 assertEquals("Location bar should have text.", "G", urlBar.getText().toS
tring()); |
| 281 } |
| 282 |
| 283 @MediumTest |
| 284 @Feature({"Omnibox", "Main"}) |
| 285 public void testAutoCompleteAndCorrectionLandscape() throws ExecutionExcepti
on, |
| 286 InterruptedException { |
| 287 // Default orientation for tablets is landscape. Default for phones is p
ortrait. |
| 288 int requestedOrientation = 1; |
| 289 if (DeviceFormFactor.isTablet(getActivity())) { |
| 290 requestedOrientation = 0; |
| 291 } |
| 292 doTestAutoCompleteAndCorrectionForOrientation(requestedOrientation); |
| 293 } |
| 294 |
| 295 @MediumTest |
| 296 @Feature({"Omnibox", "Main"}) |
| 297 public void testAutoCompleteAndCorrectionPortrait() throws ExecutionExceptio
n, |
| 298 InterruptedException { |
| 299 // Default orientation for tablets is landscape. Default for phones is p
ortrait. |
| 300 int requestedOrientation = 0; |
| 301 if (DeviceFormFactor.isTablet(getActivity())) { |
| 302 requestedOrientation = 1; |
| 303 } |
| 304 doTestAutoCompleteAndCorrectionForOrientation(requestedOrientation); |
| 305 } |
| 306 |
| 307 private void doTestAutoCompleteAndCorrectionForOrientation( |
| 308 int orientation) throws ExecutionException, InterruptedException { |
| 309 getActivity().setRequestedOrientation(orientation); |
| 310 UiUtils.settleDownUI(getInstrumentation()); |
| 311 |
| 312 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 313 new TestSuggestionResultsBuilder() |
| 314 .setTextShownFor("wiki") |
| 315 .addSuggestions(new SuggestionsResultBuilder() |
| 316 .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "wi
kipedia", null) |
| 317 .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "wi
ki", null) |
| 318 .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "wi
kileaks", null) |
| 319 .setAutocompleteText("pedia")), |
| 320 new TestSuggestionResultsBuilder() |
| 321 .setTextShownFor("onomatop") |
| 322 .addSuggestions(new SuggestionsResultBuilder() |
| 323 .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "on
omatopoeia", null) |
| 324 .addGeneratedSuggestion( |
| 325 Type.SEARCH_SUGGEST, "onomatopoeia foo",
null) |
| 326 .setAutocompleteText("oeia")), |
| 327 new TestSuggestionResultsBuilder() |
| 328 .setTextShownFor("mispellled") |
| 329 .addSuggestions(new SuggestionsResultBuilder() |
| 330 .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "mi
sspelled", null) |
| 331 .addGeneratedSuggestion( |
| 332 Type.SEARCH_SUGGEST, "misspelled words",
null) |
| 333 .setAutocompleteText("")) |
| 334 ); |
| 335 checkAutocompleteText(suggestionsMap, "wiki", "wikipedia", 4, 9); |
| 336 checkAutocompleteText(suggestionsMap, "onomatop", "onomatopoeia", 8, 12)
; |
| 337 checkAutocompleteText(suggestionsMap, "mispellled", "mispellled", 10, 10
); |
| 338 } |
| 339 |
| 340 /** |
| 341 * crbug.com/267901 |
| 342 * @MediumTest |
| 343 * @Feature({"Omnibox"}) |
| 344 */ |
| 345 @FlakyTest |
| 346 public void testPerformSearchQuery() throws InterruptedException { |
| 347 UiUtils.settleDownUI(getInstrumentation()); |
| 348 final String testQuery = "Test Query"; |
| 349 |
| 350 ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), new
Runnable() { |
| 351 @Override |
| 352 public void run() { |
| 353 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 354 @Override |
| 355 public void run() { |
| 356 final LocationBarLayout locationBar = |
| 357 (LocationBarLayout) getActivity().findViewById(R
.id.location_bar); |
| 358 locationBar.performSearchQueryForTest(testQuery); |
| 359 } |
| 360 }); |
| 361 } |
| 362 }); |
| 363 |
| 364 getInstrumentation().runOnMainSync(new Runnable() { |
| 365 @Override |
| 366 public void run() { |
| 367 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.u
rl_bar); |
| 368 String currentUrl = urlBar.getText().toString(); |
| 369 assertEquals(testQuery, currentUrl); |
| 370 } |
| 371 }); |
| 372 } |
| 373 |
| 374 @MediumTest |
| 375 @Feature({"Omnibox"}) |
| 376 public void testDuplicateAutocompleteTextResults() |
| 377 throws InterruptedException, ExecutionException { |
| 378 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 379 new TestSuggestionResultsBuilder() |
| 380 .setTextShownFor("test") |
| 381 .addSuggestions(new SuggestionsResultBuilder() |
| 382 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 383 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
sting", null) |
| 384 .setAutocompleteText("ing")) |
| 385 .addSuggestions(new SuggestionsResultBuilder() |
| 386 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 387 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
stz", null) |
| 388 .setAutocompleteText("ing")) |
| 389 .addSuggestions(new SuggestionsResultBuilder() |
| 390 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 391 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
stblarg", null) |
| 392 .setAutocompleteText("ing"))); |
| 393 checkAutocompleteText(suggestionsMap, "test", "testing", 4, 7); |
| 394 } |
| 395 |
| 396 @MediumTest |
| 397 @Feature({"Omnibox"}) |
| 398 public void testGrowingAutocompleteTextResults() |
| 399 throws InterruptedException, ExecutionException { |
| 400 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 401 new TestSuggestionResultsBuilder() |
| 402 .setTextShownFor("test") |
| 403 .addSuggestions(new SuggestionsResultBuilder() |
| 404 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 405 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
sting", null) |
| 406 .setAutocompleteText("i")) |
| 407 .addSuggestions(new SuggestionsResultBuilder() |
| 408 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 409 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
stz", null) |
| 410 .setAutocompleteText("in")) |
| 411 .addSuggestions(new SuggestionsResultBuilder() |
| 412 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 413 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
stblarg", null) |
| 414 .setAutocompleteText("ing for the win"))); |
| 415 checkAutocompleteText(suggestionsMap, "test", "testing for the win", 4,
19); |
| 416 } |
| 417 |
| 418 @MediumTest |
| 419 @Feature({"Omnibox"}) |
| 420 public void testShrinkingAutocompleteTextResults() |
| 421 throws InterruptedException, ExecutionException { |
| 422 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 423 new TestSuggestionResultsBuilder() |
| 424 .setTextShownFor("test") |
| 425 .addSuggestions(new SuggestionsResultBuilder() |
| 426 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 427 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
sting", null) |
| 428 .setAutocompleteText("ing is awesome")) |
| 429 .addSuggestions(new SuggestionsResultBuilder() |
| 430 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 431 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
stz", null) |
| 432 .setAutocompleteText("ing is hard")) |
| 433 .addSuggestions(new SuggestionsResultBuilder() |
| 434 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
st", null) |
| 435 .addGeneratedSuggestion(Type.SEARCH_HISTORY, "te
stblarg", null) |
| 436 .setAutocompleteText("ingz"))); |
| 437 checkAutocompleteText(suggestionsMap, "test", "testingz", 4, 8); |
| 438 } |
| 439 |
| 440 private void checkAutocompleteText( |
| 441 Map<String, List<SuggestionsResult>> suggestionsMap, |
| 442 final String textToType, final String expectedAutocompleteText, |
| 443 final int expectedAutocompleteStart, final int expectedAutocompleteE
nd) |
| 444 throws InterruptedException, ExecutionException { |
| 445 |
| 446 final TextView urlBarView = (TextView) getActivity().findViewById(R.id.u
rl_bar); |
| 447 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 448 @Override |
| 449 public void run() { |
| 450 urlBarView.requestFocus(); |
| 451 urlBarView.setText(""); |
| 452 } |
| 453 }); |
| 454 |
| 455 final LocationBarLayout locationBar = |
| 456 ((LocationBarLayout) getActivity().findViewById(R.id.location_ba
r)); |
| 457 |
| 458 final Object suggestionsProcessedSignal = new Object(); |
| 459 final AtomicInteger suggestionsLeft = new AtomicInteger( |
| 460 suggestionsMap.get(textToType).size()); |
| 461 OnSuggestionsReceivedListener suggestionsListener = new OnSuggestionsRec
eivedListener() { |
| 462 @Override |
| 463 public void onSuggestionsReceived( |
| 464 List<OmniboxSuggestion> suggestions, |
| 465 String inlineAutocompleteText) { |
| 466 locationBar.onSuggestionsReceived(suggestions, inlineAutocomplet
eText); |
| 467 synchronized (suggestionsProcessedSignal) { |
| 468 int remaining = suggestionsLeft.decrementAndGet(); |
| 469 if (remaining == 0) { |
| 470 suggestionsProcessedSignal.notifyAll(); |
| 471 } else if (remaining < 0) { |
| 472 fail("Unexpected suggestions received"); |
| 473 } |
| 474 } |
| 475 } |
| 476 }; |
| 477 final TestAutocompleteController controller = new TestAutocompleteContro
ller( |
| 478 locationBar, suggestionsListener, suggestionsMap); |
| 479 |
| 480 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 481 @Override |
| 482 public void run() { |
| 483 locationBar.setAutocompleteController(controller); |
| 484 } |
| 485 }); |
| 486 |
| 487 KeyUtils.typeTextIntoView(getInstrumentation(), urlBarView, textToType); |
| 488 |
| 489 synchronized (suggestionsProcessedSignal) { |
| 490 long endTime = SystemClock.uptimeMillis() + 3000; |
| 491 while (suggestionsLeft.get() != 0) { |
| 492 long waitTime = endTime - SystemClock.uptimeMillis(); |
| 493 if (waitTime <= 0) break; |
| 494 suggestionsProcessedSignal.wait(waitTime); |
| 495 } |
| 496 } |
| 497 |
| 498 CharSequence urlText = ThreadUtils.runOnUiThreadBlocking(new Callable<Ch
arSequence>() { |
| 499 @Override |
| 500 public CharSequence call() throws Exception { |
| 501 return urlBarView.getText(); |
| 502 } |
| 503 }); |
| 504 assertEquals("URL Bar text not autocompleted as expected.", |
| 505 expectedAutocompleteText, urlText.toString()); |
| 506 assertEquals(expectedAutocompleteStart, Selection.getSelectionStart(urlT
ext)); |
| 507 assertEquals(expectedAutocompleteEnd, Selection.getSelectionEnd(urlText)
); |
| 508 } |
| 509 |
| 510 /** |
| 511 * The following test is a basic way to assess how much instant slows down t
yping in the |
| 512 * omnibox. It is meant to be run manually for investigation purposes. |
| 513 * When instant was enabled for all suggestions (including searched), I woul
d get a 40% increase |
| 514 * in the average time on this test. With instant off, it was almost identic
al. |
| 515 * Marking the test disabled so it is not picked up by our test runner, as i
t is supposed to be |
| 516 * run manually. |
| 517 */ |
| 518 public void manualTestTypingPerformance() throws InterruptedException { |
| 519 final String text = "searching for pizza"; |
| 520 // Type 10 times something on the omnibox and get the average time with
and without instant. |
| 521 long instantAverage = 0; |
| 522 long noInstantAverage = 0; |
| 523 |
| 524 for (int i = 0; i < 2; ++i) { |
| 525 boolean instantOn = (i == 1); |
| 526 setAllowPrerender(instantOn); |
| 527 |
| 528 for (int j = 0; j < 10; ++j) { |
| 529 long before = System.currentTimeMillis(); |
| 530 typeInOmnibox(text, true); |
| 531 if (instantOn) { |
| 532 instantAverage += System.currentTimeMillis() - before; |
| 533 } else { |
| 534 noInstantAverage += System.currentTimeMillis() - before; |
| 535 } |
| 536 clearUrlBar(); |
| 537 getInstrumentation().waitForIdleSync(); |
| 538 } |
| 539 } |
| 540 instantAverage /= 10; |
| 541 noInstantAverage /= 10; |
| 542 System.err.println("****************************************************
**************"); |
| 543 System.err.println("**** Instant average=" + instantAverage); |
| 544 System.err.println("**** No instant average=" + noInstantAverage); |
| 545 System.err.println("****************************************************
**************"); |
| 546 } |
| 547 |
| 548 /** |
| 549 * crbug.com/414353 |
| 550 * Test to verify security-icon "lock or globe" on visiting http and secured
Urls. |
| 551 * @EnormousTest |
| 552 */ |
| 553 @FlakyTest |
| 554 public void testSecurityIcon() throws InterruptedException { |
| 555 final String testUrl = TestHttpServerClient.getUrl( |
| 556 "chrome/test/data/android/omnibox/one.html"); |
| 557 final String securedExternalUrl = "https://www.google.com"; |
| 558 |
| 559 ImageView navigationButton = (ImageView) |
| 560 getActivity().findViewById(R.id.navigation_button); |
| 561 ImageButton securityButton = (ImageButton) |
| 562 getActivity().findViewById(R.id.security_button); |
| 563 |
| 564 loadUrl(testUrl); |
| 565 final LocationBarLayout locationBar = |
| 566 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); |
| 567 boolean securityIcon = locationBar.isSecurityButtonShown(); |
| 568 assertFalse("Omnibox should not have a Security icon", securityIcon); |
| 569 assertEquals("navigation_button with wrong resource-id", |
| 570 R.id.navigation_button, navigationButton.getId()); |
| 571 assertTrue(navigationButton.isShown()); |
| 572 assertFalse(securityButton.isShown()); |
| 573 |
| 574 loadUrl(securedExternalUrl); |
| 575 securityIcon = locationBar.isSecurityButtonShown(); |
| 576 assertTrue("Omnibox should have a Security icon", securityIcon); |
| 577 assertEquals("security_button with wrong resource-id", |
| 578 R.id.security_button, securityButton.getId()); |
| 579 assertTrue(securityButton.isShown()); |
| 580 assertFalse(navigationButton.isShown()); |
| 581 } |
| 582 |
| 583 @SmallTest |
| 584 public void testSplitPathFromUrlDisplayText() { |
| 585 verifySplitUrlAndPath("", null, LocationBarLayout.splitPathFromUrlDispla
yText("")); |
| 586 verifySplitUrlAndPath( |
| 587 "https:", null, LocationBarLayout.splitPathFromUrlDisplayText("h
ttps:")); |
| 588 verifySplitUrlAndPath("about:blank", null, |
| 589 LocationBarLayout.splitPathFromUrlDisplayText("about:blank")); |
| 590 |
| 591 verifySplitUrlAndPath("chrome://flags", null, |
| 592 LocationBarLayout.splitPathFromUrlDisplayText("chrome://flags"))
; |
| 593 verifySplitUrlAndPath("chrome://flags", "/?egads", |
| 594 LocationBarLayout.splitPathFromUrlDisplayText("chrome://flags/?e
gads")); |
| 595 |
| 596 verifySplitUrlAndPath("www.google.com", null, |
| 597 LocationBarLayout.splitPathFromUrlDisplayText("www.google.com"))
; |
| 598 verifySplitUrlAndPath("www.google.com", null, |
| 599 LocationBarLayout.splitPathFromUrlDisplayText("www.google.com/")
); |
| 600 verifySplitUrlAndPath("www.google.com", "/?q=blah", |
| 601 LocationBarLayout.splitPathFromUrlDisplayText("www.google.com/?q
=blah")); |
| 602 |
| 603 verifySplitUrlAndPath("https://www.google.com", null, |
| 604 LocationBarLayout.splitPathFromUrlDisplayText("https://www.googl
e.com")); |
| 605 verifySplitUrlAndPath("https://www.google.com", null, |
| 606 LocationBarLayout.splitPathFromUrlDisplayText("https://www.googl
e.com/")); |
| 607 verifySplitUrlAndPath("https://www.google.com", "/?q=blah", |
| 608 LocationBarLayout.splitPathFromUrlDisplayText("https://www.googl
e.com/?q=blah")); |
| 609 |
| 610 // crbug.com/414990 |
| 611 String testUrl = "https://disneyworld.disney.go.com/special-offers/" |
| 612 + "?CMP=KNC-WDW_FY15_DOM_Q1RO_BR_Gold_SpOffer|G|4141300.RR.AM.01
.47" |
| 613 + "&keyword_id=s6JyxRifG_dm|walt%20disney%20world|37174067873|e|
1540wwa14043"; |
| 614 verifySplitUrlAndPath("https://disneyworld.disney.go.com", |
| 615 "/special-offers/?CMP=KNC-WDW_FY15_DOM_Q1RO_BR_Gold_SpOffer|G|41
41300.RR.AM.01.47" |
| 616 + "&keyword_id=s6JyxRifG_dm|walt%20disney%20world|371740
67873|e|" |
| 617 + "1540wwa14043", |
| 618 LocationBarLayout.splitPathFromUrlDisplayText(testUrl)); |
| 619 |
| 620 // crbug.com/415387 |
| 621 verifySplitUrlAndPath("ftp://example.com", "/ftp.html", |
| 622 LocationBarLayout.splitPathFromUrlDisplayText("ftp://example.com
/ftp.html")); |
| 623 |
| 624 // crbug.com/447416 |
| 625 verifySplitUrlAndPath("file:///dev/blah", null, |
| 626 LocationBarLayout.splitPathFromUrlDisplayText("file:///dev/blah"
)); |
| 627 verifySplitUrlAndPath("javascript:window.alert('hello');", null, |
| 628 LocationBarLayout.splitPathFromUrlDisplayText("javascript:window
.alert('hello');")); |
| 629 verifySplitUrlAndPath("data:text/html;charset=utf-8,Page%201", null, |
| 630 LocationBarLayout.splitPathFromUrlDisplayText( |
| 631 "data:text/html;charset=utf-8,Page%201")); |
| 632 } |
| 633 |
| 634 private void verifySplitUrlAndPath( |
| 635 String expectedPrePath, String expectedPostPath, Pair<String, String
> actualValues) { |
| 636 assertEquals(expectedPrePath, actualValues.first); |
| 637 assertEquals(expectedPostPath, actualValues.second); |
| 638 } |
| 639 |
| 640 @Override |
| 641 public void startMainActivity() throws InterruptedException { |
| 642 if (getName().equals("testsplitPathFromUrlDisplayText") |
| 643 || getName().equals("testDefaultText")) { |
| 644 return; |
| 645 } |
| 646 startMainActivityOnBlankPage(); |
| 647 } |
| 648 } |
OLD | NEW |