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

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

Issue 2645953005: Add more unit tests for ImageResource's DecodeError (Closed)
Patch Set: Include path fix Created 3 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/loader/resource/MockImageResourceObserver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 } 846 }
847 847
848 TEST(ImageResourceTest, CancelOnDecodeError) { 848 TEST(ImageResourceTest, CancelOnDecodeError) {
849 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 849 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
850 ScopedRegisteredURL scopedRegisteredURL(testURL); 850 ScopedRegisteredURL scopedRegisteredURL(testURL);
851 851
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 std::unique_ptr<MockImageResourceObserver> observer =
857 MockImageResourceObserver::create(imageResource->getContent());
856 858
857 imageResource->loader()->didReceiveResponse( 859 imageResource->loader()->didReceiveResponse(
858 WrappedResourceResponse( 860 WrappedResourceResponse(
859 ResourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), 861 ResourceResponse(testURL, "image/jpeg", 18, nullAtom, String())),
860 nullptr); 862 nullptr);
861 imageResource->loader()->didReceiveData("notactuallyanimage", 18); 863 imageResource->loader()->didReceiveData("notactuallyanimage", 18);
862 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); 864 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus());
865 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
866 EXPECT_EQ(ResourceStatus::DecodeError,
867 observer->statusOnImageNotifyFinished());
863 EXPECT_FALSE(imageResource->isLoading()); 868 EXPECT_FALSE(imageResource->isLoading());
864 } 869 }
865 870
871 TEST(ImageResourceTest, DecodeErrorWithEmptyBody) {
872 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
873 ScopedRegisteredURL scopedRegisteredURL(testURL);
874
875 ResourceFetcher* fetcher =
876 ResourceFetcher::create(ImageResourceTestMockFetchContext::create());
877 FetchRequest request(testURL, FetchInitiatorInfo());
878 ImageResource* imageResource = ImageResource::fetch(request, fetcher);
879 std::unique_ptr<MockImageResourceObserver> observer =
880 MockImageResourceObserver::create(imageResource->getContent());
881
882 imageResource->loader()->didReceiveResponse(
883 WrappedResourceResponse(
884 ResourceResponse(testURL, "image/jpeg", 0, nullAtom, String())),
885 nullptr);
886
887 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus());
888 EXPECT_FALSE(observer->imageNotifyFinishedCalled());
889
890 imageResource->loader()->didFinishLoading(0.0, 0, 0);
891
892 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus());
893 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
894 EXPECT_EQ(ResourceStatus::DecodeError,
895 observer->statusOnImageNotifyFinished());
896 EXPECT_FALSE(imageResource->isLoading());
897 }
898
866 TEST(ImageResourceTest, FetchDisallowPlaceholder) { 899 TEST(ImageResourceTest, FetchDisallowPlaceholder) {
867 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 900 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
868 ScopedRegisteredURL scopedRegisteredURL(testURL); 901 ScopedRegisteredURL scopedRegisteredURL(testURL);
869 902
870 FetchRequest request(testURL, FetchInitiatorInfo()); 903 FetchRequest request(testURL, FetchInitiatorInfo());
871 ImageResource* imageResource = ImageResource::fetch( 904 ImageResource* imageResource = ImageResource::fetch(
872 request, 905 request,
873 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); 906 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()));
874 EXPECT_EQ(FetchRequest::DisallowPlaceholder, 907 EXPECT_EQ(FetchRequest::DisallowPlaceholder,
875 request.placeholderImageRequestType()); 908 request.placeholderImageRequestType());
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 1258 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
1226 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 1259 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
1227 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); 1260 EXPECT_EQ(50, imageResource->getContent()->getImage()->width());
1228 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); 1261 EXPECT_EQ(50, imageResource->getContent()->getImage()->height());
1229 1262
1230 WTF::setTimeFunctionsForTesting(nullptr); 1263 WTF::setTimeFunctionsForTesting(nullptr);
1231 } 1264 }
1232 1265
1233 } // namespace 1266 } // namespace
1234 } // namespace blink 1267 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/loader/resource/MockImageResourceObserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698