| 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/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "components/navigation_interception/intercept_navigation_resource_throt
tle.h" | 11 #include "components/navigation_interception/intercept_navigation_resource_throt
tle.h" |
| 12 #include "components/navigation_interception/navigation_params.h" | 12 #include "components/navigation_interception/navigation_params.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/resource_context.h" | 15 #include "content/public/browser/resource_context.h" |
| 16 #include "content/public/browser/resource_controller.h" | 16 #include "content/public/browser/resource_controller.h" |
| 17 #include "content/public/browser/resource_dispatcher_host.h" | 17 #include "content/public/browser/resource_dispatcher_host.h" |
| 18 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 18 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 19 #include "content/public/browser/resource_request_info.h" | 19 #include "content/public/browser/resource_request_info.h" |
| 20 #include "content/public/browser/resource_throttle.h" | 20 #include "content/public/browser/resource_throttle.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_delegate.h" | 22 #include "content/public/browser/web_contents_delegate.h" |
| 23 #include "content/public/common/page_transition_types.h" | 23 #include "content/public/common/page_transition_types.h" |
| 24 #include "content/public/test/mock_resource_context.h" | 24 #include "content/public/test/mock_resource_context.h" |
| 25 #include "content/public/test/test_renderer_host.h" | 25 #include "content/public/test/test_renderer_host.h" |
| 26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 27 #include "net/http/http_response_info.h" | 27 #include "net/http/http_response_info.h" |
| 28 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
| 29 #include "net/url_request/url_request_test_util.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 using testing::_; | 33 using testing::_; |
| 33 using testing::Eq; | 34 using testing::Eq; |
| 35 using testing::Ne; |
| 34 using testing::Property; | 36 using testing::Property; |
| 35 using testing::Ne; | |
| 36 using testing::Return; | 37 using testing::Return; |
| 37 | 38 |
| 38 namespace navigation_interception { | 39 namespace navigation_interception { |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 const char kTestUrl[] = "http://www.test.com/"; | 43 const char kTestUrl[] = "http://www.test.com/"; |
| 43 const char kUnsafeTestUrl[] = "about:crash"; | 44 const char kUnsafeTestUrl[] = "about:crash"; |
| 44 | 45 |
| 45 // The MS C++ compiler complains about not being able to resolve which url() | 46 // The MS C++ compiler complains about not being able to resolve which url() |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 }; | 111 }; |
| 111 | 112 |
| 112 class TestIOThreadState { | 113 class TestIOThreadState { |
| 113 public: | 114 public: |
| 114 TestIOThreadState(const GURL& url, | 115 TestIOThreadState(const GURL& url, |
| 115 int render_process_id, | 116 int render_process_id, |
| 116 int render_view_id, | 117 int render_view_id, |
| 117 const std::string& request_method, | 118 const std::string& request_method, |
| 118 RedirectMode redirect_mode, | 119 RedirectMode redirect_mode, |
| 119 MockInterceptCallbackReceiver* callback_receiver) | 120 MockInterceptCallbackReceiver* callback_receiver) |
| 120 : request_(url, NULL, resource_context_.GetRequestContext()) { | 121 : resource_context_(&test_url_request_context_), |
| 122 request_(url, NULL, resource_context_.GetRequestContext()) { |
| 121 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 122 if (render_process_id != MSG_ROUTING_NONE && | 124 if (render_process_id != MSG_ROUTING_NONE && |
| 123 render_view_id != MSG_ROUTING_NONE) { | 125 render_view_id != MSG_ROUTING_NONE) { |
| 124 content::ResourceRequestInfo::AllocateForTesting( | 126 content::ResourceRequestInfo::AllocateForTesting( |
| 125 &request_, | 127 &request_, |
| 126 ResourceType::MAIN_FRAME, | 128 ResourceType::MAIN_FRAME, |
| 127 &resource_context_, | 129 &resource_context_, |
| 128 render_process_id, | 130 render_process_id, |
| 129 render_view_id); | 131 render_view_id); |
| 130 } | 132 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 157 return throttle_controller_.status() == | 159 return throttle_controller_.status() == |
| 158 MockResourceController::RESUMED; | 160 MockResourceController::RESUMED; |
| 159 } | 161 } |
| 160 | 162 |
| 161 bool request_cancelled() const { | 163 bool request_cancelled() const { |
| 162 return throttle_controller_.status() == | 164 return throttle_controller_.status() == |
| 163 MockResourceController::CANCELLED; | 165 MockResourceController::CANCELLED; |
| 164 } | 166 } |
| 165 | 167 |
| 166 private: | 168 private: |
| 169 net::TestURLRequestContext test_url_request_context_; |
| 167 content::MockResourceContext resource_context_; | 170 content::MockResourceContext resource_context_; |
| 168 net::URLRequest request_; | 171 net::URLRequest request_; |
| 169 scoped_ptr<InterceptNavigationResourceThrottle> throttle_; | 172 scoped_ptr<InterceptNavigationResourceThrottle> throttle_; |
| 170 MockResourceController throttle_controller_; | 173 MockResourceController throttle_controller_; |
| 171 }; | 174 }; |
| 172 | 175 |
| 173 // InterceptNavigationResourceThrottleTest ------------------------------------ | 176 // InterceptNavigationResourceThrottleTest ------------------------------------ |
| 174 | 177 |
| 175 class InterceptNavigationResourceThrottleTest | 178 class InterceptNavigationResourceThrottleTest |
| 176 : public content::RenderViewHostTestHarness { | 179 : public content::RenderViewHostTestHarness { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 REDIRECT_MODE_302, | 466 REDIRECT_MODE_302, |
| 464 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 467 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 465 web_contents()->GetRenderViewHost()->GetRoutingID(), | 468 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 466 base::Unretained(&defer))); | 469 base::Unretained(&defer))); |
| 467 | 470 |
| 468 // Wait for the request to finish processing. | 471 // Wait for the request to finish processing. |
| 469 base::RunLoop().RunUntilIdle(); | 472 base::RunLoop().RunUntilIdle(); |
| 470 } | 473 } |
| 471 | 474 |
| 472 } // namespace navigation_interception | 475 } // namespace navigation_interception |
| OLD | NEW |