1 // Copyright 2019 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 #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_LOADER_TESTING_TEST_LOADER_FACTORY_H_
6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_LOADER_TESTING_TEST_LOADER_FACTORY_H_
7 
8 #include <memory>
9 #include <utility>
10 #include "third_party/blink/public/platform/platform.h"
11 #include "third_party/blink/public/platform/scheduler/web_resource_loading_task_runner_handle.h"
12 #include "third_party/blink/public/platform/web_url_loader_factory.h"
13 #include "third_party/blink/renderer/platform/exported/wrapped_resource_request.h"
14 #include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
15 
16 namespace blink {
17 
18 // ResourceFetcher::LoaderFactory implementation for tests.
19 class TestLoaderFactory : public ResourceFetcher::LoaderFactory {
20  public:
TestLoaderFactory()21   TestLoaderFactory()
22       : url_loader_factory_(
23             Platform::Current()->CreateDefaultURLLoaderFactory()) {}
24 
25   // LoaderFactory implementations
CreateURLLoader(const ResourceRequest & request,const ResourceLoaderOptions & options,scoped_refptr<base::SingleThreadTaskRunner> task_runner)26   std::unique_ptr<WebURLLoader> CreateURLLoader(
27       const ResourceRequest& request,
28       const ResourceLoaderOptions& options,
29       scoped_refptr<base::SingleThreadTaskRunner> task_runner) override {
30     WrappedResourceRequest wrapped(request);
31     return url_loader_factory_->CreateURLLoader(
32         wrapped,
33         scheduler::WebResourceLoadingTaskRunnerHandle::CreateUnprioritized(
34             std::move(task_runner)));
35   }
CreateCodeCacheLoader()36   std::unique_ptr<CodeCacheLoader> CreateCodeCacheLoader() override {
37     return Platform::Current()->CreateCodeCacheLoader();
38   }
39 
40  private:
41   std::unique_ptr<WebURLLoaderFactory> url_loader_factory_;
42 };
43 
44 }  // namespace blink
45 
46 #endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_LOADER_TESTING_TEST_LOADER_FACTORY_H_
47