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

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

Issue 2240083004: Remove stl_util's STLDeleteContainerPairPointers. (Closed) 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 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <queue> 11 #include <queue>
12 #include <string> 12 #include <string>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h"
18 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
19 #include "base/metrics/field_trial.h" 20 #include "base/metrics/field_trial.h"
20 #include "base/run_loop.h" 21 #include "base/run_loop.h"
21 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
22 #include "base/time/time.h" 23 #include "base/time/time.h"
23 #include "chrome/common/safe_browsing/client_model.pb.h" 24 #include "chrome/common/safe_browsing/client_model.pb.h"
24 #include "chrome/common/safe_browsing/csd.pb.h" 25 #include "chrome/common/safe_browsing/csd.pb.h"
25 #include "components/variations/variations_associated_data.h" 26 #include "components/variations/variations_associated_data.h"
26 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
27 #include "crypto/sha2.h" 28 #include "crypto/sha2.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 148
148 std::queue<base::Time>& GetPhishingReportTimes() { 149 std::queue<base::Time>& GetPhishingReportTimes() {
149 return csd_service_->phishing_report_times_; 150 return csd_service_->phishing_report_times_;
150 } 151 }
151 152
152 std::queue<base::Time>& GetMalwareReportTimes() { 153 std::queue<base::Time>& GetMalwareReportTimes() {
153 return csd_service_->malware_report_times_; 154 return csd_service_->malware_report_times_;
154 } 155 }
155 156
156 void SetCache(const GURL& gurl, bool is_phishing, base::Time time) { 157 void SetCache(const GURL& gurl, bool is_phishing, base::Time time) {
157 csd_service_->cache_[gurl] = 158 csd_service_->cache_[gurl] = base::WrapUnique(
mattm 2016/08/16 20:41:22 Use MakeUnique instead of WrapUnique? (see chromiu
Avi (use Gerrit) 2016/08/17 18:25:37 Sometimes MakeUnique works, sometimes it fails for
mattm 2016/08/17 21:28:34 nit: Could you update the other ones in here too?
Avi (use Gerrit) 2016/08/17 21:34:55 Done.
158 make_linked_ptr(new ClientSideDetectionService::CacheState(is_phishing, 159 new ClientSideDetectionService::CacheState(is_phishing, time));
159 time));
160 } 160 }
161 161
162 void TestCache() { 162 void TestCache() {
163 ClientSideDetectionService::PhishingCache& cache = csd_service_->cache_; 163 auto& cache = csd_service_->cache_;
164 base::Time now = base::Time::Now(); 164 base::Time now = base::Time::Now();
165 base::Time time = 165 base::Time time =
166 now - base::TimeDelta::FromDays( 166 now - base::TimeDelta::FromDays(
167 ClientSideDetectionService::kNegativeCacheIntervalDays) + 167 ClientSideDetectionService::kNegativeCacheIntervalDays) +
168 base::TimeDelta::FromMinutes(5); 168 base::TimeDelta::FromMinutes(5);
169 cache[GURL("http://first.url.com/")] = 169 cache[GURL("http://first.url.com/")] = base::WrapUnique(
170 make_linked_ptr(new ClientSideDetectionService::CacheState(false, 170 new ClientSideDetectionService::CacheState(false, time));
171 time));
172 171
173 time = 172 time =
174 now - base::TimeDelta::FromDays( 173 now - base::TimeDelta::FromDays(
175 ClientSideDetectionService::kNegativeCacheIntervalDays) - 174 ClientSideDetectionService::kNegativeCacheIntervalDays) -
176 base::TimeDelta::FromHours(1); 175 base::TimeDelta::FromHours(1);
177 cache[GURL("http://second.url.com/")] = 176 cache[GURL("http://second.url.com/")] = base::WrapUnique(
178 make_linked_ptr(new ClientSideDetectionService::CacheState(false, 177 new ClientSideDetectionService::CacheState(false, time));
179 time));
180 178
181 time = 179 time =
182 now - base::TimeDelta::FromMinutes( 180 now - base::TimeDelta::FromMinutes(
183 ClientSideDetectionService::kPositiveCacheIntervalMinutes) - 181 ClientSideDetectionService::kPositiveCacheIntervalMinutes) -
184 base::TimeDelta::FromMinutes(5); 182 base::TimeDelta::FromMinutes(5);
185 cache[GURL("http://third.url.com/")] = 183 cache[GURL("http://third.url.com/")] = base::WrapUnique(
186 make_linked_ptr(new ClientSideDetectionService::CacheState(true, time)); 184 new ClientSideDetectionService::CacheState(true, time));
187 185
188 time = 186 time =
189 now - base::TimeDelta::FromMinutes( 187 now - base::TimeDelta::FromMinutes(
190 ClientSideDetectionService::kPositiveCacheIntervalMinutes) + 188 ClientSideDetectionService::kPositiveCacheIntervalMinutes) +
191 base::TimeDelta::FromMinutes(5); 189 base::TimeDelta::FromMinutes(5);
192 cache[GURL("http://fourth.url.com/")] = 190 cache[GURL("http://fourth.url.com/")] = base::WrapUnique(
193 make_linked_ptr(new ClientSideDetectionService::CacheState(true, time)); 191 new ClientSideDetectionService::CacheState(true, time));
194 192
195 csd_service_->UpdateCache(); 193 csd_service_->UpdateCache();
196 194
197 // 3 elements should be in the cache, the first, third, and fourth. 195 // 3 elements should be in the cache, the first, third, and fourth.
198 EXPECT_EQ(3U, cache.size()); 196 EXPECT_EQ(3U, cache.size());
199 EXPECT_TRUE(cache.find(GURL("http://first.url.com/")) != cache.end()); 197 EXPECT_TRUE(cache.find(GURL("http://first.url.com/")) != cache.end());
200 EXPECT_TRUE(cache.find(GURL("http://third.url.com/")) != cache.end()); 198 EXPECT_TRUE(cache.find(GURL("http://third.url.com/")) != cache.end());
201 EXPECT_TRUE(cache.find(GURL("http://fourth.url.com/")) != cache.end()); 199 EXPECT_TRUE(cache.find(GURL("http://fourth.url.com/")) != cache.end());
202 200
203 // While 3 elements remain, only the first and the fourth are actually 201 // While 3 elements remain, only the first and the fourth are actually
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 480
483 // Check that disabling again doesn't request the model. 481 // Check that disabling again doesn't request the model.
484 csd_service_->SetEnabledAndRefreshState(false); 482 csd_service_->SetEnabledAndRefreshState(false);
485 // No calls expected. 483 // No calls expected.
486 base::RunLoop().RunUntilIdle(); 484 base::RunLoop().RunUntilIdle();
487 Mock::VerifyAndClearExpectations(service); 485 Mock::VerifyAndClearExpectations(service);
488 Mock::VerifyAndClearExpectations(loader_1); 486 Mock::VerifyAndClearExpectations(loader_1);
489 Mock::VerifyAndClearExpectations(loader_2); 487 Mock::VerifyAndClearExpectations(loader_2);
490 } 488 }
491 } // namespace safe_browsing 489 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698