Chromium Code Reviews| 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 |