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

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: comments 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..6144f201457b80facab488c1ba7fddf2b2f19ce7 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,67 @@ 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 TrickyClient : public RawResourceClient {
+public:
+ TrickyClient(DummyClient* client, Resource* resource)
+ : m_dummyClient(client)
Nate Chapin 2014/04/10 17:36:10 Nit: indent intializers.
Alpha Left Google 2014/04/10 18:26:23 Done.
+ , m_resource(resource)
+ , m_removeClientTimer(this, &TrickyClient::removeClient) { }
+
+ virtual ~TrickyClient() { }
+
+ // ResourceClient implementation.
+ virtual void notifyFinished(Resource* resource)
+ {
+ // First schedule an asynchronous task to remove the client and delete the resource.
+ // We do not expect the client to be called.
+ m_removeClientTimer.startOneShot(0, FROM_HERE);
+ resource->addClient(m_dummyClient);
+ }
+ void removeClient(Timer<TrickyClient>* timer)
+ {
+ m_resource->removeClient(m_dummyClient);
+ }
+private:
+ DummyClient* m_dummyClient;
+ Resource* m_resource;
+ Timer<TrickyClient> m_removeClientTimer;
+};
+
+TEST(RawResourceTest, AddClientDuringCallback)
+{
+ RawResource* raw = new RawResource(ResourceRequest("data:text/html,"), Resource::Raw);
+ ResourcePtr<Resource> rawOwner = raw;
Nate Chapin 2014/04/10 17:36:10 Nit: You should be able to merge these two lines a
Alpha Left Google 2014/04/10 18:26:23 Done.
+ 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<TrickyClient> trickClient = adoptPtr(new TrickyClient(dummyClient.get(), rawOwner.get()));
+ raw->addClient(trickClient.get());
+ testing::runPendingTasks();
+ EXPECT_FALSE(dummyClient->called());
+}
+
+} // 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