| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 Vector<char> m_data; | 139 Vector<char> m_data; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 // This client adds another client when notified. | 142 // This client adds another client when notified. |
| 143 class AddingClient final : public GarbageCollectedFinalized<AddingClient>, | 143 class AddingClient final : public GarbageCollectedFinalized<AddingClient>, |
| 144 public RawResourceClient { | 144 public RawResourceClient { |
| 145 USING_GARBAGE_COLLECTED_MIXIN(AddingClient); | 145 USING_GARBAGE_COLLECTED_MIXIN(AddingClient); |
| 146 | 146 |
| 147 public: | 147 public: |
| 148 AddingClient(DummyClient* client, Resource* resource) | 148 AddingClient(DummyClient* client, Resource* resource) |
| 149 : m_dummyClient(client), | 149 : m_dummyClient(client), m_resource(resource) {} |
| 150 m_resource(resource), | |
| 151 m_removeClientTimer(this, &AddingClient::removeClient) {} | |
| 152 | 150 |
| 153 ~AddingClient() override {} | 151 ~AddingClient() override {} |
| 154 | 152 |
| 155 // ResourceClient implementation. | 153 // ResourceClient implementation. |
| 156 void notifyFinished(Resource* resource) override { | 154 void notifyFinished(Resource* resource) override { |
| 157 // First schedule an asynchronous task to remove the client. | 155 // First schedule an asynchronous task to remove the client. |
| 158 // We do not expect the client to be called. | 156 // We do not expect a client to be called if the client is removed before |
| 159 m_removeClientTimer.startOneShot(0, BLINK_FROM_HERE); | 157 // a callback invocation task queued inside addClient() is scheduled. |
| 158 Platform::current() |
| 159 ->currentThread() |
| 160 ->scheduler() |
| 161 ->loadingTaskRunner() |
| 162 ->postTask(BLINK_FROM_HERE, WTF::bind(&AddingClient::removeClient, |
| 163 wrapPersistent(this))); |
| 160 resource->addClient(m_dummyClient); | 164 resource->addClient(m_dummyClient); |
| 161 } | 165 } |
| 162 String debugName() const override { return "AddingClient"; } | 166 String debugName() const override { return "AddingClient"; } |
| 163 | 167 |
| 164 void removeClient(TimerBase* timer) { | 168 void removeClient() { m_resource->removeClient(m_dummyClient); } |
| 165 m_resource->removeClient(m_dummyClient); | |
| 166 } | |
| 167 | 169 |
| 168 DEFINE_INLINE_VIRTUAL_TRACE() { | 170 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 169 visitor->trace(m_dummyClient); | 171 visitor->trace(m_dummyClient); |
| 170 visitor->trace(m_resource); | 172 visitor->trace(m_resource); |
| 171 RawResourceClient::trace(visitor); | 173 RawResourceClient::trace(visitor); |
| 172 } | 174 } |
| 173 | 175 |
| 174 private: | 176 private: |
| 175 Member<DummyClient> m_dummyClient; | 177 Member<DummyClient> m_dummyClient; |
| 176 Member<Resource> m_resource; | 178 Member<Resource> m_resource; |
| 177 Timer<AddingClient> m_removeClientTimer; | |
| 178 }; | 179 }; |
| 179 | 180 |
| 180 TEST(RawResourceTest, RevalidationSucceeded) { | 181 TEST(RawResourceTest, RevalidationSucceeded) { |
| 181 Resource* resource = | 182 Resource* resource = |
| 182 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); | 183 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); |
| 183 ResourceResponse response; | 184 ResourceResponse response; |
| 184 response.setHTTPStatusCode(200); | 185 response.setHTTPStatusCode(200); |
| 185 resource->responseReceived(response, nullptr); | 186 resource->responseReceived(response, nullptr); |
| 186 const char data[5] = "abcd"; | 187 const char data[5] = "abcd"; |
| 187 resource->appendData(data, 4); | 188 resource->appendData(data, 4); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 558 |
| 558 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) { | 559 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) { |
| 559 ResourceRequest request("data:text/html,"); | 560 ResourceRequest request("data:text/html,"); |
| 560 request.setHTTPHeaderField( | 561 request.setHTTPHeaderField( |
| 561 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, "Foo"); | 562 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, "Foo"); |
| 562 Resource* raw = RawResource::create(request, Resource::Raw); | 563 Resource* raw = RawResource::create(request, Resource::Raw); |
| 563 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); | 564 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); |
| 564 } | 565 } |
| 565 | 566 |
| 566 } // namespace blink | 567 } // namespace blink |
| OLD | NEW |