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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "core/fetch/ImageResource.h" | 31 #include "core/loader/resource/ImageResource.h" |
32 | 32 |
33 #include "core/fetch/FetchInitiatorInfo.h" | 33 #include "core/fetch/FetchInitiatorInfo.h" |
34 #include "core/fetch/FetchRequest.h" | 34 #include "core/fetch/FetchRequest.h" |
35 #include "core/fetch/MemoryCache.h" | 35 #include "core/fetch/MemoryCache.h" |
36 #include "core/fetch/MockImageResourceClient.h" | |
37 #include "core/fetch/MockResourceClient.h" | 36 #include "core/fetch/MockResourceClient.h" |
38 #include "core/fetch/ResourceFetcher.h" | 37 #include "core/fetch/ResourceFetcher.h" |
39 #include "core/fetch/ResourceLoader.h" | 38 #include "core/fetch/ResourceLoader.h" |
40 #include "core/fetch/UniqueIdentifier.h" | 39 #include "core/fetch/UniqueIdentifier.h" |
| 40 #include "core/loader/resource/MockImageResourceClient.h" |
41 #include "platform/SharedBuffer.h" | 41 #include "platform/SharedBuffer.h" |
42 #include "platform/exported/WrappedResourceResponse.h" | 42 #include "platform/exported/WrappedResourceResponse.h" |
43 #include "platform/graphics/BitmapImage.h" | 43 #include "platform/graphics/BitmapImage.h" |
44 #include "platform/graphics/Image.h" | 44 #include "platform/graphics/Image.h" |
45 #include "platform/scheduler/test/fake_web_task_runner.h" | 45 #include "platform/scheduler/test/fake_web_task_runner.h" |
46 #include "platform/testing/TestingPlatformSupport.h" | 46 #include "platform/testing/TestingPlatformSupport.h" |
47 #include "platform/testing/URLTestHelpers.h" | 47 #include "platform/testing/URLTestHelpers.h" |
48 #include "platform/testing/UnitTestHelpers.h" | 48 #include "platform/testing/UnitTestHelpers.h" |
49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
50 #include "public/platform/WebCachePolicy.h" | 50 #include "public/platform/WebCachePolicy.h" |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 ImageResource* image = ImageResource::fetch( | 869 ImageResource* image = ImageResource::fetch( |
870 request, | 870 request, |
871 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 871 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
872 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 872 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
873 request.placeholderImageRequestType()); | 873 request.placeholderImageRequestType()); |
874 EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range")); | 874 EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range")); |
875 EXPECT_FALSE(image->isPlaceholder()); | 875 EXPECT_FALSE(image->isPlaceholder()); |
876 Persistent<MockImageResourceClient> client = | 876 Persistent<MockImageResourceClient> client = |
877 new MockImageResourceClient(image); | 877 new MockImageResourceClient(image); |
878 | 878 |
879 image->loader()->didReceiveResponse( | 879 image->loader()->didReceiveResponse(WrappedResourceResponse(ResourceResponse( |
880 WrappedResourceResponse(ResourceResponse( | 880 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); |
881 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); | |
882 image->loader()->didReceiveData(reinterpret_cast<const char*>(kJpegImage), | 881 image->loader()->didReceiveData(reinterpret_cast<const char*>(kJpegImage), |
883 sizeof(kJpegImage)); | 882 sizeof(kJpegImage)); |
884 image->loader()->didFinishLoading(0.0, sizeof(kJpegImage), | 883 image->loader()->didFinishLoading(0.0, sizeof(kJpegImage), |
885 sizeof(kJpegImage)); | 884 sizeof(kJpegImage)); |
886 | 885 |
887 EXPECT_EQ(Resource::Cached, image->getStatus()); | 886 EXPECT_EQ(Resource::Cached, image->getStatus()); |
888 EXPECT_EQ(sizeof(kJpegImage), image->encodedSize()); | 887 EXPECT_EQ(sizeof(kJpegImage), image->encodedSize()); |
889 EXPECT_FALSE(image->isPlaceholder()); | 888 EXPECT_FALSE(image->isPlaceholder()); |
890 EXPECT_LT(0, client->imageChangedCount()); | 889 EXPECT_LT(0, client->imageChangedCount()); |
891 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); | 890 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 1009 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
1011 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 1010 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
1012 request.placeholderImageRequestType()); | 1011 request.placeholderImageRequestType()); |
1013 EXPECT_EQ("bytes=0-2047", image->resourceRequest().httpHeaderField("range")); | 1012 EXPECT_EQ("bytes=0-2047", image->resourceRequest().httpHeaderField("range")); |
1014 EXPECT_TRUE(image->isPlaceholder()); | 1013 EXPECT_TRUE(image->isPlaceholder()); |
1015 Persistent<MockImageResourceClient> client = | 1014 Persistent<MockImageResourceClient> client = |
1016 new MockImageResourceClient(image); | 1015 new MockImageResourceClient(image); |
1017 | 1016 |
1018 const char kBadData[] = "notanimageresponse"; | 1017 const char kBadData[] = "notanimageresponse"; |
1019 | 1018 |
1020 image->loader()->didReceiveResponse( | 1019 image->loader()->didReceiveResponse(WrappedResourceResponse(ResourceResponse( |
1021 WrappedResourceResponse(ResourceResponse( | 1020 testURL, "image/jpeg", sizeof(kBadData), nullAtom, String()))); |
1022 testURL, "image/jpeg", sizeof(kBadData), nullAtom, String()))); | |
1023 image->loader()->didReceiveData(kBadData, sizeof(kBadData)); | 1021 image->loader()->didReceiveData(kBadData, sizeof(kBadData)); |
1024 | 1022 |
1025 // The dimensions could not be extracted, so the full original image should be | 1023 // The dimensions could not be extracted, so the full original image should be |
1026 // loading. | 1024 // loading. |
1027 EXPECT_EQ(Resource::Pending, image->getStatus()); | 1025 EXPECT_EQ(Resource::Pending, image->getStatus()); |
1028 EXPECT_FALSE(image->isPlaceholder()); | 1026 EXPECT_FALSE(image->isPlaceholder()); |
1029 EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range")); | 1027 EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range")); |
1030 EXPECT_EQ(static_cast<int>(WebCachePolicy::BypassingCache), | 1028 EXPECT_EQ(static_cast<int>(WebCachePolicy::BypassingCache), |
1031 static_cast<int>(image->resourceRequest().getCachePolicy())); | 1029 static_cast<int>(image->resourceRequest().getCachePolicy())); |
1032 EXPECT_FALSE(client->notifyFinishedCalled()); | 1030 EXPECT_FALSE(client->notifyFinishedCalled()); |
1033 EXPECT_EQ(0, client->imageNotifyFinishedCount()); | 1031 EXPECT_EQ(0, client->imageNotifyFinishedCount()); |
1034 | 1032 |
1035 image->loader()->didReceiveResponse( | 1033 image->loader()->didReceiveResponse(WrappedResourceResponse(ResourceResponse( |
1036 WrappedResourceResponse(ResourceResponse( | 1034 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); |
1037 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); | |
1038 image->loader()->didReceiveData(reinterpret_cast<const char*>(kJpegImage), | 1035 image->loader()->didReceiveData(reinterpret_cast<const char*>(kJpegImage), |
1039 sizeof(kJpegImage)); | 1036 sizeof(kJpegImage)); |
1040 image->loader()->didFinishLoading(0.0, sizeof(kJpegImage), | 1037 image->loader()->didFinishLoading(0.0, sizeof(kJpegImage), |
1041 sizeof(kJpegImage)); | 1038 sizeof(kJpegImage)); |
1042 | 1039 |
1043 EXPECT_EQ(Resource::Cached, image->getStatus()); | 1040 EXPECT_EQ(Resource::Cached, image->getStatus()); |
1044 EXPECT_EQ(sizeof(kJpegImage), image->encodedSize()); | 1041 EXPECT_EQ(sizeof(kJpegImage), image->encodedSize()); |
1045 EXPECT_FALSE(image->isPlaceholder()); | 1042 EXPECT_FALSE(image->isPlaceholder()); |
1046 EXPECT_LT(0, client->imageChangedCount()); | 1043 EXPECT_LT(0, client->imageChangedCount()); |
1047 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); | 1044 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 EXPECT_TRUE(client->notifyFinishedCalled()); | 1205 EXPECT_TRUE(client->notifyFinishedCalled()); |
1209 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); | 1206 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); |
1210 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); | 1207 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); |
1211 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); | 1208 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); |
1212 | 1209 |
1213 WTF::setTimeFunctionsForTesting(nullptr); | 1210 WTF::setTimeFunctionsForTesting(nullptr); |
1214 } | 1211 } |
1215 | 1212 |
1216 } // namespace | 1213 } // namespace |
1217 } // namespace blink | 1214 } // namespace blink |
OLD | NEW |