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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 ASSERT_TRUE(cachedImage->hasImage()); | 122 ASSERT_TRUE(cachedImage->hasImage()); |
123 ASSERT_FALSE(cachedImage->image()->isNull()); | 123 ASSERT_FALSE(cachedImage->image()->isNull()); |
124 ASSERT_EQ(cachedImage->image()->width(), 1); | 124 ASSERT_EQ(cachedImage->image()->width(), 1); |
125 ASSERT_EQ(cachedImage->image()->height(), 1); | 125 ASSERT_EQ(cachedImage->image()->height(), 1); |
126 ASSERT_EQ(client.imageChangedCount(), 2); | 126 ASSERT_EQ(client.imageChangedCount(), 2); |
127 ASSERT_TRUE(client.notifyFinishedCalled()); | 127 ASSERT_TRUE(client.notifyFinishedCalled()); |
128 } | 128 } |
129 | 129 |
130 TEST(ImageResourceTest, CancelOnDetach) | 130 TEST(ImageResourceTest, CancelOnDetach) |
131 { | 131 { |
| 132 const String cacheIdentifier = MemoryCache::defaultCacheIdentifier(); |
132 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 133 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
133 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 134 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
134 | 135 |
135 // Create enough of a mocked world to get a functioning ResourceLoader. | 136 // Create enough of a mocked world to get a functioning ResourceLoader. |
136 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(); | 137 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(); |
137 RefPtr<DocumentLoader> documentLoader = DocumentLoader::create(&dummyPageHol
der->frame(), ResourceRequest(testURL), SubstituteData()); | 138 RefPtr<DocumentLoader> documentLoader = DocumentLoader::create(&dummyPageHol
der->frame(), ResourceRequest(testURL), SubstituteData()); |
138 | 139 |
139 // Emulate starting a real load. | 140 // Emulate starting a real load. |
140 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest(t
estURL)); | 141 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest(t
estURL)); |
141 cachedImage->setIdentifier(createUniqueIdentifier()); | 142 cachedImage->setIdentifier(createUniqueIdentifier()); |
142 | 143 |
143 cachedImage->load(documentLoader->fetcher(), ResourceLoaderOptions()); | 144 cachedImage->load(documentLoader->fetcher(), ResourceLoaderOptions()); |
144 memoryCache()->add(cachedImage.get()); | 145 memoryCache()->add(cachedImage.get()); |
145 | 146 |
146 MockImageResourceClient client; | 147 MockImageResourceClient client; |
147 cachedImage->addClient(&client); | 148 cachedImage->addClient(&client); |
148 EXPECT_EQ(Resource::Pending, cachedImage->status()); | 149 EXPECT_EQ(Resource::Pending, cachedImage->status()); |
149 | 150 |
150 // The load should still be alive, but a timer should be started to cancel t
he load inside removeClient(). | 151 // The load should still be alive, but a timer should be started to cancel t
he load inside removeClient(). |
151 cachedImage->removeClient(&client); | 152 cachedImage->removeClient(&client); |
152 EXPECT_EQ(Resource::Pending, cachedImage->status()); | 153 EXPECT_EQ(Resource::Pending, cachedImage->status()); |
153 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); | 154 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(cach
eIdentifier, testURL)); |
154 | 155 |
155 // Trigger the cancel timer, ensure the load was cancelled and the resource
was evicted from the cache. | 156 // Trigger the cancel timer, ensure the load was cancelled and the resource
was evicted from the cache. |
156 blink::testing::runPendingTasks(); | 157 blink::testing::runPendingTasks(); |
157 EXPECT_EQ(Resource::LoadError, cachedImage->status()); | 158 EXPECT_EQ(Resource::LoadError, cachedImage->status()); |
158 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); | 159 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(cach
eIdentifier, testURL)); |
159 | 160 |
160 blink::Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); | 161 blink::Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); |
161 } | 162 } |
162 | 163 |
163 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) | 164 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) |
164 { | 165 { |
165 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest()
); | 166 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest()
); |
166 cachedImage->setLoading(true); | 167 cachedImage->setLoading(true); |
167 | 168 |
168 MockImageResourceClient client; | 169 MockImageResourceClient client; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 bitmapImages.add(cachedImage.get()); | 221 bitmapImages.add(cachedImage.get()); |
221 | 222 |
222 // Updating bitmap resources produces image changed callbacks on their clien
ts. | 223 // Updating bitmap resources produces image changed callbacks on their clien
ts. |
223 ImageResource::updateBitmapImages(bitmapImages); | 224 ImageResource::updateBitmapImages(bitmapImages); |
224 ASSERT_EQ(client.imageChangedCount(), 2); | 225 ASSERT_EQ(client.imageChangedCount(), 2); |
225 ImageResource::updateBitmapImages(bitmapImages, true); | 226 ImageResource::updateBitmapImages(bitmapImages, true); |
226 ASSERT_EQ(client.imageChangedCount(), 3); | 227 ASSERT_EQ(client.imageChangedCount(), 3); |
227 } | 228 } |
228 | 229 |
229 } // namespace | 230 } // namespace |
OLD | NEW |