| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 #include <memory> | 33 #include <memory> |
| 34 #include "core/loader/resource/MockImageResourceObserver.h" | 34 #include "core/loader/resource/MockImageResourceObserver.h" |
| 35 #include "platform/SharedBuffer.h" | 35 #include "platform/SharedBuffer.h" |
| 36 #include "platform/exported/WrappedResourceResponse.h" | 36 #include "platform/exported/WrappedResourceResponse.h" |
| 37 #include "platform/graphics/BitmapImage.h" | 37 #include "platform/graphics/BitmapImage.h" |
| 38 #include "platform/graphics/Image.h" | 38 #include "platform/graphics/Image.h" |
| 39 #include "platform/loader/fetch/FetchInitiatorInfo.h" | 39 #include "platform/loader/fetch/FetchInitiatorInfo.h" |
| 40 #include "platform/loader/fetch/FetchRequest.h" | 40 #include "platform/loader/fetch/FetchRequest.h" |
| 41 #include "platform/loader/fetch/MemoryCache.h" | 41 #include "platform/loader/fetch/MemoryCache.h" |
| 42 #include "platform/loader/fetch/MockFetchContext.h" |
| 42 #include "platform/loader/fetch/MockResourceClient.h" | 43 #include "platform/loader/fetch/MockResourceClient.h" |
| 43 #include "platform/loader/fetch/ResourceFetcher.h" | 44 #include "platform/loader/fetch/ResourceFetcher.h" |
| 44 #include "platform/loader/fetch/ResourceLoader.h" | 45 #include "platform/loader/fetch/ResourceLoader.h" |
| 45 #include "platform/loader/fetch/UniqueIdentifier.h" | 46 #include "platform/loader/fetch/UniqueIdentifier.h" |
| 46 #include "platform/scheduler/test/fake_web_task_runner.h" | 47 #include "platform/scheduler/test/fake_web_task_runner.h" |
| 47 #include "platform/testing/ScopedMockedURL.h" | 48 #include "platform/testing/ScopedMockedURL.h" |
| 48 #include "platform/testing/TestingPlatformSupport.h" | 49 #include "platform/testing/TestingPlatformSupport.h" |
| 49 #include "platform/testing/UnitTestHelpers.h" | 50 #include "platform/testing/UnitTestHelpers.h" |
| 50 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
| 51 #include "public/platform/WebCachePolicy.h" | 52 #include "public/platform/WebCachePolicy.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 size_t dataSize) { | 169 size_t dataSize) { |
| 169 ResourceResponse response; | 170 ResourceResponse response; |
| 170 response.setURL(url); | 171 response.setURL(url); |
| 171 response.setHTTPStatusCode(200); | 172 response.setHTTPStatusCode(200); |
| 172 response.setMimeType(mimeType); | 173 response.setMimeType(mimeType); |
| 173 imageResource->responseReceived(response, nullptr); | 174 imageResource->responseReceived(response, nullptr); |
| 174 imageResource->appendData(data, dataSize); | 175 imageResource->appendData(data, dataSize); |
| 175 imageResource->finish(); | 176 imageResource->finish(); |
| 176 } | 177 } |
| 177 | 178 |
| 178 class ImageResourceTestMockFetchContext : public FetchContext { | |
| 179 public: | |
| 180 static ImageResourceTestMockFetchContext* create() { | |
| 181 return new ImageResourceTestMockFetchContext; | |
| 182 } | |
| 183 | |
| 184 virtual ~ImageResourceTestMockFetchContext() {} | |
| 185 | |
| 186 bool allowImage(bool imagesEnabled, const KURL&) const override { | |
| 187 return true; | |
| 188 } | |
| 189 ResourceRequestBlockedReason canRequest( | |
| 190 Resource::Type, | |
| 191 const ResourceRequest&, | |
| 192 const KURL&, | |
| 193 const ResourceLoaderOptions&, | |
| 194 SecurityViolationReportingPolicy, | |
| 195 FetchRequest::OriginRestriction) const override { | |
| 196 return ResourceRequestBlockedReason::None; | |
| 197 } | |
| 198 bool shouldLoadNewResource(Resource::Type) const override { return true; } | |
| 199 RefPtr<WebTaskRunner> loadingTaskRunner() const override { return m_runner; } | |
| 200 | |
| 201 private: | |
| 202 ImageResourceTestMockFetchContext() | |
| 203 : m_runner(adoptRef(new scheduler::FakeWebTaskRunner)) {} | |
| 204 | |
| 205 RefPtr<scheduler::FakeWebTaskRunner> m_runner; | |
| 206 }; | |
| 207 | |
| 208 AtomicString buildContentRange(size_t rangeLength, size_t totalLength) { | 179 AtomicString buildContentRange(size_t rangeLength, size_t totalLength) { |
| 209 return AtomicString(String("bytes 0-" + String::number(rangeLength - 1) + | 180 return AtomicString(String("bytes 0-" + String::number(rangeLength - 1) + |
| 210 "/" + String::number(totalLength))); | 181 "/" + String::number(totalLength))); |
| 211 } | 182 } |
| 212 | 183 |
| 184 ResourceFetcher* createFetcher() { |
| 185 return ResourceFetcher::create( |
| 186 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource)); |
| 187 } |
| 188 |
| 213 TEST(ImageResourceTest, MultipartImage) { | 189 TEST(ImageResourceTest, MultipartImage) { |
| 214 ResourceFetcher* fetcher = | 190 ResourceFetcher* fetcher = createFetcher(); |
| 215 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 216 KURL testURL(ParsedURLString, kTestURL); | 191 KURL testURL(ParsedURLString, kTestURL); |
| 217 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 192 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 218 | 193 |
| 219 // Emulate starting a real load, but don't expect any "real" | 194 // Emulate starting a real load, but don't expect any "real" |
| 220 // WebURLLoaderClient callbacks. | 195 // WebURLLoaderClient callbacks. |
| 221 ImageResource* imageResource = | 196 ImageResource* imageResource = |
| 222 ImageResource::create(ResourceRequest(testURL)); | 197 ImageResource::create(ResourceRequest(testURL)); |
| 223 imageResource->setIdentifier(createUniqueIdentifier()); | 198 imageResource->setIdentifier(createUniqueIdentifier()); |
| 224 fetcher->startLoad(imageResource); | 199 fetcher->startLoad(imageResource); |
| 225 | 200 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 EXPECT_EQ(1, observer->imageChangedCount()); | 263 EXPECT_EQ(1, observer->imageChangedCount()); |
| 289 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 264 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 290 EXPECT_EQ(1, observer2->imageChangedCount()); | 265 EXPECT_EQ(1, observer2->imageChangedCount()); |
| 291 EXPECT_TRUE(observer2->imageNotifyFinishedCalled()); | 266 EXPECT_TRUE(observer2->imageNotifyFinishedCalled()); |
| 292 } | 267 } |
| 293 | 268 |
| 294 TEST(ImageResourceTest, CancelOnRemoveObserver) { | 269 TEST(ImageResourceTest, CancelOnRemoveObserver) { |
| 295 KURL testURL(ParsedURLString, kTestURL); | 270 KURL testURL(ParsedURLString, kTestURL); |
| 296 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 271 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 297 | 272 |
| 298 ResourceFetcher* fetcher = | 273 ResourceFetcher* fetcher = createFetcher(); |
| 299 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 300 | 274 |
| 301 // Emulate starting a real load. | 275 // Emulate starting a real load. |
| 302 ImageResource* imageResource = | 276 ImageResource* imageResource = |
| 303 ImageResource::create(ResourceRequest(testURL)); | 277 ImageResource::create(ResourceRequest(testURL)); |
| 304 imageResource->setIdentifier(createUniqueIdentifier()); | 278 imageResource->setIdentifier(createUniqueIdentifier()); |
| 305 | 279 |
| 306 fetcher->startLoad(imageResource); | 280 fetcher->startLoad(imageResource); |
| 307 memoryCache()->add(imageResource); | 281 memoryCache()->add(imageResource); |
| 308 | 282 |
| 309 std::unique_ptr<MockImageResourceObserver> observer = | 283 std::unique_ptr<MockImageResourceObserver> observer = |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { | 364 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { |
| 391 KURL testURL(ParsedURLString, kTestURL); | 365 KURL testURL(ParsedURLString, kTestURL); |
| 392 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 366 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 393 ResourceRequest request = ResourceRequest(testURL); | 367 ResourceRequest request = ResourceRequest(testURL); |
| 394 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | 368 request.setPreviewsState(WebURLRequest::ServerLoFiOn); |
| 395 ImageResource* imageResource = ImageResource::create(request); | 369 ImageResource* imageResource = ImageResource::create(request); |
| 396 imageResource->setStatus(ResourceStatus::Pending); | 370 imageResource->setStatus(ResourceStatus::Pending); |
| 397 | 371 |
| 398 std::unique_ptr<MockImageResourceObserver> observer = | 372 std::unique_ptr<MockImageResourceObserver> observer = |
| 399 MockImageResourceObserver::create(imageResource->getContent()); | 373 MockImageResourceObserver::create(imageResource->getContent()); |
| 400 ResourceFetcher* fetcher = | 374 ResourceFetcher* fetcher = createFetcher(); |
| 401 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 402 | 375 |
| 403 // Send the image response. | 376 // Send the image response. |
| 404 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), | 377 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), |
| 405 nullAtom); | 378 nullAtom); |
| 406 resourceResponse.addHTTPHeaderField("chrome-proxy-content-transform", | 379 resourceResponse.addHTTPHeaderField("chrome-proxy-content-transform", |
| 407 "empty-image"); | 380 "empty-image"); |
| 408 | 381 |
| 409 imageResource->responseReceived(resourceResponse, nullptr); | 382 imageResource->responseReceived(resourceResponse, nullptr); |
| 410 imageResource->appendData(reinterpret_cast<const char*>(kJpegImage), | 383 imageResource->appendData(reinterpret_cast<const char*>(kJpegImage), |
| 411 sizeof(kJpegImage)); | 384 sizeof(kJpegImage)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 418 |
| 446 // The observer should not have been notified of completion again. | 419 // The observer should not have been notified of completion again. |
| 447 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | 420 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
| 448 | 421 |
| 449 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 422 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 450 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 423 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 451 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 424 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 452 } | 425 } |
| 453 | 426 |
| 454 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderViaResourceFetcher) { | 427 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderViaResourceFetcher) { |
| 455 ResourceFetcher* fetcher = | 428 ResourceFetcher* fetcher = createFetcher(); |
| 456 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 457 | 429 |
| 458 KURL testURL(ParsedURLString, kTestURL); | 430 KURL testURL(ParsedURLString, kTestURL); |
| 459 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 431 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 460 | 432 |
| 461 ResourceRequest request = ResourceRequest(testURL); | 433 ResourceRequest request = ResourceRequest(testURL); |
| 462 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | 434 request.setPreviewsState(WebURLRequest::ServerLoFiOn); |
| 463 FetchRequest fetchRequest(request, FetchInitiatorInfo()); | 435 FetchRequest fetchRequest(request, FetchInitiatorInfo()); |
| 464 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); | 436 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); |
| 465 ImageResourceContent* content = imageResource->getContent(); | 437 ImageResourceContent* content = imageResource->getContent(); |
| 466 | 438 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 memoryCache()->remove(imageResource); | 484 memoryCache()->remove(imageResource); |
| 513 } | 485 } |
| 514 | 486 |
| 515 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) { | 487 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) { |
| 516 KURL testURL(ParsedURLString, kTestURL); | 488 KURL testURL(ParsedURLString, kTestURL); |
| 517 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 489 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 518 | 490 |
| 519 ResourceRequest request(testURL); | 491 ResourceRequest request(testURL); |
| 520 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | 492 request.setPreviewsState(WebURLRequest::ServerLoFiOn); |
| 521 FetchRequest fetchRequest(request, FetchInitiatorInfo()); | 493 FetchRequest fetchRequest(request, FetchInitiatorInfo()); |
| 522 ResourceFetcher* fetcher = | 494 ResourceFetcher* fetcher = createFetcher(); |
| 523 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 524 | 495 |
| 525 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); | 496 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); |
| 526 std::unique_ptr<MockImageResourceObserver> observer = | 497 std::unique_ptr<MockImageResourceObserver> observer = |
| 527 MockImageResourceObserver::create(imageResource->getContent()); | 498 MockImageResourceObserver::create(imageResource->getContent()); |
| 528 | 499 |
| 529 // Send the image response. | 500 // Send the image response. |
| 530 ResourceResponse initialResourceResponse(testURL, "image/jpeg", | 501 ResourceResponse initialResourceResponse(testURL, "image/jpeg", |
| 531 sizeof(kJpegImage), nullAtom); | 502 sizeof(kJpegImage), nullAtom); |
| 532 initialResourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); | 503 initialResourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
| 533 | 504 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 EXPECT_EQ(kJpegImage2Width, observer->imageWidthOnImageNotifyFinished()); | 549 EXPECT_EQ(kJpegImage2Width, observer->imageWidthOnImageNotifyFinished()); |
| 579 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 550 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 580 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 551 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 581 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 552 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 582 } | 553 } |
| 583 | 554 |
| 584 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) { | 555 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) { |
| 585 KURL testURL(ParsedURLString, kTestURL); | 556 KURL testURL(ParsedURLString, kTestURL); |
| 586 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 557 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 587 | 558 |
| 588 ResourceFetcher* fetcher = | 559 ResourceFetcher* fetcher = createFetcher(); |
| 589 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 590 FetchRequest request(testURL, FetchInitiatorInfo()); | 560 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 591 request.setAllowImagePlaceholder(); | 561 request.setAllowImagePlaceholder(); |
| 592 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 562 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
| 593 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 563 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 594 request.placeholderImageRequestType()); | 564 request.placeholderImageRequestType()); |
| 595 EXPECT_EQ("bytes=0-2047", | 565 EXPECT_EQ("bytes=0-2047", |
| 596 imageResource->resourceRequest().httpHeaderField("range")); | 566 imageResource->resourceRequest().httpHeaderField("range")); |
| 597 std::unique_ptr<MockImageResourceObserver> observer = | 567 std::unique_ptr<MockImageResourceObserver> observer = |
| 598 MockImageResourceObserver::create(imageResource->getContent()); | 568 MockImageResourceObserver::create(imageResource->getContent()); |
| 599 | 569 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | 855 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 886 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 856 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| 887 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 857 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| 888 EXPECT_TRUE(client2->notifyFinishedCalled()); | 858 EXPECT_TRUE(client2->notifyFinishedCalled()); |
| 889 } | 859 } |
| 890 | 860 |
| 891 TEST(ImageResourceTest, CancelOnDecodeError) { | 861 TEST(ImageResourceTest, CancelOnDecodeError) { |
| 892 KURL testURL(ParsedURLString, kTestURL); | 862 KURL testURL(ParsedURLString, kTestURL); |
| 893 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 863 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 894 | 864 |
| 895 ResourceFetcher* fetcher = | 865 ResourceFetcher* fetcher = createFetcher(); |
| 896 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 897 FetchRequest request(testURL, FetchInitiatorInfo()); | 866 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 898 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 867 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
| 899 std::unique_ptr<MockImageResourceObserver> observer = | 868 std::unique_ptr<MockImageResourceObserver> observer = |
| 900 MockImageResourceObserver::create(imageResource->getContent()); | 869 MockImageResourceObserver::create(imageResource->getContent()); |
| 901 | 870 |
| 902 imageResource->loader()->didReceiveResponse( | 871 imageResource->loader()->didReceiveResponse( |
| 903 WrappedResourceResponse( | 872 WrappedResourceResponse( |
| 904 ResourceResponse(testURL, "image/jpeg", 18, nullAtom)), | 873 ResourceResponse(testURL, "image/jpeg", 18, nullAtom)), |
| 905 nullptr); | 874 nullptr); |
| 906 | 875 |
| 907 EXPECT_EQ(0, observer->imageChangedCount()); | 876 EXPECT_EQ(0, observer->imageChangedCount()); |
| 908 | 877 |
| 909 imageResource->loader()->didReceiveData("notactuallyanimage", 18); | 878 imageResource->loader()->didReceiveData("notactuallyanimage", 18); |
| 910 | 879 |
| 911 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); | 880 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); |
| 912 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 881 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 913 EXPECT_EQ(ResourceStatus::DecodeError, | 882 EXPECT_EQ(ResourceStatus::DecodeError, |
| 914 observer->statusOnImageNotifyFinished()); | 883 observer->statusOnImageNotifyFinished()); |
| 915 EXPECT_EQ(2, observer->imageChangedCount()); | 884 EXPECT_EQ(2, observer->imageChangedCount()); |
| 916 EXPECT_FALSE(imageResource->isLoading()); | 885 EXPECT_FALSE(imageResource->isLoading()); |
| 917 } | 886 } |
| 918 | 887 |
| 919 TEST(ImageResourceTest, DecodeErrorWithEmptyBody) { | 888 TEST(ImageResourceTest, DecodeErrorWithEmptyBody) { |
| 920 KURL testURL(ParsedURLString, kTestURL); | 889 KURL testURL(ParsedURLString, kTestURL); |
| 921 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 890 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 922 | 891 |
| 923 ResourceFetcher* fetcher = | 892 ResourceFetcher* fetcher = createFetcher(); |
| 924 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 925 FetchRequest request(testURL, FetchInitiatorInfo()); | 893 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 926 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 894 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
| 927 std::unique_ptr<MockImageResourceObserver> observer = | 895 std::unique_ptr<MockImageResourceObserver> observer = |
| 928 MockImageResourceObserver::create(imageResource->getContent()); | 896 MockImageResourceObserver::create(imageResource->getContent()); |
| 929 | 897 |
| 930 imageResource->loader()->didReceiveResponse( | 898 imageResource->loader()->didReceiveResponse( |
| 931 WrappedResourceResponse( | 899 WrappedResourceResponse( |
| 932 ResourceResponse(testURL, "image/jpeg", 0, nullAtom)), | 900 ResourceResponse(testURL, "image/jpeg", 0, nullAtom)), |
| 933 nullptr); | 901 nullptr); |
| 934 | 902 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 948 | 916 |
| 949 // Testing DecodeError that occurs in didFinishLoading(). | 917 // Testing DecodeError that occurs in didFinishLoading(). |
| 950 // This is similar to DecodeErrorWithEmptyBody, but with non-empty body. | 918 // This is similar to DecodeErrorWithEmptyBody, but with non-empty body. |
| 951 TEST(ImageResourceTest, PartialContentWithoutDimensions) { | 919 TEST(ImageResourceTest, PartialContentWithoutDimensions) { |
| 952 KURL testURL(ParsedURLString, kTestURL); | 920 KURL testURL(ParsedURLString, kTestURL); |
| 953 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 921 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 954 | 922 |
| 955 ResourceRequest resourceRequest(testURL); | 923 ResourceRequest resourceRequest(testURL); |
| 956 resourceRequest.setHTTPHeaderField("range", "bytes=0-2"); | 924 resourceRequest.setHTTPHeaderField("range", "bytes=0-2"); |
| 957 FetchRequest request(resourceRequest, FetchInitiatorInfo()); | 925 FetchRequest request(resourceRequest, FetchInitiatorInfo()); |
| 958 ResourceFetcher* fetcher = | 926 ResourceFetcher* fetcher = createFetcher(); |
| 959 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 960 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 927 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
| 961 std::unique_ptr<MockImageResourceObserver> observer = | 928 std::unique_ptr<MockImageResourceObserver> observer = |
| 962 MockImageResourceObserver::create(imageResource->getContent()); | 929 MockImageResourceObserver::create(imageResource->getContent()); |
| 963 | 930 |
| 964 ResourceResponse partialResponse(testURL, "image/jpeg", | 931 ResourceResponse partialResponse(testURL, "image/jpeg", |
| 965 kJpegImageSubrangeWithoutDimensionsLength, | 932 kJpegImageSubrangeWithoutDimensionsLength, |
| 966 nullAtom); | 933 nullAtom); |
| 967 partialResponse.setHTTPStatusCode(206); | 934 partialResponse.setHTTPStatusCode(206); |
| 968 partialResponse.setHTTPHeaderField( | 935 partialResponse.setHTTPHeaderField( |
| 969 "content-range", | 936 "content-range", |
| (...skipping 20 matching lines...) Expand all Loading... |
| 990 observer->statusOnImageNotifyFinished()); | 957 observer->statusOnImageNotifyFinished()); |
| 991 EXPECT_EQ(1, observer->imageChangedCount()); | 958 EXPECT_EQ(1, observer->imageChangedCount()); |
| 992 EXPECT_FALSE(imageResource->isLoading()); | 959 EXPECT_FALSE(imageResource->isLoading()); |
| 993 } | 960 } |
| 994 | 961 |
| 995 TEST(ImageResourceTest, FetchDisallowPlaceholder) { | 962 TEST(ImageResourceTest, FetchDisallowPlaceholder) { |
| 996 KURL testURL(ParsedURLString, kTestURL); | 963 KURL testURL(ParsedURLString, kTestURL); |
| 997 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 964 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 998 | 965 |
| 999 FetchRequest request(testURL, FetchInitiatorInfo()); | 966 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1000 ImageResource* imageResource = ImageResource::fetch( | 967 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); |
| 1001 request, | |
| 1002 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1003 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 968 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 1004 request.placeholderImageRequestType()); | 969 request.placeholderImageRequestType()); |
| 1005 EXPECT_EQ(nullAtom, | 970 EXPECT_EQ(nullAtom, |
| 1006 imageResource->resourceRequest().httpHeaderField("range")); | 971 imageResource->resourceRequest().httpHeaderField("range")); |
| 1007 EXPECT_FALSE(imageResource->isPlaceholder()); | 972 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1008 std::unique_ptr<MockImageResourceObserver> observer = | 973 std::unique_ptr<MockImageResourceObserver> observer = |
| 1009 MockImageResourceObserver::create(imageResource->getContent()); | 974 MockImageResourceObserver::create(imageResource->getContent()); |
| 1010 | 975 |
| 1011 imageResource->loader()->didReceiveResponse(WrappedResourceResponse( | 976 imageResource->loader()->didReceiveResponse(WrappedResourceResponse( |
| 1012 ResourceResponse(testURL, "image/jpeg", sizeof(kJpegImage), nullAtom))); | 977 ResourceResponse(testURL, "image/jpeg", sizeof(kJpegImage), nullAtom))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1029 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 994 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1030 } | 995 } |
| 1031 | 996 |
| 1032 TEST(ImageResourceTest, FetchAllowPlaceholderDataURL) { | 997 TEST(ImageResourceTest, FetchAllowPlaceholderDataURL) { |
| 1033 KURL testURL(ParsedURLString, | 998 KURL testURL(ParsedURLString, |
| 1034 "data:image/jpeg;base64," + | 999 "data:image/jpeg;base64," + |
| 1035 base64Encode(reinterpret_cast<const char*>(kJpegImage), | 1000 base64Encode(reinterpret_cast<const char*>(kJpegImage), |
| 1036 sizeof(kJpegImage))); | 1001 sizeof(kJpegImage))); |
| 1037 FetchRequest request(testURL, FetchInitiatorInfo()); | 1002 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1038 request.setAllowImagePlaceholder(); | 1003 request.setAllowImagePlaceholder(); |
| 1039 ImageResource* imageResource = ImageResource::fetch( | 1004 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); |
| 1040 request, | |
| 1041 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1042 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 1005 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 1043 request.placeholderImageRequestType()); | 1006 request.placeholderImageRequestType()); |
| 1044 EXPECT_EQ(nullAtom, | 1007 EXPECT_EQ(nullAtom, |
| 1045 imageResource->resourceRequest().httpHeaderField("range")); | 1008 imageResource->resourceRequest().httpHeaderField("range")); |
| 1046 EXPECT_FALSE(imageResource->isPlaceholder()); | 1009 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1047 } | 1010 } |
| 1048 | 1011 |
| 1049 TEST(ImageResourceTest, FetchAllowPlaceholderPostRequest) { | 1012 TEST(ImageResourceTest, FetchAllowPlaceholderPostRequest) { |
| 1050 KURL testURL(ParsedURLString, kTestURL); | 1013 KURL testURL(ParsedURLString, kTestURL); |
| 1051 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1014 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1052 ResourceRequest resourceRequest(testURL); | 1015 ResourceRequest resourceRequest(testURL); |
| 1053 resourceRequest.setHTTPMethod("POST"); | 1016 resourceRequest.setHTTPMethod("POST"); |
| 1054 FetchRequest request(resourceRequest, FetchInitiatorInfo()); | 1017 FetchRequest request(resourceRequest, FetchInitiatorInfo()); |
| 1055 request.setAllowImagePlaceholder(); | 1018 request.setAllowImagePlaceholder(); |
| 1056 ImageResource* imageResource = ImageResource::fetch( | 1019 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); |
| 1057 request, | |
| 1058 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1059 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 1020 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 1060 request.placeholderImageRequestType()); | 1021 request.placeholderImageRequestType()); |
| 1061 EXPECT_EQ(nullAtom, | 1022 EXPECT_EQ(nullAtom, |
| 1062 imageResource->resourceRequest().httpHeaderField("range")); | 1023 imageResource->resourceRequest().httpHeaderField("range")); |
| 1063 EXPECT_FALSE(imageResource->isPlaceholder()); | 1024 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1064 | 1025 |
| 1065 imageResource->loader()->cancel(); | 1026 imageResource->loader()->cancel(); |
| 1066 } | 1027 } |
| 1067 | 1028 |
| 1068 TEST(ImageResourceTest, FetchAllowPlaceholderExistingRangeHeader) { | 1029 TEST(ImageResourceTest, FetchAllowPlaceholderExistingRangeHeader) { |
| 1069 KURL testURL(ParsedURLString, kTestURL); | 1030 KURL testURL(ParsedURLString, kTestURL); |
| 1070 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1031 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1071 ResourceRequest resourceRequest(testURL); | 1032 ResourceRequest resourceRequest(testURL); |
| 1072 resourceRequest.setHTTPHeaderField("range", "bytes=128-255"); | 1033 resourceRequest.setHTTPHeaderField("range", "bytes=128-255"); |
| 1073 FetchRequest request(resourceRequest, FetchInitiatorInfo()); | 1034 FetchRequest request(resourceRequest, FetchInitiatorInfo()); |
| 1074 request.setAllowImagePlaceholder(); | 1035 request.setAllowImagePlaceholder(); |
| 1075 ImageResource* imageResource = ImageResource::fetch( | 1036 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); |
| 1076 request, | |
| 1077 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1078 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 1037 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 1079 request.placeholderImageRequestType()); | 1038 request.placeholderImageRequestType()); |
| 1080 EXPECT_EQ("bytes=128-255", | 1039 EXPECT_EQ("bytes=128-255", |
| 1081 imageResource->resourceRequest().httpHeaderField("range")); | 1040 imageResource->resourceRequest().httpHeaderField("range")); |
| 1082 EXPECT_FALSE(imageResource->isPlaceholder()); | 1041 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1083 | 1042 |
| 1084 imageResource->loader()->cancel(); | 1043 imageResource->loader()->cancel(); |
| 1085 } | 1044 } |
| 1086 | 1045 |
| 1087 TEST(ImageResourceTest, FetchAllowPlaceholderSuccessful) { | 1046 TEST(ImageResourceTest, FetchAllowPlaceholderSuccessful) { |
| 1088 KURL testURL(ParsedURLString, kTestURL); | 1047 KURL testURL(ParsedURLString, kTestURL); |
| 1089 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1048 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1090 | 1049 |
| 1091 FetchRequest request(testURL, FetchInitiatorInfo()); | 1050 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1092 request.setAllowImagePlaceholder(); | 1051 request.setAllowImagePlaceholder(); |
| 1093 ImageResource* imageResource = ImageResource::fetch( | 1052 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); |
| 1094 request, | |
| 1095 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1096 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 1053 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 1097 request.placeholderImageRequestType()); | 1054 request.placeholderImageRequestType()); |
| 1098 EXPECT_EQ("bytes=0-2047", | 1055 EXPECT_EQ("bytes=0-2047", |
| 1099 imageResource->resourceRequest().httpHeaderField("range")); | 1056 imageResource->resourceRequest().httpHeaderField("range")); |
| 1100 EXPECT_TRUE(imageResource->isPlaceholder()); | 1057 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 1101 std::unique_ptr<MockImageResourceObserver> observer = | 1058 std::unique_ptr<MockImageResourceObserver> observer = |
| 1102 MockImageResourceObserver::create(imageResource->getContent()); | 1059 MockImageResourceObserver::create(imageResource->getContent()); |
| 1103 | 1060 |
| 1104 ResourceResponse response(testURL, "image/jpeg", | 1061 ResourceResponse response(testURL, "image/jpeg", |
| 1105 kJpegImageSubrangeWithDimensionsLength, nullAtom); | 1062 kJpegImageSubrangeWithDimensionsLength, nullAtom); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1131 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); | 1088 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1132 EXPECT_FALSE(imageResource->getContent()->getImage()->isSVGImage()); | 1089 EXPECT_FALSE(imageResource->getContent()->getImage()->isSVGImage()); |
| 1133 } | 1090 } |
| 1134 | 1091 |
| 1135 TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) { | 1092 TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) { |
| 1136 KURL testURL(ParsedURLString, kTestURL); | 1093 KURL testURL(ParsedURLString, kTestURL); |
| 1137 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1094 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1138 | 1095 |
| 1139 FetchRequest request(testURL, FetchInitiatorInfo()); | 1096 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1140 request.setAllowImagePlaceholder(); | 1097 request.setAllowImagePlaceholder(); |
| 1141 ImageResource* imageResource = ImageResource::fetch( | 1098 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); |
| 1142 request, | |
| 1143 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1144 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 1099 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 1145 request.placeholderImageRequestType()); | 1100 request.placeholderImageRequestType()); |
| 1146 EXPECT_EQ("bytes=0-2047", | 1101 EXPECT_EQ("bytes=0-2047", |
| 1147 imageResource->resourceRequest().httpHeaderField("range")); | 1102 imageResource->resourceRequest().httpHeaderField("range")); |
| 1148 EXPECT_TRUE(imageResource->isPlaceholder()); | 1103 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 1149 std::unique_ptr<MockImageResourceObserver> observer = | 1104 std::unique_ptr<MockImageResourceObserver> observer = |
| 1150 MockImageResourceObserver::create(imageResource->getContent()); | 1105 MockImageResourceObserver::create(imageResource->getContent()); |
| 1151 | 1106 |
| 1152 const char kBadData[] = "notanimageresponse"; | 1107 const char kBadData[] = "notanimageresponse"; |
| 1153 | 1108 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 1151 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| 1197 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1152 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1198 } | 1153 } |
| 1199 | 1154 |
| 1200 TEST(ImageResourceTest, FetchAllowPlaceholderPartialContentWithoutDimensions) { | 1155 TEST(ImageResourceTest, FetchAllowPlaceholderPartialContentWithoutDimensions) { |
| 1201 KURL testURL(ParsedURLString, kTestURL); | 1156 KURL testURL(ParsedURLString, kTestURL); |
| 1202 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1157 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1203 | 1158 |
| 1204 FetchRequest request(testURL, FetchInitiatorInfo()); | 1159 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1205 request.setAllowImagePlaceholder(); | 1160 request.setAllowImagePlaceholder(); |
| 1206 ImageResource* imageResource = ImageResource::fetch( | 1161 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); |
| 1207 request, | |
| 1208 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1209 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 1162 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 1210 request.placeholderImageRequestType()); | 1163 request.placeholderImageRequestType()); |
| 1211 EXPECT_EQ("bytes=0-2047", | 1164 EXPECT_EQ("bytes=0-2047", |
| 1212 imageResource->resourceRequest().httpHeaderField("range")); | 1165 imageResource->resourceRequest().httpHeaderField("range")); |
| 1213 EXPECT_TRUE(imageResource->isPlaceholder()); | 1166 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 1214 std::unique_ptr<MockImageResourceObserver> observer = | 1167 std::unique_ptr<MockImageResourceObserver> observer = |
| 1215 MockImageResourceObserver::create(imageResource->getContent()); | 1168 MockImageResourceObserver::create(imageResource->getContent()); |
| 1216 | 1169 |
| 1217 // TODO(hiroshige): Make the range request header and partial content length | 1170 // TODO(hiroshige): Make the range request header and partial content length |
| 1218 // consistent. https://crbug.com/689760. | 1171 // consistent. https://crbug.com/689760. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 1220 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 1268 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 1221 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| 1269 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 1222 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| 1270 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1223 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1271 } | 1224 } |
| 1272 | 1225 |
| 1273 TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) { | 1226 TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) { |
| 1274 KURL testURL(ParsedURLString, kTestURL); | 1227 KURL testURL(ParsedURLString, kTestURL); |
| 1275 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1228 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1276 | 1229 |
| 1277 ResourceFetcher* fetcher = | 1230 ResourceFetcher* fetcher = createFetcher(); |
| 1278 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 1279 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); | 1231 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); |
| 1280 placeholderRequest.setAllowImagePlaceholder(); | 1232 placeholderRequest.setAllowImagePlaceholder(); |
| 1281 ImageResource* imageResource = | 1233 ImageResource* imageResource = |
| 1282 ImageResource::fetch(placeholderRequest, fetcher); | 1234 ImageResource::fetch(placeholderRequest, fetcher); |
| 1283 std::unique_ptr<MockImageResourceObserver> observer = | 1235 std::unique_ptr<MockImageResourceObserver> observer = |
| 1284 MockImageResourceObserver::create(imageResource->getContent()); | 1236 MockImageResourceObserver::create(imageResource->getContent()); |
| 1285 | 1237 |
| 1286 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); | 1238 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); |
| 1287 ImageResource* secondImageResource = | 1239 ImageResource* secondImageResource = |
| 1288 ImageResource::fetch(nonPlaceholderRequest, fetcher); | 1240 ImageResource::fetch(nonPlaceholderRequest, fetcher); |
| 1289 EXPECT_EQ(imageResource, secondImageResource); | 1241 EXPECT_EQ(imageResource, secondImageResource); |
| 1290 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); | 1242 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 1291 EXPECT_FALSE(imageResource->isPlaceholder()); | 1243 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1292 EXPECT_EQ(nullAtom, | 1244 EXPECT_EQ(nullAtom, |
| 1293 imageResource->resourceRequest().httpHeaderField("range")); | 1245 imageResource->resourceRequest().httpHeaderField("range")); |
| 1294 EXPECT_EQ( | 1246 EXPECT_EQ( |
| 1295 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), | 1247 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), |
| 1296 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1248 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 1297 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); | 1249 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 1298 | 1250 |
| 1299 imageResource->loader()->cancel(); | 1251 imageResource->loader()->cancel(); |
| 1300 } | 1252 } |
| 1301 | 1253 |
| 1302 TEST(ImageResourceTest, | 1254 TEST(ImageResourceTest, |
| 1303 FetchAllowPlaceholderThenDisallowPlaceholderAfterLoaded) { | 1255 FetchAllowPlaceholderThenDisallowPlaceholderAfterLoaded) { |
| 1304 KURL testURL(ParsedURLString, kTestURL); | 1256 KURL testURL(ParsedURLString, kTestURL); |
| 1305 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1257 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1306 | 1258 |
| 1307 ResourceFetcher* fetcher = | 1259 ResourceFetcher* fetcher = createFetcher(); |
| 1308 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | |
| 1309 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); | 1260 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); |
| 1310 placeholderRequest.setAllowImagePlaceholder(); | 1261 placeholderRequest.setAllowImagePlaceholder(); |
| 1311 ImageResource* imageResource = | 1262 ImageResource* imageResource = |
| 1312 ImageResource::fetch(placeholderRequest, fetcher); | 1263 ImageResource::fetch(placeholderRequest, fetcher); |
| 1313 std::unique_ptr<MockImageResourceObserver> observer = | 1264 std::unique_ptr<MockImageResourceObserver> observer = |
| 1314 MockImageResourceObserver::create(imageResource->getContent()); | 1265 MockImageResourceObserver::create(imageResource->getContent()); |
| 1315 | 1266 |
| 1316 ResourceResponse response(testURL, "image/jpeg", | 1267 ResourceResponse response(testURL, "image/jpeg", |
| 1317 kJpegImageSubrangeWithDimensionsLength, nullAtom); | 1268 kJpegImageSubrangeWithDimensionsLength, nullAtom); |
| 1318 response.setHTTPStatusCode(206); | 1269 response.setHTTPStatusCode(206); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 {200, nullAtom}, | 1309 {200, nullAtom}, |
| 1359 {404, nullAtom}, | 1310 {404, nullAtom}, |
| 1360 {206, buildContentRange(sizeof(kJpegImage), sizeof(kJpegImage))}, | 1311 {206, buildContentRange(sizeof(kJpegImage), sizeof(kJpegImage))}, |
| 1361 }; | 1312 }; |
| 1362 for (const auto& test : tests) { | 1313 for (const auto& test : tests) { |
| 1363 KURL testURL(ParsedURLString, kTestURL); | 1314 KURL testURL(ParsedURLString, kTestURL); |
| 1364 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1315 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1365 | 1316 |
| 1366 FetchRequest request(testURL, FetchInitiatorInfo()); | 1317 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1367 request.setAllowImagePlaceholder(); | 1318 request.setAllowImagePlaceholder(); |
| 1368 ImageResource* imageResource = ImageResource::fetch( | 1319 ImageResource* imageResource = |
| 1369 request, | 1320 ImageResource::fetch(request, createFetcher()); |
| 1370 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1371 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 1321 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 1372 request.placeholderImageRequestType()); | 1322 request.placeholderImageRequestType()); |
| 1373 EXPECT_EQ("bytes=0-2047", | 1323 EXPECT_EQ("bytes=0-2047", |
| 1374 imageResource->resourceRequest().httpHeaderField("range")); | 1324 imageResource->resourceRequest().httpHeaderField("range")); |
| 1375 EXPECT_TRUE(imageResource->isPlaceholder()); | 1325 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 1376 std::unique_ptr<MockImageResourceObserver> observer = | 1326 std::unique_ptr<MockImageResourceObserver> observer = |
| 1377 MockImageResourceObserver::create(imageResource->getContent()); | 1327 MockImageResourceObserver::create(imageResource->getContent()); |
| 1378 | 1328 |
| 1379 ResourceResponse response(testURL, "image/jpeg", sizeof(kJpegImage), | 1329 ResourceResponse response(testURL, "image/jpeg", sizeof(kJpegImage), |
| 1380 nullAtom); | 1330 nullAtom); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 {206, buildContentRange(sizeof(kBadImageData), sizeof(kBadImageData)), | 1366 {206, buildContentRange(sizeof(kBadImageData), sizeof(kBadImageData)), |
| 1417 sizeof(kBadImageData)}, | 1367 sizeof(kBadImageData)}, |
| 1418 {204, nullAtom, 0}, | 1368 {204, nullAtom, 0}, |
| 1419 }; | 1369 }; |
| 1420 for (const auto& test : tests) { | 1370 for (const auto& test : tests) { |
| 1421 KURL testURL(ParsedURLString, kTestURL); | 1371 KURL testURL(ParsedURLString, kTestURL); |
| 1422 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1372 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1423 | 1373 |
| 1424 FetchRequest request(testURL, FetchInitiatorInfo()); | 1374 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1425 request.setAllowImagePlaceholder(); | 1375 request.setAllowImagePlaceholder(); |
| 1426 ImageResource* imageResource = ImageResource::fetch( | 1376 ImageResource* imageResource = |
| 1427 request, | 1377 ImageResource::fetch(request, createFetcher()); |
| 1428 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1429 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 1378 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 1430 request.placeholderImageRequestType()); | 1379 request.placeholderImageRequestType()); |
| 1431 EXPECT_EQ("bytes=0-2047", | 1380 EXPECT_EQ("bytes=0-2047", |
| 1432 imageResource->resourceRequest().httpHeaderField("range")); | 1381 imageResource->resourceRequest().httpHeaderField("range")); |
| 1433 EXPECT_TRUE(imageResource->isPlaceholder()); | 1382 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 1434 std::unique_ptr<MockImageResourceObserver> observer = | 1383 std::unique_ptr<MockImageResourceObserver> observer = |
| 1435 MockImageResourceObserver::create(imageResource->getContent()); | 1384 MockImageResourceObserver::create(imageResource->getContent()); |
| 1436 | 1385 |
| 1437 ResourceResponse response(testURL, "image/jpeg", test.dataSize, nullAtom); | 1386 ResourceResponse response(testURL, "image/jpeg", test.dataSize, nullAtom); |
| 1438 response.setHTTPStatusCode(test.statusCode); | 1387 response.setHTTPStatusCode(test.statusCode); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1449 | 1398 |
| 1450 TEST(ImageResourceTest, | 1399 TEST(ImageResourceTest, |
| 1451 FetchAllowPlaceholderFullResponseDecodeFailureWithReload) { | 1400 FetchAllowPlaceholderFullResponseDecodeFailureWithReload) { |
| 1452 const int kStatusCodes[] = {404, 500}; | 1401 const int kStatusCodes[] = {404, 500}; |
| 1453 for (int statusCode : kStatusCodes) { | 1402 for (int statusCode : kStatusCodes) { |
| 1454 KURL testURL(ParsedURLString, kTestURL); | 1403 KURL testURL(ParsedURLString, kTestURL); |
| 1455 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 1404 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1456 | 1405 |
| 1457 FetchRequest request(testURL, FetchInitiatorInfo()); | 1406 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1458 request.setAllowImagePlaceholder(); | 1407 request.setAllowImagePlaceholder(); |
| 1459 ImageResource* imageResource = ImageResource::fetch( | 1408 ImageResource* imageResource = |
| 1460 request, | 1409 ImageResource::fetch(request, createFetcher()); |
| 1461 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | |
| 1462 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 1410 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 1463 request.placeholderImageRequestType()); | 1411 request.placeholderImageRequestType()); |
| 1464 EXPECT_EQ("bytes=0-2047", | 1412 EXPECT_EQ("bytes=0-2047", |
| 1465 imageResource->resourceRequest().httpHeaderField("range")); | 1413 imageResource->resourceRequest().httpHeaderField("range")); |
| 1466 EXPECT_TRUE(imageResource->isPlaceholder()); | 1414 EXPECT_TRUE(imageResource->isPlaceholder()); |
| 1467 std::unique_ptr<MockImageResourceObserver> observer = | 1415 std::unique_ptr<MockImageResourceObserver> observer = |
| 1468 MockImageResourceObserver::create(imageResource->getContent()); | 1416 MockImageResourceObserver::create(imageResource->getContent()); |
| 1469 | 1417 |
| 1470 static const char kBadImageData[] = "bad image data"; | 1418 static const char kBadImageData[] = "bad image data"; |
| 1471 | 1419 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1539 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1592 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1540 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1593 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1541 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 1594 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1542 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 1595 | 1543 |
| 1596 WTF::setTimeFunctionsForTesting(nullptr); | 1544 WTF::setTimeFunctionsForTesting(nullptr); |
| 1597 } | 1545 } |
| 1598 | 1546 |
| 1599 } // namespace | 1547 } // namespace |
| 1600 } // namespace blink | 1548 } // namespace blink |
| OLD | NEW |