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

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

Issue 1509073002: Fixes for Safe Browsing with unrelated pending navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review changes for comment #13-15 Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
index cb18b215880f09c05af7b3f01363eeb1f08f0dc1..7b5e6e6a38a351748b584710178d2f4b7b129b06 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
@@ -26,9 +26,11 @@ using content::WebContentsTester;
static const char* kGoogleURL = "http://www.google.com/";
static const char* kGoodURL = "http://www.goodguys.com/";
+static const char* kGoodHTTPSURL = "https://www.goodguys.com/";
static const char* kBadURL = "http://www.badguys.com/";
static const char* kBadURL2 = "http://www.badguys2.com/";
static const char* kBadURL3 = "http://www.badguys3.com/";
+static const char* kBadHTTPSURL = "https://www.badguys.com/";
namespace safe_browsing {
@@ -38,9 +40,13 @@ namespace {
class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage {
public:
TestSafeBrowsingBlockingPage(SafeBrowsingUIManager* manager,
- WebContents* web_contents,
- const UnsafeResourceList& unsafe_resources)
- : SafeBrowsingBlockingPage(manager, web_contents, unsafe_resources) {
+ WebContents* web_contents,
+ const GURL& main_frame_url,
+ const UnsafeResourceList& unsafe_resources)
+ : SafeBrowsingBlockingPage(manager,
+ web_contents,
+ main_frame_url,
+ unsafe_resources) {
// Don't delay details at all for the unittest.
malware_details_proceed_delay_ms_ = 0;
DontCreateViewForTesting();
@@ -76,10 +82,11 @@ class TestSafeBrowsingBlockingPageFactory
SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
SafeBrowsingUIManager* manager,
WebContents* web_contents,
+ const GURL& main_frame_url,
const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources)
override {
return new TestSafeBrowsingBlockingPage(manager, web_contents,
- unsafe_resources);
+ main_frame_url, unsafe_resources);
}
};
@@ -637,6 +644,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) {
ShowInterstitial(false, kBadURL);
SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
+ EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption());
base::RunLoop().RunUntilIdle();
@@ -671,6 +679,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) {
ShowInterstitial(false, kBadURL);
SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
+ EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption());
base::RunLoop().RunUntilIdle();
@@ -690,4 +699,188 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) {
prefs::kSafeBrowsingExtendedReportingEnabled));
}
+// Test that extended reporting option is not shown on blocking an HTTPS main
+// page, and no report is sent.
+TEST_F(SafeBrowsingBlockingPageTest, ExtendedReportingNotShownOnSecurePage) {
+ // Enable malware details.
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents()->GetBrowserContext());
+ profile->GetPrefs()->SetBoolean(
+ prefs::kSafeBrowsingExtendedReportingEnabled, true);
+
+ // Start a load.
+ controller().LoadURL(GURL(kBadHTTPSURL), content::Referrer(),
+ ui::PAGE_TRANSITION_TYPED, std::string());
+
+ // Simulate the load causing a safe browsing interstitial to be shown.
+ ShowInterstitial(false, kBadHTTPSURL);
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
+ ASSERT_TRUE(sb_interstitial);
+ EXPECT_FALSE(sb_interstitial->CanShowThreatDetailsOption());
+
+ base::RunLoop().RunUntilIdle();
+
+ // Simulate the user clicking "don't proceed".
+ DontProceedThroughInterstitial(sb_interstitial);
+
+ // The interstitial should be gone.
+ EXPECT_EQ(CANCEL, user_response());
+ EXPECT_FALSE(GetSafeBrowsingBlockingPage());
+
+ // No report should have been sent.
+ EXPECT_EQ(0u, ui_manager_->GetDetails()->size());
+ ui_manager_->GetDetails()->clear();
+}
+
+// Test that extended reporting option is not shown on blocking an HTTPS
+// subresource on an HTTPS page, and no report is sent.
+TEST_F(SafeBrowsingBlockingPageTest,
+ ExtendedReportingNotShownOnSecurePageWithSecureSubresource) {
+ // Enable malware details.
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents()->GetBrowserContext());
+ profile->GetPrefs()->SetBoolean(
+ prefs::kSafeBrowsingExtendedReportingEnabled, true);
+
+ // Commit a load.
+ content::WebContentsTester::For(web_contents())
+ ->NavigateAndCommit(GURL(kGoodHTTPSURL));
+
+ // Simulate a subresource load causing a safe browsing interstitial to be
+ // shown.
+ ShowInterstitial(true, kBadHTTPSURL);
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
+ ASSERT_TRUE(sb_interstitial);
+ EXPECT_FALSE(sb_interstitial->CanShowThreatDetailsOption());
+
+ base::RunLoop().RunUntilIdle();
+
+ // Simulate the user clicking "don't proceed".
+ DontProceedThroughInterstitial(sb_interstitial);
+
+ // The interstitial should be gone.
+ EXPECT_EQ(CANCEL, user_response());
+ EXPECT_FALSE(GetSafeBrowsingBlockingPage());
+
+ // No report should have been sent.
+ EXPECT_EQ(0u, ui_manager_->GetDetails()->size());
+ ui_manager_->GetDetails()->clear();
+}
+
+// Test that extended reporting option is not shown on blocking an HTTP
+// subresource on an HTTPS page, and no report is sent.
+TEST_F(SafeBrowsingBlockingPageTest,
+ ExtendedReportingNotShownOnSecurePageWithInsecureSubresource) {
+ // Enable malware details.
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents()->GetBrowserContext());
+ profile->GetPrefs()->SetBoolean(
+ prefs::kSafeBrowsingExtendedReportingEnabled, true);
+
+ // Commit a load.
+ content::WebContentsTester::For(web_contents())
+ ->NavigateAndCommit(GURL(kGoodHTTPSURL));
+
+ // Simulate a subresource load causing a safe browsing interstitial to be
+ // shown.
+ ShowInterstitial(true, kBadURL);
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
+ ASSERT_TRUE(sb_interstitial);
+ EXPECT_FALSE(sb_interstitial->CanShowThreatDetailsOption());
+
+ base::RunLoop().RunUntilIdle();
+
+ // Simulate the user clicking "don't proceed".
+ DontProceedThroughInterstitial(sb_interstitial);
+
+ // The interstitial should be gone.
+ EXPECT_EQ(CANCEL, user_response());
+ EXPECT_FALSE(GetSafeBrowsingBlockingPage());
+
+ // No report should have been sent.
+ EXPECT_EQ(0u, ui_manager_->GetDetails()->size());
+ ui_manager_->GetDetails()->clear();
+}
+
+// Test that extended reporting option is shown on blocking an HTTPS
+// subresource on an HTTP page.
+TEST_F(SafeBrowsingBlockingPageTest,
+ ExtendedReportingOnInsecurePageWithSecureSubresource) {
+ // Enable malware details.
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents()->GetBrowserContext());
+ profile->GetPrefs()->SetBoolean(
+ prefs::kSafeBrowsingExtendedReportingEnabled, true);
+
+ // Commit a load.
+ content::WebContentsTester::For(web_contents())
+ ->NavigateAndCommit(GURL(kGoodURL));
+
+ // Simulate a subresource load causing a safe browsing interstitial to be
+ // shown.
+ ShowInterstitial(true, kBadHTTPSURL);
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
+ ASSERT_TRUE(sb_interstitial);
+ EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption());
+
+ base::RunLoop().RunUntilIdle();
+
+ // Simulate the user clicking "don't proceed".
+ DontProceedThroughInterstitial(sb_interstitial);
+
+ // The interstitial should be gone.
+ EXPECT_EQ(CANCEL, user_response());
+ EXPECT_FALSE(GetSafeBrowsingBlockingPage());
+
+ // A report should have been sent.
+ EXPECT_EQ(1u, ui_manager_->GetDetails()->size());
+ ui_manager_->GetDetails()->clear();
+}
+
+// Test that extended reporting option is not shown on blocking an HTTPS
+// subresource on an HTTPS page while there is a pending load for an HTTP page,
+// and no report is sent.
+TEST_F(SafeBrowsingBlockingPageTest,
+ ExtendedReportingNotShownOnSecurePageWithPendingInsecureLoad) {
+ // Enable malware details.
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents()->GetBrowserContext());
+ profile->GetPrefs()->SetBoolean(
+ prefs::kSafeBrowsingExtendedReportingEnabled, true);
+
+ // Commit a load.
+ content::WebContentsTester::For(web_contents())
+ ->NavigateAndCommit(GURL(kGoodHTTPSURL));
+
+ GURL pending_url("http://slow.example.com");
+
+ // Start a pending load.
+ content::WebContentsTester::For(web_contents())->StartNavigation(pending_url);
+
+ // Simulate a subresource load on the committed page causing a safe browsing
+ // interstitial to be shown.
+ ShowInterstitial(true, kBadHTTPSURL);
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
+ ASSERT_TRUE(sb_interstitial);
+ // Threat details option should not be shown. (The blocking page is for the
+ // committed HTTPS page, not the pending HTTP page.)
+ EXPECT_FALSE(sb_interstitial->CanShowThreatDetailsOption());
+
+ base::RunLoop().RunUntilIdle();
+
+ // Simulate the user clicking "don't proceed".
+ DontProceedThroughInterstitial(sb_interstitial);
+
+ // The interstitial should be gone.
+ EXPECT_EQ(CANCEL, user_response());
+ EXPECT_FALSE(GetSafeBrowsingBlockingPage());
+
+ // No report should have been sent.
+ EXPECT_EQ(0u, ui_manager_->GetDetails()->size());
+ ui_manager_->GetDetails()->clear();
+}
+
+// TODO(mattm): Add test for extended reporting not shown or sent in incognito
+// window.
+
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698