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

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

Issue 2739603003: Add TestRules for content shell test and refactor test bases (Closed)
Patch Set: limit API access 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/ContentDetectionTestCommon.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/ContentDetectionTestCommon.java
similarity index 52%
copy from content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java
copy to content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestCommon.java
index 0c2fac85d8fca07a58ddd3b3d5142304d395dd3b..0d8d96b42b76a5d2f93cd00a1a6b82135e6f3dd3 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestCommon.java
@@ -1,4 +1,4 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,6 @@ 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;
@@ -15,20 +14,24 @@ 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.ContentShellTestBase;
+import org.chromium.content_shell_apk.ContentShellActivity;
+import org.chromium.content_shell_apk.ContentShellTestCommon.TestCommonCallback;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
-/**
- * Base class for content detection test suites.
- */
-public class ContentDetectionTestBase extends ContentShellTestBase {
-
+public class ContentDetectionTestCommon {
private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(10);
+ private final TestCommonCallback<ContentShellActivity> mCallback;
+
private TestCallbackHelperContainer mCallbackHelper;
private TestContentIntentHandler mContentIntentHandler;
+ public ContentDetectionTestCommon(TestCommonCallback<ContentShellActivity> callback) {
+ mCallback = callback;
+ }
+
/**
* CallbackHelper for OnStartContentIntent.
*/
@@ -47,7 +50,7 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
/**
* ContentIntentHandler impl to test content detection.
*/
- private static class TestContentIntentHandler implements ContentIntentHandler {
+ public static class TestContentIntentHandler implements ContentIntentHandler {
private OnStartContentIntentHelper mOnStartContentIntentHelper;
public OnStartContentIntentHelper getOnStartContentIntentHelper() {
@@ -63,86 +66,58 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
}
}
- /**
- * Returns the TestCallbackHelperContainer associated with this ContentView,
- * or creates it lazily.
- */
- protected TestCallbackHelperContainer getTestCallbackHelperContainer() {
+ static String urlForContent(String content) {
+ return Uri.encode(content).replaceAll("%20", "+");
+ }
+
+ TestCallbackHelperContainer getTestCallbackHelperContainer() {
if (mCallbackHelper == null) {
- mCallbackHelper = new TestCallbackHelperContainer(getContentViewCore());
+ mCallbackHelper =
+ new TestCallbackHelperContainer(mCallback.getContentViewCoreForTestCommon());
}
return mCallbackHelper;
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ void createTestContentIntentHandler() {
mContentIntentHandler = new TestContentIntentHandler();
}
- @Override
- protected void setActivity(Activity activity) {
- super.setActivity(activity);
- getActivity()
+ void setContentHandler() {
+ mCallback.getActivityForTestCommon()
.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", "+");
- }
-
- /**
- * Checks if the provided test url is the current url in the content view.
- * @param testUrl Test url to check.
- * @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());
+ boolean isCurrentTestUrl(String testUrl) {
+ return UrlUtils.getIsolatedTestFileUrl(testUrl).equals(
+ mCallback.getContentViewCoreForTestCommon().getWebContents().getUrl());
}
- /**
- * Scrolls to the node with the provided id, taps on it and waits for an intent to come.
- * @param id Id of the node to scroll and tap.
- * @return The content url of the received intent or null if none.
- */
- protected String scrollAndTapExpectingIntent(String id) throws Throwable {
+ String scrollAndTapExpectingIntent(String id) throws InterruptedException, TimeoutException {
OnStartContentIntentHelper onStartContentIntentHelper =
mContentIntentHandler.getOnStartContentIntentHelper();
int currentCallCount = onStartContentIntentHelper.getCallCount();
- DOMUtils.clickNode(getContentViewCore(), id);
+ DOMUtils.clickNode(mCallback.getContentViewCoreForTestCommon(), id);
- onStartContentIntentHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
- TimeUnit.SECONDS);
- getInstrumentation().waitForIdleSync();
+ onStartContentIntentHelper.waitForCallback(
+ currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ mCallback.getInstrumentationForTestCommon().waitForIdleSync();
return onStartContentIntentHelper.getIntentUrl();
}
- /**
- * 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 {
+ void scrollAndTapNavigatingOut(String id) throws InterruptedException, TimeoutException {
TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHelperContainer();
OnPageFinishedHelper onPageFinishedHelper =
callbackHelperContainer.getOnPageFinishedHelper();
int currentCallCount = onPageFinishedHelper.getCallCount();
- DOMUtils.clickNode(getContentViewCore(), id);
+ DOMUtils.clickNode(mCallback.getContentViewCoreForTestCommon(), id);
- onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
- TimeUnit.SECONDS);
- getInstrumentation().waitForIdleSync();
+ onPageFinishedHelper.waitForCallback(
+ currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ mCallback.getInstrumentationForTestCommon().waitForIdleSync();
}
-}
+}

Powered by Google App Engine
This is Rietveld 408576698