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_util.h" | 9 #include "base/file_util.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/process_util.h" | 12 #include "base/process_util.h" |
12 #include "base/sha2.h" | 13 #include "base/sha2.h" |
13 #include "base/stats_counters.h" | 14 #include "base/stats_counters.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "chrome/browser/safe_browsing/protocol_parser.h" | 17 #include "chrome/browser/safe_browsing/protocol_parser.h" |
17 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using base::Time; | 23 using base::Time; |
23 | 24 |
24 static const wchar_t kSafeBrowsingTestDatabase[] = L"SafeBrowsingTestDatabase"; | |
25 static const wchar_t kBloomSuffix[] = L" Bloom"; | 25 static const wchar_t kBloomSuffix[] = L" Bloom"; |
26 | 26 |
27 namespace { | 27 namespace { |
28 SBPrefix Sha256Prefix(const std::string& str) { | 28 SBPrefix Sha256Prefix(const std::string& str) { |
29 SBPrefix hash; | 29 SBPrefix hash; |
30 base::SHA256HashString(str, &hash, sizeof(hash)); | 30 base::SHA256HashString(str, &hash, sizeof(hash)); |
31 return hash; | 31 return hash; |
32 } | 32 } |
33 | 33 |
34 // Helper function to do an AddDel or SubDel command. | 34 // Helper function to do an AddDel or SubDel command. |
(...skipping 17 matching lines...) Expand all Loading... |
52 } | 52 } |
53 | 53 |
54 void SubDelChunk(SafeBrowsingDatabase* db, | 54 void SubDelChunk(SafeBrowsingDatabase* db, |
55 const std::string& list, | 55 const std::string& list, |
56 int chunk_id) { | 56 int chunk_id) { |
57 DelChunk(db, list, chunk_id, true); | 57 DelChunk(db, list, chunk_id, true); |
58 } | 58 } |
59 | 59 |
60 // Common database test set up code. | 60 // Common database test set up code. |
61 std::wstring GetTestDatabaseName() { | 61 std::wstring GetTestDatabaseName() { |
62 std::wstring filename; | 62 FilePath filename; |
63 PathService::Get(base::DIR_TEMP, &filename); | 63 PathService::Get(base::DIR_TEMP, &filename); |
64 filename.push_back(file_util::kPathSeparator); | 64 filename = filename.Append(FILE_PATH_LITERAL("SafeBrowsingTestDatabase")); |
65 filename.append(kSafeBrowsingTestDatabase); | 65 return filename.ToWStringHack(); |
66 return filename; | |
67 } | 66 } |
68 | 67 |
69 SafeBrowsingDatabase* SetupTestDatabase() { | 68 SafeBrowsingDatabase* SetupTestDatabase() { |
70 std::wstring filename = GetTestDatabaseName(); | 69 std::wstring filename = GetTestDatabaseName(); |
71 | 70 |
72 // In case it existed from a previous run. | 71 // In case it existed from a previous run. |
73 file_util::Delete(filename + kBloomSuffix, false); | 72 file_util::Delete(filename + kBloomSuffix, false); |
74 file_util::Delete(filename, false); | 73 file_util::Delete(filename, false); |
75 | 74 |
76 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); | 75 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 | 1034 |
1036 void PeformUpdate(const std::wstring& initial_db, | 1035 void PeformUpdate(const std::wstring& initial_db, |
1037 const std::vector<ChunksInfo>& chunks, | 1036 const std::vector<ChunksInfo>& chunks, |
1038 std::vector<SBChunkDelete>* deletes) { | 1037 std::vector<SBChunkDelete>* deletes) { |
1039 // TODO(pinkerton): I don't think posix has any concept of IO counters, but | 1038 // TODO(pinkerton): I don't think posix has any concept of IO counters, but |
1040 // we can uncomment this when we implement ProcessMetrics::GetIOCounters | 1039 // we can uncomment this when we implement ProcessMetrics::GetIOCounters |
1041 #if defined(OS_WIN) || defined(OS_LINUX) | 1040 #if defined(OS_WIN) || defined(OS_LINUX) |
1042 IoCounters before, after; | 1041 IoCounters before, after; |
1043 #endif | 1042 #endif |
1044 | 1043 |
1045 std::wstring filename; | 1044 FilePath path; |
1046 PathService::Get(base::DIR_TEMP, &filename); | 1045 PathService::Get(base::DIR_TEMP, &path); |
1047 filename.push_back(file_util::kPathSeparator); | 1046 path = path.Append(FILE_PATH_LITERAL("SafeBrowsingTestDatabase")); |
1048 filename.append(L"SafeBrowsingTestDatabase"); | 1047 std::wstring filename = path.ToWStringHack(); |
| 1048 |
1049 // In case it existed from a previous run. | 1049 // In case it existed from a previous run. |
1050 file_util::Delete(filename, false); | 1050 file_util::Delete(filename, false); |
1051 | 1051 |
1052 if (!initial_db.empty()) { | 1052 if (!initial_db.empty()) { |
1053 std::wstring full_initial_db = GetFullSBDataPath(initial_db); | 1053 std::wstring full_initial_db = GetFullSBDataPath(initial_db); |
1054 ASSERT_TRUE(file_util::CopyFile(full_initial_db, filename)); | 1054 ASSERT_TRUE(file_util::CopyFile(full_initial_db, filename)); |
1055 } | 1055 } |
1056 | 1056 |
1057 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); | 1057 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); |
1058 database->SetSynchronous(); | 1058 database->SetSynchronous(); |
(...skipping 174 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 |