| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 | 8 |
| 9 import android.annotation.SuppressLint; | 9 import android.annotation.SuppressLint; |
| 10 import android.content.ClipData; | 10 import android.content.ClipData; |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 484 |
| 485 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 485 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 486 @Override | 486 @Override |
| 487 public void run() { | 487 public void run() { |
| 488 urlBar.beginBatchEdit(); | 488 urlBar.beginBatchEdit(); |
| 489 } | 489 } |
| 490 }); | 490 }); |
| 491 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 491 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 492 @Override | 492 @Override |
| 493 public void run() { | 493 public void run() { |
| 494 urlBar.mInputConnection.commitText("y", 1); | 494 urlBar.getInputConnection().commitText("y", 1); |
| 495 } | 495 } |
| 496 }); | 496 }); |
| 497 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 497 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 498 @Override | 498 @Override |
| 499 public void run() { | 499 public void run() { |
| 500 urlBar.endBatchEdit(); | 500 urlBar.endBatchEdit(); |
| 501 } | 501 } |
| 502 }); | 502 }); |
| 503 | 503 |
| 504 CriteriaHelper.pollUiThread(Criteria.equals("testy", new Callable<String
>() { | 504 CriteriaHelper.pollUiThread(Criteria.equals("testy", new Callable<String
>() { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 final UrlBar urlBar = getUrlBar(); | 596 final UrlBar urlBar = getUrlBar(); |
| 597 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 597 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 598 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); | 598 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); |
| 599 | 599 |
| 600 setTextAndVerifyNoAutocomplete(urlBar, "a"); | 600 setTextAndVerifyNoAutocomplete(urlBar, "a"); |
| 601 setAutocomplete(urlBar, "a", "mazon.com"); | 601 setAutocomplete(urlBar, "a", "mazon.com"); |
| 602 | 602 |
| 603 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 603 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 604 @Override | 604 @Override |
| 605 public void run() { | 605 public void run() { |
| 606 urlBar.mInputConnection.beginBatchEdit(); | 606 urlBar.getInputConnection().beginBatchEdit(); |
| 607 urlBar.mInputConnection.commitText("l", 1); | 607 urlBar.getInputConnection().commitText("l", 1); |
| 608 urlBar.mInputConnection.setComposingText("", 1); | 608 urlBar.getInputConnection().setComposingText("", 1); |
| 609 urlBar.mInputConnection.endBatchEdit(); | 609 urlBar.getInputConnection().endBatchEdit(); |
| 610 } | 610 } |
| 611 }); | 611 }); |
| 612 | 612 |
| 613 CriteriaHelper.pollUiThread(Criteria.equals("al", new Callable<String>()
{ | 613 CriteriaHelper.pollUiThread(Criteria.equals("al", new Callable<String>()
{ |
| 614 @Override | 614 @Override |
| 615 public String call() { | 615 public String call() { |
| 616 return urlBar.getText().toString(); | 616 return urlBar.getText().toString(); |
| 617 } | 617 } |
| 618 })); | 618 })); |
| 619 } | 619 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 644 throws InterruptedException, ExecutionException { | 644 throws InterruptedException, ExecutionException { |
| 645 mActivityTestRule.startMainActivityOnBlankPage(); | 645 mActivityTestRule.startMainActivityOnBlankPage(); |
| 646 stubLocationBarAutocomplete(); | 646 stubLocationBarAutocomplete(); |
| 647 final UrlBar urlBar = getUrlBar(); | 647 final UrlBar urlBar = getUrlBar(); |
| 648 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 648 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 649 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); | 649 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); |
| 650 | 650 |
| 651 setTextAndVerifyNoAutocomplete(urlBar, "test"); | 651 setTextAndVerifyNoAutocomplete(urlBar, "test"); |
| 652 setAutocomplete(urlBar, "test", "ing is fun"); | 652 setAutocomplete(urlBar, "test", "ing is fun"); |
| 653 | 653 |
| 654 Assert.assertNotNull(urlBar.mInputConnection); | 654 Assert.assertNotNull(urlBar.getInputConnection()); |
| 655 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { | 655 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { |
| 656 @Override | 656 @Override |
| 657 public void run() { | 657 public void run() { |
| 658 urlBar.mInputConnection.setComposingText("ing compose", 4); | 658 urlBar.getInputConnection().setComposingText("ing compose", 4); |
| 659 } | 659 } |
| 660 }); | 660 }); |
| 661 Assert.assertFalse(state.hasAutocomplete); | 661 Assert.assertFalse(state.hasAutocomplete); |
| 662 | 662 |
| 663 Editable urlText = getUrlBarText(urlBar); | 663 Editable urlText = getUrlBarText(urlBar); |
| 664 Assert.assertEquals("testing compose", urlText.toString()); | 664 Assert.assertEquals("testing compose", urlText.toString()); |
| 665 // TODO(tedchoc): Investigate why this fails on x86. | 665 // TODO(tedchoc): Investigate why this fails on x86. |
| 666 //assertEquals(4, BaseInputConnection.getComposingSpanStart(urlText)); | 666 //assertEquals(4, BaseInputConnection.getComposingSpanStart(urlText)); |
| 667 //assertEquals(15, BaseInputConnection.getComposingSpanEnd(urlText)); | 667 //assertEquals(15, BaseInputConnection.getComposingSpanEnd(urlText)); |
| 668 } | 668 } |
| 669 | 669 |
| 670 @Test | 670 @Test |
| 671 @SmallTest | 671 @SmallTest |
| 672 @Feature("Omnibox") | 672 @Feature("Omnibox") |
| 673 @RetryOnFailure | 673 @RetryOnFailure |
| 674 @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) // crbug.com/635714 | 674 @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) // crbug.com/635714 |
| 675 public void testDelayedCompositionCorrectedWithAutocomplete() | 675 public void testDelayedCompositionCorrectedWithAutocomplete() |
| 676 throws InterruptedException, ExecutionException { | 676 throws InterruptedException, ExecutionException { |
| 677 mActivityTestRule.startMainActivityOnBlankPage(); | 677 mActivityTestRule.startMainActivityOnBlankPage(); |
| 678 stubLocationBarAutocomplete(); | 678 stubLocationBarAutocomplete(); |
| 679 | 679 |
| 680 final UrlBar urlBar = getUrlBar(); | 680 final UrlBar urlBar = getUrlBar(); |
| 681 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); | 681 OmniboxTestUtils.toggleUrlBarFocus(urlBar, true); |
| 682 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); | 682 OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, true); |
| 683 | 683 |
| 684 Assert.assertNotNull(urlBar.mInputConnection); | 684 Assert.assertNotNull(urlBar.getInputConnection()); |
| 685 | 685 |
| 686 // Test with a single autocomplete | 686 // Test with a single autocomplete |
| 687 | 687 |
| 688 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); | 688 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); |
| 689 setAutocomplete(urlBar, "chrome://f", "lags"); | 689 setAutocomplete(urlBar, "chrome://f", "lags"); |
| 690 | 690 |
| 691 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { | 691 AutocompleteState state = getAutocompleteState(urlBar, new Runnable() { |
| 692 @Override | 692 @Override |
| 693 public void run() { | 693 public void run() { |
| 694 urlBar.mInputConnection.setComposingRegion(13, 14); | 694 urlBar.getInputConnection().setComposingRegion(13, 14); |
| 695 urlBar.mInputConnection.setComposingText("f", 1); | 695 urlBar.getInputConnection().setComposingText("f", 1); |
| 696 } | 696 } |
| 697 }); | 697 }); |
| 698 Assert.assertFalse(state.hasAutocomplete); | 698 Assert.assertFalse(state.hasAutocomplete); |
| 699 | 699 |
| 700 Editable urlText = getUrlBarText(urlBar); | 700 Editable urlText = getUrlBarText(urlBar); |
| 701 Assert.assertEquals("chrome://f", urlText.toString()); | 701 Assert.assertEquals("chrome://f", urlText.toString()); |
| 702 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
9); | 702 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
9); |
| 703 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10
); | 703 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10
); |
| 704 | 704 |
| 705 // Test with > 1 characters in composition. | 705 // Test with > 1 characters in composition. |
| 706 | 706 |
| 707 setTextAndVerifyNoAutocomplete(urlBar, "chrome://fl"); | 707 setTextAndVerifyNoAutocomplete(urlBar, "chrome://fl"); |
| 708 setAutocomplete(urlBar, "chrome://fl", "ags"); | 708 setAutocomplete(urlBar, "chrome://fl", "ags"); |
| 709 | 709 |
| 710 state = getAutocompleteState(urlBar, new Runnable() { | 710 state = getAutocompleteState(urlBar, new Runnable() { |
| 711 @Override | 711 @Override |
| 712 public void run() { | 712 public void run() { |
| 713 urlBar.mInputConnection.setComposingRegion(12, 14); | 713 urlBar.getInputConnection().setComposingRegion(12, 14); |
| 714 urlBar.mInputConnection.setComposingText("fl", 1); | 714 urlBar.getInputConnection().setComposingText("fl", 1); |
| 715 } | 715 } |
| 716 }); | 716 }); |
| 717 Assert.assertFalse(state.hasAutocomplete); | 717 Assert.assertFalse(state.hasAutocomplete); |
| 718 | 718 |
| 719 urlText = getUrlBarText(urlBar); | 719 urlText = getUrlBarText(urlBar); |
| 720 Assert.assertEquals("chrome://fl", urlText.toString()); | 720 Assert.assertEquals("chrome://fl", urlText.toString()); |
| 721 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
9); | 721 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
9); |
| 722 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11
); | 722 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11
); |
| 723 | 723 |
| 724 // Test with non-matching composition. Should just append to the URL te
xt. | 724 // Test with non-matching composition. Should just append to the URL te
xt. |
| 725 | 725 |
| 726 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); | 726 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); |
| 727 setAutocomplete(urlBar, "chrome://f", "lags"); | 727 setAutocomplete(urlBar, "chrome://f", "lags"); |
| 728 | 728 |
| 729 state = getAutocompleteState(urlBar, new Runnable() { | 729 state = getAutocompleteState(urlBar, new Runnable() { |
| 730 @Override | 730 @Override |
| 731 public void run() { | 731 public void run() { |
| 732 urlBar.mInputConnection.setComposingRegion(13, 14); | 732 urlBar.getInputConnection().setComposingRegion(13, 14); |
| 733 urlBar.mInputConnection.setComposingText("g", 1); | 733 urlBar.getInputConnection().setComposingText("g", 1); |
| 734 } | 734 } |
| 735 }); | 735 }); |
| 736 Assert.assertFalse(state.hasAutocomplete); | 736 Assert.assertFalse(state.hasAutocomplete); |
| 737 | 737 |
| 738 urlText = getUrlBarText(urlBar); | 738 urlText = getUrlBarText(urlBar); |
| 739 Assert.assertEquals("chrome://fg", urlText.toString()); | 739 Assert.assertEquals("chrome://fg", urlText.toString()); |
| 740 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
10); | 740 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
10); |
| 741 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11
); | 741 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 11
); |
| 742 | 742 |
| 743 // Test with composition text that matches the entire text w/o autocompl
ete. | 743 // Test with composition text that matches the entire text w/o autocompl
ete. |
| 744 | 744 |
| 745 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); | 745 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); |
| 746 setAutocomplete(urlBar, "chrome://f", "lags"); | 746 setAutocomplete(urlBar, "chrome://f", "lags"); |
| 747 | 747 |
| 748 state = getAutocompleteState(urlBar, new Runnable() { | 748 state = getAutocompleteState(urlBar, new Runnable() { |
| 749 @Override | 749 @Override |
| 750 public void run() { | 750 public void run() { |
| 751 urlBar.mInputConnection.setComposingRegion(13, 14); | 751 urlBar.getInputConnection().setComposingRegion(13, 14); |
| 752 urlBar.mInputConnection.setComposingText("chrome://f", 1); | 752 urlBar.getInputConnection().setComposingText("chrome://f", 1); |
| 753 } | 753 } |
| 754 }); | 754 }); |
| 755 Assert.assertFalse(state.hasAutocomplete); | 755 Assert.assertFalse(state.hasAutocomplete); |
| 756 | 756 |
| 757 urlText = getUrlBarText(urlBar); | 757 urlText = getUrlBarText(urlBar); |
| 758 Assert.assertEquals("chrome://f", urlText.toString()); | 758 Assert.assertEquals("chrome://f", urlText.toString()); |
| 759 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
0); | 759 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
0); |
| 760 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10
); | 760 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 10
); |
| 761 | 761 |
| 762 // Test with composition text longer than the URL text. Shouldn't crash
and should | 762 // Test with composition text longer than the URL text. Shouldn't crash
and should |
| 763 // just append text. | 763 // just append text. |
| 764 | 764 |
| 765 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); | 765 setTextAndVerifyNoAutocomplete(urlBar, "chrome://f"); |
| 766 setAutocomplete(urlBar, "chrome://f", "lags"); | 766 setAutocomplete(urlBar, "chrome://f", "lags"); |
| 767 | 767 |
| 768 state = getAutocompleteState(urlBar, new Runnable() { | 768 state = getAutocompleteState(urlBar, new Runnable() { |
| 769 @Override | 769 @Override |
| 770 public void run() { | 770 public void run() { |
| 771 urlBar.mInputConnection.setComposingRegion(13, 14); | 771 urlBar.getInputConnection().setComposingRegion(13, 14); |
| 772 urlBar.mInputConnection.setComposingText("blahblahblah", 1); | 772 urlBar.getInputConnection().setComposingText("blahblahblah", 1); |
| 773 } | 773 } |
| 774 }); | 774 }); |
| 775 Assert.assertFalse(state.hasAutocomplete); | 775 Assert.assertFalse(state.hasAutocomplete); |
| 776 | 776 |
| 777 urlText = getUrlBarText(urlBar); | 777 urlText = getUrlBarText(urlBar); |
| 778 Assert.assertEquals("chrome://fblahblahblah", urlText.toString()); | 778 Assert.assertEquals("chrome://fblahblahblah", urlText.toString()); |
| 779 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
10); | 779 Assert.assertEquals(BaseInputConnection.getComposingSpanStart(urlText),
10); |
| 780 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 22
); | 780 Assert.assertEquals(BaseInputConnection.getComposingSpanEnd(urlText), 22
); |
| 781 } | 781 } |
| 782 | 782 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 return text != null ? text.toString() : null; | 843 return text != null ? text.toString() : null; |
| 844 } | 844 } |
| 845 }); | 845 }); |
| 846 } | 846 } |
| 847 | 847 |
| 848 @Before | 848 @Before |
| 849 public void setUp() throws InterruptedException { | 849 public void setUp() throws InterruptedException { |
| 850 // Each test will start the activity. | 850 // Each test will start the activity. |
| 851 } | 851 } |
| 852 } | 852 } |
| OLD | NEW |