OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 host.entry->SetPrefixAt(1, Sha256Prefix("www.evil.com/malware.html")); | 361 host.entry->SetPrefixAt(1, Sha256Prefix("www.evil.com/malware.html")); |
362 | 362 |
363 chunk.chunk_number = 1; | 363 chunk.chunk_number = 1; |
364 chunk.is_add = true; | 364 chunk.is_add = true; |
365 chunk.hosts.clear(); | 365 chunk.hosts.clear(); |
366 chunk.hosts.push_back(host); | 366 chunk.hosts.push_back(host); |
367 | 367 |
368 chunks = new std::deque<SBChunk>; | 368 chunks = new std::deque<SBChunk>; |
369 chunks->push_back(chunk); | 369 chunks->push_back(chunk); |
370 database->UpdateStarted(); | 370 database->UpdateStarted(); |
371 GetListsInfo(database, &lists); | 371 database->GetListsInfo(&lists); |
372 database->InsertChunks(safe_browsing_util::kMalwareList, chunks); | 372 database->InsertChunks(safe_browsing_util::kMalwareList, chunks); |
373 database->UpdateFinished(true); | 373 database->UpdateFinished(true); |
374 lists.clear(); | 374 lists.clear(); |
375 | 375 |
376 GetListsInfo(database, &lists); | 376 GetListsInfo(database, &lists); |
377 EXPECT_TRUE(lists[0].name == safe_browsing_util::kMalwareList); | 377 EXPECT_TRUE(lists[0].name == safe_browsing_util::kMalwareList); |
378 EXPECT_EQ(lists[0].adds, "1-3"); | 378 EXPECT_EQ(lists[0].adds, "1-3"); |
379 EXPECT_TRUE(lists[0].subs.empty()); | 379 EXPECT_TRUE(lists[0].subs.empty()); |
380 lists.clear(); | 380 lists.clear(); |
381 | 381 |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 | 899 |
900 // Prefix miss cache should be cleared. | 900 // Prefix miss cache should be cleared. |
901 EXPECT_EQ(database->prefix_miss_cache()->size(), 0U); | 901 EXPECT_EQ(database->prefix_miss_cache()->size(), 0U); |
902 | 902 |
903 lists.clear(); | 903 lists.clear(); |
904 prefixes.clear(); | 904 prefixes.clear(); |
905 full_hashes.clear(); | 905 full_hashes.clear(); |
906 | 906 |
907 // Test receiving a full add chunk. The old implementation doesn't support | 907 // Test receiving a full add chunk. The old implementation doesn't support |
908 // this test, so we bail here. | 908 // this test, so we bail here. |
909 if (!CommandLine().HasSwitch(switches::kUseNewSafeBrowsing)) { | 909 if (CommandLine().HasSwitch(switches::kUseOldSafeBrowsing)) { |
910 TearDownTestDatabase(database); | 910 TearDownTestDatabase(database); |
911 return; | 911 return; |
912 } | 912 } |
913 | 913 |
914 host.host = Sha256Prefix("www.fullevil.com/"); | 914 host.host = Sha256Prefix("www.fullevil.com/"); |
915 host.entry = SBEntry::Create(SBEntry::ADD_FULL_HASH, 2); | 915 host.entry = SBEntry::Create(SBEntry::ADD_FULL_HASH, 2); |
916 host.entry->set_chunk_id(20); | 916 host.entry->set_chunk_id(20); |
917 SBFullHash full_add1; | 917 SBFullHash full_add1; |
918 base::SHA256HashString("www.fullevil.com/bad1.html", | 918 base::SHA256HashString("www.fullevil.com/bad1.html", |
919 &full_add1.full_hash, sizeof(SBFullHash)); | 919 &full_add1.full_hash, sizeof(SBFullHash)); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) { | 1233 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) { |
1234 std::vector<ChunksInfo> chunks; | 1234 std::vector<ChunksInfo> chunks; |
1235 std::vector<SBChunkDelete>* deletes = new std::vector<SBChunkDelete>; | 1235 std::vector<SBChunkDelete>* deletes = new std::vector<SBChunkDelete>; |
1236 SBChunkDelete del; | 1236 SBChunkDelete del; |
1237 del.is_sub_del = false; | 1237 del.is_sub_del = false; |
1238 del.list_name = safe_browsing_util::kMalwareList; | 1238 del.list_name = safe_browsing_util::kMalwareList; |
1239 del.chunk_del.push_back(ChunkRange(3539, 3579)); | 1239 del.chunk_del.push_back(ChunkRange(3539, 3579)); |
1240 deletes->push_back(del); | 1240 deletes->push_back(del); |
1241 PeformUpdate(GetOldSafeBrowsingPath(), chunks, deletes); | 1241 PeformUpdate(GetOldSafeBrowsingPath(), chunks, deletes); |
1242 } | 1242 } |
OLD | NEW |