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 // Unit tests for the SafeBrowsing storage system. | 5 // Unit tests for the SafeBrowsing storage system. |
6 | 6 |
7 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 7 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <utility> | 10 #include <utility> |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 chunks); | 433 chunks); |
434 | 434 |
435 chunks.clear(); | 435 chunks.clear(); |
436 chunks.push_back(AddChunkHashedIpValue(10, "::ffff:192.168.1.0", 120)); | 436 chunks.push_back(AddChunkHashedIpValue(10, "::ffff:192.168.1.0", 120)); |
437 database_->InsertChunks(kIPBlacklist, chunks); | 437 database_->InsertChunks(kIPBlacklist, chunks); |
438 | 438 |
439 chunks.clear(); | 439 chunks.clear(); |
440 chunks.push_back(AddChunkPrefixValue(11, "www.unwanted.com/software.html")); | 440 chunks.push_back(AddChunkPrefixValue(11, "www.unwanted.com/software.html")); |
441 database_->InsertChunks(kUnwantedUrlList, chunks); | 441 database_->InsertChunks(kUnwantedUrlList, chunks); |
442 | 442 |
| 443 chunks.clear(); |
| 444 chunks.push_back(AddChunkPrefixValue(12, "chrome.dll")); |
| 445 database_->InsertChunks(kModuleWhitelist, chunks); |
| 446 |
443 database_->UpdateFinished(true); | 447 database_->UpdateFinished(true); |
444 | 448 |
445 GetListsInfo(&lists); | 449 GetListsInfo(&lists); |
446 ASSERT_EQ(9U, lists.size()); | 450 ASSERT_EQ(9U, lists.size()); |
447 EXPECT_EQ(kMalwareList, lists[0].name); | 451 EXPECT_EQ(kMalwareList, lists[0].name); |
448 EXPECT_EQ("1", lists[0].adds); | 452 EXPECT_EQ("1", lists[0].adds); |
449 EXPECT_TRUE(lists[0].subs.empty()); | 453 EXPECT_TRUE(lists[0].subs.empty()); |
450 EXPECT_EQ(kPhishingList, lists[1].name); | 454 EXPECT_EQ(kPhishingList, lists[1].name); |
451 EXPECT_EQ("2", lists[1].adds); | 455 EXPECT_EQ("2", lists[1].adds); |
452 EXPECT_TRUE(lists[1].subs.empty()); | 456 EXPECT_TRUE(lists[1].subs.empty()); |
(...skipping 11 matching lines...) Expand all Loading... |
464 EXPECT_TRUE(lists[5].subs.empty()); | 468 EXPECT_TRUE(lists[5].subs.empty()); |
465 EXPECT_EQ(kExtensionBlacklist, lists[6].name); | 469 EXPECT_EQ(kExtensionBlacklist, lists[6].name); |
466 EXPECT_EQ("8", lists[6].adds); | 470 EXPECT_EQ("8", lists[6].adds); |
467 EXPECT_TRUE(lists[6].subs.empty()); | 471 EXPECT_TRUE(lists[6].subs.empty()); |
468 EXPECT_EQ(kIPBlacklist, lists[7].name); | 472 EXPECT_EQ(kIPBlacklist, lists[7].name); |
469 EXPECT_EQ("10", lists[7].adds); | 473 EXPECT_EQ("10", lists[7].adds); |
470 EXPECT_TRUE(lists[7].subs.empty()); | 474 EXPECT_TRUE(lists[7].subs.empty()); |
471 EXPECT_EQ(kUnwantedUrlList, lists[8].name); | 475 EXPECT_EQ(kUnwantedUrlList, lists[8].name); |
472 EXPECT_EQ("11", lists[8].adds); | 476 EXPECT_EQ("11", lists[8].adds); |
473 EXPECT_TRUE(lists[8].subs.empty()); | 477 EXPECT_TRUE(lists[8].subs.empty()); |
| 478 EXPECT_EQ(kModuleWhitelist, lists[9].name); |
| 479 EXPECT_EQ("12", lists[9].adds); |
| 480 EXPECT_TRUE(lists[9].subs.empty()); |
474 | 481 |
475 database_.reset(); | 482 database_.reset(); |
476 } | 483 } |
477 | 484 |
478 // Checks database reading and writing for browse and unwanted PrefixSets. | 485 // Checks database reading and writing for browse and unwanted PrefixSets. |
479 TEST_F(SafeBrowsingDatabaseTest, BrowseAndUnwantedDatabasesAndPrefixSets) { | 486 TEST_F(SafeBrowsingDatabaseTest, BrowseAndUnwantedDatabasesAndPrefixSets) { |
480 | 487 |
481 struct TestCase { | 488 struct TestCase { |
482 using TestListContainsBadUrl = bool (SafeBrowsingDatabase::*)( | 489 using TestListContainsBadUrl = bool (SafeBrowsingDatabase::*)( |
483 const GURL& url, | 490 const GURL& url, |
(...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2277 ASSERT_EQ(1U, prefix_hits.size()); | 2284 ASSERT_EQ(1U, prefix_hits.size()); |
2278 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); | 2285 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); |
2279 EXPECT_TRUE(cache_hits.empty()); | 2286 EXPECT_TRUE(cache_hits.empty()); |
2280 | 2287 |
2281 // This prefix collides, but no full hash match. | 2288 // This prefix collides, but no full hash match. |
2282 EXPECT_FALSE(database_->ContainsBrowseUrl( | 2289 EXPECT_FALSE(database_->ContainsBrowseUrl( |
2283 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); | 2290 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); |
2284 } | 2291 } |
2285 | 2292 |
2286 } // namespace safe_browsing | 2293 } // namespace safe_browsing |
OLD | NEW |