Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Merging the latest changes from trunk. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 {
Nathan Parker 2015/11/05 22:00:53 This should be "namespace safe_browsing" since the
vakh (old account. dont use) 2015/11/07 01:22:56 Done.
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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 414 } // namespace
415 415
416 namespace safe_browsing {
417
416 // Tests the safe browsing blocking page in a browser. 418 // Tests the safe browsing blocking page in a browser.
417 class SafeBrowsingServiceTest : public InProcessBrowserTest { 419 class SafeBrowsingServiceTest : public InProcessBrowserTest {
418 public: 420 public:
419 SafeBrowsingServiceTest() { 421 SafeBrowsingServiceTest() {
420 } 422 }
421 423
422 static void GenUrlFullhashResult(const GURL& url, 424 static void GenUrlFullhashResult(const GURL& url,
423 int list_id, 425 int list_id,
424 SBFullHashResult* full_hash) { 426 SBFullHashResult* full_hash) {
425 std::string host; 427 std::string host;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 return LocalDatabaseManagerForService(sb_service)->check_timeout_; 522 return LocalDatabaseManagerForService(sb_service)->check_timeout_;
521 } 523 }
522 524
523 static void SetCheckTimeout(SafeBrowsingService* sb_service, 525 static void SetCheckTimeout(SafeBrowsingService* sb_service,
524 const base::TimeDelta& delay) { 526 const base::TimeDelta& delay) {
525 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay; 527 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay;
526 } 528 }
527 529
528 void CreateCSDService() { 530 void CreateCSDService() {
529 #if defined(SAFE_BROWSING_CSD) 531 #if defined(SAFE_BROWSING_CSD)
530 safe_browsing::ClientSideDetectionService* csd_service = 532 ClientSideDetectionService* csd_service =
531 safe_browsing::ClientSideDetectionService::Create(NULL); 533 ClientSideDetectionService::Create(NULL);
532 SafeBrowsingService* sb_service = 534 SafeBrowsingService* sb_service =
533 g_browser_process->safe_browsing_service(); 535 g_browser_process->safe_browsing_service();
534 536
535 // A CSD service should already exist. 537 // A CSD service should already exist.
536 EXPECT_TRUE(sb_service->csd_service_); 538 EXPECT_TRUE(sb_service->csd_service_);
537 539
538 sb_service->csd_service_.reset(csd_service); 540 sb_service->csd_service_.reset(csd_service);
539 sb_service->RefreshState(); 541 sb_service->RefreshState();
540 #endif 542 #endif
541 } 543 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 class SafeBrowsingServiceMetadataTest 598 class SafeBrowsingServiceMetadataTest
597 : public SafeBrowsingServiceTest, 599 : public SafeBrowsingServiceTest,
598 public ::testing::WithParamInterface<MalwareMetadataTestType> { 600 public ::testing::WithParamInterface<MalwareMetadataTestType> {
599 public: 601 public:
600 SafeBrowsingServiceMetadataTest() {} 602 SafeBrowsingServiceMetadataTest() {}
601 603
602 void GenUrlFullhashResultWithMetadata(const GURL& url, 604 void GenUrlFullhashResultWithMetadata(const GURL& url,
603 SBFullHashResult* full_hash) { 605 SBFullHashResult* full_hash) {
604 GenUrlFullhashResult(url, safe_browsing::MALWARE, full_hash); 606 GenUrlFullhashResult(url, safe_browsing::MALWARE, full_hash);
605 607
606 safe_browsing::MalwarePatternType proto; 608 MalwarePatternType proto;
607 switch (GetParam()) { 609 switch (GetParam()) {
608 case METADATA_NONE: 610 case METADATA_NONE:
609 full_hash->metadata = std::string(); 611 full_hash->metadata = std::string();
610 break; 612 break;
611 case METADATA_LANDING: 613 case METADATA_LANDING:
612 proto.set_pattern_type(safe_browsing::MalwarePatternType::LANDING); 614 proto.set_pattern_type(MalwarePatternType::LANDING);
613 full_hash->metadata = proto.SerializeAsString(); 615 full_hash->metadata = proto.SerializeAsString();
614 break; 616 break;
615 case METADATA_DISTRIBUTION: 617 case METADATA_DISTRIBUTION:
616 proto.set_pattern_type(safe_browsing::MalwarePatternType::DISTRIBUTION); 618 proto.set_pattern_type(MalwarePatternType::DISTRIBUTION);
617 full_hash->metadata = proto.SerializeAsString(); 619 full_hash->metadata = proto.SerializeAsString();
618 break; 620 break;
619 } 621 }
620 } 622 }
621 623
622 private: 624 private:
623 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); 625 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest);
624 }; 626 };
625 627
626 namespace { 628 namespace {
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 // There should be a timeout and the hash would be considered as safe. 1052 // There should be a timeout and the hash would be considered as safe.
1051 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); 1053 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType());
1052 1054
1053 // Need to set the timeout back to the default value. 1055 // Need to set the timeout back to the default value.
1054 SetCheckTimeout(sb_service, default_urlcheck_timeout); 1056 SetCheckTimeout(sb_service, default_urlcheck_timeout);
1055 } 1057 }
1056 1058
1057 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) { 1059 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) {
1058 CreateCSDService(); 1060 CreateCSDService();
1059 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); 1061 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
1060 safe_browsing::ClientSideDetectionService* csd_service = 1062 ClientSideDetectionService* csd_service =
1061 sb_service->safe_browsing_detection_service(); 1063 sb_service->safe_browsing_detection_service();
1062 PrefService* pref_service = browser()->profile()->GetPrefs(); 1064 PrefService* pref_service = browser()->profile()->GetPrefs();
1063 1065
1064 ASSERT_TRUE(sb_service != NULL); 1066 ASSERT_TRUE(sb_service != NULL);
1065 ASSERT_TRUE(csd_service != NULL); 1067 ASSERT_TRUE(csd_service != NULL);
1066 ASSERT_TRUE(pref_service != NULL); 1068 ASSERT_TRUE(pref_service != NULL);
1067 1069
1068 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); 1070 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled));
1069 1071
1070 // SBS might still be starting, make sure this doesn't flake. 1072 // SBS might still be starting, make sure this doesn't flake.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 } 1151 }
1150 1152
1151 protected: 1153 protected:
1152 Profile* profile2_; 1154 Profile* profile2_;
1153 }; 1155 };
1154 1156
1155 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceShutdownTest, 1157 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceShutdownTest,
1156 DontStartAfterShutdown) { 1158 DontStartAfterShutdown) {
1157 CreateCSDService(); 1159 CreateCSDService();
1158 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); 1160 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
1159 safe_browsing::ClientSideDetectionService* csd_service = 1161 ClientSideDetectionService* csd_service =
1160 sb_service->safe_browsing_detection_service(); 1162 sb_service->safe_browsing_detection_service();
1161 PrefService* pref_service = browser()->profile()->GetPrefs(); 1163 PrefService* pref_service = browser()->profile()->GetPrefs();
1162 1164
1163 ASSERT_TRUE(sb_service != NULL); 1165 ASSERT_TRUE(sb_service != NULL);
1164 ASSERT_TRUE(csd_service != NULL); 1166 ASSERT_TRUE(csd_service != NULL);
1165 ASSERT_TRUE(pref_service != NULL); 1167 ASSERT_TRUE(pref_service != NULL);
1166 1168
1167 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); 1169 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled));
1168 1170
1169 // SBS might still be starting, make sure this doesn't flake. 1171 // SBS might still be starting, make sure this doesn't flake.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 content::WindowedNotificationObserver observer( 1355 content::WindowedNotificationObserver observer(
1354 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, 1356 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE,
1355 content::Source<SafeBrowsingDatabaseManager>( 1357 content::Source<SafeBrowsingDatabaseManager>(
1356 sb_service_->database_manager().get())); 1358 sb_service_->database_manager().get()));
1357 BrowserThread::PostTask( 1359 BrowserThread::PostTask(
1358 BrowserThread::IO, 1360 BrowserThread::IO,
1359 FROM_HERE, 1361 FROM_HERE,
1360 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); 1362 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this));
1361 observer.Wait(); 1363 observer.Wait();
1362 } 1364 }
1365
1366 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698