| 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 327 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 328 ASSERT_EQ(client->imageChangedCount(), 2); | 328 ASSERT_EQ(client->imageChangedCount(), 2); |
| 329 ASSERT_TRUE(client->notifyFinishedCalled()); | 329 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 330 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 330 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 331 } | 331 } |
| 332 | 332 |
| 333 TEST(ImageResourceTest, ReloadIfLoFi) | 333 TEST(ImageResourceTest, ReloadIfLoFi) |
| 334 { | 334 { |
| 335 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 335 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 336 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 336 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 337 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; | 337 ResourceRequest request = ResourceRequest(testURL); |
| 338 request.setLoFiState(WebURLRequest::LoFiOn); |
| 339 ImageResource* cachedImage = ImageResource::create(request); |
| 338 cachedImage->setStatus(Resource::Pending); | 340 cachedImage->setStatus(Resource::Pending); |
| 339 | 341 |
| 340 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); | 342 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); |
| 341 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); | 343 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
| 342 | 344 |
| 343 // Send the image response. | 345 // Send the image response. |
| 344 Vector<unsigned char> jpeg = jpegImage(); | 346 Vector<unsigned char> jpeg = jpegImage(); |
| 345 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto
m, String()); | 347 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto
m, String()); |
| 346 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); | 348 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
| 347 | 349 |
| 348 cachedImage->responseReceived(resourceResponse, nullptr); | 350 cachedImage->responseReceived(resourceResponse, nullptr); |
| 349 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 351 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 350 cachedImage->finish(); | 352 cachedImage->finish(); |
| 351 ASSERT_FALSE(cachedImage->errorOccurred()); | 353 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 352 ASSERT_TRUE(cachedImage->hasImage()); | 354 ASSERT_TRUE(cachedImage->hasImage()); |
| 353 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 355 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 354 ASSERT_EQ(client->imageChangedCount(), 2); | 356 ASSERT_EQ(client->imageChangedCount(), 2); |
| 355 ASSERT_TRUE(client->notifyFinishedCalled()); | 357 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 356 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 358 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 359 EXPECT_EQ(1, cachedImage->getImage()->width()); |
| 360 EXPECT_EQ(1, cachedImage->getImage()->height()); |
| 357 | 361 |
| 358 cachedImage->reloadIfLoFi(fetcher); | 362 cachedImage->reloadIfLoFi(fetcher); |
| 359 ASSERT_FALSE(cachedImage->errorOccurred()); | 363 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 360 ASSERT_FALSE(cachedImage->resourceBuffer()); | 364 ASSERT_FALSE(cachedImage->resourceBuffer()); |
| 361 ASSERT_TRUE(cachedImage->hasImage()); | 365 ASSERT_FALSE(cachedImage->hasImage()); |
| 362 ASSERT_EQ(client->imageChangedCount(), 3); | 366 ASSERT_EQ(client->imageChangedCount(), 3); |
| 363 | 367 |
| 368 Vector<unsigned char> jpeg2 = jpegImage2(); |
| 364 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r
esourceResponse), nullptr); | 369 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r
esourceResponse), nullptr); |
| 365 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); | 370 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg2.data()), jpeg2.size(), jpeg2.size()); |
| 366 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); | 371 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg2.size()); |
| 367 ASSERT_FALSE(cachedImage->errorOccurred()); | 372 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 368 ASSERT_TRUE(cachedImage->hasImage()); | 373 ASSERT_TRUE(cachedImage->hasImage()); |
| 369 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 374 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 370 ASSERT_TRUE(client->notifyFinishedCalled()); | 375 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 371 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 376 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 377 EXPECT_EQ(50, cachedImage->getImage()->width()); |
| 378 EXPECT_EQ(50, cachedImage->getImage()->height()); |
| 372 } | 379 } |
| 373 | 380 |
| 374 TEST(ImageResourceTest, SVGImage) | 381 TEST(ImageResourceTest, SVGImage) |
| 375 { | 382 { |
| 376 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 383 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
| 377 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 384 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
| 378 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima
geResource); | 385 Persistent<MockImageResourceClient> client = new MockImageResourceClient(ima
geResource); |
| 379 | 386 |
| 380 receiveResponse(imageResource, url, "image/svg+xml", svgImage()); | 387 receiveResponse(imageResource, url, "image/svg+xml", svgImage()); |
| 381 | 388 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); | 612 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); |
| 606 | 613 |
| 607 ASSERT_TRUE(imageResource->hasImage()); | 614 ASSERT_TRUE(imageResource->hasImage()); |
| 608 EXPECT_FALSE(imageResource->getImage()->isNull()); | 615 EXPECT_FALSE(imageResource->getImage()->isNull()); |
| 609 EXPECT_EQ(1, imageResource->getImage()->width()); | 616 EXPECT_EQ(1, imageResource->getImage()->width()); |
| 610 EXPECT_EQ(1, imageResource->getImage()->height()); | 617 EXPECT_EQ(1, imageResource->getImage()->height()); |
| 611 EXPECT_TRUE(client2->notifyFinishedCalled()); | 618 EXPECT_TRUE(client2->notifyFinishedCalled()); |
| 612 } | 619 } |
| 613 | 620 |
| 614 } // namespace blink | 621 } // namespace blink |
| OLD | NEW |