| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/loader/fetch/FetchTestingPlatformSupport.h" | 5 #include "platform/loader/fetch/FetchTestingPlatformSupport.h" |
| 6 | 6 |
| 7 #include "platform/loader/fetch/MockFetchContext.h" | 7 #include "platform/loader/fetch/MockFetchContext.h" |
| 8 #include "platform/network/ResourceError.h" | 8 #include "platform/network/ResourceError.h" |
| 9 #include "platform/testing/WebURLLoaderMockFactoryImpl.h" | 9 #include "platform/testing/WebURLLoaderMockFactoryImpl.h" |
| 10 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
| 11 #include "public/platform/WebURL.h" | 11 #include "public/platform/WebURL.h" |
| 12 #include "public/platform/WebURLLoader.h" | 12 #include "public/platform/WebURLLoader.h" |
| 13 #include "public/platform/WebURLLoaderMockFactory.h" | 13 #include "public/platform/WebURLLoaderMockFactory.h" |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 namespace { | |
| 19 | |
| 20 // WebURLLoader that does nothing. This instance should be passed as a default | |
| 21 // WebURLLoader to create a WebURLLoader through WebURLLoaderMockFactory. | |
| 22 class AssertWebURLLoader : public WebURLLoader { | |
| 23 public: | |
| 24 ~AssertWebURLLoader() override {} | |
| 25 | |
| 26 // WebURLLoader: | |
| 27 void loadSynchronously(const WebURLRequest&, | |
| 28 WebURLResponse&, | |
| 29 WebURLError&, | |
| 30 WebData&, | |
| 31 int64_t& encodedDataLength, | |
| 32 int64_t& encodedBodyLength) override { | |
| 33 NOTREACHED(); | |
| 34 } | |
| 35 void loadAsynchronously(const WebURLRequest&, WebURLLoaderClient*) override { | |
| 36 NOTREACHED(); | |
| 37 } | |
| 38 void cancel() override { NOTREACHED(); } | |
| 39 void setDefersLoading(bool defer) override { NOTREACHED(); } | |
| 40 void setLoadingTaskRunner(base::SingleThreadTaskRunner*) override { | |
| 41 NOTREACHED(); | |
| 42 } | |
| 43 }; | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 47 FetchTestingPlatformSupport::FetchTestingPlatformSupport() | 18 FetchTestingPlatformSupport::FetchTestingPlatformSupport() |
| 48 : m_urlLoaderMockFactory(new WebURLLoaderMockFactoryImpl(this)) {} | 19 : m_urlLoaderMockFactory(new WebURLLoaderMockFactoryImpl(this)) {} |
| 49 | 20 |
| 50 FetchTestingPlatformSupport::~FetchTestingPlatformSupport() = default; | 21 FetchTestingPlatformSupport::~FetchTestingPlatformSupport() = default; |
| 51 | 22 |
| 52 MockFetchContext* FetchTestingPlatformSupport::context() { | 23 MockFetchContext* FetchTestingPlatformSupport::context() { |
| 53 if (!m_context) { | 24 if (!m_context) { |
| 54 m_context = MockFetchContext::create( | 25 m_context = MockFetchContext::create( |
| 55 MockFetchContext::kShouldLoadNewResource, | 26 MockFetchContext::kShouldLoadNewResource, |
| 56 currentThread()->scheduler()->loadingTaskRunner()); | 27 currentThread()->scheduler()->loadingTaskRunner()); |
| 57 } | 28 } |
| 58 return m_context; | 29 return m_context; |
| 59 } | 30 } |
| 60 | 31 |
| 61 WebURLError FetchTestingPlatformSupport::cancelledError( | 32 WebURLError FetchTestingPlatformSupport::cancelledError( |
| 62 const WebURL& url) const { | 33 const WebURL& url) const { |
| 63 return ResourceError(errorDomainBlinkInternal, -1, url.string(), | 34 return ResourceError(errorDomainBlinkInternal, -1, url.string(), |
| 64 "cancelledError for testing"); | 35 "cancelledError for testing"); |
| 65 } | 36 } |
| 66 | 37 |
| 67 WebURLLoaderMockFactory* | 38 WebURLLoaderMockFactory* |
| 68 FetchTestingPlatformSupport::getURLLoaderMockFactory() { | 39 FetchTestingPlatformSupport::getURLLoaderMockFactory() { |
| 69 return m_urlLoaderMockFactory.get(); | 40 return m_urlLoaderMockFactory.get(); |
| 70 } | 41 } |
| 71 | 42 |
| 72 WebURLLoader* FetchTestingPlatformSupport::createURLLoader() { | 43 WebURLLoader* FetchTestingPlatformSupport::createURLLoader() { |
| 73 return m_urlLoaderMockFactory->createURLLoader(new AssertWebURLLoader); | 44 return m_urlLoaderMockFactory->createURLLoader(nullptr); |
| 74 } | 45 } |
| 75 | 46 |
| 76 } // namespace blink | 47 } // namespace blink |
| OLD | NEW |