Chromium Code Reviews| Index: content/browser/loader/navigation_url_loader_unittest.cc |
| diff --git a/content/browser/loader/navigation_url_loader_unittest.cc b/content/browser/loader/navigation_url_loader_unittest.cc |
| index 097035ca2199d9cadef0a04a1ed0958ef990a02e..5e514a960979eaa1981fd5651d787a772828825e 100644 |
| --- a/content/browser/loader/navigation_url_loader_unittest.cc |
| +++ b/content/browser/loader/navigation_url_loader_unittest.cc |
| @@ -62,8 +62,7 @@ class StreamProtocolHandler |
| class TestNavigationURLLoaderDelegate : public NavigationURLLoaderDelegate { |
| public: |
| TestNavigationURLLoaderDelegate() |
| - : net_error_(0) { |
| - } |
| + : net_error_(0), about_to_begin_navigation_counter_(0) {} |
| const net::RedirectInfo& redirect_info() const { return redirect_info_; } |
| ResourceResponse* redirect_response() const { |
| @@ -72,6 +71,9 @@ class TestNavigationURLLoaderDelegate : public NavigationURLLoaderDelegate { |
| ResourceResponse* response() const { return response_.get(); } |
| StreamHandle* body() const { return body_.get(); } |
| int net_error() const { return net_error_; } |
| + int about_to_begin_navigation_counter() const { |
| + return about_to_begin_navigation_counter_; |
| + } |
| void WaitForRequestRedirected() { |
| request_redirected_.reset(new base::RunLoop); |
| @@ -119,12 +121,18 @@ class TestNavigationURLLoaderDelegate : public NavigationURLLoaderDelegate { |
| request_failed_->Quit(); |
| } |
| + void NavigationRequested(base::TimeTicks timestamp) override { |
| + ASSERT_FALSE(timestamp.is_null()); |
| + ++about_to_begin_navigation_counter_; |
| + } |
| + |
| private: |
| net::RedirectInfo redirect_info_; |
| scoped_refptr<ResourceResponse> redirect_response_; |
| scoped_refptr<ResourceResponse> response_; |
| scoped_ptr<StreamHandle> body_; |
| int net_error_; |
| + int about_to_begin_navigation_counter_; |
| scoped_ptr<base::RunLoop> request_redirected_; |
| scoped_ptr<base::RunLoop> response_started_; |
| @@ -222,6 +230,8 @@ TEST_F(NavigationURLLoaderTest, Basic) { |
| // Check the body is correct. |
| EXPECT_EQ(net::URLRequestTestJob::test_data_1(), |
| FetchURL(delegate.body()->GetURL())); |
| + |
| + EXPECT_EQ(1, delegate.about_to_begin_navigation_counter()); |
| } |
| // Tests that request failures are propagated correctly. |
| @@ -233,6 +243,7 @@ TEST_F(NavigationURLLoaderTest, RequestFailed) { |
| // Wait for the request to fail as expected. |
| delegate.WaitForRequestFailed(); |
| EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, delegate.net_error()); |
| + EXPECT_EQ(1, delegate.about_to_begin_navigation_counter()); |
| } |
| // Test that redirects are sent to the delegate. |
| @@ -252,6 +263,7 @@ TEST_F(NavigationURLLoaderTest, RequestRedirected) { |
| EXPECT_EQ(net::URLRequestTestJob::test_url_2(), |
| delegate.redirect_info().new_first_party_for_cookies); |
| EXPECT_EQ(302, delegate.redirect_response()->head.headers->response_code()); |
| + EXPECT_EQ(1, delegate.about_to_begin_navigation_counter()); |
| // Wait for the response to complete. |
| loader->FollowRedirect(); |
| @@ -265,6 +277,8 @@ TEST_F(NavigationURLLoaderTest, RequestRedirected) { |
| EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| EXPECT_EQ(net::URLRequestTestJob::test_data_2(), |
| FetchURL(delegate.body()->GetURL())); |
| + |
| + EXPECT_EQ(1, delegate.about_to_begin_navigation_counter()); |
| } |
| // Tests that the destroying the loader cancels the request. |
| @@ -325,6 +339,7 @@ TEST_F(NavigationURLLoaderTest, CancelByContext) { |
| // Wait for the request to now be aborted. |
| delegate.WaitForRequestFailed(); |
| EXPECT_EQ(net::ERR_ABORTED, delegate.net_error()); |
| + EXPECT_EQ(1, delegate.about_to_begin_navigation_counter()); |
| } |
| // Tests that, if the request is blocked by the ResourceDispatcherHostDelegate, |
| @@ -340,6 +355,7 @@ TEST_F(NavigationURLLoaderTest, RequestBlocked) { |
| // Wait for the request to fail as expected. |
| delegate.WaitForRequestFailed(); |
| EXPECT_EQ(net::ERR_ABORTED, delegate.net_error()); |
| + EXPECT_EQ(0, delegate.about_to_begin_navigation_counter()); |
|
davidben
2015/01/28 21:33:27
This doesn't quite match the other path with OnReq
carlosk
2015/01/30 14:01:47
Done. This behavior changed once I moved the initi
|
| host_.SetDelegate(nullptr); |
| } |