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

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc

Issue 663023007: Include high-fidelity metadata about a download in incident reports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: sync to r301101 Created 6 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/incident_reporting/last_download_finder.h " 5 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h "
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 profile_name, 146 profile_name,
147 prefs.Pass(), 147 prefs.Pass(),
148 base::UTF8ToUTF16(profile_name), // user_name 148 base::UTF8ToUTF16(profile_name), // user_name
149 0, // avatar_id 149 0, // avatar_id
150 std::string(), // supervised_user_id 150 std::string(), // supervised_user_id
151 factories); 151 factories);
152 152
153 return profile; 153 return profile;
154 } 154 }
155 155
156 safe_browsing::LastDownloadFinder::DownloadDetailsGetter
Alexei Svitkine (slow) 2014/10/27 17:09:07 Make the code in this file be in safe_browsing nam
grt (UTC plus 2) 2014/10/30 15:11:40 Done.
157 GetDownloadDetailsGetter() {
158 return base::Bind(&LastDownloadFinderTest::GetDownloadDetails,
159 base::Unretained(this));
160 }
161
156 void AddDownload(Profile* profile, const history::DownloadRow& download) { 162 void AddDownload(Profile* profile, const history::DownloadRow& download) {
157 base::RunLoop run_loop; 163 base::RunLoop run_loop;
158 164
159 HistoryService* history_service = 165 HistoryService* history_service =
160 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); 166 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);
161 history_service->CreateDownload( 167 history_service->CreateDownload(
162 download, 168 download,
163 base::Bind(&LastDownloadFinderTest::ContinueOnDownloadCreated, 169 base::Bind(&LastDownloadFinderTest::ContinueOnDownloadCreated,
164 base::Unretained(this), 170 base::Unretained(this),
165 run_loop.QuitClosure())); 171 run_loop.QuitClosure()));
(...skipping 22 matching lines...) Expand all
188 // download or an empty pointer if none was found. 194 // download or an empty pointer if none was found.
189 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> 195 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails>
190 RunLastDownloadFinder() { 196 RunLastDownloadFinder() {
191 base::RunLoop run_loop; 197 base::RunLoop run_loop;
192 198
193 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> 199 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails>
194 last_download; 200 last_download;
195 201
196 scoped_ptr<safe_browsing::LastDownloadFinder> finder( 202 scoped_ptr<safe_browsing::LastDownloadFinder> finder(
197 safe_browsing::LastDownloadFinder::Create( 203 safe_browsing::LastDownloadFinder::Create(
204 GetDownloadDetailsGetter(),
198 base::Bind(&LastDownloadFinderTest::OnLastDownload, 205 base::Bind(&LastDownloadFinderTest::OnLastDownload,
199 base::Unretained(this), 206 base::Unretained(this),
200 &last_download, 207 &last_download,
201 run_loop.QuitClosure()))); 208 run_loop.QuitClosure())));
202 209
203 if (finder) 210 if (finder)
204 run_loop.Run(); 211 run_loop.Run();
205 212
206 return last_download.Pass(); 213 return last_download.Pass();
207 } 214 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // created and runs |closure|. 255 // created and runs |closure|.
249 void ContinueOnDownloadCreated(const base::Closure& closure, bool created) { 256 void ContinueOnDownloadCreated(const base::Closure& closure, bool created) {
250 ASSERT_TRUE(created); 257 ASSERT_TRUE(created);
251 closure.Run(); 258 closure.Run();
252 } 259 }
253 260
254 // A HistoryService::DownloadCreateCallback that asserts that the download was 261 // A HistoryService::DownloadCreateCallback that asserts that the download was
255 // created. 262 // created.
256 void OnDownloadCreated(bool created) { ASSERT_TRUE(created); } 263 void OnDownloadCreated(bool created) { ASSERT_TRUE(created); }
257 264
265 void GetDownloadDetails(
266 content::BrowserContext* context,
267 const safe_browsing::DownloadMetadataManager::GetDownloadDetailsCallback&
268 callback) {
269 callback.Run(
270 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails>());
271 }
272
258 int profile_number_; 273 int profile_number_;
259 }; 274 };
260 275
261 // Tests that nothing happens if there are no profiles at all. 276 // Tests that nothing happens if there are no profiles at all.
262 TEST_F(LastDownloadFinderTest, NoProfiles) { 277 TEST_F(LastDownloadFinderTest, NoProfiles) {
263 ExpectNoDownloadFound(RunLastDownloadFinder()); 278 ExpectNoDownloadFound(RunLastDownloadFinder());
264 } 279 }
265 280
266 // Tests that nothing happens other than the callback being invoked if there are 281 // Tests that nothing happens other than the callback being invoked if there are
267 // no profiles participating in safe browsing. 282 // no profiles participating in safe browsing.
(...skipping 21 matching lines...) Expand all
289 // Tests that there is no crash if the finder is deleted before results arrive. 304 // Tests that there is no crash if the finder is deleted before results arrive.
290 TEST_F(LastDownloadFinderTest, DeleteBeforeResults) { 305 TEST_F(LastDownloadFinderTest, DeleteBeforeResults) {
291 // Create a profile with a history service that is opted-in. 306 // Create a profile with a history service that is opted-in.
292 TestingProfile* profile = CreateProfile(SAFE_BROWSING_OPT_IN); 307 TestingProfile* profile = CreateProfile(SAFE_BROWSING_OPT_IN);
293 308
294 // Add a download. 309 // Add a download.
295 AddDownload(profile, CreateTestDownloadRow()); 310 AddDownload(profile, CreateTestDownloadRow());
296 311
297 // Start a finder and kill it before the search completes. 312 // Start a finder and kill it before the search completes.
298 safe_browsing::LastDownloadFinder::Create( 313 safe_browsing::LastDownloadFinder::Create(
314 GetDownloadDetailsGetter(),
299 base::Bind(&LastDownloadFinderTest::NeverCalled, base::Unretained(this))) 315 base::Bind(&LastDownloadFinderTest::NeverCalled, base::Unretained(this)))
300 .reset(); 316 .reset();
301 317
302 // Flush tasks on the history backend thread. 318 // Flush tasks on the history backend thread.
303 FlushHistoryBackend(profile); 319 FlushHistoryBackend(profile);
304 } 320 }
305 321
306 // Tests that a download in profile added after the search is begun is found. 322 // Tests that a download in profile added after the search is begun is found.
307 TEST_F(LastDownloadFinderTest, AddProfileAfterStarting) { 323 TEST_F(LastDownloadFinderTest, AddProfileAfterStarting) {
308 // Create a profile with a history service that is opted-in. 324 // Create a profile with a history service that is opted-in.
309 CreateProfile(SAFE_BROWSING_OPT_IN); 325 CreateProfile(SAFE_BROWSING_OPT_IN);
310 326
311 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> last_download; 327 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> last_download;
312 base::RunLoop run_loop; 328 base::RunLoop run_loop;
313 329
314 // Post a task that will create a second profile once the main loop is run. 330 // Post a task that will create a second profile once the main loop is run.
315 base::MessageLoop::current()->PostTask( 331 base::MessageLoop::current()->PostTask(
316 FROM_HERE, 332 FROM_HERE,
317 base::Bind(&LastDownloadFinderTest::CreateProfileWithDownload, 333 base::Bind(&LastDownloadFinderTest::CreateProfileWithDownload,
318 base::Unretained(this))); 334 base::Unretained(this)));
319 335
320 // Create a finder that we expect will find a download in the second profile. 336 // Create a finder that we expect will find a download in the second profile.
321 scoped_ptr<safe_browsing::LastDownloadFinder> finder( 337 scoped_ptr<safe_browsing::LastDownloadFinder> finder(
322 safe_browsing::LastDownloadFinder::Create( 338 safe_browsing::LastDownloadFinder::Create(
339 GetDownloadDetailsGetter(),
323 base::Bind(&LastDownloadFinderTest::OnLastDownload, 340 base::Bind(&LastDownloadFinderTest::OnLastDownload,
324 base::Unretained(this), 341 base::Unretained(this),
325 &last_download, 342 &last_download,
326 run_loop.QuitClosure()))); 343 run_loop.QuitClosure())));
327 344
328 run_loop.Run(); 345 run_loop.Run();
329 346
330 ExpectFoundTestDownload(last_download.Pass()); 347 ExpectFoundTestDownload(last_download.Pass());
331 } 348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698