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

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

Issue 2886043002: Refrain from sending hit report when user is in incognito mode (Closed)
Patch Set: ready for review Created 3 years, 7 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 // 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 <algorithm> 9 #include <algorithm>
10 10
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 report_ = serialized; 181 report_ = serialized;
182 182
183 EXPECT_FALSE(threat_details_done_callback_.is_null()); 183 EXPECT_FALSE(threat_details_done_callback_.is_null());
184 if (!threat_details_done_callback_.is_null()) { 184 if (!threat_details_done_callback_.is_null()) {
185 threat_details_done_callback_.Run(); 185 threat_details_done_callback_.Run();
186 threat_details_done_callback_ = base::Closure(); 186 threat_details_done_callback_ = base::Closure();
187 } 187 }
188 threat_details_done_ = true; 188 threat_details_done_ = true;
189 } 189 }
190 190
191 void MaybeReportSafeBrowsingHit(const HitReport& hit_report,
192 WebContents* web_contents) override {
193 if (SafeBrowsingUIManager::ShouldSendHitReport(hit_report, web_contents)) {
194 hit_report_sent_ = true;
195 }
196 }
197
198 bool hit_report_sent() { return hit_report_sent_; }
199
191 void set_threat_details_done_callback(const base::Closure& callback) { 200 void set_threat_details_done_callback(const base::Closure& callback) {
192 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
193 EXPECT_TRUE(threat_details_done_callback_.is_null()); 202 EXPECT_TRUE(threat_details_done_callback_.is_null());
194 threat_details_done_callback_ = callback; 203 threat_details_done_callback_ = callback;
195 } 204 }
196 205
197 std::string GetReport() { 206 std::string GetReport() {
198 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 207 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
199 return report_; 208 return report_;
200 } 209 }
201 210
202 protected: 211 protected:
203 ~FakeSafeBrowsingUIManager() override {} 212 ~FakeSafeBrowsingUIManager() override {}
204 213
205 private: 214 private:
206 std::string report_; 215 std::string report_;
207 base::Closure threat_details_done_callback_; 216 base::Closure threat_details_done_callback_;
208 bool threat_details_done_; 217 bool threat_details_done_;
218 bool hit_report_sent_ = false;
Jialiu Lin 2017/05/18 22:32:12 nit: since all the other members are initialized i
mortonm 2017/05/19 20:21:03 Done.
209 219
210 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingUIManager); 220 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingUIManager);
211 }; 221 };
212 222
213 } // namespace 223 } // namespace
214 224
215 class TestThreatDetailsFactory : public ThreatDetailsFactory { 225 class TestThreatDetailsFactory : public ThreatDetailsFactory {
216 public: 226 public:
217 TestThreatDetailsFactory() : details_() {} 227 TestThreatDetailsFactory() : details_() {}
218 ~TestThreatDetailsFactory() override {} 228 ~TestThreatDetailsFactory() override {}
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 382
373 void ClearBadURL(const GURL& url) { 383 void ClearBadURL(const GURL& url) {
374 TestSafeBrowsingService* service = factory_.test_safe_browsing_service(); 384 TestSafeBrowsingService* service = factory_.test_safe_browsing_service();
375 ASSERT_TRUE(service); 385 ASSERT_TRUE(service);
376 386
377 static_cast<FakeSafeBrowsingDatabaseManager*>( 387 static_cast<FakeSafeBrowsingDatabaseManager*>(
378 service->database_manager().get()) 388 service->database_manager().get())
379 ->ClearBadURL(url); 389 ->ClearBadURL(url);
380 } 390 }
381 391
382 // The basic version of this method, which uses a HTTP test URL. 392 // The basic version of this method, which uses an HTTP test URL.
383 GURL SetupWarningAndNavigate() { 393 GURL SetupWarningAndNavigate(bool is_incognito) {
384 return SetupWarningAndNavigateToURL( 394 return SetupWarningAndNavigateToURL(
385 net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage)); 395 net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage), is_incognito);
386 } 396 }
387 397
388 // Navigates to a warning on a valid HTTPS website. 398 // Navigates to a warning on a valid HTTPS website.
389 GURL SetupWarningAndNavigateToValidHTTPS() { 399 GURL SetupWarningAndNavigateToValidHTTPS() {
390 EXPECT_TRUE(https_server_.Start()); 400 EXPECT_TRUE(https_server_.Start());
391 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate()); 401 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate());
392 net::CertVerifyResult verify_result; 402 net::CertVerifyResult verify_result;
393 verify_result.is_issued_by_known_root = true; 403 verify_result.is_issued_by_known_root = true;
394 verify_result.verified_cert = cert; 404 verify_result.verified_cert = cert;
395 verify_result.cert_status = 0; 405 verify_result.cert_status = 0;
396 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK); 406 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK);
397 GURL url = https_server_.GetURL(kHTTPSPage); 407 GURL url = https_server_.GetURL(kHTTPSPage);
398 return SetupWarningAndNavigateToURL(url); 408 return SetupWarningAndNavigateToURL(url, false);
399 } 409 }
400 410
401 // Navigates through an HTTPS interstitial, then opens up a SB warning on that 411 // Navigates through an HTTPS interstitial, then opens up a SB warning on that
402 // same URL. 412 // same URL.
403 GURL SetupWarningAndNavigateToInvalidHTTPS() { 413 GURL SetupWarningAndNavigateToInvalidHTTPS() {
404 https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); 414 https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
405 EXPECT_TRUE(https_server_.Start()); 415 EXPECT_TRUE(https_server_.Start());
406 GURL url = https_server_.GetURL(kHTTPSPage); 416 GURL url = https_server_.GetURL(kHTTPSPage);
407 417
408 // Proceed through the HTTPS interstitial. 418 // Proceed through the HTTPS interstitial.
409 ui_test_utils::NavigateToURL(browser(), url); 419 ui_test_utils::NavigateToURL(browser(), url);
410 EXPECT_TRUE(WaitForReady()); 420 EXPECT_TRUE(WaitForReady(browser()));
411 InterstitialPage* https_warning = browser() 421 InterstitialPage* https_warning = browser()
412 ->tab_strip_model() 422 ->tab_strip_model()
413 ->GetActiveWebContents() 423 ->GetActiveWebContents()
414 ->GetInterstitialPage(); 424 ->GetInterstitialPage();
415 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, 425 EXPECT_EQ(SSLBlockingPage::kTypeForTesting,
416 https_warning->GetDelegateForTesting()->GetTypeForTesting()); 426 https_warning->GetDelegateForTesting()->GetTypeForTesting());
417 https_warning->Proceed(); 427 https_warning->Proceed();
418 content::WaitForInterstitialDetach( 428 content::WaitForInterstitialDetach(
419 browser()->tab_strip_model()->GetActiveWebContents()); 429 browser()->tab_strip_model()->GetActiveWebContents());
420 430
421 return SetupWarningAndNavigateToURL(url); 431 return SetupWarningAndNavigateToURL(url, false);
422 } 432 }
423 433
424 // Adds a safebrowsing threat results to the fake safebrowsing service, 434 // Adds a safebrowsing threat results to the fake safebrowsing service,
425 // navigates to a page with an iframe containing the threat site, and returns 435 // navigates to a page with an iframe containing the threat site, and returns
426 // the url of the parent page. 436 // the url of the parent page.
427 GURL SetupThreatIframeWarningAndNavigate() { 437 GURL SetupThreatIframeWarningAndNavigate() {
428 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(kCrossSiteMaliciousPage); 438 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(kCrossSiteMaliciousPage);
429 GURL iframe_url = net::URLRequestMockHTTPJob::GetMockUrl(kMaliciousIframe); 439 GURL iframe_url = net::URLRequestMockHTTPJob::GetMockUrl(kMaliciousIframe);
430 SetURLThreatType(iframe_url, testing::get<0>(GetParam())); 440 SetURLThreatType(iframe_url, testing::get<0>(GetParam()));
431 441
432 ui_test_utils::NavigateToURL(browser(), url); 442 ui_test_utils::NavigateToURL(browser(), url);
433 EXPECT_TRUE(WaitForReady()); 443 EXPECT_TRUE(WaitForReady(browser()));
434 return url; 444 return url;
435 } 445 }
436 446
437 // Adds a safebrowsing threat results to the fake safebrowsing service, and 447 // Adds a safebrowsing threat results to the fake safebrowsing service, and
438 // navigates to a page with a cross-origin iframe containing the threat site. 448 // navigates to a page with a cross-origin iframe containing the threat site.
439 // Returns the url of the parent page and sets |iframe_url| to the malicious 449 // Returns the url of the parent page and sets |iframe_url| to the malicious
440 // cross-origin iframe. 450 // cross-origin iframe.
441 GURL SetupCrossOriginThreatIframeWarningAndNavigate(GURL* iframe_url) { 451 GURL SetupCrossOriginThreatIframeWarningAndNavigate(GURL* iframe_url) {
442 content::SetupCrossSiteRedirector(embedded_test_server()); 452 content::SetupCrossSiteRedirector(embedded_test_server());
443 EXPECT_TRUE(embedded_test_server()->Start()); 453 EXPECT_TRUE(embedded_test_server()->Start());
444 GURL url = embedded_test_server()->GetURL( 454 GURL url = embedded_test_server()->GetURL(
445 std::string("/") + kPageWithCrossOriginMaliciousIframe); 455 std::string("/") + kPageWithCrossOriginMaliciousIframe);
446 *iframe_url = 456 *iframe_url =
447 embedded_test_server()->GetURL(std::string("/") + kMaliciousIframe); 457 embedded_test_server()->GetURL(std::string("/") + kMaliciousIframe);
448 GURL::Replacements replace_host; 458 GURL::Replacements replace_host;
449 replace_host.SetHostStr(kCrossOriginMaliciousIframeHost); 459 replace_host.SetHostStr(kCrossOriginMaliciousIframeHost);
450 *iframe_url = iframe_url->ReplaceComponents(replace_host); 460 *iframe_url = iframe_url->ReplaceComponents(replace_host);
451 SetURLThreatType(*iframe_url, testing::get<0>(GetParam())); 461 SetURLThreatType(*iframe_url, testing::get<0>(GetParam()));
452 462
453 ui_test_utils::NavigateToURL(browser(), url); 463 ui_test_utils::NavigateToURL(browser(), url);
454 EXPECT_TRUE(WaitForReady()); 464 EXPECT_TRUE(WaitForReady(browser()));
455 return url; 465 return url;
456 } 466 }
457 467
458 void SendCommand( 468 void SendCommand(
459 security_interstitials::SecurityInterstitialCommands command) { 469 security_interstitials::SecurityInterstitialCommands command) {
460 WebContents* contents = 470 WebContents* contents =
461 browser()->tab_strip_model()->GetActiveWebContents(); 471 browser()->tab_strip_model()->GetActiveWebContents();
462 // We use InterstitialPage::GetInterstitialPage(tab) instead of 472 // We use InterstitialPage::GetInterstitialPage(tab) instead of
463 // tab->GetInterstitialPage() because the tab doesn't have a pointer 473 // tab->GetInterstitialPage() because the tab doesn't have a pointer
464 // to its interstital page until it gets a command from the renderer 474 // to its interstital page until it gets a command from the renderer
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 553 }
544 554
545 content::RenderFrameHost* GetRenderFrameHost() { 555 content::RenderFrameHost* GetRenderFrameHost() {
546 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( 556 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage(
547 browser()->tab_strip_model()->GetActiveWebContents()); 557 browser()->tab_strip_model()->GetActiveWebContents());
548 if (!interstitial) 558 if (!interstitial)
549 return NULL; 559 return NULL;
550 return interstitial->GetMainFrame(); 560 return interstitial->GetMainFrame();
551 } 561 }
552 562
553 bool WaitForReady() { 563 bool WaitForReady(Browser* browser) {
554 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( 564 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage(
555 browser()->tab_strip_model()->GetActiveWebContents()); 565 browser->tab_strip_model()->GetActiveWebContents());
556 if (!interstitial) 566 if (!interstitial)
557 return false; 567 return false;
558 return content::WaitForRenderFrameReady(interstitial->GetMainFrame()); 568 return content::WaitForRenderFrameReady(interstitial->GetMainFrame());
559 } 569 }
560 570
561 Visibility GetVisibility(const std::string& node_id) { 571 Visibility GetVisibility(const std::string& node_id) {
562 content::RenderFrameHost* rfh = GetRenderFrameHost(); 572 content::RenderFrameHost* rfh = GetRenderFrameHost();
563 if (!rfh) 573 if (!rfh)
564 return VISIBILITY_ERROR; 574 return VISIBILITY_ERROR;
565 575
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 if (!Click(node_id)) 622 if (!Click(node_id))
613 return false; 623 return false;
614 content::WaitForInterstitialDetach( 624 content::WaitForInterstitialDetach(
615 browser()->tab_strip_model()->GetActiveWebContents()); 625 browser()->tab_strip_model()->GetActiveWebContents());
616 return true; 626 return true;
617 } 627 }
618 628
619 void TestReportingDisabledAndDontProceed(const GURL& url) { 629 void TestReportingDisabledAndDontProceed(const GURL& url) {
620 SetURLThreatType(url, testing::get<0>(GetParam())); 630 SetURLThreatType(url, testing::get<0>(GetParam()));
621 ui_test_utils::NavigateToURL(browser(), url); 631 ui_test_utils::NavigateToURL(browser(), url);
622 ASSERT_TRUE(WaitForReady()); 632 ASSERT_TRUE(WaitForReady(browser()));
623 633
624 EXPECT_EQ(HIDDEN, GetVisibility("extended-reporting-opt-in")); 634 EXPECT_EQ(HIDDEN, GetVisibility("extended-reporting-opt-in"));
625 EXPECT_EQ(HIDDEN, GetVisibility("opt-in-checkbox")); 635 EXPECT_EQ(HIDDEN, GetVisibility("opt-in-checkbox"));
626 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); 636 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link"));
627 EXPECT_EQ(VISIBLE, GetVisibility("learn-more-link")); 637 EXPECT_EQ(VISIBLE, GetVisibility("learn-more-link"));
628 EXPECT_TRUE(Click("details-button")); 638 EXPECT_TRUE(Click("details-button"));
629 EXPECT_EQ(VISIBLE, GetVisibility("proceed-link")); 639 EXPECT_EQ(VISIBLE, GetVisibility("proceed-link"));
630 640
631 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); 641 EXPECT_TRUE(ClickAndWaitForDetach("primary-button"));
632 AssertNoInterstitial(false); // Assert the interstitial is gone 642 AssertNoInterstitial(false); // Assert the interstitial is gone
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 SecurityStateTabHelper* helper = 701 SecurityStateTabHelper* helper =
692 SecurityStateTabHelper::FromWebContents(tab); 702 SecurityStateTabHelper::FromWebContents(tab);
693 ASSERT_TRUE(helper); 703 ASSERT_TRUE(helper);
694 security_state::SecurityInfo security_info; 704 security_state::SecurityInfo security_info;
695 helper->GetSecurityInfo(&security_info); 705 helper->GetSecurityInfo(&security_info);
696 EXPECT_EQ(security_state::NONE, security_info.security_level); 706 EXPECT_EQ(security_state::NONE, security_info.security_level);
697 EXPECT_EQ(security_state::MALICIOUS_CONTENT_STATUS_NONE, 707 EXPECT_EQ(security_state::MALICIOUS_CONTENT_STATUS_NONE,
698 security_info.malicious_content_status); 708 security_info.malicious_content_status);
699 } 709 }
700 710
711 bool hit_report_sent() {
712 return static_cast<FakeSafeBrowsingUIManager*>(
713 factory_.test_safe_browsing_service()->ui_manager().get())
714 ->hit_report_sent();
715 }
716
701 protected: 717 protected:
702 TestThreatDetailsFactory details_factory_; 718 TestThreatDetailsFactory details_factory_;
703 719
704 private: 720 private:
705 // Adds a safebrowsing result of the current test threat to the fake 721 // Adds a safebrowsing result of the current test threat to the fake
706 // safebrowsing service, navigates to that page, and returns the url. 722 // safebrowsing service, navigates to that page, and returns the url.
707 // The various wrappers supply different URLs. 723 // The various wrappers supply different URLs.
708 GURL SetupWarningAndNavigateToURL(GURL url) { 724 GURL SetupWarningAndNavigateToURL(GURL url, bool is_incognito) {
709 SetURLThreatType(url, testing::get<0>(GetParam())); 725 SetURLThreatType(url, testing::get<0>(GetParam()));
710 ui_test_utils::NavigateToURL(browser(), url); 726 if (is_incognito) {
711 EXPECT_TRUE(WaitForReady()); 727 Browser* incognito_browser = CreateIncognitoBrowser();
728 ui_test_utils::NavigateToURL(incognito_browser, url);
729 EXPECT_TRUE(WaitForReady(incognito_browser));
730 } else {
731 ui_test_utils::NavigateToURL(browser(), url);
732 EXPECT_TRUE(WaitForReady(browser()));
733 }
712 return url; 734 return url;
713 } 735 }
714 736
715 TestSafeBrowsingServiceFactory factory_; 737 TestSafeBrowsingServiceFactory factory_;
716 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; 738 TestSafeBrowsingBlockingPageFactory blocking_page_factory_;
717 net::EmbeddedTestServer https_server_; 739 net::EmbeddedTestServer https_server_;
740 // Browser* incognito_browser;
Jialiu Lin 2017/05/18 22:32:12 You probably need this one. See my comments below.
mortonm 2017/05/19 20:21:03 Done.
718 741
719 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageBrowserTest); 742 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageBrowserTest);
720 }; 743 };
721 744
722 // TODO(linux_aura) https://crbug.com/163931 745 // TODO(linux_aura) https://crbug.com/163931
723 // TODO(win_aura) https://crbug.com/154081 746 // TODO(win_aura) https://crbug.com/154081
724 #if defined(USE_AURA) && !defined(OS_CHROMEOS) 747 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
725 #define MAYBE_RedirectInIFrameCanceled DISABLED_RedirectInIFrameCanceled 748 #define MAYBE_RedirectInIFrameCanceled DISABLED_RedirectInIFrameCanceled
726 #else 749 #else
727 #define MAYBE_RedirectInIFrameCanceled RedirectInIFrameCanceled 750 #define MAYBE_RedirectInIFrameCanceled RedirectInIFrameCanceled
728 #endif 751 #endif
729 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 752 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
730 MAYBE_RedirectInIFrameCanceled) { 753 MAYBE_RedirectInIFrameCanceled) {
731 // 1. Test the case that redirect is a subresource. 754 // 1. Test the case that redirect is a subresource.
732 MalwareRedirectCancelAndProceed("openWinIFrame"); 755 MalwareRedirectCancelAndProceed("openWinIFrame");
733 // If the redirect was from subresource but canceled, "proceed" will continue 756 // If the redirect was from subresource but canceled, "proceed" will continue
734 // with the rest of resources. 757 // with the rest of resources.
735 AssertNoInterstitial(true); 758 AssertNoInterstitial(true);
736 } 759 }
737 760
738 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, RedirectCanceled) { 761 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, RedirectCanceled) {
739 // 2. Test the case that redirect is the only resource. 762 // 2. Test the case that redirect is the only resource.
740 MalwareRedirectCancelAndProceed("openWin"); 763 MalwareRedirectCancelAndProceed("openWin");
741 // Clicking proceed won't do anything if the main request is cancelled 764 // Clicking proceed won't do anything if the main request is cancelled
742 // already. See crbug.com/76460. 765 // already. See crbug.com/76460.
743 EXPECT_TRUE(YesInterstitial()); 766 EXPECT_TRUE(YesInterstitial());
744 } 767 }
745 768
746 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, DontProceed) { 769 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, DontProceed) {
747 SetupWarningAndNavigate(); 770 SetupWarningAndNavigate(false);
748 771
749 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); 772 EXPECT_EQ(VISIBLE, GetVisibility("primary-button"));
750 EXPECT_EQ(HIDDEN, GetVisibility("details")); 773 EXPECT_EQ(HIDDEN, GetVisibility("details"));
751 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); 774 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link"));
752 EXPECT_EQ(HIDDEN, GetVisibility("error-code")); 775 EXPECT_EQ(HIDDEN, GetVisibility("error-code"));
753 EXPECT_TRUE(Click("details-button")); 776 EXPECT_TRUE(Click("details-button"));
754 EXPECT_EQ(VISIBLE, GetVisibility("details")); 777 EXPECT_EQ(VISIBLE, GetVisibility("details"));
755 EXPECT_EQ(VISIBLE, GetVisibility("proceed-link")); 778 EXPECT_EQ(VISIBLE, GetVisibility("proceed-link"));
756 EXPECT_EQ(HIDDEN, GetVisibility("error-code")); 779 EXPECT_EQ(HIDDEN, GetVisibility("error-code"));
757 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); 780 EXPECT_TRUE(ClickAndWaitForDetach("primary-button"));
758 781
759 AssertNoInterstitial(false); // Assert the interstitial is gone 782 AssertNoInterstitial(false); // Assert the interstitial is gone
760 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" 783 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank"
761 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 784 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
762 } 785 }
763 786
764 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, Proceed) { 787 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, Proceed) {
765 GURL url = SetupWarningAndNavigate(); 788 GURL url = SetupWarningAndNavigate(false);
766 789
767 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 790 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
768 AssertNoInterstitial(true); // Assert the interstitial is gone. 791 AssertNoInterstitial(true); // Assert the interstitial is gone.
769 EXPECT_EQ(url, 792 EXPECT_EQ(url,
770 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 793 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
771 } 794 }
772 795
773 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, IframeDontProceed) { 796 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, IframeDontProceed) {
774 SetupThreatIframeWarningAndNavigate(); 797 SetupThreatIframeWarningAndNavigate();
775 798
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // Navigate to a safe page which contains multiple potential DOM details. 924 // Navigate to a safe page which contains multiple potential DOM details.
902 // (Despite the name, kMaliciousPage is not the page flagged as bad in this 925 // (Despite the name, kMaliciousPage is not the page flagged as bad in this
903 // test.) 926 // test.)
904 GURL safe_url(net::URLRequestMockHTTPJob::GetMockUrl(kMaliciousPage)); 927 GURL safe_url(net::URLRequestMockHTTPJob::GetMockUrl(kMaliciousPage));
905 ui_test_utils::NavigateToURL(browser(), safe_url); 928 ui_test_utils::NavigateToURL(browser(), safe_url);
906 929
907 EXPECT_EQ(nullptr, details_factory_.get_details()); 930 EXPECT_EQ(nullptr, details_factory_.get_details());
908 931
909 // Start navigation to bad page (kEmptyPage), which will be blocked before it 932 // Start navigation to bad page (kEmptyPage), which will be blocked before it
910 // is committed. 933 // is committed.
911 GURL url = SetupWarningAndNavigate(); 934 GURL url = SetupWarningAndNavigate(false);
912 935
913 ThreatDetails* threat_details = details_factory_.get_details(); 936 ThreatDetails* threat_details = details_factory_.get_details();
914 EXPECT_EQ(expect_threat_details, threat_details != nullptr); 937 EXPECT_EQ(expect_threat_details, threat_details != nullptr);
915 938
916 // Go back. 939 // Go back.
917 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in")); 940 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in"));
918 EXPECT_TRUE(Click("opt-in-checkbox")); 941 EXPECT_TRUE(Click("opt-in-checkbox"));
919 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); 942 EXPECT_TRUE(ClickAndWaitForDetach("primary-button"));
920 AssertNoInterstitial(true); // Assert the interstitial is gone 943 AssertNoInterstitial(true); // Assert the interstitial is gone
921 944
(...skipping 30 matching lines...) Expand all
952 // Navigate to a safe page which contains multiple potential DOM details. 975 // Navigate to a safe page which contains multiple potential DOM details.
953 // (Despite the name, kMaliciousPage is not the page flagged as bad in this 976 // (Despite the name, kMaliciousPage is not the page flagged as bad in this
954 // test.) 977 // test.)
955 ui_test_utils::NavigateToURL( 978 ui_test_utils::NavigateToURL(
956 browser(), net::URLRequestMockHTTPJob::GetMockUrl(kMaliciousPage)); 979 browser(), net::URLRequestMockHTTPJob::GetMockUrl(kMaliciousPage));
957 980
958 EXPECT_EQ(nullptr, details_factory_.get_details()); 981 EXPECT_EQ(nullptr, details_factory_.get_details());
959 982
960 // Start navigation to bad page (kEmptyPage), which will be blocked before it 983 // Start navigation to bad page (kEmptyPage), which will be blocked before it
961 // is committed. 984 // is committed.
962 GURL url = SetupWarningAndNavigate(); 985 GURL url = SetupWarningAndNavigate(false);
963 986
964 ThreatDetails* threat_details = details_factory_.get_details(); 987 ThreatDetails* threat_details = details_factory_.get_details();
965 EXPECT_EQ(expect_threat_details, threat_details != nullptr); 988 EXPECT_EQ(expect_threat_details, threat_details != nullptr);
966 989
967 // Proceed through the warning. 990 // Proceed through the warning.
968 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in")); 991 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in"));
969 EXPECT_TRUE(Click("opt-in-checkbox")); 992 EXPECT_TRUE(Click("opt-in-checkbox"));
970 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 993 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
971 AssertNoInterstitial(true); // Assert the interstitial is gone 994 AssertNoInterstitial(true); // Assert the interstitial is gone
972 995
(...skipping 16 matching lines...) Expand all
989 } 1012 }
990 1013
991 // Verifies that the "proceed anyway" link isn't available when it is disabled 1014 // Verifies that the "proceed anyway" link isn't available when it is disabled
992 // by the corresponding policy. Also verifies that sending the "proceed" 1015 // by the corresponding policy. Also verifies that sending the "proceed"
993 // command anyway doesn't advance to the unsafe site. 1016 // command anyway doesn't advance to the unsafe site.
994 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ProceedDisabled) { 1017 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ProceedDisabled) {
995 // Simulate a policy disabling the "proceed anyway" link. 1018 // Simulate a policy disabling the "proceed anyway" link.
996 browser()->profile()->GetPrefs()->SetBoolean( 1019 browser()->profile()->GetPrefs()->SetBoolean(
997 prefs::kSafeBrowsingProceedAnywayDisabled, true); 1020 prefs::kSafeBrowsingProceedAnywayDisabled, true);
998 1021
999 SetupWarningAndNavigate(); 1022 SetupWarningAndNavigate(false);
1000 1023
1001 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); 1024 EXPECT_EQ(VISIBLE, GetVisibility("primary-button"));
1002 EXPECT_EQ(HIDDEN, GetVisibility("details")); 1025 EXPECT_EQ(HIDDEN, GetVisibility("details"));
1003 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); 1026 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link"));
1004 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); 1027 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph"));
1005 EXPECT_TRUE(Click("details-button")); 1028 EXPECT_TRUE(Click("details-button"));
1006 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); 1029 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link"));
1007 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); 1030 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph"));
1008 SendCommand(security_interstitials::CMD_PROCEED); 1031 SendCommand(security_interstitials::CMD_PROCEED);
1009 1032
(...skipping 14 matching lines...) Expand all
1024 TestReportingDisabledAndDontProceed( 1047 TestReportingDisabledAndDontProceed(
1025 net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage)); 1048 net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage));
1026 } 1049 }
1027 1050
1028 // Verifies that the reporting checkbox is still shown if the page is reloaded 1051 // Verifies that the reporting checkbox is still shown if the page is reloaded
1029 // while the interstitial is showing. 1052 // while the interstitial is showing.
1030 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1053 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1031 ReloadWhileInterstitialShowing) { 1054 ReloadWhileInterstitialShowing) {
1032 // Start navigation to bad page (kEmptyPage), which will be blocked before it 1055 // Start navigation to bad page (kEmptyPage), which will be blocked before it
1033 // is committed. 1056 // is committed.
1034 const GURL url = SetupWarningAndNavigate(); 1057 const GURL url = SetupWarningAndNavigate(false);
1035 1058
1036 // Checkbox should be showing. 1059 // Checkbox should be showing.
1037 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in")); 1060 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in"));
1038 1061
1039 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 1062 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
1040 ASSERT_TRUE(tab); 1063 ASSERT_TRUE(tab);
1041 // Security indicator should be showing. 1064 // Security indicator should be showing.
1042 ExpectSecurityIndicatorDowngrade(tab, 0u); 1065 ExpectSecurityIndicatorDowngrade(tab, 0u);
1043 1066
1044 // Check navigation entry state. 1067 // Check navigation entry state.
1045 const NavigationController& controller = tab->GetController(); 1068 const NavigationController& controller = tab->GetController();
1046 ASSERT_TRUE(controller.GetVisibleEntry()); 1069 ASSERT_TRUE(controller.GetVisibleEntry());
1047 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 1070 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
1048 ASSERT_TRUE(controller.GetPendingEntry()); 1071 ASSERT_TRUE(controller.GetPendingEntry());
1049 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); 1072 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
1050 1073
1051 // "Reload" the tab. 1074 // "Reload" the tab.
1052 SetupWarningAndNavigate(); 1075 SetupWarningAndNavigate(false);
1053 1076
1054 // Checkbox should be showing. 1077 // Checkbox should be showing.
1055 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in")); 1078 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in"));
1056 1079
1057 // TODO(crbug.com/666172): Security indicator should be showing. 1080 // TODO(crbug.com/666172): Security indicator should be showing.
1058 // Call |ExpectSecurityIndicatorDowngrade(tab, 0u);| here once the bug is 1081 // Call |ExpectSecurityIndicatorDowngrade(tab, 0u);| here once the bug is
1059 // fixed. 1082 // fixed.
1060 1083
1061 // Check navigation entry state. 1084 // Check navigation entry state.
1062 ASSERT_TRUE(controller.GetVisibleEntry()); 1085 ASSERT_TRUE(controller.GetVisibleEntry());
1063 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 1086 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
1064 ASSERT_TRUE(controller.GetPendingEntry()); 1087 ASSERT_TRUE(controller.GetPendingEntry());
1065 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); 1088 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
1066 } 1089 }
1067 1090
1068 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) { 1091 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) {
1069 SetupWarningAndNavigate(); 1092 SetupWarningAndNavigate(false);
1070 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link")); 1093 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link"));
1071 AssertNoInterstitial(false); // Assert the interstitial is gone 1094 AssertNoInterstitial(false); // Assert the interstitial is gone
1072 1095
1073 // We are in the help page. 1096 // We are in the help page.
1074 EXPECT_EQ( 1097 EXPECT_EQ(
1075 GURL("https://support.google.com/chrome/answer/99020").GetWithEmptyPath(), 1098 GURL("https://support.google.com/chrome/answer/99020").GetWithEmptyPath(),
1076 browser() 1099 browser()
1077 ->tab_strip_model() 1100 ->tab_strip_model()
1078 ->GetActiveWebContents() 1101 ->GetActiveWebContents()
1079 ->GetURL() 1102 ->GetURL()
(...skipping 17 matching lines...) Expand all
1097 const std::string interaction_histogram = 1120 const std::string interaction_histogram =
1098 "interstitial." + prefix + ".interaction"; 1121 "interstitial." + prefix + ".interaction";
1099 1122
1100 // TODO(nparker): Check for *.from_device as well. 1123 // TODO(nparker): Check for *.from_device as well.
1101 1124
1102 // Histograms should start off empty. 1125 // Histograms should start off empty.
1103 histograms.ExpectTotalCount(decision_histogram, 0); 1126 histograms.ExpectTotalCount(decision_histogram, 0);
1104 histograms.ExpectTotalCount(interaction_histogram, 0); 1127 histograms.ExpectTotalCount(interaction_histogram, 0);
1105 1128
1106 // After navigating to the page, the totals should be set. 1129 // After navigating to the page, the totals should be set.
1107 SetupWarningAndNavigate(); 1130 SetupWarningAndNavigate(false);
1108 histograms.ExpectTotalCount(decision_histogram, 1); 1131 histograms.ExpectTotalCount(decision_histogram, 1);
1109 histograms.ExpectBucketCount(decision_histogram, 1132 histograms.ExpectBucketCount(decision_histogram,
1110 security_interstitials::MetricsHelper::SHOW, 1); 1133 security_interstitials::MetricsHelper::SHOW, 1);
1111 histograms.ExpectTotalCount(interaction_histogram, 1); 1134 histograms.ExpectTotalCount(interaction_histogram, 1);
1112 histograms.ExpectBucketCount( 1135 histograms.ExpectBucketCount(
1113 interaction_histogram, 1136 interaction_histogram,
1114 security_interstitials::MetricsHelper::TOTAL_VISITS, 1); 1137 security_interstitials::MetricsHelper::TOTAL_VISITS, 1);
1115 1138
1116 // Decision should be recorded. 1139 // Decision should be recorded.
1117 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); 1140 EXPECT_TRUE(ClickAndWaitForDetach("primary-button"));
(...skipping 23 matching lines...) Expand all
1141 NOTREACHED(); 1164 NOTREACHED();
1142 const std::string decision_histogram = "interstitial." + prefix + ".decision"; 1165 const std::string decision_histogram = "interstitial." + prefix + ".decision";
1143 const std::string interaction_histogram = 1166 const std::string interaction_histogram =
1144 "interstitial." + prefix + ".interaction"; 1167 "interstitial." + prefix + ".interaction";
1145 1168
1146 // Histograms should start off empty. 1169 // Histograms should start off empty.
1147 histograms.ExpectTotalCount(decision_histogram, 0); 1170 histograms.ExpectTotalCount(decision_histogram, 0);
1148 histograms.ExpectTotalCount(interaction_histogram, 0); 1171 histograms.ExpectTotalCount(interaction_histogram, 0);
1149 1172
1150 // After navigating to the page, the totals should be set. 1173 // After navigating to the page, the totals should be set.
1151 GURL url = SetupWarningAndNavigate(); 1174 GURL url = SetupWarningAndNavigate(false);
1152 histograms.ExpectTotalCount(decision_histogram, 1); 1175 histograms.ExpectTotalCount(decision_histogram, 1);
1153 histograms.ExpectBucketCount(decision_histogram, 1176 histograms.ExpectBucketCount(decision_histogram,
1154 security_interstitials::MetricsHelper::SHOW, 1); 1177 security_interstitials::MetricsHelper::SHOW, 1);
1155 histograms.ExpectTotalCount(interaction_histogram, 1); 1178 histograms.ExpectTotalCount(interaction_histogram, 1);
1156 histograms.ExpectBucketCount( 1179 histograms.ExpectBucketCount(
1157 interaction_histogram, 1180 interaction_histogram,
1158 security_interstitials::MetricsHelper::TOTAL_VISITS, 1); 1181 security_interstitials::MetricsHelper::TOTAL_VISITS, 1);
1159 1182
1160 // Decision should be recorded. 1183 // Decision should be recorded.
1161 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 1184 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
1162 AssertNoInterstitial(true); // Assert the interstitial is gone. 1185 AssertNoInterstitial(true); // Assert the interstitial is gone.
1163 histograms.ExpectTotalCount(decision_histogram, 2); 1186 histograms.ExpectTotalCount(decision_histogram, 2);
1164 histograms.ExpectBucketCount( 1187 histograms.ExpectBucketCount(
1165 decision_histogram, security_interstitials::MetricsHelper::PROCEED, 1); 1188 decision_histogram, security_interstitials::MetricsHelper::PROCEED, 1);
1166 histograms.ExpectTotalCount(interaction_histogram, 1); 1189 histograms.ExpectTotalCount(interaction_histogram, 1);
1167 histograms.ExpectBucketCount( 1190 histograms.ExpectBucketCount(
1168 interaction_histogram, 1191 interaction_histogram,
1169 security_interstitials::MetricsHelper::TOTAL_VISITS, 1); 1192 security_interstitials::MetricsHelper::TOTAL_VISITS, 1);
1170 } 1193 }
1171 1194
1172 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, WhitelistRevisit) { 1195 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, WhitelistRevisit) {
1173 GURL url = SetupWarningAndNavigate(); 1196 GURL url = SetupWarningAndNavigate(false);
1174 1197
1175 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 1198 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
1176 AssertNoInterstitial(true); // Assert the interstitial is gone. 1199 AssertNoInterstitial(true); // Assert the interstitial is gone.
1177 EXPECT_EQ(url, 1200 EXPECT_EQ(url,
1178 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 1201 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1179 1202
1180 // Unrelated pages should not be whitelisted now. 1203 // Unrelated pages should not be whitelisted now.
1181 ui_test_utils::NavigateToURL(browser(), GURL(kUnrelatedUrl)); 1204 ui_test_utils::NavigateToURL(browser(), GURL(kUnrelatedUrl));
1182 AssertNoInterstitial(false); 1205 AssertNoInterstitial(false);
1183 1206
(...skipping 14 matching lines...) Expand all
1198 // Unrelated pages should not be whitelisted now. 1221 // Unrelated pages should not be whitelisted now.
1199 ui_test_utils::NavigateToURL(browser(), GURL(kUnrelatedUrl)); 1222 ui_test_utils::NavigateToURL(browser(), GURL(kUnrelatedUrl));
1200 AssertNoInterstitial(false); 1223 AssertNoInterstitial(false);
1201 1224
1202 // The whitelisted page should remain whitelisted. 1225 // The whitelisted page should remain whitelisted.
1203 ui_test_utils::NavigateToURL(browser(), url); 1226 ui_test_utils::NavigateToURL(browser(), url);
1204 AssertNoInterstitial(false); 1227 AssertNoInterstitial(false);
1205 } 1228 }
1206 1229
1207 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, WhitelistUnsaved) { 1230 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, WhitelistUnsaved) {
1208 GURL url = SetupWarningAndNavigate(); 1231 GURL url = SetupWarningAndNavigate(false);
1209 1232
1210 // Navigate without making a decision. 1233 // Navigate without making a decision.
1211 ui_test_utils::NavigateToURL(browser(), GURL(kUnrelatedUrl)); 1234 ui_test_utils::NavigateToURL(browser(), GURL(kUnrelatedUrl));
1212 AssertNoInterstitial(false); 1235 AssertNoInterstitial(false);
1213 1236
1214 // The non-whitelisted page should now show an interstitial. 1237 // The non-whitelisted page should now show an interstitial.
1215 ui_test_utils::NavigateToURL(browser(), url); 1238 ui_test_utils::NavigateToURL(browser(), url);
1216 EXPECT_TRUE(WaitForReady()); 1239 EXPECT_TRUE(WaitForReady(browser()));
1217 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 1240 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
1218 AssertNoInterstitial(true); 1241 AssertNoInterstitial(true);
1219 } 1242 }
1220 1243
1244 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1245 VerifyHitReportSentOnSBERAndNotIncognito) {
1246 // The extended reporting opt-in is presented in the interstitial for malware,
1247 // phishing, and UwS threats.
1248 const bool expect_threat_details =
1249 SafeBrowsingBlockingPage::ShouldReportThreatDetails(
1250 testing::get<0>(GetParam()));
1251
1252 scoped_refptr<content::MessageLoopRunner> threat_report_sent_runner(
1253 new content::MessageLoopRunner);
1254 if (expect_threat_details)
1255 SetReportSentCallback(threat_report_sent_runner->QuitClosure());
1256
1257 browser()->profile()->GetPrefs()->SetBoolean(
1258 prefs::kSafeBrowsingExtendedReportingEnabled, true); // set up SBER
1259 GURL url = SetupWarningAndNavigate(false); // not incognito
1260 EXPECT_TRUE(hit_report_sent());
1261 }
1262
1263 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1264 VerifyHitReportNotSentOnIncognito) {
1265 // The extended reporting opt-in is presented in the interstitial for malware,
1266 // phishing, and UwS threats.
1267 const bool expect_threat_details =
1268 SafeBrowsingBlockingPage::ShouldReportThreatDetails(
1269 testing::get<0>(GetParam()));
1270
1271 scoped_refptr<content::MessageLoopRunner> threat_report_sent_runner(
1272 new content::MessageLoopRunner);
1273 if (expect_threat_details)
1274 SetReportSentCallback(threat_report_sent_runner->QuitClosure());
1275
1276 browser()->profile()->GetPrefs()->SetBoolean(
Jialiu Lin 2017/05/18 22:32:12 You're configuring the extended reporting prefs on
mortonm 2017/05/19 20:21:03 Done.
1277 prefs::kSafeBrowsingExtendedReportingEnabled, true); // set up SBER
1278 GURL url = SetupWarningAndNavigate(true); // incognito
1279 EXPECT_FALSE(hit_report_sent());
1280 }
1281
1282 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1283 VerifyHitReportNotSentWithoutSBER) {
1284 // The extended reporting opt-in is presented in the interstitial for malware,
1285 // phishing, and UwS threats.
1286 const bool expect_threat_details =
1287 SafeBrowsingBlockingPage::ShouldReportThreatDetails(
1288 testing::get<0>(GetParam()));
1289
1290 scoped_refptr<content::MessageLoopRunner> threat_report_sent_runner(
1291 new content::MessageLoopRunner);
1292 if (expect_threat_details)
1293 SetReportSentCallback(threat_report_sent_runner->QuitClosure());
1294
1295 browser()->profile()->GetPrefs()->SetBoolean(
1296 prefs::kSafeBrowsingExtendedReportingEnabled, false); // no SBER
1297 GURL url = SetupWarningAndNavigate(false); // not incognito
1298 EXPECT_FALSE(hit_report_sent());
1299 }
1300
1221 namespace { 1301 namespace {
1222 1302
1223 class SecurityStyleTestObserver : public content::WebContentsObserver { 1303 class SecurityStyleTestObserver : public content::WebContentsObserver {
1224 public: 1304 public:
1225 explicit SecurityStyleTestObserver(content::WebContents* web_contents) 1305 explicit SecurityStyleTestObserver(content::WebContents* web_contents)
1226 : content::WebContentsObserver(web_contents), 1306 : content::WebContentsObserver(web_contents),
1227 latest_security_style_(blink::kWebSecurityStyleUnknown), 1307 latest_security_style_(blink::kWebSecurityStyleUnknown),
1228 latest_security_style_explanations_() {} 1308 latest_security_style_explanations_() {}
1229 1309
1230 blink::WebSecurityStyle latest_security_style() const { 1310 blink::WebSecurityStyle latest_security_style() const {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 // https://crbug.com/659709. 1359 // https://crbug.com/659709.
1280 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1360 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1281 SecurityStateGoBack) { 1361 SecurityStateGoBack) {
1282 // Navigate to a page so that there is somewhere to go back to. 1362 // Navigate to a page so that there is somewhere to go back to.
1283 GURL start_url = 1363 GURL start_url =
1284 net::URLRequestMockHTTPJob::GetMockUrl("http://example.test"); 1364 net::URLRequestMockHTTPJob::GetMockUrl("http://example.test");
1285 ui_test_utils::NavigateToURL(browser(), start_url); 1365 ui_test_utils::NavigateToURL(browser(), start_url);
1286 1366
1287 // The security indicator should be downgraded while the interstitial shows. 1367 // The security indicator should be downgraded while the interstitial shows.
1288 GURL bad_url = net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage); 1368 GURL bad_url = net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage);
1289 SetupWarningAndNavigate(); 1369 SetupWarningAndNavigate(false);
1290 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1370 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents();
1291 ASSERT_TRUE(error_tab); 1371 ASSERT_TRUE(error_tab);
1292 ExpectSecurityIndicatorDowngrade(error_tab, 0u); 1372 ExpectSecurityIndicatorDowngrade(error_tab, 0u);
1293 content::NavigationEntry* entry = 1373 content::NavigationEntry* entry =
1294 error_tab->GetController().GetVisibleEntry(); 1374 error_tab->GetController().GetVisibleEntry();
1295 ASSERT_TRUE(entry); 1375 ASSERT_TRUE(entry);
1296 ASSERT_EQ(bad_url, entry->GetURL()); 1376 ASSERT_EQ(bad_url, entry->GetURL());
1297 1377
1298 // Go back. 1378 // Go back.
1299 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); 1379 EXPECT_EQ(VISIBLE, GetVisibility("primary-button"));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 ui_test_utils::NavigateToURL(browser(), main_url); 1450 ui_test_utils::NavigateToURL(browser(), main_url);
1371 ExpectNoSecurityIndicatorDowngrade( 1451 ExpectNoSecurityIndicatorDowngrade(
1372 browser()->tab_strip_model()->GetActiveWebContents()); 1452 browser()->tab_strip_model()->GetActiveWebContents());
1373 } 1453 }
1374 1454
1375 // Test that the security indicator is downgraded after clicking through a 1455 // Test that the security indicator is downgraded after clicking through a
1376 // Safe Browsing interstitial. 1456 // Safe Browsing interstitial.
1377 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1457 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1378 SecurityState_HTTP) { 1458 SecurityState_HTTP) {
1379 // The security indicator should be downgraded while the interstitial shows. 1459 // The security indicator should be downgraded while the interstitial shows.
1380 SetupWarningAndNavigate(); 1460 SetupWarningAndNavigate(false);
1381 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1461 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents();
1382 ASSERT_TRUE(error_tab); 1462 ASSERT_TRUE(error_tab);
1383 ExpectSecurityIndicatorDowngrade(error_tab, 0u); 1463 ExpectSecurityIndicatorDowngrade(error_tab, 0u);
1384 1464
1385 // The security indicator should still be downgraded post-interstitial. 1465 // The security indicator should still be downgraded post-interstitial.
1386 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 1466 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
1387 AssertNoInterstitial(true); 1467 AssertNoInterstitial(true);
1388 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1468 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents();
1389 ASSERT_TRUE(post_tab); 1469 ASSERT_TRUE(post_tab);
1390 ExpectSecurityIndicatorDowngrade(post_tab, 0u); 1470 ExpectSecurityIndicatorDowngrade(post_tab, 0u);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 1567
1488 INSTANTIATE_TEST_CASE_P( 1568 INSTANTIATE_TEST_CASE_P(
1489 SafeBrowsingBlockingPageIDNTestWithThreatType, 1569 SafeBrowsingBlockingPageIDNTestWithThreatType,
1490 SafeBrowsingBlockingPageIDNTest, 1570 SafeBrowsingBlockingPageIDNTest,
1491 testing::Combine(testing::Values(false, true), 1571 testing::Combine(testing::Values(false, true),
1492 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 1572 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
1493 SB_THREAT_TYPE_URL_PHISHING, 1573 SB_THREAT_TYPE_URL_PHISHING,
1494 SB_THREAT_TYPE_URL_UNWANTED))); 1574 SB_THREAT_TYPE_URL_UNWANTED)));
1495 1575
1496 } // namespace safe_browsing 1576 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698