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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 RawResource* jpegResource(RawResource::create(jpegRequest, Resource::Raw)); | 52 RawResource* jpegResource(RawResource::create(jpegRequest, Resource::Raw)); |
53 | 53 |
54 ResourceRequest pngRequest; | 54 ResourceRequest pngRequest; |
55 pngRequest.setHTTPAccept("image/png"); | 55 pngRequest.setHTTPAccept("image/png"); |
56 | 56 |
57 ASSERT_FALSE(jpegResource->canReuse(pngRequest)); | 57 ASSERT_FALSE(jpegResource->canReuse(pngRequest)); |
58 } | 58 } |
59 | 59 |
60 class DummyClient final : public GarbageCollectedFinalized<DummyClient>, public
RawResourceClient { | 60 class DummyClient final : public GarbageCollectedFinalized<DummyClient>, public
RawResourceClient { |
| 61 USING_GARBAGE_COLLECTED_MIXIN(DummyClient); |
61 public: | 62 public: |
62 DummyClient() : m_called(false), m_numberOfRedirectsReceived(0) {} | 63 DummyClient() : m_called(false), m_numberOfRedirectsReceived(0) {} |
63 ~DummyClient() override {} | 64 ~DummyClient() override {} |
64 | 65 |
65 // ResourceClient implementation. | 66 // ResourceClient implementation. |
66 void notifyFinished(Resource* resource) override | 67 void notifyFinished(Resource* resource) override |
67 { | 68 { |
68 m_called = true; | 69 m_called = true; |
69 } | 70 } |
70 String debugName() const override { return "DummyClient"; } | 71 String debugName() const override { return "DummyClient"; } |
71 | 72 |
72 void dataReceived(Resource*, const char* data, size_t length) override | 73 void dataReceived(Resource*, const char* data, size_t length) override |
73 { | 74 { |
74 m_data.append(data, length); | 75 m_data.append(data, length); |
75 } | 76 } |
76 | 77 |
77 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&)
override | 78 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&)
override |
78 { | 79 { |
79 ++m_numberOfRedirectsReceived; | 80 ++m_numberOfRedirectsReceived; |
80 } | 81 } |
81 | 82 |
82 bool called() { return m_called; } | 83 bool called() { return m_called; } |
83 int numberOfRedirectsReceived() const { return m_numberOfRedirectsReceived;
} | 84 int numberOfRedirectsReceived() const { return m_numberOfRedirectsReceived;
} |
84 const Vector<char>& data() { return m_data; } | 85 const Vector<char>& data() { return m_data; } |
85 DEFINE_INLINE_TRACE() {} | 86 DEFINE_INLINE_TRACE() |
| 87 { |
| 88 RawResourceClient::trace(visitor); |
| 89 } |
86 | 90 |
87 private: | 91 private: |
88 bool m_called; | 92 bool m_called; |
89 int m_numberOfRedirectsReceived; | 93 int m_numberOfRedirectsReceived; |
90 Vector<char> m_data; | 94 Vector<char> m_data; |
91 }; | 95 }; |
92 | 96 |
93 // This client adds another client when notified. | 97 // This client adds another client when notified. |
94 class AddingClient final : public GarbageCollectedFinalized<AddingClient>, publi
c RawResourceClient { | 98 class AddingClient final : public GarbageCollectedFinalized<AddingClient>, publi
c RawResourceClient { |
| 99 USING_GARBAGE_COLLECTED_MIXIN(AddingClient); |
95 public: | 100 public: |
96 AddingClient(DummyClient* client, Resource* resource) | 101 AddingClient(DummyClient* client, Resource* resource) |
97 : m_dummyClient(client) | 102 : m_dummyClient(client) |
98 , m_resource(resource) | 103 , m_resource(resource) |
99 , m_removeClientTimer(this, &AddingClient::removeClient) {} | 104 , m_removeClientTimer(this, &AddingClient::removeClient) {} |
100 | 105 |
101 ~AddingClient() override {} | 106 ~AddingClient() override {} |
102 | 107 |
103 // ResourceClient implementation. | 108 // ResourceClient implementation. |
104 void notifyFinished(Resource* resource) override | 109 void notifyFinished(Resource* resource) override |
105 { | 110 { |
106 // First schedule an asynchronous task to remove the client. | 111 // First schedule an asynchronous task to remove the client. |
107 // We do not expect the client to be called. | 112 // We do not expect the client to be called. |
108 m_removeClientTimer.startOneShot(0, BLINK_FROM_HERE); | 113 m_removeClientTimer.startOneShot(0, BLINK_FROM_HERE); |
109 resource->addClient(m_dummyClient); | 114 resource->addClient(m_dummyClient); |
110 } | 115 } |
111 String debugName() const override { return "AddingClient"; } | 116 String debugName() const override { return "AddingClient"; } |
112 | 117 |
113 void removeClient(TimerBase* timer) | 118 void removeClient(TimerBase* timer) |
114 { | 119 { |
115 m_resource->removeClient(m_dummyClient); | 120 m_resource->removeClient(m_dummyClient); |
116 } | 121 } |
117 | 122 |
118 DEFINE_INLINE_VIRTUAL_TRACE() | 123 DEFINE_INLINE_VIRTUAL_TRACE() |
119 { | 124 { |
120 visitor->trace(m_dummyClient); | 125 visitor->trace(m_dummyClient); |
121 visitor->trace(m_resource); | 126 visitor->trace(m_resource); |
| 127 RawResourceClient::trace(visitor); |
122 } | 128 } |
123 | 129 |
124 private: | 130 private: |
125 Member<DummyClient> m_dummyClient; | 131 Member<DummyClient> m_dummyClient; |
126 Member<Resource> m_resource; | 132 Member<Resource> m_resource; |
127 Timer<AddingClient> m_removeClientTimer; | 133 Timer<AddingClient> m_removeClientTimer; |
128 }; | 134 }; |
129 | 135 |
130 TEST(RawResourceTest, RevalidationSucceeded) | 136 TEST(RawResourceTest, RevalidationSucceeded) |
131 { | 137 { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 Persistent<AddingClient> addingClient = new AddingClient(dummyClient.get(),
raw); | 348 Persistent<AddingClient> addingClient = new AddingClient(dummyClient.get(),
raw); |
343 raw->addClient(addingClient); | 349 raw->addClient(addingClient); |
344 testing::runPendingTasks(); | 350 testing::runPendingTasks(); |
345 raw->removeClient(addingClient); | 351 raw->removeClient(addingClient); |
346 EXPECT_FALSE(dummyClient->called()); | 352 EXPECT_FALSE(dummyClient->called()); |
347 EXPECT_FALSE(raw->hasClientsOrObservers()); | 353 EXPECT_FALSE(raw->hasClientsOrObservers()); |
348 } | 354 } |
349 | 355 |
350 // This client removes another client when notified. | 356 // This client removes another client when notified. |
351 class RemovingClient : public GarbageCollectedFinalized<RemovingClient>, public
RawResourceClient { | 357 class RemovingClient : public GarbageCollectedFinalized<RemovingClient>, public
RawResourceClient { |
| 358 USING_GARBAGE_COLLECTED_MIXIN(RemovingClient); |
352 public: | 359 public: |
353 RemovingClient(DummyClient* client) | 360 RemovingClient(DummyClient* client) |
354 : m_dummyClient(client) {} | 361 : m_dummyClient(client) {} |
355 | 362 |
356 ~RemovingClient() override {} | 363 ~RemovingClient() override {} |
357 | 364 |
358 // ResourceClient implementation. | 365 // ResourceClient implementation. |
359 void notifyFinished(Resource* resource) override | 366 void notifyFinished(Resource* resource) override |
360 { | 367 { |
361 resource->removeClient(m_dummyClient); | 368 resource->removeClient(m_dummyClient); |
362 resource->removeClient(this); | 369 resource->removeClient(this); |
363 } | 370 } |
364 String debugName() const override { return "RemovingClient"; } | 371 String debugName() const override { return "RemovingClient"; } |
365 DEFINE_INLINE_TRACE() | 372 DEFINE_INLINE_TRACE() |
366 { | 373 { |
367 visitor->trace(m_dummyClient); | 374 visitor->trace(m_dummyClient); |
| 375 RawResourceClient::trace(visitor); |
368 } | 376 } |
369 | 377 |
370 private: | 378 private: |
371 Member<DummyClient> m_dummyClient; | 379 Member<DummyClient> m_dummyClient; |
372 }; | 380 }; |
373 | 381 |
374 TEST(RawResourceTest, RemoveClientDuringCallback) | 382 TEST(RawResourceTest, RemoveClientDuringCallback) |
375 { | 383 { |
376 Resource* raw = RawResource::create(ResourceRequest("data:text/html,"), Reso
urce::Raw); | 384 Resource* raw = RawResource::create(ResourceRequest("data:text/html,"), Reso
urce::Raw); |
377 | 385 |
(...skipping 14 matching lines...) Expand all Loading... |
392 | 400 |
393 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) | 401 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) |
394 { | 402 { |
395 ResourceRequest request("data:text/html,"); | 403 ResourceRequest request("data:text/html,"); |
396 request.setHTTPHeaderField(HTTPNames::X_DevTools_Emulate_Network_Conditions_
Client_Id, "Foo"); | 404 request.setHTTPHeaderField(HTTPNames::X_DevTools_Emulate_Network_Conditions_
Client_Id, "Foo"); |
397 Resource* raw = RawResource::create(request, Resource::Raw); | 405 Resource* raw = RawResource::create(request, Resource::Raw); |
398 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); | 406 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); |
399 } | 407 } |
400 | 408 |
401 } // namespace blink | 409 } // namespace blink |
OLD | NEW |