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

Unified Diff: third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp

Issue 2610083002: Fix response header correspondence in multipart image
Patch Set: Created 3 years, 12 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 | « third_party/WebKit/Source/core/loader/resource/ImageResource.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
diff --git a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
index 2213c24b4bb9c9373a849374bbae5a3e31666bd7..5a08fdf48f5845d59d084a771f29da657cdb4746 100644
--- a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
@@ -248,10 +248,10 @@ TEST(ImageResourceTest, MultipartImage) {
EXPECT_FALSE(client->notifyFinishedCalled());
EXPECT_EQ("multipart/x-mixed-replace", cachedImage->response().mimeType());
- const char firstPart[] =
+ const char firstPartHeader[] =
"--boundary\n"
"Content-Type: image/svg+xml\n\n";
- cachedImage->appendData(firstPart, strlen(firstPart));
+ cachedImage->appendData(firstPartHeader, strlen(firstPartHeader));
// Send the response for the first real part. No image or data buffer is
// created.
EXPECT_FALSE(cachedImage->resourceBuffer());
@@ -260,12 +260,12 @@ TEST(ImageResourceTest, MultipartImage) {
EXPECT_FALSE(client->notifyFinishedCalled());
EXPECT_EQ("image/svg+xml", cachedImage->response().mimeType());
- const char secondPart[] =
+ const char firstPartBody[] =
"<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'><rect "
"width='1' height='1' fill='green'/></svg>\n";
// The first bytes arrive. The data buffer is created, but no image is
// created.
- cachedImage->appendData(secondPart, strlen(secondPart));
+ cachedImage->appendData(firstPartBody, strlen(firstPartBody));
EXPECT_TRUE(cachedImage->resourceBuffer());
EXPECT_FALSE(cachedImage->getContent()->hasImage());
EXPECT_EQ(0, client->imageChangedCount());
@@ -278,14 +278,14 @@ TEST(ImageResourceTest, MultipartImage) {
EXPECT_EQ(0, client2->imageChangedCount());
EXPECT_FALSE(client2->notifyFinishedCalled());
- const char thirdPart[] = "--boundary";
- cachedImage->appendData(thirdPart, strlen(thirdPart));
+ const char secondPartHeader[] =
+ "--boundary\n"
+ "Content-Type: image/jpeg\n\n";
+ cachedImage->appendData(secondPartHeader, strlen(secondPartHeader));
ASSERT_TRUE(cachedImage->resourceBuffer());
- EXPECT_EQ(strlen(secondPart) - 1, cachedImage->resourceBuffer()->size());
-
- // This part finishes. The image is created, callbacks are sent, and the data
- // buffer is cleared.
- cachedImage->loader()->didFinishLoading(0.0, 0, 0);
+ EXPECT_EQ(strlen(firstPartBody) - 1, cachedImage->resourceBuffer()->size());
+ // The first part finishes.
+ // The image is created, callbacks are sent, and the data buffer is cleared.
EXPECT_TRUE(cachedImage->resourceBuffer());
EXPECT_FALSE(cachedImage->errorOccurred());
ASSERT_TRUE(cachedImage->getContent()->hasImage());
@@ -296,6 +296,29 @@ TEST(ImageResourceTest, MultipartImage) {
EXPECT_TRUE(client->notifyFinishedCalled());
EXPECT_EQ(1, client2->imageChangedCount());
EXPECT_TRUE(client2->notifyFinishedCalled());
+
+ // The body of the second part arrives.
+ cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage2),
+ sizeof(kJpegImage2));
+ ASSERT_TRUE(cachedImage->resourceBuffer());
+
+ // The last boundary arrives.
+ // The second part is processed.
+ const char lastBoundary[] = "\n--boundary";
+ cachedImage->appendData(lastBoundary, strlen(lastBoundary));
+ ASSERT_TRUE(cachedImage->resourceBuffer());
+ EXPECT_EQ(sizeof(kJpegImage2), cachedImage->resourceBuffer()->size());
+
+ // Load finishes.
+ cachedImage->loader()->didFinishLoading(0.0, 0, 0);
+
+ EXPECT_FALSE(cachedImage->errorOccurred());
+ ASSERT_TRUE(cachedImage->getContent()->hasImage());
+ EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull());
+ EXPECT_EQ(50, cachedImage->getContent()->getImage()->width());
+ EXPECT_EQ(50, cachedImage->getContent()->getImage()->height());
+ EXPECT_EQ(2, client->imageChangedCount());
+ EXPECT_EQ(2, client2->imageChangedCount());
}
TEST(ImageResourceTest, CancelOnDetach) {
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698