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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 EXPECT_EQ(sizeof(SBFullHash), full_hash_str.size()); | 206 EXPECT_EQ(sizeof(SBFullHash), full_hash_str.size()); |
207 SBFullHash full_hash; | 207 SBFullHash full_hash; |
208 std::memcpy(&(full_hash.full_hash), full_hash_str.data(), sizeof(SBFullHash)); | 208 std::memcpy(&(full_hash.full_hash), full_hash_str.data(), sizeof(SBFullHash)); |
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 : logging::LogMessageHandler { |
grt (UTC plus 2)
2017/01/04 09:12:20
public inheritance and " public:" in the body
| |
217 public: | 217 bool OnMessage(int severity, |
218 ScopedLogMessageIgnorer() { | 218 const char* file, |
219 logging::SetLogMessageHandler(&LogMessageIgnorer); | 219 int line, |
220 } | 220 size_t message_start, |
221 ~ScopedLogMessageIgnorer() { | 221 const std::string& str) override { |
222 // TODO(shess): Would be better to verify whether anyone else | |
223 // changed it, and then restore it to the previous value. | |
224 logging::SetLogMessageHandler(NULL); | |
225 } | |
226 | |
227 private: | |
228 static bool LogMessageIgnorer(int severity, const char* file, int line, | |
229 size_t message_start, const std::string& str) { | |
230 // Intercept FATAL, strip the stack backtrace, and log it without | 222 // Intercept FATAL, strip the stack backtrace, and log it without |
231 // the crash part. | 223 // the crash part. |
232 if (severity == logging::LOG_FATAL) { | 224 if (severity == logging::LOG_FATAL) { |
233 size_t newline = str.find('\n'); | 225 size_t newline = str.find('\n'); |
234 if (newline != std::string::npos) { | 226 if (newline != std::string::npos) { |
235 const std::string msg = str.substr(0, newline + 1); | 227 const std::string msg = str.substr(0, newline + 1); |
236 fprintf(stderr, "%s", msg.c_str()); | 228 fprintf(stderr, "%s", msg.c_str()); |
237 fflush(stderr); | 229 fflush(stderr); |
238 } | 230 } |
239 return true; | 231 return true; |
240 } | 232 } |
241 | 233 |
242 return false; | 234 return false; |
243 } | 235 } |
244 }; | 236 }; |
grt (UTC plus 2)
2017/01/04 09:12:20
private:
DISALLOW...
| |
245 | 237 |
246 } // namespace | 238 } // namespace |
247 | 239 |
248 class SafeBrowsingDatabaseTest : public PlatformTest { | 240 class SafeBrowsingDatabaseTest : public PlatformTest { |
249 public: | 241 public: |
250 SafeBrowsingDatabaseTest() : task_runner_(new base::TestSimpleTaskRunner) {} | 242 SafeBrowsingDatabaseTest() : task_runner_(new base::TestSimpleTaskRunner) {} |
251 | 243 |
252 void SetUp() override { | 244 void SetUp() override { |
253 PlatformTest::SetUp(); | 245 PlatformTest::SetUp(); |
254 | 246 |
(...skipping 2113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2368 ASSERT_EQ(1U, prefix_hits.size()); | 2360 ASSERT_EQ(1U, prefix_hits.size()); |
2369 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); | 2361 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); |
2370 EXPECT_TRUE(cache_hits.empty()); | 2362 EXPECT_TRUE(cache_hits.empty()); |
2371 | 2363 |
2372 // This prefix collides, but no full hash match. | 2364 // This prefix collides, but no full hash match. |
2373 EXPECT_FALSE(database_->ContainsBrowseUrl( | 2365 EXPECT_FALSE(database_->ContainsBrowseUrl( |
2374 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); | 2366 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); |
2375 } | 2367 } |
2376 | 2368 |
2377 } // namespace safe_browsing | 2369 } // namespace safe_browsing |
OLD | NEW |