| Index: components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc
|
| diff --git a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc
|
| index 2b48bf66c373d7c4a34f3112bd2d006496e22e57..217afadb7164b3ede39203571bd3d91b8653e01a 100644
|
| --- a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc
|
| +++ b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc
|
| @@ -155,6 +155,15 @@ class ContentSubresourceFilterDriverFactoryTest
|
| safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
|
| }
|
|
|
| + void NavigateToUrlAndCommit(const GURL& url) {
|
| + EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1);
|
| + content::WebContentsTester::For(web_contents())->StartNavigation(url);
|
| + ::testing::Mock::VerifyAndClearExpectations(client());
|
| + factory()->ReadyToCommitMainFrameNavigation(main_rfh(), url);
|
| + content::RenderFrameHostTester::For(main_rfh())
|
| + ->SimulateNavigationCommit(url);
|
| + }
|
| +
|
| void ActivateAndExpectForFrameHostForUrl(MockSubresourceFilterDriver* driver,
|
| content::RenderFrameHost* rfh,
|
| const GURL& url,
|
| @@ -187,13 +196,7 @@ class ContentSubresourceFilterDriverFactoryTest
|
| ActivationState expected_activation_state) {
|
| EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_))
|
| .Times(should_activate);
|
| - EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1);
|
| - content::WebContentsTester::For(web_contents())->StartNavigation(url);
|
| - ::testing::Mock::VerifyAndClearExpectations(client());
|
| - factory()->ReadyToCommitMainFrameNavigation(main_rfh(), url);
|
| - content::RenderFrameHostTester::For(main_rfh())
|
| - ->SimulateNavigationCommit(url);
|
| -
|
| + NavigateToUrlAndCommit(url);
|
| ::testing::Mock::VerifyAndClearExpectations(driver());
|
|
|
| NavigateToUrlAndExpectActivationAndHidingPromptSubFrame(
|
| @@ -245,6 +248,7 @@ class ContentSubresourceFilterDriverFactoryThreatTypeTest
|
| factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
|
| test_url, std::vector<GURL>(), test_data.threat_type,
|
| test_data.threat_type_metadata);
|
| + NavigateToUrlAndCommit(test_url);
|
| EXPECT_EQ(test_data.should_add ? 1 : 0U,
|
| factory()->activation_set().size());
|
| EXPECT_EQ(test_data.should_add,
|
| @@ -258,15 +262,13 @@ class ContentSubresourceFilterDriverFactoryThreatTypeTest
|
| test_url, redirects, test_data.threat_type,
|
| test_data.threat_type_metadata);
|
| for (const auto& redirect : redirects) {
|
| - EXPECT_EQ(test_data.should_add,
|
| - factory()->ShouldActivateForURL(redirect));
|
| - EXPECT_EQ(test_data.should_add,
|
| - factory()->ShouldActivateForURL(redirect.GetWithEmptyPath()));
|
| - EXPECT_EQ(test_data.should_add, factory()->ShouldActivateForURL(
|
| - GURL("http://" + redirect.host())));
|
| - EXPECT_EQ(test_data.should_add,
|
| - factory()->ShouldActivateForURL(
|
| - GURL("http://" + redirect.host() + "/path?q=q")));
|
| + EXPECT_FALSE(factory()->ShouldActivateForURL(redirect));
|
| + EXPECT_FALSE(
|
| + factory()->ShouldActivateForURL(redirect.GetWithEmptyPath()));
|
| + EXPECT_FALSE(
|
| + factory()->ShouldActivateForURL(GURL("http://" + redirect.host())));
|
| + EXPECT_FALSE(factory()->ShouldActivateForURL(
|
| + GURL("http://" + redirect.host() + "/path?q=q")));
|
| }
|
| }
|
|
|
| @@ -281,6 +283,7 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest, SocEngHitEmptyRedirects) {
|
| kActivationScopeNoSites, kActivationListSocialEngineeringAdsInterstitial);
|
|
|
| BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>());
|
| + NavigateToUrlAndCommit(GURL(kExampleUrlWithParams));
|
| EXPECT_EQ(1U, factory()->activation_set().size());
|
|
|
| EXPECT_TRUE(factory()->ShouldActivateForURL(GURL(kExampleUrl)));
|
| @@ -308,15 +311,16 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest, SocEngHitWithRedirects) {
|
| redirects.push_back(GURL("https://example2.com"));
|
| redirects.push_back(GURL("https://example3.com"));
|
| BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), redirects);
|
| - EXPECT_EQ(4U, factory()->activation_set().size());
|
| + NavigateToUrlAndCommit(GURL(kExampleUrlWithParams));
|
| + EXPECT_EQ(1U, factory()->activation_set().size());
|
| EXPECT_TRUE(factory()->ShouldActivateForURL(GURL(kExampleUrl)));
|
|
|
| for (const auto& redirect : redirects) {
|
| - EXPECT_TRUE(factory()->ShouldActivateForURL(redirect));
|
| - EXPECT_TRUE(factory()->ShouldActivateForURL(redirect.GetWithEmptyPath()));
|
| - EXPECT_TRUE(
|
| + EXPECT_FALSE(factory()->ShouldActivateForURL(redirect));
|
| + EXPECT_FALSE(factory()->ShouldActivateForURL(redirect.GetWithEmptyPath()));
|
| + EXPECT_FALSE(
|
| factory()->ShouldActivateForURL(GURL("http://" + redirect.host())));
|
| - EXPECT_TRUE(factory()->ShouldActivateForURL(
|
| + EXPECT_FALSE(factory()->ShouldActivateForURL(
|
| GURL("http://" + redirect.host() + "/path?q=q")));
|
| }
|
| const GURL whitelisted("http://example.com/page?q=42");
|
| @@ -334,6 +338,7 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kTestUrl),
|
| false /* should_activate */);
|
| BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>());
|
| + NavigateToUrlAndCommit(GURL(kExampleUrlWithParams));
|
| ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(),
|
| GURL("https://not-example.com"),
|
| false /* should_activate */);
|
| @@ -347,6 +352,7 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest, ActivateForFrameHostNeeded) {
|
| kActivationListSocialEngineeringAdsInterstitial);
|
|
|
| BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>());
|
| + NavigateToUrlAndCommit(GURL(kExampleUrlWithParams));
|
| ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kTestUrl),
|
| false /* should_activate */);
|
| ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kExampleUrl),
|
|
|