OLD | NEW |
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 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 ResourceFetcher* fetcher = createFetcher(); | 1203 ResourceFetcher* fetcher = createFetcher(); |
1204 | 1204 |
1205 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); | 1205 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); |
1206 placeholderRequest.setAllowImagePlaceholder(); | 1206 placeholderRequest.setAllowImagePlaceholder(); |
1207 ImageResource* imageResource = | 1207 ImageResource* imageResource = |
1208 ImageResource::fetch(placeholderRequest, fetcher); | 1208 ImageResource::fetch(placeholderRequest, fetcher); |
1209 std::unique_ptr<MockImageResourceObserver> observer = | 1209 std::unique_ptr<MockImageResourceObserver> observer = |
1210 MockImageResourceObserver::create(imageResource->getContent()); | 1210 MockImageResourceObserver::create(imageResource->getContent()); |
1211 | 1211 |
1212 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); | 1212 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); |
1213 ImageResource* secondImageResource = | 1213 ImageResource* imageResource2 = |
1214 ImageResource::fetch(nonPlaceholderRequest, fetcher); | 1214 ImageResource::fetch(nonPlaceholderRequest, fetcher); |
| 1215 std::unique_ptr<MockImageResourceObserver> observer2 = |
| 1216 MockImageResourceObserver::create(imageResource2->getContent()); |
1215 | 1217 |
1216 EXPECT_EQ(imageResource, secondImageResource); | 1218 ImageResource* imageResource3 = |
| 1219 ImageResource::fetch(nonPlaceholderRequest, fetcher); |
| 1220 std::unique_ptr<MockImageResourceObserver> observer3 = |
| 1221 MockImageResourceObserver::create(imageResource3->getContent()); |
| 1222 |
| 1223 // |imageResource| remains a placeholder, while following non-placeholder |
| 1224 // requests start non-placeholder loading with a separate ImageResource. |
| 1225 ASSERT_NE(imageResource, imageResource2); |
| 1226 ASSERT_NE(imageResource->loader(), imageResource2->loader()); |
| 1227 ASSERT_NE(imageResource->getContent(), imageResource2->getContent()); |
| 1228 ASSERT_EQ(imageResource2, imageResource3); |
| 1229 |
1217 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); | 1230 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 1231 EXPECT_FALSE(observer2->imageNotifyFinishedCalled()); |
| 1232 EXPECT_FALSE(observer3->imageNotifyFinishedCalled()); |
1218 | 1233 |
1219 testThatReloadIsStartedThenServeReload( | 1234 // Checks that |imageResource2| (and |imageResource3|) loads a |
1220 testURL, imageResource, imageResource->getContent(), observer.get(), | 1235 // non-placeholder image. |
1221 WebCachePolicy::UseProtocolCachePolicy); | 1236 testThatIsNotPlaceholderRequestAndServeResponse(testURL, imageResource2, |
| 1237 observer2.get()); |
| 1238 EXPECT_TRUE(observer3->imageNotifyFinishedCalled()); |
| 1239 |
| 1240 // Checks that |imageResource| will loads a placeholder image. |
| 1241 testThatIsPlaceholderRequestAndServeResponse(testURL, imageResource, |
| 1242 observer.get()); |
| 1243 |
| 1244 // |imageResource2| is still a non-placeholder image. |
| 1245 EXPECT_FALSE(imageResource2->shouldShowPlaceholder()); |
| 1246 EXPECT_TRUE(imageResource2->getContent()->getImage()->isBitmapImage()); |
1222 } | 1247 } |
1223 | 1248 |
1224 TEST(ImageResourceTest, | 1249 TEST(ImageResourceTest, |
1225 FetchAllowPlaceholderThenDisallowPlaceholderAfterLoaded) { | 1250 FetchAllowPlaceholderThenDisallowPlaceholderAfterLoaded) { |
1226 KURL testURL(ParsedURLString, kTestURL); | 1251 KURL testURL(ParsedURLString, kTestURL); |
1227 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1252 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
1228 | 1253 |
1229 ResourceFetcher* fetcher = createFetcher(); | 1254 ResourceFetcher* fetcher = createFetcher(); |
1230 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); | 1255 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); |
1231 placeholderRequest.setAllowImagePlaceholder(); | 1256 placeholderRequest.setAllowImagePlaceholder(); |
1232 ImageResource* imageResource = | 1257 ImageResource* imageResource = |
1233 ImageResource::fetch(placeholderRequest, fetcher); | 1258 ImageResource::fetch(placeholderRequest, fetcher); |
1234 std::unique_ptr<MockImageResourceObserver> observer = | 1259 std::unique_ptr<MockImageResourceObserver> observer = |
1235 MockImageResourceObserver::create(imageResource->getContent()); | 1260 MockImageResourceObserver::create(imageResource->getContent()); |
1236 | 1261 |
1237 testThatIsPlaceholderRequestAndServeResponse(testURL, imageResource, | 1262 testThatIsPlaceholderRequestAndServeResponse(testURL, imageResource, |
1238 observer.get()); | 1263 observer.get()); |
1239 | 1264 |
1240 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); | 1265 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); |
1241 ImageResource* secondImageResource = | 1266 ImageResource* imageResource2 = |
1242 ImageResource::fetch(nonPlaceholderRequest, fetcher); | 1267 ImageResource::fetch(nonPlaceholderRequest, fetcher); |
1243 EXPECT_EQ(imageResource, secondImageResource); | 1268 std::unique_ptr<MockImageResourceObserver> observer2 = |
| 1269 MockImageResourceObserver::create(imageResource2->getContent()); |
1244 | 1270 |
1245 testThatReloadIsStartedThenServeReload( | 1271 ImageResource* imageResource3 = |
1246 testURL, imageResource, imageResource->getContent(), observer.get(), | 1272 ImageResource::fetch(nonPlaceholderRequest, fetcher); |
1247 WebCachePolicy::UseProtocolCachePolicy); | 1273 std::unique_ptr<MockImageResourceObserver> observer3 = |
| 1274 MockImageResourceObserver::create(imageResource3->getContent()); |
| 1275 |
| 1276 EXPECT_FALSE(observer2->imageNotifyFinishedCalled()); |
| 1277 EXPECT_FALSE(observer3->imageNotifyFinishedCalled()); |
| 1278 |
| 1279 // |imageResource| remains a placeholder, while following non-placeholder |
| 1280 // requests start non-placeholder loading with a separate ImageResource. |
| 1281 ASSERT_NE(imageResource, imageResource2); |
| 1282 ASSERT_EQ(imageResource2, imageResource3); |
| 1283 |
| 1284 testThatIsNotPlaceholderRequestAndServeResponse(testURL, imageResource2, |
| 1285 observer2.get()); |
| 1286 EXPECT_TRUE(observer3->imageNotifyFinishedCalled()); |
1248 } | 1287 } |
1249 | 1288 |
1250 TEST(ImageResourceTest, FetchAllowPlaceholderFullResponseDecodeSuccess) { | 1289 TEST(ImageResourceTest, FetchAllowPlaceholderFullResponseDecodeSuccess) { |
1251 const struct { | 1290 const struct { |
1252 int statusCode; | 1291 int statusCode; |
1253 AtomicString contentRange; | 1292 AtomicString contentRange; |
1254 } tests[] = { | 1293 } tests[] = { |
1255 {200, nullAtom}, | 1294 {200, nullAtom}, |
1256 {404, nullAtom}, | 1295 {404, nullAtom}, |
1257 {206, buildContentRange(sizeof(kJpegImage), sizeof(kJpegImage))}, | 1296 {206, buildContentRange(sizeof(kJpegImage), sizeof(kJpegImage))}, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1503 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
1465 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1504 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
1466 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1505 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
1467 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1506 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
1468 | 1507 |
1469 WTF::setTimeFunctionsForTesting(nullptr); | 1508 WTF::setTimeFunctionsForTesting(nullptr); |
1470 } | 1509 } |
1471 | 1510 |
1472 } // namespace | 1511 } // namespace |
1473 } // namespace blink | 1512 } // namespace blink |
OLD | NEW |