| 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 "chrome/browser/renderer_host/intercept_navigation_resource_throttle.h" | 9 #include "chrome/browser/component/navigation_interception/intercept_navigation_
resource_throttle.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/resource_context.h" | 12 #include "content/public/browser/resource_context.h" |
| 13 #include "content/public/browser/resource_controller.h" |
| 13 #include "content/public/browser/resource_dispatcher_host.h" | 14 #include "content/public/browser/resource_dispatcher_host.h" |
| 14 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 15 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 15 #include "content/public/browser/resource_request_info.h" | 16 #include "content/public/browser/resource_request_info.h" |
| 16 #include "content/public/browser/resource_throttle.h" | 17 #include "content/public/browser/resource_throttle.h" |
| 17 #include "content/public/browser/resource_controller.h" | |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
| 20 #include "content/public/test/mock_resource_context.h" | 20 #include "content/public/test/mock_resource_context.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
| 22 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 using namespace content; | 26 using namespace content; |
| 27 using namespace navigation_interception; |
| 27 using namespace ::testing; | 28 using namespace ::testing; |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 const char* kTestUrl = "http://www.test.com/"; | 32 const char* kTestUrl = "http://www.test.com/"; |
| 32 const char* kUnsafeTestUrl = "about:crash"; | 33 const char* kUnsafeTestUrl = "about:crash"; |
| 33 | 34 |
| 34 void ContinueTestCase() { | 35 void ContinueTestCase() { |
| 35 BrowserThread::PostTask( | 36 BrowserThread::PostTask( |
| 36 BrowserThread::UI, | 37 BrowserThread::UI, |
| 37 FROM_HERE, | 38 FROM_HERE, |
| 38 MessageLoop::QuitClosure()); | 39 MessageLoop::QuitClosure()); |
| 39 } | 40 } |
| 40 | 41 |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 // MockInterceptCallbackReceiver ---------------------------------------------- | 44 // MockInterceptCallbackReceiver ---------------------------------------------- |
| 44 | 45 |
| 45 class MockInterceptCallbackReceiver { | 46 class MockInterceptCallbackReceiver { |
| 46 public: | 47 public: |
| 47 MOCK_METHOD4(ShouldIgnoreNavigation, bool(RenderViewHost* source, | 48 MOCK_METHOD4(ShouldIgnoreNavigation, bool(RenderViewHost* source, |
| 48 const GURL& url, | 49 const GURL& url, |
| 49 const content::Referrer& referrer, | 50 const content::Referrer& referrer, |
| 50 bool is_content_initiated)); | 51 bool has_user_gesture)); |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 // MockResourceController ----------------------------------------------------- | 54 // MockResourceController ----------------------------------------------------- |
| 54 class MockResourceController | 55 class MockResourceController |
| 55 : public content::ResourceController { | 56 : public content::ResourceController { |
| 56 public: | 57 public: |
| 57 enum Status { | 58 enum Status { |
| 58 UNKNOWN, | 59 UNKNOWN, |
| 59 RESUMED, | 60 RESUMED, |
| 60 CANCELLED | 61 CANCELLED |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 RunThrottleWillStartRequestOnIOThread, | 281 RunThrottleWillStartRequestOnIOThread, |
| 281 base::Unretained(this), | 282 base::Unretained(this), |
| 282 GURL(kUnsafeTestUrl), | 283 GURL(kUnsafeTestUrl), |
| 283 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 284 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 284 web_contents()->GetRenderViewHost()->GetRoutingID(), | 285 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 285 base::Unretained(&defer))); | 286 base::Unretained(&defer))); |
| 286 | 287 |
| 287 // Wait for the request to finish processing. | 288 // Wait for the request to finish processing. |
| 288 message_loop_.Run(); | 289 message_loop_.Run(); |
| 289 } | 290 } |
| OLD | NEW |