| 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.chrome.test.util.OmniboxTestUtils.buildSuggestionMap; | 7 import static org.chromium.chrome.test.util.OmniboxTestUtils.buildSuggestionMap; |
| 8 | 8 |
| 9 import android.os.Build; | 9 import android.os.Build; |
| 10 import android.os.SystemClock; | 10 import android.os.SystemClock; |
| 11 import android.support.test.InstrumentationRegistry; |
| 11 import android.support.test.filters.MediumTest; | 12 import android.support.test.filters.MediumTest; |
| 12 import android.support.test.filters.SmallTest; | 13 import android.support.test.filters.SmallTest; |
| 13 import android.support.v4.view.ViewCompat; | 14 import android.support.v4.view.ViewCompat; |
| 14 import android.text.Selection; | 15 import android.text.Selection; |
| 15 import android.util.Pair; | 16 import android.util.Pair; |
| 16 import android.view.KeyEvent; | 17 import android.view.KeyEvent; |
| 17 import android.view.View; | 18 import android.view.View; |
| 18 import android.view.WindowManager; | 19 import android.view.WindowManager; |
| 19 import android.widget.ImageButton; | 20 import android.widget.ImageButton; |
| 20 import android.widget.ImageView; | 21 import android.widget.ImageView; |
| 21 import android.widget.TextView; | 22 import android.widget.TextView; |
| 22 | 23 |
| 24 import org.junit.Assert; |
| 25 import org.junit.Before; |
| 26 import org.junit.Rule; |
| 27 import org.junit.Test; |
| 28 import org.junit.runner.RunWith; |
| 29 |
| 23 import org.chromium.base.ThreadUtils; | 30 import org.chromium.base.ThreadUtils; |
| 31 import org.chromium.base.test.util.CommandLineFlags; |
| 24 import org.chromium.base.test.util.EnormousTest; | 32 import org.chromium.base.test.util.EnormousTest; |
| 25 import org.chromium.base.test.util.Feature; | 33 import org.chromium.base.test.util.Feature; |
| 26 import org.chromium.base.test.util.FlakyTest; | 34 import org.chromium.base.test.util.FlakyTest; |
| 27 import org.chromium.base.test.util.MinAndroidSdkLevel; | 35 import org.chromium.base.test.util.MinAndroidSdkLevel; |
| 28 import org.chromium.base.test.util.RetryOnFailure; | 36 import org.chromium.base.test.util.RetryOnFailure; |
| 29 import org.chromium.base.test.util.ScalableTimeout; | 37 import org.chromium.base.test.util.ScalableTimeout; |
| 30 import org.chromium.chrome.R; | 38 import org.chromium.chrome.R; |
| 31 import org.chromium.chrome.browser.ChromeActivity; | 39 import org.chromium.chrome.browser.ChromeActivity; |
| 40 import org.chromium.chrome.browser.ChromeSwitches; |
| 32 import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsR
eceivedListener; | 41 import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsR
eceivedListener; |
| 33 import org.chromium.chrome.browser.omnibox.LocationBarLayout.OmniboxSuggestionsL
ist; | 42 import org.chromium.chrome.browser.omnibox.LocationBarLayout.OmniboxSuggestionsL
ist; |
| 34 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 43 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 44 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 35 import org.chromium.chrome.test.util.ChromeTabUtils; | 45 import org.chromium.chrome.test.util.ChromeTabUtils; |
| 36 import org.chromium.chrome.test.util.OmniboxTestUtils; | 46 import org.chromium.chrome.test.util.OmniboxTestUtils; |
| 37 import org.chromium.chrome.test.util.OmniboxTestUtils.SuggestionsResult; | 47 import org.chromium.chrome.test.util.OmniboxTestUtils.SuggestionsResult; |
| 38 import org.chromium.chrome.test.util.OmniboxTestUtils.SuggestionsResultBuilder; | 48 import org.chromium.chrome.test.util.OmniboxTestUtils.SuggestionsResultBuilder; |
| 39 import org.chromium.chrome.test.util.OmniboxTestUtils.TestAutocompleteController
; | 49 import org.chromium.chrome.test.util.OmniboxTestUtils.TestAutocompleteController
; |
| 40 import org.chromium.chrome.test.util.OmniboxTestUtils.TestSuggestionResultsBuild
er; | 50 import org.chromium.chrome.test.util.OmniboxTestUtils.TestSuggestionResultsBuild
er; |
| 41 import org.chromium.content.browser.test.util.Criteria; | 51 import org.chromium.content.browser.test.util.Criteria; |
| 42 import org.chromium.content.browser.test.util.CriteriaHelper; | 52 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 43 import org.chromium.content.browser.test.util.KeyUtils; | 53 import org.chromium.content.browser.test.util.KeyUtils; |
| 54 import org.chromium.content.browser.test.util.TouchCommon; |
| 44 import org.chromium.content.browser.test.util.UiUtils; | 55 import org.chromium.content.browser.test.util.UiUtils; |
| 45 import org.chromium.net.test.EmbeddedTestServer; | 56 import org.chromium.net.test.EmbeddedTestServer; |
| 46 import org.chromium.ui.base.DeviceFormFactor; | 57 import org.chromium.ui.base.DeviceFormFactor; |
| 47 | 58 |
| 48 import java.util.HashMap; | 59 import java.util.HashMap; |
| 49 import java.util.List; | 60 import java.util.List; |
| 50 import java.util.Locale; | 61 import java.util.Locale; |
| 51 import java.util.Map; | 62 import java.util.Map; |
| 52 import java.util.concurrent.Callable; | 63 import java.util.concurrent.Callable; |
| 53 import java.util.concurrent.ExecutionException; | 64 import java.util.concurrent.ExecutionException; |
| 54 import java.util.concurrent.atomic.AtomicInteger; | 65 import java.util.concurrent.atomic.AtomicInteger; |
| 55 | 66 |
| 56 /** | 67 /** |
| 57 * Tests of the Omnibox. | 68 * Tests of the Omnibox. |
| 58 */ | 69 */ |
| 59 public class OmniboxTest extends ChromeActivityTestCaseBase<ChromeActivity> { | 70 @RunWith(ChromeJUnit4ClassRunner.class) |
| 60 | 71 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 61 public OmniboxTest() { | 72 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| 62 super(ChromeActivity.class); | 73 public class OmniboxTest { |
| 63 } | 74 @Rule |
| 75 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| 76 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 64 | 77 |
| 65 private void clearUrlBar() { | 78 private void clearUrlBar() { |
| 66 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); | 79 final UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewB
yId(R.id.url_bar); |
| 67 assertNotNull(urlBar); | 80 Assert.assertNotNull(urlBar); |
| 68 | 81 |
| 69 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 82 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 70 @Override | 83 @Override |
| 71 public void run() { | 84 public void run() { |
| 72 urlBar.setText(""); | 85 urlBar.setText(""); |
| 73 } | 86 } |
| 74 }); | 87 }); |
| 75 } | 88 } |
| 76 | 89 |
| 77 /** | 90 /** |
| 78 * Sanity check of Omnibox. The problem in http://b/5021723 would | 91 * Sanity check of Omnibox. The problem in http://b/5021723 would |
| 79 * cause this to fail (hang or crash). | 92 * cause this to fail (hang or crash). |
| 80 */ | 93 */ |
| 94 @Test |
| 81 @EnormousTest | 95 @EnormousTest |
| 82 @Feature({"Omnibox"}) | 96 @Feature({"Omnibox"}) |
| 83 @RetryOnFailure | 97 @RetryOnFailure |
| 84 public void testSimpleUse() throws InterruptedException { | 98 public void testSimpleUse() throws InterruptedException { |
| 85 typeInOmnibox("aaaaaaa", false); | 99 mActivityTestRule.typeInOmnibox("aaaaaaa", false); |
| 86 | 100 |
| 87 final LocationBarLayout locationBar = | 101 final LocationBarLayout locationBar = |
| 88 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); | 102 (LocationBarLayout) mActivityTestRule.getActivity().findViewById
(R.id.location_bar); |
| 89 OmniboxTestUtils.waitForOmniboxSuggestions(locationBar); | 103 OmniboxTestUtils.waitForOmniboxSuggestions(locationBar); |
| 90 | 104 |
| 91 ChromeTabUtils.waitForTabPageLoadStart(getActivity().getActivityTab(), n
ew Runnable() { | 105 ChromeTabUtils.waitForTabPageLoadStart( |
| 92 @Override | 106 mActivityTestRule.getActivity().getActivityTab(), new Runnable()
{ |
| 93 public void run() { | 107 @Override |
| 94 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.u
rl_bar); | 108 public void run() { |
| 95 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEve
nt.KEYCODE_ENTER); | 109 final UrlBar urlBar = |
| 96 } | 110 (UrlBar) mActivityTestRule.getActivity().findVie
wById(R.id.url_bar); |
| 97 }, ScalableTimeout.scaleTimeout(20)); | 111 KeyUtils.singleKeyEventView(InstrumentationRegistry.getI
nstrumentation(), |
| 112 urlBar, KeyEvent.KEYCODE_ENTER); |
| 113 } |
| 114 }, ScalableTimeout.scaleTimeout(20)); |
| 98 } | 115 } |
| 99 | 116 |
| 100 /** | 117 /** |
| 101 * Test for checking whether soft input model switches with focus. | 118 * Test for checking whether soft input model switches with focus. |
| 102 */ | 119 */ |
| 120 @Test |
| 103 @MediumTest | 121 @MediumTest |
| 104 @Feature({"Omnibox"}) | 122 @Feature({"Omnibox"}) |
| 105 @RetryOnFailure | 123 @RetryOnFailure |
| 106 public void testFocusChangingSoftInputMode() throws InterruptedException { | 124 public void testFocusChangingSoftInputMode() throws InterruptedException { |
| 107 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); | 125 final UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewB
yId(R.id.url_bar); |
| 108 | 126 |
| 109 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 127 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 110 CriteriaHelper.pollInstrumentationThread(Criteria.equals( | 128 CriteriaHelper.pollInstrumentationThread(Criteria.equals( |
| 111 WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN, new Callable<I
nteger>() { | 129 WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN, new Callable<I
nteger>() { |
| 112 @Override | 130 @Override |
| 113 public Integer call() { | 131 public Integer call() { |
| 114 return getActivity().getWindow().getAttributes().softInp
utMode; | 132 return mActivityTestRule.getActivity() |
| 133 .getWindow() |
| 134 .getAttributes() |
| 135 .softInputMode; |
| 115 } | 136 } |
| 116 })); | 137 })); |
| 117 | 138 |
| 118 OmniboxTestUtils.toggleUrlBarFocus(urlBar, false); | 139 OmniboxTestUtils.toggleUrlBarFocus(urlBar, false); |
| 119 CriteriaHelper.pollInstrumentationThread(Criteria.equals( | 140 CriteriaHelper.pollInstrumentationThread(Criteria.equals( |
| 120 WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE, new Callabl
e<Integer>() { | 141 WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE, new Callabl
e<Integer>() { |
| 121 @Override | 142 @Override |
| 122 public Integer call() { | 143 public Integer call() { |
| 123 return getActivity().getWindow().getAttributes().softInp
utMode; | 144 return mActivityTestRule.getActivity() |
| 145 .getWindow() |
| 146 .getAttributes() |
| 147 .softInputMode; |
| 124 } | 148 } |
| 125 })); | 149 })); |
| 126 } | 150 } |
| 127 | 151 |
| 128 /** | 152 /** |
| 129 * Tests that focusing a url bar starts a zero suggest request. | 153 * Tests that focusing a url bar starts a zero suggest request. |
| 130 */ | 154 */ |
| 155 @Test |
| 131 @MediumTest | 156 @MediumTest |
| 132 @Feature({"Omnibox"}) | 157 @Feature({"Omnibox"}) |
| 133 @RetryOnFailure | 158 @RetryOnFailure |
| 134 public void testRequestZeroSuggestOnFocus() throws Exception { | 159 public void testRequestZeroSuggestOnFocus() throws Exception { |
| 135 final LocationBarLayout locationBar = | 160 final LocationBarLayout locationBar = |
| 136 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); | 161 (LocationBarLayout) mActivityTestRule.getActivity().findViewById
(R.id.location_bar); |
| 137 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); | 162 final UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewB
yId(R.id.url_bar); |
| 138 | 163 |
| 139 ThreadUtils.runOnUiThreadBlocking(new Runnable(){ | 164 ThreadUtils.runOnUiThreadBlocking(new Runnable(){ |
| 140 @Override | 165 @Override |
| 141 public void run() { | 166 public void run() { |
| 142 urlBar.setUrl("http://www.example.com/", null); | 167 urlBar.setUrl("http://www.example.com/", null); |
| 143 } | 168 } |
| 144 }); | 169 }); |
| 145 | 170 |
| 146 final TestAutocompleteController controller = new TestAutocompleteContro
ller( | 171 final TestAutocompleteController controller = new TestAutocompleteContro
ller( |
| 147 locationBar, null, null); | 172 locationBar, null, null); |
| 148 | 173 |
| 149 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 174 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 150 @Override | 175 @Override |
| 151 public void run() { | 176 public void run() { |
| 152 locationBar.setAutocompleteController(controller); | 177 locationBar.setAutocompleteController(controller); |
| 153 } | 178 } |
| 154 }); | 179 }); |
| 155 assertEquals("Should not have any zero suggest requests yet", 0, | 180 Assert.assertEquals("Should not have any zero suggest requests yet", 0, |
| 156 controller.numZeroSuggestRequests()); | 181 controller.numZeroSuggestRequests()); |
| 157 | 182 |
| 158 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 183 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 159 | 184 |
| 160 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable
<Integer>() { | 185 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable
<Integer>() { |
| 161 @Override | 186 @Override |
| 162 public Integer call() { | 187 public Integer call() { |
| 163 return controller.numZeroSuggestRequests(); | 188 return controller.numZeroSuggestRequests(); |
| 164 } | 189 } |
| 165 })); | 190 })); |
| 166 | 191 |
| 167 getInstrumentation().waitForIdleSync(); | 192 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 168 | 193 |
| 169 assertFalse(controller.isStartAutocompleteCalled()); | 194 Assert.assertFalse(controller.isStartAutocompleteCalled()); |
| 170 } | 195 } |
| 171 | 196 |
| 172 /** | 197 /** |
| 173 * Tests that focusing a url bar starts a zero suggest request. | 198 * Tests that focusing a url bar starts a zero suggest request. |
| 174 */ | 199 */ |
| 200 @Test |
| 175 @MediumTest | 201 @MediumTest |
| 176 @Feature({"Omnibox"}) | 202 @Feature({"Omnibox"}) |
| 177 @RetryOnFailure | 203 @RetryOnFailure |
| 178 public void testRequestZeroSuggestAfterDelete() throws InterruptedException
{ | 204 public void testRequestZeroSuggestAfterDelete() throws InterruptedException
{ |
| 179 final LocationBarLayout locationBar = | 205 final LocationBarLayout locationBar = |
| 180 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); | 206 (LocationBarLayout) mActivityTestRule.getActivity().findViewById
(R.id.location_bar); |
| 181 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); | 207 final UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewB
yId(R.id.url_bar); |
| 182 final ImageButton deleteButton = (ImageButton) getActivity().findViewByI
d( | 208 final ImageButton deleteButton = |
| 183 R.id.delete_button); | 209 (ImageButton) mActivityTestRule.getActivity().findViewById(R.id.
delete_button); |
| 184 | 210 |
| 185 final OnSuggestionsReceivedListener emptySuggestionListener = | 211 final OnSuggestionsReceivedListener emptySuggestionListener = |
| 186 new OnSuggestionsReceivedListener() { | 212 new OnSuggestionsReceivedListener() { |
| 187 @Override | 213 @Override |
| 188 public void onSuggestionsReceived( | 214 public void onSuggestionsReceived( |
| 189 List<OmniboxSuggestion> suggestions, String inlineAu
tocompleteText) { | 215 List<OmniboxSuggestion> suggestions, String inlineAu
tocompleteText) { |
| 190 } | 216 } |
| 191 }; | 217 }; |
| 192 | 218 |
| 193 final TestAutocompleteController controller = new TestAutocompleteContro
ller( | 219 final TestAutocompleteController controller = new TestAutocompleteContro
ller( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 207 new Criteria("Should have drawn the delete button") { | 233 new Criteria("Should have drawn the delete button") { |
| 208 @Override | 234 @Override |
| 209 public boolean isSatisfied() { | 235 public boolean isSatisfied() { |
| 210 return deleteButton.getWidth() > 0; | 236 return deleteButton.getWidth() > 0; |
| 211 } | 237 } |
| 212 }); | 238 }); |
| 213 | 239 |
| 214 // The click view below ends up clicking on the menu button underneath t
he delete button | 240 // The click view below ends up clicking on the menu button underneath t
he delete button |
| 215 // for some time after the delete button appears. Wait for UI to settle
down before | 241 // for some time after the delete button appears. Wait for UI to settle
down before |
| 216 // clicking. | 242 // clicking. |
| 217 UiUtils.settleDownUI(getInstrumentation()); | 243 UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation()); |
| 218 | 244 |
| 219 singleClickView(deleteButton); | 245 TouchCommon.singleClickView(deleteButton); |
| 220 | 246 |
| 221 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable
<Integer>() { | 247 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable
<Integer>() { |
| 222 @Override | 248 @Override |
| 223 public Integer call() { | 249 public Integer call() { |
| 224 return controller.numZeroSuggestRequests(); | 250 return controller.numZeroSuggestRequests(); |
| 225 } | 251 } |
| 226 })); | 252 })); |
| 227 } | 253 } |
| 228 | 254 |
| 255 @Test |
| 229 @MediumTest | 256 @MediumTest |
| 230 @Feature({"Omnibox"}) | 257 @Feature({"Omnibox"}) |
| 231 public void testRequestZeroSuggestTypeAndBackspace() throws InterruptedExcep
tion { | 258 public void testRequestZeroSuggestTypeAndBackspace() throws InterruptedExcep
tion { |
| 232 final LocationBarLayout locationBar = | 259 final LocationBarLayout locationBar = |
| 233 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); | 260 (LocationBarLayout) mActivityTestRule.getActivity().findViewById
(R.id.location_bar); |
| 234 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); | 261 final UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewB
yId(R.id.url_bar); |
| 235 | 262 |
| 236 final OnSuggestionsReceivedListener emptySuggestionListener = | 263 final OnSuggestionsReceivedListener emptySuggestionListener = |
| 237 new OnSuggestionsReceivedListener() { | 264 new OnSuggestionsReceivedListener() { |
| 238 @Override | 265 @Override |
| 239 public void onSuggestionsReceived(List<OmniboxSuggestion> su
ggestions, | 266 public void onSuggestionsReceived(List<OmniboxSuggestion> su
ggestions, |
| 240 String inlineAutocompleteText) { | 267 String inlineAutocompleteText) { |
| 241 } | 268 } |
| 242 }; | 269 }; |
| 243 | 270 |
| 244 final TestAutocompleteController controller = new TestAutocompleteContro
ller( | 271 final TestAutocompleteController controller = new TestAutocompleteContro
ller( |
| 245 locationBar, emptySuggestionListener, | 272 locationBar, emptySuggestionListener, |
| 246 new HashMap<String, List<SuggestionsResult>>()); | 273 new HashMap<String, List<SuggestionsResult>>()); |
| 247 | 274 |
| 248 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 275 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 249 | 276 |
| 250 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 277 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 251 @Override | 278 @Override |
| 252 public void run() { | 279 public void run() { |
| 253 locationBar.setAutocompleteController(controller); | 280 locationBar.setAutocompleteController(controller); |
| 254 urlBar.setText("g"); | 281 urlBar.setText("g"); |
| 255 urlBar.setSelection(1); | 282 urlBar.setSelection(1); |
| 256 } | 283 } |
| 257 }); | 284 }); |
| 258 | 285 |
| 259 assertEquals("No calls to zero suggest yet", 0, controller.numZeroSugges
tRequests()); | 286 Assert.assertEquals("No calls to zero suggest yet", 0, controller.numZer
oSuggestRequests()); |
| 260 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEvent.KEYCO
DE_DEL); | 287 KeyUtils.singleKeyEventView( |
| 288 InstrumentationRegistry.getInstrumentation(), urlBar, KeyEvent.K
EYCODE_DEL); |
| 261 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable
<Integer>() { | 289 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable
<Integer>() { |
| 262 @Override | 290 @Override |
| 263 public Integer call() { | 291 public Integer call() { |
| 264 return controller.numZeroSuggestRequests(); | 292 return controller.numZeroSuggestRequests(); |
| 265 } | 293 } |
| 266 })); | 294 })); |
| 267 } | 295 } |
| 268 | 296 |
| 269 // Sanity check that no text is displayed in the omnibox when on the NTP pag
e and that the hint | 297 // Sanity check that no text is displayed in the omnibox when on the NTP pag
e and that the hint |
| 270 // text is correct. | 298 // text is correct. |
| 299 @Test |
| 271 @MediumTest | 300 @MediumTest |
| 272 @Feature({"Omnibox"}) | 301 @Feature({"Omnibox"}) |
| 273 @RetryOnFailure | 302 @RetryOnFailure |
| 274 public void testDefaultText() throws InterruptedException { | 303 public void testDefaultText() throws InterruptedException { |
| 275 startMainActivityFromLauncher(); | 304 mActivityTestRule.startMainActivityFromLauncher(); |
| 276 | 305 |
| 277 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); | 306 final UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewB
yId(R.id.url_bar); |
| 278 | 307 |
| 279 // Omnibox on NTP shows the hint text. | 308 // Omnibox on NTP shows the hint text. |
| 280 assertNotNull(urlBar); | 309 Assert.assertNotNull(urlBar); |
| 281 assertEquals("Location bar has text.", "", urlBar.getText().toString()); | 310 Assert.assertEquals("Location bar has text.", "", urlBar.getText().toStr
ing()); |
| 282 assertEquals("Location bar has incorrect hint.", | 311 Assert.assertEquals("Location bar has incorrect hint.", |
| 283 getActivity().getResources().getString(R.string.search_or_type_u
rl), | 312 mActivityTestRule.getActivity().getResources().getString( |
| 313 R.string.search_or_type_url), |
| 284 urlBar.getHint().toString()); | 314 urlBar.getHint().toString()); |
| 285 | 315 |
| 286 // Type something in the omnibox. | 316 // Type something in the omnibox. |
| 287 // Note that the TextView does not provide a way to test if the hint is
showing, the API | 317 // Note that the TextView does not provide a way to test if the hint is
showing, the API |
| 288 // documentation simply says it shows when the text is empty. | 318 // documentation simply says it shows when the text is empty. |
| 289 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 319 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 290 @Override | 320 @Override |
| 291 public void run() { | 321 public void run() { |
| 292 urlBar.requestFocus(); | 322 urlBar.requestFocus(); |
| 293 urlBar.setText("G"); | 323 urlBar.setText("G"); |
| 294 } | 324 } |
| 295 }); | 325 }); |
| 296 assertEquals("Location bar should have text.", "G", urlBar.getText().toS
tring()); | 326 Assert.assertEquals("Location bar should have text.", "G", urlBar.getTex
t().toString()); |
| 297 } | 327 } |
| 298 | 328 |
| 329 @Test |
| 299 @MediumTest | 330 @MediumTest |
| 300 @Feature({"Omnibox", "Main"}) | 331 @Feature({"Omnibox", "Main"}) |
| 301 @RetryOnFailure | 332 @RetryOnFailure |
| 302 public void testAutoCompleteAndCorrectionLandscape() throws ExecutionExcepti
on, | 333 public void testAutoCompleteAndCorrectionLandscape() |
| 303 InterruptedException { | 334 throws ExecutionException, InterruptedException { |
| 304 // Default orientation for tablets is landscape. Default for phones is p
ortrait. | 335 // Default orientation for tablets is landscape. Default for phones is p
ortrait. |
| 305 int requestedOrientation = 1; | 336 int requestedOrientation = 1; |
| 306 if (DeviceFormFactor.isTablet(getActivity())) { | 337 if (DeviceFormFactor.isTablet(mActivityTestRule.getActivity())) { |
| 307 requestedOrientation = 0; | 338 requestedOrientation = 0; |
| 308 } | 339 } |
| 309 doTestAutoCompleteAndCorrectionForOrientation(requestedOrientation); | 340 doTestAutoCompleteAndCorrectionForOrientation(requestedOrientation); |
| 310 } | 341 } |
| 311 | 342 |
| 343 @Test |
| 312 @MediumTest | 344 @MediumTest |
| 313 @Feature({"Omnibox", "Main"}) | 345 @Feature({"Omnibox", "Main"}) |
| 314 @RetryOnFailure | 346 @RetryOnFailure |
| 315 public void testAutoCompleteAndCorrectionPortrait() throws ExecutionExceptio
n, | 347 public void testAutoCompleteAndCorrectionPortrait() |
| 316 InterruptedException { | 348 throws ExecutionException, InterruptedException { |
| 317 // Default orientation for tablets is landscape. Default for phones is p
ortrait. | 349 // Default orientation for tablets is landscape. Default for phones is p
ortrait. |
| 318 int requestedOrientation = 0; | 350 int requestedOrientation = 0; |
| 319 if (DeviceFormFactor.isTablet(getActivity())) { | 351 if (DeviceFormFactor.isTablet(mActivityTestRule.getActivity())) { |
| 320 requestedOrientation = 1; | 352 requestedOrientation = 1; |
| 321 } | 353 } |
| 322 doTestAutoCompleteAndCorrectionForOrientation(requestedOrientation); | 354 doTestAutoCompleteAndCorrectionForOrientation(requestedOrientation); |
| 323 } | 355 } |
| 324 | 356 |
| 325 private void doTestAutoCompleteAndCorrectionForOrientation( | 357 private void doTestAutoCompleteAndCorrectionForOrientation( |
| 326 int orientation) throws ExecutionException, InterruptedException { | 358 int orientation) throws ExecutionException, InterruptedException { |
| 327 getActivity().setRequestedOrientation(orientation); | 359 mActivityTestRule.getActivity().setRequestedOrientation(orientation); |
| 328 UiUtils.settleDownUI(getInstrumentation()); | 360 UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation()); |
| 329 | 361 |
| 330 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( | 362 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 331 new TestSuggestionResultsBuilder() | 363 new TestSuggestionResultsBuilder() |
| 332 .setTextShownFor("wiki") | 364 .setTextShownFor("wiki") |
| 333 .addSuggestions(new SuggestionsResultBuilder() | 365 .addSuggestions(new SuggestionsResultBuilder() |
| 334 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_SUGGEST, | 366 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_SUGGEST, |
| 335 "wikipedia", null) | 367 "wikipedia", null) |
| 336 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_SUGGEST, | 368 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_SUGGEST, |
| 337 "wiki", null) | 369 "wiki", null) |
| 338 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_SUGGEST, | 370 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_SUGGEST, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 354 "misspelled", null) | 386 "misspelled", null) |
| 355 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_SUGGEST, | 387 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_SUGGEST, |
| 356 "misspelled words", null) | 388 "misspelled words", null) |
| 357 .setAutocompleteText("")) | 389 .setAutocompleteText("")) |
| 358 ); | 390 ); |
| 359 checkAutocompleteText(suggestionsMap, "wiki", "wikipedia", 4, 9); | 391 checkAutocompleteText(suggestionsMap, "wiki", "wikipedia", 4, 9); |
| 360 checkAutocompleteText(suggestionsMap, "onomatop", "onomatopoeia", 8, 12)
; | 392 checkAutocompleteText(suggestionsMap, "onomatop", "onomatopoeia", 8, 12)
; |
| 361 checkAutocompleteText(suggestionsMap, "mispellled", "mispellled", 10, 10
); | 393 checkAutocompleteText(suggestionsMap, "mispellled", "mispellled", 10, 10
); |
| 362 } | 394 } |
| 363 | 395 |
| 396 @Test |
| 364 @MediumTest | 397 @MediumTest |
| 365 @Feature({"Omnibox"}) | 398 @Feature({"Omnibox"}) |
| 366 @RetryOnFailure | 399 @RetryOnFailure |
| 367 public void testDuplicateAutocompleteTextResults() | 400 public void testDuplicateAutocompleteTextResults() |
| 368 throws InterruptedException, ExecutionException { | 401 throws InterruptedException, ExecutionException { |
| 369 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( | 402 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 370 new TestSuggestionResultsBuilder() | 403 new TestSuggestionResultsBuilder() |
| 371 .setTextShownFor("test") | 404 .setTextShownFor("test") |
| 372 .addSuggestions(new SuggestionsResultBuilder() | 405 .addSuggestions(new SuggestionsResultBuilder() |
| 373 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 406 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 374 "test", null) | 407 "test", null) |
| 375 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 408 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 376 "testing", null) | 409 "testing", null) |
| 377 .setAutocompleteText("ing")) | 410 .setAutocompleteText("ing")) |
| 378 .addSuggestions(new SuggestionsResultBuilder() | 411 .addSuggestions(new SuggestionsResultBuilder() |
| 379 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 412 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 380 "test", null) | 413 "test", null) |
| 381 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 414 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 382 "testz", null) | 415 "testz", null) |
| 383 .setAutocompleteText("ing")) | 416 .setAutocompleteText("ing")) |
| 384 .addSuggestions(new SuggestionsResultBuilder() | 417 .addSuggestions(new SuggestionsResultBuilder() |
| 385 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 418 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 386 "test", null) | 419 "test", null) |
| 387 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 420 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 388 "testblarg", null) | 421 "testblarg", null) |
| 389 .setAutocompleteText("ing"))); | 422 .setAutocompleteText("ing"))); |
| 390 checkAutocompleteText(suggestionsMap, "test", "testing", 4, 7); | 423 checkAutocompleteText(suggestionsMap, "test", "testing", 4, 7); |
| 391 } | 424 } |
| 392 | 425 |
| 426 @Test |
| 393 @MediumTest | 427 @MediumTest |
| 394 @Feature({"Omnibox"}) | 428 @Feature({"Omnibox"}) |
| 395 @RetryOnFailure | 429 @RetryOnFailure |
| 396 public void testGrowingAutocompleteTextResults() | 430 public void testGrowingAutocompleteTextResults() |
| 397 throws InterruptedException, ExecutionException { | 431 throws InterruptedException, ExecutionException { |
| 398 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( | 432 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 399 new TestSuggestionResultsBuilder() | 433 new TestSuggestionResultsBuilder() |
| 400 .setTextShownFor("test") | 434 .setTextShownFor("test") |
| 401 .addSuggestions(new SuggestionsResultBuilder() | 435 .addSuggestions(new SuggestionsResultBuilder() |
| 402 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 436 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 403 "test", null) | 437 "test", null) |
| 404 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 438 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 405 "testing", null) | 439 "testing", null) |
| 406 .setAutocompleteText("i")) | 440 .setAutocompleteText("i")) |
| 407 .addSuggestions(new SuggestionsResultBuilder() | 441 .addSuggestions(new SuggestionsResultBuilder() |
| 408 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 442 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 409 "test", null) | 443 "test", null) |
| 410 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 444 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 411 "testz", null) | 445 "testz", null) |
| 412 .setAutocompleteText("in")) | 446 .setAutocompleteText("in")) |
| 413 .addSuggestions(new SuggestionsResultBuilder() | 447 .addSuggestions(new SuggestionsResultBuilder() |
| 414 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 448 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 415 "test", null) | 449 "test", null) |
| 416 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 450 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 417 "testblarg", null) | 451 "testblarg", null) |
| 418 .setAutocompleteText("ing for the win"))); | 452 .setAutocompleteText("ing for the win"))); |
| 419 checkAutocompleteText(suggestionsMap, "test", "testing for the win", 4,
19); | 453 checkAutocompleteText(suggestionsMap, "test", "testing for the win", 4,
19); |
| 420 } | 454 } |
| 421 | 455 |
| 456 @Test |
| 422 @MediumTest | 457 @MediumTest |
| 423 @Feature({"Omnibox"}) | 458 @Feature({"Omnibox"}) |
| 424 @RetryOnFailure | 459 @RetryOnFailure |
| 425 public void testShrinkingAutocompleteTextResults() | 460 public void testShrinkingAutocompleteTextResults() |
| 426 throws InterruptedException, ExecutionException { | 461 throws InterruptedException, ExecutionException { |
| 427 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( | 462 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 428 new TestSuggestionResultsBuilder() | 463 new TestSuggestionResultsBuilder() |
| 429 .setTextShownFor("test") | 464 .setTextShownFor("test") |
| 430 .addSuggestions(new SuggestionsResultBuilder() | 465 .addSuggestions(new SuggestionsResultBuilder() |
| 431 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 466 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 446 "testblarg", null) | 481 "testblarg", null) |
| 447 .setAutocompleteText("ingz"))); | 482 .setAutocompleteText("ingz"))); |
| 448 checkAutocompleteText(suggestionsMap, "test", "testingz", 4, 8); | 483 checkAutocompleteText(suggestionsMap, "test", "testingz", 4, 8); |
| 449 } | 484 } |
| 450 | 485 |
| 451 private void checkAutocompleteText( | 486 private void checkAutocompleteText( |
| 452 Map<String, List<SuggestionsResult>> suggestionsMap, | 487 Map<String, List<SuggestionsResult>> suggestionsMap, |
| 453 final String textToType, final String expectedAutocompleteText, | 488 final String textToType, final String expectedAutocompleteText, |
| 454 final int expectedAutocompleteStart, final int expectedAutocompleteE
nd) | 489 final int expectedAutocompleteStart, final int expectedAutocompleteE
nd) |
| 455 throws InterruptedException, ExecutionException { | 490 throws InterruptedException, ExecutionException { |
| 456 | 491 final TextView urlBarView = |
| 457 final TextView urlBarView = (TextView) getActivity().findViewById(R.id.u
rl_bar); | 492 (TextView) mActivityTestRule.getActivity().findViewById(R.id.url
_bar); |
| 458 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 493 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 459 @Override | 494 @Override |
| 460 public void run() { | 495 public void run() { |
| 461 urlBarView.requestFocus(); | 496 urlBarView.requestFocus(); |
| 462 urlBarView.setText(""); | 497 urlBarView.setText(""); |
| 463 } | 498 } |
| 464 }); | 499 }); |
| 465 | 500 |
| 466 final LocationBarLayout locationBar = | 501 final LocationBarLayout locationBar = |
| 467 ((LocationBarLayout) getActivity().findViewById(R.id.location_ba
r)); | 502 ((LocationBarLayout) mActivityTestRule.getActivity().findViewByI
d( |
| 503 R.id.location_bar)); |
| 468 | 504 |
| 469 final Object suggestionsProcessedSignal = new Object(); | 505 final Object suggestionsProcessedSignal = new Object(); |
| 470 final AtomicInteger suggestionsLeft = new AtomicInteger( | 506 final AtomicInteger suggestionsLeft = new AtomicInteger( |
| 471 suggestionsMap.get(textToType).size()); | 507 suggestionsMap.get(textToType).size()); |
| 472 OnSuggestionsReceivedListener suggestionsListener = new OnSuggestionsRec
eivedListener() { | 508 OnSuggestionsReceivedListener suggestionsListener = new OnSuggestionsRec
eivedListener() { |
| 473 @Override | 509 @Override |
| 474 public void onSuggestionsReceived( | 510 public void onSuggestionsReceived( |
| 475 List<OmniboxSuggestion> suggestions, | 511 List<OmniboxSuggestion> suggestions, |
| 476 String inlineAutocompleteText) { | 512 String inlineAutocompleteText) { |
| 477 locationBar.onSuggestionsReceived(suggestions, inlineAutocomplet
eText); | 513 locationBar.onSuggestionsReceived(suggestions, inlineAutocomplet
eText); |
| 478 synchronized (suggestionsProcessedSignal) { | 514 synchronized (suggestionsProcessedSignal) { |
| 479 int remaining = suggestionsLeft.decrementAndGet(); | 515 int remaining = suggestionsLeft.decrementAndGet(); |
| 480 if (remaining == 0) { | 516 if (remaining == 0) { |
| 481 suggestionsProcessedSignal.notifyAll(); | 517 suggestionsProcessedSignal.notifyAll(); |
| 482 } else if (remaining < 0) { | 518 } else if (remaining < 0) { |
| 483 fail("Unexpected suggestions received"); | 519 Assert.fail("Unexpected suggestions received"); |
| 484 } | 520 } |
| 485 } | 521 } |
| 486 } | 522 } |
| 487 }; | 523 }; |
| 488 final TestAutocompleteController controller = new TestAutocompleteContro
ller( | 524 final TestAutocompleteController controller = new TestAutocompleteContro
ller( |
| 489 locationBar, suggestionsListener, suggestionsMap); | 525 locationBar, suggestionsListener, suggestionsMap); |
| 490 | 526 |
| 491 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 527 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 492 @Override | 528 @Override |
| 493 public void run() { | 529 public void run() { |
| 494 locationBar.setAutocompleteController(controller); | 530 locationBar.setAutocompleteController(controller); |
| 495 } | 531 } |
| 496 }); | 532 }); |
| 497 | 533 |
| 498 KeyUtils.typeTextIntoView(getInstrumentation(), urlBarView, textToType); | 534 KeyUtils.typeTextIntoView( |
| 535 InstrumentationRegistry.getInstrumentation(), urlBarView, textTo
Type); |
| 499 | 536 |
| 500 synchronized (suggestionsProcessedSignal) { | 537 synchronized (suggestionsProcessedSignal) { |
| 501 long endTime = SystemClock.uptimeMillis() + 3000; | 538 long endTime = SystemClock.uptimeMillis() + 3000; |
| 502 while (suggestionsLeft.get() != 0) { | 539 while (suggestionsLeft.get() != 0) { |
| 503 long waitTime = endTime - SystemClock.uptimeMillis(); | 540 long waitTime = endTime - SystemClock.uptimeMillis(); |
| 504 if (waitTime <= 0) break; | 541 if (waitTime <= 0) break; |
| 505 suggestionsProcessedSignal.wait(waitTime); | 542 suggestionsProcessedSignal.wait(waitTime); |
| 506 } | 543 } |
| 507 } | 544 } |
| 508 | 545 |
| 509 CharSequence urlText = ThreadUtils.runOnUiThreadBlocking(new Callable<Ch
arSequence>() { | 546 CharSequence urlText = ThreadUtils.runOnUiThreadBlocking(new Callable<Ch
arSequence>() { |
| 510 @Override | 547 @Override |
| 511 public CharSequence call() throws Exception { | 548 public CharSequence call() throws Exception { |
| 512 return urlBarView.getText(); | 549 return urlBarView.getText(); |
| 513 } | 550 } |
| 514 }); | 551 }); |
| 515 assertEquals("URL Bar text not autocompleted as expected.", | 552 Assert.assertEquals("URL Bar text not autocompleted as expected.", expec
tedAutocompleteText, |
| 516 expectedAutocompleteText, urlText.toString()); | 553 urlText.toString()); |
| 517 assertEquals(expectedAutocompleteStart, Selection.getSelectionStart(urlT
ext)); | 554 Assert.assertEquals(expectedAutocompleteStart, Selection.getSelectionSta
rt(urlText)); |
| 518 assertEquals(expectedAutocompleteEnd, Selection.getSelectionEnd(urlText)
); | 555 Assert.assertEquals(expectedAutocompleteEnd, Selection.getSelectionEnd(u
rlText)); |
| 519 } | 556 } |
| 520 | 557 |
| 521 /** | 558 /** |
| 522 * The following test is a basic way to assess how much instant slows down t
yping in the | 559 * The following test is a basic way to assess how much instant slows down t
yping in the |
| 523 * omnibox. It is meant to be run manually for investigation purposes. | 560 * omnibox. It is meant to be run manually for investigation purposes. |
| 524 * When instant was enabled for all suggestions (including searched), I woul
d get a 40% increase | 561 * When instant was enabled for all suggestions (including searched), I woul
d get a 40% increase |
| 525 * in the average time on this test. With instant off, it was almost identic
al. | 562 * in the average time on this test. With instant off, it was almost identic
al. |
| 526 * Marking the test disabled so it is not picked up by our test runner, as i
t is supposed to be | 563 * Marking the test disabled so it is not picked up by our test runner, as i
t is supposed to be |
| 527 * run manually. | 564 * run manually. |
| 528 */ | 565 */ |
| 529 public void manualTestTypingPerformance() throws InterruptedException { | 566 public void manualTestTypingPerformance() throws InterruptedException { |
| 530 final String text = "searching for pizza"; | 567 final String text = "searching for pizza"; |
| 531 // Type 10 times something on the omnibox and get the average time with
and without instant. | 568 // Type 10 times something on the omnibox and get the average time with
and without instant. |
| 532 long instantAverage = 0; | 569 long instantAverage = 0; |
| 533 long noInstantAverage = 0; | 570 long noInstantAverage = 0; |
| 534 | 571 |
| 535 for (int i = 0; i < 2; ++i) { | 572 for (int i = 0; i < 2; ++i) { |
| 536 boolean instantOn = (i == 1); | 573 boolean instantOn = (i == 1); |
| 537 setNetworkPredictionEnabled(instantOn); | 574 mActivityTestRule.setNetworkPredictionEnabled(instantOn); |
| 538 | 575 |
| 539 for (int j = 0; j < 10; ++j) { | 576 for (int j = 0; j < 10; ++j) { |
| 540 long before = System.currentTimeMillis(); | 577 long before = System.currentTimeMillis(); |
| 541 typeInOmnibox(text, true); | 578 mActivityTestRule.typeInOmnibox(text, true); |
| 542 if (instantOn) { | 579 if (instantOn) { |
| 543 instantAverage += System.currentTimeMillis() - before; | 580 instantAverage += System.currentTimeMillis() - before; |
| 544 } else { | 581 } else { |
| 545 noInstantAverage += System.currentTimeMillis() - before; | 582 noInstantAverage += System.currentTimeMillis() - before; |
| 546 } | 583 } |
| 547 clearUrlBar(); | 584 clearUrlBar(); |
| 548 getInstrumentation().waitForIdleSync(); | 585 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 549 } | 586 } |
| 550 } | 587 } |
| 551 instantAverage /= 10; | 588 instantAverage /= 10; |
| 552 noInstantAverage /= 10; | 589 noInstantAverage /= 10; |
| 553 System.err.println("****************************************************
**************"); | 590 System.err.println("****************************************************
**************"); |
| 554 System.err.println("**** Instant average=" + instantAverage); | 591 System.err.println("**** Instant average=" + instantAverage); |
| 555 System.err.println("**** No instant average=" + noInstantAverage); | 592 System.err.println("**** No instant average=" + noInstantAverage); |
| 556 System.err.println("****************************************************
**************"); | 593 System.err.println("****************************************************
**************"); |
| 557 } | 594 } |
| 558 | 595 |
| 559 /** | 596 /** |
| 560 * Test to verify security-icon "lock or globe" on visiting http and secured
Urls. | 597 * Test to verify security-icon "lock or globe" on visiting http and secured
Urls. |
| 561 * @EnormousTest | 598 * @EnormousTest |
| 562 */ | 599 */ |
| 600 @Test |
| 563 @FlakyTest(message = "crbug.com/414353") | 601 @FlakyTest(message = "crbug.com/414353") |
| 564 public void testSecurityIcon() throws InterruptedException { | 602 public void testSecurityIcon() throws InterruptedException { |
| 565 EmbeddedTestServer testServer = EmbeddedTestServer.createAndStartServer( | 603 EmbeddedTestServer testServer = EmbeddedTestServer.createAndStartServer( |
| 566 getInstrumentation().getContext()); | 604 InstrumentationRegistry.getInstrumentation().getContext()); |
| 567 try { | 605 try { |
| 568 final String testUrl = testServer.getURL("/chrome/test/data/android/
omnibox/one.html"); | 606 final String testUrl = testServer.getURL("/chrome/test/data/android/
omnibox/one.html"); |
| 569 final String securedExternalUrl = "https://www.google.com"; | 607 final String securedExternalUrl = "https://www.google.com"; |
| 570 | 608 |
| 571 ImageView navigationButton = (ImageView) | 609 ImageView navigationButton = (ImageView) mActivityTestRule.getActivi
ty().findViewById( |
| 572 getActivity().findViewById(R.id.navigation_button); | 610 R.id.navigation_button); |
| 573 ImageButton securityButton = (ImageButton) | 611 ImageButton securityButton = (ImageButton) mActivityTestRule.getActi
vity().findViewById( |
| 574 getActivity().findViewById(R.id.security_button); | 612 R.id.security_button); |
| 575 | 613 |
| 576 loadUrl(testUrl); | 614 mActivityTestRule.loadUrl(testUrl); |
| 577 final LocationBarLayout locationBar = | 615 final LocationBarLayout locationBar = |
| 578 (LocationBarLayout) getActivity().findViewById(R.id.location
_bar); | 616 (LocationBarLayout) mActivityTestRule.getActivity().findView
ById( |
| 617 R.id.location_bar); |
| 579 boolean securityIcon = locationBar.isSecurityButtonShown(); | 618 boolean securityIcon = locationBar.isSecurityButtonShown(); |
| 580 assertFalse("Omnibox should not have a Security icon", securityIcon)
; | 619 Assert.assertFalse("Omnibox should not have a Security icon", securi
tyIcon); |
| 581 assertEquals("navigation_button with wrong resource-id", | 620 Assert.assertEquals("navigation_button with wrong resource-id", R.id
.navigation_button, |
| 582 R.id.navigation_button, navigationButton.getId()); | 621 navigationButton.getId()); |
| 583 assertTrue(navigationButton.isShown()); | 622 Assert.assertTrue(navigationButton.isShown()); |
| 584 assertFalse(securityButton.isShown()); | 623 Assert.assertFalse(securityButton.isShown()); |
| 585 | 624 |
| 586 loadUrl(securedExternalUrl); | 625 mActivityTestRule.loadUrl(securedExternalUrl); |
| 587 securityIcon = locationBar.isSecurityButtonShown(); | 626 securityIcon = locationBar.isSecurityButtonShown(); |
| 588 assertTrue("Omnibox should have a Security icon", securityIcon); | 627 Assert.assertTrue("Omnibox should have a Security icon", securityIco
n); |
| 589 assertEquals("security_button with wrong resource-id", | 628 Assert.assertEquals("security_button with wrong resource-id", R.id.s
ecurity_button, |
| 590 R.id.security_button, securityButton.getId()); | 629 securityButton.getId()); |
| 591 assertTrue(securityButton.isShown()); | 630 Assert.assertTrue(securityButton.isShown()); |
| 592 assertFalse(navigationButton.isShown()); | 631 Assert.assertFalse(navigationButton.isShown()); |
| 593 } finally { | 632 } finally { |
| 594 testServer.stopAndDestroyServer(); | 633 testServer.stopAndDestroyServer(); |
| 595 } | 634 } |
| 596 } | 635 } |
| 597 | 636 |
| 637 @Test |
| 598 @SmallTest | 638 @SmallTest |
| 599 @RetryOnFailure | 639 @RetryOnFailure |
| 600 public void testSplitPathFromUrlDisplayText() { | 640 public void testSplitPathFromUrlDisplayText() { |
| 601 verifySplitUrlAndPath("", null, LocationBarLayout.splitPathFromUrlDispla
yText("")); | 641 verifySplitUrlAndPath("", null, LocationBarLayout.splitPathFromUrlDispla
yText("")); |
| 602 verifySplitUrlAndPath( | 642 verifySplitUrlAndPath( |
| 603 "https:", null, LocationBarLayout.splitPathFromUrlDisplayText("h
ttps:")); | 643 "https:", null, LocationBarLayout.splitPathFromUrlDisplayText("h
ttps:")); |
| 604 verifySplitUrlAndPath("about:blank", null, | 644 verifySplitUrlAndPath("about:blank", null, |
| 605 LocationBarLayout.splitPathFromUrlDisplayText("about:blank")); | 645 LocationBarLayout.splitPathFromUrlDisplayText("about:blank")); |
| 606 | 646 |
| 607 verifySplitUrlAndPath("chrome://flags", null, | 647 verifySplitUrlAndPath("chrome://flags", null, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 LocationBarLayout.splitPathFromUrlDisplayText("file:///dev/blah"
)); | 682 LocationBarLayout.splitPathFromUrlDisplayText("file:///dev/blah"
)); |
| 643 verifySplitUrlAndPath("javascript:window.alert('hello');", null, | 683 verifySplitUrlAndPath("javascript:window.alert('hello');", null, |
| 644 LocationBarLayout.splitPathFromUrlDisplayText("javascript:window
.alert('hello');")); | 684 LocationBarLayout.splitPathFromUrlDisplayText("javascript:window
.alert('hello');")); |
| 645 verifySplitUrlAndPath("data:text/html;charset=utf-8,Page%201", null, | 685 verifySplitUrlAndPath("data:text/html;charset=utf-8,Page%201", null, |
| 646 LocationBarLayout.splitPathFromUrlDisplayText( | 686 LocationBarLayout.splitPathFromUrlDisplayText( |
| 647 "data:text/html;charset=utf-8,Page%201")); | 687 "data:text/html;charset=utf-8,Page%201")); |
| 648 } | 688 } |
| 649 | 689 |
| 650 private void verifySplitUrlAndPath( | 690 private void verifySplitUrlAndPath( |
| 651 String expectedPrePath, String expectedPostPath, Pair<String, String
> actualValues) { | 691 String expectedPrePath, String expectedPostPath, Pair<String, String
> actualValues) { |
| 652 assertEquals(expectedPrePath, actualValues.first); | 692 Assert.assertEquals(expectedPrePath, actualValues.first); |
| 653 assertEquals(expectedPostPath, actualValues.second); | 693 Assert.assertEquals(expectedPostPath, actualValues.second); |
| 654 } | 694 } |
| 655 | 695 |
| 696 @Test |
| 656 @MediumTest | 697 @MediumTest |
| 657 @Feature({"Omnibox"}) | 698 @Feature({"Omnibox"}) |
| 658 @RetryOnFailure | 699 @RetryOnFailure |
| 659 @MinAndroidSdkLevel(Build.VERSION_CODES.JELLY_BEAN_MR1) | 700 @MinAndroidSdkLevel(Build.VERSION_CODES.JELLY_BEAN_MR1) |
| 660 public void testSuggestionDirectionSwitching() throws InterruptedException { | 701 public void testSuggestionDirectionSwitching() throws InterruptedException { |
| 661 final TextView urlBarView = (TextView) getActivity().findViewById(R.id.u
rl_bar); | 702 final TextView urlBarView = |
| 703 (TextView) mActivityTestRule.getActivity().findViewById(R.id.url
_bar); |
| 662 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 704 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 663 @Override | 705 @Override |
| 664 public void run() { | 706 public void run() { |
| 665 urlBarView.requestFocus(); | 707 urlBarView.requestFocus(); |
| 666 urlBarView.setText(""); | 708 urlBarView.setText(""); |
| 667 } | 709 } |
| 668 }); | 710 }); |
| 669 | 711 |
| 670 final LocationBarLayout locationBar = | 712 final LocationBarLayout locationBar = |
| 671 ((LocationBarLayout) getActivity().findViewById(R.id.location_ba
r)); | 713 ((LocationBarLayout) mActivityTestRule.getActivity().findViewByI
d( |
| 714 R.id.location_bar)); |
| 672 | 715 |
| 673 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( | 716 Map<String, List<SuggestionsResult>> suggestionsMap = buildSuggestionMap
( |
| 674 new TestSuggestionResultsBuilder() | 717 new TestSuggestionResultsBuilder() |
| 675 .setTextShownFor("ل") | 718 .setTextShownFor("ل") |
| 676 .addSuggestions(new SuggestionsResultBuilder() | 719 .addSuggestions(new SuggestionsResultBuilder() |
| 677 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 720 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 678 "للك", null) | 721 "للك", null) |
| 679 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 722 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| 680 "www.test.com", null) | 723 "www.test.com", null) |
| 681 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, | 724 .addGeneratedSuggestion(OmniboxSuggestionType.SE
ARCH_HISTORY, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 765 |
| 723 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 766 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 724 @Override | 767 @Override |
| 725 public void run() { | 768 public void run() { |
| 726 urlBarView.setText("f"); | 769 urlBarView.setText("f"); |
| 727 } | 770 } |
| 728 }); | 771 }); |
| 729 verifyOmniboxSuggestionAlignment(locationBar, 3, View.LAYOUT_DIRECTION_L
TR); | 772 verifyOmniboxSuggestionAlignment(locationBar, 3, View.LAYOUT_DIRECTION_L
TR); |
| 730 } | 773 } |
| 731 | 774 |
| 732 private void verifyOmniboxSuggestionAlignment( | 775 private void verifyOmniboxSuggestionAlignment(final LocationBarLayout locati
onBar, |
| 733 final LocationBarLayout locationBar, final int expectedSuggestionCou
nt, | 776 final int expectedSuggestionCount, final int expectedLayoutDirection
) { |
| 734 final int expectedLayoutDirection) throws InterruptedException { | |
| 735 OmniboxTestUtils.waitForOmniboxSuggestions(locationBar, expectedSuggesti
onCount); | 777 OmniboxTestUtils.waitForOmniboxSuggestions(locationBar, expectedSuggesti
onCount); |
| 736 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 778 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 737 @Override | 779 @Override |
| 738 public void run() { | 780 public void run() { |
| 739 OmniboxSuggestionsList suggestionsList = locationBar.getSuggesti
onList(); | 781 OmniboxSuggestionsList suggestionsList = locationBar.getSuggesti
onList(); |
| 740 assertEquals(expectedSuggestionCount, suggestionsList.getChildCo
unt()); | 782 Assert.assertEquals(expectedSuggestionCount, suggestionsList.get
ChildCount()); |
| 741 for (int i = 0; i < suggestionsList.getChildCount(); i++) { | 783 for (int i = 0; i < suggestionsList.getChildCount(); i++) { |
| 742 SuggestionView suggestionView = (SuggestionView) suggestions
List.getChildAt(i); | 784 SuggestionView suggestionView = (SuggestionView) suggestions
List.getChildAt(i); |
| 743 assertEquals( | 785 Assert.assertEquals( |
| 744 String.format( | 786 String.format(Locale.getDefault(), |
| 745 Locale.getDefault(), | 787 "Incorrect layout direction of suggestion at
index %d", i), |
| 746 "Incorrect layout direction of suggestion at
index %d", | 788 expectedLayoutDirection, ViewCompat.getLayoutDirecti
on(suggestionView)); |
| 747 i), | |
| 748 expectedLayoutDirection, | |
| 749 ViewCompat.getLayoutDirection(suggestionView)); | |
| 750 } | 789 } |
| 751 } | 790 } |
| 752 }); | 791 }); |
| 753 } | 792 } |
| 754 | 793 |
| 755 @Override | 794 @Before |
| 756 public void startMainActivity() throws InterruptedException { | 795 public void setUp() throws InterruptedException { |
| 757 if (getName().equals("testsplitPathFromUrlDisplayText") | 796 if (mActivityTestRule.getName().equals("testsplitPathFromUrlDisplayText"
) |
| 758 || getName().equals("testDefaultText")) { | 797 || mActivityTestRule.getName().equals("testDefaultText")) { |
| 759 return; | 798 return; |
| 760 } | 799 } |
| 761 startMainActivityOnBlankPage(); | 800 mActivityTestRule.startMainActivityOnBlankPage(); |
| 762 } | 801 } |
| 763 } | 802 } |
| OLD | NEW |