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

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

Powered by Google App Engine
This is Rietveld 408576698