Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 44 #include "public/platform/WebURL.h" | 44 #include "public/platform/WebURL.h" |
| 45 #include "public/platform/WebURLLoaderMockFactory.h" | 45 #include "public/platform/WebURLLoaderMockFactory.h" |
| 46 #include "public/platform/WebURLResponse.h" | 46 #include "public/platform/WebURLResponse.h" |
| 47 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
| 48 #include "wtf/PtrUtil.h" | 48 #include "wtf/PtrUtil.h" |
| 49 #include <memory> | 49 #include <memory> |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 | 52 |
| 53 namespace { | |
| 54 | |
| 55 // An image of size 1x1. | |
| 53 static Vector<unsigned char> jpegImage() | 56 static Vector<unsigned char> jpegImage() |
| 54 { | 57 { |
| 55 Vector<unsigned char> jpeg; | 58 Vector<unsigned char> jpeg; |
| 56 | 59 |
| 57 static const unsigned char data[] = { | 60 static const unsigned char data[] = { |
| 58 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, | 61 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, |
| 59 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, | 62 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, |
| 60 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0xff, 0xdb, 0x00, 0x43, | 63 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0xff, 0xdb, 0x00, 0x43, |
| 61 0x00, 0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, | 64 0x00, 0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, |
| 62 0x07, 0x0c, 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, 0x09, 0x0c, 0x11, 0x0f, 0x12, | 65 0x07, 0x0c, 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, 0x09, 0x0c, 0x11, 0x0f, 0x12, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11, | 78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11, |
| 76 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 79 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 77 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, | 80 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, |
| 78 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9 | 81 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9 |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 jpeg.append(data, sizeof(data)); | 84 jpeg.append(data, sizeof(data)); |
| 82 return jpeg; | 85 return jpeg; |
| 83 } | 86 } |
| 84 | 87 |
| 85 namespace { | 88 // An image of size 50x50. |
| 89 static Vector<unsigned char> jpegImage2() | |
| 90 { | |
| 91 Vector<unsigned char> jpeg; | |
| 92 | |
| 93 static const unsigned char data[] = { | |
| 94 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x48, | |
| 95 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
| 96 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
| 97 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
| 98 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
| 99 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, | |
| 100 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
| 101 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
| 102 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
| 103 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, | |
| 104 0x00, 0x11, 0x08, 0x00, 0x32, 0x00, 0x32, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, | |
| 105 0x01, 0xff, 0xc4, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
| 106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x10, 0x01, 0x00, 0x00, 0x00, | |
| 107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, | |
| 108 0x15, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
| 109 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
| 110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, | |
| 111 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x00, 0x94, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, | |
| 112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
| 113 0x03, 0xff, 0xd9 | |
| 114 }; | |
| 115 | |
| 116 jpeg.append(data, sizeof(data)); | |
| 117 return jpeg; | |
| 118 } | |
| 119 | |
| 120 static Vector<unsigned char> svgImage() | |
| 121 { | |
| 122 static const char data[] = | |
| 123 "<svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" | |
| 124 "<rect x=\"0\" y=\"0\" width=\"100px\" height=\"100px\" fill=\"red\"/>" | |
| 125 "</svg>"; | |
| 126 | |
| 127 Vector<unsigned char> svg; | |
| 128 svg.append(data, strlen(data)); | |
| 129 return svg; | |
| 130 } | |
| 131 | |
| 132 static Vector<unsigned char> svgImage2() | |
| 133 { | |
| 134 static const char data[] = | |
| 135 "<svg width=\"300\" height=\"300\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" | |
| 136 "<rect x=\"0\" y=\"0\" width=\"200px\" height=\"200px\" fill=\"green\"/> " | |
| 137 "</svg>"; | |
| 138 | |
| 139 Vector<unsigned char> svg; | |
| 140 svg.append(data, strlen(data)); | |
| 141 return svg; | |
| 142 } | |
| 143 | |
| 144 void receiveResponse(ImageResource* imageResource, const KURL& url, const Atomic String& mimeType, const Vector<unsigned char>& data) | |
| 145 { | |
| 146 ResourceResponse response; | |
| 147 response.setURL(url); | |
| 148 response.setHTTPStatusCode(200); | |
| 149 response.setMimeType(mimeType); | |
| 150 imageResource->responseReceived(response, nullptr); | |
| 151 imageResource->appendData(reinterpret_cast<const char*>(data.data()), data.s ize()); | |
| 152 imageResource->finish(); | |
| 153 } | |
| 86 | 154 |
| 87 class MockTaskRunner : public blink::WebTaskRunner { | 155 class MockTaskRunner : public blink::WebTaskRunner { |
| 88 void postTask(const WebTraceLocation&, Task*) override { } | 156 void postTask(const WebTraceLocation&, Task*) override { } |
| 89 void postDelayedTask(const WebTraceLocation&, Task*, double) override { } | 157 void postDelayedTask(const WebTraceLocation&, Task*, double) override { } |
| 90 WebTaskRunner* clone() override { return nullptr; } | 158 WebTaskRunner* clone() override { return nullptr; } |
| 91 double virtualTimeSeconds() const override { return 0.0; } | 159 double virtualTimeSeconds() const override { return 0.0; } |
| 92 double monotonicallyIncreasingVirtualTimeSeconds() const override { return 0 .0; } | 160 double monotonicallyIncreasingVirtualTimeSeconds() const override { return 0 .0; } |
| 93 }; | 161 }; |
| 94 | 162 |
| 95 } | 163 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r esourceResponse), nullptr); | 364 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r esourceResponse), nullptr); |
| 297 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*> (jpeg.data()), jpeg.size(), jpeg.size()); | 365 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*> (jpeg.data()), jpeg.size(), jpeg.size()); |
| 298 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); | 366 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); |
| 299 ASSERT_FALSE(cachedImage->errorOccurred()); | 367 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 300 ASSERT_TRUE(cachedImage->hasImage()); | 368 ASSERT_TRUE(cachedImage->hasImage()); |
| 301 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 369 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 302 ASSERT_TRUE(client->notifyFinishedCalled()); | 370 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 303 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 371 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 304 } | 372 } |
| 305 | 373 |
| 374 TEST(ImageResourceTest, SVGImage) | |
| 375 { | |
| 376 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | |
| 377 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | |
| 378 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima geResource); | |
| 379 | |
| 380 receiveResponse(imageResource, url, "image/svg+xml", svgImage()); | |
| 381 | |
| 382 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 383 ASSERT_TRUE(imageResource->hasImage()); | |
| 384 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 385 EXPECT_EQ(1, client->imageChangedCount()); | |
| 386 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 387 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | |
| 388 } | |
| 389 | |
| 390 TEST(ImageResourceTest, SuccessfulRevalidationJpeg) | |
| 391 { | |
| 392 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | |
| 393 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | |
| 394 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima geResource); | |
| 395 | |
| 396 receiveResponse(imageResource, url, "image/jpeg", jpegImage()); | |
| 397 | |
| 398 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 399 ASSERT_TRUE(imageResource->hasImage()); | |
| 400 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 401 EXPECT_EQ(2, client->imageChangedCount()); | |
| 402 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 403 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | |
| 404 EXPECT_EQ(1, imageResource->getImage()->width()); | |
| 405 EXPECT_EQ(1, imageResource->getImage()->height()); | |
| 406 | |
| 407 imageResource->setRevalidatingRequest(ResourceRequest(url)); | |
| 408 ResourceResponse response; | |
| 409 response.setURL(url); | |
| 410 response.setHTTPStatusCode(304); | |
| 411 | |
| 412 imageResource->responseReceived(response, nullptr); | |
| 413 | |
| 414 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 415 ASSERT_TRUE(imageResource->hasImage()); | |
| 416 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 417 EXPECT_EQ(2, client->imageChangedCount()); | |
| 418 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 419 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | |
| 420 EXPECT_EQ(1, imageResource->getImage()->width()); | |
| 421 EXPECT_EQ(1, imageResource->getImage()->height()); | |
| 422 } | |
| 423 | |
| 424 TEST(ImageResourceTest, SuccessfulRevalidationSvg) | |
| 425 { | |
| 426 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | |
| 427 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | |
| 428 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima geResource); | |
| 429 | |
| 430 receiveResponse(imageResource, url, "image/svg+xml", svgImage()); | |
| 431 | |
| 432 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 433 ASSERT_TRUE(imageResource->hasImage()); | |
| 434 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 435 EXPECT_EQ(1, client->imageChangedCount()); | |
| 436 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 437 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | |
| 438 EXPECT_EQ(200, imageResource->getImage()->width()); | |
| 439 EXPECT_EQ(200, imageResource->getImage()->height()); | |
| 440 | |
| 441 imageResource->setRevalidatingRequest(ResourceRequest(url)); | |
| 442 ResourceResponse response; | |
| 443 response.setURL(url); | |
| 444 response.setHTTPStatusCode(304); | |
| 445 imageResource->responseReceived(response, nullptr); | |
| 446 | |
| 447 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 448 ASSERT_TRUE(imageResource->hasImage()); | |
| 449 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 450 EXPECT_EQ(1, client->imageChangedCount()); | |
| 451 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 452 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | |
| 453 EXPECT_EQ(200, imageResource->getImage()->width()); | |
| 454 EXPECT_EQ(200, imageResource->getImage()->height()); | |
| 455 } | |
| 456 | |
| 457 TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) | |
| 458 { | |
| 459 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | |
| 460 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | |
| 461 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima geResource); | |
| 462 | |
| 463 receiveResponse(imageResource, url, "image/jpeg", jpegImage()); | |
| 464 | |
| 465 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 466 ASSERT_TRUE(imageResource->hasImage()); | |
| 467 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 468 EXPECT_EQ(2, client->imageChangedCount()); | |
| 469 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 470 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | |
| 471 EXPECT_EQ(1, imageResource->getImage()->width()); | |
| 472 EXPECT_EQ(1, imageResource->getImage()->height()); | |
| 473 | |
| 474 imageResource->setRevalidatingRequest(ResourceRequest(url)); | |
| 475 receiveResponse(imageResource, url, "image/jpeg", jpegImage2()); | |
| 476 | |
| 477 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 478 ASSERT_TRUE(imageResource->hasImage()); | |
| 479 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 480 EXPECT_EQ(4, client->imageChangedCount()); | |
|
Yoav Weiss
2016/07/04 08:28:10
hmm, why is that 4?
hiroshige
2016/07/04 09:02:10
For each of the first response (jpegImage()) and t
| |
| 481 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 482 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | |
| 483 EXPECT_EQ(50, imageResource->getImage()->width()); | |
| 484 EXPECT_EQ(50, imageResource->getImage()->height()); | |
| 485 } | |
| 486 | |
| 487 TEST(ImageResourceTest, FailedRevalidationJpegToSvg) | |
| 488 { | |
| 489 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | |
| 490 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | |
| 491 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima geResource); | |
| 492 | |
| 493 receiveResponse(imageResource, url, "image/jpeg", jpegImage()); | |
| 494 | |
| 495 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 496 ASSERT_TRUE(imageResource->hasImage()); | |
| 497 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 498 EXPECT_EQ(2, client->imageChangedCount()); | |
| 499 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 500 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | |
| 501 EXPECT_EQ(1, imageResource->getImage()->width()); | |
| 502 EXPECT_EQ(1, imageResource->getImage()->height()); | |
| 503 | |
| 504 imageResource->setRevalidatingRequest(ResourceRequest(url)); | |
| 505 receiveResponse(imageResource, url, "image/svg+xml", svgImage()); | |
| 506 | |
| 507 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 508 ASSERT_TRUE(imageResource->hasImage()); | |
| 509 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 510 EXPECT_EQ(3, client->imageChangedCount()); | |
| 511 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 512 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | |
| 513 EXPECT_EQ(200, imageResource->getImage()->width()); | |
| 514 EXPECT_EQ(200, imageResource->getImage()->height()); | |
| 515 } | |
| 516 | |
| 517 TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) | |
| 518 { | |
| 519 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | |
| 520 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | |
| 521 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima geResource); | |
| 522 | |
| 523 receiveResponse(imageResource, url, "image/svg+xml", svgImage()); | |
| 524 | |
| 525 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 526 ASSERT_TRUE(imageResource->hasImage()); | |
| 527 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 528 EXPECT_EQ(1, client->imageChangedCount()); | |
| 529 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 530 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | |
| 531 EXPECT_EQ(200, imageResource->getImage()->width()); | |
| 532 EXPECT_EQ(200, imageResource->getImage()->height()); | |
| 533 | |
| 534 imageResource->setRevalidatingRequest(ResourceRequest(url)); | |
| 535 receiveResponse(imageResource, url, "image/jpeg", jpegImage()); | |
| 536 | |
| 537 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 538 ASSERT_TRUE(imageResource->hasImage()); | |
| 539 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 540 EXPECT_EQ(3, client->imageChangedCount()); | |
| 541 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 542 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | |
| 543 EXPECT_EQ(1, imageResource->getImage()->width()); | |
| 544 EXPECT_EQ(1, imageResource->getImage()->height()); | |
| 545 } | |
| 546 | |
| 547 TEST(ImageResourceTest, FailedRevalidationSvgToSvg) | |
| 548 { | |
| 549 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | |
| 550 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | |
| 551 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima geResource); | |
| 552 | |
| 553 receiveResponse(imageResource, url, "image/svg+xml", svgImage()); | |
| 554 | |
| 555 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 556 ASSERT_TRUE(imageResource->hasImage()); | |
| 557 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 558 EXPECT_EQ(client->imageChangedCount(), 1); | |
| 559 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 560 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | |
| 561 EXPECT_EQ(200, imageResource->getImage()->width()); | |
| 562 EXPECT_EQ(200, imageResource->getImage()->height()); | |
| 563 | |
| 564 imageResource->setRevalidatingRequest(ResourceRequest(url)); | |
| 565 receiveResponse(imageResource, url, "image/svg+xml", svgImage2()); | |
| 566 | |
| 567 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 568 ASSERT_TRUE(imageResource->hasImage()); | |
| 569 EXPECT_FALSE(imageResource->getImage()->isNull()); | |
| 570 EXPECT_EQ(2, client->imageChangedCount()); | |
| 571 EXPECT_TRUE(client->notifyFinishedCalled()); | |
| 572 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | |
| 573 EXPECT_EQ(300, imageResource->getImage()->width()); | |
| 574 EXPECT_EQ(300, imageResource->getImage()->height()); | |
| 575 } | |
| 576 | |
| 306 } // namespace blink | 577 } // namespace blink |
| OLD | NEW |