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.contextualsearch; | 5 package org.chromium.chrome.browser.contextualsearch; |
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 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; | 8 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; |
9 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL ING_INTERVAL; | 9 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL ING_INTERVAL; |
10 | 10 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 assertTrue("Bar never showed desired text.", | 384 assertTrue("Bar never showed desired text.", |
385 CriteriaHelper.pollForCriteria(new Criteria() { | 385 CriteriaHelper.pollForCriteria(new Criteria() { |
386 @Override | 386 @Override |
387 public boolean isSatisfied() { | 387 public boolean isSatisfied() { |
388 return TextUtils.equals(text, getSelectedText()); | 388 return TextUtils.equals(text, getSelectedText()); |
389 } | 389 } |
390 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL)); | 390 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL)); |
391 } | 391 } |
392 | 392 |
393 /** | 393 /** |
394 * Waits for the selection to be dissolved. | |
395 * This is needed because the renderer's notification of a selection going a way is async, | |
396 * and a subsequent tap may think there's a current selection until it has b een dissolved. | |
397 */ | |
398 private void waitForSelectionDissolved() throws InterruptedException { | |
399 assertTrue("Selection never dissolved.", CriteriaHelper.pollForCriteria( new Criteria() { | |
400 @Override | |
401 public boolean isSatisfied() { | |
402 return mSelectionController.isSelectionDissolved(); | |
403 } | |
404 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL)); | |
405 } | |
406 | |
407 /** | |
394 * A ContentViewCore that has some methods stubbed out for testing. | 408 * A ContentViewCore that has some methods stubbed out for testing. |
395 */ | 409 */ |
396 private static final class StubbedContentViewCore extends ContentViewCore { | 410 private static final class StubbedContentViewCore extends ContentViewCore { |
397 private boolean mIsFocusedNodeEditable; | 411 private boolean mIsFocusedNodeEditable; |
398 | 412 |
399 public StubbedContentViewCore(Context context) { | 413 public StubbedContentViewCore(Context context) { |
400 super(context); | 414 super(context); |
401 } | 415 } |
402 | 416 |
403 public void setIsFocusedNodeEditableForTest(boolean isFocusedNodeEditabl e) { | 417 public void setIsFocusedNodeEditableForTest(boolean isFocusedNodeEditabl e) { |
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1753 final ContentViewCore contentViewCore = getActivity().getActivityTab().g etContentViewCore(); | 1767 final ContentViewCore contentViewCore = getActivity().getActivityTab().g etContentViewCore(); |
1754 assertWaitForSelectActionBarVisible(true); | 1768 assertWaitForSelectActionBarVisible(true); |
1755 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 1769 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
1756 @Override | 1770 @Override |
1757 public void run() { | 1771 public void run() { |
1758 contentViewCore.hideSelectActionMode(); | 1772 contentViewCore.hideSelectActionMode(); |
1759 } | 1773 } |
1760 }); | 1774 }); |
1761 assertWaitForSelectActionBarVisible(false); | 1775 assertWaitForSelectActionBarVisible(false); |
1762 | 1776 |
1763 waitForPanelToCloseAndAssert(); | 1777 waitForPanelToCloseAndAssert(); |
jdduke (slow)
2015/07/16 23:15:50
I guess in the follow-up you could change "waitFor
Donn Denman
2015/07/16 23:24:52
That's all spot-on -- will do in the next CL.
| |
1764 assertEquals(1, observer.hideCount); | 1778 assertEquals(1, observer.hideCount); |
1765 } | 1779 } |
1766 | 1780 |
1767 /** | 1781 /** |
1768 * Tests that the Contextual Search panel does not reappear when a long-pres s selection is | 1782 * Tests that the Contextual Search panel does not reappear when a long-pres s selection is |
1769 * modified after the user has taken an action to explicitly dismiss the pan el. Also tests | 1783 * modified after the user has taken an action to explicitly dismiss the pan el. Also tests |
1770 * that the panel reappears when a new selection is made. | 1784 * that the panel reappears when a new selection is made. |
1771 */ | 1785 */ |
1772 @SmallTest | 1786 @SmallTest |
1773 @Feature({"ContextualSearch"}) | 1787 @Feature({"ContextualSearch"}) |
1774 @Restriction({RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON_LOW_END_DEVICE}) | 1788 @Restriction({RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON_LOW_END_DEVICE}) |
1775 public void testPreventHandlingCurrentSelectionModification() | 1789 public void testPreventHandlingCurrentSelectionModification() |
1776 throws InterruptedException, TimeoutException { | 1790 throws InterruptedException, TimeoutException { |
1777 longPressNode("intelligence"); | 1791 longPressNode("intelligence"); |
1778 waitForPanelToPeekAndAssert(); | 1792 waitForPanelToPeekAndAssert(); |
1779 | 1793 |
1780 // Dismiss the Contextual Search panel. | 1794 // Dismiss the Contextual Search panel. |
1781 scrollBasePage(); | 1795 scrollBasePage(); |
1782 assertPanelClosedOrUndefined(); | 1796 assertPanelClosedOrUndefined(); |
1783 assertEquals("Intelligence", getSelectedText()); | 1797 assertEquals("Intelligence", getSelectedText()); |
1784 | 1798 |
1785 // Simulate a selection change event and assert that the panel has not r eappeared. | 1799 // Simulate a selection change event and assert that the panel has not r eappeared. |
1786 mManager.onSelectionEvent(SelectionEventType.SELECTION_DRAG_STARTED, 333 , 450); | 1800 mManager.onSelectionEvent(SelectionEventType.SELECTION_HANDLE_DRAG_START ED, 333, 450); |
1787 mManager.onSelectionEvent(SelectionEventType.SELECTION_DRAG_STOPPED, 303 , 450); | 1801 mManager.onSelectionEvent(SelectionEventType.SELECTION_HANDLE_DRAG_STOPP ED, 303, 450); |
1788 assertPanelClosedOrUndefined(); | 1802 assertPanelClosedOrUndefined(); |
1789 | 1803 |
1790 // Select a different word and assert that the panel has appeared. | 1804 // Select a different word and assert that the panel has appeared. |
1791 longPressNode("states-far"); | 1805 longPressNode("states-far"); |
1792 waitForPanelToPeekAndAssert(); | 1806 waitForPanelToPeekAndAssert(); |
1793 } | 1807 } |
1808 | |
1809 /** | |
1810 * Tests a bunch of taps in a row. | |
1811 * We've had reliability problems with simple taps due to async clearing | |
1812 * of selection bounds, so this helps prevent a regression with that. | |
1813 */ | |
1814 @Restriction({RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON_LOW_END_DEVICE}) | |
1815 @CommandLineFlags.Add({ContextualSearchFieldTrial.TAP_RESOLVE_LIMIT_FOR_DECI DED + "=200", | |
1816 ContextualSearchFieldTrial.TAP_RESOLVE_LIMIT_FOR_UNDECIDED + "=200", | |
1817 ContextualSearchFieldTrial.TAP_PREFETCH_LIMIT_FOR_DECIDED + "=200", | |
1818 ContextualSearchFieldTrial.TAP_PREFETCH_LIMIT_FOR_UNDECIDED + "=200" }) | |
1819 public void testTapALot() throws InterruptedException, TimeoutException { | |
1820 for (int i = 0; i < 50; i++) { | |
1821 clickToTriggerSearchTermResolution(); | |
1822 waitForSelectionDissolved(); | |
1823 assertSearchTermRequested(); | |
1824 } | |
1825 } | |
1794 } | 1826 } |
OLD | NEW |