| 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 4a6fa24506f4db8dc0fbd25d0259fc885f14b168..0c2fac85d8fca07a58ddd3b3d5142304d395dd3b 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
|
| @@ -6,13 +6,15 @@ 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.browser.test.util.TestCallbackHelperContainer.OnStartContentIntentHelper;
|
| +import org.chromium.content_shell.ShellViewAndroidDelegate.ContentIntentHandler;
|
| import org.chromium.content_shell_apk.ContentShellTestBase;
|
|
|
| import java.util.concurrent.TimeUnit;
|
| @@ -25,6 +27,41 @@ 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);
|
| + }
|
| + }
|
|
|
| /**
|
| * Returns the TestCallbackHelperContainer associated with this ContentView,
|
| @@ -37,12 +74,28 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
|
| return mCallbackHelper;
|
| }
|
|
|
| + @Override
|
| + protected void setUp() throws Exception {
|
| + super.setUp();
|
| + mContentIntentHandler = new TestContentIntentHandler();
|
| + }
|
| +
|
| + @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 String urlForContent(String content) {
|
| + protected static String urlForContent(String content) {
|
| return Uri.encode(content).replaceAll("%20", "+");
|
| }
|
|
|
| @@ -62,9 +115,8 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
|
| * @return The content url of the received intent or null if none.
|
| */
|
| protected String scrollAndTapExpectingIntent(String id) throws Throwable {
|
| - TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHelperContainer();
|
| OnStartContentIntentHelper onStartContentIntentHelper =
|
| - callbackHelperContainer.getOnStartContentIntentHelper();
|
| + mContentIntentHandler.getOnStartContentIntentHelper();
|
| int currentCallCount = onStartContentIntentHelper.getCallCount();
|
|
|
| DOMUtils.clickNode(getContentViewCore(), id);
|
| @@ -93,4 +145,4 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
|
| TimeUnit.SECONDS);
|
| getInstrumentation().waitForIdleSync();
|
| }
|
| -}
|
| +}
|
|
|