Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTapEventTest.java

Issue 2858933002: Reland: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: Patch takes out flaky tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.hamcrest.CoreMatchers.equalTo;
8 import static org.hamcrest.CoreMatchers.is;
9 import static org.junit.Assert.assertThat;
10
11 import android.content.Context; 7 import android.content.Context;
12 import android.net.Uri; 8 import android.net.Uri;
13 import android.support.test.filters.SmallTest; 9 import android.support.test.filters.SmallTest;
14 import android.widget.LinearLayout; 10 import android.widget.LinearLayout;
15 11
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17
16 import org.chromium.base.ThreadUtils; 18 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.test.util.CommandLineFlags;
17 import org.chromium.base.test.util.Feature; 20 import org.chromium.base.test.util.Feature;
18 import org.chromium.base.test.util.Restriction; 21 import org.chromium.base.test.util.Restriction;
19 import org.chromium.chrome.browser.ChromeActivity; 22 import org.chromium.chrome.browser.ChromeActivity;
23 import org.chromium.chrome.browser.ChromeSwitches;
20 import org.chromium.chrome.browser.WebContentsFactory; 24 import org.chromium.chrome.browser.WebContentsFactory;
21 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager; 25 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager;
22 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManagerWrapp er; 26 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManagerWrapp er;
23 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context ualSearchPanel; 27 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context ualSearchPanel;
24 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost; 28 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
25 import org.chromium.chrome.browser.contextualsearch.ContextualSearchInternalStat eController.InternalState; 29 import org.chromium.chrome.browser.contextualsearch.ContextualSearchInternalStat eController.InternalState;
26 import org.chromium.chrome.browser.contextualsearch.ContextualSearchSelectionCon troller.SelectionType; 30 import org.chromium.chrome.browser.contextualsearch.ContextualSearchSelectionCon troller.SelectionType;
27 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 31 import org.chromium.chrome.test.ChromeActivityTestRule;
32 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
28 import org.chromium.content.browser.ContentViewCore; 33 import org.chromium.content.browser.ContentViewCore;
29 import org.chromium.content.browser.SelectionClient; 34 import org.chromium.content.browser.SelectionClient;
30 import org.chromium.content.browser.SelectionPopupController; 35 import org.chromium.content.browser.SelectionPopupController;
31 import org.chromium.content_public.browser.WebContents; 36 import org.chromium.content_public.browser.WebContents;
32 import org.chromium.ui.resources.dynamics.DynamicResourceLoader; 37 import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
33 import org.chromium.ui.touch_selection.SelectionEventType; 38 import org.chromium.ui.touch_selection.SelectionEventType;
34 39
35 import javax.annotation.Nullable; 40 import javax.annotation.Nullable;
36 41
37 /** 42 /**
38 * Mock touch events with Contextual Search to test behavior of its panel and ma nager. 43 * Mock touch events with Contextual Search to test behavior of its panel and ma nager.
39 */ 44 */
40 public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr omeActivity> { 45 @RunWith(ChromeJUnit4ClassRunner.class)
46 @CommandLineFlags.Add({
47 ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
48 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
49 })
50 public class ContextualSearchTapEventTest {
51 @Rule
52 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
53 new ChromeActivityTestRule<>(ChromeActivity.class);
41 54
42 private ContextualSearchManagerWrapper mContextualSearchManager; 55 private ContextualSearchManagerWrapper mContextualSearchManager;
43 private ContextualSearchPanel mPanel; 56 private ContextualSearchPanel mPanel;
44 private OverlayPanelManagerWrapper mPanelManager; 57 private OverlayPanelManagerWrapper mPanelManager;
45 private SelectionClient mContextualSearchClient; 58 private SelectionClient mContextualSearchClient;
46 59
47 /** 60 /**
48 * A ContextualSearchRequest that foregoes URI template lookup. 61 * A ContextualSearchRequest that foregoes URI template lookup.
49 */ 62 */
50 private static class MockContextualSearchRequest extends ContextualSearchReq uest { 63 private static class MockContextualSearchRequest extends ContextualSearchReq uest {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 255 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
243 @Override 256 @Override
244 public void run() { 257 public void run() {
245 mContextualSearchManager.handleSelection(text, true, SelectionTy pe.TAP, 0, 0); 258 mContextualSearchManager.handleSelection(text, true, SelectionTy pe.TAP, 0, 0);
246 } 259 }
247 }); 260 });
248 } 261 }
249 262
250 // ------------------------------------------------------------------------- ------------------- 263 // ------------------------------------------------------------------------- -------------------
251 264
252 public ContextualSearchTapEventTest() { 265 @Before
253 super(ChromeActivity.class); 266 public void setUp() throws Exception {
254 } 267 mActivityTestRule.startMainActivityOnBlankPage();
255 268 final ChromeActivity activity = mActivityTestRule.getActivity();
256 @Override
257 protected void setUp() throws Exception {
258 super.setUp();
259
260 final ChromeActivity activity = getActivity();
261 269
262 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 270 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
263 @Override 271 @Override
264 public void run() { 272 public void run() {
265 mPanelManager = new OverlayPanelManagerWrapper(); 273 mPanelManager = new OverlayPanelManagerWrapper();
266 mPanelManager.setContainerView(new LinearLayout(activity)); 274 mPanelManager.setContainerView(new LinearLayout(activity));
267 mPanelManager.setDynamicResourceLoader(new DynamicResourceLoader (0, null)); 275 mPanelManager.setDynamicResourceLoader(new DynamicResourceLoader (0, null));
268 276
269 mContextualSearchManager = new ContextualSearchManagerWrapper(ac tivity); 277 mContextualSearchManager = new ContextualSearchManagerWrapper(ac tivity);
270 mPanel = new ContextualSearchPanelWrapper(activity, null, mPanel Manager); 278 mPanel = new ContextualSearchPanelWrapper(activity, null, mPanel Manager);
271 mPanel.setManagementDelegate(mContextualSearchManager); 279 mPanel.setManagementDelegate(mContextualSearchManager);
272 mContextualSearchManager.setContextualSearchPanel(mPanel); 280 mContextualSearchManager.setContextualSearchPanel(mPanel);
273 281
274 mContextualSearchClient = mContextualSearchManager; 282 mContextualSearchClient = mContextualSearchManager;
275 } 283 }
276 }); 284 });
277 } 285 }
278 286
279 @Override
280 public void startMainActivity() throws InterruptedException {
281 startMainActivityWithURL("about:blank");
282 }
283
284 /** 287 /**
285 * Tests that a Tap gesture followed by tapping empty space closes the panel . 288 * Tests that a Tap gesture followed by tapping empty space closes the panel .
286 */ 289 */
290 @Test
287 @SmallTest 291 @SmallTest
288 @Feature({"ContextualSearch"}) 292 @Feature({"ContextualSearch"})
289 @Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE) 293 @Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE)
290 public void testLongpressFollowedByNonTextTap() { 294 public void testLongpressFollowedByNonTextTap() {
291 assertTrue(mPanelManager.getRequestPanelShowCount() == 0); 295 Assert.assertEquals(mPanelManager.getRequestPanelShowCount(), 0);
292 296
293 // Fake a selection event. 297 // Fake a selection event.
294 mockLongpressText("text"); 298 mockLongpressText("text");
295 299
296 assertThat(mPanelManager.getRequestPanelShowCount(), is(1)); 300 Assert.assertEquals(mPanelManager.getRequestPanelShowCount(), 1);
297 assertThat(mPanelManager.getPanelHideCount(), is(0)); 301 Assert.assertEquals(mPanelManager.getPanelHideCount(), 0);
298 assertThat(mContextualSearchManager.getSelectionController().getSelected Text(), 302 Assert.assertEquals(mContextualSearchManager.getSelectionController().ge tSelectedText(),
299 equalTo("text")); 303 "text");
300 304
301 // Fake tap on non-text. 305 // Fake tap on non-text.
302 mockTapEmptySpace(); 306 mockTapEmptySpace();
303 307
304 assertThat(mPanelManager.getRequestPanelShowCount(), is(1)); 308 Assert.assertEquals(mPanelManager.getRequestPanelShowCount(), 1);
305 assertThat(mPanelManager.getPanelHideCount(), is(1)); 309 Assert.assertEquals(mPanelManager.getPanelHideCount(), 1);
306 assertNull(mContextualSearchManager.getSelectionController().getSelected Text()); 310 Assert.assertNull(mContextualSearchManager.getSelectionController().getS electedText());
307 } 311 }
308 312
309 /** 313 /**
310 * Tests that a Tap gesture followed by tapping empty space closes the panel . 314 * Tests that a Tap gesture followed by tapping empty space closes the panel .
311 */ 315 */
316 @Test
312 @SmallTest 317 @SmallTest
313 @Feature({"ContextualSearch"}) 318 @Feature({"ContextualSearch"})
314 @Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE) 319 @Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE)
315 public void testTextTapFollowedByNonTextTap() { 320 public void testTextTapFollowedByNonTextTap() {
316 assertTrue(mPanelManager.getRequestPanelShowCount() == 0); 321 Assert.assertEquals(mPanelManager.getRequestPanelShowCount(), 0);
317 322
318 // Fake a Tap event. 323 // Fake a Tap event.
319 mockTapText("text"); 324 mockTapText("text");
320 // Right now the tap-processing sequence will stall at selectWordAroundC aret, so we need 325 // Right now the tap-processing sequence will stall at selectWordAroundC aret, so we need
321 // to prod it forward with a manual hack: 326 // to prod it forward with a manual hack:
322 mockSelectWordAroundCaretAck("text"); 327 mockSelectWordAroundCaretAck("text");
323 assertThat(mPanelManager.getRequestPanelShowCount(), is(1)); 328 Assert.assertEquals(mPanelManager.getRequestPanelShowCount(), 1);
324 assertThat(mPanelManager.getPanelHideCount(), is(0)); 329 Assert.assertEquals(mPanelManager.getPanelHideCount(), 0);
325 } 330 }
326 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698