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

Unified Diff: Source/core/fetch/RawResourceTest.cpp

Issue 231873006: Make sure resource client is called asynchronously (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: stupid cq won't let me land Created 6 years, 8 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/fetch/Resource.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fetch/RawResourceTest.cpp
diff --git a/Source/core/fetch/RawResourceTest.cpp b/Source/core/fetch/RawResourceTest.cpp
index 3c4d009947947d01a0fb91fd109987be0a49a197..f51ff48186302589c2d58aa068ee4ec6ecd46ac9 100644
--- a/Source/core/fetch/RawResourceTest.cpp
+++ b/Source/core/fetch/RawResourceTest.cpp
@@ -47,7 +47,7 @@
using namespace WebCore;
-namespace {
+namespace WebCore {
TEST(RawResourceTest, DontIgnoreAcceptForCacheReuse)
{
@@ -86,4 +86,105 @@ TEST(RawResourceTest, RevalidationSucceeded)
EXPECT_NE(newResource.get(), newResourcePointer);
}
-} // namespace
+class DummyClient : public RawResourceClient {
+public:
+ DummyClient() : m_called(false) { }
+ virtual ~DummyClient() { }
+
+ // ResourceClient implementation.
+ virtual void notifyFinished(Resource* resource)
+ {
+ m_called = true;
+ }
+
+ bool called() { return m_called; }
+private:
+ bool m_called;
+};
+
+// This client adds another client when notified.
+class AddingClient : public RawResourceClient {
+public:
+ AddingClient(DummyClient* client, Resource* resource)
+ : m_dummyClient(client)
+ , m_resource(resource)
+ , m_removeClientTimer(this, &AddingClient::removeClient) { }
+
+ virtual ~AddingClient() { }
+
+ // ResourceClient implementation.
+ virtual void notifyFinished(Resource* resource)
+ {
+ // First schedule an asynchronous task to remove the client.
+ // We do not expect the client to be called.
+ m_removeClientTimer.startOneShot(0, FROM_HERE);
+ resource->addClient(m_dummyClient);
+ }
+ void removeClient(Timer<AddingClient>* timer)
+ {
+ m_resource->removeClient(m_dummyClient);
+ }
+private:
+ DummyClient* m_dummyClient;
+ Resource* m_resource;
+ Timer<AddingClient> m_removeClientTimer;
+};
+
+TEST(RawResourceTest, AddClientDuringCallback)
+{
+ ResourcePtr<Resource> raw = new RawResource(ResourceRequest("data:text/html,"), Resource::Raw);
+ raw->setLoading(false);
+
+ // Create a non-null response.
+ ResourceResponse response = raw->response();
+ response.setURL(KURL(ParsedURLString, "http://600.613/"));
+ raw->setResponse(response);
+ EXPECT_FALSE(raw->response().isNull());
+
+ OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient());
+ OwnPtr<AddingClient> addingClient = adoptPtr(new AddingClient(dummyClient.get(), raw.get()));
+ raw->addClient(addingClient.get());
+ testing::runPendingTasks();
+ raw->removeClient(addingClient.get());
+ EXPECT_FALSE(dummyClient->called());
+ EXPECT_FALSE(raw->hasClients());
+}
+
+// This client removes another client when notified.
+class RemovingClient : public RawResourceClient {
+public:
+ RemovingClient(DummyClient* client)
+ : m_dummyClient(client) { }
+
+ virtual ~RemovingClient() { }
+
+ // ResourceClient implementation.
+ virtual void notifyFinished(Resource* resource)
+ {
+ resource->removeClient(m_dummyClient);
+ resource->removeClient(this);
+ }
+private:
+ DummyClient* m_dummyClient;
+};
+
+TEST(RawResourceTest, RemoveClientDuringCallback)
+{
+ ResourcePtr<Resource> raw = new RawResource(ResourceRequest("data:text/html,"), Resource::Raw);
+ raw->setLoading(false);
+
+ // Create a non-null response.
+ ResourceResponse response = raw->response();
+ response.setURL(KURL(ParsedURLString, "http://600.613/"));
+ raw->setResponse(response);
+ EXPECT_FALSE(raw->response().isNull());
+
+ OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient());
+ OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyClient.get()));
+ raw->addClient(dummyClient.get());
+ raw->addClient(removingClient.get());
+ testing::runPendingTasks();
+ EXPECT_FALSE(raw->hasClients());
+}
+
+} // namespace WebCore
« no previous file with comments | « no previous file | Source/core/fetch/Resource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698