Chromium Code Reviews| 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 by |
| 144 // the NavigationHandleImplTest. | 145 // the NavigationHandleImplTest. |
| 145 test_handle_->WillProcessResponse( | 146 test_handle_->WillProcessResponse( |
| 146 main_test_rfh(), | 147 main_test_rfh(), scoped_refptr<net::HttpResponseHeaders>(), |
| 147 scoped_refptr<net::HttpResponseHeaders>(), SSLStatus(), | 148 net::HttpResponseInfo::CONNECTION_INFO_QUIC, SSLStatus(), |
|
clamy
2016/11/02 14:09:27
Why do you use different values in WillRedirectReq
jkarlin
2016/11/02 15:14:21
To verify that the connection info is plumbed thro
clamy
2016/11/02 15:32:33
Acknowledged. Could you add a comment explaining t
jkarlin
2016/11/02 15:44:48
Done.
| |
| 148 GlobalRequestID(), false, false, false, base::Closure(), | 149 GlobalRequestID(), false, false, false, base::Closure(), |
| 149 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, | 150 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, |
| 150 base::Unretained(this))); | 151 base::Unretained(this))); |
| 151 } | 152 } |
| 152 | 153 |
| 153 // Returns the handle used in tests. | 154 // Returns the handle used in tests. |
| 154 NavigationHandleImpl* test_handle() const { return test_handle_.get(); } | 155 NavigationHandleImpl* test_handle() const { return test_handle_.get(); } |
| 155 | 156 |
| 156 // Whether the callback was called. | 157 // Whether the callback was called. |
| 157 bool was_callback_called() const { return was_callback_called_; } | 158 bool was_callback_called() const { return was_callback_called_; } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 185 bool was_callback_called_; | 186 bool was_callback_called_; |
| 186 NavigationThrottle::ThrottleCheckResult callback_result_; | 187 NavigationThrottle::ThrottleCheckResult callback_result_; |
| 187 }; | 188 }; |
| 188 | 189 |
| 189 // Checks that the request_context_type is properly set. | 190 // Checks that the request_context_type is properly set. |
| 190 // Note: can be extended to cover more internal members. | 191 // Note: can be extended to cover more internal members. |
| 191 TEST_F(NavigationHandleImplTest, SimpleDataChecks) { | 192 TEST_F(NavigationHandleImplTest, SimpleDataChecks) { |
| 192 SimulateWillStartRequest(); | 193 SimulateWillStartRequest(); |
| 193 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, | 194 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| 194 test_handle()->GetRequestContextType()); | 195 test_handle()->GetRequestContextType()); |
| 196 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN, | |
| 197 test_handle()->GetConnectionInfo()); | |
| 195 | 198 |
| 196 test_handle()->Resume(); | 199 test_handle()->Resume(); |
| 197 SimulateWillRedirectRequest(); | 200 SimulateWillRedirectRequest(); |
| 198 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, | 201 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| 199 test_handle()->GetRequestContextType()); | 202 test_handle()->GetRequestContextType()); |
| 203 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1, | |
| 204 test_handle()->GetConnectionInfo()); | |
| 200 | 205 |
| 201 test_handle()->Resume(); | 206 test_handle()->Resume(); |
| 202 SimulateWillProcessResponse(); | 207 SimulateWillProcessResponse(); |
| 203 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, | 208 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| 204 test_handle()->GetRequestContextType()); | 209 test_handle()->GetRequestContextType()); |
| 210 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_QUIC, | |
| 211 test_handle()->GetConnectionInfo()); | |
| 212 } | |
| 213 | |
| 214 TEST_F(NavigationHandleImplTest, SimpleDataCheckNoRedirect) { | |
| 215 SimulateWillStartRequest(); | |
| 216 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN, | |
| 217 test_handle()->GetConnectionInfo()); | |
| 218 | |
| 219 test_handle()->Resume(); | |
| 220 SimulateWillProcessResponse(); | |
| 221 EXPECT_EQ(net::HttpResponseInfo::CONNECTION_INFO_QUIC, | |
| 222 test_handle()->GetConnectionInfo()); | |
| 205 } | 223 } |
| 206 | 224 |
| 207 // Checks that a deferred navigation can be properly resumed. | 225 // Checks that a deferred navigation can be properly resumed. |
| 208 TEST_F(NavigationHandleImplTest, ResumeDeferred) { | 226 TEST_F(NavigationHandleImplTest, ResumeDeferred) { |
| 209 TestNavigationThrottle* test_throttle = | 227 TestNavigationThrottle* test_throttle = |
| 210 CreateTestNavigationThrottle(NavigationThrottle::DEFER); | 228 CreateTestNavigationThrottle(NavigationThrottle::DEFER); |
| 211 EXPECT_FALSE(IsDeferringStart()); | 229 EXPECT_FALSE(IsDeferringStart()); |
| 212 EXPECT_FALSE(IsDeferringRedirect()); | 230 EXPECT_FALSE(IsDeferringRedirect()); |
| 213 EXPECT_FALSE(IsDeferringResponse()); | 231 EXPECT_FALSE(IsDeferringResponse()); |
| 214 EXPECT_EQ(0, test_throttle->will_start_calls()); | 232 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()); | 683 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 666 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 684 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 667 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 685 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 668 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 686 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
| 669 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 687 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 670 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 688 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 671 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 689 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
| 672 } | 690 } |
| 673 | 691 |
| 674 } // namespace content | 692 } // namespace content |
| OLD | NEW |