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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java

Issue 1708683003: [Android] Switch UrlOverridingTest over to the EmbeddedTestServer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: yfriedman comment Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/android/url_overriding/navigation_with_fallback_url.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java
index 0ac226a62e4bc7448f604057e12b47446ee52f6c..084a60d077a2cdb8af6dd34de3045bd90dc772a0 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java
@@ -11,9 +11,11 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
+import android.os.Environment;
import android.os.SystemClock;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
+import android.util.Base64;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeActivity;
@@ -24,13 +26,14 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.test.ChromeActivityTestCaseBase;
import org.chromium.chrome.test.util.ChromeRestriction;
-import org.chromium.chrome.test.util.TestHttpServerClient;
import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.LoadUrlParams;
+import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.ui.base.PageTransition;
+import java.io.UnsupportedEncodingException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -38,32 +41,32 @@ import java.util.concurrent.TimeoutException;
* Test suite for verifying the behavior of various URL overriding actions.
*/
public class UrlOverridingTest extends ChromeActivityTestCaseBase<ChromeActivity> {
- private static final String BASE_URL = "chrome/test/data/android/url_overriding/";
+ private static final String BASE_PATH = "/chrome/test/data/android/url_overriding/";
private static final String NAVIGATION_FROM_TIMEOUT_PAGE =
- BASE_URL + "navigation_from_timer.html";
+ BASE_PATH + "navigation_from_timer.html";
private static final String NAVIGATION_FROM_TIMEOUT_PARENT_FRAME_PAGE =
- BASE_URL + "navigation_from_timer_parent_frame.html";
+ BASE_PATH + "navigation_from_timer_parent_frame.html";
private static final String NAVIGATION_FROM_USER_GESTURE_PAGE =
- BASE_URL + "navigation_from_user_gesture.html";
+ BASE_PATH + "navigation_from_user_gesture.html";
private static final String NAVIGATION_FROM_USER_GESTURE_PARENT_FRAME_PAGE =
- BASE_URL + "navigation_from_user_gesture_parent_frame.html";
+ BASE_PATH + "navigation_from_user_gesture_parent_frame.html";
private static final String NAVIGATION_FROM_XHR_CALLBACK_PAGE =
- BASE_URL + "navigation_from_xhr_callback.html";
+ BASE_PATH + "navigation_from_xhr_callback.html";
private static final String NAVIGATION_FROM_XHR_CALLBACK_PARENT_FRAME_PAGE =
- BASE_URL + "navigation_from_xhr_callback_parent_frame.html";
+ BASE_PATH + "navigation_from_xhr_callback_parent_frame.html";
private static final String NAVIGATION_FROM_XHR_CALLBACK_AND_SHORT_TIMEOUT_PAGE =
- BASE_URL + "navigation_from_xhr_callback_and_short_timeout.html";
+ BASE_PATH + "navigation_from_xhr_callback_and_short_timeout.html";
private static final String NAVIGATION_FROM_XHR_CALLBACK_AND_LONG_TIMEOUT_PAGE =
- BASE_URL + "navigation_from_xhr_callback_and_long_timeout.html";
+ BASE_PATH + "navigation_from_xhr_callback_and_long_timeout.html";
private static final String NAVIGATION_WITH_FALLBACK_URL_PAGE =
- BASE_URL + "navigation_with_fallback_url.html";
+ BASE_PATH + "navigation_with_fallback_url.html";
private static final String NAVIGATION_WITH_FALLBACK_URL_PARENT_FRAME_PAGE =
- BASE_URL + "navigation_with_fallback_url_parent_frame.html";
- private static final String FALLBACK_LANDING_URL = BASE_URL + "hello.html";
+ BASE_PATH + "navigation_with_fallback_url_parent_frame.html";
+ private static final String FALLBACK_LANDING_PATH = BASE_PATH + "hello.html";
private static final String OPEN_WINDOW_FROM_USER_GESTURE_PAGE =
- BASE_URL + "open_window_from_user_gesture.html";
+ BASE_PATH + "open_window_from_user_gesture.html";
private static final String NAVIGATION_FROM_JAVA_REDIRECTION_PAGE =
- BASE_URL + "navigation_from_java_redirection.html";
+ BASE_PATH + "navigation_from_java_redirection.html";
private static class TestTabObserver extends EmptyTabObserver {
private final CallbackHelper mFinishCallback;
@@ -101,9 +104,11 @@ public class UrlOverridingTest extends ChromeActivityTestCaseBase<ChromeActivity
}
private ActivityMonitor mActivityMonitor;
+ private EmbeddedTestServer mTestServer;
public UrlOverridingTest() {
super(ChromeActivity.class);
+ mSkipCheckHttpServer = true;
}
@Override
@@ -114,6 +119,14 @@ public class UrlOverridingTest extends ChromeActivityTestCaseBase<ChromeActivity
filter.addDataScheme("market");
mActivityMonitor = getInstrumentation().addMonitor(
filter, new Instrumentation.ActivityResult(Activity.RESULT_OK, null), true);
+ mTestServer = EmbeddedTestServer.createAndStartFileServer(
+ getInstrumentation().getContext(), Environment.getExternalStorageDirectory());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mTestServer.stopAndDestroyServer();
+ super.tearDown();
}
private void loadUrlAndWaitForIntentUrl(final String url, boolean needClick,
@@ -197,6 +210,8 @@ public class UrlOverridingTest extends ChromeActivityTestCaseBase<ChromeActivity
.getLastOverrideUrlLoadingResultForTests())) {
return false;
}
+ updateFailureReason("Expected: " + expectedFinalUrl + " actual: "
+ + tab.getUrl());
return expectedFinalUrl == null
|| TextUtils.equals(expectedFinalUrl, tab.getUrl());
}
@@ -206,81 +221,104 @@ public class UrlOverridingTest extends ChromeActivityTestCaseBase<ChromeActivity
@SmallTest
public void testNavigationFromTimer() throws InterruptedException {
loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_FROM_TIMEOUT_PAGE), false, false, true);
+ mTestServer.getURL(NAVIGATION_FROM_TIMEOUT_PAGE), false, false, true);
}
@SmallTest
public void testNavigationFromTimerInSubFrame() throws InterruptedException {
loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_FROM_TIMEOUT_PARENT_FRAME_PAGE), false,
+ mTestServer.getURL(NAVIGATION_FROM_TIMEOUT_PARENT_FRAME_PAGE), false,
false, false);
}
@SmallTest
public void testNavigationFromUserGesture() throws InterruptedException {
loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_FROM_USER_GESTURE_PAGE), true, true, true);
+ mTestServer.getURL(NAVIGATION_FROM_USER_GESTURE_PAGE), true, true, true);
}
@SmallTest
public void testNavigationFromUserGestureInSubFrame() throws InterruptedException {
loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_FROM_USER_GESTURE_PARENT_FRAME_PAGE), true,
+ mTestServer.getURL(NAVIGATION_FROM_USER_GESTURE_PARENT_FRAME_PAGE), true,
true, false);
}
@SmallTest
public void testNavigationFromXHRCallback() throws InterruptedException {
loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_FROM_XHR_CALLBACK_PAGE), true, true, true);
+ mTestServer.getURL(NAVIGATION_FROM_XHR_CALLBACK_PAGE), true, true, true);
}
@SmallTest
public void testNavigationFromXHRCallbackInSubFrame() throws InterruptedException {
loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_FROM_XHR_CALLBACK_PARENT_FRAME_PAGE), true,
+ mTestServer.getURL(NAVIGATION_FROM_XHR_CALLBACK_PARENT_FRAME_PAGE), true,
true, false);
}
@SmallTest
public void testNavigationFromXHRCallbackAndShortTimeout() throws InterruptedException {
loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_FROM_XHR_CALLBACK_AND_SHORT_TIMEOUT_PAGE),
+ mTestServer.getURL(NAVIGATION_FROM_XHR_CALLBACK_AND_SHORT_TIMEOUT_PAGE),
true, true, true);
}
@SmallTest
public void testNavigationFromXHRCallbackAndLongTimeout() throws InterruptedException {
loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_FROM_XHR_CALLBACK_AND_LONG_TIMEOUT_PAGE),
+ mTestServer.getURL(NAVIGATION_FROM_XHR_CALLBACK_AND_LONG_TIMEOUT_PAGE),
true, false, true);
}
@SmallTest
- public void testNavigationWithFallbackURL() throws InterruptedException {
- loadUrlAndWaitForIntentUrl(TestHttpServerClient.getUrl(NAVIGATION_WITH_FALLBACK_URL_PAGE),
- true, 0, false, TestHttpServerClient.getUrl(FALLBACK_LANDING_URL), true);
+ public void testNavigationWithFallbackURL()
+ throws InterruptedException, UnsupportedEncodingException {
+ String fallbackUrl = mTestServer.getURL(FALLBACK_LANDING_PATH);
+ String originalUrl = mTestServer.getURL(
+ NAVIGATION_WITH_FALLBACK_URL_PAGE + "?replace_text="
+ + Base64.encodeToString("PARAM_FALLBACK_URL".getBytes("utf-8"), Base64.URL_SAFE)
+ + ":" + Base64.encodeToString(fallbackUrl.getBytes("utf-8"), Base64.URL_SAFE));
+ loadUrlAndWaitForIntentUrl(originalUrl, true, 0, false, fallbackUrl, true);
}
@SmallTest
- public void testNavigationWithFallbackURLInSubFrame() throws InterruptedException {
+ public void testNavigationWithFallbackURLInSubFrame()
+ throws InterruptedException, UnsupportedEncodingException {
+ // The replace_text parameters for NAVIGATION_WITH_FALLBACK_URL_PAGE, which is loaded in
+ // the iframe in NAVIGATION_WITH_FALLBACK_URL_PARENT_FRAME_PAGE, have to go through the
+ // embedded test server twice and, as such, have to be base64-encoded twice.
+ String fallbackUrl = mTestServer.getURL(FALLBACK_LANDING_PATH);
+ byte[] paramBase64Name = "PARAM_BASE64_NAME".getBytes("utf-8");
+ byte[] base64ParamFallbackUrl = Base64.encode("PARAM_FALLBACK_URL".getBytes("utf-8"),
+ Base64.URL_SAFE);
+ byte[] paramBase64Value = "PARAM_BASE64_VALUE".getBytes("utf-8");
+ byte[] base64FallbackUrl = Base64.encode(fallbackUrl.getBytes("utf-8"), Base64.URL_SAFE);
+
+ String originalUrl = mTestServer.getURL(
+ NAVIGATION_WITH_FALLBACK_URL_PARENT_FRAME_PAGE
+ + "?replace_text="
+ + Base64.encodeToString(paramBase64Name, Base64.URL_SAFE) + ":"
+ + Base64.encodeToString(base64ParamFallbackUrl, Base64.URL_SAFE)
+ + "&replace_text="
+ + Base64.encodeToString(paramBase64Value, Base64.URL_SAFE) + ":"
+ + Base64.encodeToString(base64FallbackUrl, Base64.URL_SAFE));
+
// Fallback URL from a subframe will not trigger main or sub frame navigation.
- loadUrlAndWaitForIntentUrl(
- TestHttpServerClient.getUrl(NAVIGATION_WITH_FALLBACK_URL_PARENT_FRAME_PAGE), true,
- false, false);
+ loadUrlAndWaitForIntentUrl(originalUrl, true, false, false);
}
@SmallTest
@Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET)
public void testOpenWindowFromUserGesture() throws InterruptedException {
- loadUrlAndWaitForIntentUrl(TestHttpServerClient.getUrl(OPEN_WINDOW_FROM_USER_GESTURE_PAGE),
+ loadUrlAndWaitForIntentUrl(mTestServer.getURL(OPEN_WINDOW_FROM_USER_GESTURE_PAGE),
true, 1, true, null, true);
}
@SmallTest
public void testRedirectionFromIntent() throws InterruptedException {
Intent intent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(TestHttpServerClient.getUrl(NAVIGATION_FROM_JAVA_REDIRECTION_PAGE)));
+ Uri.parse(mTestServer.getURL(NAVIGATION_FROM_JAVA_REDIRECTION_PAGE)));
Context targetContext = getInstrumentation().getTargetContext();
intent.setClassName(targetContext, ChromeLauncherActivity.class.getName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
« no previous file with comments | « no previous file | chrome/test/data/android/url_overriding/navigation_with_fallback_url.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698