| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "content/browser/frame_host/navigation_handle_impl.h" | 6 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 7 #include "content/public/browser/navigation_throttle.h" | 7 #include "content/public/browser/navigation_throttle.h" |
| 8 #include "content/public/browser/ssl_status.h" | 8 #include "content/public/browser/ssl_status.h" |
| 9 #include "content/public/common/request_context_type.h" | 9 #include "content/public/common/request_context_type.h" |
| 10 #include "content/test/test_render_frame_host.h" | 10 #include "content/test/test_render_frame_host.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // TODO(clamy): this should also simulate that WillStartRequest was called if | 120 // TODO(clamy): this should also simulate that WillStartRequest was called if |
| 121 // it has not been called before. | 121 // it has not been called before. |
| 122 void SimulateWillRedirectRequest() { | 122 void SimulateWillRedirectRequest() { |
| 123 was_callback_called_ = false; | 123 was_callback_called_ = false; |
| 124 callback_result_ = NavigationThrottle::DEFER; | 124 callback_result_ = NavigationThrottle::DEFER; |
| 125 | 125 |
| 126 // It's safe to use base::Unretained since the NavigationHandle is owned by | 126 // It's safe to use base::Unretained since the NavigationHandle is owned by |
| 127 // the NavigationHandleImplTest. | 127 // the NavigationHandleImplTest. |
| 128 test_handle_->WillRedirectRequest( | 128 test_handle_->WillRedirectRequest( |
| 129 GURL(), "GET", GURL(), false, scoped_refptr<net::HttpResponseHeaders>(), | 129 GURL(), "GET", GURL(), false, scoped_refptr<net::HttpResponseHeaders>(), |
| 130 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1, |
| 130 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, | 131 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, |
| 131 base::Unretained(this))); | 132 base::Unretained(this))); |
| 132 } | 133 } |
| 133 | 134 |
| 134 // Helper function to call WillProcessResponse on |handle|. If this function | 135 // Helper function to call WillProcessResponse on |handle|. If this function |
| 135 // returns DEFER, |callback_result_| will be set to the actual result of the | 136 // returns DEFER, |callback_result_| will be set to the actual result of the |
| 136 // throttle checks when they are finished. | 137 // throttle checks when they are finished. |
| 137 // TODO(clamy): this should also simulate that WillStartRequest was called if | 138 // TODO(clamy): this should also simulate that WillStartRequest was called if |
| 138 // it has not been called before. | 139 // it has not been called before. |
| 139 void SimulateWillProcessResponse() { | 140 void SimulateWillProcessResponse() { |
| 140 was_callback_called_ = false; | 141 was_callback_called_ = false; |
| 141 callback_result_ = NavigationThrottle::DEFER; | 142 callback_result_ = NavigationThrottle::DEFER; |
| 142 | 143 |
| 143 // It's safe to use base::Unretained since the NavigationHandle is owned by | 144 // It's safe to use base::Unretained since the NavigationHandle is owned |
| 144 // the NavigationHandleImplTest. | 145 // by the NavigationHandleImplTest. The ConnectionInfo is different from |
| 146 // that sent to WillRedirectRequest to verify that it's correctly plumbed |
| 147 // in both cases. |
| 145 test_handle_->WillProcessResponse( | 148 test_handle_->WillProcessResponse( |
| 146 main_test_rfh(), | 149 main_test_rfh(), scoped_refptr<net::HttpResponseHeaders>(), |
| 147 scoped_refptr<net::HttpResponseHeaders>(), SSLStatus(), | 150 net::HttpResponseInfo::CONNECTION_INFO_QUIC, SSLStatus(), |
| 148 GlobalRequestID(), false, false, false, base::Closure(), | 151 GlobalRequestID(), false, false, false, base::Closure(), |
| 149 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, | 152 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, |
| 150 base::Unretained(this))); | 153 base::Unretained(this))); |
| 151 } | 154 } |
| 152 | 155 |
| 153 // Returns the handle used in tests. | 156 // Returns the handle used in tests. |
| 154 NavigationHandleImpl* test_handle() const { return test_handle_.get(); } | 157 NavigationHandleImpl* test_handle() const { return test_handle_.get(); } |
| 155 | 158 |
| 156 // Whether the callback was called. | 159 // Whether the callback was called. |
| 157 bool was_callback_called() const { return was_callback_called_; } | 160 bool was_callback_called() const { return was_callback_called_; } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 185 bool was_callback_called_; | 188 bool was_callback_called_; |
| 186 NavigationThrottle::ThrottleCheckResult callback_result_; | 189 NavigationThrottle::ThrottleCheckResult callback_result_; |
| 187 }; | 190 }; |
| 188 | 191 |
| 189 // Checks that the request_context_type is properly set. | 192 // Checks that the request_context_type is properly set. |
| 190 // Note: can be extended to cover more internal members. | 193 // Note: can be extended to cover more internal members. |
| 191 TEST_F(NavigationHandleImplTest, SimpleDataChecks) { | 194 TEST_F(NavigationHandleImplTest, SimpleDataChecks) { |
| 192 SimulateWillStartRequest(); | 195 SimulateWillStartRequest(); |
| 193 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, | 196 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| 194 test_handle()->GetRequestContextType()); | 197 test_handle()->GetRequestContextType()); |
| 198 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN, |
| 199 test_handle()->GetConnectionInfo()); |
| 195 | 200 |
| 196 test_handle()->Resume(); | 201 test_handle()->Resume(); |
| 197 SimulateWillRedirectRequest(); | 202 SimulateWillRedirectRequest(); |
| 198 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, | 203 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| 199 test_handle()->GetRequestContextType()); | 204 test_handle()->GetRequestContextType()); |
| 205 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1, |
| 206 test_handle()->GetConnectionInfo()); |
| 200 | 207 |
| 201 test_handle()->Resume(); | 208 test_handle()->Resume(); |
| 202 SimulateWillProcessResponse(); | 209 SimulateWillProcessResponse(); |
| 203 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, | 210 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| 204 test_handle()->GetRequestContextType()); | 211 test_handle()->GetRequestContextType()); |
| 212 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_QUIC, |
| 213 test_handle()->GetConnectionInfo()); |
| 214 } |
| 215 |
| 216 TEST_F(NavigationHandleImplTest, SimpleDataCheckNoRedirect) { |
| 217 SimulateWillStartRequest(); |
| 218 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN, |
| 219 test_handle()->GetConnectionInfo()); |
| 220 |
| 221 test_handle()->Resume(); |
| 222 SimulateWillProcessResponse(); |
| 223 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_QUIC, |
| 224 test_handle()->GetConnectionInfo()); |
| 205 } | 225 } |
| 206 | 226 |
| 207 // Checks that a deferred navigation can be properly resumed. | 227 // Checks that a deferred navigation can be properly resumed. |
| 208 TEST_F(NavigationHandleImplTest, ResumeDeferred) { | 228 TEST_F(NavigationHandleImplTest, ResumeDeferred) { |
| 209 TestNavigationThrottle* test_throttle = | 229 TestNavigationThrottle* test_throttle = |
| 210 CreateTestNavigationThrottle(NavigationThrottle::DEFER); | 230 CreateTestNavigationThrottle(NavigationThrottle::DEFER); |
| 211 EXPECT_FALSE(IsDeferringStart()); | 231 EXPECT_FALSE(IsDeferringStart()); |
| 212 EXPECT_FALSE(IsDeferringRedirect()); | 232 EXPECT_FALSE(IsDeferringRedirect()); |
| 213 EXPECT_FALSE(IsDeferringResponse()); | 233 EXPECT_FALSE(IsDeferringResponse()); |
| 214 EXPECT_EQ(0, test_throttle->will_start_calls()); | 234 EXPECT_EQ(0, test_throttle->will_start_calls()); |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 685 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 666 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 686 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 667 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 687 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 668 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 688 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
| 669 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 689 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 670 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 690 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 671 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 691 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
| 672 } | 692 } |
| 673 | 693 |
| 674 } // namespace content | 694 } // namespace content |
| OLD | NEW |