OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/safe_browsing_database.h" | 7 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 return BuildChunk(chunk_number, ChunkData::ADD, ChunkData::FULL_32B, | 209 return BuildChunk(chunk_number, ChunkData::ADD, ChunkData::FULL_32B, |
210 &full_hash, sizeof(full_hash), std::vector<int>()); | 210 &full_hash, sizeof(full_hash), std::vector<int>()); |
211 } | 211 } |
212 | 212 |
213 // Prevent DCHECK from killing tests. | 213 // Prevent DCHECK from killing tests. |
214 // TODO(shess): Pawel disputes the use of this, so the test which uses | 214 // TODO(shess): Pawel disputes the use of this, so the test which uses |
215 // it is DISABLED. http://crbug.com/56448 | 215 // it is DISABLED. http://crbug.com/56448 |
216 class ScopedLogMessageIgnorer { | 216 class ScopedLogMessageIgnorer { |
217 public: | 217 public: |
218 ScopedLogMessageIgnorer() { | 218 ScopedLogMessageIgnorer() { |
219 logging::SetLogMessageHandler(&LogMessageIgnorer); | 219 logging::AddLogMessageHandler(&LogMessageIgnorer); |
220 } | 220 } |
221 ~ScopedLogMessageIgnorer() { | 221 ~ScopedLogMessageIgnorer() { |
222 // TODO(shess): Would be better to verify whether anyone else | 222 logging::RemoveLogMessageHandler(&LogMessageIgnorer); |
223 // changed it, and then restore it to the previous value. | |
224 logging::SetLogMessageHandler(NULL); | |
225 } | 223 } |
226 | 224 |
227 private: | 225 private: |
228 static bool LogMessageIgnorer(int severity, const char* file, int line, | 226 static bool LogMessageIgnorer(int severity, const std::string& file, int line, |
229 size_t message_start, const std::string& str) { | 227 const std::string& str) { |
230 // Intercept FATAL, strip the stack backtrace, and log it without | 228 // Intercept FATAL, strip the stack backtrace, and log it without |
231 // the crash part. | 229 // the crash part. |
232 if (severity == logging::LOG_FATAL) { | 230 if (severity == logging::LOG_FATAL) { |
233 size_t newline = str.find('\n'); | 231 size_t newline = str.find('\n'); |
234 if (newline != std::string::npos) { | 232 if (newline != std::string::npos) { |
235 const std::string msg = str.substr(0, newline + 1); | 233 const std::string msg = str.substr(0, newline + 1); |
236 fprintf(stderr, "%s", msg.c_str()); | 234 fprintf(stderr, "%s", msg.c_str()); |
237 fflush(stderr); | 235 fflush(stderr); |
238 } | 236 } |
239 return true; | 237 return true; |
(...skipping 2128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2368 ASSERT_EQ(1U, prefix_hits.size()); | 2366 ASSERT_EQ(1U, prefix_hits.size()); |
2369 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); | 2367 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); |
2370 EXPECT_TRUE(cache_hits.empty()); | 2368 EXPECT_TRUE(cache_hits.empty()); |
2371 | 2369 |
2372 // This prefix collides, but no full hash match. | 2370 // This prefix collides, but no full hash match. |
2373 EXPECT_FALSE(database_->ContainsBrowseUrl( | 2371 EXPECT_FALSE(database_->ContainsBrowseUrl( |
2374 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); | 2372 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); |
2375 } | 2373 } |
2376 | 2374 |
2377 } // namespace safe_browsing | 2375 } // namespace safe_browsing |
OLD | NEW |