OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/subresource_filter/content/browser/activation_state_computi
ng_navigation_throttle.h" | 5 #include "components/subresource_filter/content/browser/activation_state_computi
ng_navigation_throttle.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 void CreateTestNavigationForSubframe( | 101 void CreateTestNavigationForSubframe( |
102 const GURL& first_url, | 102 const GURL& first_url, |
103 const ActivationState& parent_activation_state) { | 103 const ActivationState& parent_activation_state) { |
104 subframe_ = content::RenderFrameHostTester::For(main_rfh()) | 104 subframe_ = content::RenderFrameHostTester::For(main_rfh()) |
105 ->AppendChild("subframe"); | 105 ->AppendChild("subframe"); |
106 test_handle_ = content::NavigationHandle::CreateNavigationHandleForTesting( | 106 test_handle_ = content::NavigationHandle::CreateNavigationHandleForTesting( |
107 first_url, subframe_); | 107 first_url, subframe_); |
108 std::unique_ptr<ActivationStateComputingNavigationThrottle> throttle = | 108 std::unique_ptr<ActivationStateComputingNavigationThrottle> throttle = |
109 ActivationStateComputingNavigationThrottle::CreateForSubframe( | 109 ActivationStateComputingNavigationThrottle::CreateForSubframe( |
110 test_handle_.get(), ruleset_handle(), parent_activation_state); | 110 test_handle_.get(), ruleset_handle(), parent_activation_state, |
| 111 base::OnceClosure()); |
111 test_throttle_ = throttle.get(); | 112 test_throttle_ = throttle.get(); |
112 test_handle_->RegisterThrottleForTesting(std::move(throttle)); | 113 test_handle_->RegisterThrottleForTesting(std::move(throttle)); |
113 } | 114 } |
114 | 115 |
115 void SimulateWillStartAndExpectToProceed() { | 116 void SimulateWillStartAndExpectToProceed() { |
116 EXPECT_EQ(content::NavigationThrottle::PROCEED, | 117 EXPECT_EQ(content::NavigationThrottle::PROCEED, |
117 test_handle_->CallWillStartRequestForTesting( | 118 test_handle_->CallWillStartRequestForTesting( |
118 false /* is_post */, content::Referrer(), | 119 false /* is_post */, content::Referrer(), |
119 true /* has_user_gesture */, | 120 true /* has_user_gesture */, |
120 ui::PageTransition::PAGE_TRANSITION_LINK, | 121 ui::PageTransition::PAGE_TRANSITION_LINK, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 }; | 175 }; |
175 | 176 |
176 // Main frame tests | 177 // Main frame tests |
177 TEST_F(ActivationStateComputingNavigationThrottleTest, ActivateMainFrame) { | 178 TEST_F(ActivationStateComputingNavigationThrottleTest, ActivateMainFrame) { |
178 CreateTestNavigationForMainFrame(GURL("http://example.test/activate.html")); | 179 CreateTestNavigationForMainFrame(GURL("http://example.test/activate.html")); |
179 SimulateWillStartAndExpectToProceed(); | 180 SimulateWillStartAndExpectToProceed(); |
180 SimulateWillRedirectAndExpectToProceed( | 181 SimulateWillRedirectAndExpectToProceed( |
181 GURL("http://example.test/activate.html?v=1")); | 182 GURL("http://example.test/activate.html?v=1")); |
182 | 183 |
183 test_throttle()->NotifyPageActivationWithRuleset( | 184 test_throttle()->NotifyPageActivationWithRuleset( |
184 ruleset_handle(), ActivationState(ActivationLevel::ENABLED)); | 185 ruleset_handle(), ActivationState(ActivationLevel::ENABLED), |
| 186 base::OnceClosure()); |
185 SimulateWillProcessResponseAndExpectResult( | 187 SimulateWillProcessResponseAndExpectResult( |
186 true /* expect_async */, content::NavigationThrottle::PROCEED); | 188 true /* expect_async */, content::NavigationThrottle::PROCEED); |
187 | 189 |
188 // Simulate ReadyToCommitNavigation. | 190 // Simulate ReadyToCommitNavigation. |
189 ActivationState state = test_throttle()->GetActivationState(); | 191 ActivationState state = test_throttle()->GetActivationState(); |
190 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); | 192 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); |
191 EXPECT_FALSE(state.filtering_disabled_for_document); | 193 EXPECT_FALSE(state.filtering_disabled_for_document); |
192 DCHECK(test_throttle()->ReleaseFilter()); | 194 DCHECK(test_throttle()->ReleaseFilter()); |
193 } | 195 } |
194 | 196 |
(...skipping 17 matching lines...) Expand all Loading... |
212 TEST_F(ActivationStateComputingNavigationThrottleTest, | 214 TEST_F(ActivationStateComputingNavigationThrottleTest, |
213 DoNotActivateMainFrameForInactivePage2) { | 215 DoNotActivateMainFrameForInactivePage2) { |
214 CreateTestNavigationForMainFrame(GURL("http://example.test/inactivate.html")); | 216 CreateTestNavigationForMainFrame(GURL("http://example.test/inactivate.html")); |
215 SimulateWillStartAndExpectToProceed(); | 217 SimulateWillStartAndExpectToProceed(); |
216 SimulateWillRedirectAndExpectToProceed( | 218 SimulateWillRedirectAndExpectToProceed( |
217 GURL("http://example.test/inactivate.html?v=1")); | 219 GURL("http://example.test/inactivate.html?v=1")); |
218 | 220 |
219 // Notify that the page level state is explicitly disabled. Should be | 221 // Notify that the page level state is explicitly disabled. Should be |
220 // equivalent to not sending the message at all. | 222 // equivalent to not sending the message at all. |
221 test_throttle()->NotifyPageActivationWithRuleset( | 223 test_throttle()->NotifyPageActivationWithRuleset( |
222 nullptr, ActivationState(ActivationLevel::DISABLED)); | 224 nullptr, ActivationState(ActivationLevel::DISABLED), base::OnceClosure()); |
223 SimulateWillProcessResponseAndExpectResult( | 225 SimulateWillProcessResponseAndExpectResult( |
224 false /* expect_async */, content::NavigationThrottle::PROCEED); | 226 false /* expect_async */, content::NavigationThrottle::PROCEED); |
225 | 227 |
226 // Simulate ReadyToCommitNavigation. | 228 // Simulate ReadyToCommitNavigation. |
227 ActivationState state = test_throttle()->GetActivationState(); | 229 ActivationState state = test_throttle()->GetActivationState(); |
228 EXPECT_EQ(ActivationLevel::DISABLED, state.activation_level); | 230 EXPECT_EQ(ActivationLevel::DISABLED, state.activation_level); |
229 DCHECK(!test_throttle()->ReleaseFilter()); | 231 DCHECK(!test_throttle()->ReleaseFilter()); |
230 } | 232 } |
231 | 233 |
232 TEST_F(ActivationStateComputingNavigationThrottleTest, | 234 TEST_F(ActivationStateComputingNavigationThrottleTest, |
233 ActivateMainFrameWhitelistedSubframe) { | 235 ActivateMainFrameWhitelistedSubframe) { |
234 InitializeDocumentSubresourceFilter(GURL("http://parent.com/")); | 236 InitializeDocumentSubresourceFilter(GURL("http://parent.com/")); |
235 // Not really a child frame, so whitelist should not apply. | 237 // Not really a child frame, so whitelist should not apply. |
236 CreateTestNavigationForMainFrame(GURL("http://whitelist.com/")); | 238 CreateTestNavigationForMainFrame(GURL("http://whitelist.com/")); |
237 SimulateWillStartAndExpectToProceed(); | 239 SimulateWillStartAndExpectToProceed(); |
238 | 240 |
239 // Main frames will usually have their "parent" activation state set right | 241 // Main frames will usually have their "parent" activation state set right |
240 // before WillProcessResponse. | 242 // before WillProcessResponse. |
241 test_throttle()->NotifyPageActivationWithRuleset( | 243 test_throttle()->NotifyPageActivationWithRuleset( |
242 ruleset_handle(), ActivationState(ActivationLevel::ENABLED)); | 244 ruleset_handle(), ActivationState(ActivationLevel::ENABLED), |
| 245 base::OnceClosure()); |
243 SimulateWillProcessResponseAndExpectResult( | 246 SimulateWillProcessResponseAndExpectResult( |
244 true /* expect_async */, content::NavigationThrottle::PROCEED); | 247 true /* expect_async */, content::NavigationThrottle::PROCEED); |
245 | 248 |
246 // Simulate ReadyToCommitNavigation. | 249 // Simulate ReadyToCommitNavigation. |
247 ActivationState state = test_throttle()->GetActivationState(); | 250 ActivationState state = test_throttle()->GetActivationState(); |
248 EXPECT_FALSE(state.filtering_disabled_for_document); | 251 EXPECT_FALSE(state.filtering_disabled_for_document); |
249 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); | 252 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); |
250 DCHECK(test_throttle()->ReleaseFilter()); | 253 DCHECK(test_throttle()->ReleaseFilter()); |
251 } | 254 } |
252 | 255 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 340 |
338 // Simulate ReadyToCommitNavigation. | 341 // Simulate ReadyToCommitNavigation. |
339 ActivationState state = test_throttle()->GetActivationState(); | 342 ActivationState state = test_throttle()->GetActivationState(); |
340 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); | 343 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); |
341 EXPECT_FALSE(state.filtering_disabled_for_document); | 344 EXPECT_FALSE(state.filtering_disabled_for_document); |
342 EXPECT_TRUE(state.generic_blocking_rules_disabled); | 345 EXPECT_TRUE(state.generic_blocking_rules_disabled); |
343 DCHECK(test_throttle()->ReleaseFilter()); | 346 DCHECK(test_throttle()->ReleaseFilter()); |
344 } | 347 } |
345 | 348 |
346 } // namespace subresource_filter | 349 } // namespace subresource_filter |
OLD | NEW |