Index: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java |
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java |
index d26b7558674b60522bb75ab3c9044ba4bb576d90..074f7c6b38804be72ab93004a681440e3f81df22 100644 |
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java |
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java |
@@ -9,9 +9,9 @@ import android.graphics.Color; |
import android.os.Build; |
import android.test.suitebuilder.annotation.SmallTest; |
import android.util.Pair; |
+import android.webkit.WebResourceResponse; |
import org.chromium.android_webview.AwContents; |
-import org.chromium.android_webview.AwWebResourceResponse; |
import org.chromium.android_webview.test.util.AwTestTouchUtils; |
import org.chromium.android_webview.test.util.CommonResources; |
import org.chromium.android_webview.test.util.GraphicsTestUtils; |
@@ -45,35 +45,35 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
public static class ShouldInterceptRequestHelper extends CallbackHelper { |
private List<String> mShouldInterceptRequestUrls = new ArrayList<String>(); |
- private ConcurrentHashMap<String, AwWebResourceResponse> mReturnValuesByUrls = |
- new ConcurrentHashMap<String, AwWebResourceResponse>(); |
- private ConcurrentHashMap<String, AwWebResourceRequest> mRequestsByUrls = |
- new ConcurrentHashMap<String, AwWebResourceRequest>(); |
+ private ConcurrentHashMap<String, WebResourceResponse> mReturnValuesByUrls = |
+ new ConcurrentHashMap<String, WebResourceResponse>(); |
+ private ConcurrentHashMap<String, WebResourceRequestImpl> mRequestsByUrls = |
+ new ConcurrentHashMap<String, WebResourceRequestImpl>(); |
// This is read from the IO thread, so needs to be marked volatile. |
- private volatile AwWebResourceResponse mShouldInterceptRequestReturnValue = null; |
- void setReturnValue(AwWebResourceResponse value) { |
+ private volatile WebResourceResponse mShouldInterceptRequestReturnValue = null; |
+ void setReturnValue(WebResourceResponse value) { |
mShouldInterceptRequestReturnValue = value; |
} |
- void setReturnValueForUrl(String url, AwWebResourceResponse value) { |
+ void setReturnValueForUrl(String url, WebResourceResponse value) { |
mReturnValuesByUrls.put(url, value); |
} |
public List<String> getUrls() { |
assert getCallCount() > 0; |
return mShouldInterceptRequestUrls; |
} |
- public AwWebResourceResponse getReturnValue(String url) { |
- AwWebResourceResponse value = mReturnValuesByUrls.get(url); |
+ public WebResourceResponse getReturnValue(String url) { |
+ WebResourceResponse value = mReturnValuesByUrls.get(url); |
if (value != null) return value; |
return mShouldInterceptRequestReturnValue; |
} |
- public AwWebResourceRequest getRequestsForUrl(String url) { |
+ public WebResourceRequestImpl getRequestsForUrl(String url) { |
assert getCallCount() > 0; |
assert mRequestsByUrls.containsKey(url); |
return mRequestsByUrls.get(url); |
} |
- public void notifyCalled(AwWebResourceRequest request) { |
- mShouldInterceptRequestUrls.add(request.url); |
- mRequestsByUrls.put(request.url, request); |
+ public void notifyCalled(WebResourceRequestImpl request) { |
+ mShouldInterceptRequestUrls.add(request.getUrlString()); |
+ mRequestsByUrls.put(request.getUrlString(), request); |
notifyCalled(); |
} |
} |
@@ -93,9 +93,9 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
} |
@Override |
- public AwWebResourceResponse shouldInterceptRequest(AwWebResourceRequest request) { |
- AwWebResourceResponse returnValue = |
- mShouldInterceptRequestHelper.getReturnValue(request.url); |
+ public WebResourceResponse shouldInterceptRequest(WebResourceRequestImpl request) { |
+ WebResourceResponse returnValue = |
+ mShouldInterceptRequestHelper.getReturnValue(request.getUrlString()); |
mShouldInterceptRequestHelper.notifyCalled(request); |
return returnValue; |
} |
@@ -138,11 +138,11 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
CommonResources.ABOUT_HTML); |
} |
- private AwWebResourceResponse stringToAwWebResourceResponse(String input) throws Throwable { |
+ private WebResourceResponse stringToAwWebResourceResponse(String input) throws Throwable { |
final String mimeType = "text/html"; |
final String encoding = "UTF-8"; |
- return new AwWebResourceResponse( |
+ return new WebResourceResponse( |
mimeType, encoding, new ByteArrayInputStream(input.getBytes(encoding))); |
} |
@@ -201,9 +201,9 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
assertEquals(2, mShouldInterceptRequestHelper.getUrls().size()); |
assertEquals(false, |
- mShouldInterceptRequestHelper.getRequestsForUrl(subframeUrl).isMainFrame); |
- assertEquals(true, |
- mShouldInterceptRequestHelper.getRequestsForUrl(pageWithIframeUrl).isMainFrame); |
+ mShouldInterceptRequestHelper.getRequestsForUrl(subframeUrl).isForMainFrame()); |
+ assertEquals(true, mShouldInterceptRequestHelper.getRequestsForUrl(pageWithIframeUrl) |
+ .isForMainFrame()); |
} |
@SmallTest |
@@ -218,14 +218,14 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
loadUrlAsync(mAwContents, pageWithFormUrl); |
mShouldInterceptRequestHelper.waitForCallback(callCount); |
assertEquals("GET", |
- mShouldInterceptRequestHelper.getRequestsForUrl(pageWithFormUrl).method); |
+ mShouldInterceptRequestHelper.getRequestsForUrl(pageWithFormUrl).getMethod()); |
callCount = mShouldInterceptRequestHelper.getCallCount(); |
JSUtils.clickOnLinkUsingJs(this, mAwContents, |
mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link"); |
mShouldInterceptRequestHelper.waitForCallback(callCount); |
assertEquals("POST", |
- mShouldInterceptRequestHelper.getRequestsForUrl(pageToPostToUrl).method); |
+ mShouldInterceptRequestHelper.getRequestsForUrl(pageToPostToUrl).getMethod()); |
} |
@SmallTest |
@@ -240,7 +240,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
loadUrlAsync(mAwContents, pageWithLinkUrl); |
mShouldInterceptRequestHelper.waitForCallback(callCount); |
assertEquals(false, |
- mShouldInterceptRequestHelper.getRequestsForUrl(pageWithLinkUrl).hasUserGesture); |
+ mShouldInterceptRequestHelper.getRequestsForUrl(pageWithLinkUrl).hasGesture()); |
// TODO(mkosiba): Remove this once we have a real API to wait for the page to load and |
// display. |
@@ -260,8 +260,8 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
callCount = mShouldInterceptRequestHelper.getCallCount(); |
AwTestTouchUtils.simulateTouchCenterOfView(mTestContainerView); |
mShouldInterceptRequestHelper.waitForCallback(callCount); |
- assertEquals(true, |
- mShouldInterceptRequestHelper.getRequestsForUrl(aboutPageUrl).hasUserGesture); |
+ assertEquals( |
+ true, mShouldInterceptRequestHelper.getRequestsForUrl(aboutPageUrl).hasGesture()); |
} |
@SmallTest |
@@ -286,7 +286,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
mShouldInterceptRequestHelper.waitForCallback(callCount, 2); |
Map<String, String> headers = |
- mShouldInterceptRequestHelper.getRequestsForUrl(syncGetUrl).requestHeaders; |
+ mShouldInterceptRequestHelper.getRequestsForUrl(syncGetUrl).getRequestHeaders(); |
assertTrue(headers.containsKey(headerName)); |
assertEquals(headerValue, headers.get(headerName)); |
} |
@@ -312,19 +312,18 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", null)); |
+ new WebResourceResponse("text/html", "UTF-8", null)); |
int callCount = mShouldInterceptRequestHelper.getCallCount(); |
loadUrlAsync(mAwContents, aboutPageUrl); |
mShouldInterceptRequestHelper.waitForCallback(callCount); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse(null, null, new ByteArrayInputStream(new byte[0]))); |
+ new WebResourceResponse(null, null, new ByteArrayInputStream(new byte[0]))); |
callCount = mShouldInterceptRequestHelper.getCallCount(); |
loadUrlAsync(mAwContents, aboutPageUrl); |
mShouldInterceptRequestHelper.waitForCallback(callCount); |
- mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse(null, null, null)); |
+ mShouldInterceptRequestHelper.setReturnValue(new WebResourceResponse(null, null, null)); |
callCount = mShouldInterceptRequestHelper.getCallCount(); |
loadUrlAsync(mAwContents, aboutPageUrl); |
mShouldInterceptRequestHelper.waitForCallback(callCount); |
@@ -365,7 +364,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputStream())); |
+ new WebResourceResponse("text/html", "UTF-8", new EmptyInputStream())); |
int shouldInterceptRequestCallCount = mShouldInterceptRequestHelper.getCallCount(); |
int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); |
@@ -408,7 +407,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", new ThrowingInputStream())); |
+ new WebResourceResponse("text/html", "UTF-8", new ThrowingInputStream())); |
int shouldInterceptRequestCallCount = mShouldInterceptRequestHelper.getCallCount(); |
int onPageFinishedCallCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); |
@@ -418,7 +417,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
mContentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinishedCallCount); |
} |
- private static class SlowAwWebResourceResponse extends AwWebResourceResponse { |
+ private static class SlowAwWebResourceResponse extends WebResourceResponse { |
private CallbackHelper mReadStartedCallbackHelper = new CallbackHelper(); |
private CountDownLatch mLatch = new CountDownLatch(1); |
@@ -501,18 +500,18 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), aboutPageUrl); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", null)); |
+ new WebResourceResponse("text/html", "UTF-8", null)); |
assertEquals("\"[404][Not Found]\"", |
executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, syncGetJs)); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputStream())); |
+ new WebResourceResponse("text/html", "UTF-8", new EmptyInputStream())); |
assertEquals("\"[200][OK]\"", |
executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, syncGetJs)); |
- mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputStream(), |
- TEAPOT_STATUS_CODE, TEAPOT_RESPONSE_PHRASE, new HashMap<String, String>())); |
+ mShouldInterceptRequestHelper.setReturnValue(new WebResourceResponse("text/html", "UTF-8", |
+ TEAPOT_STATUS_CODE, TEAPOT_RESPONSE_PHRASE, new HashMap<String, String>(), |
+ new EmptyInputStream())); |
assertEquals("\"[" + TEAPOT_STATUS_CODE + "][" + TEAPOT_RESPONSE_PHRASE + "]\"", |
executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, syncGetJs)); |
} |
@@ -553,11 +552,11 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
// The response header is set regardless of whether the embedder has provided a |
// valid resource stream. |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", null)); |
+ new WebResourceResponse("text/html", "UTF-8", null)); |
assertEquals(clientResponseHeaderValue, |
getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientResponseHeaderName)); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", new EmptyInputStream())); |
+ new WebResourceResponse("text/html", "UTF-8", new EmptyInputStream())); |
assertEquals(clientResponseHeaderValue, |
getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientResponseHeaderName)); |
@@ -577,7 +576,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), aboutPageUrl); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", null, 0, null, headers)); |
+ new WebResourceResponse("text/html", "UTF-8", 0, null, headers, null)); |
assertEquals(clientResponseHeaderValue, |
getHeaderValue(mAwContents, mContentsClient, syncGetUrl, clientResponseHeaderName)); |
} |
@@ -592,7 +591,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), aboutPageUrl); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", null, 0, null, null)); |
+ new WebResourceResponse("text/html", "UTF-8", 0, null, null, null)); |
assertEquals(null, getHeaderValue(mAwContents, mContentsClient, syncGetUrl, "Some-Header")); |
} |
@@ -639,7 +638,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
mContentsClient.getOnReceivedErrorHelper(); |
mShouldInterceptRequestHelper.setReturnValue( |
- new AwWebResourceResponse("text/html", "UTF-8", null)); |
+ new WebResourceResponse("text/html", "UTF-8", null)); |
final String aboutPageUrl = addAboutPageToTestServer(mWebServer); |
final int callCount = onReceivedErrorHelper.getCallCount(); |
@@ -670,7 +669,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
@SmallTest |
@Feature({"AndroidWebView"}) |
public void testOnReceivedErrorCallback() throws Throwable { |
- mShouldInterceptRequestHelper.setReturnValue(new AwWebResourceResponse(null, null, null)); |
+ mShouldInterceptRequestHelper.setReturnValue(new WebResourceResponse(null, null, null)); |
OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); |
int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(); |
loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), "foo://bar"); |
@@ -687,7 +686,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { |
addPageToTestServer(mWebServer, "/page_with_image.html", |
CommonResources.getOnImageLoadedHtml(CommonResources.FAVICON_FILENAME)); |
mShouldInterceptRequestHelper.setReturnValueForUrl( |
- imageUrl, new AwWebResourceResponse(null, null, null)); |
+ imageUrl, new WebResourceResponse(null, null, null)); |
OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); |
int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(); |
loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageWithImage); |