| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This test creates a safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
| 6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
| 7 // service. | 7 // service. |
| 8 | 8 |
| 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 10 | 10 |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 test_ruleset_publisher.SetRuleset(test_ruleset_pair.unindexed)); | 921 test_ruleset_publisher.SetRuleset(test_ruleset_pair.unindexed)); |
| 922 | 922 |
| 923 GURL phishing_url = embedded_test_server()->GetURL( | 923 GURL phishing_url = embedded_test_server()->GetURL( |
| 924 "/subresource_filter/frame_with_included_script.html"); | 924 "/subresource_filter/frame_with_included_script.html"); |
| 925 SBFullHashResult malware_full_hash; | 925 SBFullHashResult malware_full_hash; |
| 926 GenUrlFullHashResultWithMetadata(phishing_url, PHISH, | 926 GenUrlFullHashResultWithMetadata(phishing_url, PHISH, |
| 927 ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 927 ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
| 928 &malware_full_hash); | 928 &malware_full_hash); |
| 929 SetupResponseForUrl(phishing_url, malware_full_hash); | 929 SetupResponseForUrl(phishing_url, malware_full_hash); |
| 930 | 930 |
| 931 WebContents* web_contents = |
| 932 browser()->tab_strip_model()->GetActiveWebContents(); |
| 933 auto* driver_factory = subresource_filter:: |
| 934 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); |
| 935 driver_factory->set_configuration_for_testing( |
| 936 subresource_filter::GetActiveConfiguration()); |
| 937 |
| 931 // Navigation to a phishing page should trigger an interstitial. If the user | 938 // Navigation to a phishing page should trigger an interstitial. If the user |
| 932 // clicks through it, the page load should proceed, but with subresource | 939 // clicks through it, the page load should proceed, but with subresource |
| 933 // filtering activated. This is verified by probing whether `included_script` | 940 // filtering activated. This is verified by probing whether `included_script` |
| 934 // that is disallowed above indeed fails to load. | 941 // that is disallowed above indeed fails to load. |
| 935 WebContents* web_contents = | |
| 936 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 937 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(phishing_url))); | 942 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(phishing_url))); |
| 938 ui_test_utils::NavigateToURL(browser(), phishing_url); | 943 ui_test_utils::NavigateToURL(browser(), phishing_url); |
| 939 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&observer_)); | 944 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&observer_)); |
| 940 ASSERT_TRUE(got_hit_report()); | 945 ASSERT_TRUE(got_hit_report()); |
| 941 content::WaitForInterstitialAttach(web_contents); | 946 content::WaitForInterstitialAttach(web_contents); |
| 942 ASSERT_TRUE(ShowingInterstitialPage()); | 947 ASSERT_TRUE(ShowingInterstitialPage()); |
| 943 | 948 |
| 944 content::WindowedNotificationObserver load_stop_observer( | 949 content::WindowedNotificationObserver load_stop_observer( |
| 945 content::NOTIFICATION_LOAD_STOP, | 950 content::NOTIFICATION_LOAD_STOP, |
| 946 content::Source<content::NavigationController>( | 951 content::Source<content::NavigationController>( |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1989 "included_script.js", &test_ruleset_pair); | 1994 "included_script.js", &test_ruleset_pair); |
| 1990 subresource_filter::testing::TestRulesetPublisher test_ruleset_publisher; | 1995 subresource_filter::testing::TestRulesetPublisher test_ruleset_publisher; |
| 1991 ASSERT_NO_FATAL_FAILURE( | 1996 ASSERT_NO_FATAL_FAILURE( |
| 1992 test_ruleset_publisher.SetRuleset(test_ruleset_pair.unindexed)); | 1997 test_ruleset_publisher.SetRuleset(test_ruleset_pair.unindexed)); |
| 1993 | 1998 |
| 1994 GURL phishing_url = embedded_test_server()->GetURL( | 1999 GURL phishing_url = embedded_test_server()->GetURL( |
| 1995 "/subresource_filter/frame_with_included_script.html"); | 2000 "/subresource_filter/frame_with_included_script.html"); |
| 1996 MarkUrlForPhishingUnexpired(phishing_url, | 2001 MarkUrlForPhishingUnexpired(phishing_url, |
| 1997 ThreatPatternType::SOCIAL_ENGINEERING_ADS); | 2002 ThreatPatternType::SOCIAL_ENGINEERING_ADS); |
| 1998 | 2003 |
| 2004 WebContents* web_contents = |
| 2005 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2006 auto* driver_factory = subresource_filter:: |
| 2007 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); |
| 2008 driver_factory->set_configuration_for_testing( |
| 2009 subresource_filter::GetActiveConfiguration()); |
| 2010 |
| 1999 // Navigation to a phishing page should trigger an interstitial. If the user | 2011 // Navigation to a phishing page should trigger an interstitial. If the user |
| 2000 // clicks through it, the page load should proceed, but with subresource | 2012 // clicks through it, the page load should proceed, but with subresource |
| 2001 // filtering activated. This is verified by probing whether `included_script` | 2013 // filtering activated. This is verified by probing whether `included_script` |
| 2002 // that is disallowed above indeed fails to load. | 2014 // that is disallowed above indeed fails to load. |
| 2003 WebContents* web_contents = | |
| 2004 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2005 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(phishing_url))); | 2015 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(phishing_url))); |
| 2006 ui_test_utils::NavigateToURL(browser(), phishing_url); | 2016 ui_test_utils::NavigateToURL(browser(), phishing_url); |
| 2007 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&observer_)); | 2017 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&observer_)); |
| 2008 ASSERT_TRUE(got_hit_report()); | 2018 ASSERT_TRUE(got_hit_report()); |
| 2009 content::WaitForInterstitialAttach(web_contents); | 2019 content::WaitForInterstitialAttach(web_contents); |
| 2010 ASSERT_TRUE(ShowingInterstitialPage()); | 2020 ASSERT_TRUE(ShowingInterstitialPage()); |
| 2011 | 2021 |
| 2012 content::WindowedNotificationObserver load_stop_observer( | 2022 content::WindowedNotificationObserver load_stop_observer( |
| 2013 content::NOTIFICATION_LOAD_STOP, | 2023 content::NOTIFICATION_LOAD_STOP, |
| 2014 content::Source<content::NavigationController>( | 2024 content::Source<content::NavigationController>( |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2487 } | 2497 } |
| 2488 | 2498 |
| 2489 INSTANTIATE_TEST_CASE_P( | 2499 INSTANTIATE_TEST_CASE_P( |
| 2490 MaybeSetMetadata, | 2500 MaybeSetMetadata, |
| 2491 V4SafeBrowsingServiceMetadataTest, | 2501 V4SafeBrowsingServiceMetadataTest, |
| 2492 testing::Values(ThreatPatternType::NONE, | 2502 testing::Values(ThreatPatternType::NONE, |
| 2493 ThreatPatternType::MALWARE_LANDING, | 2503 ThreatPatternType::MALWARE_LANDING, |
| 2494 ThreatPatternType::MALWARE_DISTRIBUTION)); | 2504 ThreatPatternType::MALWARE_DISTRIBUTION)); |
| 2495 | 2505 |
| 2496 } // namespace safe_browsing | 2506 } // namespace safe_browsing |
| OLD | NEW |