Commit 56eb36cf authored by zqzhang's avatar zqzhang Committed by Commit bot

[MediaNotification] Don't check HTTP status code for image fetch

ImageDownloader does not return valid HTTP status code for local
URLs. This CL removes the check for HTTP status code from
MediaImageManager, so that it only checks for the list of
downloaded to see if the image fetch succeeded or not.

This CL also adds tests for verifying ImageDownloader returns
correct results.

BUG=679694

Review-Url: https://codereview.chromium.org/2625703002
Cr-Commit-Position: refs/heads/master@{#442949}
parent 690c3cf2
......@@ -154,11 +154,6 @@ public class MediaImageManager implements ImageDownloadCallback {
public void onFinishDownloadImage(int id, int httpStatusCode, String imageUrl,
List<Bitmap> bitmaps, List<Rect> originalImageSizes) {
if (id != mRequestId) return;
if (httpStatusCode < 200 || httpStatusCode >= 300) {
mCallback.onImageDownloaded(null);
clearRequests();
return;
}
Iterator<Bitmap> iterBitmap = bitmaps.iterator();
Iterator<Rect> iterSize = originalImageSizes.iterator();
......
......@@ -177,7 +177,7 @@ public class MediaImageManagerTest {
public void testDownloadImageFails() {
mMediaImageManager.downloadImage(mImages, mCallback);
mMediaImageManager.onFinishDownloadImage(
REQUEST_ID_1, 404, IMAGE_URL, mBitmaps, mOriginalImageSizes);
REQUEST_ID_1, 404, IMAGE_URL, new ArrayList<Bitmap>(), new ArrayList<Rect>());
verify(mCallback).onImageDownloaded(isNull(Bitmap.class));
verify(mCallback, times(0)).onImageDownloaded(isNotNull(Bitmap.class));
......
......@@ -1174,10 +1174,12 @@ class DownloadImageObserver {
};
void DownloadImageTestInternal(Shell* shell,
const GURL &image_url,
int expected_http_status) {
const GURL& image_url,
int expected_http_status,
int expected_number_of_images) {
using ::testing::_;
using ::testing::InvokeWithoutArgs;
using ::testing::SizeIs;
// Set up everything.
DownloadImageObserver download_image_observer;
......@@ -1186,7 +1188,8 @@ void DownloadImageTestInternal(Shell* shell,
// Set up expectation and stub.
EXPECT_CALL(download_image_observer,
OnFinishDownloadImage(_, expected_http_status, _, _, _));
OnFinishDownloadImage(_, expected_http_status, _,
SizeIs(expected_number_of_images), _));
ON_CALL(download_image_observer, OnFinishDownloadImage(_, _, _, _, _))
.WillByDefault(
InvokeWithoutArgs(loop_runner.get(), &MessageLoopRunner::Quit));
......@@ -1218,16 +1221,26 @@ void ExpectNoValidImageCallback(const base::Closure& quit_closure,
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
DownloadImage_HttpImage) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL kImageUrl =
embedded_test_server()->GetURL("/image.jpg");
DownloadImageTestInternal(shell(), kImageUrl, 200);
const GURL kImageUrl = embedded_test_server()->GetURL("/single_face.jpg");
DownloadImageTestInternal(shell(), kImageUrl, 200, 1);
}
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
DownloadImage_Deny_FileImage) {
ASSERT_TRUE(embedded_test_server()->Start());
shell()->LoadURL(embedded_test_server()->GetURL("/simple_page.html"));
const GURL kImageUrl = GetTestUrl("", "single_face.jpg");
DownloadImageTestInternal(shell(), kImageUrl, 0, 0);
}
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
DownloadImage_Allow_FileImage) {
shell()->LoadURL(GetTestUrl("", "simple_page.html"));
const GURL kImageUrl =
GetTestUrl("", "image.jpg");
DownloadImageTestInternal(shell(), kImageUrl, 0);
DownloadImageTestInternal(shell(), kImageUrl, 0, 0);
}
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DownloadImage_NoValidImage) {
......@@ -1242,6 +1255,19 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DownloadImage_NoValidImage) {
run_loop.Run();
}
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DownloadImage_DataImage) {
const GURL kImageUrl = GURL(
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHE"
"lEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==");
DownloadImageTestInternal(shell(), kImageUrl, 0, 1);
}
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
DownloadImage_InvalidDataImage) {
const GURL kImageUrl = GURL("data:image/png;invalid");
DownloadImageTestInternal(shell(), kImageUrl, 0, 0);
}
class MouseLockDelegate : public WebContentsDelegate {
public:
// WebContentsDelegate:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment