clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 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 | |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 10 | #include "base/memory/weak_ptr.h" |
| 11 | #include "content/browser/frame_host/navigation_request_info.h" |
| 12 | #include "content/browser/loader/navigation_url_loader.h" |
| 13 | #include "content/common/navigation_params.h" |
| 14 | |
| 15 | namespace net { |
| 16 | struct RedirectInfo; |
| 17 | } |
| 18 | |
| 19 | namespace content { |
| 20 | |
ryansturm | fe32816 | 2016-05-11 22:28:47 | [diff] [blame] | 21 | class NavigationData; |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 22 | class NavigationURLLoaderDelegate; |
| 23 | class StreamHandle; |
| 24 | struct ResourceResponse; |
| 25 | |
| 26 | // PlzNavigate |
| 27 | // Test implementation of NavigationURLLoader to simulate the network stack |
| 28 | // response. |
| 29 | class TestNavigationURLLoader |
| 30 | : public NavigationURLLoader, |
| 31 | public base::SupportsWeakPtr<TestNavigationURLLoader> { |
| 32 | public: |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 33 | TestNavigationURLLoader(std::unique_ptr<NavigationRequestInfo> request_info, |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 34 | NavigationURLLoaderDelegate* delegate); |
| 35 | |
| 36 | // NavigationURLLoader implementation. |
| 37 | void FollowRedirect() override; |
clamy | 5a3c364 | 2016-03-24 17:46:56 | [diff] [blame] | 38 | void ProceedWithResponse() override; |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 39 | |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 40 | NavigationRequestInfo* request_info() const { return request_info_.get(); } |
| 41 | |
carlosk | d6a4ef36 | 2015-03-04 10:46:17 | [diff] [blame] | 42 | void SimulateServerRedirect(const GURL& redirect_url); |
| 43 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 44 | void SimulateError(int error_code); |
| 45 | |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 46 | void CallOnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 47 | const scoped_refptr<ResourceResponse>& response); |
| 48 | void CallOnResponseStarted(const scoped_refptr<ResourceResponse>& response, |
ryansturm | fe32816 | 2016-05-11 22:28:47 | [diff] [blame] | 49 | std::unique_ptr<StreamHandle> body, |
| 50 | std::unique_ptr<NavigationData> navigation_data); |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 51 | |
| 52 | int redirect_count() { return redirect_count_; } |
| 53 | |
clamy | 5a3c364 | 2016-03-24 17:46:56 | [diff] [blame] | 54 | bool response_proceeded() { return response_proceeded_; } |
| 55 | |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 56 | private: |
dcheng | 6e342bf | 2014-12-23 00:09:35 | [diff] [blame] | 57 | ~TestNavigationURLLoader() override; |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 58 | |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 59 | std::unique_ptr<NavigationRequestInfo> request_info_; |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 60 | NavigationURLLoaderDelegate* delegate_; |
| 61 | int redirect_count_; |
clamy | 5a3c364 | 2016-03-24 17:46:56 | [diff] [blame] | 62 | bool response_proceeded_; |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace content |
| 66 | |
| 67 | #endif // CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_H_ |