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

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java

Issue 255503004: Do not attempt to download favicons with 404 status in WebView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 8 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: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java
index fd86014729847812f60706b67c1425b57253c361..973155eb53c1056b9a164f0d6e7940b7ca7946c4 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java
@@ -8,6 +8,8 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.test.suitebuilder.annotation.SmallTest;
+import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
+
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.test.util.CommonResources;
import org.chromium.content.browser.test.util.CallbackHelper;
@@ -16,6 +18,7 @@ import org.chromium.net.test.util.TestWebServer;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
+import java.util.concurrent.Callable;
/**
* Tests for the Favicon and TouchIcon related APIs.
@@ -40,6 +43,9 @@ public class AwContentsClientFaviconTest extends AwTestBase {
+ "\" />",
"Body");
+ // Maximum number of milliseconds within which a request to web server is made.
+ private static final long MAX_REQUEST_WAITING_LIMIT_MS = scaleTimeout(500);
+
private static class FaviconHelper extends CallbackHelper {
private Bitmap mIcon;
private HashMap<String, Boolean> mTouchIcons = new HashMap<String, Boolean>();
@@ -112,11 +118,41 @@ public class AwContentsClientFaviconTest extends AwTestBase {
loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
mContentsClient.mFaviconHelper.waitForCallback(callCount);
+ assertEquals(1, mWebServer.getRequestCount(FAVICON1_URL));
Object originalFaviconSource = (new URL(faviconUrl)).getContent();
Bitmap originalFavicon = BitmapFactory.decodeStream((InputStream) originalFaviconSource);
assertNotNull(originalFavicon);
assertNotNull(mContentsClient.mFaviconHelper.mIcon);
assertTrue(mContentsClient.mFaviconHelper.mIcon.sameAs(originalFavicon));
+
+ // Make sure the request counter for favicon is incremented when the page is loaded again
+ // successfully.
+ loadUrlAsync(mAwContents, pageUrl);
+ mContentsClient.mFaviconHelper.waitForCallback(callCount);
+ assertEquals(2, mWebServer.getRequestCount(FAVICON1_URL));
+ }
+
+ @SmallTest
+ public void testDoNotMakeRequestForFaviconAfter404() throws Throwable {
+ init(new TestAwContentsClientFavicon());
+
+ mWebServer.setResponseWithNotFoundStatus(FAVICON1_URL);
+ final String pageUrl = mWebServer.setResponse(FAVICON1_PAGE_URL, FAVICON1_PAGE_HTML,
+ CommonResources.getTextHtmlHeaders(true));
+
+ loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+ poll(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ return mWebServer.getRequestCount(FAVICON1_URL) == 1;
+ }
+ });
+
+ // Make sure the request counter for favicon is not incremented, since we already got 404.
+ loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+ // If a request hasn't been done within this time period, we assume it won't be done.
+ Thread.sleep(MAX_REQUEST_WAITING_LIMIT_MS);
+ assertEquals(1, mWebServer.getRequestCount(FAVICON1_URL));
}
@SmallTest

Powered by Google App Engine
This is Rietveld 408576698