Index: chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc |
diff --git a/chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc b/chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc |
index ccea446063de1404012c1a23a46b33474a8feda5..9d257b26d0def84431b679288b38dfc975873d34 100644 |
--- a/chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc |
+++ b/chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc |
@@ -61,10 +61,11 @@ KeyedService* BuildHistoryService(content::BrowserContext* context) { |
} // namespace |
+namespace safe_browsing { |
+ |
class LastDownloadFinderTest : public testing::Test { |
public: |
- void NeverCalled(scoped_ptr< |
- safe_browsing::ClientIncidentReport_DownloadDetails> download) { |
+ void NeverCalled(scoped_ptr<ClientIncidentReport_DownloadDetails> download) { |
FAIL(); |
} |
@@ -80,13 +81,12 @@ class LastDownloadFinderTest : public testing::Test { |
base::Unretained(this))); |
} |
- // safe_browsing::LastDownloadFinder::LastDownloadCallback implementation that |
+ // LastDownloadFinder::LastDownloadCallback implementation that |
// passes the found download to |result| and then runs a closure. |
void OnLastDownload( |
- scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails>* result, |
+ scoped_ptr<ClientIncidentReport_DownloadDetails>* result, |
const base::Closure& quit_closure, |
- scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> |
- download) { |
+ scoped_ptr<ClientIncidentReport_DownloadDetails> download) { |
*result = download.Pass(); |
quit_closure.Run(); |
} |
@@ -153,6 +153,11 @@ class LastDownloadFinderTest : public testing::Test { |
return profile; |
} |
+ LastDownloadFinder::DownloadDetailsGetter GetDownloadDetailsGetter() { |
+ return base::Bind(&LastDownloadFinderTest::GetDownloadDetails, |
+ base::Unretained(this)); |
+ } |
+ |
void AddDownload(Profile* profile, const history::DownloadRow& download) { |
base::RunLoop run_loop; |
@@ -186,19 +191,17 @@ class LastDownloadFinderTest : public testing::Test { |
// Runs the last download finder on all loaded profiles, returning the found |
// download or an empty pointer if none was found. |
- scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> |
- RunLastDownloadFinder() { |
+ scoped_ptr<ClientIncidentReport_DownloadDetails> RunLastDownloadFinder() { |
base::RunLoop run_loop; |
- scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> |
- last_download; |
+ scoped_ptr<ClientIncidentReport_DownloadDetails> last_download; |
- scoped_ptr<safe_browsing::LastDownloadFinder> finder( |
- safe_browsing::LastDownloadFinder::Create( |
- base::Bind(&LastDownloadFinderTest::OnLastDownload, |
- base::Unretained(this), |
- &last_download, |
- run_loop.QuitClosure()))); |
+ scoped_ptr<LastDownloadFinder> finder(LastDownloadFinder::Create( |
+ GetDownloadDetailsGetter(), |
+ base::Bind(&LastDownloadFinderTest::OnLastDownload, |
+ base::Unretained(this), |
+ &last_download, |
+ run_loop.QuitClosure()))); |
if (finder) |
run_loop.Run(); |
@@ -230,13 +233,13 @@ class LastDownloadFinderTest : public testing::Test { |
std::string()); // ext_name |
} |
- void ExpectNoDownloadFound(scoped_ptr< |
- safe_browsing::ClientIncidentReport_DownloadDetails> download) { |
+ void ExpectNoDownloadFound( |
+ scoped_ptr<ClientIncidentReport_DownloadDetails> download) { |
EXPECT_FALSE(download); |
} |
- void ExpectFoundTestDownload(scoped_ptr< |
- safe_browsing::ClientIncidentReport_DownloadDetails> download) { |
+ void ExpectFoundTestDownload( |
+ scoped_ptr<ClientIncidentReport_DownloadDetails> download) { |
ASSERT_TRUE(download); |
} |
@@ -255,6 +258,12 @@ class LastDownloadFinderTest : public testing::Test { |
// created. |
void OnDownloadCreated(bool created) { ASSERT_TRUE(created); } |
+ void GetDownloadDetails( |
+ content::BrowserContext* context, |
+ const DownloadMetadataManager::GetDownloadDetailsCallback& callback) { |
+ callback.Run(scoped_ptr<ClientIncidentReport_DownloadDetails>()); |
+ } |
+ |
int profile_number_; |
}; |
@@ -295,9 +304,9 @@ TEST_F(LastDownloadFinderTest, DeleteBeforeResults) { |
AddDownload(profile, CreateTestDownloadRow()); |
// Start a finder and kill it before the search completes. |
- safe_browsing::LastDownloadFinder::Create( |
- base::Bind(&LastDownloadFinderTest::NeverCalled, base::Unretained(this))) |
- .reset(); |
+ LastDownloadFinder::Create(GetDownloadDetailsGetter(), |
+ base::Bind(&LastDownloadFinderTest::NeverCalled, |
+ base::Unretained(this))).reset(); |
// Flush tasks on the history backend thread. |
FlushHistoryBackend(profile); |
@@ -308,7 +317,7 @@ TEST_F(LastDownloadFinderTest, AddProfileAfterStarting) { |
// Create a profile with a history service that is opted-in. |
CreateProfile(SAFE_BROWSING_OPT_IN); |
- scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> last_download; |
+ scoped_ptr<ClientIncidentReport_DownloadDetails> last_download; |
base::RunLoop run_loop; |
// Post a task that will create a second profile once the main loop is run. |
@@ -318,14 +327,16 @@ TEST_F(LastDownloadFinderTest, AddProfileAfterStarting) { |
base::Unretained(this))); |
// Create a finder that we expect will find a download in the second profile. |
- scoped_ptr<safe_browsing::LastDownloadFinder> finder( |
- safe_browsing::LastDownloadFinder::Create( |
- base::Bind(&LastDownloadFinderTest::OnLastDownload, |
- base::Unretained(this), |
- &last_download, |
- run_loop.QuitClosure()))); |
+ scoped_ptr<LastDownloadFinder> finder(LastDownloadFinder::Create( |
+ GetDownloadDetailsGetter(), |
+ base::Bind(&LastDownloadFinderTest::OnLastDownload, |
+ base::Unretained(this), |
+ &last_download, |
+ run_loop.QuitClosure()))); |
run_loop.Run(); |
ExpectFoundTestDownload(last_download.Pass()); |
} |
+ |
+} // namespace safe_browsing |