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

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

Issue 1673733002: Support new Safe Browsing list "goog-badresource-shavar" in SafeBrowsingDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Check resource URLs in database manager Created 4 years, 10 months 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "chrome/browser/safe_browsing/local_database_manager.h" 14 #include "chrome/browser/safe_browsing/local_database_manager.h"
15
Nathan Parker 2016/02/16 21:42:00 rm blank line
veranika 2016/02/17 15:37:54 Done.
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 17 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h" 20 #include "testing/platform_test.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 using content::TestBrowserThreadBundle; 23 using content::TestBrowserThreadBundle;
23 24
24 namespace safe_browsing { 25 namespace safe_browsing {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 143 }
143 144
144 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlSeverestThreatType) { 145 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlSeverestThreatType) {
145 std::vector<SBFullHashResult> full_hashes; 146 std::vector<SBFullHashResult> full_hashes;
146 147
147 const GURL kMalwareUrl("http://www.malware.com/page.html"); 148 const GURL kMalwareUrl("http://www.malware.com/page.html");
148 const GURL kPhishingUrl("http://www.phishing.com/page.html"); 149 const GURL kPhishingUrl("http://www.phishing.com/page.html");
149 const GURL kUnwantedUrl("http://www.unwanted.com/page.html"); 150 const GURL kUnwantedUrl("http://www.unwanted.com/page.html");
150 const GURL kUnwantedAndMalwareUrl( 151 const GURL kUnwantedAndMalwareUrl(
151 "http://www.unwantedandmalware.com/page.html"); 152 "http://www.unwantedandmalware.com/page.html");
153 const GURL kBlacklistedResourceUrl("http://www.blacklisted.com/script.js");
154 const GURL kUnwantedResourceUrl("http://www.unwantedresource.com/script.js");
155 const GURL kMalwareResourceUrl("http://www.malwareresource.com/script.js");
152 const GURL kSafeUrl("http://www.safe.com/page.html"); 156 const GURL kSafeUrl("http://www.safe.com/page.html");
153 157
154 const SBFullHash kMalwareHostHash = SBFullHashForString("malware.com/"); 158 const SBFullHash kMalwareHostHash = SBFullHashForString("malware.com/");
155 const SBFullHash kPhishingHostHash = SBFullHashForString("phishing.com/"); 159 const SBFullHash kPhishingHostHash = SBFullHashForString("phishing.com/");
156 const SBFullHash kUnwantedHostHash = SBFullHashForString("unwanted.com/"); 160 const SBFullHash kUnwantedHostHash = SBFullHashForString("unwanted.com/");
157 const SBFullHash kUnwantedAndMalwareHostHash = 161 const SBFullHash kUnwantedAndMalwareHostHash =
158 SBFullHashForString("unwantedandmalware.com/"); 162 SBFullHashForString("unwantedandmalware.com/");
163 const SBFullHash kBlacklistedResourceHostHash =
164 SBFullHashForString("blacklisted.com/");
165 const SBFullHash kUnwantedResourceHostHash =
166 SBFullHashForString("unwantedresource.com/");
167 const SBFullHash kMalwareResourceHostHash =
168 SBFullHashForString("malwareresource.com/");
159 const SBFullHash kSafeHostHash = SBFullHashForString("www.safe.com/"); 169 const SBFullHash kSafeHostHash = SBFullHashForString("www.safe.com/");
160 170
161 { 171 {
162 SBFullHashResult full_hash; 172 SBFullHashResult full_hash;
163 full_hash.hash = kMalwareHostHash; 173 full_hash.hash = kMalwareHostHash;
164 full_hash.list_id = static_cast<int>(MALWARE); 174 full_hash.list_id = static_cast<int>(MALWARE);
165 full_hashes.push_back(full_hash); 175 full_hashes.push_back(full_hash);
166 } 176 }
167 177
168 { 178 {
169 SBFullHashResult full_hash; 179 SBFullHashResult full_hash;
170 full_hash.hash = kPhishingHostHash; 180 full_hash.hash = kPhishingHostHash;
171 full_hash.list_id = static_cast<int>(PHISH); 181 full_hash.list_id = static_cast<int>(PHISH);
172 full_hashes.push_back(full_hash); 182 full_hashes.push_back(full_hash);
173 } 183 }
174 184
175 { 185 {
176 SBFullHashResult full_hash; 186 SBFullHashResult full_hash;
177 full_hash.hash = kUnwantedHostHash; 187 full_hash.hash = kUnwantedHostHash;
178 full_hash.list_id = static_cast<int>(UNWANTEDURL); 188 full_hash.list_id = static_cast<int>(UNWANTEDURL);
179 full_hashes.push_back(full_hash); 189 full_hashes.push_back(full_hash);
180 } 190 }
181 191
182 { 192 {
193 SBFullHashResult full_hash;
194 full_hash.hash = kBlacklistedResourceHostHash;
195 full_hash.list_id = static_cast<int>(RESOURCEBLACKLIST);
196 full_hashes.push_back(full_hash);
197 }
198
199 {
183 // Add both MALWARE and UNWANTEDURL list IDs for 200 // Add both MALWARE and UNWANTEDURL list IDs for
184 // kUnwantedAndMalwareHostHash. 201 // kUnwantedAndMalwareHostHash.
185 SBFullHashResult full_hash_malware; 202 SBFullHashResult full_hash_malware;
186 full_hash_malware.hash = kUnwantedAndMalwareHostHash; 203 full_hash_malware.hash = kUnwantedAndMalwareHostHash;
187 full_hash_malware.list_id = static_cast<int>(MALWARE); 204 full_hash_malware.list_id = static_cast<int>(MALWARE);
188 full_hashes.push_back(full_hash_malware); 205 full_hashes.push_back(full_hash_malware);
189 206
190 SBFullHashResult full_hash_unwanted; 207 SBFullHashResult full_hash_unwanted;
191 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash; 208 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash;
192 full_hash_unwanted.list_id = static_cast<int>(UNWANTEDURL); 209 full_hash_unwanted.list_id = static_cast<int>(UNWANTEDURL);
193 full_hashes.push_back(full_hash_unwanted); 210 full_hashes.push_back(full_hash_unwanted);
194 } 211 }
195 212
213 {
214 SBFullHashResult full_hash_unwanted =
215 {kUnwantedResourceHostHash, static_cast<int>(UNWANTEDURL)};
216 full_hashes.push_back(full_hash_unwanted);
217
218 SBFullHashResult full_hash_resource =
219 {kUnwantedResourceHostHash, static_cast<int>(RESOURCEBLACKLIST)};
220 full_hashes.push_back(full_hash_resource);
221 }
222
223 {
224 SBFullHashResult full_hash_malware =
225 {kMalwareResourceHostHash, static_cast<int>(MALWARE)};
226 full_hashes.push_back(full_hash_malware);
227
228 SBFullHashResult full_hash_resource =
229 {kMalwareResourceHostHash, static_cast<int>(RESOURCEBLACKLIST)};
230 full_hashes.push_back(full_hash_resource);
231 }
232
196 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 233 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
197 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( 234 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
198 kMalwareHostHash, full_hashes)); 235 kMalwareHostHash, full_hashes));
199 236
200 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, 237 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING,
201 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( 238 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
202 kPhishingHostHash, full_hashes)); 239 kPhishingHostHash, full_hashes));
203 240
204 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, 241 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED,
205 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( 242 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
206 kUnwantedHostHash, full_hashes)); 243 kUnwantedHostHash, full_hashes));
207 244
208 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 245 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
209 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( 246 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
210 kUnwantedAndMalwareHostHash, full_hashes)); 247 kUnwantedAndMalwareHostHash, full_hashes));
211 248
249 EXPECT_EQ(SB_THREAT_TYPE_BLACKLISTED_RESOURCE,
250 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
251 kBlacklistedResourceHostHash, full_hashes));
252
253 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED,
254 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
255 kUnwantedResourceHostHash, full_hashes));
256
257 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
258 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
259 kMalwareResourceHostHash, full_hashes));
260
212 EXPECT_EQ(SB_THREAT_TYPE_SAFE, 261 EXPECT_EQ(SB_THREAT_TYPE_SAFE,
213 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( 262 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
214 kSafeHostHash, full_hashes)); 263 kSafeHostHash, full_hashes));
215 264
216 const size_t kArbitraryValue = 123456U; 265 const size_t kArbitraryValue = 123456U;
217 size_t index = kArbitraryValue; 266 size_t index = kArbitraryValue;
218 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 267 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
219 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 268 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
220 kMalwareUrl, full_hashes, &index)); 269 kMalwareUrl, full_hashes, &index));
221 EXPECT_EQ(0U, index); 270 EXPECT_EQ(0U, index);
222 271
223 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, 272 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING,
224 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 273 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
225 kPhishingUrl, full_hashes, &index)); 274 kPhishingUrl, full_hashes, &index));
226 EXPECT_EQ(1U, index); 275 EXPECT_EQ(1U, index);
227 276
228 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, 277 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED,
229 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 278 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
230 kUnwantedUrl, full_hashes, &index)); 279 kUnwantedUrl, full_hashes, &index));
231 EXPECT_EQ(2U, index); 280 EXPECT_EQ(2U, index);
232 281
282 EXPECT_EQ(SB_THREAT_TYPE_BLACKLISTED_RESOURCE,
283 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
284 kBlacklistedResourceUrl, full_hashes, &index));
285 EXPECT_EQ(3U, index);
286
233 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 287 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
234 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 288 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
235 kUnwantedAndMalwareUrl, full_hashes, &index)); 289 kUnwantedAndMalwareUrl, full_hashes, &index));
236 EXPECT_EQ(3U, index); 290 EXPECT_EQ(4U, index);
291
292 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED,
293 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
294 kUnwantedResourceUrl, full_hashes, &index));
295 EXPECT_EQ(6U, index);
296
297 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
298 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
299 kMalwareResourceUrl, full_hashes, &index));
300 EXPECT_EQ(8U, index);
237 301
238 index = kArbitraryValue; 302 index = kArbitraryValue;
239 EXPECT_EQ(SB_THREAT_TYPE_SAFE, 303 EXPECT_EQ(SB_THREAT_TYPE_SAFE,
240 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 304 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
241 kSafeUrl, full_hashes, &index)); 305 kSafeUrl, full_hashes, &index));
242 EXPECT_EQ(kArbitraryValue, index); 306 EXPECT_EQ(kArbitraryValue, index);
243 } 307 }
244 308
245 TEST_F(SafeBrowsingDatabaseManagerTest, ServiceStopWithPendingChecks) { 309 TEST_F(SafeBrowsingDatabaseManagerTest, ServiceStopWithPendingChecks) {
246 scoped_refptr<SafeBrowsingService> sb_service( 310 scoped_refptr<SafeBrowsingService> sb_service(
(...skipping 16 matching lines...) Expand all
263 // Stop the service without first flushing above tasks. 327 // Stop the service without first flushing above tasks.
264 db_manager->StopOnIOThread(false); 328 db_manager->StopOnIOThread(false);
265 329
266 // Now run posted tasks, whish should include the extension check which has 330 // Now run posted tasks, whish should include the extension check which has
267 // been posted to the safe browsing task runner. This should not crash. 331 // been posted to the safe browsing task runner. This should not crash.
268 content::RunAllBlockingPoolTasksUntilIdle(); 332 content::RunAllBlockingPoolTasksUntilIdle();
269 base::RunLoop().RunUntilIdle(); 333 base::RunLoop().RunUntilIdle();
270 } 334 }
271 335
272 } // namespace safe_browsing 336 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698