Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 #include "chrome/test/base/in_process_browser_test.h" | 47 #include "chrome/test/base/in_process_browser_test.h" |
| 48 #include "chrome/test/base/ui_test_utils.h" | 48 #include "chrome/test/base/ui_test_utils.h" |
| 49 #include "components/bookmarks/browser/startup_task_runner_service.h" | 49 #include "components/bookmarks/browser/startup_task_runner_service.h" |
| 50 #include "components/content_settings/core/browser/host_content_settings_map.h" | 50 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 51 #include "components/prefs/pref_service.h" | 51 #include "components/prefs/pref_service.h" |
| 52 #include "components/safe_browsing/common/safebrowsing_switches.h" | 52 #include "components/safe_browsing/common/safebrowsing_switches.h" |
| 53 #include "components/safe_browsing_db/database_manager.h" | 53 #include "components/safe_browsing_db/database_manager.h" |
| 54 #include "components/safe_browsing_db/metadata.pb.h" | 54 #include "components/safe_browsing_db/metadata.pb.h" |
| 55 #include "components/safe_browsing_db/test_database_manager.h" | 55 #include "components/safe_browsing_db/test_database_manager.h" |
| 56 #include "components/safe_browsing_db/util.h" | 56 #include "components/safe_browsing_db/util.h" |
| 57 #include "components/safe_browsing_db/v4_database.h" | |
| 58 #include "components/safe_browsing_db/v4_feature_list.h" | |
| 59 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | |
| 57 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 60 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 58 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver.h" | 61 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver.h" |
| 59 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" | 62 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" |
| 60 #include "components/subresource_filter/core/browser/subresource_filter_features .h" | 63 #include "components/subresource_filter/core/browser/subresource_filter_features .h" |
| 61 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" | 64 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" |
| 62 #include "content/public/browser/interstitial_page.h" | 65 #include "content/public/browser/interstitial_page.h" |
| 63 #include "content/public/browser/navigation_entry.h" | 66 #include "content/public/browser/navigation_entry.h" |
| 64 #include "content/public/browser/render_frame_host.h" | 67 #include "content/public/browser/render_frame_host.h" |
| 65 #include "content/public/browser/web_contents.h" | 68 #include "content/public/browser/web_contents.h" |
| 66 #include "content/public/test/browser_test_utils.h" | 69 #include "content/public/test/browser_test_utils.h" |
| 70 #include "crypto/sha2.h" | |
| 67 #include "net/cookies/cookie_store.h" | 71 #include "net/cookies/cookie_store.h" |
| 68 #include "net/cookies/cookie_util.h" | 72 #include "net/cookies/cookie_util.h" |
| 69 #include "net/test/embedded_test_server/embedded_test_server.h" | 73 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 70 #include "net/test/embedded_test_server/http_request.h" | 74 #include "net/test/embedded_test_server/http_request.h" |
| 71 #include "net/test/embedded_test_server/http_response.h" | 75 #include "net/test/embedded_test_server/http_response.h" |
| 72 #include "sql/connection.h" | 76 #include "sql/connection.h" |
| 73 #include "sql/statement.h" | 77 #include "sql/statement.h" |
| 74 #include "testing/gmock/include/gmock/gmock.h" | 78 #include "testing/gmock/include/gmock/gmock.h" |
| 75 #include "url/gurl.h" | 79 #include "url/gurl.h" |
| 76 | 80 |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 | 686 |
| 683 // Waits for pending tasks on the IO thread to complete and check if the | 687 // Waits for pending tasks on the IO thread to complete and check if the |
| 684 // SafeBrowsingService enabled state matches |enabled|. | 688 // SafeBrowsingService enabled state matches |enabled|. |
| 685 void WaitForIOAndCheckEnabled(SafeBrowsingService* service, bool enabled) { | 689 void WaitForIOAndCheckEnabled(SafeBrowsingService* service, bool enabled) { |
| 686 scoped_refptr<ServiceEnabledHelper> enabled_helper(new ServiceEnabledHelper( | 690 scoped_refptr<ServiceEnabledHelper> enabled_helper(new ServiceEnabledHelper( |
| 687 service, enabled, | 691 service, enabled, |
| 688 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); | 692 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); |
| 689 ASSERT_TRUE(enabled_helper->Run()); | 693 ASSERT_TRUE(enabled_helper->Run()); |
| 690 } | 694 } |
| 691 | 695 |
| 692 private: | 696 protected: |
| 693 std::unique_ptr<TestSafeBrowsingServiceFactory> sb_factory_; | 697 std::unique_ptr<TestSafeBrowsingServiceFactory> sb_factory_; |
| 694 TestSafeBrowsingDatabaseFactory db_factory_; | 698 TestSafeBrowsingDatabaseFactory db_factory_; |
| 695 TestSBProtocolManagerFactory pm_factory_; | 699 TestSBProtocolManagerFactory pm_factory_; |
| 696 | 700 |
| 697 // Owned by ContentSubresourceFilterFactory. | 701 // Owned by ContentSubresourceFilterFactory. |
| 698 MockSubresourceFilterDriver* driver_; | 702 MockSubresourceFilterDriver* driver_; |
| 699 | 703 |
| 704 private: | |
| 700 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTest); | 705 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTest); |
| 701 }; | 706 }; |
| 702 | 707 |
| 703 class SafeBrowsingServiceMetadataTest | 708 class SafeBrowsingServiceMetadataTest |
| 704 : public SafeBrowsingServiceTest, | 709 : public SafeBrowsingServiceTest, |
| 705 public ::testing::WithParamInterface<ThreatPatternType> { | 710 public ::testing::WithParamInterface<ThreatPatternType> { |
| 706 public: | 711 public: |
| 707 SafeBrowsingServiceMetadataTest() {} | 712 SafeBrowsingServiceMetadataTest() {} |
| 708 | 713 |
| 709 void GenUrlFullHashResultWithMetadata(const GURL& url, | 714 void GenUrlFullHashResultWithMetadata(const GURL& url, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 737 EXPECT_FALSE(hit_report().is_subresource); | 742 EXPECT_FALSE(hit_report().is_subresource); |
| 738 } | 743 } |
| 739 | 744 |
| 740 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareIFrame) { | 745 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareIFrame) { |
| 741 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 746 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
| 742 GURL iframe_url = embedded_test_server()->GetURL(kMalwareIFrame); | 747 GURL iframe_url = embedded_test_server()->GetURL(kMalwareIFrame); |
| 743 | 748 |
| 744 // Add the iframe url as malware and then load the parent page. | 749 // Add the iframe url as malware and then load the parent page. |
| 745 SBFullHashResult malware_full_hash; | 750 SBFullHashResult malware_full_hash; |
| 746 GenUrlFullHashResultWithMetadata(iframe_url, &malware_full_hash); | 751 GenUrlFullHashResultWithMetadata(iframe_url, &malware_full_hash); |
| 747 EXPECT_CALL(observer_, | 752 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(iframe_url))) |
| 748 OnSafeBrowsingHit(IsUnsafeResourceFor(iframe_url))).Times(1); | 753 .Times(1); |
| 749 SetupResponseForUrl(iframe_url, malware_full_hash); | 754 SetupResponseForUrl(iframe_url, malware_full_hash); |
| 750 ui_test_utils::NavigateToURL(browser(), main_url); | 755 ui_test_utils::NavigateToURL(browser(), main_url); |
| 751 // All types should show the interstitial. | 756 // All types should show the interstitial. |
| 752 EXPECT_TRUE(ShowingInterstitialPage()); | 757 EXPECT_TRUE(ShowingInterstitialPage()); |
| 753 | 758 |
| 754 EXPECT_TRUE(got_hit_report()); | 759 EXPECT_TRUE(got_hit_report()); |
| 755 EXPECT_EQ(iframe_url, hit_report().malicious_url); | 760 EXPECT_EQ(iframe_url, hit_report().malicious_url); |
| 756 EXPECT_EQ(main_url, hit_report().page_url); | 761 EXPECT_EQ(main_url, hit_report().page_url); |
| 757 EXPECT_EQ(GURL(), hit_report().referrer_url); | 762 EXPECT_EQ(GURL(), hit_report().referrer_url); |
| 758 EXPECT_TRUE(hit_report().is_subresource); | 763 EXPECT_TRUE(hit_report().is_subresource); |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1827 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 1832 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
| 1828 content::Source<SafeBrowsingDatabaseManager>( | 1833 content::Source<SafeBrowsingDatabaseManager>( |
| 1829 sb_factory_->test_safe_browsing_service()->database_manager().get())); | 1834 sb_factory_->test_safe_browsing_service()->database_manager().get())); |
| 1830 BrowserThread::PostTask( | 1835 BrowserThread::PostTask( |
| 1831 BrowserThread::IO, FROM_HERE, | 1836 BrowserThread::IO, FROM_HERE, |
| 1832 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, | 1837 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, |
| 1833 base::Unretained(this))); | 1838 base::Unretained(this))); |
| 1834 observer.Wait(); | 1839 observer.Wait(); |
| 1835 } | 1840 } |
| 1836 | 1841 |
| 1842 class TestV4Store : public V4Store { | |
| 1843 public: | |
| 1844 TestV4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
| 1845 const base::FilePath& store_path) | |
| 1846 : V4Store(task_runner, store_path, 0) {} | |
| 1847 | |
| 1848 void MarkPrefixAsBad(HashPrefix prefix) { | |
| 1849 hash_prefix_map_[prefix.size()] = prefix; | |
| 1850 } | |
| 1851 }; | |
| 1852 | |
| 1853 class TestV4StoreFactory : public V4StoreFactory { | |
| 1854 public: | |
| 1855 V4Store* CreateV4Store( | |
| 1856 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
| 1857 const base::FilePath& store_path) override { | |
| 1858 V4Store* new_store = new TestV4Store(task_runner, store_path); | |
| 1859 new_store->Initialize(); | |
| 1860 return new_store; | |
| 1861 } | |
| 1862 }; | |
| 1863 | |
| 1864 class TestV4Database : public V4Database { | |
| 1865 public: | |
| 1866 TestV4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | |
| 1867 std::unique_ptr<StoreMap> store_map) | |
| 1868 : V4Database(db_task_runner, std::move(store_map)) {} | |
| 1869 | |
| 1870 void MarkPrefixAsBad(ListIdentifier list_id, HashPrefix prefix) { | |
| 1871 V4Store* base_store = store_map_->at(list_id).get(); | |
| 1872 TestV4Store* test_store = static_cast<TestV4Store*>(base_store); | |
| 1873 if (test_store) { | |
|
Nathan Parker
2017/02/08 01:22:53
Should test_store always be non-null? If so, you
vakh (use Gerrit instead)
2017/02/09 03:30:28
Done.
| |
| 1874 test_store->MarkPrefixAsBad(prefix); | |
| 1875 } | |
| 1876 } | |
| 1877 }; | |
| 1878 | |
| 1879 class TestV4DatabaseFactory : public V4DatabaseFactory { | |
| 1880 public: | |
| 1881 TestV4DatabaseFactory() : v4_db_(nullptr) {} | |
| 1882 | |
| 1883 TestV4Database* Create( | |
|
Nathan Parker
2017/02/08 01:22:48
Should this return a V4Database instead of TestV4D
vakh (use Gerrit instead)
2017/02/09 03:30:28
Done.
| |
| 1884 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | |
| 1885 std::unique_ptr<StoreMap> store_map) override { | |
| 1886 v4_db_ = new TestV4Database(db_task_runner, std::move(store_map)); | |
| 1887 return v4_db_; | |
| 1888 } | |
| 1889 | |
| 1890 void MarkPrefixAsBad(ListIdentifier list_id, HashPrefix prefix) { | |
| 1891 v4_db_->MarkPrefixAsBad(list_id, prefix); | |
| 1892 } | |
| 1893 | |
| 1894 private: | |
| 1895 TestV4Database* v4_db_; | |
|
Nathan Parker
2017/02/08 01:22:54
Add comment that this isn't owned.
I'm assuming w
vakh (use Gerrit instead)
2017/02/09 03:30:28
Done.
| |
| 1896 }; | |
| 1897 | |
| 1898 class TestV4GetHashProtocolManager : public V4GetHashProtocolManager { | |
| 1899 public: | |
| 1900 TestV4GetHashProtocolManager( | |
| 1901 net::URLRequestContextGetter* request_context_getter, | |
| 1902 const StoresToCheck& stores_to_check, | |
| 1903 const V4ProtocolConfig& config) | |
| 1904 : V4GetHashProtocolManager(request_context_getter, | |
| 1905 stores_to_check, | |
| 1906 config) {} | |
| 1907 | |
| 1908 void AddToFullHashCache(FullHashInfo fhi) { | |
| 1909 full_hash_cache_[fhi.full_hash].full_hash_infos.push_back(fhi); | |
| 1910 } | |
| 1911 }; | |
| 1912 | |
| 1913 class TestV4GetHashProtocolManagerFactory | |
| 1914 : public V4GetHashProtocolManagerFactory { | |
| 1915 public: | |
| 1916 std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager( | |
| 1917 net::URLRequestContextGetter* request_context_getter, | |
| 1918 const StoresToCheck& stores_to_check, | |
| 1919 const V4ProtocolConfig& config) override { | |
| 1920 pm_ = new TestV4GetHashProtocolManager(request_context_getter, | |
| 1921 stores_to_check, config); | |
| 1922 return base::WrapUnique(pm_); | |
| 1923 } | |
| 1924 | |
| 1925 void AddToFullHashCache(FullHashInfo fhi) { pm_->AddToFullHashCache(fhi); } | |
| 1926 | |
| 1927 private: | |
| 1928 TestV4GetHashProtocolManager* pm_; | |
|
Nathan Parker
2017/02/08 01:22:48
Add comment that this isn't owned. Similar questi
vakh (use Gerrit instead)
2017/02/09 03:30:28
Done.
| |
| 1929 }; | |
| 1930 | |
| 1931 // Tests the safe browsing blocking page in a browser. | |
| 1932 class V4SafeBrowsingServiceTest : public SafeBrowsingServiceTest { | |
| 1933 public: | |
| 1934 V4SafeBrowsingServiceTest() : SafeBrowsingServiceTest() {} | |
| 1935 | |
| 1936 void SetUp() override { | |
| 1937 sb_factory_.reset( | |
|
Nathan Parker
2017/02/08 01:22:46
nit:
sb_factory_ = std::make_unique<TestSafeBrowsi
vakh (use Gerrit instead)
2017/02/09 03:30:28
Done.
| |
| 1938 new TestSafeBrowsingServiceFactory(V4UsageStatus::V4_ONLY)); | |
| 1939 sb_factory_->SetTestUIManager(new FakeSafeBrowsingUIManager()); | |
| 1940 SafeBrowsingService::RegisterFactory(sb_factory_.get()); | |
| 1941 V4Database::RegisterFactory(&v4_db_factory_); | |
| 1942 std::unique_ptr<TestV4GetHashProtocolManagerFactory> v4_get_hash_factory = | |
| 1943 base::MakeUnique<TestV4GetHashProtocolManagerFactory>(); | |
| 1944 v4_get_hash_factory_ = v4_get_hash_factory.get(); | |
|
Nathan Parker
2017/02/08 01:22:49
Can skip the temp var here
vakh (use Gerrit instead)
2017/02/09 03:30:27
Done.
| |
| 1945 V4GetHashProtocolManager::RegisterFactory(std::move(v4_get_hash_factory)); | |
| 1946 InProcessBrowserTest::SetUp(); | |
| 1947 } | |
| 1948 | |
| 1949 FullHashInfo GetFullHashInfo(const GURL& url, const ListIdentifier& list_id) { | |
|
Nathan Parker
2017/02/08 01:22:52
Can you add some comments to these functions, as t
vakh (use Gerrit instead)
2017/02/09 03:30:28
Done.
| |
| 1950 std::string host; | |
| 1951 std::string path; | |
| 1952 V4ProtocolManagerUtil::CanonicalizeUrl(url, &host, &path, nullptr); | |
| 1953 | |
| 1954 return FullHashInfo(crypto::SHA256HashString(host + path), list_id, | |
| 1955 base::Time::Now() + base::TimeDelta::FromMinutes(5)); | |
|
Nathan Parker
2017/02/08 01:22:45
Is this time actually used? If not, make it (0).
vakh (use Gerrit instead)
2017/02/09 03:30:28
I tried using Time() instead but the test failed b
| |
| 1956 } | |
| 1957 | |
| 1958 FullHashInfo GetFullHashInfoWithMetadata( | |
| 1959 const GURL& url, | |
| 1960 const ListIdentifier& list_id, | |
| 1961 ThreatPatternType threat_pattern_type) { | |
| 1962 FullHashInfo fhi = GetFullHashInfo(url, list_id); | |
| 1963 fhi.metadata.threat_pattern_type = threat_pattern_type; | |
| 1964 return fhi; | |
| 1965 } | |
| 1966 | |
| 1967 void MarkUrlForMalwareUnexpired(const GURL& bad_url, | |
| 1968 ThreatPatternType threat_pattern_type) { | |
| 1969 FullHashInfo full_hash_info = GetFullHashInfoWithMetadata( | |
| 1970 bad_url, GetUrlMalwareId(), threat_pattern_type); | |
| 1971 | |
| 1972 v4_db_factory_.MarkPrefixAsBad(GetUrlMalwareId(), full_hash_info.full_hash); | |
| 1973 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | |
| 1974 } | |
| 1975 | |
| 1976 void MarkUrlForUwsUnexpired(const GURL& bad_url) { | |
| 1977 FullHashInfo full_hash_info = GetFullHashInfo(bad_url, GetUrlUwsId()); | |
| 1978 v4_db_factory_.MarkPrefixAsBad(GetUrlUwsId(), full_hash_info.full_hash); | |
| 1979 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | |
| 1980 } | |
| 1981 | |
| 1982 private: | |
| 1983 TestV4DatabaseFactory v4_db_factory_; | |
| 1984 TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_; | |
|
Nathan Parker
2017/02/08 01:22:44
// Unowned
(I assume)
vakh (use Gerrit instead)
2017/02/09 03:30:28
Done.
| |
| 1985 | |
| 1986 DISALLOW_COPY_AND_ASSIGN(V4SafeBrowsingServiceTest); | |
| 1987 }; | |
| 1988 | |
| 1989 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, UnwantedImgIgnored) { | |
|
Nathan Parker
2017/02/08 01:22:48
How about an UnwantedMainFrame, to confirm that we
vakh (use Gerrit instead)
2017/02/09 03:30:28
There are a lot of tests remaining to be written.
| |
| 1990 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | |
| 1991 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); | |
| 1992 | |
| 1993 // Add the img url as coming from a site serving UwS and then load the parent | |
| 1994 // page. | |
| 1995 MarkUrlForUwsUnexpired(img_url); | |
| 1996 | |
| 1997 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 1998 | |
| 1999 EXPECT_FALSE(ShowingInterstitialPage()); | |
| 2000 EXPECT_FALSE(got_hit_report()); | |
| 2001 } | |
| 2002 | |
| 2003 class V4SafeBrowsingServiceMetadataTest | |
|
Nathan Parker
2017/02/08 01:22:50
IMHO this file is big enough to merit some comment
vakh (use Gerrit instead)
2017/02/09 03:30:28
Done.
| |
| 2004 : public V4SafeBrowsingServiceTest, | |
| 2005 public ::testing::WithParamInterface<ThreatPatternType> { | |
| 2006 public: | |
| 2007 V4SafeBrowsingServiceMetadataTest() {} | |
| 2008 | |
| 2009 private: | |
| 2010 DISALLOW_COPY_AND_ASSIGN(V4SafeBrowsingServiceMetadataTest); | |
| 2011 }; | |
| 2012 | |
| 2013 IN_PROC_BROWSER_TEST_P(V4SafeBrowsingServiceMetadataTest, MalwareMainFrame) { | |
| 2014 GURL url = embedded_test_server()->GetURL(kEmptyPage); | |
| 2015 MarkUrlForMalwareUnexpired(url, GetParam()); | |
| 2016 | |
| 2017 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1); | |
| 2018 | |
| 2019 ui_test_utils::NavigateToURL(browser(), url); | |
| 2020 // All types should show the interstitial. | |
| 2021 EXPECT_TRUE(ShowingInterstitialPage()); | |
| 2022 | |
| 2023 EXPECT_TRUE(got_hit_report()); | |
| 2024 EXPECT_EQ(url, hit_report().malicious_url); | |
| 2025 EXPECT_EQ(url, hit_report().page_url); | |
| 2026 EXPECT_EQ(GURL(), hit_report().referrer_url); | |
| 2027 EXPECT_FALSE(hit_report().is_subresource); | |
| 2028 } | |
| 2029 | |
| 2030 IN_PROC_BROWSER_TEST_P(V4SafeBrowsingServiceMetadataTest, MalwareIFrame) { | |
| 2031 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | |
| 2032 GURL iframe_url = embedded_test_server()->GetURL(kMalwareIFrame); | |
| 2033 | |
| 2034 // Add the iframe url as malware and then load the parent page. | |
| 2035 MarkUrlForMalwareUnexpired(iframe_url, GetParam()); | |
| 2036 | |
| 2037 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(iframe_url))) | |
| 2038 .Times(1); | |
| 2039 | |
| 2040 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 2041 // All types should show the interstitial. | |
| 2042 EXPECT_TRUE(ShowingInterstitialPage()); | |
| 2043 | |
| 2044 EXPECT_TRUE(got_hit_report()); | |
| 2045 EXPECT_EQ(iframe_url, hit_report().malicious_url); | |
| 2046 EXPECT_EQ(main_url, hit_report().page_url); | |
| 2047 EXPECT_EQ(GURL(), hit_report().referrer_url); | |
| 2048 EXPECT_TRUE(hit_report().is_subresource); | |
| 2049 } | |
| 2050 | |
| 2051 IN_PROC_BROWSER_TEST_P(V4SafeBrowsingServiceMetadataTest, MalwareImg) { | |
| 2052 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | |
| 2053 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); | |
| 2054 | |
| 2055 // Add the img url as malware and then load the parent page. | |
| 2056 MarkUrlForMalwareUnexpired(img_url, GetParam()); | |
| 2057 | |
| 2058 switch (GetParam()) { | |
| 2059 case ThreatPatternType::NONE: // Falls through. | |
| 2060 case ThreatPatternType::MALWARE_DISTRIBUTION: | |
| 2061 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(img_url))) | |
| 2062 .Times(1); | |
| 2063 break; | |
| 2064 case ThreatPatternType::MALWARE_LANDING: | |
| 2065 // No interstitial shown, so no notifications expected. | |
| 2066 break; | |
| 2067 default: | |
| 2068 break; | |
| 2069 } | |
| 2070 | |
| 2071 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 2072 | |
| 2073 // Subresource which is tagged as a landing page should not show an | |
| 2074 // interstitial, the other types should. | |
| 2075 switch (GetParam()) { | |
| 2076 case ThreatPatternType::NONE: // Falls through. | |
| 2077 case ThreatPatternType::MALWARE_DISTRIBUTION: | |
| 2078 EXPECT_TRUE(ShowingInterstitialPage()); | |
| 2079 EXPECT_TRUE(got_hit_report()); | |
| 2080 EXPECT_EQ(img_url, hit_report().malicious_url); | |
| 2081 EXPECT_EQ(main_url, hit_report().page_url); | |
| 2082 EXPECT_EQ(GURL(), hit_report().referrer_url); | |
| 2083 EXPECT_TRUE(hit_report().is_subresource); | |
| 2084 break; | |
| 2085 case ThreatPatternType::MALWARE_LANDING: | |
| 2086 EXPECT_FALSE(ShowingInterstitialPage()); | |
| 2087 EXPECT_FALSE(got_hit_report()); | |
| 2088 break; | |
| 2089 default: | |
| 2090 break; | |
| 2091 } | |
| 2092 } | |
| 2093 | |
| 2094 INSTANTIATE_TEST_CASE_P( | |
| 2095 MaybeSetMetadata, | |
| 2096 V4SafeBrowsingServiceMetadataTest, | |
| 2097 testing::Values(ThreatPatternType::NONE, | |
| 2098 ThreatPatternType::MALWARE_LANDING, | |
| 2099 ThreatPatternType::MALWARE_DISTRIBUTION)); | |
| 2100 | |
| 1837 } // namespace safe_browsing | 2101 } // namespace safe_browsing |
| OLD | NEW |