Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1531)

Unified Diff: Source/core/loader/cache/CachedImageTest.cpp

Issue 17436003: Evict CachedResources if they are cancelled due to last client being removed. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/core/loader/cache/CachedResource.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/loader/cache/CachedImageTest.cpp
diff --git a/Source/core/loader/cache/CachedImageTest.cpp b/Source/core/loader/cache/CachedImageTest.cpp
index 1468726ec467cf0cb5b74bb38461552dfbd4b3d4..b9472992d78e20d53d1e485d2162d47204368eb3 100644
--- a/Source/core/loader/cache/CachedImageTest.cpp
+++ b/Source/core/loader/cache/CachedImageTest.cpp
@@ -31,10 +31,19 @@
#include "config.h"
#include "core/loader/cache/CachedImage.h"
+#include "core/loader/DocumentLoader.h"
+#include "core/loader/EmptyClients.h"
#include "core/loader/cache/CachedImageClient.h"
#include "core/loader/cache/CachedResourceHandle.h"
+#include "core/loader/cache/CachedResourceLoader.h"
+#include "core/loader/cache/MemoryCache.h"
+#include "core/page/Frame.h"
+#include "core/page/FrameView.h"
+#include "core/page/Page.h"
#include "core/platform/SharedBuffer.h"
#include "core/platform/graphics/Image.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebThread.h"
#include <gtest/gtest.h>
using namespace WebCore;
@@ -69,6 +78,20 @@ private:
bool m_notifyFinishedCalled;
};
+class QuitTask : public WebKit::WebThread::Task {
+public:
+ virtual void run()
+ {
+ WebKit::Platform::current()->currentThread()->exitRunLoop();
+ }
+};
+
+void runPendingTasks()
+{
+ WebKit::Platform::current()->currentThread()->postTask(new QuitTask);
+ WebKit::Platform::current()->currentThread()->enterRunLoop();
+}
+
TEST(CachedImageTest, MultipartImage)
{
CachedResourceHandle<CachedImage> cachedImage = new CachedImage(ResourceRequest());
@@ -113,4 +136,38 @@ TEST(CachedImageTest, MultipartImage)
ASSERT_TRUE(client.notifyFinishedCalled());
}
+TEST(CachedImageTest, CancelOnDetach)
+{
+ // Create enough of a mocked world to get a functioning ResourceLoader.
+ KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
+ Page::PageClients pageClients;
+ fillWithEmptyClients(pageClients);
+ EmptyFrameLoaderClient frameLoaderClient;
+ Page page(pageClients);
+ RefPtr<Frame> frame = Frame::create(&page, 0, &frameLoaderClient);
+ frame->setView(FrameView::create(frame.get()));
+ frame->init();
+ RefPtr<DocumentLoader> documentLoader = DocumentLoader::create(ResourceRequest(testURL), SubstituteData());
+ documentLoader->setFrame(frame.get());
+
+ // Emulate starting a real load.
+ CachedResourceHandle<CachedImage> cachedImage = new CachedImage(ResourceRequest(testURL));
+ cachedImage->load(documentLoader->cachedResourceLoader(), ResourceLoaderOptions());
+ memoryCache()->add(cachedImage.get());
+
+ MockCachedImageClient client;
+ cachedImage->addClient(&client);
+ EXPECT_EQ(CachedResource::Pending, cachedImage->status());
+
+ // The load should still be alive, but a timer should be started to cancel the load inside removeClient().
+ cachedImage->removeClient(&client);
+ EXPECT_EQ(CachedResource::Pending, cachedImage->status());
+ EXPECT_NE(reinterpret_cast<CachedResource*>(0), memoryCache()->resourceForURL(testURL));
+
+ // Trigger the cancel timer, ensure the load was cancelled and the resource was evicted from the cache.
+ runPendingTasks();
+ EXPECT_EQ(CachedResource::LoadError, cachedImage->status());
+ EXPECT_EQ(reinterpret_cast<CachedResource*>(0), memoryCache()->resourceForURL(testURL));
+}
+
} // namespace
« no previous file with comments | « no previous file | Source/core/loader/cache/CachedResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698