OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/subresource_filter/content/browser/content_subresource_filt er_throttle_manager.h" | |
6 | |
7 #include <memory> | |
8 #include <utility> | |
9 | |
10 #include "base/logging.h" | |
11 #include "base/memory/ptr_util.h" | |
12 #include "base/run_loop.h" | |
13 #include "base/strings/stringprintf.h" | |
14 #include "base/test/test_simple_task_runner.h" | |
15 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter.h" | |
16 #include "components/subresource_filter/core/common/activation_level.h" | |
17 #include "components/subresource_filter/core/common/activation_state.h" | |
18 #include "components/subresource_filter/core/common/proto/rules.pb.h" | |
19 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | |
20 #include "components/subresource_filter/core/common/test_ruleset_utils.h" | |
21 #include "content/public/browser/navigation_handle.h" | |
22 #include "content/public/browser/navigation_throttle.h" | |
23 #include "content/public/browser/web_contents.h" | |
24 #include "content/public/test/mock_render_process_host.h" | |
25 #include "content/public/test/navigation_simulator.h" | |
26 #include "content/public/test/test_renderer_host.h" | |
27 #include "testing/gtest/include/gtest/gtest.h" | |
28 | |
29 namespace subresource_filter { | |
30 | |
31 const char kActivatePageEnabled[] = "https://www.activate-page-enabled.com/"; | |
engedy
2017/03/10 20:50:35
nit: How about changing these from the imperative
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
32 const char kActivatePageEnabled2[] = "https://www.activate-page-enabled-2.com/"; | |
33 const char kActivatePageDryRun[] = "https://www.activate-page-dry-run/"; | |
34 | |
35 // Simple throttle that sends page-level activation to the manager for a | |
36 // specific set of URLs. | |
engedy
2017/03/10 20:50:35
nit: hardcoded set of testing URLs
Also, as disc
Charlie Harrison
2017/03/14 23:18:32
I couldn't think of a great criteria for which tes
engedy
2017/03/20 18:58:14
Hmm, I'm not against it as long as these parameter
Charlie Harrison
2017/03/20 20:02:56
Just did a gut check on the flakiness dashboard an
| |
37 class MockPageStateActivationThrottle : public content::NavigationThrottle { | |
38 public: | |
39 MockPageStateActivationThrottle( | |
40 content::NavigationHandle* navigation_handle, | |
41 ContentSubresourceFilterThrottleManager* throttle_manager) | |
42 : content::NavigationThrottle(navigation_handle), | |
43 throttle_manager_(throttle_manager) { | |
44 mock_page_activations_[GURL(kActivatePageEnabled)] = | |
45 ActivationState(ActivationLevel::ENABLED); | |
46 mock_page_activations_[GURL(kActivatePageEnabled2)] = | |
47 ActivationState(ActivationLevel::ENABLED); | |
48 mock_page_activations_[GURL(kActivatePageDryRun)] = | |
49 ActivationState(ActivationLevel::DRYRUN); | |
50 } | |
51 ~MockPageStateActivationThrottle() override {} | |
52 | |
53 // content::NavigationThrottle: | |
54 content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() | |
55 override { | |
56 auto it = mock_page_activations_.find(navigation_handle()->GetURL()); | |
57 if (it != mock_page_activations_.end()) { | |
58 throttle_manager_->NotifyPageActivationComputed(navigation_handle(), | |
59 it->second); | |
60 } | |
61 return content::NavigationThrottle::PROCEED; | |
62 } | |
63 | |
64 private: | |
65 std::map<GURL, ActivationState> mock_page_activations_; | |
66 ContentSubresourceFilterThrottleManager* throttle_manager_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(MockPageStateActivationThrottle); | |
69 }; | |
70 | |
71 class ContentSubresourceFilterThrottleManagerTest | |
72 : public content::RenderViewHostTestHarness, | |
73 public content::WebContentsObserver, | |
74 public ContentSubresourceFilterThrottleManager::Delegate { | |
75 public: | |
76 ContentSubresourceFilterThrottleManagerTest() | |
77 : ContentSubresourceFilterThrottleManager::Delegate() {} | |
78 ~ContentSubresourceFilterThrottleManagerTest() override {} | |
79 | |
80 // content::RenderViewHostTestHarness: | |
81 void SetUp() override { | |
82 content::RenderViewHostTestHarness::SetUp(); | |
83 | |
84 NavigateAndCommit(GURL("https://example.first")); | |
85 | |
86 Observe(RenderViewHostTestHarness::web_contents()); | |
87 | |
88 // Initialize the ruleset dealer. | |
89 std::vector<proto::UrlRule> rules; | |
90 rules.push_back(testing::CreateWhitelistRuleForDocument( | |
91 "whitelist.com", proto::ACTIVATION_TYPE_DOCUMENT, | |
92 {"activate-page-enabled.com"})); | |
93 rules.push_back(testing::CreateSuffixRule("disallowed.html")); | |
94 ASSERT_NO_FATAL_FAILURE(test_ruleset_creator_.CreateRulesetWithRules( | |
95 rules, &test_ruleset_pair_)); | |
96 | |
97 // Make the blocking task runner run on the current task runner for the | |
98 // tests, to ensure that the NavigationSimulator properly runs all necessary | |
99 // tasks while waiting for throttle checks to finish. | |
100 dealer_handle_ = base::MakeUnique<VerifiedRulesetDealer::Handle>( | |
101 base::MessageLoop::current()->task_runner()); | |
102 dealer_handle_->SetRulesetFile( | |
103 testing::TestRuleset::Open(test_ruleset_pair_.indexed)); | |
104 | |
105 throttle_manager_ = | |
106 base::MakeUnique<ContentSubresourceFilterThrottleManager>( | |
107 this, dealer_handle_.get(), | |
108 RenderViewHostTestHarness::web_contents()); | |
109 } | |
110 | |
111 void TearDown() override { | |
112 throttle_manager_.reset(); | |
113 dealer_handle_.reset(); | |
114 base::RunLoop().RunUntilIdle(); | |
115 content::RenderViewHostTestHarness::TearDown(); | |
116 } | |
117 | |
118 // content::WebContentsObserver | |
engedy
2017/03/10 20:50:34
nit: Once again, let's move these into a protected
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
119 void DidStartNavigation( | |
120 content::NavigationHandle* navigation_handle) override { | |
121 // Inject the proper throttles at this time. | |
122 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; | |
123 throttles.push_back(base::MakeUnique<MockPageStateActivationThrottle>( | |
124 navigation_handle, throttle_manager_.get())); | |
125 throttle_manager_->MaybeAppendNavigationThrottles(navigation_handle, | |
126 &throttles); | |
127 for (auto& it : throttles) { | |
128 navigation_handle->RegisterThrottleForTesting(std::move(it)); | |
129 } | |
130 } | |
131 | |
132 // ContentSubresourceFilterThrottleManager::Delegate: | |
133 void OnFirstSubresourceLoadDisallowed() override { | |
134 ++disallowed_notification_count_; | |
135 } | |
136 | |
137 bool ShouldSuppressActivation( | |
138 content::NavigationHandle* navigation_handle) override { | |
139 ++attempted_frame_activations_; | |
140 return urls_to_suppress_activation_.find(navigation_handle->GetURL()) != | |
141 urls_to_suppress_activation_.end(); | |
142 } | |
143 | |
144 // Helper methods: | |
145 | |
146 void CreateTestNavigation(const GURL& url, | |
147 content::RenderFrameHost* render_frame_host) { | |
148 DCHECK(!navigation_simulator_); | |
149 DCHECK(render_frame_host); | |
150 navigation_simulator_ = | |
151 content::NavigationSimulator::CreateRendererInitiated( | |
152 url, render_frame_host); | |
153 } | |
154 | |
155 void CreateTestSubframeNavigation(const GURL& url, | |
engedy
2017/03/10 20:50:35
nit: CreateSubframe{And|With}TestNavigation
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
156 content::RenderFrameHost* parent) { | |
157 content::RenderFrameHost* subframe = | |
158 content::RenderFrameHostTester::For(parent)->AppendChild( | |
159 base::StringPrintf("subframe-%s", url.spec().c_str())); | |
160 CreateTestNavigation(url, subframe); | |
161 } | |
162 | |
163 void SimulateStartAndExpectResult( | |
164 content::NavigationThrottle::ThrottleCheckResult expect_result) { | |
165 navigation_simulator_->Start(); | |
166 content::NavigationThrottle::ThrottleCheckResult result = | |
167 navigation_simulator_->GetLastThrottleCheckResult(); | |
168 EXPECT_EQ(expect_result, result); | |
169 if (result != content::NavigationThrottle::PROCEED) | |
170 navigation_simulator_.reset(); | |
171 } | |
172 | |
173 void SimulateRedirectAndExpectResult( | |
174 const GURL& new_url, | |
175 content::NavigationThrottle::ThrottleCheckResult expect_result) { | |
176 navigation_simulator_->Redirect(new_url); | |
177 content::NavigationThrottle::ThrottleCheckResult result = | |
178 navigation_simulator_->GetLastThrottleCheckResult(); | |
179 EXPECT_EQ(expect_result, result); | |
180 if (result != content::NavigationThrottle::PROCEED) | |
181 navigation_simulator_.reset(); | |
engedy
2017/03/10 20:50:34
Does this somehow call DidFinishNavigation?
Charlie Harrison
2017/03/14 23:18:32
No, it will be caused by the throttle cancelling i
engedy
2017/03/20 18:58:14
Ah, got it, thanks.
| |
182 } | |
183 | |
184 // Returns the RenderFrameHost that the navigation commit in. | |
185 content::RenderFrameHost* SimulateCommitAndExpectResult( | |
186 content::NavigationThrottle::ThrottleCheckResult expect_result) { | |
187 navigation_simulator_->Commit(); | |
188 content::NavigationThrottle::ThrottleCheckResult result = | |
189 navigation_simulator_->GetLastThrottleCheckResult(); | |
190 EXPECT_EQ(expect_result, result); | |
191 | |
192 auto scoped_simulator = std::move(navigation_simulator_); | |
193 if (result == content::NavigationThrottle::PROCEED) | |
194 return scoped_simulator->GetFinalRenderFrameHost(); | |
195 return nullptr; | |
196 } | |
197 | |
198 void SimulateSamePageCommit() { | |
199 navigation_simulator_->CommitSamePage(); | |
200 navigation_simulator_.reset(); | |
201 } | |
202 | |
203 void NavigateAndCommitMainFrame(const GURL& url) { | |
204 CreateTestNavigation(url, main_rfh()); | |
205 // A main frame navigation should never have start deferred. | |
engedy
2017/03/10 20:50:34
nit: This comment is no longer meaningful.
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
206 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
207 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
208 } | |
209 | |
210 void SuppressActivationForUrl(const GURL& url) { | |
211 urls_to_suppress_activation_.insert(url); | |
212 } | |
213 | |
214 bool ManagerHasRulesetHandle() { | |
215 return throttle_manager_->ruleset_handle_for_testing(); | |
216 } | |
217 | |
218 int disallowed_notification_count() { return disallowed_notification_count_; } | |
219 | |
220 int attempted_frame_activations() { return attempted_frame_activations_; } | |
221 | |
222 private: | |
223 testing::TestRulesetCreator test_ruleset_creator_; | |
224 testing::TestRulesetPair test_ruleset_pair_; | |
225 | |
226 std::set<GURL> urls_to_suppress_activation_; | |
227 | |
228 std::unique_ptr<VerifiedRulesetDealer::Handle> dealer_handle_; | |
229 | |
230 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; | |
231 | |
232 std::unique_ptr<content::NavigationSimulator> navigation_simulator_; | |
233 | |
234 // Logged on every OnFirstSubresourceLoadDisallowed call. | |
engedy
2017/03/10 20:50:34
nit: s/Logged/Incremented/g
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
235 int disallowed_notification_count_ = 0; | |
236 | |
237 // Logged every time the manager asks the harness for an activation | |
engedy
2017/03/10 20:50:34
nit: s/asks an/queries/
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
238 // suppression. | |
239 int attempted_frame_activations_ = 0; | |
240 | |
241 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManagerTest); | |
242 }; | |
243 | |
244 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
245 ActivateMainFrameAndFilterSubframeNavigation) { | |
246 // Commit a navigation that triggers page level activation. | |
247 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
248 | |
249 // A disallowed subframe navigation should be successfully filtered. | |
250 CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), | |
251 main_rfh()); | |
252 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
253 | |
254 EXPECT_EQ(1, disallowed_notification_count()); | |
255 EXPECT_EQ(1, attempted_frame_activations()); | |
256 } | |
257 | |
258 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
259 ActivateMainFrameAndDoNotFilterDryRun) { | |
260 // Commit a navigation that triggers page level activation. | |
261 NavigateAndCommitMainFrame(GURL(kActivatePageDryRun)); | |
262 | |
263 // A disallowed subframe navigation should not be filtered in dry-run mode. | |
264 CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), | |
265 main_rfh()); | |
266 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
267 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
268 | |
269 EXPECT_EQ(0, disallowed_notification_count()); | |
270 EXPECT_EQ(2, attempted_frame_activations()); | |
271 } | |
272 | |
273 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
274 ActivateMainFrameAndFilterSubframeNavigationOnRedirect) { | |
275 // Commit a navigation that triggers page level activation. | |
276 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
277 | |
278 // A disallowed subframe navigation via redirect should be successfully | |
279 // filtered. | |
280 CreateTestSubframeNavigation( | |
281 GURL("https://www.example.com/before-redirect.html"), main_rfh()); | |
282 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
283 SimulateRedirectAndExpectResult( | |
284 GURL("https://www.example.com/disallowed.html"), | |
285 content::NavigationThrottle::CANCEL); | |
286 | |
287 EXPECT_EQ(1, disallowed_notification_count()); | |
288 EXPECT_EQ(1, attempted_frame_activations()); | |
289 } | |
290 | |
291 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
292 ActivateMainFrameAndDoNotFilterSubframeNavigation) { | |
293 // Commit a navigation that triggers page level activation. | |
294 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
295 | |
296 // An allowed subframe navigation should complete successfully. | |
297 CreateTestSubframeNavigation(GURL("https://www.example.com/allowed1.html"), | |
298 main_rfh()); | |
299 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
300 SimulateRedirectAndExpectResult(GURL("https://www.example.com/allowed2.html"), | |
301 content::NavigationThrottle::PROCEED); | |
302 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
303 | |
304 EXPECT_EQ(0, disallowed_notification_count()); | |
305 EXPECT_EQ(2, attempted_frame_activations()); | |
306 } | |
307 | |
308 // This should fail if the throttle manager notifies the delegate twice of a | |
309 // disallowed load for the same page load. | |
310 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
311 ActivateMainFrameAndFilterTwoSubframeNavigations) { | |
312 // Commit a navigation that triggers page level activation. | |
313 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
314 | |
315 // A disallowed subframe navigation should be successfully filtered. | |
316 CreateTestSubframeNavigation( | |
317 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); | |
318 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
319 | |
320 EXPECT_EQ(1, disallowed_notification_count()); | |
321 | |
322 CreateTestSubframeNavigation( | |
323 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); | |
324 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
325 | |
326 EXPECT_EQ(1, disallowed_notification_count()); | |
327 EXPECT_EQ(1, attempted_frame_activations()); | |
328 } | |
329 | |
330 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
331 ActivateTwoMainFramesAndFilterTwoSubframeNavigations) { | |
332 // Commit a navigation that triggers page level activation. | |
333 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
334 | |
335 // A disallowed subframe navigation should be successfully filtered. | |
336 CreateTestSubframeNavigation( | |
337 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); | |
338 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
339 | |
340 EXPECT_EQ(1, disallowed_notification_count()); | |
341 | |
342 // Commit another navigation that triggers page level activation. | |
343 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled2)); | |
344 | |
345 CreateTestSubframeNavigation( | |
346 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); | |
347 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
348 | |
349 EXPECT_EQ(2, disallowed_notification_count()); | |
350 EXPECT_EQ(2, attempted_frame_activations()); | |
351 } | |
352 | |
353 // Test that the disallow load notification will not repeat if a load is | |
engedy
2017/03/10 20:50:35
nit: ... will not be repeated for the first disall
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
354 // disallowed after a same-document navigation. | |
355 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
356 ActivateMainFrameDoNotNotifyAfterSameDocumentNav) { | |
357 // Commit a navigation that triggers page level activation. | |
358 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
359 | |
360 // A disallowed subframe navigation should be successfully filtered. | |
361 CreateTestSubframeNavigation( | |
362 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); | |
363 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
364 | |
365 EXPECT_EQ(1, disallowed_notification_count()); | |
366 | |
367 // Commit another navigation that triggers page level activation. | |
368 GURL url2 = GURL(base::StringPrintf("%s#ref", kActivatePageEnabled)); | |
369 CreateTestNavigation(url2, main_rfh()); | |
370 SimulateSamePageCommit(); | |
371 | |
372 CreateTestSubframeNavigation( | |
373 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); | |
374 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
375 | |
376 EXPECT_EQ(1, disallowed_notification_count()); | |
377 EXPECT_EQ(1, attempted_frame_activations()); | |
378 } | |
379 | |
380 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
381 DoNotFilterForInactiveFrame) { | |
382 NavigateAndCommitMainFrame(GURL("https://do-not-activate.html")); | |
383 | |
384 // A subframe navigation should complete successfully. | |
385 CreateTestSubframeNavigation(GURL("https://www.example.com/allowed.html"), | |
386 main_rfh()); | |
387 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
388 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
389 | |
390 EXPECT_EQ(0, disallowed_notification_count()); | |
391 EXPECT_EQ(0, attempted_frame_activations()); | |
392 } | |
393 | |
394 TEST_F(ContentSubresourceFilterThrottleManagerTest, SuppressActivation) { | |
395 SuppressActivationForUrl(GURL(kActivatePageEnabled)); | |
396 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
397 | |
398 // A subframe navigation should complete successfully. | |
399 CreateTestSubframeNavigation(GURL("https://www.example.com/allowed.html"), | |
400 main_rfh()); | |
401 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
402 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
403 | |
404 EXPECT_EQ(0, disallowed_notification_count()); | |
405 EXPECT_EQ(1, attempted_frame_activations()); | |
406 } | |
407 | |
408 // Once there are no activated frames, the manager drops its ruleset handle. If | |
409 // another frame is activated, make sure the handle is regenerated. | |
410 TEST_F(ContentSubresourceFilterThrottleManagerTest, RulesetHandleRegeneration) { | |
411 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
412 | |
413 // A subframe navigation should complete successfully. | |
414 CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), | |
415 main_rfh()); | |
416 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
417 | |
418 EXPECT_EQ(1, disallowed_notification_count()); | |
419 | |
420 // Simulate a renderer crash which should delete the frame. | |
421 EXPECT_TRUE(ManagerHasRulesetHandle()); | |
422 process()->SimulateCrash(); | |
423 EXPECT_FALSE(ManagerHasRulesetHandle()); | |
424 | |
425 NavigateAndCommit(GURL("https://example.reset")); | |
426 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
427 | |
428 // A subframe navigation should complete successfully. | |
429 CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), | |
430 main_rfh()); | |
431 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
432 | |
433 EXPECT_EQ(2, disallowed_notification_count()); | |
434 EXPECT_EQ(2, attempted_frame_activations()); | |
435 } | |
436 | |
437 // Ensure activation propagates into great-grandchild frames, including cross | |
438 // process ones. | |
439 TEST_F(ContentSubresourceFilterThrottleManagerTest, ActivationPropagation) { | |
440 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
441 | |
442 // Navigate a subframe that is not filtered, but should still activate. | |
engedy
2017/03/10 20:50:34
nit: To clarify the terminology around this unit t
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
443 CreateTestSubframeNavigation(GURL("https://www.example.com/allowed.html"), | |
444 main_rfh()); | |
445 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
446 content::RenderFrameHost* subframe1 = | |
447 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
448 | |
449 // Navigate a sub-subframe that is not filtered, but should still activate. | |
450 CreateTestSubframeNavigation(GURL("https://www.example.com/allowed.html"), | |
engedy
2017/03/10 20:50:35
For good measure, let's make this cross-origin too
Charlie Harrison
2017/03/14 23:18:32
Done.
| |
451 subframe1); | |
452 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
453 content::RenderFrameHost* subframe2 = | |
454 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
455 | |
456 // A final, nested subframe navigation is filtered. | |
457 CreateTestSubframeNavigation(GURL("https://example.com/disallowed.html"), | |
458 subframe2); | |
459 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
460 | |
461 EXPECT_EQ(1, disallowed_notification_count()); | |
462 EXPECT_EQ(3, attempted_frame_activations()); | |
463 } | |
464 | |
465 // Ensure activation propagates through whitelisted documents. | |
466 TEST_F(ContentSubresourceFilterThrottleManagerTest, ActivationPropagation2) { | |
467 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
468 | |
469 // Navigate a subframe that is not filtered, but should still activate. | |
470 CreateTestSubframeNavigation(GURL("https://whitelist.com"), main_rfh()); | |
471 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
472 content::RenderFrameHost* subframe1 = | |
473 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
474 | |
475 // Navigate a sub-subframe that is not filtered due to the whitelist. | |
476 CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), | |
477 subframe1); | |
478 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
479 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
480 | |
481 EXPECT_EQ(3, attempted_frame_activations()); | |
482 EXPECT_EQ(0, disallowed_notification_count()); | |
483 | |
484 // An identical series of events that don't match whitelist rules cause | |
485 // filtering. | |
486 CreateTestSubframeNavigation(GURL("https://average-joe.com"), main_rfh()); | |
487 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
488 content::RenderFrameHost* subframe3 = | |
489 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
490 | |
491 // Navigate a sub-subframe that is not filtered due to the whitelist. | |
492 CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), | |
493 subframe3); | |
494 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | |
495 | |
496 EXPECT_EQ(4, attempted_frame_activations()); | |
497 EXPECT_EQ(1, disallowed_notification_count()); | |
498 } | |
499 | |
500 // Same-site navigations within a single RFH do not persist activation. | |
501 TEST_F(ContentSubresourceFilterThrottleManagerTest, | |
502 SameSiteNavigationStopsActivation) { | |
503 NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); | |
504 EXPECT_EQ(1, attempted_frame_activations()); | |
505 | |
506 // Mock a same-site navigation, in the same RFH, this URL does not trigger | |
507 // page level activation. | |
508 NavigateAndCommitMainFrame( | |
509 GURL(base::StringPrintf("%s/some_path/", kActivatePageEnabled))); | |
510 EXPECT_EQ(1, attempted_frame_activations()); | |
511 | |
512 CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), | |
513 main_rfh()); | |
514 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
515 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
516 | |
517 EXPECT_EQ(0, disallowed_notification_count()); | |
518 EXPECT_EQ(1, attempted_frame_activations()); | |
519 } | |
520 | |
521 // TODO(csharrison): Make sure the following conditions are exercised in tests: | |
522 // | |
523 // - Verify IPCs are sent on activation. | |
524 | |
525 } // namespace subresource_filter | |
OLD | NEW |