clamy | 9fb38cd | 2016-04-11 12:57:48 | [diff] [blame] | 1 | // Copyright 2016 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_DELEGATE_H_ |
| 6 | #define CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_DELEGATE_H_ |
| 7 | |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
clamy | 9fb38cd | 2016-04-11 12:57:48 | [diff] [blame] | 10 | #include "base/macros.h" |
| 11 | #include "base/memory/ref_counted.h" |
clamy | 9fb38cd | 2016-04-11 12:57:48 | [diff] [blame] | 12 | #include "base/time/time.h" |
| 13 | #include "content/browser/loader/navigation_url_loader_delegate.h" |
| 14 | #include "net/url_request/redirect_info.h" |
| 15 | |
| 16 | namespace base { |
| 17 | class RunLoop; |
| 18 | } |
| 19 | |
| 20 | namespace content { |
| 21 | |
| 22 | class StreamHandle; |
| 23 | struct ResourceResponse; |
| 24 | |
| 25 | // PlzNavigate |
| 26 | // Test implementation of NavigationURLLoaderDelegate to monitor navigation |
| 27 | // progress in the network stack. |
| 28 | class TestNavigationURLLoaderDelegate : public NavigationURLLoaderDelegate { |
| 29 | public: |
| 30 | TestNavigationURLLoaderDelegate(); |
| 31 | ~TestNavigationURLLoaderDelegate() override; |
| 32 | |
| 33 | const net::RedirectInfo& redirect_info() const { return redirect_info_; } |
| 34 | ResourceResponse* redirect_response() const { |
| 35 | return redirect_response_.get(); |
| 36 | } |
| 37 | ResourceResponse* response() const { return response_.get(); } |
| 38 | StreamHandle* body() const { return body_.get(); } |
| 39 | int net_error() const { return net_error_; } |
| 40 | int on_request_handled_counter() const { return on_request_handled_counter_; } |
| 41 | |
| 42 | // Waits for various navigation events. |
| 43 | // Note: if the event already happened, the functions will hang. |
| 44 | // TODO(clamy): Make the functions not hang if they are called after the |
| 45 | // event happened. |
| 46 | void WaitForRequestRedirected(); |
| 47 | void WaitForResponseStarted(); |
| 48 | void WaitForRequestFailed(); |
| 49 | void WaitForRequestStarted(); |
| 50 | |
| 51 | void ReleaseBody(); |
| 52 | |
| 53 | // NavigationURLLoaderDelegate implementation. |
| 54 | void OnRequestRedirected( |
| 55 | const net::RedirectInfo& redirect_info, |
| 56 | const scoped_refptr<ResourceResponse>& response) override; |
ryansturm | fe32816 | 2016-05-11 22:28:47 | [diff] [blame] | 57 | void OnResponseStarted( |
| 58 | const scoped_refptr<ResourceResponse>& response, |
| 59 | std::unique_ptr<StreamHandle> body, |
jam | b981f48 | 2016-08-30 05:55:02 | [diff] [blame] | 60 | const SSLStatus& ssl_status, |
ryansturm | fe32816 | 2016-05-11 22:28:47 | [diff] [blame] | 61 | std::unique_ptr<NavigationData> navigation_data) override; |
clamy | 9fb38cd | 2016-04-11 12:57:48 | [diff] [blame] | 62 | void OnRequestFailed(bool in_cache, int net_error) override; |
| 63 | void OnRequestStarted(base::TimeTicks timestamp) override; |
clamy | 9fb38cd | 2016-04-11 12:57:48 | [diff] [blame] | 64 | |
| 65 | private: |
| 66 | net::RedirectInfo redirect_info_; |
| 67 | scoped_refptr<ResourceResponse> redirect_response_; |
| 68 | scoped_refptr<ResourceResponse> response_; |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame] | 69 | std::unique_ptr<StreamHandle> body_; |
clamy | 9fb38cd | 2016-04-11 12:57:48 | [diff] [blame] | 70 | int net_error_; |
| 71 | int on_request_handled_counter_; |
| 72 | |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame] | 73 | std::unique_ptr<base::RunLoop> request_redirected_; |
| 74 | std::unique_ptr<base::RunLoop> response_started_; |
| 75 | std::unique_ptr<base::RunLoop> request_failed_; |
| 76 | std::unique_ptr<base::RunLoop> request_started_; |
clamy | 9fb38cd | 2016-04-11 12:57:48 | [diff] [blame] | 77 | |
| 78 | DISALLOW_COPY_AND_ASSIGN(TestNavigationURLLoaderDelegate); |
| 79 | }; |
| 80 | |
| 81 | } // namespace content |
| 82 | |
| 83 | #endif // CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_DELEGATE_H |