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

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

Issue 1829403002: Clean up font loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Resource_status
Patch Set: Another rebase! Created 4 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 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return jpeg; 80 return jpeg;
81 } 81 }
82 82
83 TEST(ImageResourceTest, MultipartImage) 83 TEST(ImageResourceTest, MultipartImage)
84 { 84 {
85 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 85 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
86 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 86 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
87 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); 87 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html ");
88 88
89 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks. 89 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks.
90 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL), nullptr); 90 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL)) ;
91 cachedImage->setIdentifier(createUniqueIdentifier()); 91 cachedImage->setIdentifier(createUniqueIdentifier());
92 cachedImage->load(fetcher); 92 cachedImage->load(fetcher);
93 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); 93 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL);
94 94
95 MockImageResourceClient client(cachedImage); 95 MockImageResourceClient client(cachedImage);
96 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); 96 EXPECT_EQ(Resource::Pending, cachedImage->getStatus());
97 97
98 // Send the multipart response. No image or data buffer is created. 98 // Send the multipart response. No image or data buffer is created.
99 // Note that the response must be routed through ResourceLoader to 99 // Note that the response must be routed through ResourceLoader to
100 // ensure the load is flagged as multipart. 100 // ensure the load is flagged as multipart.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 TEST(ImageResourceTest, CancelOnDetach) 146 TEST(ImageResourceTest, CancelOnDetach)
147 { 147 {
148 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 148 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
149 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); 149 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html ");
150 150
151 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 151 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
152 152
153 // Emulate starting a real load. 153 // Emulate starting a real load.
154 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL), nullptr); 154 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL)) ;
155 cachedImage->setIdentifier(createUniqueIdentifier()); 155 cachedImage->setIdentifier(createUniqueIdentifier());
156 156
157 cachedImage->load(fetcher); 157 cachedImage->load(fetcher);
158 memoryCache()->add(cachedImage); 158 memoryCache()->add(cachedImage);
159 159
160 MockImageResourceClient client(cachedImage); 160 MockImageResourceClient client(cachedImage);
161 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); 161 EXPECT_EQ(Resource::Pending, cachedImage->getStatus());
162 162
163 // The load should still be alive, but a timer should be started to cancel t he load inside removeClient(). 163 // The load should still be alive, but a timer should be started to cancel t he load inside removeClient().
164 client.removeAsClient(); 164 client.removeAsClient();
165 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); 165 EXPECT_EQ(Resource::Pending, cachedImage->getStatus());
166 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); 166 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL));
167 167
168 // Trigger the cancel timer, ensure the load was cancelled and the resource was evicted from the cache. 168 // Trigger the cancel timer, ensure the load was cancelled and the resource was evicted from the cache.
169 blink::testing::runPendingTasks(); 169 blink::testing::runPendingTasks();
170 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus()); 170 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus());
171 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); 171 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL));
172 172
173 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); 173 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL);
174 } 174 }
175 175
176 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) 176 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
177 { 177 {
178 ImageResource* cachedImage = ImageResource::create(ResourceRequest(), nullpt r); 178 ImageResource* cachedImage = ImageResource::create(ResourceRequest());
179 cachedImage->setStatus(Resource::Pending); 179 cachedImage->setStatus(Resource::Pending);
180 180
181 MockImageResourceClient client(cachedImage); 181 MockImageResourceClient client(cachedImage);
182 182
183 // Send the image response. 183 // Send the image response.
184 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re place", 0, nullAtom, String()), nullptr); 184 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re place", 0, nullAtom, String()), nullptr);
185 185
186 Vector<unsigned char> jpeg = jpegImage(); 186 Vector<unsigned char> jpeg = jpegImage();
187 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr); 187 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr);
188 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 188 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
(...skipping 12 matching lines...) Expand all
201 // The ImageResource no longer has clients. The image should be deleted by p rune. 201 // The ImageResource no longer has clients. The image should be deleted by p rune.
202 client.removeAsClient(); 202 client.removeAsClient();
203 cachedImage->prune(); 203 cachedImage->prune();
204 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); 204 ASSERT_FALSE(cachedImage->hasClientsOrObservers());
205 ASSERT_FALSE(cachedImage->hasImage()); 205 ASSERT_FALSE(cachedImage->hasImage());
206 ASSERT_TRUE(cachedImage->getImage()->isNull()); 206 ASSERT_TRUE(cachedImage->getImage()->isNull());
207 } 207 }
208 208
209 TEST(ImageResourceTest, UpdateBitmapImages) 209 TEST(ImageResourceTest, UpdateBitmapImages)
210 { 210 {
211 ImageResource* cachedImage = ImageResource::create(ResourceRequest(), nullpt r); 211 ImageResource* cachedImage = ImageResource::create(ResourceRequest());
212 cachedImage->setStatus(Resource::Pending); 212 cachedImage->setStatus(Resource::Pending);
213 213
214 MockImageResourceClient client(cachedImage); 214 MockImageResourceClient client(cachedImage);
215 215
216 // Send the image response. 216 // Send the image response.
217 Vector<unsigned char> jpeg = jpegImage(); 217 Vector<unsigned char> jpeg = jpegImage();
218 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr); 218 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr);
219 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 219 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
220 cachedImage->finish(); 220 cachedImage->finish();
221 ASSERT_FALSE(cachedImage->errorOccurred()); 221 ASSERT_FALSE(cachedImage->errorOccurred());
222 ASSERT_TRUE(cachedImage->hasImage()); 222 ASSERT_TRUE(cachedImage->hasImage());
223 ASSERT_FALSE(cachedImage->getImage()->isNull()); 223 ASSERT_FALSE(cachedImage->getImage()->isNull());
224 ASSERT_EQ(client.imageChangedCount(), 2); 224 ASSERT_EQ(client.imageChangedCount(), 2);
225 ASSERT_TRUE(client.notifyFinishedCalled()); 225 ASSERT_TRUE(client.notifyFinishedCalled());
226 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 226 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
227 } 227 }
228 228
229 TEST(ImageResourceTest, ReloadIfLoFi) 229 TEST(ImageResourceTest, ReloadIfLoFi)
230 { 230 {
231 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 231 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
232 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); 232 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html ");
233 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL), nullptr); 233 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL)) ;
234 cachedImage->setStatus(Resource::Pending); 234 cachedImage->setStatus(Resource::Pending);
235 235
236 MockImageResourceClient client(cachedImage); 236 MockImageResourceClient client(cachedImage);
237 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 237 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
238 238
239 // Send the image response. 239 // Send the image response.
240 Vector<unsigned char> jpeg = jpegImage(); 240 Vector<unsigned char> jpeg = jpegImage();
241 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto m, String()); 241 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto m, String());
242 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); 242 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low");
243 243
(...skipping 17 matching lines...) Expand all
261 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 261 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
262 cachedImage->finish(); 262 cachedImage->finish();
263 ASSERT_FALSE(cachedImage->errorOccurred()); 263 ASSERT_FALSE(cachedImage->errorOccurred());
264 ASSERT_TRUE(cachedImage->hasImage()); 264 ASSERT_TRUE(cachedImage->hasImage());
265 ASSERT_FALSE(cachedImage->getImage()->isNull()); 265 ASSERT_FALSE(cachedImage->getImage()->isNull());
266 ASSERT_TRUE(client.notifyFinishedCalled()); 266 ASSERT_TRUE(client.notifyFinishedCalled());
267 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 267 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
268 } 268 }
269 269
270 } // namespace blink 270 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ImageResource.cpp ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698