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/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 "components/navigation_interception/intercept_navigation_throttle.h" | 8 #include "components/navigation_interception/intercept_navigation_throttle.h" |
9 #include "components/navigation_interception/navigation_params.h" | 9 #include "components/navigation_interception/navigation_params.h" |
10 #include "content/public/browser/navigation_handle.h" | 10 #include "content/public/browser/navigation_handle.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 class InterceptNavigationThrottleTest | 53 class InterceptNavigationThrottleTest |
54 : public content::RenderViewHostTestHarness { | 54 : public content::RenderViewHostTestHarness { |
55 public: | 55 public: |
56 InterceptNavigationThrottleTest() | 56 InterceptNavigationThrottleTest() |
57 : mock_callback_receiver_(new MockInterceptCallbackReceiver()) {} | 57 : mock_callback_receiver_(new MockInterceptCallbackReceiver()) {} |
58 | 58 |
59 NavigationThrottle::ThrottleCheckResult | 59 NavigationThrottle::ThrottleCheckResult |
60 SimulateWillStart(const GURL& url, const GURL& sanitized_url, bool is_post) { | 60 SimulateWillStart(const GURL& url, const GURL& sanitized_url, bool is_post) { |
61 scoped_ptr<content::NavigationHandle> test_handle = | 61 scoped_ptr<content::NavigationHandle> test_handle = |
62 content::NavigationHandle::CreateNavigationHandleForTesting( | 62 content::NavigationHandle::CreateNavigationHandleForTesting( |
63 url, true, web_contents()); | 63 url, true, main_rfh()); |
64 test_handle->RegisterThrottleForTesting( | 64 test_handle->RegisterThrottleForTesting( |
65 scoped_ptr<NavigationThrottle>( | 65 scoped_ptr<NavigationThrottle>( |
66 new InterceptNavigationThrottle( | 66 new InterceptNavigationThrottle( |
67 test_handle.get(), | 67 test_handle.get(), |
68 base::Bind( | 68 base::Bind( |
69 &MockInterceptCallbackReceiver::ShouldIgnoreNavigation, | 69 &MockInterceptCallbackReceiver::ShouldIgnoreNavigation, |
70 base::Unretained(mock_callback_receiver_.get())))) | 70 base::Unretained(mock_callback_receiver_.get())))) |
71 .Pass()); | 71 .Pass()); |
72 return test_handle->CallWillStartRequestForTesting( | 72 return test_handle->CallWillStartRequestForTesting( |
73 is_post, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); | 73 is_post, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); |
74 } | 74 } |
75 | 75 |
76 NavigationThrottle::ThrottleCheckResult Simulate302() { | 76 NavigationThrottle::ThrottleCheckResult Simulate302() { |
77 scoped_ptr<content::NavigationHandle> test_handle = | 77 scoped_ptr<content::NavigationHandle> test_handle = |
78 content::NavigationHandle::CreateNavigationHandleForTesting( | 78 content::NavigationHandle::CreateNavigationHandleForTesting( |
79 GURL(kTestUrl), true, web_contents()); | 79 GURL(kTestUrl), true, main_rfh()); |
80 test_handle->RegisterThrottleForTesting( | 80 test_handle->RegisterThrottleForTesting( |
81 scoped_ptr<NavigationThrottle>( | 81 scoped_ptr<NavigationThrottle>( |
82 new InterceptNavigationThrottle( | 82 new InterceptNavigationThrottle( |
83 test_handle.get(), | 83 test_handle.get(), |
84 base::Bind( | 84 base::Bind( |
85 &MockInterceptCallbackReceiver::ShouldIgnoreNavigation, | 85 &MockInterceptCallbackReceiver::ShouldIgnoreNavigation, |
86 base::Unretained(mock_callback_receiver_.get())))) | 86 base::Unretained(mock_callback_receiver_.get())))) |
87 .Pass()); | 87 .Pass()); |
88 test_handle->CallWillStartRequestForTesting( | 88 test_handle->CallWillStartRequestForTesting( |
89 true, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); | 89 true, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 ShouldIgnoreNavigation( | 156 ShouldIgnoreNavigation( |
157 _, AllOf(NavigationParamsUrlIsTest(), | 157 _, AllOf(NavigationParamsUrlIsTest(), |
158 Property(&NavigationParams::is_post, Eq(false))))) | 158 Property(&NavigationParams::is_post, Eq(false))))) |
159 .WillOnce(Return(false)); | 159 .WillOnce(Return(false)); |
160 NavigationThrottle::ThrottleCheckResult result = Simulate302(); | 160 NavigationThrottle::ThrottleCheckResult result = Simulate302(); |
161 | 161 |
162 EXPECT_EQ(NavigationThrottle::PROCEED, result); | 162 EXPECT_EQ(NavigationThrottle::PROCEED, result); |
163 } | 163 } |
164 | 164 |
165 } // namespace navigation_interception | 165 } // namespace navigation_interception |
OLD | NEW |