| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "platform/loader/fetch/FetchTestingPlatformSupport.h" | |
| 6 | |
| 7 #include "platform/loader/fetch/MockFetchContext.h" | |
| 8 #include "platform/network/ResourceError.h" | |
| 9 #include "platform/testing/weburl_loader_mock_factory_impl.h" | |
| 10 #include "public/platform/Platform.h" | |
| 11 #include "public/platform/WebURL.h" | |
| 12 #include "public/platform/WebURLLoader.h" | |
| 13 #include "public/platform/WebURLLoaderMockFactory.h" | |
| 14 #include <memory> | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 FetchTestingPlatformSupport::FetchTestingPlatformSupport() | |
| 19 : m_urlLoaderMockFactory(new WebURLLoaderMockFactoryImpl(this)) {} | |
| 20 | |
| 21 FetchTestingPlatformSupport::~FetchTestingPlatformSupport() { | |
| 22 // Shutdowns WebURLLoaderMockFactory gracefully, serving all pending requests | |
| 23 // first, then flushing all registered URLs. | |
| 24 m_urlLoaderMockFactory->serveAsynchronousRequests(); | |
| 25 m_urlLoaderMockFactory->unregisterAllURLsAndClearMemoryCache(); | |
| 26 } | |
| 27 | |
| 28 MockFetchContext* FetchTestingPlatformSupport::context() { | |
| 29 if (!m_context) { | |
| 30 m_context = MockFetchContext::create( | |
| 31 MockFetchContext::kShouldLoadNewResource, | |
| 32 currentThread()->scheduler()->loadingTaskRunner()); | |
| 33 } | |
| 34 return m_context; | |
| 35 } | |
| 36 | |
| 37 WebURLError FetchTestingPlatformSupport::cancelledError( | |
| 38 const WebURL& url) const { | |
| 39 return ResourceError(errorDomainBlinkInternal, -1, url.string(), | |
| 40 "cancelledError for testing"); | |
| 41 } | |
| 42 | |
| 43 WebURLLoaderMockFactory* | |
| 44 FetchTestingPlatformSupport::getURLLoaderMockFactory() { | |
| 45 return m_urlLoaderMockFactory.get(); | |
| 46 } | |
| 47 | |
| 48 WebURLLoader* FetchTestingPlatformSupport::createURLLoader() { | |
| 49 return m_urlLoaderMockFactory->createURLLoader(nullptr); | |
| 50 } | |
| 51 | |
| 52 } // namespace blink | |
| OLD | NEW |