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

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

Issue 1802123002: Unify Resource loading status tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 blink::testing::runPendingTasks(); 170 blink::testing::runPendingTasks();
171 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus()); 171 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus());
172 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); 172 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL));
173 173
174 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); 174 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL);
175 } 175 }
176 176
177 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) 177 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
178 { 178 {
179 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(), nullptr); 179 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(), nullptr);
180 cachedImage->setLoading(true); 180 cachedImage->setStatus(Resource::Pending);
181 181
182 MockImageResourceClient client(cachedImage); 182 MockImageResourceClient client(cachedImage);
183 183
184 // Send the image response. 184 // Send the image response.
185 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re place", 0, nullAtom, String()), nullptr); 185 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re place", 0, nullAtom, String()), nullptr);
186 186
187 Vector<unsigned char> jpeg = jpegImage(); 187 Vector<unsigned char> jpeg = jpegImage();
188 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr); 188 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr);
189 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 189 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
190 cachedImage->finish(); 190 cachedImage->finish();
(...skipping 12 matching lines...) Expand all
203 client.removeAsClient(); 203 client.removeAsClient();
204 cachedImage->prune(); 204 cachedImage->prune();
205 ASSERT_FALSE(cachedImage->hasClients()); 205 ASSERT_FALSE(cachedImage->hasClients());
206 ASSERT_FALSE(cachedImage->hasImage()); 206 ASSERT_FALSE(cachedImage->hasImage());
207 ASSERT_TRUE(cachedImage->getImage()->isNull()); 207 ASSERT_TRUE(cachedImage->getImage()->isNull());
208 } 208 }
209 209
210 TEST(ImageResourceTest, UpdateBitmapImages) 210 TEST(ImageResourceTest, UpdateBitmapImages)
211 { 211 {
212 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(), nullptr); 212 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(), nullptr);
213 cachedImage->setLoading(true); 213 cachedImage->setStatus(Resource::Pending);
214 214
215 MockImageResourceClient client(cachedImage); 215 MockImageResourceClient client(cachedImage);
216 216
217 // Send the image response. 217 // Send the image response.
218 Vector<unsigned char> jpeg = jpegImage(); 218 Vector<unsigned char> jpeg = jpegImage();
219 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr); 219 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr);
220 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 220 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
221 cachedImage->finish(); 221 cachedImage->finish();
222 ASSERT_FALSE(cachedImage->errorOccurred()); 222 ASSERT_FALSE(cachedImage->errorOccurred());
223 ASSERT_TRUE(cachedImage->hasImage()); 223 ASSERT_TRUE(cachedImage->hasImage());
224 ASSERT_FALSE(cachedImage->getImage()->isNull()); 224 ASSERT_FALSE(cachedImage->getImage()->isNull());
225 ASSERT_EQ(client.imageChangedCount(), 2); 225 ASSERT_EQ(client.imageChangedCount(), 2);
226 ASSERT_TRUE(client.notifyFinishedCalled()); 226 ASSERT_TRUE(client.notifyFinishedCalled());
227 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 227 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
228 } 228 }
229 229
230 TEST(ImageResourceTest, ReloadIfLoFi) 230 TEST(ImageResourceTest, ReloadIfLoFi)
231 { 231 {
232 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 232 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
233 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); 233 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html ");
234 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(testURL), nullptr); 234 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(testURL), nullptr);
235 cachedImage->setLoading(true); 235 cachedImage->setStatus(Resource::Pending);
236 236
237 MockImageResourceClient client(cachedImage); 237 MockImageResourceClient client(cachedImage);
238 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 238 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
239 239
240 // Send the image response. 240 // Send the image response.
241 Vector<unsigned char> jpeg = jpegImage(); 241 Vector<unsigned char> jpeg = jpegImage();
242 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto m, String()); 242 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto m, String());
243 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); 243 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low");
244 244
245 cachedImage->responseReceived(resourceResponse, nullptr); 245 cachedImage->responseReceived(resourceResponse, nullptr);
(...skipping 16 matching lines...) Expand all
262 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 262 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
263 cachedImage->finish(); 263 cachedImage->finish();
264 ASSERT_FALSE(cachedImage->errorOccurred()); 264 ASSERT_FALSE(cachedImage->errorOccurred());
265 ASSERT_TRUE(cachedImage->hasImage()); 265 ASSERT_TRUE(cachedImage->hasImage());
266 ASSERT_FALSE(cachedImage->getImage()->isNull()); 266 ASSERT_FALSE(cachedImage->getImage()->isNull());
267 ASSERT_TRUE(client.notifyFinishedCalled()); 267 ASSERT_TRUE(client.notifyFinishedCalled());
268 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 268 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
269 } 269 }
270 270
271 } // namespace blink 271 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698