| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 std::wstring GetTestDatabaseName() { | 56 std::wstring GetTestDatabaseName() { |
| 57 std::wstring filename; | 57 std::wstring filename; |
| 58 PathService::Get(base::DIR_TEMP, &filename); | 58 PathService::Get(base::DIR_TEMP, &filename); |
| 59 filename.push_back(file_util::kPathSeparator); | 59 filename.push_back(file_util::kPathSeparator); |
| 60 filename.append(kSafeBrowsingTestDatabase); | 60 filename.append(kSafeBrowsingTestDatabase); |
| 61 return filename; | 61 return filename; |
| 62 } | 62 } |
| 63 | 63 |
| 64 SafeBrowsingDatabase* SetupTestDatabase() { | 64 SafeBrowsingDatabase* SetupTestDatabase() { |
| 65 std::wstring filename = GetTestDatabaseName(); | 65 std::wstring filename = GetTestDatabaseName(); |
| 66 DeleteFile(filename.c_str()); // In case it existed from a previous run. | 66 // In case it existed from a previous run. |
| 67 file_util::Delete(filename, false); |
| 67 | 68 |
| 68 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); | 69 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); |
| 69 database->SetSynchronous(); | 70 database->SetSynchronous(); |
| 70 EXPECT_TRUE(database->Init(filename, NULL)); | 71 EXPECT_TRUE(database->Init(filename, NULL)); |
| 71 | 72 |
| 72 return database; | 73 return database; |
| 73 } | 74 } |
| 74 | 75 |
| 75 void TearDownTestDatabase(SafeBrowsingDatabase* database) { | 76 void TearDownTestDatabase(SafeBrowsingDatabase* database) { |
| 76 DeleteFile(GetTestDatabaseName().c_str()); | 77 file_util::Delete(GetTestDatabaseName(), false); |
| 77 delete database; | 78 delete database; |
| 78 } | 79 } |
| 79 | 80 |
| 80 } // namespace | 81 } // namespace |
| 81 | 82 |
| 82 // Checks database reading and writing. | 83 // Checks database reading and writing. |
| 83 TEST(SafeBrowsingDatabase, Database) { | 84 TEST(SafeBrowsingDatabase, Database) { |
| 84 SafeBrowsingDatabase* database = SetupTestDatabase(); | 85 SafeBrowsingDatabase* database = SetupTestDatabase(); |
| 85 | 86 |
| 86 // Add a simple chunk with one hostkey. | 87 // Add a simple chunk with one hostkey. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 135 |
| 135 chunks = new std::deque<SBChunk>; | 136 chunks = new std::deque<SBChunk>; |
| 136 chunks->push_back(chunk); | 137 chunks->push_back(chunk); |
| 137 database->InsertChunks("goog-malware", chunks); | 138 database->InsertChunks("goog-malware", chunks); |
| 138 database->UpdateFinished(); | 139 database->UpdateFinished(); |
| 139 | 140 |
| 140 | 141 |
| 141 // Make sure they were added correctly. | 142 // Make sure they were added correctly. |
| 142 std::vector<SBListChunkRanges> lists; | 143 std::vector<SBListChunkRanges> lists; |
| 143 database->GetListsInfo(&lists); | 144 database->GetListsInfo(&lists); |
| 144 EXPECT_EQ(lists.size(), 1); | 145 EXPECT_EQ(lists.size(), 1U); |
| 145 EXPECT_EQ(lists[0].name, "goog-malware"); | 146 EXPECT_EQ(lists[0].name, "goog-malware"); |
| 146 EXPECT_EQ(lists[0].adds, "1-3"); | 147 EXPECT_EQ(lists[0].adds, "1-3"); |
| 147 EXPECT_TRUE(lists[0].subs.empty()); | 148 EXPECT_TRUE(lists[0].subs.empty()); |
| 148 | 149 |
| 149 const Time now = Time::Now(); | 150 const Time now = Time::Now(); |
| 150 std::vector<SBFullHashResult> full_hashes; | 151 std::vector<SBFullHashResult> full_hashes; |
| 151 std::vector<SBPrefix> prefix_hits; | 152 std::vector<SBPrefix> prefix_hits; |
| 152 std::string matching_list; | 153 std::string matching_list; |
| 153 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/phishing.html"), | 154 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/phishing.html"), |
| 154 &matching_list, &prefix_hits, | 155 &matching_list, &prefix_hits, |
| 155 &full_hashes, now)); | 156 &full_hashes, now)); |
| 156 EXPECT_EQ(prefix_hits[0], Sha256Prefix("www.evil.com/phishing.html")); | 157 EXPECT_EQ(prefix_hits[0], Sha256Prefix("www.evil.com/phishing.html")); |
| 157 EXPECT_EQ(prefix_hits.size(), 1); | 158 EXPECT_EQ(prefix_hits.size(), 1U); |
| 158 | 159 |
| 159 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/malware.html"), | 160 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/malware.html"), |
| 160 &matching_list, &prefix_hits, | 161 &matching_list, &prefix_hits, |
| 161 &full_hashes, now)); | 162 &full_hashes, now)); |
| 162 | 163 |
| 163 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/notevil1.html"), | 164 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/notevil1.html"), |
| 164 &matching_list, &prefix_hits, | 165 &matching_list, &prefix_hits, |
| 165 &full_hashes, now)); | 166 &full_hashes, now)); |
| 166 | 167 |
| 167 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/notevil2.html"), | 168 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/notevil2.html"), |
| 168 &matching_list, &prefix_hits, | 169 &matching_list, &prefix_hits, |
| 169 &full_hashes, now)); | 170 &full_hashes, now)); |
| 170 | 171 |
| 171 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.good.com/good1.html"), | 172 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.good.com/good1.html"), |
| 172 &matching_list, &prefix_hits, | 173 &matching_list, &prefix_hits, |
| 173 &full_hashes, now)); | 174 &full_hashes, now)); |
| 174 | 175 |
| 175 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.good.com/good2.html"), | 176 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.good.com/good2.html"), |
| 176 &matching_list, &prefix_hits, | 177 &matching_list, &prefix_hits, |
| 177 &full_hashes, now)); | 178 &full_hashes, now)); |
| 178 | 179 |
| 179 EXPECT_TRUE(database->ContainsUrl(GURL("http://192.168.0.1/malware.html"), | 180 EXPECT_TRUE(database->ContainsUrl(GURL("http://192.168.0.1/malware.html"), |
| 180 &matching_list, &prefix_hits, | 181 &matching_list, &prefix_hits, |
| 181 &full_hashes, now)); | 182 &full_hashes, now)); |
| 182 | 183 |
| 183 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/"), | 184 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/"), |
| 184 &matching_list, &prefix_hits, | 185 &matching_list, &prefix_hits, |
| 185 &full_hashes, now)); | 186 &full_hashes, now)); |
| 186 EXPECT_EQ(prefix_hits.size(), 0); | 187 EXPECT_EQ(prefix_hits.size(), 0U); |
| 187 | 188 |
| 188 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/robots.txt"), | 189 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/robots.txt"), |
| 189 &matching_list, &prefix_hits, | 190 &matching_list, &prefix_hits, |
| 190 &full_hashes, now)); | 191 &full_hashes, now)); |
| 191 | 192 |
| 192 // Test removing a single prefix from the add chunk. | 193 // Test removing a single prefix from the add chunk. |
| 193 host.host = Sha256Prefix("www.evil.com/"); | 194 host.host = Sha256Prefix("www.evil.com/"); |
| 194 host.entry = SBEntry::Create(SBEntry::SUB_PREFIX, 2); | 195 host.entry = SBEntry::Create(SBEntry::SUB_PREFIX, 2); |
| 195 host.entry->set_chunk_id(2); | 196 host.entry->set_chunk_id(2); |
| 196 host.entry->SetChunkIdAtPrefix(0, 2); | 197 host.entry->SetChunkIdAtPrefix(0, 2); |
| 197 host.entry->SetPrefixAt(0, Sha256Prefix("www.evil.com/notevil1.html")); | 198 host.entry->SetPrefixAt(0, Sha256Prefix("www.evil.com/notevil1.html")); |
| 198 | 199 |
| 199 chunk.is_add = false; | 200 chunk.is_add = false; |
| 200 chunk.chunk_number = 4; | 201 chunk.chunk_number = 4; |
| 201 chunk.hosts.clear(); | 202 chunk.hosts.clear(); |
| 202 chunk.hosts.push_back(host); | 203 chunk.hosts.push_back(host); |
| 203 | 204 |
| 204 chunks = new std::deque<SBChunk>; | 205 chunks = new std::deque<SBChunk>; |
| 205 chunks->push_back(chunk); | 206 chunks->push_back(chunk); |
| 206 | 207 |
| 207 database->InsertChunks("goog-malware", chunks); | 208 database->InsertChunks("goog-malware", chunks); |
| 208 database->UpdateFinished(); | 209 database->UpdateFinished(); |
| 209 | 210 |
| 210 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/phishing.html"), | 211 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/phishing.html"), |
| 211 &matching_list, &prefix_hits, | 212 &matching_list, &prefix_hits, |
| 212 &full_hashes, now)); | 213 &full_hashes, now)); |
| 213 EXPECT_EQ(prefix_hits[0], Sha256Prefix("www.evil.com/phishing.html")); | 214 EXPECT_EQ(prefix_hits[0], Sha256Prefix("www.evil.com/phishing.html")); |
| 214 EXPECT_EQ(prefix_hits.size(), 1); | 215 EXPECT_EQ(prefix_hits.size(), 1U); |
| 215 | 216 |
| 216 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/notevil1.html"), | 217 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/notevil1.html"), |
| 217 &matching_list, &prefix_hits, | 218 &matching_list, &prefix_hits, |
| 218 &full_hashes, now)); | 219 &full_hashes, now)); |
| 219 EXPECT_EQ(prefix_hits.size(), 0); | 220 EXPECT_EQ(prefix_hits.size(), 0U); |
| 220 | 221 |
| 221 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/notevil2.html"), | 222 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/notevil2.html"), |
| 222 &matching_list, &prefix_hits, | 223 &matching_list, &prefix_hits, |
| 223 &full_hashes, now)); | 224 &full_hashes, now)); |
| 224 | 225 |
| 225 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.good.com/good1.html"), | 226 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.good.com/good1.html"), |
| 226 &matching_list, &prefix_hits, | 227 &matching_list, &prefix_hits, |
| 227 &full_hashes, now)); | 228 &full_hashes, now)); |
| 228 | 229 |
| 229 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.good.com/good2.html"), | 230 EXPECT_TRUE(database->ContainsUrl(GURL("http://www.good.com/good2.html"), |
| 230 &matching_list, &prefix_hits, | 231 &matching_list, &prefix_hits, |
| 231 &full_hashes, now)); | 232 &full_hashes, now)); |
| 232 | 233 |
| 233 database->GetListsInfo(&lists); | 234 database->GetListsInfo(&lists); |
| 234 EXPECT_EQ(lists.size(), 1); | 235 EXPECT_EQ(lists.size(), 1U); |
| 235 EXPECT_EQ(lists[0].name, "goog-malware"); | 236 EXPECT_EQ(lists[0].name, "goog-malware"); |
| 236 EXPECT_EQ(lists[0].subs, "4"); | 237 EXPECT_EQ(lists[0].subs, "4"); |
| 237 | 238 |
| 238 // Test removing all the prefixes from an add chunk. | 239 // Test removing all the prefixes from an add chunk. |
| 239 AddDelChunk(database, "goog-malware", 2); | 240 AddDelChunk(database, "goog-malware", 2); |
| 240 database->UpdateFinished(); | 241 database->UpdateFinished(); |
| 241 | 242 |
| 242 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/notevil2.html"), | 243 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/notevil2.html"), |
| 243 &matching_list, &prefix_hits, | 244 &matching_list, &prefix_hits, |
| 244 &full_hashes, now)); | 245 &full_hashes, now)); |
| 245 | 246 |
| 246 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.good.com/good1.html"), | 247 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.good.com/good1.html"), |
| 247 &matching_list, &prefix_hits, | 248 &matching_list, &prefix_hits, |
| 248 &full_hashes, now)); | 249 &full_hashes, now)); |
| 249 | 250 |
| 250 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.good.com/good2.html"), | 251 EXPECT_FALSE(database->ContainsUrl(GURL("http://www.good.com/good2.html"), |
| 251 &matching_list, &prefix_hits, | 252 &matching_list, &prefix_hits, |
| 252 &full_hashes, now)); | 253 &full_hashes, now)); |
| 253 | 254 |
| 254 database->GetListsInfo(&lists); | 255 database->GetListsInfo(&lists); |
| 255 EXPECT_EQ(lists.size(), 1); | 256 EXPECT_EQ(lists.size(), 1U); |
| 256 EXPECT_EQ(lists[0].name, "goog-malware"); | 257 EXPECT_EQ(lists[0].name, "goog-malware"); |
| 257 EXPECT_EQ(lists[0].adds, "1,3"); | 258 EXPECT_EQ(lists[0].adds, "1,3"); |
| 258 EXPECT_EQ(lists[0].subs, "4"); | 259 EXPECT_EQ(lists[0].subs, "4"); |
| 259 | 260 |
| 260 // The adddel command exposed a bug in the transaction code where any | 261 // The adddel command exposed a bug in the transaction code where any |
| 261 // transaction after it would fail. Add a dummy entry and remove it to | 262 // transaction after it would fail. Add a dummy entry and remove it to |
| 262 // make sure the transcation works fine. | 263 // make sure the transcation works fine. |
| 263 host.host = Sha256Prefix("www.redherring.com/"); | 264 host.host = Sha256Prefix("www.redherring.com/"); |
| 264 host.entry = SBEntry::Create(SBEntry::ADD_PREFIX, 1); | 265 host.entry = SBEntry::Create(SBEntry::ADD_PREFIX, 1); |
| 265 host.entry->set_chunk_id(1); | 266 host.entry->set_chunk_id(1); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 276 | 277 |
| 277 // Now remove the dummy entry. If there are any problems with the | 278 // Now remove the dummy entry. If there are any problems with the |
| 278 // transactions, asserts will fire. | 279 // transactions, asserts will fire. |
| 279 AddDelChunk(database, "goog-malware", 44); | 280 AddDelChunk(database, "goog-malware", 44); |
| 280 | 281 |
| 281 // Test the subdel command. | 282 // Test the subdel command. |
| 282 SubDelChunk(database, "goog-malware", 4); | 283 SubDelChunk(database, "goog-malware", 4); |
| 283 database->UpdateFinished(); | 284 database->UpdateFinished(); |
| 284 | 285 |
| 285 database->GetListsInfo(&lists); | 286 database->GetListsInfo(&lists); |
| 286 EXPECT_EQ(lists.size(), 1); | 287 EXPECT_EQ(lists.size(), 1U); |
| 287 EXPECT_EQ(lists[0].name, "goog-malware"); | 288 EXPECT_EQ(lists[0].name, "goog-malware"); |
| 288 EXPECT_EQ(lists[0].adds, "1,3"); | 289 EXPECT_EQ(lists[0].adds, "1,3"); |
| 289 EXPECT_EQ(lists[0].subs, ""); | 290 EXPECT_EQ(lists[0].subs, ""); |
| 290 | 291 |
| 291 // Test a sub command coming in before the add. | 292 // Test a sub command coming in before the add. |
| 292 host.host = Sha256Prefix("www.notevilanymore.com/"); | 293 host.host = Sha256Prefix("www.notevilanymore.com/"); |
| 293 host.entry = SBEntry::Create(SBEntry::SUB_PREFIX, 2); | 294 host.entry = SBEntry::Create(SBEntry::SUB_PREFIX, 2); |
| 294 host.entry->set_chunk_id(10); | 295 host.entry->set_chunk_id(10); |
| 295 host.entry->SetPrefixAt(0, Sha256Prefix("www.notevilanymore.com/index.html")); | 296 host.entry->SetPrefixAt(0, Sha256Prefix("www.notevilanymore.com/index.html")); |
| 296 host.entry->SetChunkIdAtPrefix(0, 10); | 297 host.entry->SetChunkIdAtPrefix(0, 10); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 database->UpdateFinished(); | 455 database->UpdateFinished(); |
| 455 list_chunks_empty.clear(); | 456 list_chunks_empty.clear(); |
| 456 database->GetListsInfo(&list_chunks_empty); | 457 database->GetListsInfo(&list_chunks_empty); |
| 457 EXPECT_EQ(list_chunks_empty[0].adds, "1,10,19-20,22"); | 458 EXPECT_EQ(list_chunks_empty[0].adds, "1,10,19-20,22"); |
| 458 EXPECT_EQ(list_chunks_empty[0].subs, ""); | 459 EXPECT_EQ(list_chunks_empty[0].subs, ""); |
| 459 | 460 |
| 460 TearDownTestDatabase(database); | 461 TearDownTestDatabase(database); |
| 461 } | 462 } |
| 462 | 463 |
| 463 void PrintStat(const wchar_t* name) { | 464 void PrintStat(const wchar_t* name) { |
| 465 #if defined(OS_WIN) |
| 464 int value = StatsTable::current()->GetCounterValue(name); | 466 int value = StatsTable::current()->GetCounterValue(name); |
| 465 std::wstring out = StringPrintf(L"%ls %d\r\n", name, value); | 467 LOG(INFO) << StringPrintf(L"%ls %d", name, value); |
| 466 OutputDebugStringW(out.c_str()); | 468 #else |
| 469 // TODO(port): Enable when StatsTable is ported. |
| 470 NOTIMPLEMENTED(); |
| 471 #endif |
| 467 } | 472 } |
| 468 | 473 |
| 469 std::wstring GetFullSBDataPath(const std::wstring& path) { | 474 std::wstring GetFullSBDataPath(const std::wstring& path) { |
| 470 std::wstring full_path; | 475 std::wstring full_path; |
| 471 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &full_path)); | 476 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &full_path)); |
| 472 file_util::AppendToPath(&full_path, L"chrome\\test\\data\\safe_browsing"); | 477 file_util::AppendToPath(&full_path, L"chrome"); |
| 478 file_util::AppendToPath(&full_path, L"test"); |
| 479 file_util::AppendToPath(&full_path, L"data"); |
| 480 file_util::AppendToPath(&full_path, L"safe_browsing"); |
| 473 file_util::AppendToPath(&full_path, path); | 481 file_util::AppendToPath(&full_path, path); |
| 474 CHECK(file_util::PathExists(full_path)); | 482 CHECK(file_util::PathExists(full_path)); |
| 475 return full_path; | 483 return full_path; |
| 476 } | 484 } |
| 477 | 485 |
| 478 struct ChunksInfo { | 486 struct ChunksInfo { |
| 479 std::deque<SBChunk>* chunks; | 487 std::deque<SBChunk>* chunks; |
| 480 std::string listname; | 488 std::string listname; |
| 481 }; | 489 }; |
| 482 | 490 |
| 483 void PeformUpdate(const std::wstring& initial_db, | 491 void PeformUpdate(const std::wstring& initial_db, |
| 484 const std::vector<ChunksInfo>& chunks, | 492 const std::vector<ChunksInfo>& chunks, |
| 485 std::vector<SBChunkDelete>* deletes) { | 493 std::vector<SBChunkDelete>* deletes) { |
| 486 IoCounters before, after; | 494 IoCounters before, after; |
| 487 | 495 |
| 488 std::wstring filename; | 496 std::wstring filename; |
| 489 PathService::Get(base::DIR_TEMP, &filename); | 497 PathService::Get(base::DIR_TEMP, &filename); |
| 490 filename.push_back(file_util::kPathSeparator); | 498 filename.push_back(file_util::kPathSeparator); |
| 491 filename.append(L"SafeBrowsingTestDatabase"); | 499 filename.append(L"SafeBrowsingTestDatabase"); |
| 492 DeleteFile(filename.c_str()); // In case it existed from a previous run. | 500 // In case it existed from a previous run. |
| 501 file_util::Delete(filename, false); |
| 493 | 502 |
| 494 if (!initial_db.empty()) { | 503 if (!initial_db.empty()) { |
| 495 std::wstring full_initial_db = GetFullSBDataPath(initial_db); | 504 std::wstring full_initial_db = GetFullSBDataPath(initial_db); |
| 496 ASSERT_TRUE(file_util::CopyFile(full_initial_db, filename)); | 505 ASSERT_TRUE(file_util::CopyFile(full_initial_db, filename)); |
| 497 } | 506 } |
| 498 | 507 |
| 499 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); | 508 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); |
| 500 database->SetSynchronous(); | 509 database->SetSynchronous(); |
| 501 EXPECT_TRUE(database->Init(filename, NULL)); | 510 EXPECT_TRUE(database->Init(filename, NULL)); |
| 502 | 511 |
| 503 Time before_time = Time::Now(); | 512 Time before_time = Time::Now(); |
| 504 ProcessHandle handle = Process::Current().handle(); | 513 ProcessHandle handle = Process::Current().handle(); |
| 505 scoped_ptr<process_util::ProcessMetrics> metric( | 514 scoped_ptr<process_util::ProcessMetrics> metric( |
| 506 process_util::ProcessMetrics::CreateProcessMetrics(handle)); | 515 process_util::ProcessMetrics::CreateProcessMetrics(handle)); |
| 507 CHECK(metric->GetIOCounters(&before)); | 516 CHECK(metric->GetIOCounters(&before)); |
| 508 | 517 |
| 509 database->DeleteChunks(deletes); | 518 database->DeleteChunks(deletes); |
| 510 | 519 |
| 511 for (size_t i = 0; i < chunks.size(); ++i) | 520 for (size_t i = 0; i < chunks.size(); ++i) |
| 512 database->InsertChunks(chunks[i].listname, chunks[i].chunks); | 521 database->InsertChunks(chunks[i].listname, chunks[i].chunks); |
| 513 | 522 |
| 514 database->UpdateFinished(); | 523 database->UpdateFinished(); |
| 515 | 524 |
| 516 CHECK(metric->GetIOCounters(&after)); | 525 CHECK(metric->GetIOCounters(&after)); |
| 517 | 526 |
| 518 OutputDebugStringA(StringPrintf("I/O Read Bytes: %d\r\n", | 527 LOG(INFO) << StringPrintf("I/O Read Bytes: %d", |
| 519 after.ReadTransferCount - before.ReadTransferCount).c_str()); | 528 after.ReadTransferCount - before.ReadTransferCount); |
| 520 OutputDebugStringA(StringPrintf("I/O Write Bytes: %d\r\n", | 529 LOG(INFO) << StringPrintf("I/O Write Bytes: %d", |
| 521 after.WriteTransferCount - before.WriteTransferCount).c_str()); | 530 after.WriteTransferCount - before.WriteTransferCount); |
| 522 OutputDebugStringA(StringPrintf("I/O Reads: %d\r\n", | 531 LOG(INFO) << StringPrintf("I/O Reads: %d", |
| 523 after.ReadOperationCount - before.ReadOperationCount).c_str()); | 532 after.ReadOperationCount - before.ReadOperationCount); |
| 524 OutputDebugStringA(StringPrintf("I/O Writes: %d\r\n", | 533 LOG(INFO) << StringPrintf("I/O Writes: %d", |
| 525 after.WriteOperationCount - before.WriteOperationCount).c_str()); | 534 after.WriteOperationCount - before.WriteOperationCount); |
| 526 OutputDebugStringA(StringPrintf("Finished in %d ms\r\n", | 535 LOG(INFO) << StringPrintf("Finished in %d ms", |
| 527 (Time::Now() - before_time).InMilliseconds()).c_str()); | 536 (Time::Now() - before_time).InMilliseconds()); |
| 528 | 537 |
| 529 PrintStat(L"c:SB.HostSelect"); | 538 PrintStat(L"c:SB.HostSelect"); |
| 530 PrintStat(L"c:SB.HostSelectForBloomFilter"); | 539 PrintStat(L"c:SB.HostSelectForBloomFilter"); |
| 531 PrintStat(L"c:SB.HostReplace"); | 540 PrintStat(L"c:SB.HostReplace"); |
| 532 PrintStat(L"c:SB.HostInsert"); | 541 PrintStat(L"c:SB.HostInsert"); |
| 533 PrintStat(L"c:SB.HostDelete"); | 542 PrintStat(L"c:SB.HostDelete"); |
| 534 PrintStat(L"c:SB.ChunkSelect"); | 543 PrintStat(L"c:SB.ChunkSelect"); |
| 535 PrintStat(L"c:SB.ChunkInsert"); | 544 PrintStat(L"c:SB.ChunkInsert"); |
| 536 PrintStat(L"c:SB.ChunkDelete"); | 545 PrintStat(L"c:SB.ChunkDelete"); |
| 537 PrintStat(L"c:SB.TransactionCommit"); | 546 PrintStat(L"c:SB.TransactionCommit"); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 &urls); | 607 &urls); |
| 599 DCHECK(result); | 608 DCHECK(result); |
| 600 if (!updates_path.empty()) | 609 if (!updates_path.empty()) |
| 601 DCHECK(urls.size() == chunks.size()); | 610 DCHECK(urls.size() == chunks.size()); |
| 602 } | 611 } |
| 603 } | 612 } |
| 604 | 613 |
| 605 PeformUpdate(initial_db, chunks, deletes); | 614 PeformUpdate(initial_db, chunks, deletes); |
| 606 } | 615 } |
| 607 | 616 |
| 617 namespace { |
| 618 |
| 619 const wchar_t* GetOldSafeBrowsingPath() { |
| 620 std::wstring path = L"old"; |
| 621 file_util::AppendToPath(&path, L"SafeBrowsing"); |
| 622 return path.c_str(); |
| 623 } |
| 624 |
| 625 const wchar_t* GetOldResponsePath() { |
| 626 std::wstring path = L"old"; |
| 627 file_util::AppendToPath(&path, L"response"); |
| 628 return path.c_str(); |
| 629 } |
| 630 |
| 631 const wchar_t* GetOldUpdatesPath() { |
| 632 std::wstring path = L"old"; |
| 633 file_util::AppendToPath(&path, L"updates"); |
| 634 return path.c_str(); |
| 635 } |
| 636 |
| 637 } // namespace |
| 638 |
| 608 // Counts the IO needed for the initial update of a database. | 639 // Counts the IO needed for the initial update of a database. |
| 609 // test\data\safe_browsing\download_update.py was used to fetch the add/sub | 640 // test\data\safe_browsing\download_update.py was used to fetch the add/sub |
| 610 // chunks that are read, in order to get repeatable runs. | 641 // chunks that are read, in order to get repeatable runs. |
| 611 TEST(SafeBrowsingDatabase, DISABLED_DatabaseInitialIO) { | 642 TEST(SafeBrowsingDatabase, DISABLED_DatabaseInitialIO) { |
| 612 UpdateDatabase(L"", L"", L"initial"); | 643 UpdateDatabase(L"", L"", L"initial"); |
| 613 } | 644 } |
| 614 | 645 |
| 646 // TODO(port): For now on Linux the test below would fail with error below: |
| 647 // [1004/201323:FATAL:browser/safe_browsing/safe_browsing_database_impl.cc(712)] |
| 648 // Check failed: false. |
| 649 // |
| 615 // Counts the IO needed to update a month old database. | 650 // Counts the IO needed to update a month old database. |
| 616 // The data files were generated by running "..\download_update.py postdata" | 651 // The data files were generated by running "..\download_update.py postdata" |
| 617 // in the "safe_browsing\old" directory. | 652 // in the "safe_browsing\old" directory. |
| 618 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldIO) { | 653 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldIO) { |
| 619 UpdateDatabase(L"old\\SafeBrowsing", L"old\\response", L"old\\updates"); | 654 UpdateDatabase(GetOldSafeBrowsingPath(), GetOldResponsePath(), |
| 655 GetOldUpdatesPath()); |
| 620 } | 656 } |
| 621 | 657 |
| 658 // TODO(port): For now on Linux the test below would fail with error below: |
| 659 // [1004/201323:FATAL:browser/safe_browsing/safe_browsing_database_impl.cc(712)] |
| 660 // Check failed: false. |
| 661 // |
| 622 // Like DatabaseOldIO but only the deletes. | 662 // Like DatabaseOldIO but only the deletes. |
| 623 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldDeletesIO) { | 663 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldDeletesIO) { |
| 624 UpdateDatabase(L"old\\SafeBrowsing", L"old\\response", L""); | 664 UpdateDatabase(GetOldSafeBrowsingPath(), GetOldResponsePath(), L""); |
| 625 } | 665 } |
| 626 | 666 |
| 627 // Like DatabaseOldIO but only the updates. | 667 // Like DatabaseOldIO but only the updates. |
| 628 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldUpdatesIO) { | 668 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldUpdatesIO) { |
| 629 UpdateDatabase(L"old\\SafeBrowsing", L"", L"old\\updates"); | 669 UpdateDatabase(GetOldSafeBrowsingPath(), L"", GetOldUpdatesPath()); |
| 630 } | 670 } |
| 631 | 671 |
| 672 // TODO(port): For now on Linux the test below would fail with error below: |
| 673 // [1004/201323:FATAL:browser/safe_browsing/safe_browsing_database_impl.cc(712)] |
| 674 // Check failed: false. |
| 675 // |
| 632 // Does a a lot of addel's on very large chunks. | 676 // Does a a lot of addel's on very large chunks. |
| 633 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) { | 677 TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) { |
| 634 std::vector<ChunksInfo> chunks; | 678 std::vector<ChunksInfo> chunks; |
| 635 std::vector<SBChunkDelete>* deletes = new std::vector<SBChunkDelete>; | 679 std::vector<SBChunkDelete>* deletes = new std::vector<SBChunkDelete>; |
| 636 SBChunkDelete del; | 680 SBChunkDelete del; |
| 637 del.is_sub_del = false; | 681 del.is_sub_del = false; |
| 638 del.list_name = "goog-malware-shavar"; | 682 del.list_name = "goog-malware-shavar"; |
| 639 del.chunk_del.push_back(ChunkRange(3539, 3579)); | 683 del.chunk_del.push_back(ChunkRange(3539, 3579)); |
| 640 deletes->push_back(del); | 684 deletes->push_back(del); |
| 641 PeformUpdate(L"old\\SafeBrowsing", chunks, deletes); | 685 PeformUpdate(GetOldSafeBrowsingPath(), chunks, deletes); |
| 642 } | 686 } |
| OLD | NEW |