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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 std::unique_ptr<MockImageResourceObserver> observer = | 856 std::unique_ptr<MockImageResourceObserver> observer = |
857 MockImageResourceObserver::create(imageResource->getContent()); | 857 MockImageResourceObserver::create(imageResource->getContent()); |
858 | 858 |
859 imageResource->loader()->didReceiveResponse( | 859 imageResource->loader()->didReceiveResponse( |
860 WrappedResourceResponse( | 860 WrappedResourceResponse( |
861 ResourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), | 861 ResourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), |
862 nullptr); | 862 nullptr); |
| 863 |
| 864 EXPECT_EQ(0, observer->imageChangedCount()); |
| 865 |
863 imageResource->loader()->didReceiveData("notactuallyanimage", 18); | 866 imageResource->loader()->didReceiveData("notactuallyanimage", 18); |
| 867 |
864 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); | 868 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); |
865 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 869 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
866 EXPECT_EQ(ResourceStatus::DecodeError, | 870 EXPECT_EQ(ResourceStatus::DecodeError, |
867 observer->statusOnImageNotifyFinished()); | 871 observer->statusOnImageNotifyFinished()); |
| 872 EXPECT_EQ(2, observer->imageChangedCount()); |
868 EXPECT_FALSE(imageResource->isLoading()); | 873 EXPECT_FALSE(imageResource->isLoading()); |
869 } | 874 } |
870 | 875 |
871 TEST(ImageResourceTest, DecodeErrorWithEmptyBody) { | 876 TEST(ImageResourceTest, DecodeErrorWithEmptyBody) { |
872 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 877 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
873 ScopedRegisteredURL scopedRegisteredURL(testURL); | 878 ScopedRegisteredURL scopedRegisteredURL(testURL); |
874 | 879 |
875 ResourceFetcher* fetcher = | 880 ResourceFetcher* fetcher = |
876 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 881 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
877 FetchRequest request(testURL, FetchInitiatorInfo()); | 882 FetchRequest request(testURL, FetchInitiatorInfo()); |
878 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 883 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
879 std::unique_ptr<MockImageResourceObserver> observer = | 884 std::unique_ptr<MockImageResourceObserver> observer = |
880 MockImageResourceObserver::create(imageResource->getContent()); | 885 MockImageResourceObserver::create(imageResource->getContent()); |
881 | 886 |
882 imageResource->loader()->didReceiveResponse( | 887 imageResource->loader()->didReceiveResponse( |
883 WrappedResourceResponse( | 888 WrappedResourceResponse( |
884 ResourceResponse(testURL, "image/jpeg", 0, nullAtom, String())), | 889 ResourceResponse(testURL, "image/jpeg", 0, nullAtom, String())), |
885 nullptr); | 890 nullptr); |
886 | 891 |
887 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); | 892 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
888 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); | 893 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 894 EXPECT_EQ(0, observer->imageChangedCount()); |
889 | 895 |
890 imageResource->loader()->didFinishLoading(0.0, 0, 0); | 896 imageResource->loader()->didFinishLoading(0.0, 0, 0); |
891 | 897 |
892 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); | 898 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); |
893 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 899 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
894 EXPECT_EQ(ResourceStatus::DecodeError, | 900 EXPECT_EQ(ResourceStatus::DecodeError, |
895 observer->statusOnImageNotifyFinished()); | 901 observer->statusOnImageNotifyFinished()); |
| 902 EXPECT_EQ(1, observer->imageChangedCount()); |
896 EXPECT_FALSE(imageResource->isLoading()); | 903 EXPECT_FALSE(imageResource->isLoading()); |
897 } | 904 } |
898 | 905 |
899 TEST(ImageResourceTest, FetchDisallowPlaceholder) { | 906 TEST(ImageResourceTest, FetchDisallowPlaceholder) { |
900 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 907 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
901 ScopedRegisteredURL scopedRegisteredURL(testURL); | 908 ScopedRegisteredURL scopedRegisteredURL(testURL); |
902 | 909 |
903 FetchRequest request(testURL, FetchInitiatorInfo()); | 910 FetchRequest request(testURL, FetchInitiatorInfo()); |
904 ImageResource* imageResource = ImageResource::fetch( | 911 ImageResource* imageResource = ImageResource::fetch( |
905 request, | 912 request, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 imageResource->resourceRequest().httpHeaderField("range")); | 1060 imageResource->resourceRequest().httpHeaderField("range")); |
1054 EXPECT_TRUE(imageResource->isPlaceholder()); | 1061 EXPECT_TRUE(imageResource->isPlaceholder()); |
1055 std::unique_ptr<MockImageResourceObserver> observer = | 1062 std::unique_ptr<MockImageResourceObserver> observer = |
1056 MockImageResourceObserver::create(imageResource->getContent()); | 1063 MockImageResourceObserver::create(imageResource->getContent()); |
1057 | 1064 |
1058 const char kBadData[] = "notanimageresponse"; | 1065 const char kBadData[] = "notanimageresponse"; |
1059 | 1066 |
1060 imageResource->loader()->didReceiveResponse( | 1067 imageResource->loader()->didReceiveResponse( |
1061 WrappedResourceResponse(ResourceResponse( | 1068 WrappedResourceResponse(ResourceResponse( |
1062 testURL, "image/jpeg", sizeof(kBadData), nullAtom, String()))); | 1069 testURL, "image/jpeg", sizeof(kBadData), nullAtom, String()))); |
| 1070 |
| 1071 EXPECT_EQ(0, observer->imageChangedCount()); |
| 1072 |
1063 imageResource->loader()->didReceiveData(kBadData, sizeof(kBadData)); | 1073 imageResource->loader()->didReceiveData(kBadData, sizeof(kBadData)); |
1064 | 1074 |
1065 // The dimensions could not be extracted, so the full original image should be | 1075 // The dimensions could not be extracted, so the full original image should be |
1066 // loading. | 1076 // loading. |
1067 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); | 1077 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
1068 EXPECT_FALSE(imageResource->isPlaceholder()); | 1078 EXPECT_FALSE(imageResource->isPlaceholder()); |
1069 EXPECT_EQ(nullAtom, | 1079 EXPECT_EQ(nullAtom, |
1070 imageResource->resourceRequest().httpHeaderField("range")); | 1080 imageResource->resourceRequest().httpHeaderField("range")); |
1071 EXPECT_EQ( | 1081 EXPECT_EQ( |
1072 static_cast<int>(WebCachePolicy::BypassingCache), | 1082 static_cast<int>(WebCachePolicy::BypassingCache), |
1073 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1083 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
1074 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); | 1084 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 1085 EXPECT_EQ(3, observer->imageChangedCount()); |
1075 | 1086 |
1076 imageResource->loader()->didReceiveResponse( | 1087 imageResource->loader()->didReceiveResponse( |
1077 WrappedResourceResponse(ResourceResponse( | 1088 WrappedResourceResponse(ResourceResponse( |
1078 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); | 1089 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()))); |
1079 imageResource->loader()->didReceiveData( | 1090 imageResource->loader()->didReceiveData( |
1080 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); | 1091 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); |
1081 imageResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage), | 1092 imageResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage), |
1082 sizeof(kJpegImage)); | 1093 sizeof(kJpegImage)); |
1083 | 1094 |
1084 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus()); | 1095 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus()); |
1085 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize()); | 1096 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize()); |
1086 EXPECT_FALSE(imageResource->isPlaceholder()); | 1097 EXPECT_FALSE(imageResource->isPlaceholder()); |
1087 EXPECT_LT(0, observer->imageChangedCount()); | 1098 EXPECT_LT(3, observer->imageChangedCount()); |
1088 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); | 1099 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); |
1089 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1100 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
1090 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | 1101 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
1091 | 1102 |
1092 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 1103 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
1093 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 1104 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
1094 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 1105 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
1095 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1106 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
1096 } | 1107 } |
1097 | 1108 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1269 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
1259 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1270 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
1260 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1271 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
1261 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1272 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
1262 | 1273 |
1263 WTF::setTimeFunctionsForTesting(nullptr); | 1274 WTF::setTimeFunctionsForTesting(nullptr); |
1264 } | 1275 } |
1265 | 1276 |
1266 } // namespace | 1277 } // namespace |
1267 } // namespace blink | 1278 } // namespace blink |
OLD | NEW |