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

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionActivityTestRule.java

Issue 2632043002: Create ContentShellActivityTestRule and BaseJUnitRunner (Closed)
Patch Set: Add TODO for launchContentShellWithUrlSync Created 3 years, 10 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.content.browser;
6
7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
8
9 import android.net.Uri;
10 import android.support.test.InstrumentationRegistry;
11
12 import org.chromium.base.test.util.UrlUtils;
13 import org.chromium.content.browser.test.util.DOMUtils;
14 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
15 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage FinishedHelper;
16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnStar tContentIntentHelper;
17 import org.chromium.content_shell_apk.ContentShellActivityTestRule;
18
19 import java.util.concurrent.TimeUnit;
20
21 /**
22 * ActivityTestRule for content detection test suites.
23 */
24 public class ContentDetectionActivityTestRule extends ContentShellActivityTestRu le {
25 private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(10);
26
27 private TestCallbackHelperContainer mCallbackHelper;
28
29 /**
30 * Returns the TestCallbackHelperContainer associated with this ContentView,
31 * or creates it lazily.
32 */
33 public TestCallbackHelperContainer getTestCallbackHelperContainer() {
34 if (mCallbackHelper == null) {
35 mCallbackHelper = new TestCallbackHelperContainer(getContentViewCore ());
36 }
37 return mCallbackHelper;
38 }
39
40 /**
41 * Encodes the provided content string into an escaped url as intents do.
42 * @param content Content to escape into a url.
43 * @return Escaped url.
44 */
45 public String urlForContent(String content) {
46 return Uri.encode(content).replaceAll("%20", "+");
47 }
48
49 /**
50 * Checks if the provided test url is the current url in the content view.
51 * @param testUrl Test url to check.
52 * @return true if the test url is the current one, false otherwise.
53 */
54 public boolean isCurrentTestUrl(String testUrl) {
55 return UrlUtils.getIsolatedTestFileUrl(testUrl).equals(
56 getContentViewCore().getWebContents().getUrl());
57 }
58
59 /**
60 * Scrolls to the node with the provided id, taps on it and waits for an int ent to come.
61 * @param id Id of the node to scroll and tap.
62 * @return The content url of the received intent or null if none.
63 */
64 public String scrollAndTapExpectingIntent(String id) throws Throwable {
65 TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHel perContainer();
66 OnStartContentIntentHelper onStartContentIntentHelper =
67 callbackHelperContainer.getOnStartContentIntentHelper();
68 int currentCallCount = onStartContentIntentHelper.getCallCount();
69
70 DOMUtils.clickNode(getContentViewCore(), id);
71
72 onStartContentIntentHelper.waitForCallback(
73 currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
74 InstrumentationRegistry.getInstrumentation().waitForIdleSync();
75 return onStartContentIntentHelper.getIntentUrl();
76 }
77
78 /**
79 * Scrolls to the node with the provided id, taps on it and waits for a new page load to finish.
80 * Useful when tapping on links that take to other pages.
81 * @param id Id of the node to scroll and tap.
82 * @return The content url of the received intent or null if none.
83 */
84 public void scrollAndTapNavigatingOut(String id) throws Throwable {
85 TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHel perContainer();
86 OnPageFinishedHelper onPageFinishedHelper =
87 callbackHelperContainer.getOnPageFinishedHelper();
88 int currentCallCount = onPageFinishedHelper.getCallCount();
89
90 DOMUtils.clickNode(getContentViewCore(), id);
91
92 onPageFinishedHelper.waitForCallback(
93 currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
94 InstrumentationRegistry.getInstrumentation().waitForIdleSync();
95 }
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698