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

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

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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
OLDNEW
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
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{
217 public: 217 bool OnMessage(int severity, const char* file, int line,
218 ScopedLogMessageIgnorer() { 218 size_t message_start, const std::string& str) override {
219 logging::SetLogMessageHandler(&LogMessageIgnorer);
220 }
221 ~ScopedLogMessageIgnorer() {
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 219 // Intercept FATAL, strip the stack backtrace, and log it without
231 // the crash part. 220 // the crash part.
232 if (severity == logging::LOG_FATAL) { 221 if (severity == logging::LOG_FATAL) {
233 size_t newline = str.find('\n'); 222 size_t newline = str.find('\n');
234 if (newline != std::string::npos) { 223 if (newline != std::string::npos) {
235 const std::string msg = str.substr(0, newline + 1); 224 const std::string msg = str.substr(0, newline + 1);
236 fprintf(stderr, "%s", msg.c_str()); 225 fprintf(stderr, "%s", msg.c_str());
237 fflush(stderr); 226 fflush(stderr);
238 } 227 }
239 return true; 228 return true;
(...skipping 2128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 ASSERT_EQ(1U, prefix_hits.size()); 2357 ASSERT_EQ(1U, prefix_hits.size());
2369 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); 2358 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]);
2370 EXPECT_TRUE(cache_hits.empty()); 2359 EXPECT_TRUE(cache_hits.empty());
2371 2360
2372 // This prefix collides, but no full hash match. 2361 // This prefix collides, but no full hash match.
2373 EXPECT_FALSE(database_->ContainsBrowseUrl( 2362 EXPECT_FALSE(database_->ContainsBrowseUrl(
2374 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); 2363 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits));
2375 } 2364 }
2376 2365
2377 } // namespace safe_browsing 2366 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698