| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 ResourceResponse response; | 77 ResourceResponse response; |
| 78 response.setHTTPStatusCode(304); | 78 response.setHTTPStatusCode(304); |
| 79 newResource->responseReceived(response, nullptr); | 79 newResource->responseReceived(response, nullptr); |
| 80 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), oldResource.get()); | 80 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), oldResource.get()); |
| 81 EXPECT_EQ(oldResource.get(), newResource.get()); | 81 EXPECT_EQ(oldResource.get(), newResource.get()); |
| 82 EXPECT_NE(newResource.get(), newResourcePointer); | 82 EXPECT_NE(newResource.get(), newResourcePointer); |
| 83 } | 83 } |
| 84 | 84 |
| 85 class DummyClient : public RawResourceClient { | 85 class DummyClient : public RawResourceClient { |
| 86 public: | 86 public: |
| 87 DummyClient() : m_called(false) { } | 87 DummyClient() : m_called(false) {} |
| 88 virtual ~DummyClient() { } | 88 ~DummyClient() override {} |
| 89 | 89 |
| 90 // ResourceClient implementation. | 90 // ResourceClient implementation. |
| 91 virtual void notifyFinished(Resource* resource) | 91 virtual void notifyFinished(Resource* resource) |
| 92 { | 92 { |
| 93 m_called = true; | 93 m_called = true; |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool called() { return m_called; } | 96 bool called() { return m_called; } |
| 97 private: | 97 private: |
| 98 bool m_called; | 98 bool m_called; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 // This client adds another client when notified. | 101 // This client adds another client when notified. |
| 102 class AddingClient : public RawResourceClient { | 102 class AddingClient : public RawResourceClient { |
| 103 public: | 103 public: |
| 104 AddingClient(DummyClient* client, Resource* resource) | 104 AddingClient(DummyClient* client, Resource* resource) |
| 105 : m_dummyClient(client) | 105 : m_dummyClient(client) |
| 106 , m_resource(resource) | 106 , m_resource(resource) |
| 107 , m_removeClientTimer(this, &AddingClient::removeClient) { } | 107 , m_removeClientTimer(this, &AddingClient::removeClient) {} |
| 108 | 108 |
| 109 virtual ~AddingClient() { } | 109 ~AddingClient() override {} |
| 110 | 110 |
| 111 // ResourceClient implementation. | 111 // ResourceClient implementation. |
| 112 virtual void notifyFinished(Resource* resource) | 112 virtual void notifyFinished(Resource* resource) |
| 113 { | 113 { |
| 114 // First schedule an asynchronous task to remove the client. | 114 // First schedule an asynchronous task to remove the client. |
| 115 // We do not expect the client to be called. | 115 // We do not expect the client to be called. |
| 116 m_removeClientTimer.startOneShot(0, FROM_HERE); | 116 m_removeClientTimer.startOneShot(0, FROM_HERE); |
| 117 resource->addClient(m_dummyClient); | 117 resource->addClient(m_dummyClient); |
| 118 } | 118 } |
| 119 void removeClient(Timer<AddingClient>* timer) | 119 void removeClient(Timer<AddingClient>* timer) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 143 testing::runPendingTasks(); | 143 testing::runPendingTasks(); |
| 144 raw->removeClient(addingClient.get()); | 144 raw->removeClient(addingClient.get()); |
| 145 EXPECT_FALSE(dummyClient->called()); | 145 EXPECT_FALSE(dummyClient->called()); |
| 146 EXPECT_FALSE(raw->hasClients()); | 146 EXPECT_FALSE(raw->hasClients()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // This client removes another client when notified. | 149 // This client removes another client when notified. |
| 150 class RemovingClient : public RawResourceClient { | 150 class RemovingClient : public RawResourceClient { |
| 151 public: | 151 public: |
| 152 RemovingClient(DummyClient* client) | 152 RemovingClient(DummyClient* client) |
| 153 : m_dummyClient(client) { } | 153 : m_dummyClient(client) {} |
| 154 | 154 |
| 155 virtual ~RemovingClient() { } | 155 ~RemovingClient() override {} |
| 156 | 156 |
| 157 // ResourceClient implementation. | 157 // ResourceClient implementation. |
| 158 virtual void notifyFinished(Resource* resource) | 158 virtual void notifyFinished(Resource* resource) |
| 159 { | 159 { |
| 160 resource->removeClient(m_dummyClient); | 160 resource->removeClient(m_dummyClient); |
| 161 resource->removeClient(this); | 161 resource->removeClient(this); |
| 162 } | 162 } |
| 163 private: | 163 private: |
| 164 DummyClient* m_dummyClient; | 164 DummyClient* m_dummyClient; |
| 165 }; | 165 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 177 | 177 |
| 178 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); | 178 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); |
| 179 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); | 179 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); |
| 180 raw->addClient(dummyClient.get()); | 180 raw->addClient(dummyClient.get()); |
| 181 raw->addClient(removingClient.get()); | 181 raw->addClient(removingClient.get()); |
| 182 testing::runPendingTasks(); | 182 testing::runPendingTasks(); |
| 183 EXPECT_FALSE(raw->hasClients()); | 183 EXPECT_FALSE(raw->hasClients()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace blink | 186 } // namespace blink |
| OLD | NEW |