| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 87 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 88 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 88 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 89 | 89 |
| 90 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. | 90 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. |
| 91 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(testURL), nullptr); | 91 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(testURL), nullptr); |
| 92 cachedImage->setIdentifier(createUniqueIdentifier()); | 92 cachedImage->setIdentifier(createUniqueIdentifier()); |
| 93 cachedImage->load(fetcher, ResourceLoaderOptions()); | 93 cachedImage->load(fetcher, ResourceLoaderOptions()); |
| 94 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); | 94 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); |
| 95 | 95 |
| 96 MockImageResourceClient client(cachedImage); | 96 MockImageResourceClient client(cachedImage); |
| 97 EXPECT_EQ(Resource::Pending, cachedImage->status()); | 97 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); |
| 98 | 98 |
| 99 // Send the multipart response. No image or data buffer is created. | 99 // Send the multipart response. No image or data buffer is created. |
| 100 // Note that the response must be routed through ResourceLoader to | 100 // Note that the response must be routed through ResourceLoader to |
| 101 // ensure the load is flagged as multipart. | 101 // ensure the load is flagged as multipart. |
| 102 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n
ullAtom, String()); | 102 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n
ullAtom, String()); |
| 103 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(m
ultipartResponse), nullptr); | 103 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(m
ultipartResponse), nullptr); |
| 104 ASSERT_FALSE(cachedImage->resourceBuffer()); | 104 ASSERT_FALSE(cachedImage->resourceBuffer()); |
| 105 ASSERT_FALSE(cachedImage->hasImage()); | 105 ASSERT_FALSE(cachedImage->hasImage()); |
| 106 ASSERT_EQ(client.imageChangedCount(), 0); | 106 ASSERT_EQ(client.imageChangedCount(), 0); |
| 107 ASSERT_FALSE(client.notifyFinishedCalled()); | 107 ASSERT_FALSE(client.notifyFinishedCalled()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); | 144 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); |
| 145 | 145 |
| 146 // Emulate starting a real load. | 146 // Emulate starting a real load. |
| 147 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(testURL), nullptr); | 147 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(testURL), nullptr); |
| 148 cachedImage->setIdentifier(createUniqueIdentifier()); | 148 cachedImage->setIdentifier(createUniqueIdentifier()); |
| 149 | 149 |
| 150 cachedImage->load(fetcher, ResourceLoaderOptions()); | 150 cachedImage->load(fetcher, ResourceLoaderOptions()); |
| 151 memoryCache()->add(cachedImage.get()); | 151 memoryCache()->add(cachedImage.get()); |
| 152 | 152 |
| 153 MockImageResourceClient client(cachedImage); | 153 MockImageResourceClient client(cachedImage); |
| 154 EXPECT_EQ(Resource::Pending, cachedImage->status()); | 154 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); |
| 155 | 155 |
| 156 // The load should still be alive, but a timer should be started to cancel t
he load inside removeClient(). | 156 // The load should still be alive, but a timer should be started to cancel t
he load inside removeClient(). |
| 157 client.removeAsClient(); | 157 client.removeAsClient(); |
| 158 EXPECT_EQ(Resource::Pending, cachedImage->status()); | 158 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); |
| 159 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); | 159 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); |
| 160 | 160 |
| 161 // Trigger the cancel timer, ensure the load was cancelled and the resource
was evicted from the cache. | 161 // Trigger the cancel timer, ensure the load was cancelled and the resource
was evicted from the cache. |
| 162 blink::testing::runPendingTasks(); | 162 blink::testing::runPendingTasks(); |
| 163 EXPECT_EQ(Resource::LoadError, cachedImage->status()); | 163 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus()); |
| 164 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); | 164 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); |
| 165 | 165 |
| 166 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); | 166 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) | 169 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) |
| 170 { | 170 { |
| 171 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); | 171 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); |
| 172 cachedImage->setLoading(true); | 172 cachedImage->setLoading(true); |
| 173 | 173 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 254 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 255 cachedImage->finish(); | 255 cachedImage->finish(); |
| 256 ASSERT_FALSE(cachedImage->errorOccurred()); | 256 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 257 ASSERT_TRUE(cachedImage->hasImage()); | 257 ASSERT_TRUE(cachedImage->hasImage()); |
| 258 ASSERT_FALSE(cachedImage->image()->isNull()); | 258 ASSERT_FALSE(cachedImage->image()->isNull()); |
| 259 ASSERT_TRUE(client.notifyFinishedCalled()); | 259 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 260 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); | 260 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 } // namespace blink | 263 } // namespace blink |
| OLD | NEW |