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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ImageResourceTest.cpp

Issue 1710733002: Move multipart resource handling to core/fetch (2/2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@multipart-cleanup
Patch Set: Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 cachedImage->load(fetcher, ResourceLoaderOptions()); 93 cachedImage->load(fetcher, ResourceLoaderOptions());
94 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); 94 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL);
95 95
96 MockImageResourceClient client(cachedImage); 96 MockImageResourceClient client(cachedImage);
97 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); 97 EXPECT_EQ(Resource::Pending, cachedImage->getStatus());
98 98
99 // Send the multipart response. No image or data buffer is created. 99 // Send the multipart response. No image or data buffer is created.
100 // Note that the response must be routed through ResourceLoader to 100 // Note that the response must be routed through ResourceLoader to
101 // ensure the load is flagged as multipart. 101 // ensure the load is flagged as multipart.
102 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n ullAtom, String()); 102 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n ullAtom, String());
103 multipartResponse.setMultipartBoundary("boundary", strlen("boundary"));
103 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(m ultipartResponse), nullptr); 104 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(m ultipartResponse), nullptr);
104 ASSERT_FALSE(cachedImage->resourceBuffer()); 105 ASSERT_FALSE(cachedImage->resourceBuffer());
105 ASSERT_FALSE(cachedImage->hasImage()); 106 ASSERT_FALSE(cachedImage->hasImage());
106 ASSERT_EQ(client.imageChangedCount(), 0); 107 ASSERT_EQ(client.imageChangedCount(), 0);
107 ASSERT_FALSE(client.notifyFinishedCalled()); 108 ASSERT_FALSE(client.notifyFinishedCalled());
109 EXPECT_EQ("multipart/x-mixed-replace", cachedImage->response().mimeType());
108 110
111 const char firstPart[] =
112 "--boundary\n"
113 "Content-Type: image/svg+xml\n\n";
114 cachedImage->appendData(firstPart, strlen(firstPart));
109 // Send the response for the first real part. No image or data buffer is cre ated. 115 // Send the response for the first real part. No image or data buffer is cre ated.
110 const char* svgData = "<svg xmlns='http://www.w3.org/2000/svg' width='1' hei ght='1'><rect width='1' height='1' fill='green'/></svg>";
111 unsigned svgDataLength = strlen(svgData);
112 ResourceResponse payloadResponse(KURL(), "image/svg+xml", svgDataLength, nul lAtom, String());
113 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(p ayloadResponse), nullptr);
114 ASSERT_FALSE(cachedImage->resourceBuffer()); 116 ASSERT_FALSE(cachedImage->resourceBuffer());
115 ASSERT_FALSE(cachedImage->hasImage()); 117 ASSERT_FALSE(cachedImage->hasImage());
116 ASSERT_EQ(client.imageChangedCount(), 0); 118 ASSERT_EQ(client.imageChangedCount(), 0);
117 ASSERT_FALSE(client.notifyFinishedCalled()); 119 ASSERT_FALSE(client.notifyFinishedCalled());
120 EXPECT_EQ("image/svg+xml", cachedImage->response().mimeType());
118 121
122 const char secondPart[] = "<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'><rect width='1' height='1' fill='green'/></svg>\n";
119 // The first bytes arrive. The data buffer is created, but no image is creat ed. 123 // The first bytes arrive. The data buffer is created, but no image is creat ed.
120 cachedImage->appendData(svgData, svgDataLength); 124 cachedImage->appendData(secondPart, strlen(secondPart));
121 ASSERT_TRUE(cachedImage->resourceBuffer()); 125 ASSERT_TRUE(cachedImage->resourceBuffer());
122 ASSERT_EQ(cachedImage->resourceBuffer()->size(), svgDataLength); 126 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart));
123 ASSERT_FALSE(cachedImage->hasImage()); 127 ASSERT_FALSE(cachedImage->hasImage());
124 ASSERT_EQ(client.imageChangedCount(), 0); 128 ASSERT_EQ(client.imageChangedCount(), 0);
125 ASSERT_FALSE(client.notifyFinishedCalled()); 129 ASSERT_FALSE(client.notifyFinishedCalled());
126 130
127 // This part finishes. The image is created, callbacks are sent, and the dat a buffer is cleared. 131 // This part finishes. The image is created, callbacks are sent, and the dat a buffer is cleared.
128 cachedImage->finish(); 132 cachedImage->finish();
129 ASSERT_FALSE(cachedImage->resourceBuffer()); 133 ASSERT_FALSE(cachedImage->resourceBuffer());
130 ASSERT_FALSE(cachedImage->errorOccurred()); 134 ASSERT_FALSE(cachedImage->errorOccurred());
131 ASSERT_TRUE(cachedImage->hasImage()); 135 ASSERT_TRUE(cachedImage->hasImage());
132 ASSERT_FALSE(cachedImage->image()->isNull()); 136 ASSERT_FALSE(cachedImage->image()->isNull());
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 258 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
255 cachedImage->finish(); 259 cachedImage->finish();
256 ASSERT_FALSE(cachedImage->errorOccurred()); 260 ASSERT_FALSE(cachedImage->errorOccurred());
257 ASSERT_TRUE(cachedImage->hasImage()); 261 ASSERT_TRUE(cachedImage->hasImage());
258 ASSERT_FALSE(cachedImage->image()->isNull()); 262 ASSERT_FALSE(cachedImage->image()->isNull());
259 ASSERT_TRUE(client.notifyFinishedCalled()); 263 ASSERT_TRUE(client.notifyFinishedCalled());
260 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); 264 ASSERT_TRUE(cachedImage->image()->isBitmapImage());
261 } 265 }
262 266
263 } // namespace blink 267 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698