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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, main_rfh()); | 63 url, main_rfh()); |
64 test_handle->RegisterThrottleForTesting( | 64 test_handle->RegisterThrottleForTesting( |
65 scoped_ptr<NavigationThrottle>( | 65 scoped_ptr<NavigationThrottle>(new InterceptNavigationThrottle( |
66 new InterceptNavigationThrottle( | 66 test_handle.get(), |
67 test_handle.get(), | 67 base::Bind(&MockInterceptCallbackReceiver::ShouldIgnoreNavigation, |
68 base::Bind( | 68 base::Unretained(mock_callback_receiver_.get())), |
69 &MockInterceptCallbackReceiver::ShouldIgnoreNavigation, | 69 true))); |
70 base::Unretained(mock_callback_receiver_.get())), | |
71 true)) | |
72 .Pass()); | |
73 return test_handle->CallWillStartRequestForTesting( | 70 return test_handle->CallWillStartRequestForTesting( |
74 is_post, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); | 71 is_post, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); |
75 } | 72 } |
76 | 73 |
77 NavigationThrottle::ThrottleCheckResult Simulate302() { | 74 NavigationThrottle::ThrottleCheckResult Simulate302() { |
78 scoped_ptr<content::NavigationHandle> test_handle = | 75 scoped_ptr<content::NavigationHandle> test_handle = |
79 content::NavigationHandle::CreateNavigationHandleForTesting( | 76 content::NavigationHandle::CreateNavigationHandleForTesting( |
80 GURL(kTestUrl), main_rfh()); | 77 GURL(kTestUrl), main_rfh()); |
81 test_handle->RegisterThrottleForTesting( | 78 test_handle->RegisterThrottleForTesting( |
82 scoped_ptr<NavigationThrottle>( | 79 scoped_ptr<NavigationThrottle>(new InterceptNavigationThrottle( |
83 new InterceptNavigationThrottle( | 80 test_handle.get(), |
84 test_handle.get(), | 81 base::Bind(&MockInterceptCallbackReceiver::ShouldIgnoreNavigation, |
85 base::Bind( | 82 base::Unretained(mock_callback_receiver_.get())), |
86 &MockInterceptCallbackReceiver::ShouldIgnoreNavigation, | 83 true))); |
87 base::Unretained(mock_callback_receiver_.get())), | |
88 true)) | |
89 .Pass()); | |
90 test_handle->CallWillStartRequestForTesting( | 84 test_handle->CallWillStartRequestForTesting( |
91 true, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); | 85 true, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); |
92 return test_handle->CallWillRedirectRequestForTesting(GURL(kTestUrl), false, | 86 return test_handle->CallWillRedirectRequestForTesting(GURL(kTestUrl), false, |
93 GURL(), false); | 87 GURL(), false); |
94 } | 88 } |
95 | 89 |
96 scoped_ptr<MockInterceptCallbackReceiver> mock_callback_receiver_; | 90 scoped_ptr<MockInterceptCallbackReceiver> mock_callback_receiver_; |
97 }; | 91 }; |
98 | 92 |
99 TEST_F(InterceptNavigationThrottleTest, | 93 TEST_F(InterceptNavigationThrottleTest, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 ShouldIgnoreNavigation( | 152 ShouldIgnoreNavigation( |
159 _, AllOf(NavigationParamsUrlIsTest(), | 153 _, AllOf(NavigationParamsUrlIsTest(), |
160 Property(&NavigationParams::is_post, Eq(false))))) | 154 Property(&NavigationParams::is_post, Eq(false))))) |
161 .WillOnce(Return(false)); | 155 .WillOnce(Return(false)); |
162 NavigationThrottle::ThrottleCheckResult result = Simulate302(); | 156 NavigationThrottle::ThrottleCheckResult result = Simulate302(); |
163 | 157 |
164 EXPECT_EQ(NavigationThrottle::PROCEED, result); | 158 EXPECT_EQ(NavigationThrottle::PROCEED, result); |
165 } | 159 } |
166 | 160 |
167 } // namespace navigation_interception | 161 } // namespace navigation_interception |
OLD | NEW |