Index: components/subresource_filter/content/browser/content_subresource_filter_throttle_manager_unittest.cc |
diff --git a/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager_unittest.cc b/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3e212060b4f0192a5d3ad8cd3505e19af1dc908c |
--- /dev/null |
+++ b/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager_unittest.cc |
@@ -0,0 +1,525 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h" |
+ |
+#include <memory> |
+#include <utility> |
+ |
+#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
+#include "base/run_loop.h" |
+#include "base/strings/stringprintf.h" |
+#include "base/test/test_simple_task_runner.h" |
+#include "components/subresource_filter/content/browser/async_document_subresource_filter.h" |
+#include "components/subresource_filter/core/common/activation_level.h" |
+#include "components/subresource_filter/core/common/activation_state.h" |
+#include "components/subresource_filter/core/common/proto/rules.pb.h" |
+#include "components/subresource_filter/core/common/test_ruleset_creator.h" |
+#include "components/subresource_filter/core/common/test_ruleset_utils.h" |
+#include "content/public/browser/navigation_handle.h" |
+#include "content/public/browser/navigation_throttle.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/test/mock_render_process_host.h" |
+#include "content/public/test/navigation_simulator.h" |
+#include "content/public/test/test_renderer_host.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace subresource_filter { |
+ |
+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.
|
+const char kActivatePageEnabled2[] = "https://www.activate-page-enabled-2.com/"; |
+const char kActivatePageDryRun[] = "https://www.activate-page-dry-run/"; |
+ |
+// Simple throttle that sends page-level activation to the manager for a |
+// 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
|
+class MockPageStateActivationThrottle : public content::NavigationThrottle { |
+ public: |
+ MockPageStateActivationThrottle( |
+ content::NavigationHandle* navigation_handle, |
+ ContentSubresourceFilterThrottleManager* throttle_manager) |
+ : content::NavigationThrottle(navigation_handle), |
+ throttle_manager_(throttle_manager) { |
+ mock_page_activations_[GURL(kActivatePageEnabled)] = |
+ ActivationState(ActivationLevel::ENABLED); |
+ mock_page_activations_[GURL(kActivatePageEnabled2)] = |
+ ActivationState(ActivationLevel::ENABLED); |
+ mock_page_activations_[GURL(kActivatePageDryRun)] = |
+ ActivationState(ActivationLevel::DRYRUN); |
+ } |
+ ~MockPageStateActivationThrottle() override {} |
+ |
+ // content::NavigationThrottle: |
+ content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() |
+ override { |
+ auto it = mock_page_activations_.find(navigation_handle()->GetURL()); |
+ if (it != mock_page_activations_.end()) { |
+ throttle_manager_->NotifyPageActivationComputed(navigation_handle(), |
+ it->second); |
+ } |
+ return content::NavigationThrottle::PROCEED; |
+ } |
+ |
+ private: |
+ std::map<GURL, ActivationState> mock_page_activations_; |
+ ContentSubresourceFilterThrottleManager* throttle_manager_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MockPageStateActivationThrottle); |
+}; |
+ |
+class ContentSubresourceFilterThrottleManagerTest |
+ : public content::RenderViewHostTestHarness, |
+ public content::WebContentsObserver, |
+ public ContentSubresourceFilterThrottleManager::Delegate { |
+ public: |
+ ContentSubresourceFilterThrottleManagerTest() |
+ : ContentSubresourceFilterThrottleManager::Delegate() {} |
+ ~ContentSubresourceFilterThrottleManagerTest() override {} |
+ |
+ // content::RenderViewHostTestHarness: |
+ void SetUp() override { |
+ content::RenderViewHostTestHarness::SetUp(); |
+ |
+ NavigateAndCommit(GURL("https://example.first")); |
+ |
+ Observe(RenderViewHostTestHarness::web_contents()); |
+ |
+ // Initialize the ruleset dealer. |
+ std::vector<proto::UrlRule> rules; |
+ rules.push_back(testing::CreateWhitelistRuleForDocument( |
+ "whitelist.com", proto::ACTIVATION_TYPE_DOCUMENT, |
+ {"activate-page-enabled.com"})); |
+ rules.push_back(testing::CreateSuffixRule("disallowed.html")); |
+ ASSERT_NO_FATAL_FAILURE(test_ruleset_creator_.CreateRulesetWithRules( |
+ rules, &test_ruleset_pair_)); |
+ |
+ // Make the blocking task runner run on the current task runner for the |
+ // tests, to ensure that the NavigationSimulator properly runs all necessary |
+ // tasks while waiting for throttle checks to finish. |
+ dealer_handle_ = base::MakeUnique<VerifiedRulesetDealer::Handle>( |
+ base::MessageLoop::current()->task_runner()); |
+ dealer_handle_->SetRulesetFile( |
+ testing::TestRuleset::Open(test_ruleset_pair_.indexed)); |
+ |
+ throttle_manager_ = |
+ base::MakeUnique<ContentSubresourceFilterThrottleManager>( |
+ this, dealer_handle_.get(), |
+ RenderViewHostTestHarness::web_contents()); |
+ } |
+ |
+ void TearDown() override { |
+ throttle_manager_.reset(); |
+ dealer_handle_.reset(); |
+ base::RunLoop().RunUntilIdle(); |
+ content::RenderViewHostTestHarness::TearDown(); |
+ } |
+ |
+ // 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.
|
+ void DidStartNavigation( |
+ content::NavigationHandle* navigation_handle) override { |
+ // Inject the proper throttles at this time. |
+ std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
+ throttles.push_back(base::MakeUnique<MockPageStateActivationThrottle>( |
+ navigation_handle, throttle_manager_.get())); |
+ throttle_manager_->MaybeAppendNavigationThrottles(navigation_handle, |
+ &throttles); |
+ for (auto& it : throttles) { |
+ navigation_handle->RegisterThrottleForTesting(std::move(it)); |
+ } |
+ } |
+ |
+ // ContentSubresourceFilterThrottleManager::Delegate: |
+ void OnFirstSubresourceLoadDisallowed() override { |
+ ++disallowed_notification_count_; |
+ } |
+ |
+ bool ShouldSuppressActivation( |
+ content::NavigationHandle* navigation_handle) override { |
+ ++attempted_frame_activations_; |
+ return urls_to_suppress_activation_.find(navigation_handle->GetURL()) != |
+ urls_to_suppress_activation_.end(); |
+ } |
+ |
+ // Helper methods: |
+ |
+ void CreateTestNavigation(const GURL& url, |
+ content::RenderFrameHost* render_frame_host) { |
+ DCHECK(!navigation_simulator_); |
+ DCHECK(render_frame_host); |
+ navigation_simulator_ = |
+ content::NavigationSimulator::CreateRendererInitiated( |
+ url, render_frame_host); |
+ } |
+ |
+ 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.
|
+ content::RenderFrameHost* parent) { |
+ content::RenderFrameHost* subframe = |
+ content::RenderFrameHostTester::For(parent)->AppendChild( |
+ base::StringPrintf("subframe-%s", url.spec().c_str())); |
+ CreateTestNavigation(url, subframe); |
+ } |
+ |
+ void SimulateStartAndExpectResult( |
+ content::NavigationThrottle::ThrottleCheckResult expect_result) { |
+ navigation_simulator_->Start(); |
+ content::NavigationThrottle::ThrottleCheckResult result = |
+ navigation_simulator_->GetLastThrottleCheckResult(); |
+ EXPECT_EQ(expect_result, result); |
+ if (result != content::NavigationThrottle::PROCEED) |
+ navigation_simulator_.reset(); |
+ } |
+ |
+ void SimulateRedirectAndExpectResult( |
+ const GURL& new_url, |
+ content::NavigationThrottle::ThrottleCheckResult expect_result) { |
+ navigation_simulator_->Redirect(new_url); |
+ content::NavigationThrottle::ThrottleCheckResult result = |
+ navigation_simulator_->GetLastThrottleCheckResult(); |
+ EXPECT_EQ(expect_result, result); |
+ if (result != content::NavigationThrottle::PROCEED) |
+ 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.
|
+ } |
+ |
+ // Returns the RenderFrameHost that the navigation commit in. |
+ content::RenderFrameHost* SimulateCommitAndExpectResult( |
+ content::NavigationThrottle::ThrottleCheckResult expect_result) { |
+ navigation_simulator_->Commit(); |
+ content::NavigationThrottle::ThrottleCheckResult result = |
+ navigation_simulator_->GetLastThrottleCheckResult(); |
+ EXPECT_EQ(expect_result, result); |
+ |
+ auto scoped_simulator = std::move(navigation_simulator_); |
+ if (result == content::NavigationThrottle::PROCEED) |
+ return scoped_simulator->GetFinalRenderFrameHost(); |
+ return nullptr; |
+ } |
+ |
+ void SimulateSamePageCommit() { |
+ navigation_simulator_->CommitSamePage(); |
+ navigation_simulator_.reset(); |
+ } |
+ |
+ void NavigateAndCommitMainFrame(const GURL& url) { |
+ CreateTestNavigation(url, main_rfh()); |
+ // 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.
|
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ } |
+ |
+ void SuppressActivationForUrl(const GURL& url) { |
+ urls_to_suppress_activation_.insert(url); |
+ } |
+ |
+ bool ManagerHasRulesetHandle() { |
+ return throttle_manager_->ruleset_handle_for_testing(); |
+ } |
+ |
+ int disallowed_notification_count() { return disallowed_notification_count_; } |
+ |
+ int attempted_frame_activations() { return attempted_frame_activations_; } |
+ |
+ private: |
+ testing::TestRulesetCreator test_ruleset_creator_; |
+ testing::TestRulesetPair test_ruleset_pair_; |
+ |
+ std::set<GURL> urls_to_suppress_activation_; |
+ |
+ std::unique_ptr<VerifiedRulesetDealer::Handle> dealer_handle_; |
+ |
+ std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; |
+ |
+ std::unique_ptr<content::NavigationSimulator> navigation_simulator_; |
+ |
+ // 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.
|
+ int disallowed_notification_count_ = 0; |
+ |
+ // 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.
|
+ // suppression. |
+ int attempted_frame_activations_ = 0; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManagerTest); |
+}; |
+ |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ ActivateMainFrameAndFilterSubframeNavigation) { |
+ // Commit a navigation that triggers page level activation. |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // A disallowed subframe navigation should be successfully filtered. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ EXPECT_EQ(1, attempted_frame_activations()); |
+} |
+ |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ ActivateMainFrameAndDoNotFilterDryRun) { |
+ // Commit a navigation that triggers page level activation. |
+ NavigateAndCommitMainFrame(GURL(kActivatePageDryRun)); |
+ |
+ // A disallowed subframe navigation should not be filtered in dry-run mode. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ EXPECT_EQ(0, disallowed_notification_count()); |
+ EXPECT_EQ(2, attempted_frame_activations()); |
+} |
+ |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ ActivateMainFrameAndFilterSubframeNavigationOnRedirect) { |
+ // Commit a navigation that triggers page level activation. |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // A disallowed subframe navigation via redirect should be successfully |
+ // filtered. |
+ CreateTestSubframeNavigation( |
+ GURL("https://www.example.com/before-redirect.html"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ SimulateRedirectAndExpectResult( |
+ GURL("https://www.example.com/disallowed.html"), |
+ content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ EXPECT_EQ(1, attempted_frame_activations()); |
+} |
+ |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ ActivateMainFrameAndDoNotFilterSubframeNavigation) { |
+ // Commit a navigation that triggers page level activation. |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // An allowed subframe navigation should complete successfully. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/allowed1.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ SimulateRedirectAndExpectResult(GURL("https://www.example.com/allowed2.html"), |
+ content::NavigationThrottle::PROCEED); |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ EXPECT_EQ(0, disallowed_notification_count()); |
+ EXPECT_EQ(2, attempted_frame_activations()); |
+} |
+ |
+// This should fail if the throttle manager notifies the delegate twice of a |
+// disallowed load for the same page load. |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ ActivateMainFrameAndFilterTwoSubframeNavigations) { |
+ // Commit a navigation that triggers page level activation. |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // A disallowed subframe navigation should be successfully filtered. |
+ CreateTestSubframeNavigation( |
+ GURL("https://www.example.com/1/disallowed.html"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ |
+ CreateTestSubframeNavigation( |
+ GURL("https://www.example.com/2/disallowed.html"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ EXPECT_EQ(1, attempted_frame_activations()); |
+} |
+ |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ ActivateTwoMainFramesAndFilterTwoSubframeNavigations) { |
+ // Commit a navigation that triggers page level activation. |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // A disallowed subframe navigation should be successfully filtered. |
+ CreateTestSubframeNavigation( |
+ GURL("https://www.example.com/1/disallowed.html"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ |
+ // Commit another navigation that triggers page level activation. |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled2)); |
+ |
+ CreateTestSubframeNavigation( |
+ GURL("https://www.example.com/2/disallowed.html"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(2, disallowed_notification_count()); |
+ EXPECT_EQ(2, attempted_frame_activations()); |
+} |
+ |
+// 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.
|
+// disallowed after a same-document navigation. |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ ActivateMainFrameDoNotNotifyAfterSameDocumentNav) { |
+ // Commit a navigation that triggers page level activation. |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // A disallowed subframe navigation should be successfully filtered. |
+ CreateTestSubframeNavigation( |
+ GURL("https://www.example.com/1/disallowed.html"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ |
+ // Commit another navigation that triggers page level activation. |
+ GURL url2 = GURL(base::StringPrintf("%s#ref", kActivatePageEnabled)); |
+ CreateTestNavigation(url2, main_rfh()); |
+ SimulateSamePageCommit(); |
+ |
+ CreateTestSubframeNavigation( |
+ GURL("https://www.example.com/2/disallowed.html"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ EXPECT_EQ(1, attempted_frame_activations()); |
+} |
+ |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ DoNotFilterForInactiveFrame) { |
+ NavigateAndCommitMainFrame(GURL("https://do-not-activate.html")); |
+ |
+ // A subframe navigation should complete successfully. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/allowed.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ EXPECT_EQ(0, disallowed_notification_count()); |
+ EXPECT_EQ(0, attempted_frame_activations()); |
+} |
+ |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, SuppressActivation) { |
+ SuppressActivationForUrl(GURL(kActivatePageEnabled)); |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // A subframe navigation should complete successfully. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/allowed.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ EXPECT_EQ(0, disallowed_notification_count()); |
+ EXPECT_EQ(1, attempted_frame_activations()); |
+} |
+ |
+// Once there are no activated frames, the manager drops its ruleset handle. If |
+// another frame is activated, make sure the handle is regenerated. |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, RulesetHandleRegeneration) { |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // A subframe navigation should complete successfully. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ |
+ // Simulate a renderer crash which should delete the frame. |
+ EXPECT_TRUE(ManagerHasRulesetHandle()); |
+ process()->SimulateCrash(); |
+ EXPECT_FALSE(ManagerHasRulesetHandle()); |
+ |
+ NavigateAndCommit(GURL("https://example.reset")); |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // A subframe navigation should complete successfully. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(2, disallowed_notification_count()); |
+ EXPECT_EQ(2, attempted_frame_activations()); |
+} |
+ |
+// Ensure activation propagates into great-grandchild frames, including cross |
+// process ones. |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, ActivationPropagation) { |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // 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.
|
+ CreateTestSubframeNavigation(GURL("https://www.example.com/allowed.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ content::RenderFrameHost* subframe1 = |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ // Navigate a sub-subframe that is not filtered, but should still activate. |
+ 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.
|
+ subframe1); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ content::RenderFrameHost* subframe2 = |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ // A final, nested subframe navigation is filtered. |
+ CreateTestSubframeNavigation(GURL("https://example.com/disallowed.html"), |
+ subframe2); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+ EXPECT_EQ(3, attempted_frame_activations()); |
+} |
+ |
+// Ensure activation propagates through whitelisted documents. |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, ActivationPropagation2) { |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ |
+ // Navigate a subframe that is not filtered, but should still activate. |
+ CreateTestSubframeNavigation(GURL("https://whitelist.com"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ content::RenderFrameHost* subframe1 = |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ // Navigate a sub-subframe that is not filtered due to the whitelist. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), |
+ subframe1); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ EXPECT_EQ(3, attempted_frame_activations()); |
+ EXPECT_EQ(0, disallowed_notification_count()); |
+ |
+ // An identical series of events that don't match whitelist rules cause |
+ // filtering. |
+ CreateTestSubframeNavigation(GURL("https://average-joe.com"), main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ content::RenderFrameHost* subframe3 = |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ // Navigate a sub-subframe that is not filtered due to the whitelist. |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), |
+ subframe3); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
+ |
+ EXPECT_EQ(4, attempted_frame_activations()); |
+ EXPECT_EQ(1, disallowed_notification_count()); |
+} |
+ |
+// Same-site navigations within a single RFH do not persist activation. |
+TEST_F(ContentSubresourceFilterThrottleManagerTest, |
+ SameSiteNavigationStopsActivation) { |
+ NavigateAndCommitMainFrame(GURL(kActivatePageEnabled)); |
+ EXPECT_EQ(1, attempted_frame_activations()); |
+ |
+ // Mock a same-site navigation, in the same RFH, this URL does not trigger |
+ // page level activation. |
+ NavigateAndCommitMainFrame( |
+ GURL(base::StringPrintf("%s/some_path/", kActivatePageEnabled))); |
+ EXPECT_EQ(1, attempted_frame_activations()); |
+ |
+ CreateTestSubframeNavigation(GURL("https://www.example.com/disallowed.html"), |
+ main_rfh()); |
+ SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
+ SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
+ |
+ EXPECT_EQ(0, disallowed_notification_count()); |
+ EXPECT_EQ(1, attempted_frame_activations()); |
+} |
+ |
+// TODO(csharrison): Make sure the following conditions are exercised in tests: |
+// |
+// - Verify IPCs are sent on activation. |
+ |
+} // namespace subresource_filter |