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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc

Issue 4822002: Send malware reports when a user opts-in from the safe browsing interstitial ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc
===================================================================
--- chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc (revision 68800)
+++ chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc (working copy)
@@ -9,13 +9,17 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
+#include "chrome/browser/safe_browsing/malware_details.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
@@ -52,6 +56,26 @@
badurls[url.spec()] = checkresult;
}
+ virtual void ReportMalwareDetails(scoped_refptr<MalwareDetails> details) {
+ details_.push_back(details);
+ // Notify the UI thread, that we got a report.
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this,
+ &FakeSafeBrowsingService::OnMalwareDetailsDone));
+ }
+
+ void OnMalwareDetailsDone() {
+ EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ MessageLoopForUI::current()->Quit();
+ }
+
+ std::list<scoped_refptr<MalwareDetails> >* GetDetails() {
+ return &details_;
+ }
+
+ std::list<scoped_refptr<MalwareDetails> > details_;
+
+
private:
base::hash_map<std::string, UrlCheckResult> badurls;
};
@@ -102,7 +126,7 @@
g_browser_process->resource_dispatcher_host()->
safe_browsing_service());
- ASSERT_TRUE(service != NULL);
+ ASSERT_TRUE(service);
service->AddURLResult(url, checkresult);
}
@@ -141,6 +165,17 @@
ui_test_utils::WaitForNavigation(controller);
}
+ void AssertReportSent() {
+ // When a report is scheduled in the IO thread we should get notified.
+ ui_test_utils::RunMessageLoop();
+
+ FakeSafeBrowsingService* service =
+ static_cast<FakeSafeBrowsingService*>(
+ g_browser_process->resource_dispatcher_host()->
+ safe_browsing_service());
+ ASSERT_EQ(1u, service->GetDetails()->size());
+ }
+
private:
TestSafeBrowsingServiceFactory factory;
@@ -258,4 +293,25 @@
EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL());
}
+IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
+ MalwareIframeReportDetails) {
+ // Enable reporting of malware details.
+ browser()->GetProfile()->GetPrefs()->SetBoolean(
+ prefs::kSafeBrowsingReportingEnabled, true);
+ EXPECT_TRUE(browser()->GetProfile()->GetPrefs()->GetBoolean(
+ prefs::kSafeBrowsingReportingEnabled));
+
+ GURL url = test_server()->GetURL(kMalwarePage);
+ GURL iframe_url = test_server()->GetURL(kMalwareIframe);
+ AddURLResult(iframe_url, SafeBrowsingService::URL_MALWARE);
+
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ SendCommand("\"proceed\""); // Simulate the user clicking "back"
+ AssertNoInterstitial(); // Assert the interstitial is gone
+
+ EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL());
+ AssertReportSent();
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698