| 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.content.SharedPreferences; | 16 import android.content.SharedPreferences; |
| 17 import android.graphics.Point; | 17 import android.graphics.Point; |
| 18 import android.os.SystemClock; | 18 import android.os.SystemClock; |
| 19 import android.support.test.InstrumentationRegistry; | |
| 20 import android.support.test.filters.SmallTest; | 19 import android.support.test.filters.SmallTest; |
| 21 import android.text.TextUtils; | 20 import android.text.TextUtils; |
| 22 import android.view.KeyEvent; | 21 import android.view.KeyEvent; |
| 23 import android.view.View; | 22 import android.view.View; |
| 24 import android.view.ViewConfiguration; | 23 import android.view.ViewConfiguration; |
| 25 | 24 |
| 26 import org.junit.After; | |
| 27 import org.junit.Assert; | |
| 28 import org.junit.Before; | |
| 29 import org.junit.Rule; | |
| 30 import org.junit.Test; | |
| 31 import org.junit.runner.RunWith; | |
| 32 | |
| 33 import org.chromium.base.ContextUtils; | 25 import org.chromium.base.ContextUtils; |
| 34 import org.chromium.base.ThreadUtils; | 26 import org.chromium.base.ThreadUtils; |
| 35 import org.chromium.base.test.util.CallbackHelper; | 27 import org.chromium.base.test.util.CallbackHelper; |
| 36 import org.chromium.base.test.util.CommandLineFlags; | 28 import org.chromium.base.test.util.CommandLineFlags; |
| 37 import org.chromium.base.test.util.DisableIf; | 29 import org.chromium.base.test.util.DisableIf; |
| 38 import org.chromium.base.test.util.DisabledTest; | 30 import org.chromium.base.test.util.DisabledTest; |
| 39 import org.chromium.base.test.util.Feature; | 31 import org.chromium.base.test.util.Feature; |
| 40 import org.chromium.base.test.util.FlakyTest; | 32 import org.chromium.base.test.util.FlakyTest; |
| 41 import org.chromium.base.test.util.Restriction; | 33 import org.chromium.base.test.util.Restriction; |
| 42 import org.chromium.base.test.util.RetryOnFailure; | 34 import org.chromium.base.test.util.RetryOnFailure; |
| 43 import org.chromium.chrome.R; | 35 import org.chromium.chrome.R; |
| 44 import org.chromium.chrome.browser.ChromeActivity; | 36 import org.chromium.chrome.browser.ChromeActivity; |
| 45 import org.chromium.chrome.browser.ChromeSwitches; | |
| 46 import org.chromium.chrome.browser.ChromeTabbedActivity; | 37 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 47 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate; | 38 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate; |
| 48 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentProgressOb
server; | 39 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentProgressOb
server; |
| 49 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState; | 40 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState; |
| 50 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; | 41 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; |
| 51 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchBarControl; | 42 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchBarControl; |
| 52 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchCaptionControl; | 43 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchCaptionControl; |
| 53 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchImageControl; | 44 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchImageControl; |
| 54 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel; | 45 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel; |
| 55 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchQuickActionControl; | 46 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchQuickActionControl; |
| 56 import org.chromium.chrome.browser.contextualsearch.ContextualSearchFakeServer.F
akeSlowResolveSearch; | 47 import org.chromium.chrome.browser.contextualsearch.ContextualSearchFakeServer.F
akeSlowResolveSearch; |
| 57 import org.chromium.chrome.browser.contextualsearch.ContextualSearchInternalStat
eController.InternalState; | 48 import org.chromium.chrome.browser.contextualsearch.ContextualSearchInternalStat
eController.InternalState; |
| 58 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; | 49 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; |
| 59 import org.chromium.chrome.browser.firstrun.FirstRunStatus; | 50 import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
| 60 import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection; | 51 import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection; |
| 61 import org.chromium.chrome.browser.omnibox.UrlBar; | 52 import org.chromium.chrome.browser.omnibox.UrlBar; |
| 62 import org.chromium.chrome.browser.tab.Tab; | 53 import org.chromium.chrome.browser.tab.Tab; |
| 63 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; | 54 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; |
| 64 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver; | 55 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver; |
| 65 import org.chromium.chrome.browser.tabmodel.TabModelUtils; | 56 import org.chromium.chrome.browser.tabmodel.TabModelUtils; |
| 66 import org.chromium.chrome.test.ChromeActivityTestRule; | 57 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 67 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | |
| 68 import org.chromium.chrome.test.util.ChromeRestriction; | 58 import org.chromium.chrome.test.util.ChromeRestriction; |
| 69 import org.chromium.chrome.test.util.ChromeTabUtils; | 59 import org.chromium.chrome.test.util.ChromeTabUtils; |
| 70 import org.chromium.chrome.test.util.FullscreenTestUtils; | 60 import org.chromium.chrome.test.util.FullscreenTestUtils; |
| 71 import org.chromium.chrome.test.util.OmniboxTestUtils; | 61 import org.chromium.chrome.test.util.OmniboxTestUtils; |
| 72 import org.chromium.components.navigation_interception.NavigationParams; | 62 import org.chromium.components.navigation_interception.NavigationParams; |
| 73 import org.chromium.content.browser.ContentViewCore; | 63 import org.chromium.content.browser.ContentViewCore; |
| 74 import org.chromium.content.browser.test.util.Criteria; | 64 import org.chromium.content.browser.test.util.Criteria; |
| 75 import org.chromium.content.browser.test.util.CriteriaHelper; | 65 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 76 import org.chromium.content.browser.test.util.DOMUtils; | 66 import org.chromium.content.browser.test.util.DOMUtils; |
| 77 import org.chromium.content.browser.test.util.KeyUtils; | 67 import org.chromium.content.browser.test.util.KeyUtils; |
| 78 import org.chromium.content.browser.test.util.TouchCommon; | 68 import org.chromium.content.browser.test.util.TouchCommon; |
| 79 import org.chromium.net.test.EmbeddedTestServer; | 69 import org.chromium.net.test.EmbeddedTestServer; |
| 80 import org.chromium.ui.base.PageTransition; | 70 import org.chromium.ui.base.PageTransition; |
| 81 import org.chromium.ui.touch_selection.SelectionEventType; | 71 import org.chromium.ui.touch_selection.SelectionEventType; |
| 82 | 72 |
| 83 import java.util.concurrent.Callable; | 73 import java.util.concurrent.Callable; |
| 84 import java.util.concurrent.TimeoutException; | 74 import java.util.concurrent.TimeoutException; |
| 85 | 75 |
| 86 // TODO(pedrosimonetti): Create class with limited API to encapsulate the intern
als of simulations. | 76 // TODO(pedrosimonetti): Create class with limited API to encapsulate the intern
als of simulations. |
| 87 // TODO(pedrosimonetti): Separate tests into different classes grouped by type o
f tests. Examples: | 77 // TODO(pedrosimonetti): Separate tests into different classes grouped by type o
f tests. Examples: |
| 88 // Gestures (Tap, LongPress), Search Term Resolution (resolves, expand selection
, prevent preload, | 78 // Gestures (Tap, LongPress), Search Term Resolution (resolves, expand selection
, prevent preload, |
| 89 // translation), Panel interaction (tap, fling up/down, close), Content (creatio
n, loading, | 79 // translation), Panel interaction (tap, fling up/down, close), Content (creatio
n, loading, |
| 90 // visibility, history, delayed load), Tab Promotion, Policy (add tests to check
if policies | 80 // visibility, history, delayed load), Tab Promotion, Policy (add tests to check
if policies |
| 91 // affect the behavior correctly), General (remaining tests), etc. | 81 // affect the behavior correctly), General (remaining tests), etc. |
| 92 | 82 |
| 93 /** | 83 /** |
| 94 * Tests the Contextual Search Manager using instrumentation tests. | 84 * Tests the Contextual Search Manager using instrumentation tests. |
| 95 */ | 85 */ |
| 96 // NOTE: Disable online detection so we we'll default to online on test bots wit
h no network. | 86 // NOTE: Disable online detection so we we'll default to online on test bots wit
h no network. |
| 97 @RunWith(ChromeJUnit4ClassRunner.class) | |
| 98 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, | |
| 99 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG, | |
| 100 ContextualSearchFieldTrial.ONLINE_DETECTION_DISABLED}) | |
| 101 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 87 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 88 @CommandLineFlags.Add(ContextualSearchFieldTrial.ONLINE_DETECTION_DISABLED) |
| 102 @RetryOnFailure | 89 @RetryOnFailure |
| 103 public class ContextualSearchManagerTest { | 90 public class ContextualSearchManagerTest extends ChromeActivityTestCaseBase<Chro
meActivity> { |
| 104 @Rule | |
| 105 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = | |
| 106 new ChromeActivityTestRule<>(ChromeActivity.class); | |
| 107 | |
| 108 private static final String TEST_PAGE = | 91 private static final String TEST_PAGE = |
| 109 "/chrome/test/data/android/contextualsearch/tap_test.html"; | 92 "/chrome/test/data/android/contextualsearch/tap_test.html"; |
| 110 private static final int TEST_TIMEOUT = 15000; | 93 private static final int TEST_TIMEOUT = 15000; |
| 111 private static final int TEST_EXPECTED_FAILURE_TIMEOUT = 1000; | 94 private static final int TEST_EXPECTED_FAILURE_TIMEOUT = 1000; |
| 112 private static final int PLENTY_OF_TAPS = 1000; | 95 private static final int PLENTY_OF_TAPS = 1000; |
| 113 | 96 |
| 114 // TODO(donnd): get these from TemplateURL once the low-priority or Contextu
al Search API | 97 // TODO(donnd): get these from TemplateURL once the low-priority or Contextu
al Search API |
| 115 // is fully supported. | 98 // is fully supported. |
| 116 private static final String NORMAL_PRIORITY_SEARCH_ENDPOINT = "/search?"; | 99 private static final String NORMAL_PRIORITY_SEARCH_ENDPOINT = "/search?"; |
| 117 private static final String LOW_PRIORITY_SEARCH_ENDPOINT = "/s?"; | 100 private static final String LOW_PRIORITY_SEARCH_ENDPOINT = "/s?"; |
| 118 private static final String LOW_PRIORITY_INVALID_SEARCH_ENDPOINT = "/s/inval
id"; | 101 private static final String LOW_PRIORITY_INVALID_SEARCH_ENDPOINT = "/s/inval
id"; |
| 119 private static final String CONTEXTUAL_SEARCH_PREFETCH_PARAM = "&pf=c"; | 102 private static final String CONTEXTUAL_SEARCH_PREFETCH_PARAM = "&pf=c"; |
| 120 // The number of ms to delay startup for all tests. | 103 // The number of ms to delay startup for all tests. |
| 121 private static final int ACTIVITY_STARTUP_DELAY_MS = 1000; | 104 private static final int ACTIVITY_STARTUP_DELAY_MS = 1000; |
| 122 | 105 |
| 123 private ActivityMonitor mActivityMonitor; | 106 private ActivityMonitor mActivityMonitor; |
| 124 private ContextualSearchFakeServer mFakeServer; | 107 private ContextualSearchFakeServer mFakeServer; |
| 125 private ContextualSearchManager mManager; | 108 private ContextualSearchManager mManager; |
| 126 private ContextualSearchPanel mPanel; | 109 private ContextualSearchPanel mPanel; |
| 127 private ContextualSearchPolicy mPolicy; | 110 private ContextualSearchPolicy mPolicy; |
| 128 private ContextualSearchSelectionController mSelectionController; | 111 private ContextualSearchSelectionController mSelectionController; |
| 129 private EmbeddedTestServer mTestServer; | 112 private EmbeddedTestServer mTestServer; |
| 130 | 113 |
| 131 private float mDpToPx; | 114 private float mDpToPx; |
| 132 | 115 |
| 133 // State for an individual test. | 116 // State for an individual test. |
| 134 FakeSlowResolveSearch mLatestSlowResolveSearch; | 117 FakeSlowResolveSearch mLatestSlowResolveSearch; |
| 135 | 118 |
| 136 @Before | 119 public ContextualSearchManagerTest() { |
| 137 public void setUp() throws Exception { | 120 super(ChromeActivity.class); |
| 121 } |
| 122 |
| 123 @Override |
| 124 protected void setUp() throws Exception { |
| 138 // We have to set up the test server before starting the activity. | 125 // We have to set up the test server before starting the activity. |
| 139 mTestServer = EmbeddedTestServer.createAndStartServer( | 126 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); |
| 140 InstrumentationRegistry.getInstrumentation().getContext()); | |
| 141 | 127 |
| 142 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 128 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 143 @Override | 129 @Override |
| 144 public void run() { | 130 public void run() { |
| 145 FirstRunStatus.setFirstRunFlowComplete(true); | 131 FirstRunStatus.setFirstRunFlowComplete(true); |
| 146 } | 132 } |
| 147 }); | 133 }); |
| 148 mActivityTestRule.startMainActivityWithURL(mTestServer.getURL(TEST_PAGE)
); | 134 super.setUp(); |
| 149 // There's a problem with immediate startup that causes flakes due to th
e page not being | |
| 150 // ready, so specify a startup-delay of 1000 for legacy behavior. See c
rbug.com/635661. | |
| 151 // TODO(donnd): find a better way to wait for page-ready, or at least re
duce the delay! | |
| 152 Thread.sleep(ACTIVITY_STARTUP_DELAY_MS); | |
| 153 mManager = mActivityTestRule.getActivity().getContextualSearchManager(); | |
| 154 | 135 |
| 155 Assert.assertNotNull(mManager); | 136 mManager = getActivity().getContextualSearchManager(); |
| 137 |
| 138 assertNotNull(mManager); |
| 156 mPanel = mManager.getContextualSearchPanel(); | 139 mPanel = mManager.getContextualSearchPanel(); |
| 157 | 140 |
| 158 mSelectionController = mManager.getSelectionController(); | 141 mSelectionController = mManager.getSelectionController(); |
| 159 mPolicy = mManager.getContextualSearchPolicy(); | 142 mPolicy = mManager.getContextualSearchPolicy(); |
| 160 mPolicy.overrideDecidedStateForTesting(true); | 143 mPolicy.overrideDecidedStateForTesting(true); |
| 161 resetCounters(); | 144 resetCounters(); |
| 162 | 145 |
| 163 mFakeServer = new ContextualSearchFakeServer(mPolicy, this, mManager, | 146 mFakeServer = new ContextualSearchFakeServer(mPolicy, this, mManager, |
| 164 mManager.getOverlayContentDelegate(), new OverlayContentProgress
Observer(), | 147 mManager.getOverlayContentDelegate(), new OverlayContentProgress
Observer(), |
| 165 mActivityTestRule.getActivity()); | 148 getActivity()); |
| 166 | 149 |
| 167 mPanel.setOverlayPanelContentFactory(mFakeServer); | 150 mPanel.setOverlayPanelContentFactory(mFakeServer); |
| 168 mManager.setNetworkCommunicator(mFakeServer); | 151 mManager.setNetworkCommunicator(mFakeServer); |
| 169 | 152 |
| 170 registerFakeSearches(); | 153 registerFakeSearches(); |
| 171 | 154 |
| 172 IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW); | 155 IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW); |
| 173 filter.addCategory(Intent.CATEGORY_BROWSABLE); | 156 filter.addCategory(Intent.CATEGORY_BROWSABLE); |
| 174 filter.addDataScheme("market"); | 157 filter.addDataScheme("market"); |
| 175 mActivityMonitor = InstrumentationRegistry.getInstrumentation().addMonit
or( | 158 mActivityMonitor = getInstrumentation().addMonitor( |
| 176 filter, new Instrumentation.ActivityResult(Activity.RESULT_OK, n
ull), true); | 159 filter, new Instrumentation.ActivityResult(Activity.RESULT_OK, n
ull), true); |
| 177 | 160 |
| 178 mDpToPx = mActivityTestRule.getActivity().getResources().getDisplayMetri
cs().density; | 161 mDpToPx = getActivity().getResources().getDisplayMetrics().density; |
| 179 } | 162 } |
| 180 | 163 |
| 181 @After | 164 @Override |
| 182 public void tearDown() throws Exception { | 165 protected void tearDown() throws Exception { |
| 183 mTestServer.stopAndDestroyServer(); | 166 mTestServer.stopAndDestroyServer(); |
| 184 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 167 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 185 @Override | 168 @Override |
| 186 public void run() { | 169 public void run() { |
| 187 FirstRunStatus.setFirstRunFlowComplete(false); | 170 FirstRunStatus.setFirstRunFlowComplete(false); |
| 188 } | 171 } |
| 189 }); | 172 }); |
| 173 super.tearDown(); |
| 190 } | 174 } |
| 191 | 175 |
| 192 /** | 176 /** |
| 193 * Sets the online status and reloads the current Tab with our test URL. | 177 * Sets the online status and reloads the current Tab with our test URL. |
| 194 * @param isOnline Whether to go online. | 178 * @param isOnline Whether to go online. |
| 195 * @throws InterruptedException | 179 * @throws InterruptedException |
| 196 * @throws TimeoutException | 180 * @throws TimeoutException |
| 197 */ | 181 */ |
| 198 private void setOnlineStatusAndReload(boolean isOnline) | 182 private void setOnlineStatusAndReload(boolean isOnline) |
| 199 throws InterruptedException, TimeoutException { | 183 throws InterruptedException, TimeoutException { |
| 200 mFakeServer.setIsOnline(isOnline); | 184 mFakeServer.setIsOnline(isOnline); |
| 201 final String testUrl = mTestServer.getURL(TEST_PAGE); | 185 final String testUrl = mTestServer.getURL(TEST_PAGE); |
| 202 final Tab tab = mActivityTestRule.getActivity().getActivityTab(); | 186 final Tab tab = getActivity().getActivityTab(); |
| 203 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 187 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 204 @Override | 188 @Override |
| 205 public void run() { | 189 public void run() { |
| 206 tab.reload(); | 190 tab.reload(); |
| 207 } | 191 } |
| 208 }); | 192 }); |
| 209 // Make sure the page is fully loaded. | 193 // Make sure the page is fully loaded. |
| 210 ChromeTabUtils.waitForTabPageLoaded(tab, testUrl); | 194 ChromeTabUtils.waitForTabPageLoaded(tab, testUrl); |
| 211 } | 195 } |
| 212 | 196 |
| 213 //==========================================================================
================== | 197 //==========================================================================
================== |
| 214 // Public API | 198 // Public API |
| 215 //==========================================================================
================== | 199 //==========================================================================
================== |
| 216 | 200 |
| 217 /** | 201 /** |
| 218 * Simulates a long-press on the given node without waiting for the panel to
respond. | 202 * Simulates a long-press on the given node without waiting for the panel to
respond. |
| 219 * @param nodeId A string containing the node ID. | 203 * @param nodeId A string containing the node ID. |
| 220 */ | 204 */ |
| 221 public void longPressNodeWithoutWaiting(String nodeId) | 205 public void longPressNodeWithoutWaiting(String nodeId) |
| 222 throws InterruptedException, TimeoutException { | 206 throws InterruptedException, TimeoutException { |
| 223 Tab tab = mActivityTestRule.getActivity().getActivityTab(); | 207 Tab tab = getActivity().getActivityTab(); |
| 224 DOMUtils.longPressNode(tab.getContentViewCore(), nodeId); | 208 DOMUtils.longPressNode(tab.getContentViewCore(), nodeId); |
| 225 } | 209 } |
| 226 | 210 |
| 227 /** | 211 /** |
| 228 * Simulates a long-press on the given node and waits for the panel to peek. | 212 * Simulates a long-press on the given node and waits for the panel to peek. |
| 229 * @param nodeId A string containing the node ID. | 213 * @param nodeId A string containing the node ID. |
| 230 */ | 214 */ |
| 231 public void longPressNode(String nodeId) throws InterruptedException, Timeou
tException { | 215 public void longPressNode(String nodeId) throws InterruptedException, Timeou
tException { |
| 232 longPressNodeWithoutWaiting(nodeId); | 216 longPressNodeWithoutWaiting(nodeId); |
| 233 waitForPanelToPeek(); | 217 waitForPanelToPeek(); |
| 234 } | 218 } |
| 235 | 219 |
| 236 /** | 220 /** |
| 237 * Simulates a click on the given node. | 221 * Simulates a click on the given node. |
| 238 * @param nodeId A string containing the node ID. | 222 * @param nodeId A string containing the node ID. |
| 239 */ | 223 */ |
| 240 public void clickNode(String nodeId) throws InterruptedException, TimeoutExc
eption { | 224 public void clickNode(String nodeId) throws InterruptedException, TimeoutExc
eption { |
| 241 Tab tab = mActivityTestRule.getActivity().getActivityTab(); | 225 Tab tab = getActivity().getActivityTab(); |
| 242 DOMUtils.clickNode(tab.getContentViewCore(), nodeId); | 226 DOMUtils.clickNode(tab.getContentViewCore(), nodeId); |
| 243 } | 227 } |
| 244 | 228 |
| 245 /** | 229 /** |
| 246 * Waits for the selected text string to be the given string, and asserts. | 230 * Waits for the selected text string to be the given string, and asserts. |
| 247 * @param text The string to wait for the selection to become. | 231 * @param text The string to wait for the selection to become. |
| 248 */ | 232 */ |
| 249 public void waitForSelectionToBe(final String text) { | 233 public void waitForSelectionToBe(final String text) { |
| 250 CriteriaHelper.pollInstrumentationThread(Criteria.equals(text, new Calla
ble<String>() { | 234 CriteriaHelper.pollInstrumentationThread(Criteria.equals(text, new Calla
ble<String>() { |
| 251 @Override | 235 @Override |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 } | 285 } |
| 302 }, | 286 }, |
| 303 TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL); | 287 TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL); |
| 304 } | 288 } |
| 305 | 289 |
| 306 /** | 290 /** |
| 307 * Runs the given Runnable in the main thread. | 291 * Runs the given Runnable in the main thread. |
| 308 * @param runnable The Runnable. | 292 * @param runnable The Runnable. |
| 309 */ | 293 */ |
| 310 public void runOnMainSync(Runnable runnable) { | 294 public void runOnMainSync(Runnable runnable) { |
| 311 InstrumentationRegistry.getInstrumentation().runOnMainSync(runnable); | 295 getInstrumentation().runOnMainSync(runnable); |
| 296 } |
| 297 |
| 298 @Override |
| 299 public void startMainActivity() throws InterruptedException { |
| 300 startMainActivityWithURL(mTestServer.getURL(TEST_PAGE)); |
| 301 // There's a problem with immediate startup that causes flakes due to th
e page not being |
| 302 // ready, so specify a startup-delay of 1000 for legacy behavior. See c
rbug.com/635661. |
| 303 // TODO(donnd): find a better way to wait for page-ready, or at least re
duce the delay! |
| 304 Thread.sleep(ACTIVITY_STARTUP_DELAY_MS); |
| 312 } | 305 } |
| 313 | 306 |
| 314 //==========================================================================
================== | 307 //==========================================================================
================== |
| 315 // Fake Searches Helpers | 308 // Fake Searches Helpers |
| 316 //==========================================================================
================== | 309 //==========================================================================
================== |
| 317 | 310 |
| 318 /** | 311 /** |
| 319 * Simulates a long-press triggered search. | 312 * Simulates a long-press triggered search. |
| 320 * | 313 * |
| 321 * @param nodeId The id of the node to be long-pressed. | 314 * @param nodeId The id of the node to be long-pressed. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 453 |
| 461 /** | 454 /** |
| 462 * Fakes a server response with the parameters given. | 455 * Fakes a server response with the parameters given. |
| 463 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. | 456 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. |
| 464 */ | 457 */ |
| 465 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, St
ring searchTerm, | 458 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, St
ring searchTerm, |
| 466 String displayText, String alternateTerm, String mid, boolean doPrev
entPreload, | 459 String displayText, String alternateTerm, String mid, boolean doPrev
entPreload, |
| 467 int startAdjust, int endAdjust, String contextLanguage, String thumb
nailUrl, | 460 int startAdjust, int endAdjust, String contextLanguage, String thumb
nailUrl, |
| 468 String caption, String quickActionUri, int quickActionCategory) { | 461 String caption, String quickActionUri, int quickActionCategory) { |
| 469 if (mFakeServer.getSearchTermRequested() != null) { | 462 if (mFakeServer.getSearchTermRequested() != null) { |
| 470 InstrumentationRegistry.getInstrumentation().runOnMainSync(new FakeR
esponseOnMainThread( | 463 getInstrumentation().runOnMainSync(new FakeResponseOnMainThread(isNe
tworkUnavailable, |
| 471 isNetworkUnavailable, responseCode, searchTerm, displayText,
alternateTerm, mid, | 464 responseCode, searchTerm, displayText, alternateTerm, mid, d
oPreventPreload, |
| 472 doPreventPreload, startAdjust, endAdjust, contextLanguage, t
humbnailUrl, | 465 startAdjust, endAdjust, contextLanguage, thumbnailUrl, capti
on, |
| 473 caption, quickActionUri, quickActionCategory)); | 466 quickActionUri, quickActionCategory)); |
| 474 } | 467 } |
| 475 } | 468 } |
| 476 | 469 |
| 477 //==========================================================================
================== | 470 //==========================================================================
================== |
| 478 // Content Helpers | 471 // Content Helpers |
| 479 //==========================================================================
================== | 472 //==========================================================================
================== |
| 480 | 473 |
| 481 /** | 474 /** |
| 482 * @return The Panel's ContentViewCore. | 475 * @return The Panel's ContentViewCore. |
| 483 */ | 476 */ |
| 484 private ContentViewCore getPanelContentViewCore() { | 477 private ContentViewCore getPanelContentViewCore() { |
| 485 return mPanel.getContentViewCore(); | 478 return mPanel.getContentViewCore(); |
| 486 } | 479 } |
| 487 | 480 |
| 488 /** | 481 /** |
| 489 * @return Whether the Panel's ContentViewCore is visible. | 482 * @return Whether the Panel's ContentViewCore is visible. |
| 490 */ | 483 */ |
| 491 private boolean isContentViewCoreVisible() { | 484 private boolean isContentViewCoreVisible() { |
| 492 ContextualSearchFakeServer.ContentViewCoreWrapper contentViewCore = | 485 ContextualSearchFakeServer.ContentViewCoreWrapper contentViewCore = |
| 493 (ContextualSearchFakeServer.ContentViewCoreWrapper) getPanelCont
entViewCore(); | 486 (ContextualSearchFakeServer.ContentViewCoreWrapper) getPanelCont
entViewCore(); |
| 494 return contentViewCore != null ? contentViewCore.isVisible() : false; | 487 return contentViewCore != null ? contentViewCore.isVisible() : false; |
| 495 } | 488 } |
| 496 | 489 |
| 497 /** | 490 /** |
| 498 * Asserts that the Panel's ContentViewCore is created. | 491 * Asserts that the Panel's ContentViewCore is created. |
| 499 */ | 492 */ |
| 500 private void assertContentViewCoreCreated() { | 493 private void assertContentViewCoreCreated() { |
| 501 Assert.assertNotNull(getPanelContentViewCore()); | 494 assertNotNull(getPanelContentViewCore()); |
| 502 } | 495 } |
| 503 | 496 |
| 504 /** | 497 /** |
| 505 * Asserts that the Panel's ContentViewCore is not created. | 498 * Asserts that the Panel's ContentViewCore is not created. |
| 506 */ | 499 */ |
| 507 private void assertNoContentViewCore() { | 500 private void assertNoContentViewCore() { |
| 508 Assert.assertNull(getPanelContentViewCore()); | 501 assertNull(getPanelContentViewCore()); |
| 509 } | 502 } |
| 510 | 503 |
| 511 /** | 504 /** |
| 512 * Asserts that the Panel's ContentViewCore is visible. | 505 * Asserts that the Panel's ContentViewCore is visible. |
| 513 */ | 506 */ |
| 514 private void assertContentViewCoreVisible() { | 507 private void assertContentViewCoreVisible() { |
| 515 Assert.assertTrue(isContentViewCoreVisible()); | 508 assertTrue(isContentViewCoreVisible()); |
| 516 } | 509 } |
| 517 | 510 |
| 518 /** | 511 /** |
| 519 * Asserts that the Panel's ContentViewCore onShow() method was never called
. | 512 * Asserts that the Panel's ContentViewCore onShow() method was never called
. |
| 520 */ | 513 */ |
| 521 private void assertNeverCalledContentViewCoreOnShow() { | 514 private void assertNeverCalledContentViewCoreOnShow() { |
| 522 Assert.assertFalse(mFakeServer.didEverCallContentViewCoreOnShow()); | 515 assertFalse(mFakeServer.didEverCallContentViewCoreOnShow()); |
| 523 } | 516 } |
| 524 | 517 |
| 525 /** | 518 /** |
| 526 * Asserts that the Panel's ContentViewCore is created | 519 * Asserts that the Panel's ContentViewCore is created |
| 527 */ | 520 */ |
| 528 private void assertContentViewCoreCreatedButNeverMadeVisible() { | 521 private void assertContentViewCoreCreatedButNeverMadeVisible() { |
| 529 assertContentViewCoreCreated(); | 522 assertContentViewCoreCreated(); |
| 530 Assert.assertFalse(isContentViewCoreVisible()); | 523 assertFalse(isContentViewCoreVisible()); |
| 531 assertNeverCalledContentViewCoreOnShow(); | 524 assertNeverCalledContentViewCoreOnShow(); |
| 532 } | 525 } |
| 533 | 526 |
| 534 /** | 527 /** |
| 535 * Fakes navigation of the Content View to the URL that was previously reque
sted. | 528 * Fakes navigation of the Content View to the URL that was previously reque
sted. |
| 536 * @param isFailure whether the request resulted in a failure. | 529 * @param isFailure whether the request resulted in a failure. |
| 537 */ | 530 */ |
| 538 private void fakeContentViewDidNavigate(boolean isFailure) { | 531 private void fakeContentViewDidNavigate(boolean isFailure) { |
| 539 String url = mFakeServer.getLoadedUrl(); | 532 String url = mFakeServer.getLoadedUrl(); |
| 540 mManager.getOverlayContentDelegate().onMainFrameNavigation(url, false, i
sFailure); | 533 mManager.getOverlayContentDelegate().onMainFrameNavigation(url, false, i
sFailure); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 private void clickWordNode(String nodeId) throws InterruptedException, Timeo
utException { | 571 private void clickWordNode(String nodeId) throws InterruptedException, Timeo
utException { |
| 579 clickNode(nodeId); | 572 clickNode(nodeId); |
| 580 waitForPanelToPeek(); | 573 waitForPanelToPeek(); |
| 581 } | 574 } |
| 582 | 575 |
| 583 /** | 576 /** |
| 584 * Simulates a key press. | 577 * Simulates a key press. |
| 585 * @param keycode The key's code. | 578 * @param keycode The key's code. |
| 586 */ | 579 */ |
| 587 private void pressKey(int keycode) { | 580 private void pressKey(int keycode) { |
| 588 KeyUtils.singleKeyEventActivity(InstrumentationRegistry.getInstrumentati
on(), | 581 KeyUtils.singleKeyEventActivity(getInstrumentation(), getActivity(), key
code); |
| 589 mActivityTestRule.getActivity(), keycode); | |
| 590 } | 582 } |
| 591 | 583 |
| 592 /** | 584 /** |
| 593 * Simulates pressing back button. | 585 * Simulates pressing back button. |
| 594 */ | 586 */ |
| 595 private void pressBackButton() { | 587 private void pressBackButton() { |
| 596 pressKey(KeyEvent.KEYCODE_BACK); | 588 pressKey(KeyEvent.KEYCODE_BACK); |
| 597 } | 589 } |
| 598 | 590 |
| 599 /** | 591 /** |
| 600 * @return The selected text. | 592 * @return The selected text. |
| 601 */ | 593 */ |
| 602 private String getSelectedText() { | 594 private String getSelectedText() { |
| 603 return mSelectionController.getSelectedText(); | 595 return mSelectionController.getSelectedText(); |
| 604 } | 596 } |
| 605 | 597 |
| 606 /** | 598 /** |
| 607 * Asserts that the loaded search term matches the provided value. | 599 * Asserts that the loaded search term matches the provided value. |
| 608 * @param searchTerm The provided search term. | 600 * @param searchTerm The provided search term. |
| 609 */ | 601 */ |
| 610 private void assertLoadedSearchTermMatches(String searchTerm) { | 602 private void assertLoadedSearchTermMatches(String searchTerm) { |
| 611 boolean doesMatch = false; | 603 boolean doesMatch = false; |
| 612 String loadedUrl = mFakeServer.getLoadedUrl(); | 604 String loadedUrl = mFakeServer.getLoadedUrl(); |
| 613 doesMatch = loadedUrl != null && loadedUrl.contains("q=" + searchTerm); | 605 doesMatch = loadedUrl != null && loadedUrl.contains("q=" + searchTerm); |
| 614 String message = loadedUrl == null ? "but there was no loaded URL!" | 606 String message = loadedUrl == null ? "but there was no loaded URL!" |
| 615 : "in URL: " + loadedUrl; | 607 : "in URL: " + loadedUrl; |
| 616 Assert.assertTrue( | 608 assertTrue("Expected to find searchTerm '" + searchTerm + "', " + messag
e, doesMatch); |
| 617 "Expected to find searchTerm '" + searchTerm + "', " + message,
doesMatch); | |
| 618 } | 609 } |
| 619 | 610 |
| 620 /** | 611 /** |
| 621 * Asserts that the given parameters are present in the most recently loaded
URL. | 612 * Asserts that the given parameters are present in the most recently loaded
URL. |
| 622 */ | 613 */ |
| 623 private void assertContainsParameters(String searchTerm, String alternateTer
m) { | 614 private void assertContainsParameters(String searchTerm, String alternateTer
m) { |
| 624 Assert.assertTrue(mFakeServer.getSearchTermRequested() == null | 615 assertTrue(mFakeServer.getSearchTermRequested() == null |
| 625 || mFakeServer.getLoadedUrl().contains(searchTerm) | 616 || mFakeServer.getLoadedUrl().contains(searchTerm) |
| 626 && mFakeServer.getLoadedUrl().contains(alternateTerm)); | 617 && mFakeServer.getLoadedUrl().contains(alternateTerm)); |
| 627 } | 618 } |
| 628 | 619 |
| 629 /** | 620 /** |
| 630 * Asserts that a Search Term has been requested. | 621 * Asserts that a Search Term has been requested. |
| 631 */ | 622 */ |
| 632 private void assertSearchTermRequested() { | 623 private void assertSearchTermRequested() { |
| 633 Assert.assertNotNull(mFakeServer.getSearchTermRequested()); | 624 assertNotNull(mFakeServer.getSearchTermRequested()); |
| 634 } | 625 } |
| 635 | 626 |
| 636 /** | 627 /** |
| 637 * Asserts that there has not been any Search Term requested. | 628 * Asserts that there has not been any Search Term requested. |
| 638 */ | 629 */ |
| 639 private void assertSearchTermNotRequested() { | 630 private void assertSearchTermNotRequested() { |
| 640 Assert.assertNull(mFakeServer.getSearchTermRequested()); | 631 assertNull(mFakeServer.getSearchTermRequested()); |
| 641 } | 632 } |
| 642 | 633 |
| 643 /** | 634 /** |
| 644 * Asserts that the panel is currently closed or in an undefined state. | 635 * Asserts that the panel is currently closed or in an undefined state. |
| 645 */ | 636 */ |
| 646 private void assertPanelClosedOrUndefined() { | 637 private void assertPanelClosedOrUndefined() { |
| 647 boolean success = false; | 638 boolean success = false; |
| 648 if (mPanel == null) { | 639 if (mPanel == null) { |
| 649 success = true; | 640 success = true; |
| 650 } else { | 641 } else { |
| 651 PanelState panelState = mPanel.getPanelState(); | 642 PanelState panelState = mPanel.getPanelState(); |
| 652 success = panelState == PanelState.CLOSED || panelState == PanelStat
e.UNDEFINED; | 643 success = panelState == PanelState.CLOSED || panelState == PanelStat
e.UNDEFINED; |
| 653 } | 644 } |
| 654 Assert.assertTrue(success); | 645 assertTrue(success); |
| 655 } | 646 } |
| 656 | 647 |
| 657 /** | 648 /** |
| 658 * Asserts that the panel is currently in the "peeking" state (just showing
the Bar). | 649 * Asserts that the panel is currently in the "peeking" state (just showing
the Bar). |
| 659 */ | 650 */ |
| 660 private void assertPanelPeeked() { | 651 private void assertPanelPeeked() { |
| 661 Assert.assertTrue(mPanel.getPanelState() == PanelState.PEEKED); | 652 assertTrue(mPanel.getPanelState() == PanelState.PEEKED); |
| 662 } | 653 } |
| 663 | 654 |
| 664 /** | 655 /** |
| 665 * Asserts that no URL has been loaded in the Overlay Panel. | 656 * Asserts that no URL has been loaded in the Overlay Panel. |
| 666 */ | 657 */ |
| 667 private void assertLoadedNoUrl() { | 658 private void assertLoadedNoUrl() { |
| 668 Assert.assertTrue("Requested a search or preload when none was expected!
", | 659 assertTrue("Requested a search or preload when none was expected!", |
| 669 mFakeServer.getLoadedUrl() == null); | 660 mFakeServer.getLoadedUrl() == null); |
| 670 } | 661 } |
| 671 | 662 |
| 672 /** | 663 /** |
| 673 * Asserts that a low-priority URL has been loaded in the Overlay Panel. | 664 * Asserts that a low-priority URL has been loaded in the Overlay Panel. |
| 674 */ | 665 */ |
| 675 private void assertLoadedLowPriorityUrl() { | 666 private void assertLoadedLowPriorityUrl() { |
| 676 String message = "Expected a low priority search request URL, but got " | 667 String message = "Expected a low priority search request URL, but got " |
| 677 + (mFakeServer.getLoadedUrl() != null ? mFakeServer.getLoadedUrl
() : "null"); | 668 + (mFakeServer.getLoadedUrl() != null ? mFakeServer.getLoadedUrl
() : "null"); |
| 678 Assert.assertTrue(message, | 669 assertTrue(message, mFakeServer.getLoadedUrl() != null |
| 679 mFakeServer.getLoadedUrl() != null | 670 && mFakeServer.getLoadedUrl().contains(LOW_PRIORITY_SEARCH_ENDPO
INT)); |
| 680 && mFakeServer.getLoadedUrl().contains(LOW_PRIORITY_SEAR
CH_ENDPOINT)); | 671 assertTrue("Low priority request does not have the required prefetch par
ameter!", |
| 681 Assert.assertTrue("Low priority request does not have the required prefe
tch parameter!", | |
| 682 mFakeServer.getLoadedUrl() != null | 672 mFakeServer.getLoadedUrl() != null |
| 683 && mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARCH
_PREFETCH_PARAM)); | 673 && mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARCH
_PREFETCH_PARAM)); |
| 684 } | 674 } |
| 685 | 675 |
| 686 /** | 676 /** |
| 687 * Asserts that a low-priority URL that is intentionally invalid has been lo
aded in the Overlay | 677 * Asserts that a low-priority URL that is intentionally invalid has been lo
aded in the Overlay |
| 688 * Panel (in order to produce an error). | 678 * Panel (in order to produce an error). |
| 689 */ | 679 */ |
| 690 private void assertLoadedLowPriorityInvalidUrl() { | 680 private void assertLoadedLowPriorityInvalidUrl() { |
| 691 String message = "Expected a low priority invalid search request URL, bu
t got " | 681 String message = "Expected a low priority invalid search request URL, bu
t got " |
| 692 + (String.valueOf(mFakeServer.getLoadedUrl())); | 682 + (String.valueOf(mFakeServer.getLoadedUrl())); |
| 693 Assert.assertTrue(message, | 683 assertTrue(message, mFakeServer.getLoadedUrl() != null |
| 694 mFakeServer.getLoadedUrl() != null | |
| 695 && mFakeServer.getLoadedUrl().contains( | 684 && mFakeServer.getLoadedUrl().contains( |
| 696 LOW_PRIORITY_INVALID_SEARCH_ENDPOINT)); | 685 LOW_PRIORITY_INVALID_SEARCH_ENDPOINT)); |
| 697 Assert.assertTrue("Low priority request does not have the required prefe
tch parameter!", | 686 assertTrue("Low priority request does not have the required prefetch par
ameter!", |
| 698 mFakeServer.getLoadedUrl() != null | 687 mFakeServer.getLoadedUrl() != null |
| 699 && mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARCH
_PREFETCH_PARAM)); | 688 && mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARCH
_PREFETCH_PARAM)); |
| 700 } | 689 } |
| 701 | 690 |
| 702 /** | 691 /** |
| 703 * Asserts that a normal priority URL has been loaded in the Overlay Panel. | 692 * Asserts that a normal priority URL has been loaded in the Overlay Panel. |
| 704 */ | 693 */ |
| 705 private void assertLoadedNormalPriorityUrl() { | 694 private void assertLoadedNormalPriorityUrl() { |
| 706 String message = "Expected a normal priority search request URL, but got
" | 695 String message = "Expected a normal priority search request URL, but got
" |
| 707 + (mFakeServer.getLoadedUrl() != null ? mFakeServer.getLoadedUrl
() : "null"); | 696 + (mFakeServer.getLoadedUrl() != null ? mFakeServer.getLoadedUrl
() : "null"); |
| 708 Assert.assertTrue(message, | 697 assertTrue(message, mFakeServer.getLoadedUrl() != null |
| 709 mFakeServer.getLoadedUrl() != null | 698 && mFakeServer.getLoadedUrl().contains(NORMAL_PRIORITY_SEARCH_EN
DPOINT)); |
| 710 && mFakeServer.getLoadedUrl().contains(NORMAL_PRIORITY_S
EARCH_ENDPOINT)); | 699 assertTrue("Normal priority request should not have the prefetch paramet
er, but did!", |
| 711 Assert.assertTrue( | |
| 712 "Normal priority request should not have the prefetch parameter,
but did!", | |
| 713 mFakeServer.getLoadedUrl() != null | 700 mFakeServer.getLoadedUrl() != null |
| 714 && !mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARC
H_PREFETCH_PARAM)); | 701 && !mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARC
H_PREFETCH_PARAM)); |
| 715 } | 702 } |
| 716 | 703 |
| 717 /** | 704 /** |
| 718 * Asserts that no URLs have been loaded in the Overlay Panel since the last
{@link reset}. | 705 * Asserts that no URLs have been loaded in the Overlay Panel since the last
{@link reset}. |
| 719 */ | 706 */ |
| 720 private void assertNoSearchesLoaded() { | 707 private void assertNoSearchesLoaded() { |
| 721 Assert.assertEquals(0, mFakeServer.getLoadedUrlCount()); | 708 assertEquals(0, mFakeServer.getLoadedUrlCount()); |
| 722 assertLoadedNoUrl(); | 709 assertLoadedNoUrl(); |
| 723 } | 710 } |
| 724 | 711 |
| 725 /** | 712 /** |
| 726 * Asserts that the tap triggered promo counter is enabled and at the specif
ied count. | 713 * Asserts that the tap triggered promo counter is enabled and at the specif
ied count. |
| 727 */ | 714 */ |
| 728 private void assertTapPromoCounterEnabledAt(int expectedCount) { | 715 private void assertTapPromoCounterEnabledAt(int expectedCount) { |
| 729 Assert.assertTrue(mPolicy.getPromoTapCounter().isEnabled()); | 716 assertTrue(mPolicy.getPromoTapCounter().isEnabled()); |
| 730 Assert.assertEquals(expectedCount, mPolicy.getPromoTapCounter().getCount
()); | 717 assertEquals(expectedCount, mPolicy.getPromoTapCounter().getCount()); |
| 731 } | 718 } |
| 732 | 719 |
| 733 /** | 720 /** |
| 734 * Asserts that the tap triggered promo counter is disabled and at the speci
fied count. | 721 * Asserts that the tap triggered promo counter is disabled and at the speci
fied count. |
| 735 */ | 722 */ |
| 736 private void assertTapPromoCounterDisabledAt(int expectedCount) { | 723 private void assertTapPromoCounterDisabledAt(int expectedCount) { |
| 737 Assert.assertFalse(mPolicy.getPromoTapCounter().isEnabled()); | 724 assertFalse(mPolicy.getPromoTapCounter().isEnabled()); |
| 738 Assert.assertEquals(expectedCount, mPolicy.getPromoTapCounter().getCount
()); | 725 assertEquals(expectedCount, mPolicy.getPromoTapCounter().getCount()); |
| 739 } | 726 } |
| 740 | 727 |
| 741 /** | 728 /** |
| 742 * Waits for the Search Panel (the Search Bar) to peek up from the bottom, a
nd asserts that it | 729 * Waits for the Search Panel (the Search Bar) to peek up from the bottom, a
nd asserts that it |
| 743 * did peek. | 730 * did peek. |
| 744 * @throws InterruptedException | 731 * @throws InterruptedException |
| 745 */ | 732 */ |
| 746 private void waitForPanelToPeek() throws InterruptedException { | 733 private void waitForPanelToPeek() throws InterruptedException { |
| 747 waitForPanelToEnterState(PanelState.PEEKED); | 734 waitForPanelToEnterState(PanelState.PEEKED); |
| 748 } | 735 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 */ | 789 */ |
| 803 private void assertPanelStillInState(final PanelState initialState) | 790 private void assertPanelStillInState(final PanelState initialState) |
| 804 throws InterruptedException { | 791 throws InterruptedException { |
| 805 boolean didChangeState = false; | 792 boolean didChangeState = false; |
| 806 long startTime = SystemClock.uptimeMillis(); | 793 long startTime = SystemClock.uptimeMillis(); |
| 807 while (!didChangeState | 794 while (!didChangeState |
| 808 && SystemClock.uptimeMillis() - startTime < TEST_EXPECTED_FAILUR
E_TIMEOUT) { | 795 && SystemClock.uptimeMillis() - startTime < TEST_EXPECTED_FAILUR
E_TIMEOUT) { |
| 809 Thread.sleep(DEFAULT_POLLING_INTERVAL); | 796 Thread.sleep(DEFAULT_POLLING_INTERVAL); |
| 810 didChangeState = mPanel.getPanelState() != initialState; | 797 didChangeState = mPanel.getPanelState() != initialState; |
| 811 } | 798 } |
| 812 Assert.assertFalse(didChangeState); | 799 assertFalse(didChangeState); |
| 813 } | 800 } |
| 814 | 801 |
| 815 /** | 802 /** |
| 816 * Waits for the manager to finish processing a gesture. | 803 * Waits for the manager to finish processing a gesture. |
| 817 * Tells the manager that a gesture has started, and then waits for it to co
mplete. | 804 * Tells the manager that a gesture has started, and then waits for it to co
mplete. |
| 818 * @throws InterruptedException | 805 * @throws InterruptedException |
| 819 */ | 806 */ |
| 820 private void waitForGestureProcessing() { | 807 private void waitForGestureProcessing() { |
| 821 CriteriaHelper.pollInstrumentationThread( | 808 CriteriaHelper.pollInstrumentationThread( |
| 822 new Criteria("Gesture processing did not complete.") { | 809 new Criteria("Gesture processing did not complete.") { |
| 823 @Override | 810 @Override |
| 824 public boolean isSatisfied() { | 811 public boolean isSatisfied() { |
| 825 return !mSelectionController.wasAnyTapGestureDetected(); | 812 return !mSelectionController.wasAnyTapGestureDetected(); |
| 826 } | 813 } |
| 827 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL); | 814 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL); |
| 828 } | 815 } |
| 829 | 816 |
| 830 /** | 817 /** |
| 831 * Shorthand for a common sequence: | 818 * Shorthand for a common sequence: |
| 832 * 1) Waits for gesture processing, | 819 * 1) Waits for gesture processing, |
| 833 * 2) Waits for the panel to close, | 820 * 2) Waits for the panel to close, |
| 834 * 3) Asserts that there is no selection and that the panel closed. | 821 * 3) Asserts that there is no selection and that the panel closed. |
| 835 * @throws InterruptedException | 822 * @throws InterruptedException |
| 836 */ | 823 */ |
| 837 private void waitForGestureToClosePanelAndAssertNoSelection() throws Interru
ptedException { | 824 private void waitForGestureToClosePanelAndAssertNoSelection() throws Interru
ptedException { |
| 838 waitForGestureProcessing(); | 825 waitForGestureProcessing(); |
| 839 waitForPanelToClose(); | 826 waitForPanelToClose(); |
| 840 assertPanelClosedOrUndefined(); | 827 assertPanelClosedOrUndefined(); |
| 841 Assert.assertTrue(TextUtils.isEmpty(getSelectedText())); | 828 assertTrue(TextUtils.isEmpty(getSelectedText())); |
| 842 } | 829 } |
| 843 | 830 |
| 844 /** | 831 /** |
| 845 * Waits for the selection to be empty. | 832 * Waits for the selection to be empty. |
| 846 * Use this method any time a test repeatedly establishes and dissolves a se
lection to ensure | 833 * Use this method any time a test repeatedly establishes and dissolves a se
lection to ensure |
| 847 * that the selection has been completely dissolved before simulating the ne
xt selection event. | 834 * that the selection has been completely dissolved before simulating the ne
xt selection event. |
| 848 * This is needed because the renderer's notification of a selection going a
way is async, | 835 * This is needed because the renderer's notification of a selection going a
way is async, |
| 849 * and a subsequent tap may think there's a current selection until it has b
een dissolved. | 836 * and a subsequent tap may think there's a current selection until it has b
een dissolved. |
| 850 */ | 837 */ |
| 851 private void waitForSelectionEmpty() { | 838 private void waitForSelectionEmpty() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 872 // short that this shouldn't conflict with tap refinement by the user. | 859 // short that this shouldn't conflict with tap refinement by the user. |
| 873 Thread.sleep(ViewConfiguration.getDoubleTapTimeout()); | 860 Thread.sleep(ViewConfiguration.getDoubleTapTimeout()); |
| 874 } | 861 } |
| 875 | 862 |
| 876 /** | 863 /** |
| 877 * Generate a fling sequence from the given start/end X,Y percentages, for t
he given steps. | 864 * Generate a fling sequence from the given start/end X,Y percentages, for t
he given steps. |
| 878 * Works in either landscape or portrait orientation. | 865 * Works in either landscape or portrait orientation. |
| 879 */ | 866 */ |
| 880 private void fling(float startX, float startY, float endX, float endY, int s
tepCount) { | 867 private void fling(float startX, float startY, float endX, float endY, int s
tepCount) { |
| 881 Point size = new Point(); | 868 Point size = new Point(); |
| 882 mActivityTestRule.getActivity().getWindowManager().getDefaultDisplay().g
etSize(size); | 869 getActivity().getWindowManager().getDefaultDisplay().getSize(size); |
| 883 float dragStartX = size.x * startX; | 870 float dragStartX = size.x * startX; |
| 884 float dragEndX = size.x * endX; | 871 float dragEndX = size.x * endX; |
| 885 float dragStartY = size.y * startY; | 872 float dragStartY = size.y * startY; |
| 886 float dragEndY = size.y * endY; | 873 float dragEndY = size.y * endY; |
| 887 long downTime = SystemClock.uptimeMillis(); | 874 long downTime = SystemClock.uptimeMillis(); |
| 888 TouchCommon.dragStart(mActivityTestRule.getActivity(), dragStartX, dragS
tartY, downTime); | 875 dragStart(dragStartX, dragStartY, downTime); |
| 889 TouchCommon.dragTo(mActivityTestRule.getActivity(), dragStartX, dragEndX
, dragStartY, | 876 dragTo(dragStartX, dragEndX, dragStartY, dragEndY, stepCount, downTime); |
| 890 dragEndY, stepCount, downTime); | 877 dragEnd(dragEndX, dragEndY, downTime); |
| 891 TouchCommon.dragEnd(mActivityTestRule.getActivity(), dragEndX, dragEndY,
downTime); | |
| 892 } | 878 } |
| 893 | 879 |
| 894 /** | 880 /** |
| 895 * Generate a swipe sequence from the given start/end X,Y percentages, for t
he given steps. | 881 * Generate a swipe sequence from the given start/end X,Y percentages, for t
he given steps. |
| 896 * Works in either landscape or portrait orientation. | 882 * Works in either landscape or portrait orientation. |
| 897 */ | 883 */ |
| 898 private void swipe(float startX, float startY, float endX, float endY, int s
tepCount) { | 884 private void swipe(float startX, float startY, float endX, float endY, int s
tepCount) { |
| 899 Point size = new Point(); | 885 Point size = new Point(); |
| 900 mActivityTestRule.getActivity().getWindowManager().getDefaultDisplay().g
etSize(size); | 886 getActivity().getWindowManager().getDefaultDisplay().getSize(size); |
| 901 float dragStartX = size.x * startX; | 887 float dragStartX = size.x * startX; |
| 902 float dragEndX = size.x * endX; | 888 float dragEndX = size.x * endX; |
| 903 float dragStartY = size.y * startY; | 889 float dragStartY = size.y * startY; |
| 904 float dragEndY = size.y * endY; | 890 float dragEndY = size.y * endY; |
| 905 int halfCount = stepCount / 2; | 891 int halfCount = stepCount / 2; |
| 906 long downTime = SystemClock.uptimeMillis(); | 892 long downTime = SystemClock.uptimeMillis(); |
| 907 TouchCommon.dragStart(mActivityTestRule.getActivity(), dragStartX, dragS
tartY, downTime); | 893 dragStart(dragStartX, dragStartY, downTime); |
| 908 TouchCommon.dragTo(mActivityTestRule.getActivity(), dragStartX, dragEndX
, dragStartY, | 894 dragTo(dragStartX, dragEndX, dragStartY, dragEndY, halfCount, downTime); |
| 909 dragEndY, halfCount, downTime); | |
| 910 // Generate events in the stationary end position in order to simulate a
"pause" in | 895 // Generate events in the stationary end position in order to simulate a
"pause" in |
| 911 // the movement, therefore preventing this gesture from being interprete
d as a fling. | 896 // the movement, therefore preventing this gesture from being interprete
d as a fling. |
| 912 TouchCommon.dragTo(mActivityTestRule.getActivity(), dragEndX, dragEndX,
dragEndY, dragEndY, | 897 dragTo(dragEndX, dragEndX, dragEndY, dragEndY, halfCount, downTime); |
| 913 halfCount, downTime); | 898 dragEnd(dragEndX, dragEndY, downTime); |
| 914 TouchCommon.dragEnd(mActivityTestRule.getActivity(), dragEndX, dragEndY,
downTime); | |
| 915 } | 899 } |
| 916 | 900 |
| 917 /** | 901 /** |
| 918 * Flings the panel up to its expanded state. | 902 * Flings the panel up to its expanded state. |
| 919 */ | 903 */ |
| 920 private void flingPanelUp() { | 904 private void flingPanelUp() { |
| 921 // TODO(pedrosimonetti): Consider using a swipe method instead. | 905 // TODO(pedrosimonetti): Consider using a swipe method instead. |
| 922 fling(0.5f, 0.95f, 0.5f, 0.55f, 1000); | 906 fling(0.5f, 0.95f, 0.5f, 0.55f, 1000); |
| 923 } | 907 } |
| 924 | 908 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 // long press and trying to close with the bar peeking, with a long pres
s selection | 942 // long press and trying to close with the bar peeking, with a long pres
s selection |
| 959 // established). | 943 // established). |
| 960 tapBasePage(0.9f, 0.35f); | 944 tapBasePage(0.9f, 0.35f); |
| 961 waitForPanelToClose(); | 945 waitForPanelToClose(); |
| 962 } | 946 } |
| 963 | 947 |
| 964 /** | 948 /** |
| 965 * Taps the base page at the given x, y position. | 949 * Taps the base page at the given x, y position. |
| 966 */ | 950 */ |
| 967 private void tapBasePage(float x, float y) { | 951 private void tapBasePage(float x, float y) { |
| 968 View root = mActivityTestRule.getActivity().getWindow().getDecorView().g
etRootView(); | 952 View root = getActivity().getWindow().getDecorView().getRootView(); |
| 969 x *= root.getWidth(); | 953 x *= root.getWidth(); |
| 970 y *= root.getHeight(); | 954 y *= root.getHeight(); |
| 971 TouchCommon.singleClickView(root, (int) x, (int) y); | 955 TouchCommon.singleClickView(root, (int) x, (int) y); |
| 972 } | 956 } |
| 973 | 957 |
| 974 /** | 958 /** |
| 975 * Click various places to cause the panel to show, expand, then close. | 959 * Click various places to cause the panel to show, expand, then close. |
| 976 */ | 960 */ |
| 977 private void clickToExpandAndClosePanel() throws InterruptedException, Timeo
utException { | 961 private void clickToExpandAndClosePanel() throws InterruptedException, Timeo
utException { |
| 978 clickWordNode("states"); | 962 clickWordNode("states"); |
| 979 tapBarToExpandAndClosePanel(); | 963 tapBarToExpandAndClosePanel(); |
| 980 waitForSelectionEmpty(); | 964 waitForSelectionEmpty(); |
| 981 } | 965 } |
| 982 | 966 |
| 983 /** | 967 /** |
| 984 * Tap on the peeking Bar to expand the panel, then taps on the base page to
close it. | 968 * Tap on the peeking Bar to expand the panel, then taps on the base page to
close it. |
| 985 */ | 969 */ |
| 986 private void tapBarToExpandAndClosePanel() throws InterruptedException { | 970 private void tapBarToExpandAndClosePanel() throws InterruptedException { |
| 987 tapPeekingBarToExpandAndAssert(); | 971 tapPeekingBarToExpandAndAssert(); |
| 988 tapBasePageToClosePanel(); | 972 tapBasePageToClosePanel(); |
| 989 } | 973 } |
| 990 | 974 |
| 991 /** | 975 /** |
| 992 * Generate a click in the middle of panel's bar. | 976 * Generate a click in the middle of panel's bar. |
| 993 * TODO(donnd): Replace this method with panelBarClick since this appears to
be unreliable. | 977 * TODO(donnd): Replace this method with panelBarClick since this appears to
be unreliable. |
| 994 */ | 978 */ |
| 995 private void clickPanelBar() { | 979 private void clickPanelBar() { |
| 996 View root = mActivityTestRule.getActivity().getWindow().getDecorView().g
etRootView(); | 980 View root = getActivity().getWindow().getDecorView().getRootView(); |
| 997 float tapX = ((mPanel.getOffsetX() + mPanel.getWidth()) / 2f) * mDpToPx; | 981 float tapX = ((mPanel.getOffsetX() + mPanel.getWidth()) / 2f) * mDpToPx; |
| 998 float tapY = (mPanel.getOffsetY() + (mPanel.getBarContainerHeight() / 2f
)) * mDpToPx; | 982 float tapY = (mPanel.getOffsetY() + (mPanel.getBarContainerHeight() / 2f
)) * mDpToPx; |
| 999 | 983 |
| 1000 TouchCommon.singleClickView(root, (int) tapX, (int) tapY); | 984 TouchCommon.singleClickView(root, (int) tapX, (int) tapY); |
| 1001 } | 985 } |
| 1002 | 986 |
| 1003 /** | 987 /** |
| 1004 * Taps the peeking bar to expand the panel | 988 * Taps the peeking bar to expand the panel |
| 1005 */ | 989 */ |
| 1006 private void tapPeekingBarToExpandAndAssert() throws InterruptedException { | 990 private void tapPeekingBarToExpandAndAssert() throws InterruptedException { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 .apply(); | 1050 .apply(); |
| 1067 } | 1051 } |
| 1068 }); | 1052 }); |
| 1069 } | 1053 } |
| 1070 | 1054 |
| 1071 /** | 1055 /** |
| 1072 * Force the Panel to handle a click in the Bar. | 1056 * Force the Panel to handle a click in the Bar. |
| 1073 * @throws InterruptedException | 1057 * @throws InterruptedException |
| 1074 */ | 1058 */ |
| 1075 private void forcePanelToHandleBarClick() throws InterruptedException { | 1059 private void forcePanelToHandleBarClick() throws InterruptedException { |
| 1076 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 1060 getInstrumentation().runOnMainSync(new Runnable() { |
| 1077 @Override | 1061 @Override |
| 1078 public void run() { | 1062 public void run() { |
| 1079 // TODO(donnd): provide better time and x,y data to make this mo
re broadly useful. | 1063 // TODO(donnd): provide better time and x,y data to make this mo
re broadly useful. |
| 1080 mPanel.handleBarClick(0, 0, 0); | 1064 mPanel.handleBarClick(0, 0, 0); |
| 1081 } | 1065 } |
| 1082 }); | 1066 }); |
| 1083 } | 1067 } |
| 1084 | 1068 |
| 1085 /** | 1069 /** |
| 1086 * Force the Panel to close. | 1070 * Force the Panel to close. |
| 1087 * @throws InterruptedException | 1071 * @throws InterruptedException |
| 1088 */ | 1072 */ |
| 1089 private void closePanel() throws InterruptedException { | 1073 private void closePanel() throws InterruptedException { |
| 1090 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 1074 getInstrumentation().runOnMainSync(new Runnable() { |
| 1091 @Override | 1075 @Override |
| 1092 public void run() { | 1076 public void run() { |
| 1093 mPanel.closePanel(StateChangeReason.UNKNOWN, false); | 1077 mPanel.closePanel(StateChangeReason.UNKNOWN, false); |
| 1094 } | 1078 } |
| 1095 }); | 1079 }); |
| 1096 } | 1080 } |
| 1097 | 1081 |
| 1098 /** | 1082 /** |
| 1099 * Waits for the Action Bar to be visible in response to a selection. | 1083 * Waits for the Action Bar to be visible in response to a selection. |
| 1100 */ | 1084 */ |
| 1101 private void waitForSelectActionBarVisible() throws InterruptedException { | 1085 private void waitForSelectActionBarVisible() throws InterruptedException { |
| 1102 assertWaitForSelectActionBarVisible(true); | 1086 assertWaitForSelectActionBarVisible(true); |
| 1103 } | 1087 } |
| 1104 | 1088 |
| 1105 //==========================================================================
================== | 1089 //==========================================================================
================== |
| 1106 // Test Cases | 1090 // Test Cases |
| 1107 //==========================================================================
================== | 1091 //==========================================================================
================== |
| 1108 | 1092 |
| 1109 /** | 1093 /** |
| 1110 * Tests whether the contextual search panel hides when omnibox is clicked. | 1094 * Tests whether the contextual search panel hides when omnibox is clicked. |
| 1111 */ | 1095 */ |
| 1112 //@SmallTest | 1096 //@SmallTest |
| 1113 //@Feature({"ContextualSearch"}) | 1097 //@Feature({"ContextualSearch"}) |
| 1114 @Test | |
| 1115 @DisabledTest | 1098 @DisabledTest |
| 1116 public void testHidesWhenOmniboxFocused() throws InterruptedException, Timeo
utException { | 1099 public void testHidesWhenOmniboxFocused() throws InterruptedException, Timeo
utException { |
| 1117 clickWordNode("intelligence"); | 1100 clickWordNode("intelligence"); |
| 1118 | 1101 |
| 1119 Assert.assertEquals("Intelligence", mFakeServer.getSearchTermRequested()
); | 1102 assertEquals("Intelligence", mFakeServer.getSearchTermRequested()); |
| 1120 fakeResponse(false, 200, "Intelligence", "display-text", "alternate-term
", false); | 1103 fakeResponse(false, 200, "Intelligence", "display-text", "alternate-term
", false); |
| 1121 assertContainsParameters("Intelligence", "alternate-term"); | 1104 assertContainsParameters("Intelligence", "alternate-term"); |
| 1122 waitForPanelToPeek(); | 1105 waitForPanelToPeek(); |
| 1123 | 1106 |
| 1124 OmniboxTestUtils.toggleUrlBarFocus( | 1107 OmniboxTestUtils.toggleUrlBarFocus((UrlBar) getActivity().findViewById(R
.id.url_bar), true); |
| 1125 (UrlBar) mActivityTestRule.getActivity().findViewById(R.id.url_b
ar), true); | |
| 1126 | 1108 |
| 1127 assertPanelClosedOrUndefined(); | 1109 assertPanelClosedOrUndefined(); |
| 1128 } | 1110 } |
| 1129 | 1111 |
| 1130 /** | 1112 /** |
| 1131 * Tests the doesContainAWord method. | 1113 * Tests the doesContainAWord method. |
| 1132 */ | 1114 */ |
| 1133 @Test | |
| 1134 @SmallTest | 1115 @SmallTest |
| 1135 @Feature({"ContextualSearch"}) | 1116 @Feature({"ContextualSearch"}) |
| 1136 public void testDoesContainAWord() { | 1117 public void testDoesContainAWord() { |
| 1137 Assert.assertTrue(mSelectionController.doesContainAWord("word")); | 1118 assertTrue(mSelectionController.doesContainAWord("word")); |
| 1138 Assert.assertTrue(mSelectionController.doesContainAWord("word ")); | 1119 assertTrue(mSelectionController.doesContainAWord("word ")); |
| 1139 Assert.assertFalse("Emtpy string should not be considered a word!", | 1120 assertFalse("Emtpy string should not be considered a word!", |
| 1140 mSelectionController.doesContainAWord("")); | 1121 mSelectionController.doesContainAWord("")); |
| 1141 Assert.assertFalse("Special symbols should not be considered a word!", | 1122 assertFalse("Special symbols should not be considered a word!", |
| 1142 mSelectionController.doesContainAWord("@")); | 1123 mSelectionController.doesContainAWord("@")); |
| 1143 Assert.assertFalse("White space should not be considered a word", | 1124 assertFalse("White space should not be considered a word", |
| 1144 mSelectionController.doesContainAWord(" ")); | 1125 mSelectionController.doesContainAWord(" ")); |
| 1145 Assert.assertTrue(mSelectionController.doesContainAWord("Q2")); | 1126 assertTrue(mSelectionController.doesContainAWord("Q2")); |
| 1146 Assert.assertTrue(mSelectionController.doesContainAWord("123")); | 1127 assertTrue(mSelectionController.doesContainAWord("123")); |
| 1147 } | 1128 } |
| 1148 | 1129 |
| 1149 /** | 1130 /** |
| 1150 * Tests the isValidSelection method. | 1131 * Tests the isValidSelection method. |
| 1151 */ | 1132 */ |
| 1152 @Test | |
| 1153 @SmallTest | 1133 @SmallTest |
| 1154 @Feature({"ContextualSearch"}) | 1134 @Feature({"ContextualSearch"}) |
| 1155 public void testIsValidSelection() { | 1135 public void testIsValidSelection() { |
| 1156 StubbedContentViewCore stubbedCvc = | 1136 StubbedContentViewCore stubbedCvc = new StubbedContentViewCore( |
| 1157 new StubbedContentViewCore(mActivityTestRule.getActivity().getBa
seContext()); | 1137 getActivity().getBaseContext()); |
| 1158 Assert.assertTrue(mSelectionController.isValidSelection("valid", stubbed
Cvc)); | 1138 assertTrue(mSelectionController.isValidSelection("valid", stubbedCvc)); |
| 1159 Assert.assertFalse(mSelectionController.isValidSelection(" ", stubbedCvc
)); | 1139 assertFalse(mSelectionController.isValidSelection(" ", stubbedCvc)); |
| 1160 stubbedCvc.setIsFocusedNodeEditableForTest(true); | 1140 stubbedCvc.setIsFocusedNodeEditableForTest(true); |
| 1161 Assert.assertFalse(mSelectionController.isValidSelection("editable", stu
bbedCvc)); | 1141 assertFalse(mSelectionController.isValidSelection("editable", stubbedCvc
)); |
| 1162 stubbedCvc.setIsFocusedNodeEditableForTest(false); | 1142 stubbedCvc.setIsFocusedNodeEditableForTest(false); |
| 1163 String numberString = "0123456789"; | 1143 String numberString = "0123456789"; |
| 1164 StringBuilder longStringBuilder = new StringBuilder(); | 1144 StringBuilder longStringBuilder = new StringBuilder(); |
| 1165 for (int i = 0; i < 11; i++) { | 1145 for (int i = 0; i < 11; i++) { |
| 1166 longStringBuilder.append(numberString); | 1146 longStringBuilder.append(numberString); |
| 1167 } | 1147 } |
| 1168 Assert.assertTrue(mSelectionController.isValidSelection(numberString, st
ubbedCvc)); | 1148 assertTrue(mSelectionController.isValidSelection(numberString, stubbedCv
c)); |
| 1169 Assert.assertFalse( | 1149 assertFalse(mSelectionController.isValidSelection(longStringBuilder.toSt
ring(), |
| 1170 mSelectionController.isValidSelection(longStringBuilder.toString
(), stubbedCvc)); | 1150 stubbedCvc)); |
| 1171 } | 1151 } |
| 1172 | 1152 |
| 1173 /** | 1153 /** |
| 1174 * Tests a simple Tap. | 1154 * Tests a simple Tap. |
| 1175 */ | 1155 */ |
| 1176 @Test | |
| 1177 @SmallTest | 1156 @SmallTest |
| 1178 @Feature({"ContextualSearch"}) | 1157 @Feature({"ContextualSearch"}) |
| 1179 public void testTap() throws InterruptedException, TimeoutException { | 1158 public void testTap() throws InterruptedException, TimeoutException { |
| 1180 clickWordNode("intelligence"); | 1159 clickWordNode("intelligence"); |
| 1181 | 1160 |
| 1182 Assert.assertEquals("Intelligence", mFakeServer.getSearchTermRequested()
); | 1161 assertEquals("Intelligence", mFakeServer.getSearchTermRequested()); |
| 1183 fakeResponse(false, 200, "Intelligence", "display-text", "alternate-term
", false); | 1162 fakeResponse(false, 200, "Intelligence", "display-text", "alternate-term
", false); |
| 1184 assertContainsParameters("Intelligence", "alternate-term"); | 1163 assertContainsParameters("Intelligence", "alternate-term"); |
| 1185 waitForPanelToPeek(); | 1164 waitForPanelToPeek(); |
| 1186 assertLoadedLowPriorityUrl(); | 1165 assertLoadedLowPriorityUrl(); |
| 1187 } | 1166 } |
| 1188 | 1167 |
| 1189 /** | 1168 /** |
| 1190 * Tests a simple Long-Press gesture, without opening the panel. | 1169 * Tests a simple Long-Press gesture, without opening the panel. |
| 1191 */ | 1170 */ |
| 1192 @Test | |
| 1193 @SmallTest | 1171 @SmallTest |
| 1194 @Feature({"ContextualSearch"}) | 1172 @Feature({"ContextualSearch"}) |
| 1195 public void testLongPress() throws InterruptedException, TimeoutException { | 1173 public void testLongPress() throws InterruptedException, TimeoutException { |
| 1196 longPressNode("states"); | 1174 longPressNode("states"); |
| 1197 | 1175 |
| 1198 Assert.assertNull(mFakeServer.getSearchTermRequested()); | 1176 assertNull(mFakeServer.getSearchTermRequested()); |
| 1199 waitForPanelToPeek(); | 1177 waitForPanelToPeek(); |
| 1200 assertLoadedNoUrl(); | 1178 assertLoadedNoUrl(); |
| 1201 assertNoContentViewCore(); | 1179 assertNoContentViewCore(); |
| 1202 } | 1180 } |
| 1203 | 1181 |
| 1204 /** | 1182 /** |
| 1205 * Tests swiping the overlay open, after an initial tap that activates the p
eeking card. | 1183 * Tests swiping the overlay open, after an initial tap that activates the p
eeking card. |
| 1206 */ | 1184 */ |
| 1207 @Test | |
| 1208 @SmallTest | 1185 @SmallTest |
| 1209 @Feature({"ContextualSearch"}) | 1186 @Feature({"ContextualSearch"}) |
| 1210 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 1187 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 1211 public void testSwipeExpand() throws InterruptedException, TimeoutException
{ | 1188 public void testSwipeExpand() throws InterruptedException, TimeoutException
{ |
| 1212 assertNoSearchesLoaded(); | 1189 assertNoSearchesLoaded(); |
| 1213 clickWordNode("intelligence"); | 1190 clickWordNode("intelligence"); |
| 1214 assertNoSearchesLoaded(); | 1191 assertNoSearchesLoaded(); |
| 1215 | 1192 |
| 1216 // Fake a search term resolution response. | 1193 // Fake a search term resolution response. |
| 1217 fakeResponse(false, 200, "Intelligence", "United States Intelligence", "
alternate-term", | 1194 fakeResponse(false, 200, "Intelligence", "United States Intelligence", "
alternate-term", |
| 1218 false); | 1195 false); |
| 1219 assertContainsParameters("Intelligence", "alternate-term"); | 1196 assertContainsParameters("Intelligence", "alternate-term"); |
| 1220 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1197 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1221 assertLoadedLowPriorityUrl(); | 1198 assertLoadedLowPriorityUrl(); |
| 1222 | 1199 |
| 1223 waitForPanelToPeek(); | 1200 waitForPanelToPeek(); |
| 1224 flingPanelUp(); | 1201 flingPanelUp(); |
| 1225 waitForPanelToExpand(); | 1202 waitForPanelToExpand(); |
| 1226 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1203 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1227 assertLoadedLowPriorityUrl(); | 1204 assertLoadedLowPriorityUrl(); |
| 1228 } | 1205 } |
| 1229 | 1206 |
| 1230 /** | 1207 /** |
| 1231 * Tests swiping the overlay open, after an initial long-press that activate
s the peeking card, | 1208 * Tests swiping the overlay open, after an initial long-press that activate
s the peeking card, |
| 1232 * followed by closing the panel. | 1209 * followed by closing the panel. |
| 1233 * This test also verifies that we don't create any {@link ContentViewCore}
or load any URL | 1210 * This test also verifies that we don't create any {@link ContentViewCore}
or load any URL |
| 1234 * until the panel is opened. | 1211 * until the panel is opened. |
| 1235 */ | 1212 */ |
| 1236 @Test | |
| 1237 @SmallTest | 1213 @SmallTest |
| 1238 @Feature({"ContextualSearch"}) | 1214 @Feature({"ContextualSearch"}) |
| 1239 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 1215 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 1240 public void testLongPressSwipeExpand() throws InterruptedException, TimeoutE
xception { | 1216 public void testLongPressSwipeExpand() throws InterruptedException, TimeoutE
xception { |
| 1241 simulateLongPressSearch("search"); | 1217 simulateLongPressSearch("search"); |
| 1242 assertNoContentViewCore(); | 1218 assertNoContentViewCore(); |
| 1243 assertLoadedNoUrl(); | 1219 assertLoadedNoUrl(); |
| 1244 | 1220 |
| 1245 tapPeekingBarToExpandAndAssert(); | 1221 tapPeekingBarToExpandAndAssert(); |
| 1246 assertContentViewCoreCreated(); | 1222 assertContentViewCoreCreated(); |
| 1247 assertLoadedNormalPriorityUrl(); | 1223 assertLoadedNormalPriorityUrl(); |
| 1248 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1224 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1249 | 1225 |
| 1250 // tap the base page to close. | 1226 // tap the base page to close. |
| 1251 closePanel(); | 1227 closePanel(); |
| 1252 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1228 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1253 assertNoContentViewCore(); | 1229 assertNoContentViewCore(); |
| 1254 } | 1230 } |
| 1255 | 1231 |
| 1256 /** | 1232 /** |
| 1257 * Tests that only a single low-priority request is issued for a Tap/Open se
quence. | 1233 * Tests that only a single low-priority request is issued for a Tap/Open se
quence. |
| 1258 */ | 1234 */ |
| 1259 @Test | |
| 1260 @SmallTest | 1235 @SmallTest |
| 1261 @Feature({"ContextualSearch"}) | 1236 @Feature({"ContextualSearch"}) |
| 1262 public void testTapCausesOneLowPriorityRequest() throws InterruptedException
, TimeoutException { | 1237 public void testTapCausesOneLowPriorityRequest() throws InterruptedException
, TimeoutException { |
| 1263 mFakeServer.reset(); | 1238 mFakeServer.reset(); |
| 1264 clickWordNode("states"); | 1239 clickWordNode("states"); |
| 1265 | 1240 |
| 1266 // We should not make a second-request until we get a good response from
the first-request. | 1241 // We should not make a second-request until we get a good response from
the first-request. |
| 1267 assertLoadedNoUrl(); | 1242 assertLoadedNoUrl(); |
| 1268 Assert.assertEquals(0, mFakeServer.getLoadedUrlCount()); | 1243 assertEquals(0, mFakeServer.getLoadedUrlCount()); |
| 1269 fakeResponse(false, 200, "states", "United States Intelligence", "altern
ate-term", false); | 1244 fakeResponse(false, 200, "states", "United States Intelligence", "altern
ate-term", false); |
| 1270 assertLoadedLowPriorityUrl(); | 1245 assertLoadedLowPriorityUrl(); |
| 1271 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1246 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1272 | 1247 |
| 1273 // When the second request succeeds, we should not issue a new request. | 1248 // When the second request succeeds, we should not issue a new request. |
| 1274 fakeContentViewDidNavigate(false); | 1249 fakeContentViewDidNavigate(false); |
| 1275 assertLoadedLowPriorityUrl(); | 1250 assertLoadedLowPriorityUrl(); |
| 1276 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1251 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1277 | 1252 |
| 1278 // When the bar opens, we should not make any additional request. | 1253 // When the bar opens, we should not make any additional request. |
| 1279 tapPeekingBarToExpandAndAssert(); | 1254 tapPeekingBarToExpandAndAssert(); |
| 1280 assertLoadedLowPriorityUrl(); | 1255 assertLoadedLowPriorityUrl(); |
| 1281 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1256 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1282 assertLoadedLowPriorityUrl(); | 1257 assertLoadedLowPriorityUrl(); |
| 1283 } | 1258 } |
| 1284 | 1259 |
| 1285 /** | 1260 /** |
| 1286 * Tests that a failover for a prefetch request is issued after the panel is
opened. | 1261 * Tests that a failover for a prefetch request is issued after the panel is
opened. |
| 1287 */ | 1262 */ |
| 1288 @Test | |
| 1289 @SmallTest | 1263 @SmallTest |
| 1290 @Feature({"ContextualSearch"}) | 1264 @Feature({"ContextualSearch"}) |
| 1291 public void testPrefetchFailoverRequestMadeAfterOpen() | 1265 public void testPrefetchFailoverRequestMadeAfterOpen() |
| 1292 throws InterruptedException, TimeoutException { | 1266 throws InterruptedException, TimeoutException { |
| 1293 mFakeServer.reset(); | 1267 mFakeServer.reset(); |
| 1294 clickWordNode("states"); | 1268 clickWordNode("states"); |
| 1295 | 1269 |
| 1296 // We should not make a SERP request until we get a good response from t
he resolve request. | 1270 // We should not make a SERP request until we get a good response from t
he resolve request. |
| 1297 assertLoadedNoUrl(); | 1271 assertLoadedNoUrl(); |
| 1298 Assert.assertEquals(0, mFakeServer.getLoadedUrlCount()); | 1272 assertEquals(0, mFakeServer.getLoadedUrlCount()); |
| 1299 fakeResponse(false, 200, "states", "United States Intelligence", "altern
ate-term", false); | 1273 fakeResponse(false, 200, "states", "United States Intelligence", "altern
ate-term", false); |
| 1300 assertLoadedLowPriorityUrl(); | 1274 assertLoadedLowPriorityUrl(); |
| 1301 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1275 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1302 | 1276 |
| 1303 // When the second request fails, we should not automatically issue a ne
w request. | 1277 // When the second request fails, we should not automatically issue a ne
w request. |
| 1304 fakeContentViewDidNavigate(true); | 1278 fakeContentViewDidNavigate(true); |
| 1305 assertLoadedLowPriorityUrl(); | 1279 assertLoadedLowPriorityUrl(); |
| 1306 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1280 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1307 | 1281 |
| 1308 // Once the bar opens, we make a new request at normal priority. | 1282 // Once the bar opens, we make a new request at normal priority. |
| 1309 tapPeekingBarToExpandAndAssert(); | 1283 tapPeekingBarToExpandAndAssert(); |
| 1310 assertLoadedNormalPriorityUrl(); | 1284 assertLoadedNormalPriorityUrl(); |
| 1311 Assert.assertEquals(2, mFakeServer.getLoadedUrlCount()); | 1285 assertEquals(2, mFakeServer.getLoadedUrlCount()); |
| 1312 } | 1286 } |
| 1313 | 1287 |
| 1314 /** | 1288 /** |
| 1315 * Tests that a live request that fails (for an invalid URL) does a failover
to a | 1289 * Tests that a live request that fails (for an invalid URL) does a failover
to a |
| 1316 * normal priority request once the user triggers the failover by opening th
e panel. | 1290 * normal priority request once the user triggers the failover by opening th
e panel. |
| 1317 */ | 1291 */ |
| 1318 @Test | |
| 1319 @SmallTest | 1292 @SmallTest |
| 1320 @Feature({"ContextualSearch"}) | 1293 @Feature({"ContextualSearch"}) |
| 1321 public void testLivePrefetchFailoverRequestMadeAfterOpen() | 1294 public void testLivePrefetchFailoverRequestMadeAfterOpen() |
| 1322 throws InterruptedException, TimeoutException { | 1295 throws InterruptedException, TimeoutException { |
| 1323 mFakeServer.reset(); | 1296 mFakeServer.reset(); |
| 1324 mFakeServer.setLowPriorityPathInvalid(); | 1297 mFakeServer.setLowPriorityPathInvalid(); |
| 1325 simulateTapSearch("search"); | 1298 simulateTapSearch("search"); |
| 1326 assertLoadedLowPriorityInvalidUrl(); | 1299 assertLoadedLowPriorityInvalidUrl(); |
| 1327 Assert.assertTrue(mFakeServer.didAttemptLoadInvalidUrl()); | 1300 assertTrue(mFakeServer.didAttemptLoadInvalidUrl()); |
| 1328 | 1301 |
| 1329 // we should not automatically issue a new request. | 1302 // we should not automatically issue a new request. |
| 1330 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 1303 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 1331 | 1304 |
| 1332 // Fake a navigation error if offline. | 1305 // Fake a navigation error if offline. |
| 1333 // When connected to the Internet this error may already have happened d
ue to actually | 1306 // When connected to the Internet this error may already have happened d
ue to actually |
| 1334 // trying to load the invalid URL. But on test bots that are not online
we need to | 1307 // trying to load the invalid URL. But on test bots that are not online
we need to |
| 1335 // fake that a navigation happened with an error. See crbug.com/682953 f
or details. | 1308 // fake that a navigation happened with an error. See crbug.com/682953 f
or details. |
| 1336 if (!mManager.isOnline()) { | 1309 if (!mManager.isOnline()) { |
| 1337 boolean isFailure = true; | 1310 boolean isFailure = true; |
| 1338 fakeContentViewDidNavigate(isFailure); | 1311 fakeContentViewDidNavigate(isFailure); |
| 1339 } | 1312 } |
| 1340 | 1313 |
| 1341 // Once the bar opens, we make a new request at normal priority. | 1314 // Once the bar opens, we make a new request at normal priority. |
| 1342 tapPeekingBarToExpandAndAssert(); | 1315 tapPeekingBarToExpandAndAssert(); |
| 1343 waitForNormalPriorityUrlLoaded(); | 1316 waitForNormalPriorityUrlLoaded(); |
| 1344 Assert.assertEquals(2, mFakeServer.getLoadedUrlCount()); | 1317 assertEquals(2, mFakeServer.getLoadedUrlCount()); |
| 1345 } | 1318 } |
| 1346 | 1319 |
| 1347 /** | 1320 /** |
| 1348 * Tests a simple Tap with disable-preload set. | 1321 * Tests a simple Tap with disable-preload set. |
| 1349 */ | 1322 */ |
| 1350 @Test | |
| 1351 @SmallTest | 1323 @SmallTest |
| 1352 @Feature({"ContextualSearch"}) | 1324 @Feature({"ContextualSearch"}) |
| 1353 public void testTapDisablePreload() throws InterruptedException, TimeoutExce
ption { | 1325 public void testTapDisablePreload() throws InterruptedException, TimeoutExce
ption { |
| 1354 clickWordNode("intelligence"); | 1326 clickWordNode("intelligence"); |
| 1355 | 1327 |
| 1356 assertSearchTermRequested(); | 1328 assertSearchTermRequested(); |
| 1357 fakeResponse(false, 200, "Intelligence", "display-text", "alternate-term
", true); | 1329 fakeResponse(false, 200, "Intelligence", "display-text", "alternate-term
", true); |
| 1358 assertLoadedNoUrl(); | 1330 assertLoadedNoUrl(); |
| 1359 waitForPanelToPeek(); | 1331 waitForPanelToPeek(); |
| 1360 assertLoadedNoUrl(); | 1332 assertLoadedNoUrl(); |
| 1361 } | 1333 } |
| 1362 | 1334 |
| 1363 /** | 1335 /** |
| 1364 * Tests that long-press selects text, and a subsequent tap will unselect te
xt. | 1336 * Tests that long-press selects text, and a subsequent tap will unselect te
xt. |
| 1365 */ | 1337 */ |
| 1366 @Test | |
| 1367 @SmallTest | 1338 @SmallTest |
| 1368 @Feature({"ContextualSearch"}) | 1339 @Feature({"ContextualSearch"}) |
| 1369 public void testLongPressGestureSelects() throws InterruptedException, Timeo
utException { | 1340 public void testLongPressGestureSelects() throws InterruptedException, Timeo
utException { |
| 1370 longPressNode("intelligence"); | 1341 longPressNode("intelligence"); |
| 1371 Assert.assertEquals("Intelligence", getSelectedText()); | 1342 assertEquals("Intelligence", getSelectedText()); |
| 1372 fakeResponse(false, 200, "Intelligence", "Intelligence", "alternate-term
", false); | 1343 fakeResponse(false, 200, "Intelligence", "Intelligence", "alternate-term
", false); |
| 1373 assertContainsParameters("Intelligence", "alternate-term"); | 1344 assertContainsParameters("Intelligence", "alternate-term"); |
| 1374 waitForPanelToPeek(); | 1345 waitForPanelToPeek(); |
| 1375 assertLoadedNoUrl(); // No load after long-press until opening panel. | 1346 assertLoadedNoUrl(); // No load after long-press until opening panel. |
| 1376 clickNode("question-mark"); | 1347 clickNode("question-mark"); |
| 1377 waitForGestureProcessing(); | 1348 waitForGestureProcessing(); |
| 1378 waitForPanelToCloseAndSelectionEmpty(); | 1349 waitForPanelToCloseAndSelectionEmpty(); |
| 1379 Assert.assertTrue(TextUtils.isEmpty(getSelectedText())); | 1350 assertTrue(TextUtils.isEmpty(getSelectedText())); |
| 1380 assertLoadedNoUrl(); | 1351 assertLoadedNoUrl(); |
| 1381 } | 1352 } |
| 1382 | 1353 |
| 1383 /** | 1354 /** |
| 1384 * Tests that a Tap gesture selects the expected text. | 1355 * Tests that a Tap gesture selects the expected text. |
| 1385 */ | 1356 */ |
| 1386 @Test | |
| 1387 @SmallTest | 1357 @SmallTest |
| 1388 @Feature({"ContextualSearch"}) | 1358 @Feature({"ContextualSearch"}) |
| 1389 public void testTapGestureSelects() throws InterruptedException, TimeoutExce
ption { | 1359 public void testTapGestureSelects() throws InterruptedException, TimeoutExce
ption { |
| 1390 clickWordNode("intelligence"); | 1360 clickWordNode("intelligence"); |
| 1391 Assert.assertEquals("Intelligence", getSelectedText()); | 1361 assertEquals("Intelligence", getSelectedText()); |
| 1392 fakeResponse(false, 200, "Intelligence", "Intelligence", "alternate-term
", false); | 1362 fakeResponse(false, 200, "Intelligence", "Intelligence", "alternate-term
", false); |
| 1393 assertContainsParameters("Intelligence", "alternate-term"); | 1363 assertContainsParameters("Intelligence", "alternate-term"); |
| 1394 waitForPanelToPeek(); | 1364 waitForPanelToPeek(); |
| 1395 assertLoadedLowPriorityUrl(); | 1365 assertLoadedLowPriorityUrl(); |
| 1396 clickNode("question-mark"); | 1366 clickNode("question-mark"); |
| 1397 waitForPanelToClose(); | 1367 waitForPanelToClose(); |
| 1398 Assert.assertNull(getSelectedText()); | 1368 assertNull(getSelectedText()); |
| 1399 } | 1369 } |
| 1400 | 1370 |
| 1401 /** | 1371 /** |
| 1402 * Tests that a Tap gesture on a special character does not select or show t
he panel. | 1372 * Tests that a Tap gesture on a special character does not select or show t
he panel. |
| 1403 */ | 1373 */ |
| 1404 @Test | |
| 1405 @SmallTest | 1374 @SmallTest |
| 1406 @Feature({"ContextualSearch"}) | 1375 @Feature({"ContextualSearch"}) |
| 1407 public void testTapGestureOnSpecialCharacterDoesntSelect() | 1376 public void testTapGestureOnSpecialCharacterDoesntSelect() |
| 1408 throws InterruptedException, TimeoutException { | 1377 throws InterruptedException, TimeoutException { |
| 1409 clickNode("question-mark"); | 1378 clickNode("question-mark"); |
| 1410 waitForGestureProcessing(); | 1379 waitForGestureProcessing(); |
| 1411 Assert.assertNull(getSelectedText()); | 1380 assertNull(getSelectedText()); |
| 1412 assertPanelClosedOrUndefined(); | 1381 assertPanelClosedOrUndefined(); |
| 1413 assertLoadedNoUrl(); | 1382 assertLoadedNoUrl(); |
| 1414 } | 1383 } |
| 1415 | 1384 |
| 1416 /** | 1385 /** |
| 1417 * Tests that a Tap gesture followed by scrolling clears the selection. | 1386 * Tests that a Tap gesture followed by scrolling clears the selection. |
| 1418 */ | 1387 */ |
| 1419 @Test | |
| 1420 @SmallTest | 1388 @SmallTest |
| 1421 @Feature({"ContextualSearch"}) | 1389 @Feature({"ContextualSearch"}) |
| 1422 public void testTapGestureFollowedByScrollClearsSelection() | 1390 public void testTapGestureFollowedByScrollClearsSelection() |
| 1423 throws InterruptedException, TimeoutException { | 1391 throws InterruptedException, TimeoutException { |
| 1424 clickWordNode("intelligence"); | 1392 clickWordNode("intelligence"); |
| 1425 fakeResponse(false, 200, "Intelligence", "Intelligence", "alternate-term
", false); | 1393 fakeResponse(false, 200, "Intelligence", "Intelligence", "alternate-term
", false); |
| 1426 assertContainsParameters("Intelligence", "alternate-term"); | 1394 assertContainsParameters("Intelligence", "alternate-term"); |
| 1427 waitForPanelToPeek(); | 1395 waitForPanelToPeek(); |
| 1428 assertLoadedLowPriorityUrl(); | 1396 assertLoadedLowPriorityUrl(); |
| 1429 scrollBasePage(); | 1397 scrollBasePage(); |
| 1430 assertPanelClosedOrUndefined(); | 1398 assertPanelClosedOrUndefined(); |
| 1431 Assert.assertTrue(TextUtils.isEmpty(mSelectionController.getSelectedText
())); | 1399 assertTrue(TextUtils.isEmpty(mSelectionController.getSelectedText())); |
| 1432 } | 1400 } |
| 1433 | 1401 |
| 1434 /** | 1402 /** |
| 1435 * Tests that a Tap gesture followed by tapping an invalid character doesn't
select. | 1403 * Tests that a Tap gesture followed by tapping an invalid character doesn't
select. |
| 1436 */ | 1404 */ |
| 1437 @Test | |
| 1438 @SmallTest | 1405 @SmallTest |
| 1439 @Feature({"ContextualSearch"}) | 1406 @Feature({"ContextualSearch"}) |
| 1440 public void testTapGestureFollowedByInvalidTextTapCloses() | 1407 public void testTapGestureFollowedByInvalidTextTapCloses() |
| 1441 throws InterruptedException, TimeoutException { | 1408 throws InterruptedException, TimeoutException { |
| 1442 clickWordNode("states-far"); | 1409 clickWordNode("states-far"); |
| 1443 waitForPanelToPeek(); | 1410 waitForPanelToPeek(); |
| 1444 clickNode("question-mark"); | 1411 clickNode("question-mark"); |
| 1445 waitForPanelToClose(); | 1412 waitForPanelToClose(); |
| 1446 Assert.assertNull(mSelectionController.getSelectedText()); | 1413 assertNull(mSelectionController.getSelectedText()); |
| 1447 } | 1414 } |
| 1448 | 1415 |
| 1449 /** | 1416 /** |
| 1450 * Tests that a Tap gesture followed by tapping a non-text character doesn't
select. | 1417 * Tests that a Tap gesture followed by tapping a non-text character doesn't
select. |
| 1451 * @SmallTest | 1418 * @SmallTest |
| 1452 * @Feature({"ContextualSearch"}) | 1419 * @Feature({"ContextualSearch"}) |
| 1453 * crbug.com/665633 | 1420 * crbug.com/665633 |
| 1454 */ | 1421 */ |
| 1455 @Test | |
| 1456 @DisabledTest | 1422 @DisabledTest |
| 1457 public void testTapGestureFollowedByNonTextTap() throws InterruptedException
, TimeoutException { | 1423 public void testTapGestureFollowedByNonTextTap() throws InterruptedException
, TimeoutException { |
| 1458 clickWordNode("states-far"); | 1424 clickWordNode("states-far"); |
| 1459 waitForPanelToPeek(); | 1425 waitForPanelToPeek(); |
| 1460 clickNode("button"); | 1426 clickNode("button"); |
| 1461 waitForPanelToCloseAndSelectionEmpty(); | 1427 waitForPanelToCloseAndSelectionEmpty(); |
| 1462 } | 1428 } |
| 1463 | 1429 |
| 1464 /** | 1430 /** |
| 1465 * Tests that a Tap gesture far away toggles selecting text. | 1431 * Tests that a Tap gesture far away toggles selecting text. |
| 1466 */ | 1432 */ |
| 1467 @Test | |
| 1468 @SmallTest | 1433 @SmallTest |
| 1469 @Feature({"ContextualSearch"}) | 1434 @Feature({"ContextualSearch"}) |
| 1470 public void testTapGestureFarAwayTogglesSelecting() | 1435 public void testTapGestureFarAwayTogglesSelecting() |
| 1471 throws InterruptedException, TimeoutException { | 1436 throws InterruptedException, TimeoutException { |
| 1472 clickWordNode("states"); | 1437 clickWordNode("states"); |
| 1473 Assert.assertEquals("States", getSelectedText()); | 1438 assertEquals("States", getSelectedText()); |
| 1474 waitForPanelToPeek(); | 1439 waitForPanelToPeek(); |
| 1475 clickNode("states-far"); | 1440 clickNode("states-far"); |
| 1476 waitForPanelToClose(); | 1441 waitForPanelToClose(); |
| 1477 Assert.assertNull(getSelectedText()); | 1442 assertNull(getSelectedText()); |
| 1478 clickNode("states-far"); | 1443 clickNode("states-far"); |
| 1479 waitForGestureProcessing(); | 1444 waitForGestureProcessing(); |
| 1480 waitForPanelToPeek(); | 1445 waitForPanelToPeek(); |
| 1481 Assert.assertEquals("States", getSelectedText()); | 1446 assertEquals("States", getSelectedText()); |
| 1482 } | 1447 } |
| 1483 | 1448 |
| 1484 /** | 1449 /** |
| 1485 * Tests that sequential Tap gestures nearby keep selecting. | 1450 * Tests that sequential Tap gestures nearby keep selecting. |
| 1486 */ | 1451 */ |
| 1487 @Test | |
| 1488 @SmallTest | 1452 @SmallTest |
| 1489 @Feature({"ContextualSearch"}) | 1453 @Feature({"ContextualSearch"}) |
| 1490 public void testTapGesturesNearbyKeepSelecting() throws InterruptedException
, TimeoutException { | 1454 public void testTapGesturesNearbyKeepSelecting() throws InterruptedException
, TimeoutException { |
| 1491 clickWordNode("states"); | 1455 clickWordNode("states"); |
| 1492 Assert.assertEquals("States", getSelectedText()); | 1456 assertEquals("States", getSelectedText()); |
| 1493 waitForPanelToPeek(); | 1457 waitForPanelToPeek(); |
| 1494 // Avoid issues with double-tap detection by ensuring sequential taps | 1458 // Avoid issues with double-tap detection by ensuring sequential taps |
| 1495 // aren't treated as such. Double-tapping can also select words much as | 1459 // aren't treated as such. Double-tapping can also select words much as |
| 1496 // longpress, in turn showing the pins and preventing contextual tap | 1460 // longpress, in turn showing the pins and preventing contextual tap |
| 1497 // refinement from nearby taps. The double-tap timeout is sufficiently | 1461 // refinement from nearby taps. The double-tap timeout is sufficiently |
| 1498 // short that this shouldn't conflict with tap refinement by the user. | 1462 // short that this shouldn't conflict with tap refinement by the user. |
| 1499 Thread.sleep(ViewConfiguration.getDoubleTapTimeout()); | 1463 Thread.sleep(ViewConfiguration.getDoubleTapTimeout()); |
| 1500 // Because sequential taps never hide the bar, we we can't wait for it t
o peek. | 1464 // Because sequential taps never hide the bar, we we can't wait for it t
o peek. |
| 1501 // Instead we use clickNode (which doesn't wait) instead of clickWordNod
e and wait | 1465 // Instead we use clickNode (which doesn't wait) instead of clickWordNod
e and wait |
| 1502 // for the selection to change. | 1466 // for the selection to change. |
| 1503 clickNode("states-near"); | 1467 clickNode("states-near"); |
| 1504 waitForSelectionToBe("StatesNear"); | 1468 waitForSelectionToBe("StatesNear"); |
| 1505 Thread.sleep(ViewConfiguration.getDoubleTapTimeout()); | 1469 Thread.sleep(ViewConfiguration.getDoubleTapTimeout()); |
| 1506 clickNode("states"); | 1470 clickNode("states"); |
| 1507 waitForSelectionToBe("States"); | 1471 waitForSelectionToBe("States"); |
| 1508 } | 1472 } |
| 1509 | 1473 |
| 1510 /** | 1474 /** |
| 1511 * Tests that a long-press gesture followed by scrolling does not clear the
selection. | 1475 * Tests that a long-press gesture followed by scrolling does not clear the
selection. |
| 1512 */ | 1476 */ |
| 1513 @Test | |
| 1514 @SmallTest | 1477 @SmallTest |
| 1515 @Feature({"ContextualSearch"}) | 1478 @Feature({"ContextualSearch"}) |
| 1516 public void testLongPressGestureFollowedByScrollMaintainsSelection() | 1479 public void testLongPressGestureFollowedByScrollMaintainsSelection() |
| 1517 throws InterruptedException, TimeoutException { | 1480 throws InterruptedException, TimeoutException { |
| 1518 longPressNode("intelligence"); | 1481 longPressNode("intelligence"); |
| 1519 waitForPanelToPeek(); | 1482 waitForPanelToPeek(); |
| 1520 scrollBasePage(); | 1483 scrollBasePage(); |
| 1521 assertPanelClosedOrUndefined(); | 1484 assertPanelClosedOrUndefined(); |
| 1522 Assert.assertEquals("Intelligence", getSelectedText()); | 1485 assertEquals("Intelligence", getSelectedText()); |
| 1523 assertLoadedNoUrl(); | 1486 assertLoadedNoUrl(); |
| 1524 } | 1487 } |
| 1525 | 1488 |
| 1526 /** | 1489 /** |
| 1527 * Tests that a long-press gesture followed by a tap does not select. | 1490 * Tests that a long-press gesture followed by a tap does not select. |
| 1528 */ | 1491 */ |
| 1529 @Test | |
| 1530 @SmallTest | 1492 @SmallTest |
| 1531 @Feature({"ContextualSearch"}) | 1493 @Feature({"ContextualSearch"}) |
| 1532 public void testLongPressGestureFollowedByTapDoesntSelect() | 1494 public void testLongPressGestureFollowedByTapDoesntSelect() |
| 1533 throws InterruptedException, TimeoutException { | 1495 throws InterruptedException, TimeoutException { |
| 1534 longPressNode("intelligence"); | 1496 longPressNode("intelligence"); |
| 1535 waitForPanelToPeek(); | 1497 waitForPanelToPeek(); |
| 1536 clickWordNode("states-far"); | 1498 clickWordNode("states-far"); |
| 1537 waitForGestureToClosePanelAndAssertNoSelection(); | 1499 waitForGestureToClosePanelAndAssertNoSelection(); |
| 1538 assertLoadedNoUrl(); | 1500 assertLoadedNoUrl(); |
| 1539 } | 1501 } |
| 1540 | 1502 |
| 1541 /** | 1503 /** |
| 1542 * Tests that the panel closes when its base page crashes. | 1504 * Tests that the panel closes when its base page crashes. |
| 1543 */ | 1505 */ |
| 1544 @Test | |
| 1545 @SmallTest | 1506 @SmallTest |
| 1546 @Feature({"ContextualSearch"}) | 1507 @Feature({"ContextualSearch"}) |
| 1547 public void testContextualSearchDismissedOnForegroundTabCrash() | 1508 public void testContextualSearchDismissedOnForegroundTabCrash() |
| 1548 throws InterruptedException, TimeoutException { | 1509 throws InterruptedException, TimeoutException { |
| 1549 clickWordNode("states"); | 1510 clickWordNode("states"); |
| 1550 Assert.assertEquals("States", getSelectedText()); | 1511 assertEquals("States", getSelectedText()); |
| 1551 waitForPanelToPeek(); | 1512 waitForPanelToPeek(); |
| 1552 | 1513 |
| 1553 ThreadUtils.runOnUiThread(new Runnable() { | 1514 ThreadUtils.runOnUiThread(new Runnable() { |
| 1554 @Override | 1515 @Override |
| 1555 public void run() { | 1516 public void run() { |
| 1556 mActivityTestRule.getActivity().getActivityTab().simulateRendere
rKilledForTesting( | 1517 getActivity().getActivityTab().simulateRendererKilledForTesting(
true); |
| 1557 true); | |
| 1558 } | 1518 } |
| 1559 }); | 1519 }); |
| 1560 | 1520 |
| 1561 // Give the panelState time to change | 1521 // Give the panelState time to change |
| 1562 CriteriaHelper.pollInstrumentationThread(new Criteria(){ | 1522 CriteriaHelper.pollInstrumentationThread(new Criteria(){ |
| 1563 @Override | 1523 @Override |
| 1564 public boolean isSatisfied() { | 1524 public boolean isSatisfied() { |
| 1565 PanelState panelState = mPanel.getPanelState(); | 1525 PanelState panelState = mPanel.getPanelState(); |
| 1566 return panelState != PanelState.PEEKED; | 1526 return panelState != PanelState.PEEKED; |
| 1567 } | 1527 } |
| 1568 }); | 1528 }); |
| 1569 | 1529 |
| 1570 assertPanelClosedOrUndefined(); | 1530 assertPanelClosedOrUndefined(); |
| 1571 } | 1531 } |
| 1572 | 1532 |
| 1573 /** | 1533 /** |
| 1574 * Test the the panel does not close when some background tab crashes. | 1534 * Test the the panel does not close when some background tab crashes. |
| 1575 */ | 1535 */ |
| 1576 @Test | |
| 1577 @SmallTest | 1536 @SmallTest |
| 1578 @Feature({"ContextualSearch"}) | 1537 @Feature({"ContextualSearch"}) |
| 1579 public void testContextualSearchNotDismissedOnBackgroundTabCrash() | 1538 public void testContextualSearchNotDismissedOnBackgroundTabCrash() |
| 1580 throws InterruptedException, TimeoutException { | 1539 throws InterruptedException, TimeoutException { |
| 1581 ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation
(), | 1540 ChromeTabUtils.newTabFromMenu(getInstrumentation(), |
| 1582 (ChromeTabbedActivity) mActivityTestRule.getActivity()); | 1541 (ChromeTabbedActivity) getActivity()); |
| 1583 final Tab tab2 = | 1542 final Tab tab2 = TabModelUtils.getCurrentTab(getActivity().getCurrentTab
Model()); |
| 1584 TabModelUtils.getCurrentTab(mActivityTestRule.getActivity().getC
urrentTabModel()); | |
| 1585 | 1543 |
| 1586 // TODO(donnd): consider using runOnUiThreadBlocking, won't need to wait
ForIdleSync? | 1544 // TODO(donnd): consider using runOnUiThreadBlocking, won't need to wait
ForIdleSync? |
| 1587 ThreadUtils.runOnUiThread(new Runnable() { | 1545 ThreadUtils.runOnUiThread(new Runnable() { |
| 1588 @Override | 1546 @Override |
| 1589 public void run() { | 1547 public void run() { |
| 1590 TabModelUtils.setIndex(mActivityTestRule.getActivity().getCurren
tTabModel(), 0); | 1548 TabModelUtils.setIndex(getActivity().getCurrentTabModel(), 0); |
| 1591 } | 1549 } |
| 1592 }); | 1550 }); |
| 1593 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); | 1551 getInstrumentation().waitForIdleSync(); |
| 1594 | 1552 |
| 1595 clickWordNode("states"); | 1553 clickWordNode("states"); |
| 1596 Assert.assertEquals("States", getSelectedText()); | 1554 assertEquals("States", getSelectedText()); |
| 1597 waitForPanelToPeek(); | 1555 waitForPanelToPeek(); |
| 1598 | 1556 |
| 1599 ThreadUtils.runOnUiThread(new Runnable() { | 1557 ThreadUtils.runOnUiThread(new Runnable() { |
| 1600 @Override | 1558 @Override |
| 1601 public void run() { | 1559 public void run() { |
| 1602 tab2.simulateRendererKilledForTesting(false); | 1560 tab2.simulateRendererKilledForTesting(false); |
| 1603 } | 1561 } |
| 1604 }); | 1562 }); |
| 1605 | 1563 |
| 1606 waitForPanelToPeek(); | 1564 waitForPanelToPeek(); |
| 1607 } | 1565 } |
| 1608 | 1566 |
| 1609 /* | 1567 /* |
| 1610 * Test that tapping on the Search Bar before having a resolved search term
does not | 1568 * Test that tapping on the Search Bar before having a resolved search term
does not |
| 1611 * promote to a tab, and that after the resolution it does promote to a tab. | 1569 * promote to a tab, and that after the resolution it does promote to a tab. |
| 1612 */ | 1570 */ |
| 1613 @Test | |
| 1614 @SmallTest | 1571 @SmallTest |
| 1615 @Feature({"ContextualSearch"}) | 1572 @Feature({"ContextualSearch"}) |
| 1616 public void testTapSearchBarPromotesToTab() throws InterruptedException, Tim
eoutException { | 1573 public void testTapSearchBarPromotesToTab() throws InterruptedException, Tim
eoutException { |
| 1617 // -------- SET UP --------- | 1574 // -------- SET UP --------- |
| 1618 // Track Tab creation with this helper. | 1575 // Track Tab creation with this helper. |
| 1619 final CallbackHelper tabCreatedHelper = new CallbackHelper(); | 1576 final CallbackHelper tabCreatedHelper = new CallbackHelper(); |
| 1620 int tabCreatedHelperCallCount = tabCreatedHelper.getCallCount(); | 1577 int tabCreatedHelperCallCount = tabCreatedHelper.getCallCount(); |
| 1621 TabModelSelectorObserver observer = new EmptyTabModelSelectorObserver()
{ | 1578 TabModelSelectorObserver observer = new EmptyTabModelSelectorObserver()
{ |
| 1622 @Override | 1579 @Override |
| 1623 public void onNewTabCreated(Tab tab) { | 1580 public void onNewTabCreated(Tab tab) { |
| 1624 tabCreatedHelper.notifyCalled(); | 1581 tabCreatedHelper.notifyCalled(); |
| 1625 } | 1582 } |
| 1626 }; | 1583 }; |
| 1627 mActivityTestRule.getActivity().getTabModelSelector().addObserver(observ
er); | 1584 getActivity().getTabModelSelector().addObserver(observer); |
| 1628 | 1585 |
| 1629 // -------- TEST --------- | 1586 // -------- TEST --------- |
| 1630 // Start a slow-resolve search and maximize the Panel. | 1587 // Start a slow-resolve search and maximize the Panel. |
| 1631 simulateSlowResolveSearch("search"); | 1588 simulateSlowResolveSearch("search"); |
| 1632 flingPanelUpToTop(); | 1589 flingPanelUpToTop(); |
| 1633 waitForPanelToMaximize(); | 1590 waitForPanelToMaximize(); |
| 1634 | 1591 |
| 1635 // A click in the Bar should not promote since we are still waiting to R
esolve. | 1592 // A click in the Bar should not promote since we are still waiting to R
esolve. |
| 1636 forcePanelToHandleBarClick(); | 1593 forcePanelToHandleBarClick(); |
| 1637 | 1594 |
| 1638 // Assert that the Panel is still maximized. | 1595 // Assert that the Panel is still maximized. |
| 1639 waitForPanelToMaximize(); | 1596 waitForPanelToMaximize(); |
| 1640 | 1597 |
| 1641 // Let the Search Term Resolution finish. | 1598 // Let the Search Term Resolution finish. |
| 1642 simulateSlowResolveFinished(); | 1599 simulateSlowResolveFinished(); |
| 1643 | 1600 |
| 1644 // Now a click in the Bar should promote to a separate tab. | 1601 // Now a click in the Bar should promote to a separate tab. |
| 1645 forcePanelToHandleBarClick(); | 1602 forcePanelToHandleBarClick(); |
| 1646 | 1603 |
| 1647 // The Panel should now be closed. | 1604 // The Panel should now be closed. |
| 1648 waitForPanelToClose(); | 1605 waitForPanelToClose(); |
| 1649 | 1606 |
| 1650 // Make sure a tab was created. | 1607 // Make sure a tab was created. |
| 1651 tabCreatedHelper.waitForCallback(tabCreatedHelperCallCount); | 1608 tabCreatedHelper.waitForCallback(tabCreatedHelperCallCount); |
| 1652 | 1609 |
| 1653 // -------- CLEAN UP --------- | 1610 // -------- CLEAN UP --------- |
| 1654 mActivityTestRule.getActivity().getTabModelSelector().removeObserver(obs
erver); | 1611 getActivity().getTabModelSelector().removeObserver(observer); |
| 1655 } | 1612 } |
| 1656 | 1613 |
| 1657 /** | 1614 /** |
| 1658 * Tests that a Tap gesture on an element with an ARIA role does not trigger
. | 1615 * Tests that a Tap gesture on an element with an ARIA role does not trigger
. |
| 1659 */ | 1616 */ |
| 1660 @Test | |
| 1661 @SmallTest | 1617 @SmallTest |
| 1662 @Feature({"ContextualSearch"}) | 1618 @Feature({"ContextualSearch"}) |
| 1663 public void testTapOnRoleIgnored() throws InterruptedException, TimeoutExcep
tion { | 1619 public void testTapOnRoleIgnored() throws InterruptedException, TimeoutExcep
tion { |
| 1664 PanelState initialState = mPanel.getPanelState(); | 1620 PanelState initialState = mPanel.getPanelState(); |
| 1665 clickNode("role"); | 1621 clickNode("role"); |
| 1666 assertPanelStillInState(initialState); | 1622 assertPanelStillInState(initialState); |
| 1667 } | 1623 } |
| 1668 | 1624 |
| 1669 /** | 1625 /** |
| 1670 * Tests that a Tap gesture on an element with an ARIA attribute does not tr
igger. | 1626 * Tests that a Tap gesture on an element with an ARIA attribute does not tr
igger. |
| 1671 * http://crbug.com/542874 | 1627 * http://crbug.com/542874 |
| 1672 */ | 1628 */ |
| 1673 @Test | |
| 1674 @SmallTest | 1629 @SmallTest |
| 1675 @Feature({"ContextualSearch"}) | 1630 @Feature({"ContextualSearch"}) |
| 1676 public void testTapOnARIAIgnored() throws InterruptedException, TimeoutExcep
tion { | 1631 public void testTapOnARIAIgnored() throws InterruptedException, TimeoutExcep
tion { |
| 1677 PanelState initialState = mPanel.getPanelState(); | 1632 PanelState initialState = mPanel.getPanelState(); |
| 1678 clickNode("aria"); | 1633 clickNode("aria"); |
| 1679 assertPanelStillInState(initialState); | 1634 assertPanelStillInState(initialState); |
| 1680 } | 1635 } |
| 1681 | 1636 |
| 1682 /** | 1637 /** |
| 1683 * Tests that a Tap gesture on an element that is focusable does not trigger
. | 1638 * Tests that a Tap gesture on an element that is focusable does not trigger
. |
| 1684 */ | 1639 */ |
| 1685 @Test | |
| 1686 @SmallTest | 1640 @SmallTest |
| 1687 @Feature({"ContextualSearch"}) | 1641 @Feature({"ContextualSearch"}) |
| 1688 public void testTapOnFocusableIgnored() throws InterruptedException, Timeout
Exception { | 1642 public void testTapOnFocusableIgnored() throws InterruptedException, Timeout
Exception { |
| 1689 PanelState initialState = mPanel.getPanelState(); | 1643 PanelState initialState = mPanel.getPanelState(); |
| 1690 clickNode("focusable"); | 1644 clickNode("focusable"); |
| 1691 assertPanelStillInState(initialState); | 1645 assertPanelStillInState(initialState); |
| 1692 } | 1646 } |
| 1693 | 1647 |
| 1694 /** | 1648 /** |
| 1695 * Tests that taps can be resolve and prefetch limited for decided users. | 1649 * Tests that taps can be resolve and prefetch limited for decided users. |
| 1696 */ | 1650 */ |
| 1697 @Test | |
| 1698 @SmallTest | 1651 @SmallTest |
| 1699 @Feature({"ContextualSearch"}) | 1652 @Feature({"ContextualSearch"}) |
| 1700 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 1653 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 1701 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") | 1654 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1702 public void testTapLimitForDecided() throws InterruptedException, TimeoutExc
eption { | 1655 public void testTapLimitForDecided() throws InterruptedException, TimeoutExc
eption { |
| 1703 mPolicy.setTapLimitForDecidedForTesting(2); | 1656 mPolicy.setTapLimitForDecidedForTesting(2); |
| 1704 clickToTriggerPrefetch(); | 1657 clickToTriggerPrefetch(); |
| 1705 assertSearchTermRequested(); | 1658 assertSearchTermRequested(); |
| 1706 assertLoadedLowPriorityUrl(); | 1659 assertLoadedLowPriorityUrl(); |
| 1707 clickToTriggerPrefetch(); | 1660 clickToTriggerPrefetch(); |
| 1708 assertSearchTermRequested(); | 1661 assertSearchTermRequested(); |
| 1709 assertLoadedLowPriorityUrl(); | 1662 assertLoadedLowPriorityUrl(); |
| 1710 // 3rd click should not resolve or prefetch. | 1663 // 3rd click should not resolve or prefetch. |
| 1711 clickToTriggerLimitedPrefetch(); | 1664 clickToTriggerLimitedPrefetch(); |
| 1712 assertSearchTermNotRequested(); | 1665 assertSearchTermNotRequested(); |
| 1713 assertLoadedNoUrl(); | 1666 assertLoadedNoUrl(); |
| 1714 | 1667 |
| 1715 // Expanding the panel should reset the limit. | 1668 // Expanding the panel should reset the limit. |
| 1716 clickToExpandAndClosePanel(); | 1669 clickToExpandAndClosePanel(); |
| 1717 | 1670 |
| 1718 // Click should resolve and prefetch again. | 1671 // Click should resolve and prefetch again. |
| 1719 clickToTriggerPrefetch(); | 1672 clickToTriggerPrefetch(); |
| 1720 assertSearchTermRequested(); | 1673 assertSearchTermRequested(); |
| 1721 assertLoadedLowPriorityUrl(); | 1674 assertLoadedLowPriorityUrl(); |
| 1722 } | 1675 } |
| 1723 | 1676 |
| 1724 /** | 1677 /** |
| 1725 * Tests that taps can be resolve-limited for undecided users. | 1678 * Tests that taps can be resolve-limited for undecided users. |
| 1726 */ | 1679 */ |
| 1727 @Test | |
| 1728 @SmallTest | 1680 @SmallTest |
| 1729 @Feature({"ContextualSearch"}) | 1681 @Feature({"ContextualSearch"}) |
| 1730 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 1682 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 1731 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") | 1683 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1732 public void testTapLimitForUndecided() throws InterruptedException, TimeoutE
xception { | 1684 public void testTapLimitForUndecided() throws InterruptedException, TimeoutE
xception { |
| 1733 mPolicy.setTapLimitForUndecidedForTesting(2); | 1685 mPolicy.setTapLimitForUndecidedForTesting(2); |
| 1734 mPolicy.overrideDecidedStateForTesting(false); | 1686 mPolicy.overrideDecidedStateForTesting(false); |
| 1735 | 1687 |
| 1736 clickToTriggerPrefetch(); | 1688 clickToTriggerPrefetch(); |
| 1737 assertSearchTermRequested(); | 1689 assertSearchTermRequested(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1750 // Click should resolve and prefetch again. | 1702 // Click should resolve and prefetch again. |
| 1751 clickToTriggerPrefetch(); | 1703 clickToTriggerPrefetch(); |
| 1752 assertSearchTermRequested(); | 1704 assertSearchTermRequested(); |
| 1753 assertLoadedLowPriorityUrl(); | 1705 assertLoadedLowPriorityUrl(); |
| 1754 } | 1706 } |
| 1755 | 1707 |
| 1756 /** | 1708 /** |
| 1757 * Tests expanding the panel before the search term has resolved, verifies t
hat nothing | 1709 * Tests expanding the panel before the search term has resolved, verifies t
hat nothing |
| 1758 * loads until the resolve completes and that it's now a normal priority URL
. | 1710 * loads until the resolve completes and that it's now a normal priority URL
. |
| 1759 */ | 1711 */ |
| 1760 @Test | |
| 1761 @SmallTest | 1712 @SmallTest |
| 1762 @Feature({"ContextualSearch"}) | 1713 @Feature({"ContextualSearch"}) |
| 1763 public void testExpandBeforeSearchTermResolution() | 1714 public void testExpandBeforeSearchTermResolution() |
| 1764 throws InterruptedException, TimeoutException { | 1715 throws InterruptedException, TimeoutException { |
| 1765 clickWordNode("states"); | 1716 clickWordNode("states"); |
| 1766 assertNoContentViewCore(); | 1717 assertNoContentViewCore(); |
| 1767 | 1718 |
| 1768 // Expanding before the search term resolves should not load anything. | 1719 // Expanding before the search term resolves should not load anything. |
| 1769 tapPeekingBarToExpandAndAssert(); | 1720 tapPeekingBarToExpandAndAssert(); |
| 1770 assertLoadedNoUrl(); | 1721 assertLoadedNoUrl(); |
| 1771 | 1722 |
| 1772 // Once the response comes in, it should load. | 1723 // Once the response comes in, it should load. |
| 1773 fakeResponse(false, 200, "states", "United States Intelligence", "altern
ate-term", false); | 1724 fakeResponse(false, 200, "states", "United States Intelligence", "altern
ate-term", false); |
| 1774 assertContainsParameters("states", "alternate-term"); | 1725 assertContainsParameters("states", "alternate-term"); |
| 1775 assertLoadedNormalPriorityUrl(); | 1726 assertLoadedNormalPriorityUrl(); |
| 1776 assertContentViewCoreCreated(); | 1727 assertContentViewCoreCreated(); |
| 1777 assertContentViewCoreVisible(); | 1728 assertContentViewCoreVisible(); |
| 1778 } | 1729 } |
| 1779 | 1730 |
| 1780 /** | 1731 /** |
| 1781 * Tests that an error from the Search Term Resolution request causes a fall
back to a | 1732 * Tests that an error from the Search Term Resolution request causes a fall
back to a |
| 1782 * search request for the literal selection. | 1733 * search request for the literal selection. |
| 1783 */ | 1734 */ |
| 1784 @Test | |
| 1785 @SmallTest | 1735 @SmallTest |
| 1786 @Feature({"ContextualSearch"}) | 1736 @Feature({"ContextualSearch"}) |
| 1787 public void testSearchTermResolutionError() throws InterruptedException, Tim
eoutException { | 1737 public void testSearchTermResolutionError() throws InterruptedException, Tim
eoutException { |
| 1788 clickWordNode("states"); | 1738 clickWordNode("states"); |
| 1789 assertSearchTermRequested(); | 1739 assertSearchTermRequested(); |
| 1790 fakeResponse(false, 403, "", "", "", false); | 1740 fakeResponse(false, 403, "", "", "", false); |
| 1791 assertLoadedNoUrl(); | 1741 assertLoadedNoUrl(); |
| 1792 tapPeekingBarToExpandAndAssert(); | 1742 tapPeekingBarToExpandAndAssert(); |
| 1793 assertLoadedNormalPriorityUrl(); | 1743 assertLoadedNormalPriorityUrl(); |
| 1794 } | 1744 } |
| 1795 | 1745 |
| 1796 // -------------------------------------------------------------------------
------------------- | 1746 // -------------------------------------------------------------------------
------------------- |
| 1797 // HTTP/HTTPS for Undecided/Decided users. | 1747 // HTTP/HTTPS for Undecided/Decided users. |
| 1798 // -------------------------------------------------------------------------
------------------- | 1748 // -------------------------------------------------------------------------
------------------- |
| 1799 | 1749 |
| 1800 /** | 1750 /** |
| 1801 * Tests that HTTPS does not resolve in the opt-out model before the user ac
cepts. | 1751 * Tests that HTTPS does not resolve in the opt-out model before the user ac
cepts. |
| 1802 */ | 1752 */ |
| 1803 @Test | |
| 1804 @SmallTest | 1753 @SmallTest |
| 1805 @Feature({"ContextualSearch"}) | 1754 @Feature({"ContextualSearch"}) |
| 1806 public void testHttpsBeforeAcceptForOptOut() throws InterruptedException, Ti
meoutException { | 1755 public void testHttpsBeforeAcceptForOptOut() throws InterruptedException, Ti
meoutException { |
| 1807 mPolicy.overrideDecidedStateForTesting(false); | 1756 mPolicy.overrideDecidedStateForTesting(false); |
| 1808 mFakeServer.setShouldUseHttps(true); | 1757 mFakeServer.setShouldUseHttps(true); |
| 1809 | 1758 |
| 1810 clickWordNode("states"); | 1759 clickWordNode("states"); |
| 1811 assertLoadedLowPriorityUrl(); | 1760 assertLoadedLowPriorityUrl(); |
| 1812 assertSearchTermNotRequested(); | 1761 assertSearchTermNotRequested(); |
| 1813 } | 1762 } |
| 1814 | 1763 |
| 1815 /** | 1764 /** |
| 1816 * Tests that HTTPS does resolve in the opt-out model after the user accepts
. | 1765 * Tests that HTTPS does resolve in the opt-out model after the user accepts
. |
| 1817 */ | 1766 */ |
| 1818 @Test | |
| 1819 @SmallTest | 1767 @SmallTest |
| 1820 @Feature({"ContextualSearch"}) | 1768 @Feature({"ContextualSearch"}) |
| 1821 public void testHttpsAfterAcceptForOptOut() throws InterruptedException, Tim
eoutException { | 1769 public void testHttpsAfterAcceptForOptOut() throws InterruptedException, Tim
eoutException { |
| 1822 mPolicy.overrideDecidedStateForTesting(true); | 1770 mPolicy.overrideDecidedStateForTesting(true); |
| 1823 mFakeServer.setShouldUseHttps(true); | 1771 mFakeServer.setShouldUseHttps(true); |
| 1824 | 1772 |
| 1825 clickToResolveAndAssertPrefetch(); | 1773 clickToResolveAndAssertPrefetch(); |
| 1826 } | 1774 } |
| 1827 | 1775 |
| 1828 /** | 1776 /** |
| 1829 * Tests that HTTP does resolve in the opt-out model before the user accepts
. | 1777 * Tests that HTTP does resolve in the opt-out model before the user accepts
. |
| 1830 */ | 1778 */ |
| 1831 @Test | |
| 1832 @SmallTest | 1779 @SmallTest |
| 1833 @Feature({"ContextualSearch"}) | 1780 @Feature({"ContextualSearch"}) |
| 1834 public void testHttpBeforeAcceptForOptOut() throws InterruptedException, Tim
eoutException { | 1781 public void testHttpBeforeAcceptForOptOut() throws InterruptedException, Tim
eoutException { |
| 1835 mPolicy.overrideDecidedStateForTesting(false); | 1782 mPolicy.overrideDecidedStateForTesting(false); |
| 1836 | 1783 |
| 1837 clickToResolveAndAssertPrefetch(); | 1784 clickToResolveAndAssertPrefetch(); |
| 1838 } | 1785 } |
| 1839 | 1786 |
| 1840 /** | 1787 /** |
| 1841 * Tests that HTTP does resolve in the opt-out model after the user accepts. | 1788 * Tests that HTTP does resolve in the opt-out model after the user accepts. |
| 1842 */ | 1789 */ |
| 1843 @Test | |
| 1844 @SmallTest | 1790 @SmallTest |
| 1845 @Feature({"ContextualSearch"}) | 1791 @Feature({"ContextualSearch"}) |
| 1846 public void testHttpAfterAcceptForOptOut() throws InterruptedException, Time
outException { | 1792 public void testHttpAfterAcceptForOptOut() throws InterruptedException, Time
outException { |
| 1847 mPolicy.overrideDecidedStateForTesting(true); | 1793 mPolicy.overrideDecidedStateForTesting(true); |
| 1848 | 1794 |
| 1849 clickToResolveAndAssertPrefetch(); | 1795 clickToResolveAndAssertPrefetch(); |
| 1850 } | 1796 } |
| 1851 | 1797 |
| 1852 // -------------------------------------------------------------------------
------------------- | 1798 // -------------------------------------------------------------------------
------------------- |
| 1853 // App Menu Suppression | 1799 // App Menu Suppression |
| 1854 // -------------------------------------------------------------------------
------------------- | 1800 // -------------------------------------------------------------------------
------------------- |
| 1855 | 1801 |
| 1856 /** | 1802 /** |
| 1857 * Simulates pressing the App Menu button. | 1803 * Simulates pressing the App Menu button. |
| 1858 */ | 1804 */ |
| 1859 private void pressAppMenuKey() { | 1805 private void pressAppMenuKey() { |
| 1860 pressKey(KeyEvent.KEYCODE_MENU); | 1806 pressKey(KeyEvent.KEYCODE_MENU); |
| 1861 } | 1807 } |
| 1862 | 1808 |
| 1863 /** | 1809 /** |
| 1864 * Asserts whether the App Menu is visible. | 1810 * Asserts whether the App Menu is visible. |
| 1865 */ | 1811 */ |
| 1866 private void assertAppMenuVisibility(final boolean isVisible) { | 1812 private void assertAppMenuVisibility(final boolean isVisible) { |
| 1867 CriteriaHelper.pollInstrumentationThread( | 1813 CriteriaHelper.pollInstrumentationThread( |
| 1868 Criteria.equals(isVisible, new Callable<Boolean>() { | 1814 Criteria.equals(isVisible, new Callable<Boolean>() { |
| 1869 @Override | 1815 @Override |
| 1870 public Boolean call() { | 1816 public Boolean call() { |
| 1871 return mActivityTestRule.getActivity() | 1817 return getActivity().getAppMenuHandler().isAppMenuShowin
g(); |
| 1872 .getAppMenuHandler() | |
| 1873 .isAppMenuShowing(); | |
| 1874 } | 1818 } |
| 1875 })); | 1819 })); |
| 1876 } | 1820 } |
| 1877 | 1821 |
| 1878 /** | 1822 /** |
| 1879 * Tests that the App Menu gets suppressed when Search Panel is expanded. | 1823 * Tests that the App Menu gets suppressed when Search Panel is expanded. |
| 1880 */ | 1824 */ |
| 1881 @Test | |
| 1882 @SmallTest | 1825 @SmallTest |
| 1883 @Feature({"ContextualSearch"}) | 1826 @Feature({"ContextualSearch"}) |
| 1884 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 1827 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 1885 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") | 1828 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1886 public void testAppMenuSuppressedWhenExpanded() throws InterruptedException,
TimeoutException { | 1829 public void testAppMenuSuppressedWhenExpanded() throws InterruptedException,
TimeoutException { |
| 1887 clickWordNode("states"); | 1830 clickWordNode("states"); |
| 1888 tapPeekingBarToExpandAndAssert(); | 1831 tapPeekingBarToExpandAndAssert(); |
| 1889 | 1832 |
| 1890 pressAppMenuKey(); | 1833 pressAppMenuKey(); |
| 1891 assertAppMenuVisibility(false); | 1834 assertAppMenuVisibility(false); |
| 1892 | 1835 |
| 1893 tapBasePageToClosePanel(); | 1836 tapBasePageToClosePanel(); |
| 1894 | 1837 |
| 1895 pressAppMenuKey(); | 1838 pressAppMenuKey(); |
| 1896 assertAppMenuVisibility(true); | 1839 assertAppMenuVisibility(true); |
| 1897 } | 1840 } |
| 1898 | 1841 |
| 1899 /** | 1842 /** |
| 1900 * Tests that the App Menu gets suppressed when Search Panel is maximized. | 1843 * Tests that the App Menu gets suppressed when Search Panel is maximized. |
| 1901 */ | 1844 */ |
| 1902 @Test | |
| 1903 @SmallTest | 1845 @SmallTest |
| 1904 @Feature({"ContextualSearch"}) | 1846 @Feature({"ContextualSearch"}) |
| 1905 public void testAppMenuSuppressedWhenMaximized() throws InterruptedException
, TimeoutException { | 1847 public void testAppMenuSuppressedWhenMaximized() throws InterruptedException
, TimeoutException { |
| 1906 clickWordNode("states"); | 1848 clickWordNode("states"); |
| 1907 flingPanelUpToTop(); | 1849 flingPanelUpToTop(); |
| 1908 waitForPanelToMaximize(); | 1850 waitForPanelToMaximize(); |
| 1909 | 1851 |
| 1910 pressAppMenuKey(); | 1852 pressAppMenuKey(); |
| 1911 assertAppMenuVisibility(false); | 1853 assertAppMenuVisibility(false); |
| 1912 | 1854 |
| 1913 pressBackButton(); | 1855 pressBackButton(); |
| 1914 waitForPanelToClose(); | 1856 waitForPanelToClose(); |
| 1915 | 1857 |
| 1916 pressAppMenuKey(); | 1858 pressAppMenuKey(); |
| 1917 assertAppMenuVisibility(true); | 1859 assertAppMenuVisibility(true); |
| 1918 } | 1860 } |
| 1919 | 1861 |
| 1920 // -------------------------------------------------------------------------
------------------- | 1862 // -------------------------------------------------------------------------
------------------- |
| 1921 // Promo tap count - the number of promo peeks. | 1863 // Promo tap count - the number of promo peeks. |
| 1922 // -------------------------------------------------------------------------
------------------- | 1864 // -------------------------------------------------------------------------
------------------- |
| 1923 | 1865 |
| 1924 /** | 1866 /** |
| 1925 * Tests the TapN-promo-limit feature, which disables the promo on tap after
N taps if | 1867 * Tests the TapN-promo-limit feature, which disables the promo on tap after
N taps if |
| 1926 * the user has never ever opened the panel. Once the panel is opened, this
limiting-feature | 1868 * the user has never ever opened the panel. Once the panel is opened, this
limiting-feature |
| 1927 * is permanently disabled. | 1869 * is permanently disabled. |
| 1928 */ | 1870 */ |
| 1929 @Test | |
| 1930 @SmallTest | 1871 @SmallTest |
| 1931 @Feature({"ContextualSearch"}) | 1872 @Feature({"ContextualSearch"}) |
| 1932 public void testPromoTapCount() throws InterruptedException, TimeoutExceptio
n { | 1873 public void testPromoTapCount() throws InterruptedException, TimeoutExceptio
n { |
| 1933 mPolicy.setPromoTapTriggeredLimitForTesting(2); | 1874 mPolicy.setPromoTapTriggeredLimitForTesting(2); |
| 1934 mPolicy.overrideDecidedStateForTesting(false); | 1875 mPolicy.overrideDecidedStateForTesting(false); |
| 1935 assertTapPromoCounterEnabledAt(0); | 1876 assertTapPromoCounterEnabledAt(0); |
| 1936 | 1877 |
| 1937 // A simple Tap should change the counter. | 1878 // A simple Tap should change the counter. |
| 1938 clickToTriggerPrefetch(); | 1879 clickToTriggerPrefetch(); |
| 1939 assertTapPromoCounterEnabledAt(1); | 1880 assertTapPromoCounterEnabledAt(1); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1964 assertTapPromoCounterDisabledAt(2); | 1905 assertTapPromoCounterDisabledAt(2); |
| 1965 } | 1906 } |
| 1966 | 1907 |
| 1967 // -------------------------------------------------------------------------
------------------- | 1908 // -------------------------------------------------------------------------
------------------- |
| 1968 // Promo open count | 1909 // Promo open count |
| 1969 // -------------------------------------------------------------------------
------------------- | 1910 // -------------------------------------------------------------------------
------------------- |
| 1970 | 1911 |
| 1971 /** | 1912 /** |
| 1972 * Tests the promo open counter. | 1913 * Tests the promo open counter. |
| 1973 */ | 1914 */ |
| 1974 @Test | |
| 1975 @SmallTest | 1915 @SmallTest |
| 1976 @Feature({"ContextualSearch"}) | 1916 @Feature({"ContextualSearch"}) |
| 1977 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 1917 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 1978 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") | 1918 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 1979 public void testPromoOpenCountForUndecided() throws InterruptedException, Ti
meoutException { | 1919 public void testPromoOpenCountForUndecided() throws InterruptedException, Ti
meoutException { |
| 1980 mPolicy.overrideDecidedStateForTesting(false); | 1920 mPolicy.overrideDecidedStateForTesting(false); |
| 1981 | 1921 |
| 1982 // A simple click / resolve / prefetch sequence without open should not
change the counter. | 1922 // A simple click / resolve / prefetch sequence without open should not
change the counter. |
| 1983 clickToTriggerPrefetch(); | 1923 clickToTriggerPrefetch(); |
| 1984 Assert.assertEquals(0, mPolicy.getPromoOpenCount()); | 1924 assertEquals(0, mPolicy.getPromoOpenCount()); |
| 1985 | 1925 |
| 1986 // An open should count. | 1926 // An open should count. |
| 1987 clickToExpandAndClosePanel(); | 1927 clickToExpandAndClosePanel(); |
| 1988 Assert.assertEquals(1, mPolicy.getPromoOpenCount()); | 1928 assertEquals(1, mPolicy.getPromoOpenCount()); |
| 1989 | 1929 |
| 1990 // Another open should count. | 1930 // Another open should count. |
| 1991 clickToExpandAndClosePanel(); | 1931 clickToExpandAndClosePanel(); |
| 1992 Assert.assertEquals(2, mPolicy.getPromoOpenCount()); | 1932 assertEquals(2, mPolicy.getPromoOpenCount()); |
| 1993 | 1933 |
| 1994 // Once the user has decided, we should stop counting. | 1934 // Once the user has decided, we should stop counting. |
| 1995 mPolicy.overrideDecidedStateForTesting(true); | 1935 mPolicy.overrideDecidedStateForTesting(true); |
| 1996 clickToExpandAndClosePanel(); | 1936 clickToExpandAndClosePanel(); |
| 1997 Assert.assertEquals(2, mPolicy.getPromoOpenCount()); | 1937 assertEquals(2, mPolicy.getPromoOpenCount()); |
| 1998 } | 1938 } |
| 1999 | 1939 |
| 2000 /** | 1940 /** |
| 2001 * Tests the promo open counter. | 1941 * Tests the promo open counter. |
| 2002 */ | 1942 */ |
| 2003 @Test | |
| 2004 @SmallTest | 1943 @SmallTest |
| 2005 @Feature({"ContextualSearch"}) | 1944 @Feature({"ContextualSearch"}) |
| 2006 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 1945 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2007 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") | 1946 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 2008 public void testPromoOpenCountForDecided() throws InterruptedException, Time
outException { | 1947 public void testPromoOpenCountForDecided() throws InterruptedException, Time
outException { |
| 2009 mPolicy.overrideDecidedStateForTesting(true); | 1948 mPolicy.overrideDecidedStateForTesting(true); |
| 2010 | 1949 |
| 2011 // An open should not count for decided users. | 1950 // An open should not count for decided users. |
| 2012 clickToExpandAndClosePanel(); | 1951 clickToExpandAndClosePanel(); |
| 2013 Assert.assertEquals(0, mPolicy.getPromoOpenCount()); | 1952 assertEquals(0, mPolicy.getPromoOpenCount()); |
| 2014 } | 1953 } |
| 2015 | 1954 |
| 2016 // -------------------------------------------------------------------------
------------------- | 1955 // -------------------------------------------------------------------------
------------------- |
| 2017 // Tap count - number of taps between opens. | 1956 // Tap count - number of taps between opens. |
| 2018 // -------------------------------------------------------------------------
------------------- | 1957 // -------------------------------------------------------------------------
------------------- |
| 2019 /** | 1958 /** |
| 2020 * Tests the counter for the number of taps between opens. | 1959 * Tests the counter for the number of taps between opens. |
| 2021 * @SmallTest | 1960 * @SmallTest |
| 2022 * @Feature({"ContextualSearch"}) | 1961 * @Feature({"ContextualSearch"}) |
| 2023 */ | 1962 */ |
| 2024 @Test | |
| 2025 @FlakyTest | 1963 @FlakyTest |
| 2026 public void testTapCount() throws InterruptedException, TimeoutException { | 1964 public void testTapCount() throws InterruptedException, TimeoutException { |
| 2027 Assert.assertEquals(0, mPolicy.getTapCount()); | 1965 assertEquals(0, mPolicy.getTapCount()); |
| 2028 | 1966 |
| 2029 // A simple Tap should change the counter. | 1967 // A simple Tap should change the counter. |
| 2030 clickToTriggerPrefetch(); | 1968 clickToTriggerPrefetch(); |
| 2031 Assert.assertEquals(1, mPolicy.getTapCount()); | 1969 assertEquals(1, mPolicy.getTapCount()); |
| 2032 | 1970 |
| 2033 // Another Tap should increase the counter. | 1971 // Another Tap should increase the counter. |
| 2034 clickToTriggerPrefetch(); | 1972 clickToTriggerPrefetch(); |
| 2035 Assert.assertEquals(2, mPolicy.getTapCount()); | 1973 assertEquals(2, mPolicy.getTapCount()); |
| 2036 | 1974 |
| 2037 // An open should reset the counter. | 1975 // An open should reset the counter. |
| 2038 clickToExpandAndClosePanel(); | 1976 clickToExpandAndClosePanel(); |
| 2039 Assert.assertEquals(0, mPolicy.getTapCount()); | 1977 assertEquals(0, mPolicy.getTapCount()); |
| 2040 } | 1978 } |
| 2041 | 1979 |
| 2042 // -------------------------------------------------------------------------
------------------- | 1980 // -------------------------------------------------------------------------
------------------- |
| 2043 // Calls to ContextualSearchObserver. | 1981 // Calls to ContextualSearchObserver. |
| 2044 // -------------------------------------------------------------------------
------------------- | 1982 // -------------------------------------------------------------------------
------------------- |
| 2045 private static class TestContextualSearchObserver implements ContextualSearc
hObserver { | 1983 private static class TestContextualSearchObserver implements ContextualSearc
hObserver { |
| 2046 public int hideCount; | 1984 public int hideCount; |
| 2047 | 1985 |
| 2048 @Override | 1986 @Override |
| 2049 public void onShowContextualSearch(GSAContextDisplaySelection selectionC
ontext) {} | 1987 public void onShowContextualSearch(GSAContextDisplaySelection selectionC
ontext) {} |
| 2050 | 1988 |
| 2051 @Override | 1989 @Override |
| 2052 public void onHideContextualSearch() { | 1990 public void onHideContextualSearch() { |
| 2053 hideCount++; | 1991 hideCount++; |
| 2054 } | 1992 } |
| 2055 } | 1993 } |
| 2056 | 1994 |
| 2057 /** | 1995 /** |
| 2058 * Tests that ContextualSearchObserver gets notified when user brings up con
textual search | 1996 * Tests that ContextualSearchObserver gets notified when user brings up con
textual search |
| 2059 * panel via long press and then dismisses the panel by tapping on the base
page. | 1997 * panel via long press and then dismisses the panel by tapping on the base
page. |
| 2060 */ | 1998 */ |
| 2061 @Test | |
| 2062 @SmallTest | 1999 @SmallTest |
| 2063 @Feature({"ContextualSearch"}) | 2000 @Feature({"ContextualSearch"}) |
| 2064 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2001 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2065 public void testNotifyObserverHideAfterLongPress() | 2002 public void testNotifyObserverHideAfterLongPress() |
| 2066 throws InterruptedException, TimeoutException { | 2003 throws InterruptedException, TimeoutException { |
| 2067 TestContextualSearchObserver observer = new TestContextualSearchObserver
(); | 2004 TestContextualSearchObserver observer = new TestContextualSearchObserver
(); |
| 2068 mManager.addObserver(observer); | 2005 mManager.addObserver(observer); |
| 2069 longPressNode("states"); | 2006 longPressNode("states"); |
| 2070 Assert.assertEquals(0, observer.hideCount); | 2007 assertEquals(0, observer.hideCount); |
| 2071 | 2008 |
| 2072 tapBasePageToClosePanel(); | 2009 tapBasePageToClosePanel(); |
| 2073 Assert.assertEquals(1, observer.hideCount); | 2010 assertEquals(1, observer.hideCount); |
| 2074 } | 2011 } |
| 2075 | 2012 |
| 2076 /** | 2013 /** |
| 2077 * Tests that ContextualSearchObserver gets notified when user brings up con
textual search | 2014 * Tests that ContextualSearchObserver gets notified when user brings up con
textual search |
| 2078 * panel via tap and then dismisses the panel by tapping on the base page. | 2015 * panel via tap and then dismisses the panel by tapping on the base page. |
| 2079 */ | 2016 */ |
| 2080 @Test | |
| 2081 @SmallTest | 2017 @SmallTest |
| 2082 @Feature({"ContextualSearch"}) | 2018 @Feature({"ContextualSearch"}) |
| 2083 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2019 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2084 public void testNotifyObserverHideAfterTap() throws InterruptedException, Ti
meoutException { | 2020 public void testNotifyObserverHideAfterTap() throws InterruptedException, Ti
meoutException { |
| 2085 TestContextualSearchObserver observer = new TestContextualSearchObserver
(); | 2021 TestContextualSearchObserver observer = new TestContextualSearchObserver
(); |
| 2086 mManager.addObserver(observer); | 2022 mManager.addObserver(observer); |
| 2087 clickWordNode("states"); | 2023 clickWordNode("states"); |
| 2088 Assert.assertEquals(0, observer.hideCount); | 2024 assertEquals(0, observer.hideCount); |
| 2089 | 2025 |
| 2090 tapBasePageToClosePanel(); | 2026 tapBasePageToClosePanel(); |
| 2091 Assert.assertEquals(1, observer.hideCount); | 2027 assertEquals(1, observer.hideCount); |
| 2092 } | 2028 } |
| 2093 | 2029 |
| 2094 /** | 2030 /** |
| 2095 * Asserts that the action bar does or does not become visible in response t
o a selection. | 2031 * Asserts that the action bar does or does not become visible in response t
o a selection. |
| 2096 * @param visible Whether the Action Bar must become visible or not. | 2032 * @param visible Whether the Action Bar must become visible or not. |
| 2097 * @throws InterruptedException | 2033 * @throws InterruptedException |
| 2098 */ | 2034 */ |
| 2099 private void assertWaitForSelectActionBarVisible(final boolean visible) | 2035 private void assertWaitForSelectActionBarVisible(final boolean visible) |
| 2100 throws InterruptedException { | 2036 throws InterruptedException { |
| 2101 CriteriaHelper.pollUiThread(Criteria.equals(visible, new Callable<Boolea
n>() { | 2037 CriteriaHelper.pollUiThread(Criteria.equals(visible, new Callable<Boolea
n>() { |
| 2102 @Override | 2038 @Override |
| 2103 public Boolean call() { | 2039 public Boolean call() { |
| 2104 return mActivityTestRule.getActivity() | 2040 return getActivity().getActivityTab().getContentViewCore() |
| 2105 .getActivityTab() | |
| 2106 .getContentViewCore() | |
| 2107 .isSelectActionBarShowing(); | 2041 .isSelectActionBarShowing(); |
| 2108 } | 2042 } |
| 2109 })); | 2043 })); |
| 2110 } | 2044 } |
| 2111 | 2045 |
| 2112 /** | 2046 /** |
| 2113 * Tests that ContextualSearchObserver gets notified when user brings up con
textual search | 2047 * Tests that ContextualSearchObserver gets notified when user brings up con
textual search |
| 2114 * panel via long press and then dismisses the panel by tapping copy (hide s
elect action mode). | 2048 * panel via long press and then dismisses the panel by tapping copy (hide s
elect action mode). |
| 2115 */ | 2049 */ |
| 2116 @Test | |
| 2117 @SmallTest | 2050 @SmallTest |
| 2118 @Feature({"ContextualSearch"}) | 2051 @Feature({"ContextualSearch"}) |
| 2119 public void testNotifyObserverHideOnClearSelectionAfterTap() | 2052 public void testNotifyObserverHideOnClearSelectionAfterTap() |
| 2120 throws InterruptedException, TimeoutException { | 2053 throws InterruptedException, TimeoutException { |
| 2121 TestContextualSearchObserver observer = new TestContextualSearchObserver
(); | 2054 TestContextualSearchObserver observer = new TestContextualSearchObserver
(); |
| 2122 mManager.addObserver(observer); | 2055 mManager.addObserver(observer); |
| 2123 longPressNode("states"); | 2056 longPressNode("states"); |
| 2124 Assert.assertEquals(0, observer.hideCount); | 2057 assertEquals(0, observer.hideCount); |
| 2125 | 2058 |
| 2126 // Dismiss select action mode. | 2059 // Dismiss select action mode. |
| 2127 final ContentViewCore contentViewCore = | 2060 final ContentViewCore contentViewCore = getActivity().getActivityTab().g
etContentViewCore(); |
| 2128 mActivityTestRule.getActivity().getActivityTab().getContentViewC
ore(); | |
| 2129 assertWaitForSelectActionBarVisible(true); | 2061 assertWaitForSelectActionBarVisible(true); |
| 2130 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 2062 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 2131 @Override | 2063 @Override |
| 2132 public void run() { | 2064 public void run() { |
| 2133 contentViewCore.destroySelectActionMode(); | 2065 contentViewCore.destroySelectActionMode(); |
| 2134 } | 2066 } |
| 2135 }); | 2067 }); |
| 2136 assertWaitForSelectActionBarVisible(false); | 2068 assertWaitForSelectActionBarVisible(false); |
| 2137 | 2069 |
| 2138 waitForPanelToClose(); | 2070 waitForPanelToClose(); |
| 2139 Assert.assertEquals(1, observer.hideCount); | 2071 assertEquals(1, observer.hideCount); |
| 2140 } | 2072 } |
| 2141 | 2073 |
| 2142 /** | 2074 /** |
| 2143 * Tests that the Contextual Search panel does not reappear when a long-pres
s selection is | 2075 * Tests that the Contextual Search panel does not reappear when a long-pres
s selection is |
| 2144 * modified after the user has taken an action to explicitly dismiss the pan
el. Also tests | 2076 * modified after the user has taken an action to explicitly dismiss the pan
el. Also tests |
| 2145 * that the panel reappears when a new selection is made. | 2077 * that the panel reappears when a new selection is made. |
| 2146 */ | 2078 */ |
| 2147 @Test | |
| 2148 @SmallTest | 2079 @SmallTest |
| 2149 @Feature({"ContextualSearch"}) | 2080 @Feature({"ContextualSearch"}) |
| 2150 public void testPreventHandlingCurrentSelectionModification() | 2081 public void testPreventHandlingCurrentSelectionModification() |
| 2151 throws InterruptedException, TimeoutException { | 2082 throws InterruptedException, TimeoutException { |
| 2152 simulateLongPressSearch("search"); | 2083 simulateLongPressSearch("search"); |
| 2153 | 2084 |
| 2154 // Dismiss the Contextual Search panel. | 2085 // Dismiss the Contextual Search panel. |
| 2155 closePanel(); | 2086 closePanel(); |
| 2156 Assert.assertEquals("Search", getSelectedText()); | 2087 assertEquals("Search", getSelectedText()); |
| 2157 | 2088 |
| 2158 // Simulate a selection change event and assert that the panel has not r
eappeared. | 2089 // Simulate a selection change event and assert that the panel has not r
eappeared. |
| 2159 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 2090 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 2160 @Override | 2091 @Override |
| 2161 public void run() { | 2092 public void run() { |
| 2162 mManager.onSelectionEvent( | 2093 mManager.onSelectionEvent( |
| 2163 SelectionEventType.SELECTION_HANDLE_DRAG_STARTED, 333, 4
50); | 2094 SelectionEventType.SELECTION_HANDLE_DRAG_STARTED, 333, 4
50); |
| 2164 mManager.onSelectionEvent( | 2095 mManager.onSelectionEvent( |
| 2165 SelectionEventType.SELECTION_HANDLE_DRAG_STOPPED, 303, 4
50); | 2096 SelectionEventType.SELECTION_HANDLE_DRAG_STOPPED, 303, 4
50); |
| 2166 } | 2097 } |
| 2167 }); | 2098 }); |
| 2168 assertPanelClosedOrUndefined(); | 2099 assertPanelClosedOrUndefined(); |
| 2169 | 2100 |
| 2170 // Select a different word and assert that the panel has appeared. | 2101 // Select a different word and assert that the panel has appeared. |
| 2171 simulateLongPressSearch("resolution"); | 2102 simulateLongPressSearch("resolution"); |
| 2172 // The simulateLongPressSearch call will verify that the panel peeks. | 2103 // The simulateLongPressSearch call will verify that the panel peeks. |
| 2173 } | 2104 } |
| 2174 | 2105 |
| 2175 /** | 2106 /** |
| 2176 * Tests a bunch of taps in a row. | 2107 * Tests a bunch of taps in a row. |
| 2177 * We've had reliability problems with a sequence of simple taps, due to asy
nc dissolving | 2108 * We've had reliability problems with a sequence of simple taps, due to asy
nc dissolving |
| 2178 * of selection bounds, so this helps prevent a regression with that. | 2109 * of selection bounds, so this helps prevent a regression with that. |
| 2179 */ | 2110 */ |
| 2180 @Test | |
| 2181 @SmallTest | 2111 @SmallTest |
| 2182 @Feature({"ContextualSearch"}) | 2112 @Feature({"ContextualSearch"}) |
| 2183 public void testTapALot() throws InterruptedException, TimeoutException { | 2113 public void testTapALot() throws InterruptedException, TimeoutException { |
| 2184 mPolicy.setTapLimitForDecidedForTesting(PLENTY_OF_TAPS); | 2114 mPolicy.setTapLimitForDecidedForTesting(PLENTY_OF_TAPS); |
| 2185 mPolicy.setTapLimitForUndecidedForTesting(PLENTY_OF_TAPS); | 2115 mPolicy.setTapLimitForUndecidedForTesting(PLENTY_OF_TAPS); |
| 2186 for (int i = 0; i < 50; i++) { | 2116 for (int i = 0; i < 50; i++) { |
| 2187 clickToTriggerPrefetch(); | 2117 clickToTriggerPrefetch(); |
| 2188 waitForSelectionEmpty(); | 2118 waitForSelectionEmpty(); |
| 2189 assertSearchTermRequested(); | 2119 assertSearchTermRequested(); |
| 2190 } | 2120 } |
| 2191 } | 2121 } |
| 2192 | 2122 |
| 2193 /** | 2123 /** |
| 2194 * Tests ContextualSearchManager#shouldInterceptNavigation for a case that a
n external | 2124 * Tests ContextualSearchManager#shouldInterceptNavigation for a case that a
n external |
| 2195 * navigation has a user gesture. | 2125 * navigation has a user gesture. |
| 2196 */ | 2126 */ |
| 2197 @Test | |
| 2198 @SmallTest | 2127 @SmallTest |
| 2199 @Feature({"ContextualSearch"}) | 2128 @Feature({"ContextualSearch"}) |
| 2200 public void testExternalNavigationWithUserGesture() { | 2129 public void testExternalNavigationWithUserGesture() { |
| 2201 final ExternalNavigationHandler externalNavHandler = | 2130 final ExternalNavigationHandler externalNavHandler = |
| 2202 new ExternalNavigationHandler(mActivityTestRule.getActivity().ge
tActivityTab()); | 2131 new ExternalNavigationHandler(getActivity().getActivityTab()); |
| 2203 final NavigationParams navigationParams = new NavigationParams( | 2132 final NavigationParams navigationParams = new NavigationParams( |
| 2204 "intent://test/#Intent;scheme=test;package=com.chrome.test;end",
"", | 2133 "intent://test/#Intent;scheme=test;package=com.chrome.test;end",
"", |
| 2205 false /* isPost */, true /* hasUserGesture */, PageTransition.LI
NK, | 2134 false /* isPost */, true /* hasUserGesture */, PageTransition.LI
NK, |
| 2206 false /* isRedirect */, true /* isExternalProtocol */, true /* i
sMainFrame */, | 2135 false /* isRedirect */, true /* isExternalProtocol */, true /* i
sMainFrame */, |
| 2207 false /* hasUserGestureCarryover */); | 2136 false /* hasUserGestureCarryover */); |
| 2208 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 2137 getInstrumentation().runOnMainSync(new Runnable() { |
| 2209 @Override | 2138 @Override |
| 2210 public void run() { | 2139 public void run() { |
| 2211 Assert.assertFalse(mManager.getOverlayContentDelegate().shouldIn
terceptNavigation( | 2140 assertFalse( |
| 2212 externalNavHandler, navigationParams)); | 2141 mManager.getOverlayContentDelegate().shouldInterceptNavi
gation( |
| 2142 externalNavHandler, navigationParams)); |
| 2213 } | 2143 } |
| 2214 }); | 2144 }); |
| 2215 Assert.assertEquals(1, mActivityMonitor.getHits()); | 2145 assertEquals(1, mActivityMonitor.getHits()); |
| 2216 } | 2146 } |
| 2217 | 2147 |
| 2218 /** | 2148 /** |
| 2219 * Tests ContextualSearchManager#shouldInterceptNavigation for a case that a
n initial | 2149 * Tests ContextualSearchManager#shouldInterceptNavigation for a case that a
n initial |
| 2220 * navigation has a user gesture but the redirected external navigation does
n't. | 2150 * navigation has a user gesture but the redirected external navigation does
n't. |
| 2221 */ | 2151 */ |
| 2222 @Test | |
| 2223 @SmallTest | 2152 @SmallTest |
| 2224 @Feature({"ContextualSearch"}) | 2153 @Feature({"ContextualSearch"}) |
| 2225 public void testRedirectedExternalNavigationWithUserGesture() { | 2154 public void testRedirectedExternalNavigationWithUserGesture() { |
| 2226 final ExternalNavigationHandler externalNavHandler = | 2155 final ExternalNavigationHandler externalNavHandler = |
| 2227 new ExternalNavigationHandler(mActivityTestRule.getActivity().ge
tActivityTab()); | 2156 new ExternalNavigationHandler(getActivity().getActivityTab()); |
| 2228 | 2157 |
| 2229 final NavigationParams initialNavigationParams = new NavigationParams("h
ttp://test.com", "", | 2158 final NavigationParams initialNavigationParams = new NavigationParams("h
ttp://test.com", "", |
| 2230 false /* isPost */, true /* hasUserGesture */, PageTransition.LI
NK, | 2159 false /* isPost */, true /* hasUserGesture */, PageTransition.LI
NK, |
| 2231 false /* isRedirect */, false /* isExternalProtocol */, true /*
isMainFrame */, | 2160 false /* isRedirect */, false /* isExternalProtocol */, true /*
isMainFrame */, |
| 2232 false /* hasUserGestureCarryover */); | 2161 false /* hasUserGestureCarryover */); |
| 2233 final NavigationParams redirectedNavigationParams = new NavigationParams
( | 2162 final NavigationParams redirectedNavigationParams = new NavigationParams
( |
| 2234 "intent://test/#Intent;scheme=test;package=com.chrome.test;end",
"", | 2163 "intent://test/#Intent;scheme=test;package=com.chrome.test;end",
"", |
| 2235 false /* isPost */, false /* hasUserGesture */, PageTransition.L
INK, | 2164 false /* isPost */, false /* hasUserGesture */, PageTransition.L
INK, |
| 2236 true /* isRedirect */, true /* isExternalProtocol */, true /* is
MainFrame */, | 2165 true /* isRedirect */, true /* isExternalProtocol */, true /* is
MainFrame */, |
| 2237 false /* hasUserGestureCarryover */); | 2166 false /* hasUserGestureCarryover */); |
| 2238 | 2167 |
| 2239 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 2168 getInstrumentation().runOnMainSync(new Runnable() { |
| 2240 @Override | 2169 @Override |
| 2241 public void run() { | 2170 public void run() { |
| 2242 OverlayContentDelegate delegate = mManager.getOverlayContentDele
gate(); | 2171 OverlayContentDelegate delegate = mManager.getOverlayContentDele
gate(); |
| 2243 Assert.assertTrue(delegate.shouldInterceptNavigation( | 2172 assertTrue(delegate.shouldInterceptNavigation( |
| 2244 externalNavHandler, initialNavigationParams)); | 2173 externalNavHandler, initialNavigationParams)); |
| 2245 Assert.assertFalse(delegate.shouldInterceptNavigation( | 2174 assertFalse(delegate.shouldInterceptNavigation( |
| 2246 externalNavHandler, redirectedNavigationParams)); | 2175 externalNavHandler, redirectedNavigationParams)); |
| 2247 } | 2176 } |
| 2248 }); | 2177 }); |
| 2249 Assert.assertEquals(1, mActivityMonitor.getHits()); | 2178 assertEquals(1, mActivityMonitor.getHits()); |
| 2250 } | 2179 } |
| 2251 | 2180 |
| 2252 /** | 2181 /** |
| 2253 * Tests ContextualSearchManager#shouldInterceptNavigation for a case that a
n external | 2182 * Tests ContextualSearchManager#shouldInterceptNavigation for a case that a
n external |
| 2254 * navigation doesn't have a user gesture. | 2183 * navigation doesn't have a user gesture. |
| 2255 */ | 2184 */ |
| 2256 @Test | |
| 2257 @SmallTest | 2185 @SmallTest |
| 2258 @Feature({"ContextualSearch"}) | 2186 @Feature({"ContextualSearch"}) |
| 2259 public void testExternalNavigationWithoutUserGesture() { | 2187 public void testExternalNavigationWithoutUserGesture() { |
| 2260 final ExternalNavigationHandler externalNavHandler = | 2188 final ExternalNavigationHandler externalNavHandler = |
| 2261 new ExternalNavigationHandler(mActivityTestRule.getActivity().ge
tActivityTab()); | 2189 new ExternalNavigationHandler(getActivity().getActivityTab()); |
| 2262 final NavigationParams navigationParams = new NavigationParams( | 2190 final NavigationParams navigationParams = new NavigationParams( |
| 2263 "intent://test/#Intent;scheme=test;package=com.chrome.test;end",
"", | 2191 "intent://test/#Intent;scheme=test;package=com.chrome.test;end",
"", |
| 2264 false /* isPost */, false /* hasUserGesture */, PageTransition.L
INK, | 2192 false /* isPost */, false /* hasUserGesture */, PageTransition.L
INK, |
| 2265 false /* isRedirect */, true /* isExternalProtocol */, true /* i
sMainFrame */, | 2193 false /* isRedirect */, true /* isExternalProtocol */, true /* i
sMainFrame */, |
| 2266 false /* hasUserGestureCarryover */); | 2194 false /* hasUserGestureCarryover */); |
| 2267 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 2195 getInstrumentation().runOnMainSync(new Runnable() { |
| 2268 @Override | 2196 @Override |
| 2269 public void run() { | 2197 public void run() { |
| 2270 Assert.assertFalse(mManager.getOverlayContentDelegate().shouldIn
terceptNavigation( | 2198 assertFalse( |
| 2271 externalNavHandler, navigationParams)); | 2199 mManager.getOverlayContentDelegate().shouldInterceptNavi
gation( |
| 2200 externalNavHandler, navigationParams)); |
| 2272 } | 2201 } |
| 2273 }); | 2202 }); |
| 2274 Assert.assertEquals(0, mActivityMonitor.getHits()); | 2203 assertEquals(0, mActivityMonitor.getHits()); |
| 2275 } | 2204 } |
| 2276 | 2205 |
| 2277 @Test | |
| 2278 @SmallTest | 2206 @SmallTest |
| 2279 @Feature({"ContextualSearch"}) | 2207 @Feature({"ContextualSearch"}) |
| 2280 public void testSelectionExpansionOnSearchTermResolution() | 2208 public void testSelectionExpansionOnSearchTermResolution() |
| 2281 throws InterruptedException, TimeoutException { | 2209 throws InterruptedException, TimeoutException { |
| 2282 mFakeServer.reset(); | 2210 mFakeServer.reset(); |
| 2283 clickWordNode("intelligence"); | 2211 clickWordNode("intelligence"); |
| 2284 waitForPanelToPeek(); | 2212 waitForPanelToPeek(); |
| 2285 | 2213 |
| 2286 fakeResponse(false, 200, "Intelligence", "United States Intelligence", "
alternate-term", | 2214 fakeResponse(false, 200, "Intelligence", "United States Intelligence", "
alternate-term", |
| 2287 null, false, -14, 0, "", "", "", "", QuickActionCategory.NONE); | 2215 null, false, -14, 0, "", "", "", "", QuickActionCategory.NONE); |
| 2288 waitForSelectionToBe("United States Intelligence"); | 2216 waitForSelectionToBe("United States Intelligence"); |
| 2289 } | 2217 } |
| 2290 | 2218 |
| 2291 /** | 2219 /** |
| 2292 * Tests that long-press triggers the Peek Promo, and expanding the Panel di
smisses it. | 2220 * Tests that long-press triggers the Peek Promo, and expanding the Panel di
smisses it. |
| 2293 */ | 2221 */ |
| 2294 @Test | |
| 2295 @SmallTest | 2222 @SmallTest |
| 2296 @Feature({"ContextualSearch"}) | 2223 @Feature({"ContextualSearch"}) |
| 2297 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2224 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2298 @CommandLineFlags.Add(ContextualSearchFieldTrial.PEEK_PROMO_ENABLED + "=true
") | 2225 @CommandLineFlags.Add(ContextualSearchFieldTrial.PEEK_PROMO_ENABLED + "=true
") |
| 2299 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") | 2226 @DisableIf.Build(supported_abis_includes = "arm64-v8a", message = "crbug.com
/596533") |
| 2300 public void testLongPressShowsPeekPromo() | 2227 public void testLongPressShowsPeekPromo() |
| 2301 throws InterruptedException, TimeoutException { | 2228 throws InterruptedException, TimeoutException { |
| 2302 // Must be in undecided state in order to trigger the Peek Promo. | 2229 // Must be in undecided state in order to trigger the Peek Promo. |
| 2303 mPolicy.overrideDecidedStateForTesting(false); | 2230 mPolicy.overrideDecidedStateForTesting(false); |
| 2304 // Must have never opened the Panel in order to trigger the Peek Promo. | 2231 // Must have never opened the Panel in order to trigger the Peek Promo. |
| 2305 Assert.assertEquals(0, mPolicy.getPromoOpenCount()); | 2232 assertEquals(0, mPolicy.getPromoOpenCount()); |
| 2306 | 2233 |
| 2307 // Long press and make sure the Promo shows. | 2234 // Long press and make sure the Promo shows. |
| 2308 longPressNode("intelligence"); | 2235 longPressNode("intelligence"); |
| 2309 waitForPanelToPeek(); | 2236 waitForPanelToPeek(); |
| 2310 Assert.assertTrue(mPanel.isPeekPromoVisible()); | 2237 assertTrue(mPanel.isPeekPromoVisible()); |
| 2311 | 2238 |
| 2312 // After expanding the Panel the Promo should be invisible. | 2239 // After expanding the Panel the Promo should be invisible. |
| 2313 flingPanelUp(); | 2240 flingPanelUp(); |
| 2314 waitForPanelToExpand(); | 2241 waitForPanelToExpand(); |
| 2315 Assert.assertFalse(mPanel.isPeekPromoVisible()); | 2242 assertFalse(mPanel.isPeekPromoVisible()); |
| 2316 | 2243 |
| 2317 // After closing the Panel the Promo should still be invisible. | 2244 // After closing the Panel the Promo should still be invisible. |
| 2318 tapBasePageToClosePanel(); | 2245 tapBasePageToClosePanel(); |
| 2319 Assert.assertFalse(mPanel.isPeekPromoVisible()); | 2246 assertFalse(mPanel.isPeekPromoVisible()); |
| 2320 | 2247 |
| 2321 // Click elsewhere to clear the selection. | 2248 // Click elsewhere to clear the selection. |
| 2322 clickNode("question-mark"); | 2249 clickNode("question-mark"); |
| 2323 waitForSelectionToBe(null); | 2250 waitForSelectionToBe(null); |
| 2324 | 2251 |
| 2325 // Now that the Panel was opened at least once, the Promo should not sho
w again. | 2252 // Now that the Panel was opened at least once, the Promo should not sho
w again. |
| 2326 longPressNode("intelligence"); | 2253 longPressNode("intelligence"); |
| 2327 waitForPanelToPeek(); | 2254 waitForPanelToPeek(); |
| 2328 Assert.assertFalse(mPanel.isPeekPromoVisible()); | 2255 assertFalse(mPanel.isPeekPromoVisible()); |
| 2329 } | 2256 } |
| 2330 | 2257 |
| 2331 //==========================================================================
================== | 2258 //==========================================================================
================== |
| 2332 // Content Tests | 2259 // Content Tests |
| 2333 //==========================================================================
================== | 2260 //==========================================================================
================== |
| 2334 | 2261 |
| 2335 /** | 2262 /** |
| 2336 * Tests that tap followed by expand makes Content visible. | 2263 * Tests that tap followed by expand makes Content visible. |
| 2337 */ | 2264 */ |
| 2338 @Test | |
| 2339 @SmallTest | 2265 @SmallTest |
| 2340 @Feature({"ContextualSearch"}) | 2266 @Feature({"ContextualSearch"}) |
| 2341 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2267 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2342 public void testTapContentVisibility() throws InterruptedException, TimeoutE
xception { | 2268 public void testTapContentVisibility() throws InterruptedException, TimeoutE
xception { |
| 2343 // Simulate a tap and make sure Content is not visible. | 2269 // Simulate a tap and make sure Content is not visible. |
| 2344 simulateTapSearch("search"); | 2270 simulateTapSearch("search"); |
| 2345 assertContentViewCoreCreatedButNeverMadeVisible(); | 2271 assertContentViewCoreCreatedButNeverMadeVisible(); |
| 2346 | 2272 |
| 2347 // Expanding the Panel should make the Content visible. | 2273 // Expanding the Panel should make the Content visible. |
| 2348 tapPeekingBarToExpandAndAssert(); | 2274 tapPeekingBarToExpandAndAssert(); |
| 2349 assertContentViewCoreVisible(); | 2275 assertContentViewCoreVisible(); |
| 2350 | 2276 |
| 2351 // Closing the Panel should destroy the Content. | 2277 // Closing the Panel should destroy the Content. |
| 2352 tapBasePageToClosePanel(); | 2278 tapBasePageToClosePanel(); |
| 2353 assertNoContentViewCore(); | 2279 assertNoContentViewCore(); |
| 2354 } | 2280 } |
| 2355 | 2281 |
| 2356 /** | 2282 /** |
| 2357 * Tests that long press followed by expand creates Content and makes it vis
ible. | 2283 * Tests that long press followed by expand creates Content and makes it vis
ible. |
| 2358 * | 2284 * |
| 2359 */ | 2285 */ |
| 2360 @Test | |
| 2361 @SmallTest | 2286 @SmallTest |
| 2362 @Feature({"ContextualSearch"}) | 2287 @Feature({"ContextualSearch"}) |
| 2363 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2288 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2364 public void testLongPressContentVisibility() throws InterruptedException, Ti
meoutException { | 2289 public void testLongPressContentVisibility() throws InterruptedException, Ti
meoutException { |
| 2365 // Simulate a long press and make sure no Content is created. | 2290 // Simulate a long press and make sure no Content is created. |
| 2366 simulateLongPressSearch("search"); | 2291 simulateLongPressSearch("search"); |
| 2367 assertNoContentViewCore(); | 2292 assertNoContentViewCore(); |
| 2368 assertNoSearchesLoaded(); | 2293 assertNoSearchesLoaded(); |
| 2369 | 2294 |
| 2370 // Expanding the Panel should make the Content visible. | 2295 // Expanding the Panel should make the Content visible. |
| 2371 tapPeekingBarToExpandAndAssert(); | 2296 tapPeekingBarToExpandAndAssert(); |
| 2372 assertContentViewCoreCreated(); | 2297 assertContentViewCoreCreated(); |
| 2373 assertContentViewCoreVisible(); | 2298 assertContentViewCoreVisible(); |
| 2374 | 2299 |
| 2375 // Closing the Panel should destroy the Content. | 2300 // Closing the Panel should destroy the Content. |
| 2376 tapBasePageToClosePanel(); | 2301 tapBasePageToClosePanel(); |
| 2377 assertNoContentViewCore(); | 2302 assertNoContentViewCore(); |
| 2378 } | 2303 } |
| 2379 | 2304 |
| 2380 /** | 2305 /** |
| 2381 * Tests swiping panel up and down after a tap search will only load the Con
tent once. | 2306 * Tests swiping panel up and down after a tap search will only load the Con
tent once. |
| 2382 */ | 2307 */ |
| 2383 @Test | |
| 2384 @SmallTest | 2308 @SmallTest |
| 2385 @Feature({"ContextualSearch"}) | 2309 @Feature({"ContextualSearch"}) |
| 2386 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2310 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2387 public void testTapMultipleSwipeOnlyLoadsContentOnce() | 2311 public void testTapMultipleSwipeOnlyLoadsContentOnce() |
| 2388 throws InterruptedException, TimeoutException { | 2312 throws InterruptedException, TimeoutException { |
| 2389 // Simulate a tap and make sure Content is not visible. | 2313 // Simulate a tap and make sure Content is not visible. |
| 2390 simulateTapSearch("search"); | 2314 simulateTapSearch("search"); |
| 2391 assertContentViewCoreCreatedButNeverMadeVisible(); | 2315 assertContentViewCoreCreatedButNeverMadeVisible(); |
| 2392 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2316 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2393 | 2317 |
| 2394 // Expanding the Panel should make the Content visible. | 2318 // Expanding the Panel should make the Content visible. |
| 2395 tapPeekingBarToExpandAndAssert(); | 2319 tapPeekingBarToExpandAndAssert(); |
| 2396 assertContentViewCoreVisible(); | 2320 assertContentViewCoreVisible(); |
| 2397 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2321 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2398 | 2322 |
| 2399 // Swiping the Panel down should not change the visibility or load conte
nt again. | 2323 // Swiping the Panel down should not change the visibility or load conte
nt again. |
| 2400 swipePanelDown(); | 2324 swipePanelDown(); |
| 2401 waitForPanelToPeek(); | 2325 waitForPanelToPeek(); |
| 2402 assertContentViewCoreVisible(); | 2326 assertContentViewCoreVisible(); |
| 2403 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2327 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2404 | 2328 |
| 2405 // Expanding the Panel should not change the visibility or load content
again. | 2329 // Expanding the Panel should not change the visibility or load content
again. |
| 2406 tapPeekingBarToExpandAndAssert(); | 2330 tapPeekingBarToExpandAndAssert(); |
| 2407 assertContentViewCoreVisible(); | 2331 assertContentViewCoreVisible(); |
| 2408 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2332 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2409 | 2333 |
| 2410 // Closing the Panel should destroy the Content. | 2334 // Closing the Panel should destroy the Content. |
| 2411 tapBasePageToClosePanel(); | 2335 tapBasePageToClosePanel(); |
| 2412 assertNoContentViewCore(); | 2336 assertNoContentViewCore(); |
| 2413 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2337 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2414 } | 2338 } |
| 2415 | 2339 |
| 2416 /** | 2340 /** |
| 2417 * Tests swiping panel up and down after a long press search will only load
the Content once. | 2341 * Tests swiping panel up and down after a long press search will only load
the Content once. |
| 2418 */ | 2342 */ |
| 2419 @Test | |
| 2420 @SmallTest | 2343 @SmallTest |
| 2421 @Feature({"ContextualSearch"}) | 2344 @Feature({"ContextualSearch"}) |
| 2422 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2345 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2423 public void testLongPressMultipleSwipeOnlyLoadsContentOnce() | 2346 public void testLongPressMultipleSwipeOnlyLoadsContentOnce() |
| 2424 throws InterruptedException, TimeoutException { | 2347 throws InterruptedException, TimeoutException { |
| 2425 // Simulate a long press and make sure no Content is created. | 2348 // Simulate a long press and make sure no Content is created. |
| 2426 simulateLongPressSearch("search"); | 2349 simulateLongPressSearch("search"); |
| 2427 assertNoContentViewCore(); | 2350 assertNoContentViewCore(); |
| 2428 assertNoSearchesLoaded(); | 2351 assertNoSearchesLoaded(); |
| 2429 | 2352 |
| 2430 // Expanding the Panel should load the URL and make the Content visible. | 2353 // Expanding the Panel should load the URL and make the Content visible. |
| 2431 tapPeekingBarToExpandAndAssert(); | 2354 tapPeekingBarToExpandAndAssert(); |
| 2432 assertContentViewCoreCreated(); | 2355 assertContentViewCoreCreated(); |
| 2433 assertContentViewCoreVisible(); | 2356 assertContentViewCoreVisible(); |
| 2434 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2357 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2435 | 2358 |
| 2436 // Swiping the Panel down should not change the visibility or load conte
nt again. | 2359 // Swiping the Panel down should not change the visibility or load conte
nt again. |
| 2437 swipePanelDown(); | 2360 swipePanelDown(); |
| 2438 waitForPanelToPeek(); | 2361 waitForPanelToPeek(); |
| 2439 assertContentViewCoreVisible(); | 2362 assertContentViewCoreVisible(); |
| 2440 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2363 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2441 | 2364 |
| 2442 // Expanding the Panel should not change the visibility or load content
again. | 2365 // Expanding the Panel should not change the visibility or load content
again. |
| 2443 tapPeekingBarToExpandAndAssert(); | 2366 tapPeekingBarToExpandAndAssert(); |
| 2444 assertContentViewCoreVisible(); | 2367 assertContentViewCoreVisible(); |
| 2445 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2368 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2446 | 2369 |
| 2447 // Closing the Panel should destroy the Content. | 2370 // Closing the Panel should destroy the Content. |
| 2448 tapBasePageToClosePanel(); | 2371 tapBasePageToClosePanel(); |
| 2449 assertNoContentViewCore(); | 2372 assertNoContentViewCore(); |
| 2450 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2373 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2451 } | 2374 } |
| 2452 | 2375 |
| 2453 /** | 2376 /** |
| 2454 * Tests that chained tap searches create new Content. | 2377 * Tests that chained tap searches create new Content. |
| 2455 */ | 2378 */ |
| 2456 @Test | |
| 2457 @SmallTest | 2379 @SmallTest |
| 2458 @Feature({"ContextualSearch"}) | 2380 @Feature({"ContextualSearch"}) |
| 2459 public void testChainedSearchCreatesNewContent() throws InterruptedException
, TimeoutException { | 2381 public void testChainedSearchCreatesNewContent() throws InterruptedException
, TimeoutException { |
| 2460 // Simulate a tap and make sure Content is not visible. | 2382 // Simulate a tap and make sure Content is not visible. |
| 2461 simulateTapSearch("search"); | 2383 simulateTapSearch("search"); |
| 2462 assertContentViewCoreCreatedButNeverMadeVisible(); | 2384 assertContentViewCoreCreatedButNeverMadeVisible(); |
| 2463 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2385 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2464 ContentViewCore cvc1 = getPanelContentViewCore(); | 2386 ContentViewCore cvc1 = getPanelContentViewCore(); |
| 2465 | 2387 |
| 2466 waitToPreventDoubleTapRecognition(); | 2388 waitToPreventDoubleTapRecognition(); |
| 2467 | 2389 |
| 2468 // Simulate a new tap and make sure a new Content is created. | 2390 // Simulate a new tap and make sure a new Content is created. |
| 2469 simulateTapSearch("term"); | 2391 simulateTapSearch("term"); |
| 2470 assertContentViewCoreCreatedButNeverMadeVisible(); | 2392 assertContentViewCoreCreatedButNeverMadeVisible(); |
| 2471 Assert.assertEquals(2, mFakeServer.getLoadedUrlCount()); | 2393 assertEquals(2, mFakeServer.getLoadedUrlCount()); |
| 2472 ContentViewCore cvc2 = getPanelContentViewCore(); | 2394 ContentViewCore cvc2 = getPanelContentViewCore(); |
| 2473 Assert.assertNotSame(cvc1, cvc2); | 2395 assertNotSame(cvc1, cvc2); |
| 2474 | 2396 |
| 2475 waitToPreventDoubleTapRecognition(); | 2397 waitToPreventDoubleTapRecognition(); |
| 2476 | 2398 |
| 2477 // Simulate a new tap and make sure a new Content is created. | 2399 // Simulate a new tap and make sure a new Content is created. |
| 2478 simulateTapSearch("resolution"); | 2400 simulateTapSearch("resolution"); |
| 2479 assertContentViewCoreCreatedButNeverMadeVisible(); | 2401 assertContentViewCoreCreatedButNeverMadeVisible(); |
| 2480 Assert.assertEquals(3, mFakeServer.getLoadedUrlCount()); | 2402 assertEquals(3, mFakeServer.getLoadedUrlCount()); |
| 2481 ContentViewCore cvc3 = getPanelContentViewCore(); | 2403 ContentViewCore cvc3 = getPanelContentViewCore(); |
| 2482 Assert.assertNotSame(cvc2, cvc3); | 2404 assertNotSame(cvc2, cvc3); |
| 2483 | 2405 |
| 2484 // Closing the Panel should destroy the Content. | 2406 // Closing the Panel should destroy the Content. |
| 2485 closePanel(); | 2407 closePanel(); |
| 2486 assertNoContentViewCore(); | 2408 assertNoContentViewCore(); |
| 2487 Assert.assertEquals(3, mFakeServer.getLoadedUrlCount()); | 2409 assertEquals(3, mFakeServer.getLoadedUrlCount()); |
| 2488 } | 2410 } |
| 2489 | 2411 |
| 2490 /** | 2412 /** |
| 2491 * Tests that chained searches load correctly. | 2413 * Tests that chained searches load correctly. |
| 2492 */ | 2414 */ |
| 2493 @Test | |
| 2494 @DisabledTest(message = "crbug.com/551711") | 2415 @DisabledTest(message = "crbug.com/551711") |
| 2495 @SmallTest | 2416 @SmallTest |
| 2496 @Feature({"ContextualSearch"}) | 2417 @Feature({"ContextualSearch"}) |
| 2497 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2418 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2498 public void testChainedSearchLoadsCorrectSearchTerm() | 2419 public void testChainedSearchLoadsCorrectSearchTerm() |
| 2499 throws InterruptedException, TimeoutException { | 2420 throws InterruptedException, TimeoutException { |
| 2500 // Simulate a tap and make sure Content is not visible. | 2421 // Simulate a tap and make sure Content is not visible. |
| 2501 simulateTapSearch("search"); | 2422 simulateTapSearch("search"); |
| 2502 assertContentViewCoreCreatedButNeverMadeVisible(); | 2423 assertContentViewCoreCreatedButNeverMadeVisible(); |
| 2503 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2424 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2504 ContentViewCore cvc1 = getPanelContentViewCore(); | 2425 ContentViewCore cvc1 = getPanelContentViewCore(); |
| 2505 | 2426 |
| 2506 // Expanding the Panel should make the Content visible. | 2427 // Expanding the Panel should make the Content visible. |
| 2507 tapPeekingBarToExpandAndAssert(); | 2428 tapPeekingBarToExpandAndAssert(); |
| 2508 assertContentViewCoreVisible(); | 2429 assertContentViewCoreVisible(); |
| 2509 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2430 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2510 | 2431 |
| 2511 // Swiping the Panel down should not change the visibility or load conte
nt again. | 2432 // Swiping the Panel down should not change the visibility or load conte
nt again. |
| 2512 swipePanelDown(); | 2433 swipePanelDown(); |
| 2513 waitForPanelToPeek(); | 2434 waitForPanelToPeek(); |
| 2514 assertContentViewCoreVisible(); | 2435 assertContentViewCoreVisible(); |
| 2515 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2436 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2516 | 2437 |
| 2517 waitToPreventDoubleTapRecognition(); | 2438 waitToPreventDoubleTapRecognition(); |
| 2518 | 2439 |
| 2519 // Now simulate a long press, leaving the Panel peeking. | 2440 // Now simulate a long press, leaving the Panel peeking. |
| 2520 simulateLongPressSearch("resolution"); | 2441 simulateLongPressSearch("resolution"); |
| 2521 | 2442 |
| 2522 // Expanding the Panel should load and display the new search. | 2443 // Expanding the Panel should load and display the new search. |
| 2523 tapPeekingBarToExpandAndAssert(); | 2444 tapPeekingBarToExpandAndAssert(); |
| 2524 assertContentViewCoreCreated(); | 2445 assertContentViewCoreCreated(); |
| 2525 assertContentViewCoreVisible(); | 2446 assertContentViewCoreVisible(); |
| 2526 Assert.assertEquals(2, mFakeServer.getLoadedUrlCount()); | 2447 assertEquals(2, mFakeServer.getLoadedUrlCount()); |
| 2527 assertLoadedSearchTermMatches("Resolution"); | 2448 assertLoadedSearchTermMatches("Resolution"); |
| 2528 ContentViewCore cvc2 = getPanelContentViewCore(); | 2449 ContentViewCore cvc2 = getPanelContentViewCore(); |
| 2529 Assert.assertNotSame(cvc1, cvc2); | 2450 assertNotSame(cvc1, cvc2); |
| 2530 | 2451 |
| 2531 // Closing the Panel should destroy the Content. | 2452 // Closing the Panel should destroy the Content. |
| 2532 tapBasePageToClosePanel(); | 2453 tapBasePageToClosePanel(); |
| 2533 assertNoContentViewCore(); | 2454 assertNoContentViewCore(); |
| 2534 Assert.assertEquals(2, mFakeServer.getLoadedUrlCount()); | 2455 assertEquals(2, mFakeServer.getLoadedUrlCount()); |
| 2535 } | 2456 } |
| 2536 | 2457 |
| 2537 /** | 2458 /** |
| 2538 * Tests that chained searches make Content visible when opening the Panel. | 2459 * Tests that chained searches make Content visible when opening the Panel. |
| 2539 */ | 2460 */ |
| 2540 @Test | |
| 2541 @SmallTest | 2461 @SmallTest |
| 2542 @Feature({"ContextualSearch"}) | 2462 @Feature({"ContextualSearch"}) |
| 2543 public void testChainedSearchContentVisibility() throws InterruptedException
, TimeoutException { | 2463 public void testChainedSearchContentVisibility() throws InterruptedException
, TimeoutException { |
| 2544 // Simulate a tap and make sure Content is not visible. | 2464 // Simulate a tap and make sure Content is not visible. |
| 2545 simulateTapSearch("search"); | 2465 simulateTapSearch("search"); |
| 2546 assertContentViewCoreCreatedButNeverMadeVisible(); | 2466 assertContentViewCoreCreatedButNeverMadeVisible(); |
| 2547 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2467 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2548 ContentViewCore cvc1 = getPanelContentViewCore(); | 2468 ContentViewCore cvc1 = getPanelContentViewCore(); |
| 2549 | 2469 |
| 2550 waitToPreventDoubleTapRecognition(); | 2470 waitToPreventDoubleTapRecognition(); |
| 2551 | 2471 |
| 2552 // Now simulate a long press, leaving the Panel peeking. | 2472 // Now simulate a long press, leaving the Panel peeking. |
| 2553 simulateLongPressSearch("resolution"); | 2473 simulateLongPressSearch("resolution"); |
| 2554 assertNeverCalledContentViewCoreOnShow(); | 2474 assertNeverCalledContentViewCoreOnShow(); |
| 2555 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2475 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2556 | 2476 |
| 2557 // Expanding the Panel should load and display the new search. | 2477 // Expanding the Panel should load and display the new search. |
| 2558 tapPeekingBarToExpandAndAssert(); | 2478 tapPeekingBarToExpandAndAssert(); |
| 2559 assertContentViewCoreCreated(); | 2479 assertContentViewCoreCreated(); |
| 2560 assertContentViewCoreVisible(); | 2480 assertContentViewCoreVisible(); |
| 2561 Assert.assertEquals(2, mFakeServer.getLoadedUrlCount()); | 2481 assertEquals(2, mFakeServer.getLoadedUrlCount()); |
| 2562 assertLoadedSearchTermMatches("Resolution"); | 2482 assertLoadedSearchTermMatches("Resolution"); |
| 2563 ContentViewCore cvc2 = getPanelContentViewCore(); | 2483 ContentViewCore cvc2 = getPanelContentViewCore(); |
| 2564 Assert.assertNotSame(cvc1, cvc2); | 2484 assertNotSame(cvc1, cvc2); |
| 2565 } | 2485 } |
| 2566 | 2486 |
| 2567 //==========================================================================
================== | 2487 //==========================================================================
================== |
| 2568 // History Removal Tests | 2488 // History Removal Tests |
| 2569 //==========================================================================
================== | 2489 //==========================================================================
================== |
| 2570 | 2490 |
| 2571 /** | 2491 /** |
| 2572 * Tests that a tap followed by closing the Panel removes the loaded URL fro
m history. | 2492 * Tests that a tap followed by closing the Panel removes the loaded URL fro
m history. |
| 2573 */ | 2493 */ |
| 2574 @Test | |
| 2575 @SmallTest | 2494 @SmallTest |
| 2576 @Feature({"ContextualSearch"}) | 2495 @Feature({"ContextualSearch"}) |
| 2577 public void testTapCloseRemovedFromHistory() throws InterruptedException, Ti
meoutException { | 2496 public void testTapCloseRemovedFromHistory() throws InterruptedException, Ti
meoutException { |
| 2578 // Simulate a tap and make sure a URL was loaded. | 2497 // Simulate a tap and make sure a URL was loaded. |
| 2579 simulateTapSearch("search"); | 2498 simulateTapSearch("search"); |
| 2580 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2499 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2581 String url = mFakeServer.getLoadedUrl(); | 2500 String url = mFakeServer.getLoadedUrl(); |
| 2582 | 2501 |
| 2583 // Close the Panel without seeing the Content. | 2502 // Close the Panel without seeing the Content. |
| 2584 tapBasePageToClosePanel(); | 2503 tapBasePageToClosePanel(); |
| 2585 | 2504 |
| 2586 // Now check that the URL has been removed from history. | 2505 // Now check that the URL has been removed from history. |
| 2587 Assert.assertTrue(mFakeServer.hasRemovedUrl(url)); | 2506 assertTrue(mFakeServer.hasRemovedUrl(url)); |
| 2588 } | 2507 } |
| 2589 | 2508 |
| 2590 /** | 2509 /** |
| 2591 * Tests that a tap followed by opening the Panel does not remove the loaded
URL from history. | 2510 * Tests that a tap followed by opening the Panel does not remove the loaded
URL from history. |
| 2592 */ | 2511 */ |
| 2593 @Test | |
| 2594 @SmallTest | 2512 @SmallTest |
| 2595 @Feature({"ContextualSearch"}) | 2513 @Feature({"ContextualSearch"}) |
| 2596 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2514 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2597 public void testTapExpandNotRemovedFromHistory() throws InterruptedException
, TimeoutException { | 2515 public void testTapExpandNotRemovedFromHistory() throws InterruptedException
, TimeoutException { |
| 2598 // Simulate a tap and make sure a URL was loaded. | 2516 // Simulate a tap and make sure a URL was loaded. |
| 2599 simulateTapSearch("search"); | 2517 simulateTapSearch("search"); |
| 2600 Assert.assertEquals(1, mFakeServer.getLoadedUrlCount()); | 2518 assertEquals(1, mFakeServer.getLoadedUrlCount()); |
| 2601 String url = mFakeServer.getLoadedUrl(); | 2519 String url = mFakeServer.getLoadedUrl(); |
| 2602 | 2520 |
| 2603 // Expand Panel so that the Content becomes visible. | 2521 // Expand Panel so that the Content becomes visible. |
| 2604 tapPeekingBarToExpandAndAssert(); | 2522 tapPeekingBarToExpandAndAssert(); |
| 2605 | 2523 |
| 2606 // Close the Panel. | 2524 // Close the Panel. |
| 2607 tapBasePageToClosePanel(); | 2525 tapBasePageToClosePanel(); |
| 2608 | 2526 |
| 2609 // Now check that the URL has not been removed from history, since the C
ontent was seen. | 2527 // Now check that the URL has not been removed from history, since the C
ontent was seen. |
| 2610 Assert.assertFalse(mFakeServer.hasRemovedUrl(url)); | 2528 assertFalse(mFakeServer.hasRemovedUrl(url)); |
| 2611 } | 2529 } |
| 2612 | 2530 |
| 2613 /** | 2531 /** |
| 2614 * Tests that chained searches without opening the Panel removes all loaded
URLs from history. | 2532 * Tests that chained searches without opening the Panel removes all loaded
URLs from history. |
| 2615 */ | 2533 */ |
| 2616 @Test | |
| 2617 @SmallTest | 2534 @SmallTest |
| 2618 @Feature({"ContextualSearch"}) | 2535 @Feature({"ContextualSearch"}) |
| 2619 public void testChainedTapsRemovedFromHistory() throws InterruptedException,
TimeoutException { | 2536 public void testChainedTapsRemovedFromHistory() throws InterruptedException,
TimeoutException { |
| 2620 // Simulate a tap and make sure a URL was loaded. | 2537 // Simulate a tap and make sure a URL was loaded. |
| 2621 simulateTapSearch("search"); | 2538 simulateTapSearch("search"); |
| 2622 String url1 = mFakeServer.getLoadedUrl(); | 2539 String url1 = mFakeServer.getLoadedUrl(); |
| 2623 Assert.assertNotNull(url1); | 2540 assertNotNull(url1); |
| 2624 | 2541 |
| 2625 waitToPreventDoubleTapRecognition(); | 2542 waitToPreventDoubleTapRecognition(); |
| 2626 | 2543 |
| 2627 // Simulate another tap and make sure another URL was loaded. | 2544 // Simulate another tap and make sure another URL was loaded. |
| 2628 simulateTapSearch("term"); | 2545 simulateTapSearch("term"); |
| 2629 String url2 = mFakeServer.getLoadedUrl(); | 2546 String url2 = mFakeServer.getLoadedUrl(); |
| 2630 Assert.assertNotSame(url1, url2); | 2547 assertNotSame(url1, url2); |
| 2631 | 2548 |
| 2632 waitToPreventDoubleTapRecognition(); | 2549 waitToPreventDoubleTapRecognition(); |
| 2633 | 2550 |
| 2634 // Simulate another tap and make sure another URL was loaded. | 2551 // Simulate another tap and make sure another URL was loaded. |
| 2635 simulateTapSearch("resolution"); | 2552 simulateTapSearch("resolution"); |
| 2636 String url3 = mFakeServer.getLoadedUrl(); | 2553 String url3 = mFakeServer.getLoadedUrl(); |
| 2637 Assert.assertNotSame(url2, url3); | 2554 assertNotSame(url2, url3); |
| 2638 | 2555 |
| 2639 // Close the Panel without seeing any Content. | 2556 // Close the Panel without seeing any Content. |
| 2640 closePanel(); | 2557 closePanel(); |
| 2641 | 2558 |
| 2642 // Now check that all three URLs have been removed from history. | 2559 // Now check that all three URLs have been removed from history. |
| 2643 Assert.assertEquals(3, mFakeServer.getLoadedUrlCount()); | 2560 assertEquals(3, mFakeServer.getLoadedUrlCount()); |
| 2644 Assert.assertTrue(mFakeServer.hasRemovedUrl(url1)); | 2561 assertTrue(mFakeServer.hasRemovedUrl(url1)); |
| 2645 Assert.assertTrue(mFakeServer.hasRemovedUrl(url2)); | 2562 assertTrue(mFakeServer.hasRemovedUrl(url2)); |
| 2646 Assert.assertTrue(mFakeServer.hasRemovedUrl(url3)); | 2563 assertTrue(mFakeServer.hasRemovedUrl(url3)); |
| 2647 } | 2564 } |
| 2648 | 2565 |
| 2649 //==========================================================================
================== | 2566 //==========================================================================
================== |
| 2650 // Translate Tests | 2567 // Translate Tests |
| 2651 //==========================================================================
================== | 2568 //==========================================================================
================== |
| 2652 | 2569 |
| 2653 /** | 2570 /** |
| 2654 * Tests that a simple Tap with language determination triggers translation. | 2571 * Tests that a simple Tap with language determination triggers translation. |
| 2655 */ | 2572 */ |
| 2656 @Test | |
| 2657 @SmallTest | 2573 @SmallTest |
| 2658 @Feature({"ContextualSearch"}) | 2574 @Feature({"ContextualSearch"}) |
| 2659 public void testTapWithLanguage() throws InterruptedException, TimeoutExcept
ion { | 2575 public void testTapWithLanguage() throws InterruptedException, TimeoutExcept
ion { |
| 2660 // Tapping a German word should trigger translation. | 2576 // Tapping a German word should trigger translation. |
| 2661 simulateTapSearch("german"); | 2577 simulateTapSearch("german"); |
| 2662 | 2578 |
| 2663 // Make sure we tried to trigger translate. | 2579 // Make sure we tried to trigger translate. |
| 2664 Assert.assertTrue("Translation was not forced with the current request U
RL: " | 2580 assertTrue("Translation was not forced with the current request URL: " |
| 2665 + mManager.getRequest().getSearchUrl(), | 2581 + mManager.getRequest().getSearchUrl(), |
| 2666 mManager.getRequest().isTranslationForced()); | 2582 mManager.getRequest().isTranslationForced()); |
| 2667 } | 2583 } |
| 2668 | 2584 |
| 2669 /** | 2585 /** |
| 2670 * Tests translation with a simple Tap can be disabled. | 2586 * Tests translation with a simple Tap can be disabled. |
| 2671 */ | 2587 */ |
| 2672 @Test | |
| 2673 @SmallTest | 2588 @SmallTest |
| 2674 @Feature({"ContextualSearch"}) | 2589 @Feature({"ContextualSearch"}) |
| 2675 @CommandLineFlags.Add(ContextualSearchFieldTrial.DISABLE_TRANSLATION + "=tru
e") | 2590 @CommandLineFlags.Add(ContextualSearchFieldTrial.DISABLE_TRANSLATION + "=tru
e") |
| 2676 public void testTapDisabled() throws InterruptedException, TimeoutException
{ | 2591 public void testTapDisabled() throws InterruptedException, TimeoutException
{ |
| 2677 // Tapping a German word would normally trigger translation, but not wit
h the above flag. | 2592 // Tapping a German word would normally trigger translation, but not wit
h the above flag. |
| 2678 simulateTapSearch("german"); | 2593 simulateTapSearch("german"); |
| 2679 | 2594 |
| 2680 // Make sure we did not try to trigger translate. | 2595 // Make sure we did not try to trigger translate. |
| 2681 Assert.assertFalse(mManager.getRequest().isTranslationForced()); | 2596 assertFalse(mManager.getRequest().isTranslationForced()); |
| 2682 } | 2597 } |
| 2683 | 2598 |
| 2684 /** | 2599 /** |
| 2685 * Tests that a simple Tap without language determination does not trigger t
ranslation. | 2600 * Tests that a simple Tap without language determination does not trigger t
ranslation. |
| 2686 */ | 2601 */ |
| 2687 @Test | |
| 2688 @SmallTest | 2602 @SmallTest |
| 2689 @Feature({"ContextualSearch"}) | 2603 @Feature({"ContextualSearch"}) |
| 2690 public void testTapWithoutLanguage() throws InterruptedException, TimeoutExc
eption { | 2604 public void testTapWithoutLanguage() throws InterruptedException, TimeoutExc
eption { |
| 2691 // Tapping an English word should NOT trigger translation. | 2605 // Tapping an English word should NOT trigger translation. |
| 2692 simulateTapSearch("search"); | 2606 simulateTapSearch("search"); |
| 2693 | 2607 |
| 2694 // Make sure we did not try to trigger translate. | 2608 // Make sure we did not try to trigger translate. |
| 2695 Assert.assertFalse(mManager.getRequest().isTranslationForced()); | 2609 assertFalse(mManager.getRequest().isTranslationForced()); |
| 2696 } | 2610 } |
| 2697 | 2611 |
| 2698 /** | 2612 /** |
| 2699 * Tests that a long-press does trigger translation. | 2613 * Tests that a long-press does trigger translation. |
| 2700 */ | 2614 */ |
| 2701 @Test | |
| 2702 @SmallTest | 2615 @SmallTest |
| 2703 @Feature({"ContextualSearch"}) | 2616 @Feature({"ContextualSearch"}) |
| 2704 public void testLongpressTranslates() throws InterruptedException, TimeoutEx
ception { | 2617 public void testLongpressTranslates() throws InterruptedException, TimeoutEx
ception { |
| 2705 // LongPress on any word should trigger translation. | 2618 // LongPress on any word should trigger translation. |
| 2706 simulateLongPressSearch("search"); | 2619 simulateLongPressSearch("search"); |
| 2707 | 2620 |
| 2708 // Make sure we did try to trigger translate. | 2621 // Make sure we did try to trigger translate. |
| 2709 Assert.assertTrue(mManager.getRequest().isTranslationForced()); | 2622 assertTrue(mManager.getRequest().isTranslationForced()); |
| 2710 } | 2623 } |
| 2711 | 2624 |
| 2712 /** | 2625 /** |
| 2713 * Tests that a long-press does NOT trigger translation when disabled. | 2626 * Tests that a long-press does NOT trigger translation when disabled. |
| 2714 */ | 2627 */ |
| 2715 @Test | |
| 2716 @SmallTest | 2628 @SmallTest |
| 2717 @Feature({"ContextualSearch"}) | 2629 @Feature({"ContextualSearch"}) |
| 2718 @CommandLineFlags.Add(ContextualSearchFieldTrial.DISABLE_TRANSLATION + "=tru
e") | 2630 @CommandLineFlags.Add(ContextualSearchFieldTrial.DISABLE_TRANSLATION + "=tru
e") |
| 2719 public void testLongpressTranslateDisabledDoesNotTranslate() | 2631 public void testLongpressTranslateDisabledDoesNotTranslate() |
| 2720 throws InterruptedException, TimeoutException { | 2632 throws InterruptedException, TimeoutException { |
| 2721 // When disabled, LongPress on any word should not trigger translation. | 2633 // When disabled, LongPress on any word should not trigger translation. |
| 2722 simulateLongPressSearch("search"); | 2634 simulateLongPressSearch("search"); |
| 2723 | 2635 |
| 2724 // Make sure we did not try to trigger translate. | 2636 // Make sure we did not try to trigger translate. |
| 2725 Assert.assertFalse(mManager.getRequest().isTranslationForced()); | 2637 assertFalse(mManager.getRequest().isTranslationForced()); |
| 2726 } | 2638 } |
| 2727 | 2639 |
| 2728 /** | 2640 /** |
| 2729 * Tests that Contextual Search works in fullscreen. Specifically, tests tha
t tapping a word | 2641 * Tests that Contextual Search works in fullscreen. Specifically, tests tha
t tapping a word |
| 2730 * peeks the panel, expanding the bar results in the bar ending at the corre
ct spot in the page | 2642 * peeks the panel, expanding the bar results in the bar ending at the corre
ct spot in the page |
| 2731 * and tapping the base page closes the panel. | 2643 * and tapping the base page closes the panel. |
| 2732 */ | 2644 */ |
| 2733 @Test | |
| 2734 @SmallTest | 2645 @SmallTest |
| 2735 @Feature({"ContextualSearch"}) | 2646 @Feature({"ContextualSearch"}) |
| 2736 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 2647 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 2737 public void testTapContentAndExpandPanelInFullscreen() | 2648 public void testTapContentAndExpandPanelInFullscreen() |
| 2738 throws InterruptedException, TimeoutException { | 2649 throws InterruptedException, TimeoutException { |
| 2739 // Toggle tab to fulllscreen. | 2650 // Toggle tab to fulllscreen. |
| 2740 FullscreenTestUtils.togglePersistentFullscreenAndAssert( | 2651 FullscreenTestUtils.togglePersistentFullscreenAndAssert(getActivity().ge
tActivityTab(), |
| 2741 mActivityTestRule.getActivity().getActivityTab(), true, | 2652 true, getActivity()); |
| 2742 mActivityTestRule.getActivity()); | |
| 2743 | 2653 |
| 2744 // Simulate a tap and assert that the panel peeks. | 2654 // Simulate a tap and assert that the panel peeks. |
| 2745 simulateTapSearch("search"); | 2655 simulateTapSearch("search"); |
| 2746 | 2656 |
| 2747 // Expand the panel and assert that it ends up in the right place. | 2657 // Expand the panel and assert that it ends up in the right place. |
| 2748 tapPeekingBarToExpandAndAssert(); | 2658 tapPeekingBarToExpandAndAssert(); |
| 2749 Assert.assertEquals(mManager.getContextualSearchPanel().getHeight(), | 2659 assertEquals(mManager.getContextualSearchPanel().getHeight(), |
| 2750 mManager.getContextualSearchPanel().getPanelHeightFromState(Pane
lState.EXPANDED), | 2660 mManager.getContextualSearchPanel().getPanelHeightFromState(Pane
lState.EXPANDED)); |
| 2751 0); | |
| 2752 | 2661 |
| 2753 // Tap the base page and assert that the panel is closed. | 2662 // Tap the base page and assert that the panel is closed. |
| 2754 tapBasePageToClosePanel(); | 2663 tapBasePageToClosePanel(); |
| 2755 } | 2664 } |
| 2756 | 2665 |
| 2757 /** | 2666 /** |
| 2758 * Tests that the Contextual Search panel is dismissed when entering or exit
ing fullscreen. | 2667 * Tests that the Contextual Search panel is dismissed when entering or exit
ing fullscreen. |
| 2759 */ | 2668 */ |
| 2760 @Test | |
| 2761 @SmallTest | 2669 @SmallTest |
| 2762 @Feature({"ContextualSearch"}) | 2670 @Feature({"ContextualSearch"}) |
| 2763 public void testPanelDismissedOnToggleFullscreen() | 2671 public void testPanelDismissedOnToggleFullscreen() |
| 2764 throws InterruptedException, TimeoutException { | 2672 throws InterruptedException, TimeoutException { |
| 2765 // Simulate a tap and assert that the panel peeks. | 2673 // Simulate a tap and assert that the panel peeks. |
| 2766 simulateTapSearch("search"); | 2674 simulateTapSearch("search"); |
| 2767 | 2675 |
| 2768 // Toggle tab to fullscreen. | 2676 // Toggle tab to fullscreen. |
| 2769 Tab tab = mActivityTestRule.getActivity().getActivityTab(); | 2677 Tab tab = getActivity().getActivityTab(); |
| 2770 FullscreenTestUtils.togglePersistentFullscreenAndAssert( | 2678 FullscreenTestUtils.togglePersistentFullscreenAndAssert(tab, true, getAc
tivity()); |
| 2771 tab, true, mActivityTestRule.getActivity()); | |
| 2772 | 2679 |
| 2773 // Assert that the panel is closed. | 2680 // Assert that the panel is closed. |
| 2774 waitForPanelToClose(); | 2681 waitForPanelToClose(); |
| 2775 | 2682 |
| 2776 // Simulate a tap and assert that the panel peeks. | 2683 // Simulate a tap and assert that the panel peeks. |
| 2777 simulateTapSearch("search"); | 2684 simulateTapSearch("search"); |
| 2778 | 2685 |
| 2779 // Toggle tab to non-fullscreen. | 2686 // Toggle tab to non-fullscreen. |
| 2780 FullscreenTestUtils.togglePersistentFullscreenAndAssert( | 2687 FullscreenTestUtils.togglePersistentFullscreenAndAssert(tab, false, getA
ctivity()); |
| 2781 tab, false, mActivityTestRule.getActivity()); | |
| 2782 | 2688 |
| 2783 // Assert that the panel is closed. | 2689 // Assert that the panel is closed. |
| 2784 waitForPanelToClose(); | 2690 waitForPanelToClose(); |
| 2785 } | 2691 } |
| 2786 | 2692 |
| 2787 /** | 2693 /** |
| 2788 * Tests that ContextualSearchImageControl correctly sets either the icon sp
rite or thumbnail | 2694 * Tests that ContextualSearchImageControl correctly sets either the icon sp
rite or thumbnail |
| 2789 * as visible. | 2695 * as visible. |
| 2790 */ | 2696 */ |
| 2791 @Test | |
| 2792 @SmallTest | 2697 @SmallTest |
| 2793 @Feature({"ContextualSearch"}) | 2698 @Feature({"ContextualSearch"}) |
| 2794 public void testImageControl() throws InterruptedException, TimeoutException
{ | 2699 public void testImageControl() throws InterruptedException, TimeoutException
{ |
| 2795 simulateTapSearch("search"); | 2700 simulateTapSearch("search"); |
| 2796 | 2701 |
| 2797 final ContextualSearchImageControl imageControl = mPanel.getImageControl
(); | 2702 final ContextualSearchImageControl imageControl = mPanel.getImageControl
(); |
| 2798 | 2703 |
| 2799 Assert.assertFalse(imageControl.getThumbnailVisible()); | 2704 assertFalse(imageControl.getThumbnailVisible()); |
| 2800 Assert.assertTrue(TextUtils.isEmpty(imageControl.getThumbnailUrl())); | 2705 assertTrue(TextUtils.isEmpty(imageControl.getThumbnailUrl())); |
| 2801 | 2706 |
| 2802 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 2707 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 2803 @Override | 2708 @Override |
| 2804 public void run() { | 2709 public void run() { |
| 2805 imageControl.setThumbnailUrl("http://someimageurl.com/image.png"
); | 2710 imageControl.setThumbnailUrl("http://someimageurl.com/image.png"
); |
| 2806 imageControl.onThumbnailFetched(true); | 2711 imageControl.onThumbnailFetched(true); |
| 2807 } | 2712 } |
| 2808 }); | 2713 }); |
| 2809 | 2714 |
| 2810 Assert.assertTrue(imageControl.getThumbnailVisible()); | 2715 assertTrue(imageControl.getThumbnailVisible()); |
| 2811 Assert.assertEquals(imageControl.getThumbnailUrl(), "http://someimageurl
.com/image.png"); | 2716 assertEquals(imageControl.getThumbnailUrl(), "http://someimageurl.com/im
age.png"); |
| 2812 | 2717 |
| 2813 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 2718 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 2814 @Override | 2719 @Override |
| 2815 public void run() { | 2720 public void run() { |
| 2816 imageControl.hideCustomImage(false); | 2721 imageControl.hideCustomImage(false); |
| 2817 } | 2722 } |
| 2818 }); | 2723 }); |
| 2819 | 2724 |
| 2820 Assert.assertFalse(imageControl.getThumbnailVisible()); | 2725 assertFalse(imageControl.getThumbnailVisible()); |
| 2821 Assert.assertTrue(TextUtils.isEmpty(imageControl.getThumbnailUrl())); | 2726 assertTrue(TextUtils.isEmpty(imageControl.getThumbnailUrl())); |
| 2822 } | 2727 } |
| 2823 | 2728 |
| 2824 // TODO(twellington): Add an end-to-end integration test for fetching a thum
bnail based on a | 2729 // TODO(twellington): Add an end-to-end integration test for fetching a thum
bnail based on a |
| 2825 // a URL that is included with the resolution response. | 2730 // a URL that is included with the resolution response. |
| 2826 | 2731 |
| 2827 /** | 2732 /** |
| 2828 * Tests that Contextual Search is fully disabled when offline. | 2733 * Tests that Contextual Search is fully disabled when offline. |
| 2829 */ | 2734 */ |
| 2830 @Test | |
| 2831 @SmallTest | 2735 @SmallTest |
| 2832 @Feature({"ContextualSearch"}) | 2736 @Feature({"ContextualSearch"}) |
| 2833 // NOTE: Remove the flag so we will run just this test with onLine detection
enabled. | 2737 // NOTE: Remove the flag so we will run just this test with onLine detection
enabled. |
| 2834 @CommandLineFlags.Remove(ContextualSearchFieldTrial.ONLINE_DETECTION_DISABLE
D) | 2738 @CommandLineFlags.Remove(ContextualSearchFieldTrial.ONLINE_DETECTION_DISABLE
D) |
| 2835 public void testNetworkDisconnectedDeactivatesSearch() | 2739 public void testNetworkDisconnectedDeactivatesSearch() |
| 2836 throws InterruptedException, TimeoutException { | 2740 throws InterruptedException, TimeoutException { |
| 2837 setOnlineStatusAndReload(false); | 2741 setOnlineStatusAndReload(false); |
| 2838 longPressNodeWithoutWaiting("states"); | 2742 longPressNodeWithoutWaiting("states"); |
| 2839 waitForSelectActionBarVisible(); | 2743 waitForSelectActionBarVisible(); |
| 2840 // Verify the panel didn't open. It should open by now if CS has not be
en disabled. | 2744 // Verify the panel didn't open. It should open by now if CS has not be
en disabled. |
| 2841 // TODO(donnd): Consider waiting for some condition to be sure we'll cat
ch all failures, | 2745 // TODO(donnd): Consider waiting for some condition to be sure we'll cat
ch all failures, |
| 2842 // e.g. in case the Bar is about to show but has not yet appeared. Curr
ently catches ~90%. | 2746 // e.g. in case the Bar is about to show but has not yet appeared. Curr
ently catches ~90%. |
| 2843 assertPanelClosedOrUndefined(); | 2747 assertPanelClosedOrUndefined(); |
| 2844 | 2748 |
| 2845 // Similar sequence with network connected should peek for Longpress. | 2749 // Similar sequence with network connected should peek for Longpress. |
| 2846 setOnlineStatusAndReload(true); | 2750 setOnlineStatusAndReload(true); |
| 2847 longPressNodeWithoutWaiting("states"); | 2751 longPressNodeWithoutWaiting("states"); |
| 2848 waitForSelectActionBarVisible(); | 2752 waitForSelectActionBarVisible(); |
| 2849 waitForPanelToPeek(); | 2753 waitForPanelToPeek(); |
| 2850 } | 2754 } |
| 2851 | 2755 |
| 2852 /** | 2756 /** |
| 2853 * Tests that the quick action caption is set correctly when one is availabl
e. Also tests that | 2757 * Tests that the quick action caption is set correctly when one is availabl
e. Also tests that |
| 2854 * the caption gets changed when the panel is expanded and reset when the pa
nel is closed. | 2758 * the caption gets changed when the panel is expanded and reset when the pa
nel is closed. |
| 2855 */ | 2759 */ |
| 2856 @Test | |
| 2857 @SmallTest | 2760 @SmallTest |
| 2858 @Feature({"ContextualSearch"}) | 2761 @Feature({"ContextualSearch"}) |
| 2859 public void testQuickActionCaptionAndImage() throws InterruptedException, Ti
meoutException { | 2762 public void testQuickActionCaptionAndImage() throws InterruptedException, Ti
meoutException { |
| 2860 // Simulate a tap to show the Bar, then set the quick action data. | 2763 // Simulate a tap to show the Bar, then set the quick action data. |
| 2861 simulateTapSearch("search"); | 2764 simulateTapSearch("search"); |
| 2862 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 2765 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 2863 @Override | 2766 @Override |
| 2864 public void run() { | 2767 public void run() { |
| 2865 mPanel.onSearchTermResolved("search", null, "tel:555-555-5555", | 2768 mPanel.onSearchTermResolved("search", null, "tel:555-555-5555", |
| 2866 QuickActionCategory.PHONE); | 2769 QuickActionCategory.PHONE); |
| 2867 // Finish all running animations. | 2770 // Finish all running animations. |
| 2868 mPanel.onUpdateAnimation(System.currentTimeMillis(), true); | 2771 mPanel.onUpdateAnimation(System.currentTimeMillis(), true); |
| 2869 } | 2772 } |
| 2870 }); | 2773 }); |
| 2871 | 2774 |
| 2872 ContextualSearchBarControl barControl = mPanel.getSearchBarControl(); | 2775 ContextualSearchBarControl barControl = mPanel.getSearchBarControl(); |
| 2873 ContextualSearchQuickActionControl quickActionControl = barControl.getQu
ickActionControl(); | 2776 ContextualSearchQuickActionControl quickActionControl = barControl.getQu
ickActionControl(); |
| 2874 ContextualSearchImageControl imageControl = mPanel.getImageControl(); | 2777 ContextualSearchImageControl imageControl = mPanel.getImageControl(); |
| 2875 | 2778 |
| 2876 // Check that the peeking bar is showing the quick action data. | 2779 // Check that the peeking bar is showing the quick action data. |
| 2877 Assert.assertTrue(quickActionControl.hasQuickAction()); | 2780 assertTrue(quickActionControl.hasQuickAction()); |
| 2878 Assert.assertTrue(barControl.getCaptionVisible()); | 2781 assertTrue(barControl.getCaptionVisible()); |
| 2879 Assert.assertEquals(mActivityTestRule.getActivity().getResources().getSt
ring( | 2782 assertEquals(getActivity().getResources().getString( |
| 2880 R.string.contextual_search_quick_action_capt
ion_phone), | 2783 R.string.contextual_search_quick_action_caption_phone), |
| 2881 barControl.getCaptionText()); | 2784 barControl.getCaptionText()); |
| 2882 Assert.assertEquals(1.f, imageControl.getCustomImageVisibilityPercentage
(), 0); | 2785 assertEquals(1.f, imageControl.getCustomImageVisibilityPercentage()); |
| 2883 | 2786 |
| 2884 // Expand the bar. | 2787 // Expand the bar. |
| 2885 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 2788 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 2886 @Override | 2789 @Override |
| 2887 public void run() { | 2790 public void run() { |
| 2888 mPanel.simulateTapOnEndButton(); | 2791 mPanel.simulateTapOnEndButton(); |
| 2889 } | 2792 } |
| 2890 }); | 2793 }); |
| 2891 waitForPanelToExpand(); | 2794 waitForPanelToExpand(); |
| 2892 | 2795 |
| 2893 // Check that the expanded bar is showing the correct image and caption. | 2796 // Check that the expanded bar is showing the correct image and caption. |
| 2894 Assert.assertTrue(barControl.getCaptionVisible()); | 2797 assertTrue(barControl.getCaptionVisible()); |
| 2895 Assert.assertEquals(mActivityTestRule.getActivity().getResources().getSt
ring( | 2798 assertEquals(getActivity().getResources().getString( |
| 2896 ContextualSearchCaptionControl.EXPANED_CAPTI
ON_ID), | 2799 ContextualSearchCaptionControl.EXPANED_CAPTION_ID), |
| 2897 barControl.getCaptionText()); | 2800 barControl.getCaptionText()); |
| 2898 Assert.assertEquals(0.f, imageControl.getCustomImageVisibilityPercentage
(), 0); | 2801 assertEquals(0.f, imageControl.getCustomImageVisibilityPercentage()); |
| 2899 | 2802 |
| 2900 // Go back to peeking. | 2803 // Go back to peeking. |
| 2901 swipePanelDown(); | 2804 swipePanelDown(); |
| 2902 waitForPanelToPeek(); | 2805 waitForPanelToPeek(); |
| 2903 | 2806 |
| 2904 // Assert that the quick action data is showing. | 2807 // Assert that the quick action data is showing. |
| 2905 Assert.assertTrue(barControl.getCaptionVisible()); | 2808 assertTrue(barControl.getCaptionVisible()); |
| 2906 Assert.assertEquals(mActivityTestRule.getActivity().getResources().getSt
ring( | 2809 assertEquals(getActivity().getResources().getString( |
| 2907 R.string.contextual_search_quick_action_capt
ion_phone), | 2810 R.string.contextual_search_quick_action_caption_phone), |
| 2908 barControl.getCaptionText()); | 2811 barControl.getCaptionText()); |
| 2909 Assert.assertEquals(1.f, imageControl.getCustomImageVisibilityPercentage
(), 0); | 2812 assertEquals(1.f, imageControl.getCustomImageVisibilityPercentage()); |
| 2910 } | 2813 } |
| 2911 | 2814 |
| 2912 /** | 2815 /** |
| 2913 * Tests that an intent is sent when the bar is tapped and a quick action is
available. | 2816 * Tests that an intent is sent when the bar is tapped and a quick action is
available. |
| 2914 */ | 2817 */ |
| 2915 @Test | |
| 2916 @SmallTest | 2818 @SmallTest |
| 2917 @Feature({"ContextualSearch"}) | 2819 @Feature({"ContextualSearch"}) |
| 2918 public void testQuickActionIntent() throws InterruptedException, TimeoutExce
ption { | 2820 public void testQuickActionIntent() throws InterruptedException, TimeoutExce
ption { |
| 2919 // Add a new filter to the activity monitor that matches the intent that
should be fired. | 2821 // Add a new filter to the activity monitor that matches the intent that
should be fired. |
| 2920 IntentFilter quickActionFilter = new IntentFilter(Intent.ACTION_VIEW); | 2822 IntentFilter quickActionFilter = new IntentFilter(Intent.ACTION_VIEW); |
| 2921 quickActionFilter.addDataScheme("tel"); | 2823 quickActionFilter.addDataScheme("tel"); |
| 2922 mActivityMonitor = | 2824 mActivityMonitor = getInstrumentation().addMonitor( |
| 2923 InstrumentationRegistry.getInstrumentation().addMonitor(quickAct
ionFilter, | 2825 quickActionFilter, new Instrumentation.ActivityResult(Activity.R
ESULT_OK, null), |
| 2924 new Instrumentation.ActivityResult(Activity.RESULT_OK, n
ull), true); | 2826 true); |
| 2925 | 2827 |
| 2926 // Simulate a tap to show the Bar, then set the quick action data. | 2828 // Simulate a tap to show the Bar, then set the quick action data. |
| 2927 simulateTapSearch("search"); | 2829 simulateTapSearch("search"); |
| 2928 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 2830 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 2929 @Override | 2831 @Override |
| 2930 public void run() { | 2832 public void run() { |
| 2931 mPanel.onSearchTermResolved("search", null, "tel:555-555-5555", | 2833 mPanel.onSearchTermResolved("search", null, "tel:555-555-5555", |
| 2932 QuickActionCategory.PHONE); | 2834 QuickActionCategory.PHONE); |
| 2933 } | 2835 } |
| 2934 }); | 2836 }); |
| 2935 | 2837 |
| 2936 // Tap on the portion of the bar that should trigger the quick action in
tent to be fired. | 2838 // Tap on the portion of the bar that should trigger the quick action in
tent to be fired. |
| 2937 clickPanelBar(); | 2839 clickPanelBar(); |
| 2938 | 2840 |
| 2939 // Assert that an intent was fired. | 2841 // Assert that an intent was fired. |
| 2940 Assert.assertEquals(1, mActivityMonitor.getHits()); | 2842 assertEquals(1, mActivityMonitor.getHits()); |
| 2941 } | 2843 } |
| 2942 | 2844 |
| 2943 /** | 2845 /** |
| 2944 * Tests that the current tab is navigated to the quick action URI for | 2846 * Tests that the current tab is navigated to the quick action URI for |
| 2945 * QuickActionCategory#WEBSITE. | 2847 * QuickActionCategory#WEBSITE. |
| 2946 */ | 2848 */ |
| 2947 @Test | |
| 2948 @SmallTest | 2849 @SmallTest |
| 2949 @Feature({"ContextualSearch"}) | 2850 @Feature({"ContextualSearch"}) |
| 2950 public void testQuickActionUrl() throws InterruptedException, TimeoutExcepti
on { | 2851 public void testQuickActionUrl() throws InterruptedException, TimeoutExcepti
on { |
| 2951 final String testUrl = mTestServer.getURL("/chrome/test/data/android/goo
gle.html"); | 2852 final String testUrl = mTestServer.getURL("/chrome/test/data/android/goo
gle.html"); |
| 2952 | 2853 |
| 2953 // Simulate a tap to show the Bar, then set the quick action data. | 2854 // Simulate a tap to show the Bar, then set the quick action data. |
| 2954 simulateTapSearch("search"); | 2855 simulateTapSearch("search"); |
| 2955 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 2856 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 2956 @Override | 2857 @Override |
| 2957 public void run() { | 2858 public void run() { |
| 2958 mPanel.onSearchTermResolved("search", null, testUrl, QuickAction
Category.WEBSITE); | 2859 mPanel.onSearchTermResolved("search", null, testUrl, QuickAction
Category.WEBSITE); |
| 2959 } | 2860 } |
| 2960 }); | 2861 }); |
| 2961 | 2862 |
| 2962 // Tap on the portion of the bar that should trigger the quick action. | 2863 // Tap on the portion of the bar that should trigger the quick action. |
| 2963 clickPanelBar(); | 2864 clickPanelBar(); |
| 2964 | 2865 |
| 2965 // Assert that the URL was loaded. | 2866 // Assert that the URL was loaded. |
| 2966 ChromeTabUtils.waitForTabPageLoaded( | 2867 ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), test
Url); |
| 2967 mActivityTestRule.getActivity().getActivityTab(), testUrl); | |
| 2968 } | 2868 } |
| 2969 | 2869 |
| 2970 /** | 2870 /** |
| 2971 * Tests accessibility mode: Tap and Long-press don't activate CS. | 2871 * Tests accessibility mode: Tap and Long-press don't activate CS. |
| 2972 */ | 2872 */ |
| 2973 @Test | |
| 2974 @SmallTest | 2873 @SmallTest |
| 2975 @Feature({"ContextualSearch"}) | 2874 @Feature({"ContextualSearch"}) |
| 2976 public void testAccesibilityMode() throws InterruptedException, TimeoutExcep
tion { | 2875 public void testAccesibilityMode() throws InterruptedException, TimeoutExcep
tion { |
| 2977 mManager.onAccessibilityModeChanged(true); | 2876 mManager.onAccessibilityModeChanged(true); |
| 2978 | 2877 |
| 2979 // Simulate a tap that resolves to show the Bar. | 2878 // Simulate a tap that resolves to show the Bar. |
| 2980 clickNode("intelligence"); | 2879 clickNode("intelligence"); |
| 2981 assertNoContentViewCore(); | 2880 assertNoContentViewCore(); |
| 2982 assertNoSearchesLoaded(); | 2881 assertNoSearchesLoaded(); |
| 2983 | 2882 |
| 2984 // Simulate a Long-press. | 2883 // Simulate a Long-press. |
| 2985 longPressNodeWithoutWaiting("states"); | 2884 longPressNodeWithoutWaiting("states"); |
| 2986 assertNoContentViewCore(); | 2885 assertNoContentViewCore(); |
| 2987 assertNoSearchesLoaded(); | 2886 assertNoSearchesLoaded(); |
| 2988 } | 2887 } |
| 2989 | 2888 |
| 2990 /** | 2889 /** |
| 2991 * Tests that the Manager cycles through all the expected Internal States on
Tap that Resolves. | 2890 * Tests that the Manager cycles through all the expected Internal States on
Tap that Resolves. |
| 2992 */ | 2891 */ |
| 2993 @Test | |
| 2994 @SmallTest | 2892 @SmallTest |
| 2995 @Feature({"ContextualSearch"}) | 2893 @Feature({"ContextualSearch"}) |
| 2996 public void testAllInternalStatesVisitedResolvingTap() | 2894 public void testAllInternalStatesVisitedResolvingTap() |
| 2997 throws InterruptedException, TimeoutException { | 2895 throws InterruptedException, TimeoutException { |
| 2998 // Set up a tracking version of the Internal State Controller. | 2896 // Set up a tracking version of the Internal State Controller. |
| 2999 ContextualSearchInternalStateControllerWrapper internalStateControllerWr
apper = | 2897 ContextualSearchInternalStateControllerWrapper internalStateControllerWr
apper = |
| 3000 ContextualSearchInternalStateControllerWrapper | 2898 ContextualSearchInternalStateControllerWrapper |
| 3001 .makeNewInternalStateControllerWrapper(mManager); | 2899 .makeNewInternalStateControllerWrapper(mManager); |
| 3002 mManager.setContextualSearchInternalStateController(internalStateControl
lerWrapper); | 2900 mManager.setContextualSearchInternalStateController(internalStateControl
lerWrapper); |
| 3003 | 2901 |
| 3004 // Simulate a tap that resolves to show the Bar. | 2902 // Simulate a tap that resolves to show the Bar. |
| 3005 simulateTapSearch("search"); | 2903 simulateTapSearch("search"); |
| 3006 Assert.assertEquals( | 2904 assertEquals(InternalState.SHOWING_TAP_SEARCH, internalStateControllerWr
apper.getState()); |
| 3007 InternalState.SHOWING_TAP_SEARCH, internalStateControllerWrapper
.getState()); | |
| 3008 | 2905 |
| 3009 Assert.assertEquals(internalStateControllerWrapper.getStartedStates(), | 2906 assertEquals(internalStateControllerWrapper.getStartedStates(), |
| 3010 internalStateControllerWrapper.getFinishedStates()); | 2907 internalStateControllerWrapper.getFinishedStates()); |
| 3011 Assert.assertEquals( | 2908 assertEquals(ContextualSearchInternalStateControllerWrapper.EXPECTED_TAP
_RESOLVE_SEQUENCE, |
| 3012 ContextualSearchInternalStateControllerWrapper.EXPECTED_TAP_RESO
LVE_SEQUENCE, | |
| 3013 internalStateControllerWrapper.getFinishedStates()); | 2909 internalStateControllerWrapper.getFinishedStates()); |
| 3014 } | 2910 } |
| 3015 | 2911 |
| 3016 /** | 2912 /** |
| 3017 * Tests that the Manager cycles through all the expected Internal States on
a Long-press. | 2913 * Tests that the Manager cycles through all the expected Internal States on
a Long-press. |
| 3018 */ | 2914 */ |
| 3019 @Test | |
| 3020 @SmallTest | 2915 @SmallTest |
| 3021 @Feature({"ContextualSearch"}) | 2916 @Feature({"ContextualSearch"}) |
| 3022 public void testAllInternalStatesVisitedLongpress() | 2917 public void testAllInternalStatesVisitedLongpress() |
| 3023 throws InterruptedException, TimeoutException { | 2918 throws InterruptedException, TimeoutException { |
| 3024 // Set up a tracking version of the Internal State Controller. | 2919 // Set up a tracking version of the Internal State Controller. |
| 3025 ContextualSearchInternalStateControllerWrapper internalStateControllerWr
apper = | 2920 ContextualSearchInternalStateControllerWrapper internalStateControllerWr
apper = |
| 3026 ContextualSearchInternalStateControllerWrapper | 2921 ContextualSearchInternalStateControllerWrapper |
| 3027 .makeNewInternalStateControllerWrapper(mManager); | 2922 .makeNewInternalStateControllerWrapper(mManager); |
| 3028 mManager.setContextualSearchInternalStateController(internalStateControl
lerWrapper); | 2923 mManager.setContextualSearchInternalStateController(internalStateControl
lerWrapper); |
| 3029 | 2924 |
| 3030 // Simulate a Long-press to show the Bar. | 2925 // Simulate a Long-press to show the Bar. |
| 3031 simulateLongPressSearch("search"); | 2926 simulateLongPressSearch("search"); |
| 3032 | 2927 |
| 3033 Assert.assertEquals(internalStateControllerWrapper.getStartedStates(), | 2928 assertEquals(internalStateControllerWrapper.getStartedStates(), |
| 3034 internalStateControllerWrapper.getFinishedStates()); | 2929 internalStateControllerWrapper.getFinishedStates()); |
| 3035 Assert.assertEquals( | 2930 assertEquals(ContextualSearchInternalStateControllerWrapper.EXPECTED_LON
GPRESS_SEQUENCE, |
| 3036 ContextualSearchInternalStateControllerWrapper.EXPECTED_LONGPRES
S_SEQUENCE, | |
| 3037 internalStateControllerWrapper.getFinishedStates()); | 2931 internalStateControllerWrapper.getFinishedStates()); |
| 3038 } | 2932 } |
| 3039 } | 2933 } |
| OLD | NEW |