| OLD | NEW |
| 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 #include <list> | 5 #include <list> |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/safe_browsing/malware_details.h" | 10 #include "chrome/browser/safe_browsing/malware_details.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 void OnBlockingPageComplete(bool proceed) { | 117 void OnBlockingPageComplete(bool proceed) { |
| 118 if (proceed) | 118 if (proceed) |
| 119 user_response_ = OK; | 119 user_response_ = OK; |
| 120 else | 120 else |
| 121 user_response_ = CANCEL; | 121 user_response_ = CANCEL; |
| 122 } | 122 } |
| 123 | 123 |
| 124 void Navigate(const char* url, int page_id) { | 124 void Navigate(const char* url, int page_id) { |
| 125 WebContentsTester::For(web_contents())->TestDidNavigate( | 125 WebContentsTester::For(web_contents())->TestDidNavigate( |
| 126 web_contents()->GetMainFrame(), page_id, GURL(url), | 126 web_contents()->GetMainFrame(), page_id, GURL(url), |
| 127 content::PAGE_TRANSITION_TYPED); | 127 ui::PAGE_TRANSITION_TYPED); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void GoBack(bool is_cross_site) { | 130 void GoBack(bool is_cross_site) { |
| 131 NavigationEntry* entry = | 131 NavigationEntry* entry = |
| 132 web_contents()->GetController().GetEntryAtOffset(-1); | 132 web_contents()->GetController().GetEntryAtOffset(-1); |
| 133 ASSERT_TRUE(entry); | 133 ASSERT_TRUE(entry); |
| 134 web_contents()->GetController().GoBack(); | 134 web_contents()->GetController().GoBack(); |
| 135 | 135 |
| 136 // The pending RVH should commit for cross-site navigations. | 136 // The pending RVH should commit for cross-site navigations. |
| 137 content::RenderFrameHost* rfh = is_cross_site ? | 137 content::RenderFrameHost* rfh = is_cross_site ? |
| 138 WebContentsTester::For(web_contents())->GetPendingMainFrame() : | 138 WebContentsTester::For(web_contents())->GetPendingMainFrame() : |
| 139 web_contents()->GetMainFrame(); | 139 web_contents()->GetMainFrame(); |
| 140 WebContentsTester::For(web_contents())->TestDidNavigate( | 140 WebContentsTester::For(web_contents())->TestDidNavigate( |
| 141 rfh, | 141 rfh, |
| 142 entry->GetPageID(), | 142 entry->GetPageID(), |
| 143 GURL(entry->GetURL()), | 143 GURL(entry->GetURL()), |
| 144 content::PAGE_TRANSITION_TYPED); | 144 ui::PAGE_TRANSITION_TYPED); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void ShowInterstitial(bool is_subresource, const char* url) { | 147 void ShowInterstitial(bool is_subresource, const char* url) { |
| 148 SafeBrowsingUIManager::UnsafeResource resource; | 148 SafeBrowsingUIManager::UnsafeResource resource; |
| 149 InitResource(&resource, is_subresource, GURL(url)); | 149 InitResource(&resource, is_subresource, GURL(url)); |
| 150 SafeBrowsingBlockingPage::ShowBlockingPage(ui_manager_.get(), resource); | 150 SafeBrowsingBlockingPage::ShowBlockingPage(ui_manager_.get(), resource); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is | 153 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is |
| 154 // showing. | 154 // showing. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // Tests showing a blocking page for a malware page and not proceeding. | 213 // Tests showing a blocking page for a malware page and not proceeding. |
| 214 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { | 214 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { |
| 215 // Enable malware details. | 215 // Enable malware details. |
| 216 Profile* profile = Profile::FromBrowserContext( | 216 Profile* profile = Profile::FromBrowserContext( |
| 217 web_contents()->GetBrowserContext()); | 217 web_contents()->GetBrowserContext()); |
| 218 profile->GetPrefs()->SetBoolean( | 218 profile->GetPrefs()->SetBoolean( |
| 219 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 219 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
| 220 | 220 |
| 221 // Start a load. | 221 // Start a load. |
| 222 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 222 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 223 content::PAGE_TRANSITION_TYPED, std::string()); | 223 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 224 | 224 |
| 225 | 225 |
| 226 // Simulate the load causing a safe browsing interstitial to be shown. | 226 // Simulate the load causing a safe browsing interstitial to be shown. |
| 227 ShowInterstitial(false, kBadURL); | 227 ShowInterstitial(false, kBadURL); |
| 228 SafeBrowsingBlockingPage* sb_interstitial = | 228 SafeBrowsingBlockingPage* sb_interstitial = |
| 229 GetSafeBrowsingBlockingPage(); | 229 GetSafeBrowsingBlockingPage(); |
| 230 ASSERT_TRUE(sb_interstitial); | 230 ASSERT_TRUE(sb_interstitial); |
| 231 | 231 |
| 232 base::RunLoop().RunUntilIdle(); | 232 base::RunLoop().RunUntilIdle(); |
| 233 | 233 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 249 // Tests showing a blocking page for a malware page and then proceeding. | 249 // Tests showing a blocking page for a malware page and then proceeding. |
| 250 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { | 250 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { |
| 251 // Enable malware reports. | 251 // Enable malware reports. |
| 252 Profile* profile = Profile::FromBrowserContext( | 252 Profile* profile = Profile::FromBrowserContext( |
| 253 web_contents()->GetBrowserContext()); | 253 web_contents()->GetBrowserContext()); |
| 254 profile->GetPrefs()->SetBoolean( | 254 profile->GetPrefs()->SetBoolean( |
| 255 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 255 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
| 256 | 256 |
| 257 // Start a load. | 257 // Start a load. |
| 258 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 258 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 259 content::PAGE_TRANSITION_TYPED, std::string()); | 259 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 260 | 260 |
| 261 // Simulate the load causing a safe browsing interstitial to be shown. | 261 // Simulate the load causing a safe browsing interstitial to be shown. |
| 262 ShowInterstitial(false, kBadURL); | 262 ShowInterstitial(false, kBadURL); |
| 263 SafeBrowsingBlockingPage* sb_interstitial = | 263 SafeBrowsingBlockingPage* sb_interstitial = |
| 264 GetSafeBrowsingBlockingPage(); | 264 GetSafeBrowsingBlockingPage(); |
| 265 ASSERT_TRUE(sb_interstitial); | 265 ASSERT_TRUE(sb_interstitial); |
| 266 | 266 |
| 267 // Simulate the user clicking "proceed". | 267 // Simulate the user clicking "proceed". |
| 268 ProceedThroughInterstitial(sb_interstitial); | 268 ProceedThroughInterstitial(sb_interstitial); |
| 269 | 269 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 Profile* profile = Profile::FromBrowserContext( | 513 Profile* profile = Profile::FromBrowserContext( |
| 514 web_contents()->GetBrowserContext()); | 514 web_contents()->GetBrowserContext()); |
| 515 profile->GetPrefs()->SetBoolean( | 515 profile->GetPrefs()->SetBoolean( |
| 516 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 516 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
| 517 | 517 |
| 518 // Navigate somewhere. | 518 // Navigate somewhere. |
| 519 Navigate(kGoodURL, 1); | 519 Navigate(kGoodURL, 1); |
| 520 | 520 |
| 521 // Now navigate to a bad page triggerring an interstitial. | 521 // Now navigate to a bad page triggerring an interstitial. |
| 522 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 522 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 523 content::PAGE_TRANSITION_TYPED, std::string()); | 523 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 524 ShowInterstitial(false, kBadURL); | 524 ShowInterstitial(false, kBadURL); |
| 525 SafeBrowsingBlockingPage* sb_interstitial = | 525 SafeBrowsingBlockingPage* sb_interstitial = |
| 526 GetSafeBrowsingBlockingPage(); | 526 GetSafeBrowsingBlockingPage(); |
| 527 ASSERT_TRUE(sb_interstitial); | 527 ASSERT_TRUE(sb_interstitial); |
| 528 | 528 |
| 529 // Proceed, then navigate back. | 529 // Proceed, then navigate back. |
| 530 ProceedThroughInterstitial(sb_interstitial); | 530 ProceedThroughInterstitial(sb_interstitial); |
| 531 Navigate(kBadURL, 2); // Commit the navigation. | 531 Navigate(kBadURL, 2); // Commit the navigation. |
| 532 GoBack(true); | 532 GoBack(true); |
| 533 | 533 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 560 // cause problems. http://crbug.com/30079 | 560 // cause problems. http://crbug.com/30079 |
| 561 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { | 561 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { |
| 562 // Enable malware reports. | 562 // Enable malware reports. |
| 563 Profile* profile = Profile::FromBrowserContext( | 563 Profile* profile = Profile::FromBrowserContext( |
| 564 web_contents()->GetBrowserContext()); | 564 web_contents()->GetBrowserContext()); |
| 565 profile->GetPrefs()->SetBoolean( | 565 profile->GetPrefs()->SetBoolean( |
| 566 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 566 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
| 567 | 567 |
| 568 // Start a load. | 568 // Start a load. |
| 569 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 569 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 570 content::PAGE_TRANSITION_TYPED, std::string()); | 570 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 571 | 571 |
| 572 // Simulate the load causing a safe browsing interstitial to be shown. | 572 // Simulate the load causing a safe browsing interstitial to be shown. |
| 573 ShowInterstitial(false, kBadURL); | 573 ShowInterstitial(false, kBadURL); |
| 574 SafeBrowsingBlockingPage* sb_interstitial = | 574 SafeBrowsingBlockingPage* sb_interstitial = |
| 575 GetSafeBrowsingBlockingPage(); | 575 GetSafeBrowsingBlockingPage(); |
| 576 ASSERT_TRUE(sb_interstitial); | 576 ASSERT_TRUE(sb_interstitial); |
| 577 | 577 |
| 578 base::RunLoop().RunUntilIdle(); | 578 base::RunLoop().RunUntilIdle(); |
| 579 | 579 |
| 580 // Simulate the user clicking "proceed" then "don't proceed" (before the | 580 // Simulate the user clicking "proceed" then "don't proceed" (before the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 597 // Tests showing a blocking page for a malware page with reports disabled. | 597 // Tests showing a blocking page for a malware page with reports disabled. |
| 598 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { | 598 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { |
| 599 // Disable malware reports. | 599 // Disable malware reports. |
| 600 Profile* profile = Profile::FromBrowserContext( | 600 Profile* profile = Profile::FromBrowserContext( |
| 601 web_contents()->GetBrowserContext()); | 601 web_contents()->GetBrowserContext()); |
| 602 profile->GetPrefs()->SetBoolean( | 602 profile->GetPrefs()->SetBoolean( |
| 603 prefs::kSafeBrowsingExtendedReportingEnabled, false); | 603 prefs::kSafeBrowsingExtendedReportingEnabled, false); |
| 604 | 604 |
| 605 // Start a load. | 605 // Start a load. |
| 606 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 606 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 607 content::PAGE_TRANSITION_TYPED, std::string()); | 607 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 608 | 608 |
| 609 // Simulate the load causing a safe browsing interstitial to be shown. | 609 // Simulate the load causing a safe browsing interstitial to be shown. |
| 610 ShowInterstitial(false, kBadURL); | 610 ShowInterstitial(false, kBadURL); |
| 611 SafeBrowsingBlockingPage* sb_interstitial = | 611 SafeBrowsingBlockingPage* sb_interstitial = |
| 612 GetSafeBrowsingBlockingPage(); | 612 GetSafeBrowsingBlockingPage(); |
| 613 ASSERT_TRUE(sb_interstitial); | 613 ASSERT_TRUE(sb_interstitial); |
| 614 | 614 |
| 615 base::RunLoop().RunUntilIdle(); | 615 base::RunLoop().RunUntilIdle(); |
| 616 | 616 |
| 617 // Simulate the user clicking "don't proceed". | 617 // Simulate the user clicking "don't proceed". |
| (...skipping 14 matching lines...) Expand all Loading... |
| 632 // Test that toggling the checkbox has the anticipated effects. | 632 // Test that toggling the checkbox has the anticipated effects. |
| 633 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) { | 633 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) { |
| 634 // Disable malware reports. | 634 // Disable malware reports. |
| 635 Profile* profile = Profile::FromBrowserContext( | 635 Profile* profile = Profile::FromBrowserContext( |
| 636 web_contents()->GetBrowserContext()); | 636 web_contents()->GetBrowserContext()); |
| 637 profile->GetPrefs()->SetBoolean( | 637 profile->GetPrefs()->SetBoolean( |
| 638 prefs::kSafeBrowsingExtendedReportingEnabled, false); | 638 prefs::kSafeBrowsingExtendedReportingEnabled, false); |
| 639 | 639 |
| 640 // Start a load. | 640 // Start a load. |
| 641 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 641 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 642 content::PAGE_TRANSITION_TYPED, std::string()); | 642 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 643 | 643 |
| 644 // Simulate the load causing a safe browsing interstitial to be shown. | 644 // Simulate the load causing a safe browsing interstitial to be shown. |
| 645 ShowInterstitial(false, kBadURL); | 645 ShowInterstitial(false, kBadURL); |
| 646 SafeBrowsingBlockingPage* sb_interstitial = | 646 SafeBrowsingBlockingPage* sb_interstitial = |
| 647 GetSafeBrowsingBlockingPage(); | 647 GetSafeBrowsingBlockingPage(); |
| 648 ASSERT_TRUE(sb_interstitial); | 648 ASSERT_TRUE(sb_interstitial); |
| 649 | 649 |
| 650 base::RunLoop().RunUntilIdle(); | 650 base::RunLoop().RunUntilIdle(); |
| 651 | 651 |
| 652 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 652 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( |
| 653 prefs::kSafeBrowsingExtendedReportingEnabled)); | 653 prefs::kSafeBrowsingExtendedReportingEnabled)); |
| 654 | 654 |
| 655 // Simulate the user check the report agreement checkbox. | 655 // Simulate the user check the report agreement checkbox. |
| 656 sb_interstitial->SetReportingPreference(true); | 656 sb_interstitial->SetReportingPreference(true); |
| 657 | 657 |
| 658 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( | 658 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( |
| 659 prefs::kSafeBrowsingExtendedReportingEnabled)); | 659 prefs::kSafeBrowsingExtendedReportingEnabled)); |
| 660 | 660 |
| 661 // Simulate the user uncheck the report agreement checkbox. | 661 // Simulate the user uncheck the report agreement checkbox. |
| 662 sb_interstitial->SetReportingPreference(false); | 662 sb_interstitial->SetReportingPreference(false); |
| 663 | 663 |
| 664 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 664 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( |
| 665 prefs::kSafeBrowsingExtendedReportingEnabled)); | 665 prefs::kSafeBrowsingExtendedReportingEnabled)); |
| 666 } | 666 } |
| OLD | NEW |