| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 TEST(ImageResourceTest, MultipartImage) | 117 TEST(ImageResourceTest, MultipartImage) |
| 118 { | 118 { |
| 119 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); | 119 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
| 120 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 120 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 121 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 121 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 122 | 122 |
| 123 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. | 123 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. |
| 124 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; | 124 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; |
| 125 cachedImage->setIdentifier(createUniqueIdentifier()); | 125 cachedImage->setIdentifier(createUniqueIdentifier()); |
| 126 cachedImage->load(fetcher); | 126 fetcher->startLoad(cachedImage); |
| 127 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); | 127 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); |
| 128 | 128 |
| 129 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); | 129 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); |
| 130 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); | 130 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); |
| 131 | 131 |
| 132 // Send the multipart response. No image or data buffer is created. | 132 // Send the multipart response. No image or data buffer is created. |
| 133 // Note that the response must be routed through ResourceLoader to | 133 // Note that the response must be routed through ResourceLoader to |
| 134 // ensure the load is flagged as multipart. | 134 // ensure the load is flagged as multipart. |
| 135 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n
ullAtom, String()); | 135 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n
ullAtom, String()); |
| 136 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); | 136 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 { | 181 { |
| 182 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 182 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 183 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 183 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 184 | 184 |
| 185 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); | 185 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
| 186 | 186 |
| 187 // Emulate starting a real load. | 187 // Emulate starting a real load. |
| 188 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; | 188 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; |
| 189 cachedImage->setIdentifier(createUniqueIdentifier()); | 189 cachedImage->setIdentifier(createUniqueIdentifier()); |
| 190 | 190 |
| 191 cachedImage->load(fetcher); | 191 fetcher->startLoad(cachedImage); |
| 192 memoryCache()->add(cachedImage); | 192 memoryCache()->add(cachedImage); |
| 193 | 193 |
| 194 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); | 194 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); |
| 195 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); | 195 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); |
| 196 | 196 |
| 197 // The load should still be alive, but a timer should be started to cancel t
he load inside removeClient(). | 197 // The load should still be alive, but a timer should be started to cancel t
he load inside removeClient(). |
| 198 client->removeAsClient(); | 198 client->removeAsClient(); |
| 199 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); | 199 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); |
| 200 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); | 200 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); |
| 201 | 201 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); | 295 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); |
| 296 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); | 296 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); |
| 297 ASSERT_FALSE(cachedImage->errorOccurred()); | 297 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 298 ASSERT_TRUE(cachedImage->hasImage()); | 298 ASSERT_TRUE(cachedImage->hasImage()); |
| 299 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 299 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 300 ASSERT_TRUE(client->notifyFinishedCalled()); | 300 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 301 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 301 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 } // namespace blink | 304 } // namespace blink |
| OLD | NEW |