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

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

Issue 19610: Safe browsing cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
OLDNEW
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 #include "testing/platform_test.h"
23 23
24 using base::Time; 24 using base::Time;
25 25
26 static const wchar_t kBloomSuffix[] = L" Bloom"; 26 static const FilePath::CharType kBloomSuffix[] =
27 FILE_PATH_LITERAL(" Bloom");
28 static const FilePath::CharType kFilterSuffix[] =
29 FILE_PATH_LITERAL(" Filter");
27 30
28 namespace { 31 namespace {
29 SBPrefix Sha256Prefix(const std::string& str) { 32 SBPrefix Sha256Prefix(const std::string& str) {
30 SBPrefix hash; 33 SBPrefix hash;
31 base::SHA256HashString(str, &hash, sizeof(hash)); 34 base::SHA256HashString(str, &hash, sizeof(hash));
32 return hash; 35 return hash;
33 } 36 }
34 37
35 // Helper function to do an AddDel or SubDel command. 38 // Helper function to do an AddDel or SubDel command.
36 void DelChunk(SafeBrowsingDatabase* db, 39 void DelChunk(SafeBrowsingDatabase* db,
(...skipping 15 matching lines...) Expand all
52 DelChunk(db, list, chunk_id, false); 55 DelChunk(db, list, chunk_id, false);
53 } 56 }
54 57
55 void SubDelChunk(SafeBrowsingDatabase* db, 58 void SubDelChunk(SafeBrowsingDatabase* db,
56 const std::string& list, 59 const std::string& list,
57 int chunk_id) { 60 int chunk_id) {
58 DelChunk(db, list, chunk_id, true); 61 DelChunk(db, list, chunk_id, true);
59 } 62 }
60 63
61 // Common database test set up code. 64 // Common database test set up code.
62 std::wstring GetTestDatabaseName() { 65 FilePath GetTestDatabaseName() {
63 FilePath filename; 66 FilePath filename;
64 PathService::Get(base::DIR_TEMP, &filename); 67 PathService::Get(base::DIR_TEMP, &filename);
65 filename = filename.AppendASCII("SafeBrowsingTestDatabase"); 68 filename = filename.AppendASCII("SafeBrowsingTestDatabase");
66 return filename.ToWStringHack(); 69 return filename;
67 } 70 }
68 71
69 SafeBrowsingDatabase* SetupTestDatabase() { 72 SafeBrowsingDatabase* SetupTestDatabase() {
70 std::wstring filename = GetTestDatabaseName(); 73 FilePath filename = GetTestDatabaseName();
71 74
72 // In case it existed from a previous run. 75 // In case it existed from a previous run.
73 file_util::Delete(filename + kBloomSuffix, false); 76 file_util::Delete(FilePath(filename.value() + kBloomSuffix), false);
74 file_util::Delete(filename, false); 77 file_util::Delete(filename, false);
75 78
76 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); 79 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create();
77 database->SetSynchronous(); 80 database->SetSynchronous();
78 EXPECT_TRUE(database->Init(filename, NULL)); 81 EXPECT_TRUE(database->Init(filename, NULL));
79 82
80 return database; 83 return database;
81 } 84 }
82 85
83 void TearDownTestDatabase(SafeBrowsingDatabase* database) { 86 void TearDownTestDatabase(SafeBrowsingDatabase* database) {
84 std::wstring filename = database->filename(); 87 FilePath filename = database->filename();
85 delete database; 88 delete database;
86 file_util::Delete(filename, false); 89 file_util::Delete(filename, false);
87 file_util::Delete(filename + L" Filter", false); 90 file_util::Delete(FilePath(filename.value() + kFilterSuffix),
91 false);
88 } 92 }
89 93
90 void GetListsInfo(SafeBrowsingDatabase* database, 94 void GetListsInfo(SafeBrowsingDatabase* database,
91 std::vector<SBListChunkRanges>* lists) { 95 std::vector<SBListChunkRanges>* lists) {
92 EXPECT_TRUE(database->UpdateStarted()); 96 EXPECT_TRUE(database->UpdateStarted());
93 database->GetListsInfo(lists); 97 database->GetListsInfo(lists);
94 database->UpdateFinished(true); 98 database->UpdateFinished(true);
95 } 99 }
96 100
97 } // namespace 101 } // namespace
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 std::vector<SBChunkDelete>* deletes) { 1046 std::vector<SBChunkDelete>* deletes) {
1043 // TODO(pinkerton): I don't think posix has any concept of IO counters, but 1047 // TODO(pinkerton): I don't think posix has any concept of IO counters, but
1044 // we can uncomment this when we implement ProcessMetrics::GetIOCounters 1048 // we can uncomment this when we implement ProcessMetrics::GetIOCounters
1045 #if defined(OS_WIN) || defined(OS_LINUX) 1049 #if defined(OS_WIN) || defined(OS_LINUX)
1046 IoCounters before, after; 1050 IoCounters before, after;
1047 #endif 1051 #endif
1048 1052
1049 FilePath path; 1053 FilePath path;
1050 PathService::Get(base::DIR_TEMP, &path); 1054 PathService::Get(base::DIR_TEMP, &path);
1051 path = path.AppendASCII("SafeBrowsingTestDatabase"); 1055 path = path.AppendASCII("SafeBrowsingTestDatabase");
1052 std::wstring filename = path.ToWStringHack();
1053 1056
1054 // In case it existed from a previous run. 1057 // In case it existed from a previous run.
1055 file_util::Delete(filename, false); 1058 file_util::Delete(path, false);
1056 1059
1057 if (!initial_db.empty()) { 1060 if (!initial_db.empty()) {
1058 std::wstring full_initial_db = GetFullSBDataPath(initial_db); 1061 std::wstring full_initial_db = GetFullSBDataPath(initial_db);
1059 ASSERT_TRUE(file_util::CopyFile(full_initial_db, filename)); 1062 ASSERT_TRUE(file_util::CopyFile(
1063 FilePath::FromWStringHack(full_initial_db), path));
1060 } 1064 }
1061 1065
1062 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); 1066 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create();
1063 database->SetSynchronous(); 1067 database->SetSynchronous();
1064 EXPECT_TRUE(database->Init(filename, NULL)); 1068 EXPECT_TRUE(database->Init(path, NULL));
1065 1069
1066 Time before_time = Time::Now(); 1070 Time before_time = Time::Now();
1067 base::ProcessHandle handle = base::Process::Current().handle(); 1071 base::ProcessHandle handle = base::Process::Current().handle();
1068 scoped_ptr<base::ProcessMetrics> metric( 1072 scoped_ptr<base::ProcessMetrics> metric(
1069 base::ProcessMetrics::CreateProcessMetrics(handle)); 1073 base::ProcessMetrics::CreateProcessMetrics(handle));
1070 #if defined(OS_WIN) || defined(OS_LINUX) 1074 #if defined(OS_WIN) || defined(OS_LINUX)
1071 CHECK(metric->GetIOCounters(&before)); 1075 CHECK(metric->GetIOCounters(&before));
1072 #endif 1076 #endif
1073 1077
1074 std::vector<SBListChunkRanges> lists; 1078 std::vector<SBListChunkRanges> lists;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) { 1243 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) {
1240 std::vector<ChunksInfo> chunks; 1244 std::vector<ChunksInfo> chunks;
1241 std::vector<SBChunkDelete>* deletes = new std::vector<SBChunkDelete>; 1245 std::vector<SBChunkDelete>* deletes = new std::vector<SBChunkDelete>;
1242 SBChunkDelete del; 1246 SBChunkDelete del;
1243 del.is_sub_del = false; 1247 del.is_sub_del = false;
1244 del.list_name = safe_browsing_util::kMalwareList; 1248 del.list_name = safe_browsing_util::kMalwareList;
1245 del.chunk_del.push_back(ChunkRange(3539, 3579)); 1249 del.chunk_del.push_back(ChunkRange(3539, 3579));
1246 deletes->push_back(del); 1250 deletes->push_back(del);
1247 PeformUpdate(GetOldSafeBrowsingPath(), chunks, deletes); 1251 PeformUpdate(GetOldSafeBrowsingPath(), chunks, deletes);
1248 } 1252 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database_impl.cc ('k') | chrome/browser/safe_browsing/safe_browsing_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698