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_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
13 #include "base/sha2.h" | 13 #include "base/sha2.h" |
14 #include "base/stats_counters.h" | 14 #include "base/stats_counters.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "chrome/browser/safe_browsing/protocol_parser.h" | 17 #include "chrome/browser/safe_browsing/protocol_parser.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "testing/platform_test.h" |
22 | 23 |
23 using base::Time; | 24 using base::Time; |
24 | 25 |
25 static const wchar_t kBloomSuffix[] = L" Bloom"; | 26 static const wchar_t kBloomSuffix[] = L" Bloom"; |
26 | 27 |
27 namespace { | 28 namespace { |
28 SBPrefix Sha256Prefix(const std::string& str) { | 29 SBPrefix Sha256Prefix(const std::string& str) { |
29 SBPrefix hash; | 30 SBPrefix hash; |
30 base::SHA256HashString(str, &hash, sizeof(hash)); | 31 base::SHA256HashString(str, &hash, sizeof(hash)); |
31 return hash; | 32 return hash; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 89 |
89 void GetListsInfo(SafeBrowsingDatabase* database, | 90 void GetListsInfo(SafeBrowsingDatabase* database, |
90 std::vector<SBListChunkRanges>* lists) { | 91 std::vector<SBListChunkRanges>* lists) { |
91 EXPECT_TRUE(database->UpdateStarted()); | 92 EXPECT_TRUE(database->UpdateStarted()); |
92 database->GetListsInfo(lists); | 93 database->GetListsInfo(lists); |
93 database->UpdateFinished(true); | 94 database->UpdateFinished(true); |
94 } | 95 } |
95 | 96 |
96 } // namespace | 97 } // namespace |
97 | 98 |
| 99 class SafeBrowsingDatabasePlatformTest : public PlatformTest { |
| 100 }; |
| 101 |
98 // Tests retrieving list name information. | 102 // Tests retrieving list name information. |
99 TEST(SafeBrowsingDatabase, ListName) { | 103 TEST_F(SafeBrowsingDatabasePlatformTest, ListName) { |
100 SafeBrowsingDatabase* database = SetupTestDatabase(); | 104 SafeBrowsingDatabase* database = SetupTestDatabase(); |
101 | 105 |
102 // Insert some malware add chunks. | 106 // Insert some malware add chunks. |
103 SBChunkHost host; | 107 SBChunkHost host; |
104 host.host = Sha256Prefix("www.evil.com/"); | 108 host.host = Sha256Prefix("www.evil.com/"); |
105 host.entry = SBEntry::Create(SBEntry::ADD_PREFIX, 1); | 109 host.entry = SBEntry::Create(SBEntry::ADD_PREFIX, 1); |
106 host.entry->set_chunk_id(1); | 110 host.entry->set_chunk_id(1); |
107 host.entry->SetPrefixAt(0, Sha256Prefix("www.evil.com/malware.html")); | 111 host.entry->SetPrefixAt(0, Sha256Prefix("www.evil.com/malware.html")); |
108 SBChunk chunk; | 112 SBChunk chunk; |
109 chunk.chunk_number = 1; | 113 chunk.chunk_number = 1; |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) { | 1238 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) { |
1235 std::vector<ChunksInfo> chunks; | 1239 std::vector<ChunksInfo> chunks; |
1236 std::vector<SBChunkDelete>* deletes = new std::vector<SBChunkDelete>; | 1240 std::vector<SBChunkDelete>* deletes = new std::vector<SBChunkDelete>; |
1237 SBChunkDelete del; | 1241 SBChunkDelete del; |
1238 del.is_sub_del = false; | 1242 del.is_sub_del = false; |
1239 del.list_name = safe_browsing_util::kMalwareList; | 1243 del.list_name = safe_browsing_util::kMalwareList; |
1240 del.chunk_del.push_back(ChunkRange(3539, 3579)); | 1244 del.chunk_del.push_back(ChunkRange(3539, 3579)); |
1241 deletes->push_back(del); | 1245 deletes->push_back(del); |
1242 PeformUpdate(GetOldSafeBrowsingPath(), chunks, deletes); | 1246 PeformUpdate(GetOldSafeBrowsingPath(), chunks, deletes); |
1243 } | 1247 } |
OLD | NEW |