| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 // Emulate starting a real load, but don't expect any "real" | 233 // Emulate starting a real load, but don't expect any "real" |
| 234 // WebURLLoaderClient callbacks. | 234 // WebURLLoaderClient callbacks. |
| 235 ImageResource* imageResource = | 235 ImageResource* imageResource = |
| 236 ImageResource::create(ResourceRequest(testURL)); | 236 ImageResource::create(ResourceRequest(testURL)); |
| 237 imageResource->setIdentifier(createUniqueIdentifier()); | 237 imageResource->setIdentifier(createUniqueIdentifier()); |
| 238 fetcher->startLoad(imageResource); | 238 fetcher->startLoad(imageResource); |
| 239 | 239 |
| 240 std::unique_ptr<MockImageResourceObserver> observer = | 240 std::unique_ptr<MockImageResourceObserver> observer = |
| 241 MockImageResourceObserver::create(imageResource->getContent()); | 241 MockImageResourceObserver::create(imageResource->getContent()); |
| 242 EXPECT_EQ(Resource::Pending, imageResource->getStatus()); | 242 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 243 | 243 |
| 244 // Send the multipart response. No image or data buffer is created. Note that | 244 // Send the multipart response. No image or data buffer is created. Note that |
| 245 // the response must be routed through ResourceLoader to ensure the load is | 245 // the response must be routed through ResourceLoader to ensure the load is |
| 246 // flagged as multipart. | 246 // flagged as multipart. |
| 247 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, | 247 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, |
| 248 nullAtom, String()); | 248 nullAtom, String()); |
| 249 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); | 249 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); |
| 250 imageResource->loader()->didReceiveResponse( | 250 imageResource->loader()->didReceiveResponse( |
| 251 WrappedResourceResponse(multipartResponse), nullptr); | 251 WrappedResourceResponse(multipartResponse), nullptr); |
| 252 EXPECT_FALSE(imageResource->resourceBuffer()); | 252 EXPECT_FALSE(imageResource->resourceBuffer()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 // Emulate starting a real load. | 315 // Emulate starting a real load. |
| 316 ImageResource* imageResource = | 316 ImageResource* imageResource = |
| 317 ImageResource::create(ResourceRequest(testURL)); | 317 ImageResource::create(ResourceRequest(testURL)); |
| 318 imageResource->setIdentifier(createUniqueIdentifier()); | 318 imageResource->setIdentifier(createUniqueIdentifier()); |
| 319 | 319 |
| 320 fetcher->startLoad(imageResource); | 320 fetcher->startLoad(imageResource); |
| 321 memoryCache()->add(imageResource); | 321 memoryCache()->add(imageResource); |
| 322 | 322 |
| 323 std::unique_ptr<MockImageResourceObserver> observer = | 323 std::unique_ptr<MockImageResourceObserver> observer = |
| 324 MockImageResourceObserver::create(imageResource->getContent()); | 324 MockImageResourceObserver::create(imageResource->getContent()); |
| 325 EXPECT_EQ(Resource::Pending, imageResource->getStatus()); | 325 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 326 | 326 |
| 327 // The load should still be alive, but a timer should be started to cancel the | 327 // The load should still be alive, but a timer should be started to cancel the |
| 328 // load inside removeClient(). | 328 // load inside removeClient(). |
| 329 observer->removeAsObserver(); | 329 observer->removeAsObserver(); |
| 330 EXPECT_EQ(Resource::Pending, imageResource->getStatus()); | 330 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 331 EXPECT_TRUE(memoryCache()->resourceForURL(testURL)); | 331 EXPECT_TRUE(memoryCache()->resourceForURL(testURL)); |
| 332 | 332 |
| 333 // Trigger the cancel timer, ensure the load was cancelled and the resource | 333 // Trigger the cancel timer, ensure the load was cancelled and the resource |
| 334 // was evicted from the cache. | 334 // was evicted from the cache. |
| 335 blink::testing::runPendingTasks(); | 335 blink::testing::runPendingTasks(); |
| 336 EXPECT_EQ(Resource::LoadError, imageResource->getStatus()); | 336 EXPECT_EQ(ResourceStatus::LoadError, imageResource->getStatus()); |
| 337 EXPECT_FALSE(memoryCache()->resourceForURL(testURL)); | 337 EXPECT_FALSE(memoryCache()->resourceForURL(testURL)); |
| 338 } | 338 } |
| 339 | 339 |
| 340 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) { | 340 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) { |
| 341 ImageResource* imageResource = ImageResource::create(ResourceRequest()); | 341 ImageResource* imageResource = ImageResource::create(ResourceRequest()); |
| 342 imageResource->setStatus(Resource::Pending); | 342 imageResource->setStatus(ResourceStatus::Pending); |
| 343 | 343 |
| 344 std::unique_ptr<MockImageResourceObserver> observer = | 344 std::unique_ptr<MockImageResourceObserver> observer = |
| 345 MockImageResourceObserver::create(imageResource->getContent()); | 345 MockImageResourceObserver::create(imageResource->getContent()); |
| 346 | 346 |
| 347 // Send the image response. | 347 // Send the image response. |
| 348 imageResource->responseReceived( | 348 imageResource->responseReceived( |
| 349 ResourceResponse(KURL(), "multipart/x-mixed-replace", 0, nullAtom, | 349 ResourceResponse(KURL(), "multipart/x-mixed-replace", 0, nullAtom, |
| 350 String()), | 350 String()), |
| 351 nullptr); | 351 nullptr); |
| 352 | 352 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 376 observer->removeAsObserver(); | 376 observer->removeAsObserver(); |
| 377 imageResource->prune(); | 377 imageResource->prune(); |
| 378 EXPECT_FALSE(imageResource->isAlive()); | 378 EXPECT_FALSE(imageResource->isAlive()); |
| 379 EXPECT_TRUE(imageResource->getContent()->hasImage()); | 379 EXPECT_TRUE(imageResource->getContent()->hasImage()); |
| 380 // TODO(hajimehoshi): Should check imageResource doesn't have decoded image | 380 // TODO(hajimehoshi): Should check imageResource doesn't have decoded image |
| 381 // data. | 381 // data. |
| 382 } | 382 } |
| 383 | 383 |
| 384 TEST(ImageResourceTest, UpdateBitmapImages) { | 384 TEST(ImageResourceTest, UpdateBitmapImages) { |
| 385 ImageResource* imageResource = ImageResource::create(ResourceRequest()); | 385 ImageResource* imageResource = ImageResource::create(ResourceRequest()); |
| 386 imageResource->setStatus(Resource::Pending); | 386 imageResource->setStatus(ResourceStatus::Pending); |
| 387 | 387 |
| 388 std::unique_ptr<MockImageResourceObserver> observer = | 388 std::unique_ptr<MockImageResourceObserver> observer = |
| 389 MockImageResourceObserver::create(imageResource->getContent()); | 389 MockImageResourceObserver::create(imageResource->getContent()); |
| 390 | 390 |
| 391 // Send the image response. | 391 // Send the image response. |
| 392 imageResource->responseReceived( | 392 imageResource->responseReceived( |
| 393 ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom, | 393 ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom, |
| 394 String()), | 394 String()), |
| 395 nullptr); | 395 nullptr); |
| 396 imageResource->appendData(reinterpret_cast<const char*>(kJpegImage), | 396 imageResource->appendData(reinterpret_cast<const char*>(kJpegImage), |
| 397 sizeof(kJpegImage)); | 397 sizeof(kJpegImage)); |
| 398 imageResource->finish(); | 398 imageResource->finish(); |
| 399 EXPECT_FALSE(imageResource->errorOccurred()); | 399 EXPECT_FALSE(imageResource->errorOccurred()); |
| 400 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 400 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 401 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | 401 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 402 EXPECT_EQ(2, observer->imageChangedCount()); | 402 EXPECT_EQ(2, observer->imageChangedCount()); |
| 403 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 403 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 404 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 404 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 405 } | 405 } |
| 406 | 406 |
| 407 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { | 407 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { |
| 408 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 408 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 409 ScopedRegisteredURL scopedRegisteredURL(testURL); | 409 ScopedRegisteredURL scopedRegisteredURL(testURL); |
| 410 ResourceRequest request = ResourceRequest(testURL); | 410 ResourceRequest request = ResourceRequest(testURL); |
| 411 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | 411 request.setPreviewsState(WebURLRequest::ServerLoFiOn); |
| 412 ImageResource* imageResource = ImageResource::create(request); | 412 ImageResource* imageResource = ImageResource::create(request); |
| 413 imageResource->setStatus(Resource::Pending); | 413 imageResource->setStatus(ResourceStatus::Pending); |
| 414 | 414 |
| 415 std::unique_ptr<MockImageResourceObserver> observer = | 415 std::unique_ptr<MockImageResourceObserver> observer = |
| 416 MockImageResourceObserver::create(imageResource->getContent()); | 416 MockImageResourceObserver::create(imageResource->getContent()); |
| 417 ResourceFetcher* fetcher = | 417 ResourceFetcher* fetcher = |
| 418 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 418 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 419 | 419 |
| 420 // Send the image response. | 420 // Send the image response. |
| 421 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), | 421 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), |
| 422 nullAtom, String()); | 422 nullAtom, String()); |
| 423 resourceResponse.addHTTPHeaderField("chrome-proxy-content-transform", | 423 resourceResponse.addHTTPHeaderField("chrome-proxy-content-transform", |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 sizeof(kJpegImage))); | 562 sizeof(kJpegImage))); |
| 563 imageResource->loader()->didReceiveResponse( | 563 imageResource->loader()->didReceiveResponse( |
| 564 WrappedResourceResponse(response)); | 564 WrappedResourceResponse(response)); |
| 565 imageResource->loader()->didReceiveData( | 565 imageResource->loader()->didReceiveData( |
| 566 reinterpret_cast<const char*>(kJpegImage), | 566 reinterpret_cast<const char*>(kJpegImage), |
| 567 kJpegImageSubrangeWithDimensionsLength); | 567 kJpegImageSubrangeWithDimensionsLength); |
| 568 imageResource->loader()->didFinishLoading( | 568 imageResource->loader()->didFinishLoading( |
| 569 0.0, kJpegImageSubrangeWithDimensionsLength, | 569 0.0, kJpegImageSubrangeWithDimensionsLength, |
| 570 kJpegImageSubrangeWithDimensionsLength); | 570 kJpegImageSubrangeWithDimensionsLength); |
| 571 | 571 |
| 572 EXPECT_EQ(Resource::Cached, imageResource->getStatus()); | 572 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus()); |
| 573 EXPECT_TRUE(imageResource->isPlaceholder()); | 573 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 574 | 574 |
| 575 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, | 575 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, |
| 576 Resource::kReloadAlways); | 576 Resource::kReloadAlways); |
| 577 | 577 |
| 578 EXPECT_EQ(Resource::Pending, imageResource->getStatus()); | 578 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 579 EXPECT_FALSE(imageResource->isPlaceholder()); | 579 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 580 EXPECT_EQ(nullAtom, | 580 EXPECT_EQ(nullAtom, |
| 581 imageResource->resourceRequest().httpHeaderField("range")); | 581 imageResource->resourceRequest().httpHeaderField("range")); |
| 582 EXPECT_EQ( | 582 EXPECT_EQ( |
| 583 static_cast<int>(WebCachePolicy::BypassingCache), | 583 static_cast<int>(WebCachePolicy::BypassingCache), |
| 584 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 584 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 585 | 585 |
| 586 imageResource->loader()->cancel(); | 586 imageResource->loader()->cancel(); |
| 587 } | 587 } |
| 588 | 588 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 ResourceFetcher* fetcher = | 852 ResourceFetcher* fetcher = |
| 853 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 853 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 854 FetchRequest request(testURL, FetchInitiatorInfo()); | 854 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 855 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 855 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
| 856 | 856 |
| 857 imageResource->loader()->didReceiveResponse( | 857 imageResource->loader()->didReceiveResponse( |
| 858 WrappedResourceResponse( | 858 WrappedResourceResponse( |
| 859 ResourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), | 859 ResourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), |
| 860 nullptr); | 860 nullptr); |
| 861 imageResource->loader()->didReceiveData("notactuallyanimage", 18); | 861 imageResource->loader()->didReceiveData("notactuallyanimage", 18); |
| 862 EXPECT_EQ(Resource::DecodeError, imageResource->getStatus()); | 862 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); |
| 863 EXPECT_FALSE(imageResource->isLoading()); | 863 EXPECT_FALSE(imageResource->isLoading()); |
| 864 } | 864 } |
| 865 | 865 |
| 866 TEST(ImageResourceTest, FetchDisallowPlaceholder) { | 866 TEST(ImageResourceTest, FetchDisallowPlaceholder) { |
| 867 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 867 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 868 ScopedRegisteredURL scopedRegisteredURL(testURL); | 868 ScopedRegisteredURL scopedRegisteredURL(testURL); |
| 869 | 869 |
| 870 FetchRequest request(testURL, FetchInitiatorInfo()); | 870 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 871 ImageResource* imageResource = ImageResource::fetch( | 871 ImageResource* imageResource = ImageResource::fetch( |
| 872 request, | 872 request, |
| 873 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 873 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
| 874 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 874 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 875 request.placeholderImageRequestType()); | 875 request.placeholderImageRequestType()); |
| 876 EXPECT_EQ(nullAtom, | 876 EXPECT_EQ(nullAtom, |
| 877 imageResource->resourceRequest().httpHeaderField("range")); | 877 imageResource->resourceRequest().httpHeaderField("range")); |
| 878 EXPECT_FALSE(imageResource->isPlaceholder()); | 878 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 879 std::unique_ptr<MockImageResourceObserver> observer = | 879 std::unique_ptr<MockImageResourceObserver> observer = |
| 880 MockImageResourceObserver::create(imageResource->getContent()); | 880 MockImageResourceObserver::create(imageResource->getContent()); |
| 881 | 881 |
| 882 imageResource->loader()->didReceiveResponse( | 882 imageResource->loader()->didReceiveResponse( |
| 883 WrappedResourceResponse(ResourceResponse( | 883 WrappedResourceResponse(ResourceResponse( |
| 884 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); | 884 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); |
| 885 imageResource->loader()->didReceiveData( | 885 imageResource->loader()->didReceiveData( |
| 886 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); | 886 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); |
| 887 imageResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage), | 887 imageResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage), |
| 888 sizeof(kJpegImage)); | 888 sizeof(kJpegImage)); |
| 889 | 889 |
| 890 EXPECT_EQ(Resource::Cached, imageResource->getStatus()); | 890 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus()); |
| 891 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize()); | 891 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize()); |
| 892 EXPECT_FALSE(imageResource->isPlaceholder()); | 892 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 893 EXPECT_LT(0, observer->imageChangedCount()); | 893 EXPECT_LT(0, observer->imageChangedCount()); |
| 894 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); | 894 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); |
| 895 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 895 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 896 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | 896 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
| 897 | 897 |
| 898 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 898 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 899 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 899 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| 900 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 900 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 sizeof(kJpegImage))); | 982 sizeof(kJpegImage))); |
| 983 imageResource->loader()->didReceiveResponse( | 983 imageResource->loader()->didReceiveResponse( |
| 984 WrappedResourceResponse(response)); | 984 WrappedResourceResponse(response)); |
| 985 imageResource->loader()->didReceiveData( | 985 imageResource->loader()->didReceiveData( |
| 986 reinterpret_cast<const char*>(kJpegImage), | 986 reinterpret_cast<const char*>(kJpegImage), |
| 987 kJpegImageSubrangeWithDimensionsLength); | 987 kJpegImageSubrangeWithDimensionsLength); |
| 988 imageResource->loader()->didFinishLoading( | 988 imageResource->loader()->didFinishLoading( |
| 989 0.0, kJpegImageSubrangeWithDimensionsLength, | 989 0.0, kJpegImageSubrangeWithDimensionsLength, |
| 990 kJpegImageSubrangeWithDimensionsLength); | 990 kJpegImageSubrangeWithDimensionsLength); |
| 991 | 991 |
| 992 EXPECT_EQ(Resource::Cached, imageResource->getStatus()); | 992 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus()); |
| 993 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, | 993 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, |
| 994 imageResource->encodedSize()); | 994 imageResource->encodedSize()); |
| 995 EXPECT_TRUE(imageResource->isPlaceholder()); | 995 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 996 EXPECT_LT(0, observer->imageChangedCount()); | 996 EXPECT_LT(0, observer->imageChangedCount()); |
| 997 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); | 997 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); |
| 998 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 998 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 999 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | 999 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
| 1000 | 1000 |
| 1001 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 1001 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 1002 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 1002 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1024 | 1024 |
| 1025 const char kBadData[] = "notanimageresponse"; | 1025 const char kBadData[] = "notanimageresponse"; |
| 1026 | 1026 |
| 1027 imageResource->loader()->didReceiveResponse( | 1027 imageResource->loader()->didReceiveResponse( |
| 1028 WrappedResourceResponse(ResourceResponse( | 1028 WrappedResourceResponse(ResourceResponse( |
| 1029 testURL, "image/jpeg", sizeof(kBadData), nullAtom, String()))); | 1029 testURL, "image/jpeg", sizeof(kBadData), nullAtom, String()))); |
| 1030 imageResource->loader()->didReceiveData(kBadData, sizeof(kBadData)); | 1030 imageResource->loader()->didReceiveData(kBadData, sizeof(kBadData)); |
| 1031 | 1031 |
| 1032 // The dimensions could not be extracted, so the full original image should be | 1032 // The dimensions could not be extracted, so the full original image should be |
| 1033 // loading. | 1033 // loading. |
| 1034 EXPECT_EQ(Resource::Pending, imageResource->getStatus()); | 1034 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 1035 EXPECT_FALSE(imageResource->isPlaceholder()); | 1035 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1036 EXPECT_EQ(nullAtom, | 1036 EXPECT_EQ(nullAtom, |
| 1037 imageResource->resourceRequest().httpHeaderField("range")); | 1037 imageResource->resourceRequest().httpHeaderField("range")); |
| 1038 EXPECT_EQ( | 1038 EXPECT_EQ( |
| 1039 static_cast<int>(WebCachePolicy::BypassingCache), | 1039 static_cast<int>(WebCachePolicy::BypassingCache), |
| 1040 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1040 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 1041 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); | 1041 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 1042 | 1042 |
| 1043 imageResource->loader()->didReceiveResponse( | 1043 imageResource->loader()->didReceiveResponse( |
| 1044 WrappedResourceResponse(ResourceResponse( | 1044 WrappedResourceResponse(ResourceResponse( |
| 1045 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); | 1045 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); |
| 1046 imageResource->loader()->didReceiveData( | 1046 imageResource->loader()->didReceiveData( |
| 1047 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); | 1047 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); |
| 1048 imageResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage), | 1048 imageResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage), |
| 1049 sizeof(kJpegImage)); | 1049 sizeof(kJpegImage)); |
| 1050 | 1050 |
| 1051 EXPECT_EQ(Resource::Cached, imageResource->getStatus()); | 1051 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus()); |
| 1052 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize()); | 1052 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize()); |
| 1053 EXPECT_FALSE(imageResource->isPlaceholder()); | 1053 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1054 EXPECT_LT(0, observer->imageChangedCount()); | 1054 EXPECT_LT(0, observer->imageChangedCount()); |
| 1055 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); | 1055 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); |
| 1056 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1056 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1057 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | 1057 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
| 1058 | 1058 |
| 1059 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 1059 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 1060 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 1060 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| 1061 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 1061 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1072 placeholderRequest.setAllowImagePlaceholder(); | 1072 placeholderRequest.setAllowImagePlaceholder(); |
| 1073 ImageResource* imageResource = | 1073 ImageResource* imageResource = |
| 1074 ImageResource::fetch(placeholderRequest, fetcher); | 1074 ImageResource::fetch(placeholderRequest, fetcher); |
| 1075 std::unique_ptr<MockImageResourceObserver> observer = | 1075 std::unique_ptr<MockImageResourceObserver> observer = |
| 1076 MockImageResourceObserver::create(imageResource->getContent()); | 1076 MockImageResourceObserver::create(imageResource->getContent()); |
| 1077 | 1077 |
| 1078 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); | 1078 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); |
| 1079 ImageResource* secondImageResource = | 1079 ImageResource* secondImageResource = |
| 1080 ImageResource::fetch(nonPlaceholderRequest, fetcher); | 1080 ImageResource::fetch(nonPlaceholderRequest, fetcher); |
| 1081 EXPECT_EQ(imageResource, secondImageResource); | 1081 EXPECT_EQ(imageResource, secondImageResource); |
| 1082 EXPECT_EQ(Resource::Pending, imageResource->getStatus()); | 1082 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 1083 EXPECT_FALSE(imageResource->isPlaceholder()); | 1083 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1084 EXPECT_EQ(nullAtom, | 1084 EXPECT_EQ(nullAtom, |
| 1085 imageResource->resourceRequest().httpHeaderField("range")); | 1085 imageResource->resourceRequest().httpHeaderField("range")); |
| 1086 EXPECT_EQ( | 1086 EXPECT_EQ( |
| 1087 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), | 1087 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), |
| 1088 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1088 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 1089 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); | 1089 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 1090 | 1090 |
| 1091 imageResource->loader()->cancel(); | 1091 imageResource->loader()->cancel(); |
| 1092 } | 1092 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1114 sizeof(kJpegImage))); | 1114 sizeof(kJpegImage))); |
| 1115 imageResource->loader()->didReceiveResponse( | 1115 imageResource->loader()->didReceiveResponse( |
| 1116 WrappedResourceResponse(response)); | 1116 WrappedResourceResponse(response)); |
| 1117 imageResource->loader()->didReceiveData( | 1117 imageResource->loader()->didReceiveData( |
| 1118 reinterpret_cast<const char*>(kJpegImage), | 1118 reinterpret_cast<const char*>(kJpegImage), |
| 1119 kJpegImageSubrangeWithDimensionsLength); | 1119 kJpegImageSubrangeWithDimensionsLength); |
| 1120 imageResource->loader()->didFinishLoading( | 1120 imageResource->loader()->didFinishLoading( |
| 1121 0.0, kJpegImageSubrangeWithDimensionsLength, | 1121 0.0, kJpegImageSubrangeWithDimensionsLength, |
| 1122 kJpegImageSubrangeWithDimensionsLength); | 1122 kJpegImageSubrangeWithDimensionsLength); |
| 1123 | 1123 |
| 1124 EXPECT_EQ(Resource::Cached, imageResource->getStatus()); | 1124 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus()); |
| 1125 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, | 1125 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, |
| 1126 imageResource->encodedSize()); | 1126 imageResource->encodedSize()); |
| 1127 EXPECT_TRUE(imageResource->isPlaceholder()); | 1127 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 1128 EXPECT_LT(0, observer->imageChangedCount()); | 1128 EXPECT_LT(0, observer->imageChangedCount()); |
| 1129 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1129 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1130 | 1130 |
| 1131 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); | 1131 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); |
| 1132 ImageResource* secondImageResource = | 1132 ImageResource* secondImageResource = |
| 1133 ImageResource::fetch(nonPlaceholderRequest, fetcher); | 1133 ImageResource::fetch(nonPlaceholderRequest, fetcher); |
| 1134 EXPECT_EQ(imageResource, secondImageResource); | 1134 EXPECT_EQ(imageResource, secondImageResource); |
| 1135 EXPECT_EQ(Resource::Pending, imageResource->getStatus()); | 1135 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 1136 EXPECT_FALSE(imageResource->isPlaceholder()); | 1136 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1137 EXPECT_EQ(nullAtom, | 1137 EXPECT_EQ(nullAtom, |
| 1138 imageResource->resourceRequest().httpHeaderField("range")); | 1138 imageResource->resourceRequest().httpHeaderField("range")); |
| 1139 EXPECT_EQ( | 1139 EXPECT_EQ( |
| 1140 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), | 1140 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), |
| 1141 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1141 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 1142 | 1142 |
| 1143 imageResource->loader()->cancel(); | 1143 imageResource->loader()->cancel(); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 TEST(ImageResourceTest, PeriodicFlushTest) { | 1146 TEST(ImageResourceTest, PeriodicFlushTest) { |
| 1147 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> | 1147 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 1148 platform; | 1148 platform; |
| 1149 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1149 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 1150 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", | 1150 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", |
| 1151 "text/html"); | 1151 "text/html"); |
| 1152 ResourceRequest request = ResourceRequest(testURL); | 1152 ResourceRequest request = ResourceRequest(testURL); |
| 1153 ImageResource* imageResource = ImageResource::create(request); | 1153 ImageResource* imageResource = ImageResource::create(request); |
| 1154 imageResource->setStatus(Resource::Pending); | 1154 imageResource->setStatus(ResourceStatus::Pending); |
| 1155 | 1155 |
| 1156 std::unique_ptr<MockImageResourceObserver> observer = | 1156 std::unique_ptr<MockImageResourceObserver> observer = |
| 1157 MockImageResourceObserver::create(imageResource->getContent()); | 1157 MockImageResourceObserver::create(imageResource->getContent()); |
| 1158 | 1158 |
| 1159 // Send the image response. | 1159 // Send the image response. |
| 1160 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), | 1160 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), |
| 1161 nullAtom, String()); | 1161 nullAtom, String()); |
| 1162 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); | 1162 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
| 1163 | 1163 |
| 1164 imageResource->responseReceived(resourceResponse, nullptr); | 1164 imageResource->responseReceived(resourceResponse, nullptr); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1225 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1226 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1226 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1227 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1227 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 1228 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1228 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 1229 | 1229 |
| 1230 WTF::setTimeFunctionsForTesting(nullptr); | 1230 WTF::setTimeFunctionsForTesting(nullptr); |
| 1231 } | 1231 } |
| 1232 | 1232 |
| 1233 } // namespace | 1233 } // namespace |
| 1234 } // namespace blink | 1234 } // namespace blink |
| OLD | NEW |