diff options
author | michaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-29 11:54:52 +0000 |
---|---|---|
committer | michaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-29 11:54:52 +0000 |
commit | 3f33728b95ecfc506142f0e66ba7d6130749e840 (patch) | |
tree | a3ade623cbfdd172c65b9ee5f7b70ff601affdc3 /android_webview | |
parent | 607f243333deff69e4b6dccbf35c766539ff5309 (diff) | |
download | chromium_src-3f33728b95ecfc506142f0e66ba7d6130749e840.zip chromium_src-3f33728b95ecfc506142f0e66ba7d6130749e840.tar.gz chromium_src-3f33728b95ecfc506142f0e66ba7d6130749e840.tar.bz2 |
Change isMainFrame param to indicate the MainFrame itself.
Change the isMainFrame param of AwContentsIoThreadClient.shouldInterceptRequest to be the MainFrame itself instead of the resources from main frame.
BUG=280699
Review URL: https://chromiumcodereview.appspot.com/23629004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java | 39 | ||||
-rw-r--r-- | android_webview/native/aw_contents_io_thread_client_impl.cc | 3 |
2 files changed, 39 insertions, 3 deletions
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 640175c..8e4cef5 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 @@ -25,6 +25,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; import java.util.List; import java.util.Random; @@ -38,16 +39,23 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { public static class ShouldInterceptRequestHelper extends CallbackHelper { private List<String> mShouldInterceptRequestUrls = new ArrayList<String>(); + private ConcurrentHashMap<String, InterceptedRequestData> mReturnValusByUrls + = new ConcurrentHashMap<String, InterceptedRequestData>(); // This is read from the IO thread, so needs to be marked volatile. private volatile InterceptedRequestData mShouldInterceptRequestReturnValue = null; void setReturnValue(InterceptedRequestData value) { mShouldInterceptRequestReturnValue = value; } + void setReturnValueForUrl(String url, InterceptedRequestData value) { + mReturnValusByUrls.put(url, value); + } public List<String> getUrls() { assert getCallCount() > 0; return mShouldInterceptRequestUrls; } - public InterceptedRequestData getReturnValue() { + public InterceptedRequestData getReturnValue(String url) { + InterceptedRequestData value = mReturnValusByUrls.get(url); + if (value != null) return value; return mShouldInterceptRequestReturnValue; } public void notifyCalled(String url) { @@ -72,7 +80,7 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { @Override public InterceptedRequestData shouldInterceptRequest(String url) { - InterceptedRequestData returnValue = mShouldInterceptRequestHelper.getReturnValue(); + InterceptedRequestData returnValue = mShouldInterceptRequestHelper.getReturnValue(url); mShouldInterceptRequestHelper.notifyCalled(url); return returnValue; } @@ -349,6 +357,33 @@ public class AwContentsClientShouldInterceptRequestTest extends AwTestBase { @SmallTest @Feature({"AndroidWebView"}) + public void testOnReceivedErrorCallback() throws Throwable { + mShouldInterceptRequestHelper.setReturnValue(new InterceptedRequestData(null, null, null)); + OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); + int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(); + loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), "foo://bar"); + onReceivedErrorHelper.waitForCallback(onReceivedErrorHelperCallCount, 1); + } + + @SmallTest + @Feature({"AndroidWebView"}) + public void testNoOnReceivedErrorCallback() throws Throwable { + final String imagePath = "/" + CommonResources.FAVICON_FILENAME; + final String imageUrl = mWebServer.setResponseBase64(imagePath, + CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePngHeaders(true)); + final String pageWithImage = + addPageToTestServer(mWebServer, "/page_with_image.html", + CommonResources.getOnImageLoadedHtml(CommonResources.FAVICON_FILENAME)); + mShouldInterceptRequestHelper.setReturnValueForUrl( + imageUrl, new InterceptedRequestData(null, null, null)); + OnReceivedErrorHelper onReceivedErrorHelper = mContentsClient.getOnReceivedErrorHelper(); + int onReceivedErrorHelperCallCount = onReceivedErrorHelper.getCallCount(); + loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageWithImage); + assertEquals(onReceivedErrorHelperCallCount, onReceivedErrorHelper.getCallCount()); + } + + @SmallTest + @Feature({"AndroidWebView"}) public void testCalledForIframe() throws Throwable { final String aboutPageUrl = addAboutPageToTestServer(mWebServer); final String pageWithIframe = addPageToTestServer(mWebServer, "/page_with_iframe.html", diff --git a/android_webview/native/aw_contents_io_thread_client_impl.cc b/android_webview/native/aw_contents_io_thread_client_impl.cc index 81ea0de..8002851 100644 --- a/android_webview/native/aw_contents_io_thread_client_impl.cc +++ b/android_webview/native/aw_contents_io_thread_client_impl.cc @@ -197,7 +197,8 @@ AwContentsIoThreadClientImpl::ShouldInterceptRequest( return scoped_ptr<InterceptedRequestData>(); const content::ResourceRequestInfo* info = content::ResourceRequestInfo::ForRequest(request); - bool is_main_frame = info && info->IsMainFrame(); + bool is_main_frame = info && + info->GetResourceType() == ResourceType::MAIN_FRAME; JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jstring> jstring_url = |