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