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

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

Issue 1420123003: Move more declarations from c/b/sb/sb_util.h to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_components
Patch Set: Minor: Replace safe_browsing_util:: with safe_browsing:: and use safe_browsing:: namespace prefix 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 22 matching lines...) Expand all
33 SBThreatType threat_type) override {} 33 SBThreatType threat_type) override {}
34 34
35 private: 35 private:
36 DISALLOW_COPY_AND_ASSIGN(TestClient); 36 DISALLOW_COPY_AND_ASSIGN(TestClient);
37 }; 37 };
38 38
39 } // namespace 39 } // namespace
40 40
41 class SafeBrowsingDatabaseManagerTest : public PlatformTest { 41 class SafeBrowsingDatabaseManagerTest : public PlatformTest {
42 public: 42 public:
43 bool RunSBHashTest(const safe_browsing_util::ListType list_type, 43 bool RunSBHashTest(const safe_browsing::ListType list_type,
44 const std::vector<SBThreatType>& expected_threats, 44 const std::vector<SBThreatType>& expected_threats,
45 const std::string& result_list); 45 const std::string& result_list);
46 46
47 private: 47 private:
48 TestBrowserThreadBundle thread_bundle_; 48 TestBrowserThreadBundle thread_bundle_;
49 }; 49 };
50 50
51 bool SafeBrowsingDatabaseManagerTest::RunSBHashTest( 51 bool SafeBrowsingDatabaseManagerTest::RunSBHashTest(
52 const safe_browsing_util::ListType list_type, 52 const safe_browsing::ListType list_type,
53 const std::vector<SBThreatType>& expected_threats, 53 const std::vector<SBThreatType>& expected_threats,
54 const std::string& result_list) { 54 const std::string& result_list) {
55 scoped_refptr<SafeBrowsingService> sb_service_( 55 scoped_refptr<SafeBrowsingService> sb_service_(
56 SafeBrowsingService::CreateSafeBrowsingService()); 56 SafeBrowsingService::CreateSafeBrowsingService());
57 scoped_refptr<LocalSafeBrowsingDatabaseManager> db_manager_( 57 scoped_refptr<LocalSafeBrowsingDatabaseManager> db_manager_(
58 new LocalSafeBrowsingDatabaseManager(sb_service_)); 58 new LocalSafeBrowsingDatabaseManager(sb_service_));
59 const SBFullHash same_full_hash = {}; 59 const SBFullHash same_full_hash = {};
60 60
61 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck* check = 61 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck* check =
62 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck( 62 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck(
63 std::vector<GURL>(), 63 std::vector<GURL>(),
64 std::vector<SBFullHash>(1, same_full_hash), 64 std::vector<SBFullHash>(1, same_full_hash),
65 NULL, 65 NULL,
66 list_type, 66 list_type,
67 expected_threats); 67 expected_threats);
68 db_manager_->checks_.insert(check); 68 db_manager_->checks_.insert(check);
69 69
70 const SBFullHashResult full_hash_result = { 70 const SBFullHashResult full_hash_result = {
71 same_full_hash, 71 same_full_hash,
72 safe_browsing_util::GetListId(result_list) 72 safe_browsing::GetListId(result_list)
73 }; 73 };
74 74
75 std::vector<SBFullHashResult> fake_results(1, full_hash_result); 75 std::vector<SBFullHashResult> fake_results(1, full_hash_result);
76 bool result = db_manager_->HandleOneCheck(check, fake_results); 76 bool result = db_manager_->HandleOneCheck(check, fake_results);
77 db_manager_->checks_.erase(check); 77 db_manager_->checks_.erase(check);
78 delete check; 78 delete check;
79 return result; 79 return result;
80 } 80 }
81 81
82 TEST_F(SafeBrowsingDatabaseManagerTest, CheckCorrespondsListType) { 82 TEST_F(SafeBrowsingDatabaseManagerTest, CheckCorrespondsListType) {
83 std::vector<SBThreatType> malware_threat(1, 83 std::vector<SBThreatType> malware_threat(1,
84 SB_THREAT_TYPE_BINARY_MALWARE_URL); 84 SB_THREAT_TYPE_BINARY_MALWARE_URL);
85 EXPECT_FALSE(RunSBHashTest(safe_browsing_util::BINURL, 85 EXPECT_FALSE(RunSBHashTest(safe_browsing::BINURL,
86 malware_threat, 86 malware_threat,
87 safe_browsing_util::kMalwareList)); 87 safe_browsing::kMalwareList));
88 EXPECT_TRUE(RunSBHashTest(safe_browsing_util::BINURL, 88 EXPECT_TRUE(RunSBHashTest(safe_browsing::BINURL,
89 malware_threat, 89 malware_threat,
90 safe_browsing_util::kBinUrlList)); 90 safe_browsing::kBinUrlList));
91 91
92 // Check for multiple threats 92 // Check for multiple threats
93 std::vector<SBThreatType> multiple_threats; 93 std::vector<SBThreatType> multiple_threats;
94 multiple_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); 94 multiple_threats.push_back(SB_THREAT_TYPE_URL_MALWARE);
95 multiple_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); 95 multiple_threats.push_back(SB_THREAT_TYPE_URL_PHISHING);
96 EXPECT_FALSE(RunSBHashTest(safe_browsing_util::MALWARE, 96 EXPECT_FALSE(RunSBHashTest(safe_browsing::MALWARE,
97 multiple_threats, 97 multiple_threats,
98 safe_browsing_util::kBinUrlList)); 98 safe_browsing::kBinUrlList));
99 EXPECT_TRUE(RunSBHashTest(safe_browsing_util::MALWARE, 99 EXPECT_TRUE(RunSBHashTest(safe_browsing::MALWARE,
100 multiple_threats, 100 multiple_threats,
101 safe_browsing_util::kMalwareList)); 101 safe_browsing::kMalwareList));
102 } 102 }
103 103
104 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlSeverestThreatType) { 104 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlSeverestThreatType) {
105 std::vector<SBFullHashResult> full_hashes; 105 std::vector<SBFullHashResult> full_hashes;
106 106
107 const GURL kMalwareUrl("http://www.malware.com/page.html"); 107 const GURL kMalwareUrl("http://www.malware.com/page.html");
108 const GURL kPhishingUrl("http://www.phishing.com/page.html"); 108 const GURL kPhishingUrl("http://www.phishing.com/page.html");
109 const GURL kUnwantedUrl("http://www.unwanted.com/page.html"); 109 const GURL kUnwantedUrl("http://www.unwanted.com/page.html");
110 const GURL kUnwantedAndMalwareUrl( 110 const GURL kUnwantedAndMalwareUrl(
111 "http://www.unwantedandmalware.com/page.html"); 111 "http://www.unwantedandmalware.com/page.html");
112 const GURL kSafeUrl("http://www.safe.com/page.html"); 112 const GURL kSafeUrl("http://www.safe.com/page.html");
113 113
114 const SBFullHash kMalwareHostHash = SBFullHashForString("malware.com/"); 114 const SBFullHash kMalwareHostHash =
115 const SBFullHash kPhishingHostHash = SBFullHashForString("phishing.com/"); 115 safe_browsing::SBFullHashForString("malware.com/");
116 const SBFullHash kUnwantedHostHash = SBFullHashForString("unwanted.com/"); 116 const SBFullHash kPhishingHostHash =
117 safe_browsing::SBFullHashForString("phishing.com/");
118 const SBFullHash kUnwantedHostHash =
119 safe_browsing::SBFullHashForString("unwanted.com/");
117 const SBFullHash kUnwantedAndMalwareHostHash = 120 const SBFullHash kUnwantedAndMalwareHostHash =
118 SBFullHashForString("unwantedandmalware.com/"); 121 safe_browsing::SBFullHashForString("unwantedandmalware.com/");
119 const SBFullHash kSafeHostHash = SBFullHashForString("www.safe.com/"); 122 const SBFullHash kSafeHostHash =
123 safe_browsing::SBFullHashForString("www.safe.com/");
120 124
121 { 125 {
122 SBFullHashResult full_hash; 126 SBFullHashResult full_hash;
123 full_hash.hash = kMalwareHostHash; 127 full_hash.hash = kMalwareHostHash;
124 full_hash.list_id = static_cast<int>(safe_browsing_util::MALWARE); 128 full_hash.list_id = static_cast<int>(safe_browsing::MALWARE);
125 full_hashes.push_back(full_hash); 129 full_hashes.push_back(full_hash);
126 } 130 }
127 131
128 { 132 {
129 SBFullHashResult full_hash; 133 SBFullHashResult full_hash;
130 full_hash.hash = kPhishingHostHash; 134 full_hash.hash = kPhishingHostHash;
131 full_hash.list_id = static_cast<int>(safe_browsing_util::PHISH); 135 full_hash.list_id = static_cast<int>(safe_browsing::PHISH);
132 full_hashes.push_back(full_hash); 136 full_hashes.push_back(full_hash);
133 } 137 }
134 138
135 { 139 {
136 SBFullHashResult full_hash; 140 SBFullHashResult full_hash;
137 full_hash.hash = kUnwantedHostHash; 141 full_hash.hash = kUnwantedHostHash;
138 full_hash.list_id = static_cast<int>(safe_browsing_util::UNWANTEDURL); 142 full_hash.list_id = static_cast<int>(safe_browsing::UNWANTEDURL);
139 full_hashes.push_back(full_hash); 143 full_hashes.push_back(full_hash);
140 } 144 }
141 145
142 { 146 {
143 // Add both MALWARE and UNWANTEDURL list IDs for 147 // Add both MALWARE and UNWANTEDURL list IDs for
144 // kUnwantedAndMalwareHostHash. 148 // kUnwantedAndMalwareHostHash.
145 SBFullHashResult full_hash_malware; 149 SBFullHashResult full_hash_malware;
146 full_hash_malware.hash = kUnwantedAndMalwareHostHash; 150 full_hash_malware.hash = kUnwantedAndMalwareHostHash;
147 full_hash_malware.list_id = static_cast<int>(safe_browsing_util::MALWARE); 151 full_hash_malware.list_id = static_cast<int>(safe_browsing::MALWARE);
148 full_hashes.push_back(full_hash_malware); 152 full_hashes.push_back(full_hash_malware);
149 153
150 SBFullHashResult full_hash_unwanted; 154 SBFullHashResult full_hash_unwanted;
151 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash; 155 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash;
152 full_hash_unwanted.list_id = 156 full_hash_unwanted.list_id = static_cast<int>(safe_browsing::UNWANTEDURL);
153 static_cast<int>(safe_browsing_util::UNWANTEDURL);
154 full_hashes.push_back(full_hash_unwanted); 157 full_hashes.push_back(full_hash_unwanted);
155 } 158 }
156 159
157 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 160 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
158 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( 161 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
159 kMalwareHostHash, full_hashes)); 162 kMalwareHostHash, full_hashes));
160 163
161 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, 164 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING,
162 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( 165 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
163 kPhishingHostHash, full_hashes)); 166 kPhishingHostHash, full_hashes));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 db_manager->CheckExtensionIDs(extension_ids, &client); 225 db_manager->CheckExtensionIDs(extension_ids, &client);
223 226
224 // Stop the service without first flushing above tasks. 227 // Stop the service without first flushing above tasks.
225 db_manager->StopOnIOThread(false); 228 db_manager->StopOnIOThread(false);
226 229
227 // Now run posted tasks, whish should include the extension check which has 230 // Now run posted tasks, whish should include the extension check which has
228 // been posted to the safe browsing task runner. This should not crash. 231 // been posted to the safe browsing task runner. This should not crash.
229 content::RunAllBlockingPoolTasksUntilIdle(); 232 content::RunAllBlockingPoolTasksUntilIdle();
230 base::RunLoop().RunUntilIdle(); 233 base::RunLoop().RunUntilIdle();
231 } 234 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/local_database_manager.cc ('k') | chrome/browser/safe_browsing/protocol_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698