OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 5 |
6 #include "chrome/browser/prefs/pref_service.h" | 6 #include "chrome/browser/prefs/pref_service.h" |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/safe_browsing/malware_details.h" | 8 #include "chrome/browser/safe_browsing/malware_details.h" |
9 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 content::TestBrowserThread io_thread_; | 182 content::TestBrowserThread io_thread_; |
183 }; | 183 }; |
184 | 184 |
185 // Tests showing a blocking page for a malware page and not proceeding. | 185 // Tests showing a blocking page for a malware page and not proceeding. |
186 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { | 186 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { |
187 // Enable malware details. | 187 // Enable malware details. |
188 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); | 188 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); |
189 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 189 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
190 | 190 |
191 // Start a load. | 191 // Start a load. |
192 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED, | 192 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
193 std::string()); | 193 content::PAGE_TRANSITION_TYPED, std::string()); |
194 | 194 |
195 | 195 |
196 // Simulate the load causing a safe browsing interstitial to be shown. | 196 // Simulate the load causing a safe browsing interstitial to be shown. |
197 ShowInterstitial(false, kBadURL); | 197 ShowInterstitial(false, kBadURL); |
198 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 198 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
199 ASSERT_TRUE(sb_interstitial); | 199 ASSERT_TRUE(sb_interstitial); |
200 | 200 |
201 MessageLoop::current()->RunAllPending(); | 201 MessageLoop::current()->RunAllPending(); |
202 | 202 |
203 // Simulate the user clicking "don't proceed". | 203 // Simulate the user clicking "don't proceed". |
(...skipping 11 matching lines...) Expand all Loading... |
215 service_->GetDetails()->clear(); | 215 service_->GetDetails()->clear(); |
216 } | 216 } |
217 | 217 |
218 // Tests showing a blocking page for a malware page and then proceeding. | 218 // Tests showing a blocking page for a malware page and then proceeding. |
219 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { | 219 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { |
220 // Enable malware reports. | 220 // Enable malware reports. |
221 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); | 221 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); |
222 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 222 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
223 | 223 |
224 // Start a load. | 224 // Start a load. |
225 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED, | 225 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
226 std::string()); | 226 content::PAGE_TRANSITION_TYPED, std::string()); |
227 | 227 |
228 // Simulate the load causing a safe browsing interstitial to be shown. | 228 // Simulate the load causing a safe browsing interstitial to be shown. |
229 ShowInterstitial(false, kBadURL); | 229 ShowInterstitial(false, kBadURL); |
230 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 230 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
231 ASSERT_TRUE(sb_interstitial); | 231 ASSERT_TRUE(sb_interstitial); |
232 | 232 |
233 // Simulate the user clicking "proceed". | 233 // Simulate the user clicking "proceed". |
234 ProceedThroughInterstitial(sb_interstitial); | 234 ProceedThroughInterstitial(sb_interstitial); |
235 | 235 |
236 // The interstitial is shown until the navigation commits. | 236 // The interstitial is shown until the navigation commits. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // controller entries are OK. http://crbug.com/17627 | 460 // controller entries are OK. http://crbug.com/17627 |
461 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { | 461 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { |
462 // Enable malware reports. | 462 // Enable malware reports. |
463 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); | 463 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); |
464 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 464 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
465 | 465 |
466 // Navigate somewhere. | 466 // Navigate somewhere. |
467 Navigate(kGoodURL, 1); | 467 Navigate(kGoodURL, 1); |
468 | 468 |
469 // Now navigate to a bad page triggerring an interstitial. | 469 // Now navigate to a bad page triggerring an interstitial. |
470 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED, | 470 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
471 std::string()); | 471 content::PAGE_TRANSITION_TYPED, std::string()); |
472 ShowInterstitial(false, kBadURL); | 472 ShowInterstitial(false, kBadURL); |
473 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 473 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
474 ASSERT_TRUE(sb_interstitial); | 474 ASSERT_TRUE(sb_interstitial); |
475 | 475 |
476 // Proceed, then navigate back. | 476 // Proceed, then navigate back. |
477 ProceedThroughInterstitial(sb_interstitial); | 477 ProceedThroughInterstitial(sb_interstitial); |
478 Navigate(kBadURL, 2); // Commit the navigation. | 478 Navigate(kBadURL, 2); // Commit the navigation. |
479 GoBackCrossSite(); | 479 GoBackCrossSite(); |
480 | 480 |
481 // We are back on the good page. | 481 // We are back on the good page. |
(...skipping 22 matching lines...) Expand all Loading... |
504 } | 504 } |
505 | 505 |
506 // Tests that calling "don't proceed" after "proceed" has been called doesn't | 506 // Tests that calling "don't proceed" after "proceed" has been called doesn't |
507 // cause problems. http://crbug.com/30079 | 507 // cause problems. http://crbug.com/30079 |
508 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { | 508 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { |
509 // Enable malware reports. | 509 // Enable malware reports. |
510 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); | 510 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); |
511 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 511 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
512 | 512 |
513 // Start a load. | 513 // Start a load. |
514 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED, | 514 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
515 std::string()); | 515 content::PAGE_TRANSITION_TYPED, std::string()); |
516 | 516 |
517 // Simulate the load causing a safe browsing interstitial to be shown. | 517 // Simulate the load causing a safe browsing interstitial to be shown. |
518 ShowInterstitial(false, kBadURL); | 518 ShowInterstitial(false, kBadURL); |
519 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 519 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
520 ASSERT_TRUE(sb_interstitial); | 520 ASSERT_TRUE(sb_interstitial); |
521 | 521 |
522 MessageLoop::current()->RunAllPending(); | 522 MessageLoop::current()->RunAllPending(); |
523 | 523 |
524 // Simulate the user clicking "proceed" then "don't proceed" (before the | 524 // Simulate the user clicking "proceed" then "don't proceed" (before the |
525 // interstitial is shown). | 525 // interstitial is shown). |
(...skipping 12 matching lines...) Expand all Loading... |
538 service_->GetDetails()->clear(); | 538 service_->GetDetails()->clear(); |
539 } | 539 } |
540 | 540 |
541 // Tests showing a blocking page for a malware page with reports disabled. | 541 // Tests showing a blocking page for a malware page with reports disabled. |
542 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { | 542 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { |
543 // Disable malware reports. | 543 // Disable malware reports. |
544 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); | 544 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); |
545 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); | 545 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); |
546 | 546 |
547 // Start a load. | 547 // Start a load. |
548 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED, | 548 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
549 std::string()); | 549 content::PAGE_TRANSITION_TYPED, std::string()); |
550 | 550 |
551 // Simulate the load causing a safe browsing interstitial to be shown. | 551 // Simulate the load causing a safe browsing interstitial to be shown. |
552 ShowInterstitial(false, kBadURL); | 552 ShowInterstitial(false, kBadURL); |
553 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 553 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
554 ASSERT_TRUE(sb_interstitial); | 554 ASSERT_TRUE(sb_interstitial); |
555 | 555 |
556 MessageLoop::current()->RunAllPending(); | 556 MessageLoop::current()->RunAllPending(); |
557 | 557 |
558 // Simulate the user clicking "don't proceed". | 558 // Simulate the user clicking "don't proceed". |
559 DontProceedThroughInterstitial(sb_interstitial); | 559 DontProceedThroughInterstitial(sb_interstitial); |
(...skipping 10 matching lines...) Expand all Loading... |
570 service_->GetDetails()->clear(); | 570 service_->GetDetails()->clear(); |
571 } | 571 } |
572 | 572 |
573 // Test setting the malware report preferance | 573 // Test setting the malware report preferance |
574 TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { | 574 TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { |
575 // Disable malware reports. | 575 // Disable malware reports. |
576 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); | 576 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); |
577 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); | 577 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); |
578 | 578 |
579 // Start a load. | 579 // Start a load. |
580 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED, | 580 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
581 std::string()); | 581 content::PAGE_TRANSITION_TYPED, std::string()); |
582 | 582 |
583 // Simulate the load causing a safe browsing interstitial to be shown. | 583 // Simulate the load causing a safe browsing interstitial to be shown. |
584 ShowInterstitial(false, kBadURL); | 584 ShowInterstitial(false, kBadURL); |
585 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 585 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
586 ASSERT_TRUE(sb_interstitial); | 586 ASSERT_TRUE(sb_interstitial); |
587 | 587 |
588 MessageLoop::current()->RunAllPending(); | 588 MessageLoop::current()->RunAllPending(); |
589 | 589 |
590 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 590 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( |
591 prefs::kSafeBrowsingReportingEnabled)); | 591 prefs::kSafeBrowsingReportingEnabled)); |
592 | 592 |
593 // Simulate the user check the report agreement checkbox. | 593 // Simulate the user check the report agreement checkbox. |
594 sb_interstitial->SetReportingPreference(true); | 594 sb_interstitial->SetReportingPreference(true); |
595 | 595 |
596 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( | 596 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( |
597 prefs::kSafeBrowsingReportingEnabled)); | 597 prefs::kSafeBrowsingReportingEnabled)); |
598 | 598 |
599 // Simulate the user uncheck the report agreement checkbox. | 599 // Simulate the user uncheck the report agreement checkbox. |
600 sb_interstitial->SetReportingPreference(false); | 600 sb_interstitial->SetReportingPreference(false); |
601 | 601 |
602 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 602 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( |
603 prefs::kSafeBrowsingReportingEnabled)); | 603 prefs::kSafeBrowsingReportingEnabled)); |
604 } | 604 } |
OLD | NEW |