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 28 matching lines...) Expand all Loading... |
39 #include "platform/exported/WrappedResourceResponse.h" | 39 #include "platform/exported/WrappedResourceResponse.h" |
40 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
41 #include "platform/network/ResourceRequest.h" | 41 #include "platform/network/ResourceRequest.h" |
42 #include "platform/testing/URLTestHelpers.h" | 42 #include "platform/testing/URLTestHelpers.h" |
43 #include "platform/weborigin/KURL.h" | 43 #include "platform/weborigin/KURL.h" |
44 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
45 #include "public/platform/WebTaskRunner.h" | 45 #include "public/platform/WebTaskRunner.h" |
46 #include "public/platform/WebURLLoaderMockFactory.h" | 46 #include "public/platform/WebURLLoaderMockFactory.h" |
47 #include "public/platform/WebURLResponse.h" | 47 #include "public/platform/WebURLResponse.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
49 #include "wtf/PtrUtil.h" | |
50 #include <memory> | |
51 | 49 |
52 namespace blink { | 50 namespace blink { |
53 | 51 |
54 namespace { | 52 namespace { |
55 | 53 |
56 class MockTaskRunner : public blink::WebTaskRunner { | 54 class MockTaskRunner : public blink::WebTaskRunner { |
57 void postTask(const WebTraceLocation&, Task*) override { } | 55 void postTask(const WebTraceLocation&, Task*) override { } |
58 void postDelayedTask(const WebTraceLocation&, Task*, double) override { } | 56 void postDelayedTask(const WebTraceLocation&, Task*, double) override { } |
59 WebTaskRunner* clone() override { return nullptr; } | 57 WebTaskRunner* clone() override { return nullptr; } |
60 double virtualTimeSeconds() const override { return 0.0; } | 58 double virtualTimeSeconds() const override { return 0.0; } |
(...skipping 17 matching lines...) Expand all Loading... |
78 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); } | 76 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); } |
79 | 77 |
80 void setCachePolicy(CachePolicy policy) { m_policy = policy; } | 78 void setCachePolicy(CachePolicy policy) { m_policy = policy; } |
81 CachePolicy getCachePolicy() const override { return m_policy; } | 79 CachePolicy getCachePolicy() const override { return m_policy; } |
82 void setLoadComplete(bool complete) { m_complete = complete; } | 80 void setLoadComplete(bool complete) { m_complete = complete; } |
83 bool isLoadComplete() const override { return m_complete; } | 81 bool isLoadComplete() const override { return m_complete; } |
84 | 82 |
85 private: | 83 private: |
86 ResourceFetcherTestMockFetchContext() | 84 ResourceFetcherTestMockFetchContext() |
87 : m_policy(CachePolicyVerify) | 85 : m_policy(CachePolicyVerify) |
88 , m_runner(wrapUnique(new MockTaskRunner)) | 86 , m_runner(adoptPtr(new MockTaskRunner)) |
89 , m_complete(false) | 87 , m_complete(false) |
90 { } | 88 { } |
91 | 89 |
92 CachePolicy m_policy; | 90 CachePolicy m_policy; |
93 std::unique_ptr<MockTaskRunner> m_runner; | 91 OwnPtr<MockTaskRunner> m_runner; |
94 bool m_complete; | 92 bool m_complete; |
95 }; | 93 }; |
96 | 94 |
97 class ResourceFetcherTest : public ::testing::Test { | 95 class ResourceFetcherTest : public ::testing::Test { |
98 }; | 96 }; |
99 | 97 |
100 class TestResourceFactory : public ResourceFactory { | 98 class TestResourceFactory : public ResourceFactory { |
101 public: | 99 public: |
102 TestResourceFactory(Resource::Type type = Resource::Raw) | 100 TestResourceFactory(Resource::Type type = Resource::Raw) |
103 : ResourceFactory(type) { } | 101 : ResourceFactory(type) { } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 class ServeRequestsOnCompleteClient final : public GarbageCollectedFinalized<Ser
veRequestsOnCompleteClient>, public RawResourceClient { | 347 class ServeRequestsOnCompleteClient final : public GarbageCollectedFinalized<Ser
veRequestsOnCompleteClient>, public RawResourceClient { |
350 public: | 348 public: |
351 void notifyFinished(Resource*) override | 349 void notifyFinished(Resource*) override |
352 { | 350 { |
353 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest
s(); | 351 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest
s(); |
354 } | 352 } |
355 | 353 |
356 // No callbacks should be received except for the notifyFinished() | 354 // No callbacks should be received except for the notifyFinished() |
357 // triggered by ResourceLoader::cancel(). | 355 // triggered by ResourceLoader::cancel(). |
358 void dataSent(Resource*, unsigned long long, unsigned long long) override {
ASSERT_TRUE(false); } | 356 void dataSent(Resource*, unsigned long long, unsigned long long) override {
ASSERT_TRUE(false); } |
359 void responseReceived(Resource*, const ResourceResponse&, std::unique_ptr<We
bDataConsumerHandle>) override { ASSERT_TRUE(false); } | 357 void responseReceived(Resource*, const ResourceResponse&, PassOwnPtr<WebData
ConsumerHandle>) override { ASSERT_TRUE(false); } |
360 void setSerializedCachedMetadata(Resource*, const char*, size_t) override {
ASSERT_TRUE(false); } | 358 void setSerializedCachedMetadata(Resource*, const char*, size_t) override {
ASSERT_TRUE(false); } |
361 void dataReceived(Resource*, const char*, size_t) override { ASSERT_TRUE(fal
se); } | 359 void dataReceived(Resource*, const char*, size_t) override { ASSERT_TRUE(fal
se); } |
362 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&)
override { ASSERT_TRUE(false); } | 360 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&)
override { ASSERT_TRUE(false); } |
363 void dataDownloaded(Resource*, int) override { ASSERT_TRUE(false); } | 361 void dataDownloaded(Resource*, int) override { ASSERT_TRUE(false); } |
364 void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&) override
{ ASSERT_TRUE(false); } | 362 void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&) override
{ ASSERT_TRUE(false); } |
365 | 363 |
366 DEFINE_INLINE_TRACE() {} | 364 DEFINE_INLINE_TRACE() {} |
367 | 365 |
368 String debugName() const override { return "ServeRequestsOnCompleteClient";
} | 366 String debugName() const override { return "ServeRequestsOnCompleteClient";
} |
369 }; | 367 }; |
(...skipping 15 matching lines...) Expand all Loading... |
385 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); | 383 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
386 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact
ory(Resource::Raw)); | 384 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact
ory(Resource::Raw)); |
387 Persistent<ServeRequestsOnCompleteClient> client = new ServeRequestsOnComple
teClient(); | 385 Persistent<ServeRequestsOnCompleteClient> client = new ServeRequestsOnComple
teClient(); |
388 resource->addClient(client); | 386 resource->addClient(client); |
389 resource->loader()->cancel(); | 387 resource->loader()->cancel(); |
390 resource->removeClient(client); | 388 resource->removeClient(client); |
391 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 389 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
392 } | 390 } |
393 | 391 |
394 } // namespace blink | 392 } // namespace blink |
OLD | NEW |