| Index: chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java
|
| index e068f3e7fc26abf7570c5d1191a05f1da167508f..477a15ec035f30582e541147c33d5c223f8c0573 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java
|
| @@ -11,21 +11,31 @@ import android.content.ClipData;
|
| import android.content.ClipboardManager;
|
| import android.content.Context;
|
| import android.content.Intent;
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.SmallTest;
|
| import android.text.Editable;
|
| import android.text.TextUtils;
|
| import android.view.KeyEvent;
|
| import android.view.inputmethod.BaseInputConnection;
|
|
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.CallbackHelper;
|
| +import org.chromium.base.test.util.CommandLineFlags;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.Restriction;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ChromeActivity;
|
| +import org.chromium.chrome.browser.ChromeSwitches;
|
| import org.chromium.chrome.browser.profiles.Profile;
|
| -import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.chrome.test.util.OmniboxTestUtils;
|
| import org.chromium.chrome.test.util.OmniboxTestUtils.StubAutocompleteController;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| @@ -41,20 +51,23 @@ import java.util.concurrent.atomic.AtomicReference;
|
| /**
|
| * Tests for the URL bar UI component.
|
| */
|
| -public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| -
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| +public class UrlBarTest {
|
| // 9000+ chars of goodness
|
| +
|
| + @Rule
|
| + public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| + new ChromeActivityTestRule<>(ChromeActivity.class);
|
| +
|
| private static final String HUGE_URL =
|
| "data:text/plain,H"
|
| + new String(new char[9000]).replace('\0', 'u')
|
| + "ge!";
|
|
|
| - public UrlBarTest() {
|
| - super(ChromeActivity.class);
|
| - }
|
| -
|
| private UrlBar getUrlBar() {
|
| - return (UrlBar) getActivity().findViewById(R.id.url_bar);
|
| + return (UrlBar) mActivityTestRule.getActivity().findViewById(R.id.url_bar);
|
| }
|
|
|
| private void stubLocationBarAutocomplete() {
|
| @@ -66,7 +79,8 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| @Override
|
| public void run() {
|
| LocationBarLayout locationBar =
|
| - (LocationBarLayout) getActivity().findViewById(R.id.location_bar);
|
| + (LocationBarLayout) mActivityTestRule.getActivity().findViewById(
|
| + R.id.location_bar);
|
| locationBar.cancelPendingAutocompleteStart();
|
| locationBar.setAutocompleteController(controller);
|
| }
|
| @@ -124,9 +138,9 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }
|
| });
|
|
|
| - assertEquals(text, state.textWithoutAutocomplete);
|
| - assertEquals(text, state.textWithAutocomplete);
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertEquals(text, state.textWithoutAutocomplete);
|
| + Assert.assertEquals(text, state.textWithAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
| }
|
|
|
| private void setAutocomplete(final UrlBar urlBar,
|
| @@ -138,9 +152,9 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }
|
| });
|
|
|
| - assertEquals(userText, state.textWithoutAutocomplete);
|
| - assertEquals(userText + autocompleteText, state.textWithAutocomplete);
|
| - assertTrue(state.hasAutocomplete);
|
| + Assert.assertEquals(userText, state.textWithoutAutocomplete);
|
| + Assert.assertEquals(userText + autocompleteText, state.textWithAutocomplete);
|
| + Assert.assertTrue(state.hasAutocomplete);
|
| }
|
|
|
| private AutocompleteState setSelection(
|
| @@ -153,21 +167,23 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testRefocusing() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| UrlBar urlBar = getUrlBar();
|
| - assertFalse(OmniboxTestUtils.doesUrlBarHaveFocus(urlBar));
|
| + Assert.assertFalse(OmniboxTestUtils.doesUrlBarHaveFocus(urlBar));
|
| OmniboxTestUtils.checkUrlBarRefocus(urlBar, 5);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testAutocompleteUpdatedOnSetText() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| stubLocationBarAutocomplete();
|
| final UrlBar urlBar = getUrlBar();
|
| OmniboxTestUtils.toggleUrlBarFocus(urlBar, true);
|
| @@ -186,9 +202,9 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.setText(urlBar.getText().replace(1, 2, "a"));
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| - assertEquals("tasting is fun", state.textWithoutAutocomplete);
|
| - assertEquals("tasting is fun", state.textWithAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
| + Assert.assertEquals("tasting is fun", state.textWithoutAutocomplete);
|
| + Assert.assertEquals("tasting is fun", state.textWithAutocomplete);
|
|
|
| // Replace part of the autocomplete text and see that the autocomplete is cleared.
|
| setTextAndVerifyNoAutocomplete(urlBar, "test");
|
| @@ -199,9 +215,9 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.setText(urlBar.getText().replace(8, 10, "no"));
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| - assertEquals("testing no fun", state.textWithoutAutocomplete);
|
| - assertEquals("testing no fun", state.textWithAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
| + Assert.assertEquals("testing no fun", state.textWithoutAutocomplete);
|
| + Assert.assertEquals("testing no fun", state.textWithAutocomplete);
|
| }
|
|
|
| private void verifySelectionState(
|
| @@ -233,25 +249,25 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| setAutocompleteController(controller);
|
|
|
| AutocompleteState state = setSelection(urlBar, selectionStart, selectionEnd);
|
| - assertEquals("Has autocomplete", expectedHasAutocomplete, state.hasAutocomplete);
|
| - assertEquals("Text w/o Autocomplete",
|
| - expectedTextWithoutAutocomplete, state.textWithoutAutocomplete);
|
| - assertEquals("Text w/ Autocomplete",
|
| - expectedTextWithAutocomplete, state.textWithAutocomplete);
|
| + Assert.assertEquals("Has autocomplete", expectedHasAutocomplete, state.hasAutocomplete);
|
| + Assert.assertEquals("Text w/o Autocomplete", expectedTextWithoutAutocomplete,
|
| + state.textWithoutAutocomplete);
|
| + Assert.assertEquals(
|
| + "Text w/ Autocomplete", expectedTextWithAutocomplete, state.textWithAutocomplete);
|
|
|
| autocompleteHelper.waitForCallback(0);
|
| - assertEquals("Prevent inline autocomplete",
|
| - expectedPreventInline, didPreventInlineAutocomplete.get());
|
| - assertEquals("Requested autocomplete text",
|
| - expectedRequestedAutocompleteText, requestedAutocompleteText.get());
|
| + Assert.assertEquals("Prevent inline autocomplete", expectedPreventInline,
|
| + didPreventInlineAutocomplete.get());
|
| + Assert.assertEquals("Requested autocomplete text", expectedRequestedAutocompleteText,
|
| + requestedAutocompleteText.get());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| - public void testAutocompleteUpdatedOnSelection()
|
| - throws InterruptedException, TimeoutException {
|
| - startMainActivityOnBlankPage();
|
| + public void testAutocompleteUpdatedOnSelection() throws InterruptedException, TimeoutException {
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| stubLocationBarAutocomplete();
|
|
|
| final UrlBar urlBar = getUrlBar();
|
| @@ -298,9 +314,9 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| setTextAndVerifyNoAutocomplete(urlBar, "test");
|
| setAutocomplete(urlBar, "test", "ing is fun");
|
| AutocompleteState state = setSelection(urlBar, 4, 14);
|
| - assertEquals("Has autocomplete", true, state.hasAutocomplete);
|
| - assertEquals("Text w/o Autocomplete", "test", state.textWithoutAutocomplete);
|
| - assertEquals("Text w/ Autocomplete", "testing is fun", state.textWithAutocomplete);
|
| + Assert.assertEquals("Has autocomplete", true, state.hasAutocomplete);
|
| + Assert.assertEquals("Text w/o Autocomplete", "test", state.textWithoutAutocomplete);
|
| + Assert.assertEquals("Text w/ Autocomplete", "testing is fun", state.textWithAutocomplete);
|
| }
|
|
|
| /**
|
| @@ -312,12 +328,13 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| *
|
| * If we assume deletes happen any time the text gets shorter, then this would be prevented.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testAutocompleteAllowedWhenReplacingText()
|
| throws InterruptedException, TimeoutException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
|
|
| final String textToBeEntered = "c";
|
|
|
| @@ -349,20 +366,21 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }
|
| });
|
| autocompleteHelper.waitForCallback(0);
|
| - assertFalse("Inline autocomplete incorrectly prevented.",
|
| - didPreventInlineAutocomplete.get());
|
| + Assert.assertFalse(
|
| + "Inline autocomplete incorrectly prevented.", didPreventInlineAutocomplete.get());
|
| }
|
|
|
| /**
|
| * Ensure that if the user deletes just the inlined autocomplete text that the suggestions are
|
| * regenerated.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testSuggestionsUpdatedWhenDeletingInlineAutocomplete()
|
| throws InterruptedException, TimeoutException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
|
|
| stubLocationBarAutocomplete();
|
| final UrlBar urlBar = getUrlBar();
|
| @@ -386,7 +404,8 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| };
|
| setAutocompleteController(controller);
|
|
|
| - KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEvent.KEYCODE_DEL);
|
| + KeyUtils.singleKeyEventView(
|
| + InstrumentationRegistry.getInstrumentation(), urlBar, KeyEvent.KEYCODE_DEL);
|
|
|
| CriteriaHelper.pollUiThread(Criteria.equals("test", new Callable<String>() {
|
| @Override
|
| @@ -396,15 +415,16 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }));
|
|
|
| autocompleteHelper.waitForCallback(0);
|
| - assertTrue("Inline autocomplete incorrectly allowed after delete.",
|
| + Assert.assertTrue("Inline autocomplete incorrectly allowed after delete.",
|
| didPreventInlineAutocomplete.get());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testSelectionChangesIgnoredInBatchMode() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| stubLocationBarAutocomplete();
|
| final UrlBar urlBar = getUrlBar();
|
| OmniboxTestUtils.toggleUrlBarFocus(urlBar, true);
|
| @@ -420,9 +440,9 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| });
|
| // Ensure the autocomplete is not modified if in batch mode.
|
| AutocompleteState state = setSelection(urlBar, 1, 1);
|
| - assertTrue(state.hasAutocomplete);
|
| - assertEquals("test", state.textWithoutAutocomplete);
|
| - assertEquals("testing is fun", state.textWithAutocomplete);
|
| + Assert.assertTrue(state.hasAutocomplete);
|
| + Assert.assertEquals("test", state.textWithoutAutocomplete);
|
| + Assert.assertEquals("testing is fun", state.textWithAutocomplete);
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| @@ -433,16 +453,17 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| // Ensure that after batch mode has ended that the autocomplete is cleared due to the
|
| // invalid selection range.
|
| state = getAutocompleteState(urlBar, null);
|
| - assertFalse(state.hasAutocomplete);
|
| - assertEquals("test", state.textWithoutAutocomplete);
|
| - assertEquals("test", state.textWithAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
| + Assert.assertEquals("test", state.textWithoutAutocomplete);
|
| + Assert.assertEquals("test", state.textWithAutocomplete);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testBatchModeChangesTriggerCorrectSuggestions() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
|
|
| final AtomicReference<String> requestedAutocompleteText = new AtomicReference<String>();
|
| final StubAutocompleteController controller = new StubAutocompleteController() {
|
| @@ -488,11 +509,12 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }));
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature("Omnibox")
|
| @RetryOnFailure
|
| public void testAutocompleteCorrectlyPerservedOnBatchMode() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| stubLocationBarAutocomplete();
|
|
|
| final UrlBar urlBar = getUrlBar();
|
| @@ -512,9 +534,9 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.endBatchEdit();
|
| }
|
| });
|
| - assertTrue(state.hasAutocomplete);
|
| - assertEquals("google.com", state.textWithAutocomplete);
|
| - assertEquals("go", state.textWithoutAutocomplete);
|
| + Assert.assertTrue(state.hasAutocomplete);
|
| + Assert.assertEquals("google.com", state.textWithAutocomplete);
|
| + Assert.assertEquals("go", state.textWithoutAutocomplete);
|
|
|
| // Invalid case (cursor not at the end of the text)
|
| setAutocomplete(urlBar, "g", "oogle.com");
|
| @@ -529,7 +551,7 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.endBatchEdit();
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
|
|
| // Invalid case (next character did not match previous autocomplete)
|
| setAutocomplete(urlBar, "g", "oogle.com");
|
| @@ -544,7 +566,7 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.endBatchEdit();
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
|
|
| // Invalid case (multiple characters entered instead of 1)
|
| setAutocomplete(urlBar, "g", "oogle.com");
|
| @@ -559,14 +581,15 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.endBatchEdit();
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature("Omnibox")
|
| @RetryOnFailure
|
| public void testAutocompleteSpanClearedOnNonMatchingCommitText() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
|
|
| stubLocationBarAutocomplete();
|
|
|
| @@ -595,11 +618,12 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }));
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testAutocompleteUpdatedOnDefocus() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| stubLocationBarAutocomplete();
|
| final UrlBar urlBar = getUrlBar();
|
| OmniboxTestUtils.toggleUrlBarFocus(urlBar, true);
|
| @@ -609,15 +633,16 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| setAutocomplete(urlBar, "test", "ing is fun");
|
| OmniboxTestUtils.toggleUrlBarFocus(urlBar, false);
|
| AutocompleteState state = getAutocompleteState(urlBar, null);
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testAutocompleteClearedOnComposition()
|
| throws InterruptedException, ExecutionException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| stubLocationBarAutocomplete();
|
| final UrlBar urlBar = getUrlBar();
|
| OmniboxTestUtils.toggleUrlBarFocus(urlBar, true);
|
| @@ -626,36 +651,37 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| setTextAndVerifyNoAutocomplete(urlBar, "test");
|
| setAutocomplete(urlBar, "test", "ing is fun");
|
|
|
| - assertNotNull(urlBar.mInputConnection);
|
| + Assert.assertNotNull(urlBar.mInputConnection);
|
| AutocompleteState state = getAutocompleteState(urlBar, new Runnable() {
|
| @Override
|
| public void run() {
|
| urlBar.mInputConnection.setComposingText("ing compose", 4);
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
|
|
| Editable urlText = getUrlBarText(urlBar);
|
| - assertEquals("testing compose", urlText.toString());
|
| + Assert.assertEquals("testing compose", urlText.toString());
|
| // TODO(tedchoc): Investigate why this fails on x86.
|
| //assertEquals(4, BaseInputConnection.getComposingSpanStart(urlText));
|
| //assertEquals(15, BaseInputConnection.getComposingSpanEnd(urlText));
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature("Omnibox")
|
| @RetryOnFailure
|
| @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) // crbug.com/635714
|
| public void testDelayedCompositionCorrectedWithAutocomplete()
|
| throws InterruptedException, ExecutionException {
|
| - startMainActivityOnBlankPage();
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| stubLocationBarAutocomplete();
|
|
|
| final UrlBar urlBar = getUrlBar();
|
| OmniboxTestUtils.toggleUrlBarFocus(urlBar, true);
|
| OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true);
|
|
|
| - assertNotNull(urlBar.mInputConnection);
|
| + Assert.assertNotNull(urlBar.mInputConnection);
|
|
|
| // Test with a single autocomplete
|
|
|
| @@ -669,12 +695,12 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.mInputConnection.setComposingText("f", 1);
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
|
|
| Editable urlText = getUrlBarText(urlBar);
|
| - assertEquals("chrome://f", urlText.toString());
|
| - assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 9);
|
| - assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10);
|
| + Assert.assertEquals("chrome://f", urlText.toString());
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 9);
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10);
|
|
|
| // Test with > 1 characters in composition.
|
|
|
| @@ -688,12 +714,12 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.mInputConnection.setComposingText("fl", 1);
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
|
|
| urlText = getUrlBarText(urlBar);
|
| - assertEquals("chrome://fl", urlText.toString());
|
| - assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 9);
|
| - assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11);
|
| + Assert.assertEquals("chrome://fl", urlText.toString());
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 9);
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11);
|
|
|
| // Test with non-matching composition. Should just append to the URL text.
|
|
|
| @@ -707,12 +733,12 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.mInputConnection.setComposingText("g", 1);
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
|
|
| urlText = getUrlBarText(urlBar);
|
| - assertEquals("chrome://fg", urlText.toString());
|
| - assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 10);
|
| - assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11);
|
| + Assert.assertEquals("chrome://fg", urlText.toString());
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 10);
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11);
|
|
|
| // Test with composition text that matches the entire text w/o autocomplete.
|
|
|
| @@ -726,12 +752,12 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.mInputConnection.setComposingText("chrome://f", 1);
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
|
|
| urlText = getUrlBarText(urlBar);
|
| - assertEquals("chrome://f", urlText.toString());
|
| - assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 0);
|
| - assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10);
|
| + Assert.assertEquals("chrome://f", urlText.toString());
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 0);
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10);
|
|
|
| // Test with composition text longer than the URL text. Shouldn't crash and should
|
| // just append text.
|
| @@ -746,49 +772,52 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| urlBar.mInputConnection.setComposingText("blahblahblah", 1);
|
| }
|
| });
|
| - assertFalse(state.hasAutocomplete);
|
| + Assert.assertFalse(state.hasAutocomplete);
|
|
|
| urlText = getUrlBarText(urlBar);
|
| - assertEquals("chrome://fblahblahblah", urlText.toString());
|
| - assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 10);
|
| - assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 22);
|
| + Assert.assertEquals("chrome://fblahblahblah", urlText.toString());
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText), 10);
|
| + Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 22);
|
| }
|
|
|
| /**
|
| * Test to verify the omnibox can take focus during startup before native libraries have
|
| * loaded.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| - public void testFocusingOnStartup() throws InterruptedException {
|
| + public void testFocusingOnStartup() {
|
| Intent intent = new Intent(Intent.ACTION_MAIN);
|
| intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
| - prepareUrlIntent(intent, "about:blank");
|
| - startActivityCompletely(intent);
|
| + mActivityTestRule.prepareUrlIntent(intent, "about:blank");
|
| + mActivityTestRule.startActivityCompletely(intent);
|
|
|
| UrlBar urlBar = getUrlBar();
|
| - assertNotNull(urlBar);
|
| + Assert.assertNotNull(urlBar);
|
| OmniboxTestUtils.toggleUrlBarFocus(urlBar, true);
|
| OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testCopyHuge() throws InterruptedException {
|
| - startMainActivityWithURL(HUGE_URL);
|
| + mActivityTestRule.startMainActivityWithURL(HUGE_URL);
|
| OmniboxTestUtils.toggleUrlBarFocus(getUrlBar(), true);
|
| - assertEquals(HUGE_URL, copyUrlToClipboard(android.R.id.copy));
|
| + Assert.assertEquals(HUGE_URL, copyUrlToClipboard(android.R.id.copy));
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Omnibox"})
|
| @RetryOnFailure
|
| public void testCutHuge() throws InterruptedException {
|
| - startMainActivityWithURL(HUGE_URL);
|
| + mActivityTestRule.startMainActivityWithURL(HUGE_URL);
|
| OmniboxTestUtils.toggleUrlBarFocus(getUrlBar(), true);
|
| - assertEquals(HUGE_URL, copyUrlToClipboard(android.R.id.cut));
|
| + Assert.assertEquals(HUGE_URL, copyUrlToClipboard(android.R.id.cut));
|
| }
|
|
|
| /**
|
| @@ -797,26 +826,27 @@ public class UrlBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| * or android.R.id.cut.
|
| */
|
| private String copyUrlToClipboard(final int action) {
|
| - ClipboardManager clipboardManager = (ClipboardManager)
|
| - getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
| + return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<String>() {
|
| + @Override
|
| + public String call() {
|
| + ClipboardManager clipboardManager =
|
| + (ClipboardManager) mActivityTestRule.getActivity().getSystemService(
|
| + Context.CLIPBOARD_SERVICE);
|
|
|
| - clipboardManager.setPrimaryClip(ClipData.newPlainText(null, ""));
|
| + clipboardManager.setPrimaryClip(ClipData.newPlainText(null, ""));
|
|
|
| - ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - assertTrue(getUrlBar().onTextContextMenuItem(action));
|
| + Assert.assertTrue(getUrlBar().onTextContextMenuItem(action));
|
| + ClipData clip = clipboardManager.getPrimaryClip();
|
| + CharSequence text = (clip != null && clip.getItemCount() != 0)
|
| + ? clip.getItemAt(0).getText()
|
| + : null;
|
| + return text != null ? text.toString() : null;
|
| }
|
| });
|
| -
|
| - ClipData clip = clipboardManager.getPrimaryClip();
|
| - CharSequence text = (clip != null && clip.getItemCount() != 0)
|
| - ? clip.getItemAt(0).getText() : null;
|
| - return text != null ? text.toString() : null;
|
| }
|
|
|
| - @Override
|
| - public void startMainActivity() throws InterruptedException {
|
| + @Before
|
| + public void setUp() throws InterruptedException {
|
| // Each test will start the activity.
|
| }
|
| }
|
|
|