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

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

Issue 1414343007: Collect threat details for phishing and UwS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 1 month 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 // This test creates a fake safebrowsing service, where we can inject known- 5 // This test creates a fake safebrowsing service, where we can inject known-
6 // threat urls. It then uses a real browser to go to these urls, and sends 6 // threat urls. It then uses a real browser to go to these urls, and sends
7 // "goback" or "proceed" commands and verifies they work. 7 // "goback" or "proceed" commands and verifies they work.
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 public: 237 public:
238 FakeThreatDetails( 238 FakeThreatDetails(
239 SafeBrowsingUIManager* delegate, 239 SafeBrowsingUIManager* delegate,
240 WebContents* web_contents, 240 WebContents* web_contents,
241 const SafeBrowsingUIManager::UnsafeResource& unsafe_resource) 241 const SafeBrowsingUIManager::UnsafeResource& unsafe_resource)
242 : ThreatDetails(delegate, web_contents, unsafe_resource), 242 : ThreatDetails(delegate, web_contents, unsafe_resource),
243 got_dom_(false), 243 got_dom_(false),
244 waiting_(false) {} 244 waiting_(false) {}
245 245
246 void AddDOMDetails( 246 void AddDOMDetails(
247 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params) 247 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params)
248 override { 248 override {
249 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 249 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
250 ThreatDetails::AddDOMDetails(params); 250 ThreatDetails::AddDOMDetails(params);
251 251
252 // Notify the UI thread that we got the dom details. 252 // Notify the UI thread that we got the dom details.
253 BrowserThread::PostTask( 253 BrowserThread::PostTask(
254 BrowserThread::UI, FROM_HERE, 254 BrowserThread::UI, FROM_HERE,
255 base::Bind(&FakeThreatDetails::OnDOMDetailsDone, this)); 255 base::Bind(&FakeThreatDetails::OnDOMDetailsDone, this));
256 } 256 }
257 257
258 void WaitForDOM() { 258 void WaitForDOM() {
259 if (got_dom_) { 259 if (got_dom_) {
260 return; 260 return;
261 } 261 }
262 // This condition might not trigger normally, but if you add a 262 // This condition might not trigger normally, but if you add a
263 // sleep(1) in malware_dom_details it triggers :). 263 // sleep(1) in threat_dom_details it triggers :).
264 waiting_ = true; 264 waiting_ = true;
265 content::RunMessageLoop(); 265 content::RunMessageLoop();
266 EXPECT_TRUE(got_dom_); 266 EXPECT_TRUE(got_dom_);
267 } 267 }
268 268
269 private: 269 private:
270 ~FakeThreatDetails() override {} 270 ~FakeThreatDetails() override {}
271 271
272 void OnDOMDetailsDone() { 272 void OnDOMDetailsDone() {
273 got_dom_ = true; 273 got_dom_ = true;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 public: 343 public:
344 TestSafeBrowsingBlockingPageFactory() { } 344 TestSafeBrowsingBlockingPageFactory() { }
345 ~TestSafeBrowsingBlockingPageFactory() override {} 345 ~TestSafeBrowsingBlockingPageFactory() override {}
346 346
347 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( 347 SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
348 SafeBrowsingUIManager* delegate, 348 SafeBrowsingUIManager* delegate,
349 WebContents* web_contents, 349 WebContents* web_contents,
350 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) 350 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources)
351 override { 351 override {
352 return new TestSafeBrowsingBlockingPage(delegate, web_contents, 352 return new TestSafeBrowsingBlockingPage(delegate, web_contents,
353 unsafe_resources); 353 unsafe_resources);
354 } 354 }
355 }; 355 };
356 356
357 } // namespace 357 } // namespace
358 358
359 // Tests the safe browsing blocking page in a browser. 359 // Tests the safe browsing blocking page in a browser.
360 class SafeBrowsingBlockingPageBrowserTest 360 class SafeBrowsingBlockingPageBrowserTest
361 : public InProcessBrowserTest, 361 : public InProcessBrowserTest,
362 public testing::WithParamInterface<SBThreatType> { 362 public testing::WithParamInterface<SBThreatType> {
363 public: 363 public:
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 GURL url = SetupThreatIframeWarningAndNavigate(); 703 GURL url = SetupThreatIframeWarningAndNavigate();
704 704
705 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 705 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
706 AssertNoInterstitial(true); // Assert the interstitial is gone 706 AssertNoInterstitial(true); // Assert the interstitial is gone
707 707
708 EXPECT_EQ(url, 708 EXPECT_EQ(url,
709 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 709 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
710 } 710 }
711 711
712 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 712 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
713 IframeOptInAndReportMalwareDetails) { 713 IframeOptInAndReportThreatDetails) {
714 // The extended reporting opt-in is presented in the interstitial for malware, 714 // The extended reporting opt-in is presented in the interstitial for malware,
715 // phishing, and UwS threats. It however only results in uploading further 715 // phishing, and UwS threats. This test uses malware as an example to verify
716 // details about the immediate threat when facing malware threats. 716 // this reporting functionality.
717 const bool expect_malware_details = GetParam() == SB_THREAT_TYPE_URL_MALWARE; 717 const bool expect_threat_details =
718 SafeBrowsingBlockingPage::ShouldReportThreatDetails(GetParam());
718 719
719 scoped_refptr<content::MessageLoopRunner> malware_report_sent_runner( 720 scoped_refptr<content::MessageLoopRunner> threat_report_sent_runner(
720 new content::MessageLoopRunner); 721 new content::MessageLoopRunner);
721 if (expect_malware_details) 722 if (expect_threat_details)
722 SetReportSentCallback(malware_report_sent_runner->QuitClosure()); 723 SetReportSentCallback(threat_report_sent_runner->QuitClosure());
723 724
724 GURL url = SetupThreatIframeWarningAndNavigate(); 725 GURL url = SetupThreatIframeWarningAndNavigate();
725 726
726 FakeThreatDetails* fake_malware_details = details_factory_.get_details(); 727 FakeThreatDetails* fake_threat_details = details_factory_.get_details();
727 EXPECT_EQ(expect_malware_details, fake_malware_details != nullptr); 728 EXPECT_EQ(expect_threat_details, fake_threat_details != nullptr);
728 729
729 // If the DOM details from renderer did not already return when they are 730 // If the DOM details from renderer did not already return when they are
730 // expected, wait for them. 731 // expected, wait for them.
731 if (expect_malware_details) 732 if (expect_threat_details)
732 fake_malware_details->WaitForDOM(); 733 fake_threat_details->WaitForDOM();
733 734
734 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in")); 735 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in"));
735 EXPECT_TRUE(Click("opt-in-checkbox")); 736 EXPECT_TRUE(Click("opt-in-checkbox"));
736 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 737 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
737 AssertNoInterstitial(true); // Assert the interstitial is gone 738 AssertNoInterstitial(true); // Assert the interstitial is gone
738 739
739 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 740 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
740 prefs::kSafeBrowsingExtendedReportingEnabled)); 741 prefs::kSafeBrowsingExtendedReportingEnabled));
741 EXPECT_EQ(url, 742 EXPECT_EQ(url,
742 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 743 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
743 744
744 if (expect_malware_details) { 745 if (expect_threat_details) {
745 malware_report_sent_runner->Run(); 746 threat_report_sent_runner->Run();
746 std::string serialized = GetReportSent(); 747 std::string serialized = GetReportSent();
747 safe_browsing::ClientMalwareReportRequest report; 748 safe_browsing::ClientSafeBrowsingReportRequest report;
748 ASSERT_TRUE(report.ParseFromString(serialized)); 749 ASSERT_TRUE(report.ParseFromString(serialized));
749 // Verify the report is complete. 750 // Verify the report is complete.
750 EXPECT_TRUE(report.complete()); 751 EXPECT_TRUE(report.complete());
751 } 752 }
752 } 753 }
753 754
754 // Verifies that the "proceed anyway" link isn't available when it is disabled 755 // Verifies that the "proceed anyway" link isn't available when it is disabled
755 // by the corresponding policy. Also verifies that sending the "proceed" 756 // by the corresponding policy. Also verifies that sending the "proceed"
756 // command anyway doesn't advance to the unsafe site. 757 // command anyway doesn't advance to the unsafe site.
757 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ProceedDisabled) { 758 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ProceedDisabled) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageIDNTest, 1017 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageIDNTest,
1017 SafeBrowsingBlockingPageDecodesIDN) { 1018 SafeBrowsingBlockingPageDecodesIDN) {
1018 EXPECT_TRUE(VerifyIDNDecoded()); 1019 EXPECT_TRUE(VerifyIDNDecoded());
1019 } 1020 }
1020 1021
1021 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageIDNTestWithThreatType, 1022 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageIDNTestWithThreatType,
1022 SafeBrowsingBlockingPageIDNTest, 1023 SafeBrowsingBlockingPageIDNTest,
1023 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 1024 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
1024 SB_THREAT_TYPE_URL_PHISHING, 1025 SB_THREAT_TYPE_URL_PHISHING,
1025 SB_THREAT_TYPE_URL_UNWANTED)); 1026 SB_THREAT_TYPE_URL_UNWANTED));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698