| 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.content.browser.test.util.CriteriaHelper.DEFAULT_POLL
ING_INTERVAL; | 8 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL
ING_INTERVAL; |
| 9 | 9 |
| 10 import android.app.Activity; | 10 import android.app.Activity; |
| 11 import android.app.Instrumentation; | 11 import android.app.Instrumentation; |
| 12 import android.app.Instrumentation.ActivityMonitor; | 12 import android.app.Instrumentation.ActivityMonitor; |
| 13 import android.content.Context; | 13 import android.content.Context; |
| 14 import android.content.Intent; | 14 import android.content.Intent; |
| 15 import android.content.IntentFilter; | 15 import android.content.IntentFilter; |
| 16 import android.graphics.Point; | 16 import android.graphics.Point; |
| 17 import android.os.Environment; | 17 import android.os.Environment; |
| 18 import android.os.SystemClock; | 18 import android.os.SystemClock; |
| 19 import android.test.suitebuilder.annotation.SmallTest; | 19 import android.test.suitebuilder.annotation.SmallTest; |
| 20 import android.view.KeyEvent; | 20 import android.view.KeyEvent; |
| 21 import android.view.View; | 21 import android.view.View; |
| 22 import android.view.ViewConfiguration; | 22 import android.view.ViewConfiguration; |
| 23 | 23 |
| 24 import org.chromium.base.ContextUtils; | 24 import org.chromium.base.ContextUtils; |
| 25 import org.chromium.base.ThreadUtils; | 25 import org.chromium.base.ThreadUtils; |
| 26 import org.chromium.base.test.util.CommandLineFlags; | 26 import org.chromium.base.test.util.CommandLineFlags; |
| 27 import org.chromium.base.test.util.DisableIf; |
| 27 import org.chromium.base.test.util.DisabledTest; | 28 import org.chromium.base.test.util.DisabledTest; |
| 28 import org.chromium.base.test.util.Feature; | 29 import org.chromium.base.test.util.Feature; |
| 29 import org.chromium.base.test.util.FlakyTest; | 30 import org.chromium.base.test.util.FlakyTest; |
| 30 import org.chromium.base.test.util.Restriction; | 31 import org.chromium.base.test.util.Restriction; |
| 31 import org.chromium.chrome.R; | 32 import org.chromium.chrome.R; |
| 32 import org.chromium.chrome.browser.ChromeActivity; | 33 import org.chromium.chrome.browser.ChromeActivity; |
| 33 import org.chromium.chrome.browser.ChromeSwitches; | 34 import org.chromium.chrome.browser.ChromeSwitches; |
| 34 import org.chromium.chrome.browser.ChromeTabbedActivity; | 35 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 35 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate; | 36 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate; |
| 36 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentProgressOb
server; | 37 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentProgressOb
server; |
| (...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1508 clickNode("focusable"); | 1509 clickNode("focusable"); |
| 1509 assertPanelStillInState(initialState); | 1510 assertPanelStillInState(initialState); |
| 1510 } | 1511 } |
| 1511 | 1512 |
| 1512 /** | 1513 /** |
| 1513 * Tests that taps can be resolve and prefetch limited for decided users. | 1514 * Tests that taps can be resolve and prefetch limited for decided users. |
| 1514 */ | 1515 */ |
| 1515 @SmallTest | 1516 @SmallTest |
| 1516 @Feature({"ContextualSearch"}) | 1517 @Feature({"ContextualSearch"}) |
| 1517 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 1518 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 1519 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1518 public void testTapLimitForDecided() throws InterruptedException, TimeoutExc
eption { | 1520 public void testTapLimitForDecided() throws InterruptedException, TimeoutExc
eption { |
| 1519 mPolicy.setTapLimitForDecidedForTesting(2); | 1521 mPolicy.setTapLimitForDecidedForTesting(2); |
| 1520 clickToTriggerPrefetch(); | 1522 clickToTriggerPrefetch(); |
| 1521 assertSearchTermRequested(); | 1523 assertSearchTermRequested(); |
| 1522 assertLoadedLowPriorityUrl(); | 1524 assertLoadedLowPriorityUrl(); |
| 1523 clickToTriggerPrefetch(); | 1525 clickToTriggerPrefetch(); |
| 1524 assertSearchTermRequested(); | 1526 assertSearchTermRequested(); |
| 1525 assertLoadedLowPriorityUrl(); | 1527 assertLoadedLowPriorityUrl(); |
| 1526 // 3rd click should not resolve or prefetch. | 1528 // 3rd click should not resolve or prefetch. |
| 1527 clickToTriggerLimitedPrefetch(); | 1529 clickToTriggerLimitedPrefetch(); |
| 1528 assertSearchTermNotRequested(); | 1530 assertSearchTermNotRequested(); |
| 1529 assertLoadedNoUrl(); | 1531 assertLoadedNoUrl(); |
| 1530 | 1532 |
| 1531 // Expanding the panel should reset the limit. | 1533 // Expanding the panel should reset the limit. |
| 1532 clickToExpandAndClosePanel(); | 1534 clickToExpandAndClosePanel(); |
| 1533 | 1535 |
| 1534 // Click should resolve and prefetch again. | 1536 // Click should resolve and prefetch again. |
| 1535 clickToTriggerPrefetch(); | 1537 clickToTriggerPrefetch(); |
| 1536 assertSearchTermRequested(); | 1538 assertSearchTermRequested(); |
| 1537 assertLoadedLowPriorityUrl(); | 1539 assertLoadedLowPriorityUrl(); |
| 1538 } | 1540 } |
| 1539 | 1541 |
| 1540 /** | 1542 /** |
| 1541 * Tests that taps can be resolve-limited for undecided users. | 1543 * Tests that taps can be resolve-limited for undecided users. |
| 1542 */ | 1544 */ |
| 1543 @SmallTest | 1545 @SmallTest |
| 1544 @Feature({"ContextualSearch"}) | 1546 @Feature({"ContextualSearch"}) |
| 1545 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 1547 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 1548 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1546 public void testTapLimitForUndecided() throws InterruptedException, TimeoutE
xception { | 1549 public void testTapLimitForUndecided() throws InterruptedException, TimeoutE
xception { |
| 1547 mPolicy.setTapLimitForUndecidedForTesting(2); | 1550 mPolicy.setTapLimitForUndecidedForTesting(2); |
| 1548 mPolicy.overrideDecidedStateForTesting(false); | 1551 mPolicy.overrideDecidedStateForTesting(false); |
| 1549 | 1552 |
| 1550 clickToTriggerPrefetch(); | 1553 clickToTriggerPrefetch(); |
| 1551 assertSearchTermRequested(); | 1554 assertSearchTermRequested(); |
| 1552 assertLoadedLowPriorityUrl(); | 1555 assertLoadedLowPriorityUrl(); |
| 1553 clickToTriggerPrefetch(); | 1556 clickToTriggerPrefetch(); |
| 1554 assertSearchTermRequested(); | 1557 assertSearchTermRequested(); |
| 1555 assertLoadedLowPriorityUrl(); | 1558 assertLoadedLowPriorityUrl(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 } | 1689 } |
| 1687 })); | 1690 })); |
| 1688 } | 1691 } |
| 1689 | 1692 |
| 1690 /** | 1693 /** |
| 1691 * Tests that the App Menu gets suppressed when Search Panel is expanded. | 1694 * Tests that the App Menu gets suppressed when Search Panel is expanded. |
| 1692 */ | 1695 */ |
| 1693 @SmallTest | 1696 @SmallTest |
| 1694 @Feature({"ContextualSearch"}) | 1697 @Feature({"ContextualSearch"}) |
| 1695 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 1698 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 1699 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1696 public void testAppMenuSuppressedWhenExpanded() throws InterruptedException,
TimeoutException { | 1700 public void testAppMenuSuppressedWhenExpanded() throws InterruptedException,
TimeoutException { |
| 1697 clickWordNode("states"); | 1701 clickWordNode("states"); |
| 1698 tapPeekingBarToExpandAndAssert(); | 1702 tapPeekingBarToExpandAndAssert(); |
| 1699 | 1703 |
| 1700 pressAppMenuKey(); | 1704 pressAppMenuKey(); |
| 1701 assertAppMenuVisibility(false); | 1705 assertAppMenuVisibility(false); |
| 1702 | 1706 |
| 1703 tapBasePageToClosePanel(); | 1707 tapBasePageToClosePanel(); |
| 1704 | 1708 |
| 1705 pressAppMenuKey(); | 1709 pressAppMenuKey(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1777 // -------------------------------------------------------------------------
------------------- | 1781 // -------------------------------------------------------------------------
------------------- |
| 1778 // Promo open count | 1782 // Promo open count |
| 1779 // -------------------------------------------------------------------------
------------------- | 1783 // -------------------------------------------------------------------------
------------------- |
| 1780 | 1784 |
| 1781 /** | 1785 /** |
| 1782 * Tests the promo open counter. | 1786 * Tests the promo open counter. |
| 1783 */ | 1787 */ |
| 1784 @SmallTest | 1788 @SmallTest |
| 1785 @Feature({"ContextualSearch"}) | 1789 @Feature({"ContextualSearch"}) |
| 1786 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 1790 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 1791 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1787 public void testPromoOpenCountForUndecided() throws InterruptedException, Ti
meoutException { | 1792 public void testPromoOpenCountForUndecided() throws InterruptedException, Ti
meoutException { |
| 1788 mPolicy.overrideDecidedStateForTesting(false); | 1793 mPolicy.overrideDecidedStateForTesting(false); |
| 1789 | 1794 |
| 1790 // A simple click / resolve / prefetch sequence without open should not
change the counter. | 1795 // A simple click / resolve / prefetch sequence without open should not
change the counter. |
| 1791 clickToTriggerPrefetch(); | 1796 clickToTriggerPrefetch(); |
| 1792 assertEquals(0, mPolicy.getPromoOpenCount()); | 1797 assertEquals(0, mPolicy.getPromoOpenCount()); |
| 1793 | 1798 |
| 1794 // An open should count. | 1799 // An open should count. |
| 1795 clickToExpandAndClosePanel(); | 1800 clickToExpandAndClosePanel(); |
| 1796 assertEquals(1, mPolicy.getPromoOpenCount()); | 1801 assertEquals(1, mPolicy.getPromoOpenCount()); |
| 1797 | 1802 |
| 1798 // Another open should count. | 1803 // Another open should count. |
| 1799 clickToExpandAndClosePanel(); | 1804 clickToExpandAndClosePanel(); |
| 1800 assertEquals(2, mPolicy.getPromoOpenCount()); | 1805 assertEquals(2, mPolicy.getPromoOpenCount()); |
| 1801 | 1806 |
| 1802 // Once the user has decided, we should stop counting. | 1807 // Once the user has decided, we should stop counting. |
| 1803 mPolicy.overrideDecidedStateForTesting(true); | 1808 mPolicy.overrideDecidedStateForTesting(true); |
| 1804 clickToExpandAndClosePanel(); | 1809 clickToExpandAndClosePanel(); |
| 1805 assertEquals(2, mPolicy.getPromoOpenCount()); | 1810 assertEquals(2, mPolicy.getPromoOpenCount()); |
| 1806 } | 1811 } |
| 1807 | 1812 |
| 1808 /** | 1813 /** |
| 1809 * Tests the promo open counter. | 1814 * Tests the promo open counter. |
| 1810 */ | 1815 */ |
| 1811 @SmallTest | 1816 @SmallTest |
| 1812 @Feature({"ContextualSearch"}) | 1817 @Feature({"ContextualSearch"}) |
| 1813 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 1818 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 1819 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1814 public void testPromoOpenCountForDecided() throws InterruptedException, Time
outException { | 1820 public void testPromoOpenCountForDecided() throws InterruptedException, Time
outException { |
| 1815 mPolicy.overrideDecidedStateForTesting(true); | 1821 mPolicy.overrideDecidedStateForTesting(true); |
| 1816 | 1822 |
| 1817 // An open should not count for decided users. | 1823 // An open should not count for decided users. |
| 1818 clickToExpandAndClosePanel(); | 1824 clickToExpandAndClosePanel(); |
| 1819 assertEquals(0, mPolicy.getPromoOpenCount()); | 1825 assertEquals(0, mPolicy.getPromoOpenCount()); |
| 1820 } | 1826 } |
| 1821 | 1827 |
| 1822 // -------------------------------------------------------------------------
------------------- | 1828 // -------------------------------------------------------------------------
------------------- |
| 1823 // Tap count - number of taps between opens. | 1829 // Tap count - number of taps between opens. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2081 waitForSelectionToBe("United States Intelligence"); | 2087 waitForSelectionToBe("United States Intelligence"); |
| 2082 } | 2088 } |
| 2083 | 2089 |
| 2084 /** | 2090 /** |
| 2085 * Tests that long-press triggers the Peek Promo, and expanding the Panel di
smisses it. | 2091 * Tests that long-press triggers the Peek Promo, and expanding the Panel di
smisses it. |
| 2086 */ | 2092 */ |
| 2087 @SmallTest | 2093 @SmallTest |
| 2088 @Feature({"ContextualSearch"}) | 2094 @Feature({"ContextualSearch"}) |
| 2089 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 2095 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 2090 @CommandLineFlags.Add(ContextualSearchFieldTrial.PEEK_PROMO_ENABLED + "=true
") | 2096 @CommandLineFlags.Add(ContextualSearchFieldTrial.PEEK_PROMO_ENABLED + "=true
") |
| 2097 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 2091 public void testLongPressShowsPeekPromo() throws InterruptedException, Timeo
utException { | 2098 public void testLongPressShowsPeekPromo() throws InterruptedException, Timeo
utException { |
| 2092 // Must be in undecided state in order to trigger the Peek Promo. | 2099 // Must be in undecided state in order to trigger the Peek Promo. |
| 2093 mPolicy.overrideDecidedStateForTesting(false); | 2100 mPolicy.overrideDecidedStateForTesting(false); |
| 2094 // Must have never opened the Panel in order to trigger the Peek Promo. | 2101 // Must have never opened the Panel in order to trigger the Peek Promo. |
| 2095 assertEquals(0, mPolicy.getPromoOpenCount()); | 2102 assertEquals(0, mPolicy.getPromoOpenCount()); |
| 2096 | 2103 |
| 2097 // Long press and make sure the Promo shows. | 2104 // Long press and make sure the Promo shows. |
| 2098 longPressNode("intelligence"); | 2105 longPressNode("intelligence"); |
| 2099 waitForPanelToPeek(); | 2106 waitForPanelToPeek(); |
| 2100 assertTrue(mPanel.isPeekPromoVisible()); | 2107 assertTrue(mPanel.isPeekPromoVisible()); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2583 // Simulate a tap and assert that the panel peeks. | 2590 // Simulate a tap and assert that the panel peeks. |
| 2584 simulateTapSearch("search"); | 2591 simulateTapSearch("search"); |
| 2585 | 2592 |
| 2586 // Toggle tab to non-fullscreen. | 2593 // Toggle tab to non-fullscreen. |
| 2587 FullscreenTestUtils.togglePersistentFullscreenAndAssert(tab, false, getA
ctivity()); | 2594 FullscreenTestUtils.togglePersistentFullscreenAndAssert(tab, false, getA
ctivity()); |
| 2588 | 2595 |
| 2589 // Assert that the panel is closed. | 2596 // Assert that the panel is closed. |
| 2590 waitForPanelToClose(); | 2597 waitForPanelToClose(); |
| 2591 } | 2598 } |
| 2592 } | 2599 } |
| OLD | NEW |