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