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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); | 231 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
232 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); | 232 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); |
233 EXPECT_EQ(resource, newResource); | 233 EXPECT_EQ(resource, newResource); |
234 | 234 |
235 memoryCache()->remove(newResource); | 235 memoryCache()->remove(newResource); |
236 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 236 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
237 } | 237 } |
238 | 238 |
239 class RequestSameResourceOnComplete : public GarbageCollectedFinalized<RequestSa
meResourceOnComplete>, public RawResourceClient { | 239 class RequestSameResourceOnComplete : public GarbageCollectedFinalized<RequestSa
meResourceOnComplete>, public RawResourceClient { |
| 240 USING_GARBAGE_COLLECTED_MIXIN(RequestSameResourceOnComplete); |
240 public: | 241 public: |
241 explicit RequestSameResourceOnComplete(Resource* resource) | 242 explicit RequestSameResourceOnComplete(Resource* resource) |
242 : m_resource(resource) | 243 : m_resource(resource) |
243 , m_notifyFinishedCalled(false) | 244 , m_notifyFinishedCalled(false) |
244 { | 245 { |
245 } | 246 } |
246 | 247 |
247 void notifyFinished(Resource* resource) override | 248 void notifyFinished(Resource* resource) override |
248 { | 249 { |
249 ASSERT_EQ(m_resource, resource); | 250 ASSERT_EQ(m_resource, resource); |
250 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFe
tchContext::create(); | 251 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFe
tchContext::create(); |
251 context->setCachePolicy(CachePolicyRevalidate); | 252 context->setCachePolicy(CachePolicyRevalidate); |
252 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); | 253 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); |
253 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo()); | 254 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo()); |
254 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResou
rceFactory(Resource::Image)); | 255 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResou
rceFactory(Resource::Image)); |
255 EXPECT_EQ(m_resource, resource2); | 256 EXPECT_EQ(m_resource, resource2); |
256 m_notifyFinishedCalled = true; | 257 m_notifyFinishedCalled = true; |
257 } | 258 } |
258 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; } | 259 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; } |
259 | 260 |
260 DEFINE_INLINE_TRACE() | 261 DEFINE_INLINE_TRACE() |
261 { | 262 { |
262 visitor->trace(m_resource); | 263 visitor->trace(m_resource); |
| 264 RawResourceClient::trace(visitor); |
263 } | 265 } |
264 | 266 |
265 String debugName() const override { return "RequestSameResourceOnComplete";
} | 267 String debugName() const override { return "RequestSameResourceOnComplete";
} |
266 | 268 |
267 private: | 269 private: |
268 Member<Resource> m_resource; | 270 Member<Resource> m_resource; |
269 bool m_notifyFinishedCalled; | 271 bool m_notifyFinishedCalled; |
270 }; | 272 }; |
271 | 273 |
272 TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) | 274 TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 ResourceLoaderOptions options; | 357 ResourceLoaderOptions options; |
356 options.dataBufferingPolicy = DoNotBufferData; | 358 options.dataBufferingPolicy = DoNotBufferData; |
357 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i
nternal, options); | 359 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i
nternal, options); |
358 Resource* resource1 = fetcher->requestResource(fetchRequest, TestResourceFac
tory(Resource::Media)); | 360 Resource* resource1 = fetcher->requestResource(fetchRequest, TestResourceFac
tory(Resource::Media)); |
359 Resource* resource2 = fetcher->requestResource(fetchRequest, TestResourceFac
tory(Resource::Media)); | 361 Resource* resource2 = fetcher->requestResource(fetchRequest, TestResourceFac
tory(Resource::Media)); |
360 EXPECT_NE(resource1, resource2); | 362 EXPECT_NE(resource1, resource2); |
361 memoryCache()->remove(resource2); | 363 memoryCache()->remove(resource2); |
362 } | 364 } |
363 | 365 |
364 class ServeRequestsOnCompleteClient final : public GarbageCollectedFinalized<Ser
veRequestsOnCompleteClient>, public RawResourceClient { | 366 class ServeRequestsOnCompleteClient final : public GarbageCollectedFinalized<Ser
veRequestsOnCompleteClient>, public RawResourceClient { |
| 367 USING_GARBAGE_COLLECTED_MIXIN(ServeRequestsOnCompleteClient); |
365 public: | 368 public: |
366 void notifyFinished(Resource*) override | 369 void notifyFinished(Resource*) override |
367 { | 370 { |
368 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest
s(); | 371 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest
s(); |
369 } | 372 } |
370 | 373 |
371 // No callbacks should be received except for the notifyFinished() | 374 // No callbacks should be received except for the notifyFinished() |
372 // triggered by ResourceLoader::cancel(). | 375 // triggered by ResourceLoader::cancel(). |
373 void dataSent(Resource*, unsigned long long, unsigned long long) override {
ASSERT_TRUE(false); } | 376 void dataSent(Resource*, unsigned long long, unsigned long long) override {
ASSERT_TRUE(false); } |
374 void responseReceived(Resource*, const ResourceResponse&, std::unique_ptr<We
bDataConsumerHandle>) override { ASSERT_TRUE(false); } | 377 void responseReceived(Resource*, const ResourceResponse&, std::unique_ptr<We
bDataConsumerHandle>) override { ASSERT_TRUE(false); } |
375 void setSerializedCachedMetadata(Resource*, const char*, size_t) override {
ASSERT_TRUE(false); } | 378 void setSerializedCachedMetadata(Resource*, const char*, size_t) override {
ASSERT_TRUE(false); } |
376 void dataReceived(Resource*, const char*, size_t) override { ASSERT_TRUE(fal
se); } | 379 void dataReceived(Resource*, const char*, size_t) override { ASSERT_TRUE(fal
se); } |
377 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&)
override { ASSERT_TRUE(false); } | 380 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&)
override { ASSERT_TRUE(false); } |
378 void dataDownloaded(Resource*, int) override { ASSERT_TRUE(false); } | 381 void dataDownloaded(Resource*, int) override { ASSERT_TRUE(false); } |
379 void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&) override
{ ASSERT_TRUE(false); } | 382 void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&) override
{ ASSERT_TRUE(false); } |
380 | 383 |
381 DEFINE_INLINE_TRACE() {} | 384 DEFINE_INLINE_TRACE() |
| 385 { |
| 386 RawResourceClient::trace(visitor); |
| 387 } |
382 | 388 |
383 String debugName() const override { return "ServeRequestsOnCompleteClient";
} | 389 String debugName() const override { return "ServeRequestsOnCompleteClient";
} |
384 }; | 390 }; |
385 | 391 |
386 // Regression test for http://crbug.com/594072. | 392 // Regression test for http://crbug.com/594072. |
387 // This emulates a modal dialog triggering a nested run loop inside | 393 // This emulates a modal dialog triggering a nested run loop inside |
388 // ResourceLoader::cancel(). If the ResourceLoader doesn't promptly cancel its | 394 // ResourceLoader::cancel(). If the ResourceLoader doesn't promptly cancel its |
389 // WebURLLoader before notifying its clients, a nested run loop may send a | 395 // WebURLLoader before notifying its clients, a nested run loop may send a |
390 // network response, leading to an invalid state transition in ResourceLoader. | 396 // network response, leading to an invalid state transition in ResourceLoader. |
391 TEST_F(ResourceFetcherTest, ResponseOnCancel) | 397 TEST_F(ResourceFetcherTest, ResponseOnCancel) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 requester.registerRedirect(redirectURL1, redirectURL2); | 502 requester.registerRedirect(redirectURL1, redirectURL2); |
497 requester.registerRedirect(redirectURL2, redirectURL3); | 503 requester.registerRedirect(redirectURL2, redirectURL3); |
498 requester.registerRedirect(redirectURL3, finalURL); | 504 requester.registerRedirect(redirectURL3, finalURL); |
499 requester.registerFinalResource(finalURL); | 505 requester.registerFinalResource(finalURL); |
500 requester.request(redirectURL1); | 506 requester.request(redirectURL1); |
501 | 507 |
502 EXPECT_EQ(testImageSize, requester.context()->getTransferSize()); | 508 EXPECT_EQ(testImageSize, requester.context()->getTransferSize()); |
503 } | 509 } |
504 | 510 |
505 } // namespace blink | 511 } // namespace blink |
OLD | NEW |