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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return jpeg; 81 return jpeg;
82 } 82 }
83 83
84 TEST(ImageResourceTest, MultipartImage) 84 TEST(ImageResourceTest, MultipartImage)
85 { 85 {
86 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 86 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
87 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 87 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
88 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); 88 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html ");
89 89
90 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks. 90 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks.
91 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(testURL), nullptr); 91 RawPtr<ImageResource> cachedImage = ImageResource::create(ResourceRequest(te stURL), nullptr);
92 cachedImage->setIdentifier(createUniqueIdentifier()); 92 cachedImage->setIdentifier(createUniqueIdentifier());
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->status()); 97 EXPECT_EQ(Resource::Pending, cachedImage->status());
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.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 TEST(ImageResourceTest, CancelOnDetach) 139 TEST(ImageResourceTest, CancelOnDetach)
140 { 140 {
141 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 141 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
142 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); 142 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html ");
143 143
144 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 144 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
145 145
146 // Emulate starting a real load. 146 // Emulate starting a real load.
147 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(testURL), nullptr); 147 RawPtr<ImageResource> cachedImage = ImageResource::create(ResourceRequest(te stURL), nullptr);
148 cachedImage->setIdentifier(createUniqueIdentifier()); 148 cachedImage->setIdentifier(createUniqueIdentifier());
149 149
150 cachedImage->load(fetcher, ResourceLoaderOptions()); 150 cachedImage->load(fetcher, ResourceLoaderOptions());
151 memoryCache()->add(cachedImage.get()); 151 memoryCache()->add(cachedImage.get());
152 152
153 MockImageResourceClient client(cachedImage); 153 MockImageResourceClient client(cachedImage);
154 EXPECT_EQ(Resource::Pending, cachedImage->status()); 154 EXPECT_EQ(Resource::Pending, cachedImage->status());
155 155
156 // The load should still be alive, but a timer should be started to cancel t he load inside removeClient(). 156 // The load should still be alive, but a timer should be started to cancel t he load inside removeClient().
157 client.removeAsClient(); 157 client.removeAsClient();
158 EXPECT_EQ(Resource::Pending, cachedImage->status()); 158 EXPECT_EQ(Resource::Pending, cachedImage->status());
159 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); 159 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL));
160 160
161 // Trigger the cancel timer, ensure the load was cancelled and the resource was evicted from the cache. 161 // Trigger the cancel timer, ensure the load was cancelled and the resource was evicted from the cache.
162 blink::testing::runPendingTasks(); 162 blink::testing::runPendingTasks();
163 EXPECT_EQ(Resource::LoadError, cachedImage->status()); 163 EXPECT_EQ(Resource::LoadError, cachedImage->status());
164 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); 164 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL));
165 165
166 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); 166 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL);
167 } 167 }
168 168
169 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) 169 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
170 { 170 {
171 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(), nullptr); 171 RawPtr<ImageResource> cachedImage = ImageResource::create(ResourceRequest(), nullptr);
172 cachedImage->setLoading(true); 172 cachedImage->setLoading(true);
173 173
174 MockImageResourceClient client(cachedImage); 174 MockImageResourceClient client(cachedImage);
175 175
176 // Send the image response. 176 // Send the image response.
177 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re place", 0, nullAtom, String()), nullptr); 177 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re place", 0, nullAtom, String()), nullptr);
178 178
179 Vector<unsigned char> jpeg = jpegImage(); 179 Vector<unsigned char> jpeg = jpegImage();
180 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr); 180 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr);
181 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 181 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
(...skipping 12 matching lines...) Expand all
194 // The ImageResource no longer has clients. The image should be deleted by p rune. 194 // The ImageResource no longer has clients. The image should be deleted by p rune.
195 client.removeAsClient(); 195 client.removeAsClient();
196 cachedImage->prune(); 196 cachedImage->prune();
197 ASSERT_FALSE(cachedImage->hasClients()); 197 ASSERT_FALSE(cachedImage->hasClients());
198 ASSERT_FALSE(cachedImage->hasImage()); 198 ASSERT_FALSE(cachedImage->hasImage());
199 ASSERT_TRUE(cachedImage->image()->isNull()); 199 ASSERT_TRUE(cachedImage->image()->isNull());
200 } 200 }
201 201
202 TEST(ImageResourceTest, UpdateBitmapImages) 202 TEST(ImageResourceTest, UpdateBitmapImages)
203 { 203 {
204 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(), nullptr); 204 RawPtr<ImageResource> cachedImage = ImageResource::create(ResourceRequest(), nullptr);
205 cachedImage->setLoading(true); 205 cachedImage->setLoading(true);
206 206
207 MockImageResourceClient client(cachedImage); 207 MockImageResourceClient client(cachedImage);
208 208
209 // Send the image response. 209 // Send the image response.
210 Vector<unsigned char> jpeg = jpegImage(); 210 Vector<unsigned char> jpeg = jpegImage();
211 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr); 211 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr);
212 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 212 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
213 cachedImage->finish(); 213 cachedImage->finish();
214 ASSERT_FALSE(cachedImage->errorOccurred()); 214 ASSERT_FALSE(cachedImage->errorOccurred());
215 ASSERT_TRUE(cachedImage->hasImage()); 215 ASSERT_TRUE(cachedImage->hasImage());
216 ASSERT_FALSE(cachedImage->image()->isNull()); 216 ASSERT_FALSE(cachedImage->image()->isNull());
217 ASSERT_EQ(client.imageChangedCount(), 2); 217 ASSERT_EQ(client.imageChangedCount(), 2);
218 ASSERT_TRUE(client.notifyFinishedCalled()); 218 ASSERT_TRUE(client.notifyFinishedCalled());
219 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); 219 ASSERT_TRUE(cachedImage->image()->isBitmapImage());
220 } 220 }
221 221
222 TEST(ImageResourceTest, ReloadIfLoFi) 222 TEST(ImageResourceTest, ReloadIfLoFi)
223 { 223 {
224 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 224 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
225 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); 225 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html ");
226 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour ceRequest(testURL), nullptr); 226 RawPtr<ImageResource> cachedImage = ImageResource::create(ResourceRequest(te stURL), nullptr);
227 cachedImage->setLoading(true); 227 cachedImage->setLoading(true);
228 228
229 MockImageResourceClient client(cachedImage); 229 MockImageResourceClient client(cachedImage);
230 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 230 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
231 231
232 // Send the image response. 232 // Send the image response.
233 Vector<unsigned char> jpeg = jpegImage(); 233 Vector<unsigned char> jpeg = jpegImage();
234 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto m, String()); 234 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto m, String());
235 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); 235 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low");
236 236
(...skipping 17 matching lines...) Expand all
254 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 254 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
255 cachedImage->finish(); 255 cachedImage->finish();
256 ASSERT_FALSE(cachedImage->errorOccurred()); 256 ASSERT_FALSE(cachedImage->errorOccurred());
257 ASSERT_TRUE(cachedImage->hasImage()); 257 ASSERT_TRUE(cachedImage->hasImage());
258 ASSERT_FALSE(cachedImage->image()->isNull()); 258 ASSERT_FALSE(cachedImage->image()->isNull());
259 ASSERT_TRUE(client.notifyFinishedCalled()); 259 ASSERT_TRUE(client.notifyFinishedCalled());
260 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); 260 ASSERT_TRUE(cachedImage->image()->isBitmapImage());
261 } 261 }
262 262
263 } // namespace blink 263 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698