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 <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 #error This test requires SAFE_BROWSING_DB_LOCAL. | 63 #error This test requires SAFE_BROWSING_DB_LOCAL. |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 using content::BrowserThread; | 66 using content::BrowserThread; |
| 67 using content::InterstitialPage; | 67 using content::InterstitialPage; |
| 68 using content::WebContents; | 68 using content::WebContents; |
| 69 using ::testing::_; | 69 using ::testing::_; |
| 70 using ::testing::Mock; | 70 using ::testing::Mock; |
| 71 using ::testing::StrictMock; | 71 using ::testing::StrictMock; |
| 72 | 72 |
| 73 namespace { | 73 namespace safe_browsing { |
| 74 | 74 |
| 75 void InvokeFullHashCallback( | 75 void InvokeFullHashCallback( |
| 76 SafeBrowsingProtocolManager::FullHashCallback callback, | 76 SafeBrowsingProtocolManager::FullHashCallback callback, |
| 77 const std::vector<SBFullHashResult>& result) { | 77 const std::vector<SBFullHashResult>& result) { |
| 78 callback.Run(result, base::TimeDelta::FromMinutes(45)); | 78 callback.Run(result, base::TimeDelta::FromMinutes(45)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 class FakeSafeBrowsingService : public SafeBrowsingService { | 81 class FakeSafeBrowsingService : public SafeBrowsingService { |
| 82 public: | 82 public: |
| 83 explicit FakeSafeBrowsingService(const std::string& url_prefix) | 83 explicit FakeSafeBrowsingService(const std::string& url_prefix) |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 set_test_result(service_->enabled() == expected_enabled_); | 404 set_test_result(service_->enabled() == expected_enabled_); |
| 405 } | 405 } |
| 406 | 406 |
| 407 private: | 407 private: |
| 408 ~ServiceEnabledHelper() override {} | 408 ~ServiceEnabledHelper() override {} |
| 409 | 409 |
| 410 scoped_refptr<SafeBrowsingService> service_; | 410 scoped_refptr<SafeBrowsingService> service_; |
| 411 const bool expected_enabled_; | 411 const bool expected_enabled_; |
| 412 }; | 412 }; |
| 413 | 413 |
| 414 } // namespace | |
|
mattm
2015/11/11 01:10:16
Keep the anon namespace inside the new namespace.
vakh (old account. dont use)
2015/11/11 18:59:53
Done.
| |
| 415 | |
| 416 // Tests the safe browsing blocking page in a browser. | 414 // Tests the safe browsing blocking page in a browser. |
| 417 class SafeBrowsingServiceTest : public InProcessBrowserTest { | 415 class SafeBrowsingServiceTest : public InProcessBrowserTest { |
| 418 public: | 416 public: |
| 419 SafeBrowsingServiceTest() { | 417 SafeBrowsingServiceTest() { |
| 420 } | 418 } |
| 421 | 419 |
| 422 static void GenUrlFullhashResult(const GURL& url, | 420 static void GenUrlFullhashResult(const GURL& url, |
| 423 int list_id, | 421 int list_id, |
| 424 SBFullHashResult* full_hash) { | 422 SBFullHashResult* full_hash) { |
| 425 std::string host; | 423 std::string host; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 return LocalDatabaseManagerForService(sb_service)->check_timeout_; | 518 return LocalDatabaseManagerForService(sb_service)->check_timeout_; |
| 521 } | 519 } |
| 522 | 520 |
| 523 static void SetCheckTimeout(SafeBrowsingService* sb_service, | 521 static void SetCheckTimeout(SafeBrowsingService* sb_service, |
| 524 const base::TimeDelta& delay) { | 522 const base::TimeDelta& delay) { |
| 525 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay; | 523 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay; |
| 526 } | 524 } |
| 527 | 525 |
| 528 void CreateCSDService() { | 526 void CreateCSDService() { |
| 529 #if defined(SAFE_BROWSING_CSD) | 527 #if defined(SAFE_BROWSING_CSD) |
| 530 safe_browsing::ClientSideDetectionService* csd_service = | 528 ClientSideDetectionService* csd_service = |
| 531 safe_browsing::ClientSideDetectionService::Create(NULL); | 529 ClientSideDetectionService::Create(NULL); |
| 532 SafeBrowsingService* sb_service = | 530 SafeBrowsingService* sb_service = |
| 533 g_browser_process->safe_browsing_service(); | 531 g_browser_process->safe_browsing_service(); |
| 534 | 532 |
| 535 // A CSD service should already exist. | 533 // A CSD service should already exist. |
| 536 EXPECT_TRUE(sb_service->csd_service_); | 534 EXPECT_TRUE(sb_service->csd_service_); |
| 537 | 535 |
| 538 sb_service->csd_service_.reset(csd_service); | 536 sb_service->csd_service_.reset(csd_service); |
| 539 sb_service->RefreshState(); | 537 sb_service->RefreshState(); |
| 540 #endif | 538 #endif |
| 541 } | 539 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 class SafeBrowsingServiceMetadataTest | 594 class SafeBrowsingServiceMetadataTest |
| 597 : public SafeBrowsingServiceTest, | 595 : public SafeBrowsingServiceTest, |
| 598 public ::testing::WithParamInterface<MalwareMetadataTestType> { | 596 public ::testing::WithParamInterface<MalwareMetadataTestType> { |
| 599 public: | 597 public: |
| 600 SafeBrowsingServiceMetadataTest() {} | 598 SafeBrowsingServiceMetadataTest() {} |
| 601 | 599 |
| 602 void GenUrlFullhashResultWithMetadata(const GURL& url, | 600 void GenUrlFullhashResultWithMetadata(const GURL& url, |
| 603 SBFullHashResult* full_hash) { | 601 SBFullHashResult* full_hash) { |
| 604 GenUrlFullhashResult(url, safe_browsing::MALWARE, full_hash); | 602 GenUrlFullhashResult(url, safe_browsing::MALWARE, full_hash); |
| 605 | 603 |
| 606 safe_browsing::MalwarePatternType proto; | 604 MalwarePatternType proto; |
| 607 switch (GetParam()) { | 605 switch (GetParam()) { |
| 608 case METADATA_NONE: | 606 case METADATA_NONE: |
| 609 full_hash->metadata = std::string(); | 607 full_hash->metadata = std::string(); |
| 610 break; | 608 break; |
| 611 case METADATA_LANDING: | 609 case METADATA_LANDING: |
| 612 proto.set_pattern_type(safe_browsing::MalwarePatternType::LANDING); | 610 proto.set_pattern_type(MalwarePatternType::LANDING); |
| 613 full_hash->metadata = proto.SerializeAsString(); | 611 full_hash->metadata = proto.SerializeAsString(); |
| 614 break; | 612 break; |
| 615 case METADATA_DISTRIBUTION: | 613 case METADATA_DISTRIBUTION: |
| 616 proto.set_pattern_type(safe_browsing::MalwarePatternType::DISTRIBUTION); | 614 proto.set_pattern_type(MalwarePatternType::DISTRIBUTION); |
| 617 full_hash->metadata = proto.SerializeAsString(); | 615 full_hash->metadata = proto.SerializeAsString(); |
| 618 break; | 616 break; |
| 619 } | 617 } |
| 620 } | 618 } |
| 621 | 619 |
| 622 private: | 620 private: |
| 623 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); | 621 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); |
| 624 }; | 622 }; |
| 625 | 623 |
| 626 namespace { | 624 namespace { |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1050 // There should be a timeout and the hash would be considered as safe. | 1048 // There should be a timeout and the hash would be considered as safe. |
| 1051 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 1049 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
| 1052 | 1050 |
| 1053 // Need to set the timeout back to the default value. | 1051 // Need to set the timeout back to the default value. |
| 1054 SetCheckTimeout(sb_service, default_urlcheck_timeout); | 1052 SetCheckTimeout(sb_service, default_urlcheck_timeout); |
| 1055 } | 1053 } |
| 1056 | 1054 |
| 1057 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) { | 1055 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) { |
| 1058 CreateCSDService(); | 1056 CreateCSDService(); |
| 1059 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 1057 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
| 1060 safe_browsing::ClientSideDetectionService* csd_service = | 1058 ClientSideDetectionService* csd_service = |
| 1061 sb_service->safe_browsing_detection_service(); | 1059 sb_service->safe_browsing_detection_service(); |
| 1062 PrefService* pref_service = browser()->profile()->GetPrefs(); | 1060 PrefService* pref_service = browser()->profile()->GetPrefs(); |
| 1063 | 1061 |
| 1064 ASSERT_TRUE(sb_service != NULL); | 1062 ASSERT_TRUE(sb_service != NULL); |
| 1065 ASSERT_TRUE(csd_service != NULL); | 1063 ASSERT_TRUE(csd_service != NULL); |
| 1066 ASSERT_TRUE(pref_service != NULL); | 1064 ASSERT_TRUE(pref_service != NULL); |
| 1067 | 1065 |
| 1068 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | 1066 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); |
| 1069 | 1067 |
| 1070 // SBS might still be starting, make sure this doesn't flake. | 1068 // SBS might still be starting, make sure this doesn't flake. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1149 } | 1147 } |
| 1150 | 1148 |
| 1151 protected: | 1149 protected: |
| 1152 Profile* profile2_; | 1150 Profile* profile2_; |
| 1153 }; | 1151 }; |
| 1154 | 1152 |
| 1155 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceShutdownTest, | 1153 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceShutdownTest, |
| 1156 DontStartAfterShutdown) { | 1154 DontStartAfterShutdown) { |
| 1157 CreateCSDService(); | 1155 CreateCSDService(); |
| 1158 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 1156 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
| 1159 safe_browsing::ClientSideDetectionService* csd_service = | 1157 ClientSideDetectionService* csd_service = |
| 1160 sb_service->safe_browsing_detection_service(); | 1158 sb_service->safe_browsing_detection_service(); |
| 1161 PrefService* pref_service = browser()->profile()->GetPrefs(); | 1159 PrefService* pref_service = browser()->profile()->GetPrefs(); |
| 1162 | 1160 |
| 1163 ASSERT_TRUE(sb_service != NULL); | 1161 ASSERT_TRUE(sb_service != NULL); |
| 1164 ASSERT_TRUE(csd_service != NULL); | 1162 ASSERT_TRUE(csd_service != NULL); |
| 1165 ASSERT_TRUE(pref_service != NULL); | 1163 ASSERT_TRUE(pref_service != NULL); |
| 1166 | 1164 |
| 1167 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | 1165 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); |
| 1168 | 1166 |
| 1169 // SBS might still be starting, make sure this doesn't flake. | 1167 // SBS might still be starting, make sure this doesn't flake. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1353 content::WindowedNotificationObserver observer( | 1351 content::WindowedNotificationObserver observer( |
| 1354 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 1352 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
| 1355 content::Source<SafeBrowsingDatabaseManager>( | 1353 content::Source<SafeBrowsingDatabaseManager>( |
| 1356 sb_service_->database_manager().get())); | 1354 sb_service_->database_manager().get())); |
| 1357 BrowserThread::PostTask( | 1355 BrowserThread::PostTask( |
| 1358 BrowserThread::IO, | 1356 BrowserThread::IO, |
| 1359 FROM_HERE, | 1357 FROM_HERE, |
| 1360 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); | 1358 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); |
| 1361 observer.Wait(); | 1359 observer.Wait(); |
| 1362 } | 1360 } |
| 1361 | |
| 1362 } // namespace safe_browsing | |
| OLD | NEW |