Chromium Code Reviews| Index: third_party/WebKit/Source/core/fetch/FetchTestingPlatformSupport.cpp |
| diff --git a/third_party/WebKit/Source/core/fetch/FetchTestingPlatformSupport.cpp b/third_party/WebKit/Source/core/fetch/FetchTestingPlatformSupport.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a3a398a37de0f9ea7d0f53d20e61e4d2fa90135f |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/fetch/FetchTestingPlatformSupport.cpp |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/fetch/FetchTestingPlatformSupport.h" |
| + |
| +#include "core/fetch/MockFetchContext.h" |
| +#include "platform/network/ResourceError.h" |
| +#include "platform/testing/weburl_loader_mock_factory_impl.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebURL.h" |
| +#include "public/platform/WebURLLoader.h" |
| +#include "public/platform/WebURLLoaderMockFactory.h" |
| +#include <memory> |
| + |
| +namespace blink { |
| + |
| +class FetchTestingPlatformSupport::FetchTestingWebURLLoaderMockFactory |
| + : public WebURLLoaderMockFactoryImpl { |
| + private: |
| + void RunUntilIdle() override { |
| + static_cast<FetchTestingPlatformSupport*>(Platform::current()) |
| + ->runUntilIdle(); |
| + } |
|
kinuko
2017/01/20 12:30:34
I still feel this is a bit unfortunate. I think it
|
| +}; |
| + |
| +FetchTestingPlatformSupport::FetchTestingPlatformSupport() |
| + : m_urlLoaderMockFactory(new FetchTestingPlatformSupport:: |
| + FetchTestingWebURLLoaderMockFactory) {} |
| + |
| +FetchTestingPlatformSupport::~FetchTestingPlatformSupport() = default; |
| + |
| +MockFetchContext* FetchTestingPlatformSupport::context() { |
| + if (!m_context) { |
| + m_context = MockFetchContext::create( |
| + MockFetchContext::kShouldLoadNewResource, |
| + currentThread()->scheduler()->loadingTaskRunner()); |
| + } |
| + return m_context; |
| +} |
| + |
| +WebURLError FetchTestingPlatformSupport::cancelledError( |
| + const WebURL& url) const { |
| + return ResourceError::ResourceError( |
| + errorDomainBlinkInternal, -1, url.string(), "cancelledError for testing"); |
| +} |
| + |
| +WebURLLoaderMockFactory* |
| +FetchTestingPlatformSupport::getURLLoaderMockFactory() { |
| + return m_urlLoaderMockFactory.get(); |
| +} |
| + |
| +WebURLLoader* FetchTestingPlatformSupport::createURLLoader() { |
| + return m_urlLoaderMockFactory->createURLLoader( |
| + m_oldPlatform->createURLLoader()); |
| +} |
| + |
| +} // namespace blink |