1 // Copyright (c) 2014 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 CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_H_ 6 #define CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_H_ 7 8 #include <memory> 9 10 #include "base/memory/weak_ptr.h" 11 #include "content/browser/loader/navigation_url_loader.h" 12 #include "content/browser/renderer_host/navigation_request_info.h" 13 #include "content/common/navigation_params.h" 14 #include "services/network/public/mojom/url_response_head.mojom-forward.h" 15 16 namespace net { 17 struct RedirectInfo; 18 } 19 20 namespace content { 21 22 class NavigationURLLoaderDelegate; 23 24 // Test implementation of NavigationURLLoader to simulate the network stack 25 // response. 26 class TestNavigationURLLoader 27 : public NavigationURLLoader, 28 public base::SupportsWeakPtr<TestNavigationURLLoader> { 29 public: 30 TestNavigationURLLoader(std::unique_ptr<NavigationRequestInfo> request_info, 31 NavigationURLLoaderDelegate* delegate, 32 NavigationURLLoader::LoaderType loader_type); 33 34 // NavigationURLLoader implementation. 35 void FollowRedirect( 36 const std::vector<std::string>& removed_headers, 37 const net::HttpRequestHeaders& modified_headers, 38 const net::HttpRequestHeaders& modified_cors_exempt_headers, 39 blink::PreviewsState new_previews_state) override; 40 request_info()41 NavigationRequestInfo* request_info() const { return request_info_.get(); } 42 43 void SimulateServerRedirect(const GURL& redirect_url); 44 45 void SimulateError(int error_code); 46 void SimulateErrorWithStatus( 47 const network::URLLoaderCompletionStatus& status); 48 49 void CallOnRequestRedirected( 50 const net::RedirectInfo& redirect_info, 51 network::mojom::URLResponseHeadPtr response_head); 52 void CallOnResponseStarted(network::mojom::URLResponseHeadPtr response_head); 53 redirect_count()54 int redirect_count() { return redirect_count_; } 55 56 private: 57 ~TestNavigationURLLoader() override; 58 59 std::unique_ptr<NavigationRequestInfo> request_info_; 60 NavigationURLLoaderDelegate* delegate_; 61 int redirect_count_; 62 63 const NavigationURLLoader::LoaderType loader_type_; 64 }; 65 66 } // namespace content 67 68 #endif // CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_H_ 69