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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); | 82 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); |
83 memoryCache()->remove(resource.get()); | 83 memoryCache()->remove(resource.get()); |
84 } | 84 } |
85 | 85 |
86 class DummyClient : public RawResourceClient { | 86 class DummyClient : public RawResourceClient { |
87 public: | 87 public: |
88 DummyClient() : m_called(false) {} | 88 DummyClient() : m_called(false) {} |
89 ~DummyClient() override {} | 89 ~DummyClient() override {} |
90 | 90 |
91 // ResourceClient implementation. | 91 // ResourceClient implementation. |
92 virtual void notifyFinished(Resource* resource) | 92 void notifyFinished(Resource* resource) override |
93 { | 93 { |
94 m_called = true; | 94 m_called = true; |
95 } | 95 } |
| 96 String debugName() const override { return "DummyClient"; } |
96 | 97 |
97 bool called() { return m_called; } | 98 bool called() { return m_called; } |
98 private: | 99 private: |
99 bool m_called; | 100 bool m_called; |
100 }; | 101 }; |
101 | 102 |
102 // This client adds another client when notified. | 103 // This client adds another client when notified. |
103 class AddingClient : public RawResourceClient { | 104 class AddingClient : public RawResourceClient { |
104 public: | 105 public: |
105 AddingClient(DummyClient* client, Resource* resource) | 106 AddingClient(DummyClient* client, Resource* resource) |
106 : m_dummyClient(client) | 107 : m_dummyClient(client) |
107 , m_resource(resource) | 108 , m_resource(resource) |
108 , m_removeClientTimer(this, &AddingClient::removeClient) {} | 109 , m_removeClientTimer(this, &AddingClient::removeClient) {} |
109 | 110 |
110 ~AddingClient() override {} | 111 ~AddingClient() override {} |
111 | 112 |
112 // ResourceClient implementation. | 113 // ResourceClient implementation. |
113 virtual void notifyFinished(Resource* resource) | 114 void notifyFinished(Resource* resource) override |
114 { | 115 { |
115 // First schedule an asynchronous task to remove the client. | 116 // First schedule an asynchronous task to remove the client. |
116 // We do not expect the client to be called. | 117 // We do not expect the client to be called. |
117 m_removeClientTimer.startOneShot(0, BLINK_FROM_HERE); | 118 m_removeClientTimer.startOneShot(0, BLINK_FROM_HERE); |
118 resource->addClient(m_dummyClient); | 119 resource->addClient(m_dummyClient); |
119 } | 120 } |
| 121 String debugName() const override { return "AddingClient"; } |
| 122 |
120 void removeClient(Timer<AddingClient>* timer) | 123 void removeClient(Timer<AddingClient>* timer) |
121 { | 124 { |
122 m_resource->removeClient(m_dummyClient); | 125 m_resource->removeClient(m_dummyClient); |
123 } | 126 } |
124 private: | 127 private: |
125 DummyClient* m_dummyClient; | 128 DummyClient* m_dummyClient; |
126 ResourcePtr<Resource> m_resource; | 129 ResourcePtr<Resource> m_resource; |
127 Timer<AddingClient> m_removeClientTimer; | 130 Timer<AddingClient> m_removeClientTimer; |
128 }; | 131 }; |
129 | 132 |
(...skipping 19 matching lines...) Expand all Loading... |
149 | 152 |
150 // This client removes another client when notified. | 153 // This client removes another client when notified. |
151 class RemovingClient : public RawResourceClient { | 154 class RemovingClient : public RawResourceClient { |
152 public: | 155 public: |
153 RemovingClient(DummyClient* client) | 156 RemovingClient(DummyClient* client) |
154 : m_dummyClient(client) {} | 157 : m_dummyClient(client) {} |
155 | 158 |
156 ~RemovingClient() override {} | 159 ~RemovingClient() override {} |
157 | 160 |
158 // ResourceClient implementation. | 161 // ResourceClient implementation. |
159 virtual void notifyFinished(Resource* resource) | 162 void notifyFinished(Resource* resource) override |
160 { | 163 { |
161 resource->removeClient(m_dummyClient); | 164 resource->removeClient(m_dummyClient); |
162 resource->removeClient(this); | 165 resource->removeClient(this); |
163 } | 166 } |
| 167 String debugName() const override { return "RemovingClient"; } |
164 private: | 168 private: |
165 DummyClient* m_dummyClient; | 169 DummyClient* m_dummyClient; |
166 }; | 170 }; |
167 | 171 |
168 TEST(RawResourceTest, RemoveClientDuringCallback) | 172 TEST(RawResourceTest, RemoveClientDuringCallback) |
169 { | 173 { |
170 ResourcePtr<Resource> raw = new RawResource(ResourceRequest("data:text/html,
"), Resource::Raw); | 174 ResourcePtr<Resource> raw = new RawResource(ResourceRequest("data:text/html,
"), Resource::Raw); |
171 raw->setLoading(false); | 175 raw->setLoading(false); |
172 | 176 |
173 // Create a non-null response. | 177 // Create a non-null response. |
174 ResourceResponse response = raw->response(); | 178 ResourceResponse response = raw->response(); |
175 response.setURL(KURL(ParsedURLString, "http://600.613/")); | 179 response.setURL(KURL(ParsedURLString, "http://600.613/")); |
176 raw->setResponse(response); | 180 raw->setResponse(response); |
177 EXPECT_FALSE(raw->response().isNull()); | 181 EXPECT_FALSE(raw->response().isNull()); |
178 | 182 |
179 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); | 183 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); |
180 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); | 184 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); |
181 raw->addClient(dummyClient.get()); | 185 raw->addClient(dummyClient.get()); |
182 raw->addClient(removingClient.get()); | 186 raw->addClient(removingClient.get()); |
183 testing::runPendingTasks(); | 187 testing::runPendingTasks(); |
184 EXPECT_FALSE(raw->hasClients()); | 188 EXPECT_FALSE(raw->hasClients()); |
185 } | 189 } |
186 | 190 |
187 } // namespace blink | 191 } // namespace blink |
OLD | NEW |