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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java

Issue 2739603003: Add TestRules for content shell test and refactor test bases (Closed)
Patch Set: Address +boliu's comments Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java
index 0c2fac85d8fca07a58ddd3b3d5142304d395dd3b..bc234eff2080ba336cea9db5d5301dd3c51a945a 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java
@@ -4,99 +4,39 @@
package org.chromium.content.browser;
-import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
-
import android.app.Activity;
-import android.net.Uri;
-import org.chromium.base.test.util.CallbackHelper;
-import org.chromium.base.test.util.UrlUtils;
-import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
-import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
-import org.chromium.content_shell.ShellViewAndroidDelegate.ContentIntentHandler;
+import org.chromium.content_shell_apk.ContentShellActivity;
import org.chromium.content_shell_apk.ContentShellTestBase;
-
-import java.util.concurrent.TimeUnit;
+import org.chromium.content_shell_apk.ContentShellTestCommon.TestCommonCallback;
/**
* Base class for content detection test suites.
*/
-public class ContentDetectionTestBase extends ContentShellTestBase {
-
- private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(10);
-
- private TestCallbackHelperContainer mCallbackHelper;
- private TestContentIntentHandler mContentIntentHandler;
-
- /**
- * CallbackHelper for OnStartContentIntent.
- */
- private static class OnStartContentIntentHelper extends CallbackHelper {
- private String mIntentUrl;
- public void notifyCalled(String intentUrl) {
- mIntentUrl = intentUrl;
- notifyCalled();
- }
- public String getIntentUrl() {
- assert getCallCount() > 0;
- return mIntentUrl;
- }
- }
-
- /**
- * ContentIntentHandler impl to test content detection.
- */
- private static class TestContentIntentHandler implements ContentIntentHandler {
- private OnStartContentIntentHelper mOnStartContentIntentHelper;
-
- public OnStartContentIntentHelper getOnStartContentIntentHelper() {
- if (mOnStartContentIntentHelper == null) {
- mOnStartContentIntentHelper = new OnStartContentIntentHelper();
- }
- return mOnStartContentIntentHelper;
- }
-
- @Override
- public void onIntentUrlReceived(String intentUrl) {
- mOnStartContentIntentHelper.notifyCalled(intentUrl);
- }
- }
+public class ContentDetectionTestBase
+ extends ContentShellTestBase implements TestCommonCallback<ContentShellActivity> {
+ private final ContentDetectionTestCommon mTestCommon = new ContentDetectionTestCommon(this);
/**
* Returns the TestCallbackHelperContainer associated with this ContentView,
* or creates it lazily.
*/
protected TestCallbackHelperContainer getTestCallbackHelperContainer() {
- if (mCallbackHelper == null) {
- mCallbackHelper = new TestCallbackHelperContainer(getContentViewCore());
- }
- return mCallbackHelper;
+ return mTestCommon.getTestCallbackHelperContainer();
}
@Override
protected void setUp() throws Exception {
super.setUp();
- mContentIntentHandler = new TestContentIntentHandler();
+ mTestCommon.createTestContentIntentHandler();
}
+ @SuppressWarnings("deprecation")
@Override
protected void setActivity(Activity activity) {
super.setActivity(activity);
- getActivity()
- .getShellManager()
- .getActiveShell()
- .getViewAndroidDelegate()
- .setContentIntentHandler(mContentIntentHandler);
- }
-
- /**
- * Encodes the provided content string into an escaped url as intents do.
- * @param content Content to escape into a url.
- * @return Escaped url.
- */
- protected static String urlForContent(String content) {
- return Uri.encode(content).replaceAll("%20", "+");
+ mTestCommon.setContentHandler();
}
/**
@@ -105,8 +45,16 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
* @return true if the test url is the current one, false otherwise.
*/
protected boolean isCurrentTestUrl(String testUrl) {
- return UrlUtils.getIsolatedTestFileUrl(testUrl).equals(getContentViewCore()
- .getWebContents().getUrl());
+ return mTestCommon.isCurrentTestUrl(testUrl);
+ }
+
+ /**
+ * Encodes the provided content string into an escaped url as intents do.
+ * @param content Content to escape into a url.
+ * @return Escaped url.
+ */
+ public static String urlForContent(String content) {
+ return ContentDetectionTestCommon.urlForContent(content);
}
/**
@@ -115,34 +63,15 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
* @return The content url of the received intent or null if none.
*/
protected String scrollAndTapExpectingIntent(String id) throws Throwable {
- OnStartContentIntentHelper onStartContentIntentHelper =
- mContentIntentHandler.getOnStartContentIntentHelper();
- int currentCallCount = onStartContentIntentHelper.getCallCount();
-
- DOMUtils.clickNode(getContentViewCore(), id);
-
- onStartContentIntentHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
- TimeUnit.SECONDS);
- getInstrumentation().waitForIdleSync();
- return onStartContentIntentHelper.getIntentUrl();
+ return mTestCommon.scrollAndTapExpectingIntent(id);
}
/**
* Scrolls to the node with the provided id, taps on it and waits for a new page load to finish.
* Useful when tapping on links that take to other pages.
* @param id Id of the node to scroll and tap.
- * @return The content url of the received intent or null if none.
*/
protected void scrollAndTapNavigatingOut(String id) throws Throwable {
- TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHelperContainer();
- OnPageFinishedHelper onPageFinishedHelper =
- callbackHelperContainer.getOnPageFinishedHelper();
- int currentCallCount = onPageFinishedHelper.getCallCount();
-
- DOMUtils.clickNode(getContentViewCore(), id);
-
- onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
- TimeUnit.SECONDS);
- getInstrumentation().waitForIdleSync();
+ mTestCommon.scrollAndTapNavigatingOut(id);
}
}

Powered by Google App Engine
This is Rietveld 408576698