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

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

Issue 1110723002: Split to SafeBrowsingDatabaseManager into Local* and Remote*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review. Tweak comments and list initializer. Created 5 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "chrome/browser/safe_browsing/database_manager.h" 11 #include "chrome/browser/safe_browsing/local_database_manager.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 using content::TestBrowserThreadBundle; 19 using content::TestBrowserThreadBundle;
20 20
21 namespace { 21 namespace {
(...skipping 25 matching lines...) Expand all
47 private: 47 private:
48 TestBrowserThreadBundle thread_bundle_; 48 TestBrowserThreadBundle thread_bundle_;
49 }; 49 };
50 50
51 bool SafeBrowsingDatabaseManagerTest::RunSBHashTest( 51 bool SafeBrowsingDatabaseManagerTest::RunSBHashTest(
52 const safe_browsing_util::ListType list_type, 52 const safe_browsing_util::ListType list_type,
53 const std::vector<SBThreatType>& expected_threats, 53 const std::vector<SBThreatType>& expected_threats,
54 const std::string& result_list) { 54 const std::string& result_list) {
55 scoped_refptr<SafeBrowsingService> sb_service_( 55 scoped_refptr<SafeBrowsingService> sb_service_(
56 SafeBrowsingService::CreateSafeBrowsingService()); 56 SafeBrowsingService::CreateSafeBrowsingService());
57 scoped_refptr<SafeBrowsingDatabaseManager> db_manager_( 57 scoped_refptr<LocalSafeBrowsingDatabaseManager> db_manager_(
58 new SafeBrowsingDatabaseManager(sb_service_)); 58 new LocalSafeBrowsingDatabaseManager(sb_service_));
59 const SBFullHash same_full_hash = {}; 59 const SBFullHash same_full_hash = {};
60 60
61 SafeBrowsingDatabaseManager::SafeBrowsingCheck* check = 61 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck* check =
62 new SafeBrowsingDatabaseManager::SafeBrowsingCheck( 62 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck(
63 std::vector<GURL>(), 63 std::vector<GURL>(),
64 std::vector<SBFullHash>(1, same_full_hash), 64 std::vector<SBFullHash>(1, same_full_hash),
65 NULL, 65 NULL,
66 list_type, 66 list_type,
67 expected_threats); 67 expected_threats);
68 db_manager_->checks_.insert(check); 68 db_manager_->checks_.insert(check);
69 69
70 const SBFullHashResult full_hash_result = { 70 const SBFullHashResult full_hash_result = {
71 same_full_hash, 71 same_full_hash,
72 safe_browsing_util::GetListId(result_list) 72 safe_browsing_util::GetListId(result_list)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 full_hashes.push_back(full_hash_malware); 148 full_hashes.push_back(full_hash_malware);
149 149
150 SBFullHashResult full_hash_unwanted; 150 SBFullHashResult full_hash_unwanted;
151 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash; 151 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash;
152 full_hash_unwanted.list_id = 152 full_hash_unwanted.list_id =
153 static_cast<int>(safe_browsing_util::UNWANTEDURL); 153 static_cast<int>(safe_browsing_util::UNWANTEDURL);
154 full_hashes.push_back(full_hash_unwanted); 154 full_hashes.push_back(full_hash_unwanted);
155 } 155 }
156 156
157 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 157 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
158 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( 158 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
159 kMalwareHostHash, full_hashes)); 159 kMalwareHostHash, full_hashes));
160 160
161 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, 161 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING,
162 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( 162 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
163 kPhishingHostHash, full_hashes)); 163 kPhishingHostHash, full_hashes));
164 164
165 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, 165 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED,
166 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( 166 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
167 kUnwantedHostHash, full_hashes)); 167 kUnwantedHostHash, full_hashes));
168 168
169 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 169 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
170 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( 170 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
171 kUnwantedAndMalwareHostHash, full_hashes)); 171 kUnwantedAndMalwareHostHash, full_hashes));
172 172
173 EXPECT_EQ(SB_THREAT_TYPE_SAFE, 173 EXPECT_EQ(SB_THREAT_TYPE_SAFE,
174 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( 174 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType(
175 kSafeHostHash, full_hashes)); 175 kSafeHostHash, full_hashes));
176 176
177 const size_t kArbitraryValue = 123456U; 177 const size_t kArbitraryValue = 123456U;
178 size_t index = kArbitraryValue; 178 size_t index = kArbitraryValue;
179 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 179 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
180 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 180 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
181 kMalwareUrl, full_hashes, &index)); 181 kMalwareUrl, full_hashes, &index));
182 EXPECT_EQ(0U, index); 182 EXPECT_EQ(0U, index);
183 183
184 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, 184 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING,
185 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 185 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
186 kPhishingUrl, full_hashes, &index)); 186 kPhishingUrl, full_hashes, &index));
187 EXPECT_EQ(1U, index); 187 EXPECT_EQ(1U, index);
188 188
189 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, 189 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED,
190 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 190 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
191 kUnwantedUrl, full_hashes, &index)); 191 kUnwantedUrl, full_hashes, &index));
192 EXPECT_EQ(2U, index); 192 EXPECT_EQ(2U, index);
193 193
194 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, 194 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
195 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 195 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
196 kUnwantedAndMalwareUrl, full_hashes, &index)); 196 kUnwantedAndMalwareUrl, full_hashes, &index));
197 EXPECT_EQ(3U, index); 197 EXPECT_EQ(3U, index);
198 198
199 index = kArbitraryValue; 199 index = kArbitraryValue;
200 EXPECT_EQ(SB_THREAT_TYPE_SAFE, 200 EXPECT_EQ(SB_THREAT_TYPE_SAFE,
201 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( 201 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType(
202 kSafeUrl, full_hashes, &index)); 202 kSafeUrl, full_hashes, &index));
203 EXPECT_EQ(kArbitraryValue, index); 203 EXPECT_EQ(kArbitraryValue, index);
204 } 204 }
205 205
206 TEST_F(SafeBrowsingDatabaseManagerTest, ServiceStopWithPendingChecks) { 206 TEST_F(SafeBrowsingDatabaseManagerTest, ServiceStopWithPendingChecks) {
207 scoped_refptr<SafeBrowsingService> sb_service( 207 scoped_refptr<SafeBrowsingService> sb_service(
208 SafeBrowsingService::CreateSafeBrowsingService()); 208 SafeBrowsingService::CreateSafeBrowsingService());
209 scoped_refptr<SafeBrowsingDatabaseManager> db_manager( 209 scoped_refptr<LocalSafeBrowsingDatabaseManager> db_manager(
210 new SafeBrowsingDatabaseManager(sb_service)); 210 new LocalSafeBrowsingDatabaseManager(sb_service));
211 TestClient client; 211 TestClient client;
212 212
213 // Start the service and flush tasks to ensure database is made available. 213 // Start the service and flush tasks to ensure database is made available.
214 db_manager->StartOnIOThread(); 214 db_manager->StartOnIOThread();
215 content::RunAllBlockingPoolTasksUntilIdle(); 215 content::RunAllBlockingPoolTasksUntilIdle();
216 base::RunLoop().RunUntilIdle(); 216 base::RunLoop().RunUntilIdle();
217 EXPECT_TRUE(db_manager->DatabaseAvailable()); 217 EXPECT_TRUE(db_manager->DatabaseAvailable());
218 218
219 // Start an extension check operation, which is done asynchronously. 219 // Start an extension check operation, which is done asynchronously.
220 std::set<std::string> extension_ids; 220 std::set<std::string> extension_ids;
221 extension_ids.insert("testtesttesttesttesttesttesttest"); 221 extension_ids.insert("testtesttesttesttesttesttesttest");
222 db_manager->CheckExtensionIDs(extension_ids, &client); 222 db_manager->CheckExtensionIDs(extension_ids, &client);
223 223
224 // Stop the service without first flushing above tasks. 224 // Stop the service without first flushing above tasks.
225 db_manager->StopOnIOThread(false); 225 db_manager->StopOnIOThread(false);
226 226
227 // Now run posted tasks, whish should include the extension check which has 227 // Now run posted tasks, whish should include the extension check which has
228 // been posted to the safe browsing task runner. This should not crash. 228 // been posted to the safe browsing task runner. This should not crash.
229 content::RunAllBlockingPoolTasksUntilIdle(); 229 content::RunAllBlockingPoolTasksUntilIdle();
230 base::RunLoop().RunUntilIdle(); 230 base::RunLoop().RunUntilIdle();
231 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698