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

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

Issue 744183002: More explicit thread checking in SafeBrowsingDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a3_deadcode
Patch Set: extract race fix to CL#793663003 Created 6 years 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 "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/sha1.h" 14 #include "base/sha1.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "chrome/browser/safe_browsing/chunk.pb.h" 18 #include "chrome/browser/safe_browsing/chunk.pb.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" 19 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
20 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "crypto/sha2.h" 20 #include "crypto/sha2.h"
22 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
23 #include "sql/connection.h" 22 #include "sql/connection.h"
24 #include "sql/statement.h" 23 #include "sql/statement.h"
25 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
26 #include "testing/platform_test.h" 25 #include "testing/platform_test.h"
27 #include "url/gurl.h" 26 #include "url/gurl.h"
28 27
29 using base::Time; 28 using base::Time;
30 using base::TimeDelta; 29 using base::TimeDelta;
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 urls.push_back(GURL(std::string("https://") + kEvil1Url2)); 1231 urls.push_back(GURL(std::string("https://") + kEvil1Url2));
1233 EXPECT_TRUE(database_->ContainsDownloadUrl(urls, &prefix_hits)); 1232 EXPECT_TRUE(database_->ContainsDownloadUrl(urls, &prefix_hits));
1234 ASSERT_EQ(2U, prefix_hits.size()); 1233 ASSERT_EQ(2U, prefix_hits.size());
1235 EXPECT_EQ(SBPrefixForString(kEvil1Url1), prefix_hits[0]); 1234 EXPECT_EQ(SBPrefixForString(kEvil1Url1), prefix_hits[0]);
1236 EXPECT_EQ(SBPrefixForString(kEvil1Url2), prefix_hits[1]); 1235 EXPECT_EQ(SBPrefixForString(kEvil1Url2), prefix_hits[1]);
1237 database_.reset(); 1236 database_.reset();
1238 } 1237 }
1239 1238
1240 // Checks that the whitelists are handled properly. 1239 // Checks that the whitelists are handled properly.
1241 TEST_F(SafeBrowsingDatabaseTest, Whitelists) { 1240 TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
1242 database_.reset();
1243
1244 // We expect all calls to ContainsCsdWhitelistedUrl in particular to be made
1245 // from the IO thread. In general the whitelist lookups are thread-safe.
1246 content::TestBrowserThreadBundle thread_bundle_;
1247
1248 // If the whitelist is disabled everything should match the whitelist. 1241 // If the whitelist is disabled everything should match the whitelist.
1249 database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(), 1242 database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(),
1250 NULL, NULL, NULL, NULL, NULL, 1243 NULL, NULL, NULL, NULL, NULL,
1251 NULL, NULL)); 1244 NULL, NULL));
1252 database_->Init(database_filename_); 1245 database_->Init(database_filename_);
1253 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1246 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1254 GURL(std::string("http://www.phishing.com/")))); 1247 GURL(std::string("http://www.phishing.com/"))));
1255 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1248 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1256 GURL(std::string("http://www.phishing.com/")))); 1249 GURL(std::string("http://www.phishing.com/"))));
1257 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf")); 1250 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf"));
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 GURL(std::string("http://") + kExampleCollision), 2130 GURL(std::string("http://") + kExampleCollision),
2138 &prefix_hits, &cache_hits)); 2131 &prefix_hits, &cache_hits));
2139 ASSERT_EQ(1U, prefix_hits.size()); 2132 ASSERT_EQ(1U, prefix_hits.size());
2140 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); 2133 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]);
2141 EXPECT_TRUE(cache_hits.empty()); 2134 EXPECT_TRUE(cache_hits.empty());
2142 2135
2143 // This prefix collides, but no full hash match. 2136 // This prefix collides, but no full hash match.
2144 EXPECT_FALSE(database_->ContainsBrowseUrl( 2137 EXPECT_FALSE(database_->ContainsBrowseUrl(
2145 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); 2138 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits));
2146 } 2139 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database.cc ('k') | chrome/browser/safe_browsing/safe_browsing_store_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698