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

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 3 years, 11 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 const std::string& ip_str, 203 const std::string& ip_str,
204 size_t prefix_size) { 204 size_t prefix_size) {
205 const std::string full_hash_str = HashedIpPrefix(ip_str, prefix_size); 205 const std::string full_hash_str = HashedIpPrefix(ip_str, prefix_size);
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.
214 // TODO(shess): Pawel disputes the use of this, so the test which uses
215 // it is DISABLED. http://crbug.com/56448
216 class ScopedLogMessageIgnorer {
217 public:
218 ScopedLogMessageIgnorer() {
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
231 // the crash part.
232 if (severity == logging::LOG_FATAL) {
233 size_t newline = str.find('\n');
234 if (newline != std::string::npos) {
235 const std::string msg = str.substr(0, newline + 1);
236 fprintf(stderr, "%s", msg.c_str());
237 fflush(stderr);
238 }
239 return true;
240 }
241
242 return false;
243 }
244 };
245
246 } // namespace 213 } // namespace
247 214
248 class SafeBrowsingDatabaseTest : public PlatformTest { 215 class SafeBrowsingDatabaseTest : public PlatformTest {
249 public: 216 public:
250 SafeBrowsingDatabaseTest() : task_runner_(new base::TestSimpleTaskRunner) {} 217 SafeBrowsingDatabaseTest() : task_runner_(new base::TestSimpleTaskRunner) {}
251 218
252 void SetUp() override { 219 void SetUp() override {
253 PlatformTest::SetUp(); 220 PlatformTest::SetUp();
254 221
255 // Setup a database in a temporary directory. 222 // Setup a database in a temporary directory.
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 kCacheLifetime); 1132 kCacheLifetime);
1166 } 1133 }
1167 1134
1168 // The cached response means the collision no longer causes a hit. 1135 // The cached response means the collision no longer causes a hit.
1169 EXPECT_FALSE(database_->ContainsBrowseUrl( 1136 EXPECT_FALSE(database_->ContainsBrowseUrl(
1170 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); 1137 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits));
1171 } 1138 }
1172 1139
1173 // Test that corrupt databases are appropriately handled, even if the 1140 // Test that corrupt databases are appropriately handled, even if the
1174 // corruption is detected in the midst of the update. 1141 // corruption is detected in the midst of the update.
1175 // TODO(shess): Disabled until ScopedLogMessageIgnorer resolved. 1142 // TODO(shess): Disabled until DCHECK killing is resolved.
1176 // http://crbug.com/56448 1143 // http://crbug.com/56448
1177 TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) { 1144 TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) {
1178 // Re-create the database in a captive message loop so that we can 1145 // Re-create the database in a captive message loop so that we can
1179 // influence task-posting. Database specifically needs to the 1146 // influence task-posting. Database specifically needs to the
1180 // file-backed. 1147 // file-backed.
1181 database_.reset(); 1148 database_.reset();
1182 base::MessageLoop loop; 1149 base::MessageLoop loop;
1183 SafeBrowsingStoreFile* store = new SafeBrowsingStoreFile(task_runner_); 1150 SafeBrowsingStoreFile* store = new SafeBrowsingStoreFile(task_runner_);
1184 database_.reset(new SafeBrowsingDatabaseNew( 1151 database_.reset(new SafeBrowsingDatabaseNew(
1185 task_runner_, store, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)); 1152 task_runner_, store, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));
(...skipping 14 matching lines...) Expand all
1200 // until the entire table is read in |UpdateFinished()|. 1167 // until the entire table is read in |UpdateFinished()|.
1201 FILE* fp = base::OpenFile(database_filename_, "r+"); 1168 FILE* fp = base::OpenFile(database_filename_, "r+");
1202 ASSERT_TRUE(fp); 1169 ASSERT_TRUE(fp);
1203 ASSERT_NE(-1, fseek(fp, -8, SEEK_END)); 1170 ASSERT_NE(-1, fseek(fp, -8, SEEK_END));
1204 for (size_t i = 0; i < 8; ++i) { 1171 for (size_t i = 0; i < 8; ++i) {
1205 fputc('!', fp); 1172 fputc('!', fp);
1206 } 1173 }
1207 fclose(fp); 1174 fclose(fp);
1208 1175
1209 { 1176 {
1210 // The following code will cause DCHECKs, so suppress the crashes. 1177 // The following code will cause DCHECKs.
1211 ScopedLogMessageIgnorer ignorer; 1178 // There's no way to prevent DCHECK from killing tests.
1179 // TODO(shess): Pawel disputes the use of using (removed) LogMessageHandler
1180 // to hijack the message, so this test is DISABLED. http://crbug.com/56448
1212 1181
1213 // Start an update. The insert will fail due to corruption. 1182 // Start an update. The insert will fail due to corruption.
1214 ASSERT_TRUE(database_->UpdateStarted(&lists)); 1183 ASSERT_TRUE(database_->UpdateStarted(&lists));
1215 database_->InsertChunks(kMalwareList, chunks); 1184 database_->InsertChunks(kMalwareList, chunks);
1216 database_->UpdateFinished(true); 1185 database_->UpdateFinished(true);
1217 1186
1218 // Database file still exists until the corruption handler has run. 1187 // Database file still exists until the corruption handler has run.
1219 EXPECT_TRUE(base::PathExists(database_filename_)); 1188 EXPECT_TRUE(base::PathExists(database_filename_));
1220 1189
1221 // Flush through the corruption-handler task. 1190 // Flush through the corruption-handler task.
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 ASSERT_EQ(1U, prefix_hits.size()); 2337 ASSERT_EQ(1U, prefix_hits.size());
2369 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); 2338 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]);
2370 EXPECT_TRUE(cache_hits.empty()); 2339 EXPECT_TRUE(cache_hits.empty());
2371 2340
2372 // This prefix collides, but no full hash match. 2341 // This prefix collides, but no full hash match.
2373 EXPECT_FALSE(database_->ContainsBrowseUrl( 2342 EXPECT_FALSE(database_->ContainsBrowseUrl(
2374 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); 2343 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits));
2375 } 2344 }
2376 2345
2377 } // namespace safe_browsing 2346 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc/webrtc_browsertest_base.cc ('k') | chrome/browser/ui/webui/ntp/new_tab_ui_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698