| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "components/navigation_interception/intercept_navigation_resource_throt
tle.h" | 10 #include "components/navigation_interception/intercept_navigation_resource_throt
tle.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 class TestIOThreadState { | 115 class TestIOThreadState { |
| 116 public: | 116 public: |
| 117 TestIOThreadState(const GURL& url, | 117 TestIOThreadState(const GURL& url, |
| 118 int render_process_id, | 118 int render_process_id, |
| 119 int render_frame_id, | 119 int render_frame_id, |
| 120 const std::string& request_method, | 120 const std::string& request_method, |
| 121 RedirectMode redirect_mode, | 121 RedirectMode redirect_mode, |
| 122 MockInterceptCallbackReceiver* callback_receiver) | 122 MockInterceptCallbackReceiver* callback_receiver) |
| 123 : resource_context_(&test_url_request_context_), | 123 : resource_context_(&test_url_request_context_), |
| 124 request_(url, | 124 request_(resource_context_.GetRequestContext()->CreateRequest( |
| 125 net::DEFAULT_PRIORITY, | 125 url, |
| 126 NULL, | 126 net::DEFAULT_PRIORITY, |
| 127 resource_context_.GetRequestContext()) { | 127 NULL /* delegate */, |
| 128 NULL /* cookie_store */)) { |
| 128 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 129 if (render_process_id != MSG_ROUTING_NONE && | 130 if (render_process_id != MSG_ROUTING_NONE && |
| 130 render_frame_id != MSG_ROUTING_NONE) { | 131 render_frame_id != MSG_ROUTING_NONE) { |
| 131 content::ResourceRequestInfo::AllocateForTesting( | 132 content::ResourceRequestInfo::AllocateForTesting( |
| 132 &request_, | 133 request_.get(), |
| 133 content::RESOURCE_TYPE_MAIN_FRAME, | 134 content::RESOURCE_TYPE_MAIN_FRAME, |
| 134 &resource_context_, | 135 &resource_context_, |
| 135 render_process_id, | 136 render_process_id, |
| 136 MSG_ROUTING_NONE, | 137 MSG_ROUTING_NONE, |
| 137 render_frame_id, | 138 render_frame_id, |
| 138 false); | 139 false); |
| 139 } | 140 } |
| 140 throttle_.reset(new InterceptNavigationResourceThrottle( | 141 throttle_.reset(new InterceptNavigationResourceThrottle( |
| 141 &request_, | 142 request_.get(), |
| 142 base::Bind(&MockInterceptCallbackReceiver::ShouldIgnoreNavigation, | 143 base::Bind(&MockInterceptCallbackReceiver::ShouldIgnoreNavigation, |
| 143 base::Unretained(callback_receiver)))); | 144 base::Unretained(callback_receiver)))); |
| 144 throttle_->set_controller_for_testing(&throttle_controller_); | 145 throttle_->set_controller_for_testing(&throttle_controller_); |
| 145 request_.set_method(request_method); | 146 request_->set_method(request_method); |
| 146 | 147 |
| 147 if (redirect_mode == REDIRECT_MODE_302) { | 148 if (redirect_mode == REDIRECT_MODE_302) { |
| 148 net::HttpResponseInfo& response_info = | 149 net::HttpResponseInfo& response_info = |
| 149 const_cast<net::HttpResponseInfo&>(request_.response_info()); | 150 const_cast<net::HttpResponseInfo&>(request_->response_info()); |
| 150 response_info.headers = new net::HttpResponseHeaders( | 151 response_info.headers = new net::HttpResponseHeaders( |
| 151 "Status: 302 Found\0\0"); | 152 "Status: 302 Found\0\0"); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 155 void ThrottleWillStartRequest(bool* defer) { | 156 void ThrottleWillStartRequest(bool* defer) { |
| 156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 157 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 157 throttle_->WillStartRequest(defer); | 158 throttle_->WillStartRequest(defer); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void ThrottleWillRedirectRequest(const GURL& new_url, bool* defer) { | 161 void ThrottleWillRedirectRequest(const GURL& new_url, bool* defer) { |
| 161 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 162 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 162 throttle_->WillRedirectRequest(new_url, defer); | 163 throttle_->WillRedirectRequest(new_url, defer); |
| 163 } | 164 } |
| 164 | 165 |
| 165 bool request_resumed() const { | 166 bool request_resumed() const { |
| 166 return throttle_controller_.status() == | 167 return throttle_controller_.status() == |
| 167 MockResourceController::RESUMED; | 168 MockResourceController::RESUMED; |
| 168 } | 169 } |
| 169 | 170 |
| 170 bool request_cancelled() const { | 171 bool request_cancelled() const { |
| 171 return throttle_controller_.status() == | 172 return throttle_controller_.status() == |
| 172 MockResourceController::CANCELLED; | 173 MockResourceController::CANCELLED; |
| 173 } | 174 } |
| 174 | 175 |
| 175 private: | 176 private: |
| 176 net::TestURLRequestContext test_url_request_context_; | 177 net::TestURLRequestContext test_url_request_context_; |
| 177 content::MockResourceContext resource_context_; | 178 content::MockResourceContext resource_context_; |
| 178 net::URLRequest request_; | 179 scoped_ptr<net::URLRequest> request_; |
| 179 scoped_ptr<InterceptNavigationResourceThrottle> throttle_; | 180 scoped_ptr<InterceptNavigationResourceThrottle> throttle_; |
| 180 MockResourceController throttle_controller_; | 181 MockResourceController throttle_controller_; |
| 181 }; | 182 }; |
| 182 | 183 |
| 183 // InterceptNavigationResourceThrottleTest ------------------------------------ | 184 // InterceptNavigationResourceThrottleTest ------------------------------------ |
| 184 | 185 |
| 185 class InterceptNavigationResourceThrottleTest | 186 class InterceptNavigationResourceThrottleTest |
| 186 : public content::RenderViewHostTestHarness { | 187 : public content::RenderViewHostTestHarness { |
| 187 public: | 188 public: |
| 188 InterceptNavigationResourceThrottleTest() | 189 InterceptNavigationResourceThrottleTest() |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 REDIRECT_MODE_302, | 472 REDIRECT_MODE_302, |
| 472 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 473 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 473 web_contents()->GetMainFrame()->GetRoutingID(), | 474 web_contents()->GetMainFrame()->GetRoutingID(), |
| 474 base::Unretained(&defer))); | 475 base::Unretained(&defer))); |
| 475 | 476 |
| 476 // Wait for the request to finish processing. | 477 // Wait for the request to finish processing. |
| 477 base::RunLoop().RunUntilIdle(); | 478 base::RunLoop().RunUntilIdle(); |
| 478 } | 479 } |
| 479 | 480 |
| 480 } // namespace navigation_interception | 481 } // namespace navigation_interception |
| OLD | NEW |