| 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/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chrome/browser/interstitials/chrome_controller_client.h" | 8 #include "chrome/browser/interstitials/chrome_controller_client.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 11 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | 11 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
| 12 #include "chrome/browser/safe_browsing/threat_details.h" | 12 #include "chrome/browser/safe_browsing/threat_details.h" |
| 13 #include "chrome/browser/safe_browsing/ui_manager.h" | 13 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 14 #include "chrome/common/pref_names.h" | |
| 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 16 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 16 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 17 #include "content/public/browser/interstitial_page.h" | 17 #include "content/public/browser/interstitial_page.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/test/web_contents_tester.h" | 21 #include "content/public/test/web_contents_tester.h" |
| 22 | 22 |
| 23 using content::InterstitialPage; | 23 using content::InterstitialPage; |
| 24 using content::NavigationEntry; | 24 using content::NavigationEntry; |
| 25 using content::WebContents; | 25 using content::WebContents; |
| 26 using content::WebContentsTester; | 26 using content::WebContentsTester; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 UserResponse user_response_; | 224 UserResponse user_response_; |
| 225 TestSafeBrowsingBlockingPageFactory factory_; | 225 TestSafeBrowsingBlockingPageFactory factory_; |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 | 228 |
| 229 // Tests showing a blocking page for a malware page and not proceeding. | 229 // Tests showing a blocking page for a malware page and not proceeding. |
| 230 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { | 230 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { |
| 231 // Enable malware details. | 231 // Enable malware details. |
| 232 Profile* profile = Profile::FromBrowserContext( | 232 Profile* profile = Profile::FromBrowserContext( |
| 233 web_contents()->GetBrowserContext()); | 233 web_contents()->GetBrowserContext()); |
| 234 profile->GetPrefs()->SetBoolean( | 234 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 235 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 236 | 235 |
| 237 // Start a load. | 236 // Start a load. |
| 238 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 237 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 239 ui::PAGE_TRANSITION_TYPED, std::string()); | 238 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 240 | 239 |
| 241 | 240 |
| 242 // Simulate the load causing a safe browsing interstitial to be shown. | 241 // Simulate the load causing a safe browsing interstitial to be shown. |
| 243 ShowInterstitial(false, kBadURL); | 242 ShowInterstitial(false, kBadURL); |
| 244 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 243 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 245 ASSERT_TRUE(sb_interstitial); | 244 ASSERT_TRUE(sb_interstitial); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 259 // A report should have been sent. | 258 // A report should have been sent. |
| 260 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); | 259 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
| 261 ui_manager_->GetThreatDetails()->clear(); | 260 ui_manager_->GetThreatDetails()->clear(); |
| 262 } | 261 } |
| 263 | 262 |
| 264 // Tests showing a blocking page for a malware page and then proceeding. | 263 // Tests showing a blocking page for a malware page and then proceeding. |
| 265 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { | 264 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { |
| 266 // Enable malware reports. | 265 // Enable malware reports. |
| 267 Profile* profile = Profile::FromBrowserContext( | 266 Profile* profile = Profile::FromBrowserContext( |
| 268 web_contents()->GetBrowserContext()); | 267 web_contents()->GetBrowserContext()); |
| 269 profile->GetPrefs()->SetBoolean( | 268 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 270 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 271 | 269 |
| 272 // Start a load. | 270 // Start a load. |
| 273 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 271 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 274 ui::PAGE_TRANSITION_TYPED, std::string()); | 272 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 275 int pending_id = controller().GetPendingEntry()->GetUniqueID(); | 273 int pending_id = controller().GetPendingEntry()->GetUniqueID(); |
| 276 | 274 |
| 277 // Simulate the load causing a safe browsing interstitial to be shown. | 275 // Simulate the load causing a safe browsing interstitial to be shown. |
| 278 ShowInterstitial(false, kBadURL); | 276 ShowInterstitial(false, kBadURL); |
| 279 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 277 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 280 ASSERT_TRUE(sb_interstitial); | 278 ASSERT_TRUE(sb_interstitial); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 293 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); | 291 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
| 294 ui_manager_->GetThreatDetails()->clear(); | 292 ui_manager_->GetThreatDetails()->clear(); |
| 295 } | 293 } |
| 296 | 294 |
| 297 // Tests showing a blocking page for a page that contains malware subresources | 295 // Tests showing a blocking page for a page that contains malware subresources |
| 298 // and not proceeding. | 296 // and not proceeding. |
| 299 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { | 297 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { |
| 300 // Enable malware reports. | 298 // Enable malware reports. |
| 301 Profile* profile = Profile::FromBrowserContext( | 299 Profile* profile = Profile::FromBrowserContext( |
| 302 web_contents()->GetBrowserContext()); | 300 web_contents()->GetBrowserContext()); |
| 303 profile->GetPrefs()->SetBoolean( | 301 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 304 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 305 | 302 |
| 306 // Navigate somewhere. | 303 // Navigate somewhere. |
| 307 Navigate(kGoogleURL, 0, true); | 304 Navigate(kGoogleURL, 0, true); |
| 308 | 305 |
| 309 // Navigate somewhere else. | 306 // Navigate somewhere else. |
| 310 Navigate(kGoodURL, 0, true); | 307 Navigate(kGoodURL, 0, true); |
| 311 | 308 |
| 312 // Simulate that page loading a bad-resource triggering an interstitial. | 309 // Simulate that page loading a bad-resource triggering an interstitial. |
| 313 ShowInterstitial(true, kBadURL); | 310 ShowInterstitial(true, kBadURL); |
| 314 | 311 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 329 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); | 326 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
| 330 ui_manager_->GetThreatDetails()->clear(); | 327 ui_manager_->GetThreatDetails()->clear(); |
| 331 } | 328 } |
| 332 | 329 |
| 333 // Tests showing a blocking page for a page that contains malware subresources | 330 // Tests showing a blocking page for a page that contains malware subresources |
| 334 // and proceeding. | 331 // and proceeding. |
| 335 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { | 332 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { |
| 336 // Enable malware reports. | 333 // Enable malware reports. |
| 337 Profile* profile = Profile::FromBrowserContext( | 334 Profile* profile = Profile::FromBrowserContext( |
| 338 web_contents()->GetBrowserContext()); | 335 web_contents()->GetBrowserContext()); |
| 339 profile->GetPrefs()->SetBoolean( | 336 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 340 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 341 | 337 |
| 342 // Navigate somewhere. | 338 // Navigate somewhere. |
| 343 Navigate(kGoodURL, 0, true); | 339 Navigate(kGoodURL, 0, true); |
| 344 | 340 |
| 345 // Simulate that page loading a bad-resource triggering an interstitial. | 341 // Simulate that page loading a bad-resource triggering an interstitial. |
| 346 ShowInterstitial(true, kBadURL); | 342 ShowInterstitial(true, kBadURL); |
| 347 | 343 |
| 348 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 344 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 349 ASSERT_TRUE(sb_interstitial); | 345 ASSERT_TRUE(sb_interstitial); |
| 350 | 346 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 363 } | 359 } |
| 364 | 360 |
| 365 // Tests showing a blocking page for a page that contains multiple malware | 361 // Tests showing a blocking page for a page that contains multiple malware |
| 366 // subresources and not proceeding. This just tests that the extra malware | 362 // subresources and not proceeding. This just tests that the extra malware |
| 367 // subresources (which trigger queued interstitial pages) do not break anything. | 363 // subresources (which trigger queued interstitial pages) do not break anything. |
| 368 TEST_F(SafeBrowsingBlockingPageTest, | 364 TEST_F(SafeBrowsingBlockingPageTest, |
| 369 PageWithMultipleMalwareResourceDontProceed) { | 365 PageWithMultipleMalwareResourceDontProceed) { |
| 370 // Enable malware reports. | 366 // Enable malware reports. |
| 371 Profile* profile = Profile::FromBrowserContext( | 367 Profile* profile = Profile::FromBrowserContext( |
| 372 web_contents()->GetBrowserContext()); | 368 web_contents()->GetBrowserContext()); |
| 373 profile->GetPrefs()->SetBoolean( | 369 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 374 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 375 | 370 |
| 376 // Navigate somewhere. | 371 // Navigate somewhere. |
| 377 Navigate(kGoogleURL, 0, true); | 372 Navigate(kGoogleURL, 0, true); |
| 378 | 373 |
| 379 // Navigate somewhere else. | 374 // Navigate somewhere else. |
| 380 Navigate(kGoodURL, 0, true); | 375 Navigate(kGoodURL, 0, true); |
| 381 | 376 |
| 382 // Simulate that page loading a bad-resource triggering an interstitial. | 377 // Simulate that page loading a bad-resource triggering an interstitial. |
| 383 ShowInterstitial(true, kBadURL); | 378 ShowInterstitial(true, kBadURL); |
| 384 | 379 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 405 ui_manager_->GetThreatDetails()->clear(); | 400 ui_manager_->GetThreatDetails()->clear(); |
| 406 } | 401 } |
| 407 | 402 |
| 408 // Tests showing a blocking page for a page that contains multiple malware | 403 // Tests showing a blocking page for a page that contains multiple malware |
| 409 // subresources and proceeding through the first interstitial, but not the next. | 404 // subresources and proceeding through the first interstitial, but not the next. |
| 410 TEST_F(SafeBrowsingBlockingPageTest, | 405 TEST_F(SafeBrowsingBlockingPageTest, |
| 411 PageWithMultipleMalwareResourceProceedThenDontProceed) { | 406 PageWithMultipleMalwareResourceProceedThenDontProceed) { |
| 412 // Enable malware reports. | 407 // Enable malware reports. |
| 413 Profile* profile = Profile::FromBrowserContext( | 408 Profile* profile = Profile::FromBrowserContext( |
| 414 web_contents()->GetBrowserContext()); | 409 web_contents()->GetBrowserContext()); |
| 415 profile->GetPrefs()->SetBoolean( | 410 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 416 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 417 | 411 |
| 418 // Navigate somewhere. | 412 // Navigate somewhere. |
| 419 Navigate(kGoogleURL, 0, true); | 413 Navigate(kGoogleURL, 0, true); |
| 420 | 414 |
| 421 // Navigate somewhere else. | 415 // Navigate somewhere else. |
| 422 Navigate(kGoodURL, 0, true); | 416 Navigate(kGoodURL, 0, true); |
| 423 | 417 |
| 424 // Simulate that page loading a bad-resource triggering an interstitial. | 418 // Simulate that page loading a bad-resource triggering an interstitial. |
| 425 ShowInterstitial(true, kBadURL); | 419 ShowInterstitial(true, kBadURL); |
| 426 | 420 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 456 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
| 463 ui_manager_->GetThreatDetails()->clear(); | 457 ui_manager_->GetThreatDetails()->clear(); |
| 464 } | 458 } |
| 465 | 459 |
| 466 // Tests showing a blocking page for a page that contains multiple malware | 460 // Tests showing a blocking page for a page that contains multiple malware |
| 467 // subresources and proceeding through the multiple interstitials. | 461 // subresources and proceeding through the multiple interstitials. |
| 468 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { | 462 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { |
| 469 // Enable malware reports. | 463 // Enable malware reports. |
| 470 Profile* profile = Profile::FromBrowserContext( | 464 Profile* profile = Profile::FromBrowserContext( |
| 471 web_contents()->GetBrowserContext()); | 465 web_contents()->GetBrowserContext()); |
| 472 profile->GetPrefs()->SetBoolean( | 466 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 473 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 474 | 467 |
| 475 // Navigate somewhere else. | 468 // Navigate somewhere else. |
| 476 Navigate(kGoodURL, 0, true); | 469 Navigate(kGoodURL, 0, true); |
| 477 | 470 |
| 478 // Simulate that page loading a bad-resource triggering an interstitial. | 471 // Simulate that page loading a bad-resource triggering an interstitial. |
| 479 ShowInterstitial(true, kBadURL); | 472 ShowInterstitial(true, kBadURL); |
| 480 | 473 |
| 481 // More bad resources loading causing more interstitials. The new | 474 // More bad resources loading causing more interstitials. The new |
| 482 // interstitials should be queued. | 475 // interstitials should be queued. |
| 483 ShowInterstitial(true, kBadURL2); | 476 ShowInterstitial(true, kBadURL2); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 514 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 507 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
| 515 ui_manager_->GetThreatDetails()->clear(); | 508 ui_manager_->GetThreatDetails()->clear(); |
| 516 } | 509 } |
| 517 | 510 |
| 518 // Tests showing a blocking page then navigating back and forth to make sure the | 511 // Tests showing a blocking page then navigating back and forth to make sure the |
| 519 // controller entries are OK. http://crbug.com/17627 | 512 // controller entries are OK. http://crbug.com/17627 |
| 520 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { | 513 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { |
| 521 // Enable malware reports. | 514 // Enable malware reports. |
| 522 Profile* profile = Profile::FromBrowserContext( | 515 Profile* profile = Profile::FromBrowserContext( |
| 523 web_contents()->GetBrowserContext()); | 516 web_contents()->GetBrowserContext()); |
| 524 profile->GetPrefs()->SetBoolean( | 517 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 525 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 526 | 518 |
| 527 // Navigate somewhere. | 519 // Navigate somewhere. |
| 528 Navigate(kGoodURL, 0, true); | 520 Navigate(kGoodURL, 0, true); |
| 529 | 521 |
| 530 // Now navigate to a bad page triggerring an interstitial. | 522 // Now navigate to a bad page triggerring an interstitial. |
| 531 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 523 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 532 ui::PAGE_TRANSITION_TYPED, std::string()); | 524 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 533 int pending_id = controller().GetPendingEntry()->GetUniqueID(); | 525 int pending_id = controller().GetPendingEntry()->GetUniqueID(); |
| 534 ShowInterstitial(false, kBadURL); | 526 ShowInterstitial(false, kBadURL); |
| 535 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 527 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 566 EXPECT_EQ(2u, ui_manager_->GetThreatDetails()->size()); | 558 EXPECT_EQ(2u, ui_manager_->GetThreatDetails()->size()); |
| 567 ui_manager_->GetThreatDetails()->clear(); | 559 ui_manager_->GetThreatDetails()->clear(); |
| 568 } | 560 } |
| 569 | 561 |
| 570 // Tests that calling "don't proceed" after "proceed" has been called doesn't | 562 // Tests that calling "don't proceed" after "proceed" has been called doesn't |
| 571 // cause problems. http://crbug.com/30079 | 563 // cause problems. http://crbug.com/30079 |
| 572 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { | 564 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { |
| 573 // Enable malware reports. | 565 // Enable malware reports. |
| 574 Profile* profile = Profile::FromBrowserContext( | 566 Profile* profile = Profile::FromBrowserContext( |
| 575 web_contents()->GetBrowserContext()); | 567 web_contents()->GetBrowserContext()); |
| 576 profile->GetPrefs()->SetBoolean( | 568 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 577 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 578 | 569 |
| 579 // Start a load. | 570 // Start a load. |
| 580 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 571 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 581 ui::PAGE_TRANSITION_TYPED, std::string()); | 572 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 582 | 573 |
| 583 // Simulate the load causing a safe browsing interstitial to be shown. | 574 // Simulate the load causing a safe browsing interstitial to be shown. |
| 584 ShowInterstitial(false, kBadURL); | 575 ShowInterstitial(false, kBadURL); |
| 585 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 576 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 586 ASSERT_TRUE(sb_interstitial); | 577 ASSERT_TRUE(sb_interstitial); |
| 587 | 578 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 602 // Only one report should have been sent. | 593 // Only one report should have been sent. |
| 603 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); | 594 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
| 604 ui_manager_->GetThreatDetails()->clear(); | 595 ui_manager_->GetThreatDetails()->clear(); |
| 605 } | 596 } |
| 606 | 597 |
| 607 // Tests showing a blocking page for a malware page with reports disabled. | 598 // Tests showing a blocking page for a malware page with reports disabled. |
| 608 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { | 599 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { |
| 609 // Disable malware reports. | 600 // Disable malware reports. |
| 610 Profile* profile = Profile::FromBrowserContext( | 601 Profile* profile = Profile::FromBrowserContext( |
| 611 web_contents()->GetBrowserContext()); | 602 web_contents()->GetBrowserContext()); |
| 612 profile->GetPrefs()->SetBoolean( | 603 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), false); |
| 613 prefs::kSafeBrowsingExtendedReportingEnabled, false); | |
| 614 | 604 |
| 615 // Start a load. | 605 // Start a load. |
| 616 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 606 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 617 ui::PAGE_TRANSITION_TYPED, std::string()); | 607 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 618 | 608 |
| 619 // Simulate the load causing a safe browsing interstitial to be shown. | 609 // Simulate the load causing a safe browsing interstitial to be shown. |
| 620 ShowInterstitial(false, kBadURL); | 610 ShowInterstitial(false, kBadURL); |
| 621 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 611 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 622 ASSERT_TRUE(sb_interstitial); | 612 ASSERT_TRUE(sb_interstitial); |
| 623 EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption()); | 613 EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 637 // No report should have been sent. | 627 // No report should have been sent. |
| 638 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 628 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
| 639 ui_manager_->GetThreatDetails()->clear(); | 629 ui_manager_->GetThreatDetails()->clear(); |
| 640 } | 630 } |
| 641 | 631 |
| 642 // Test that toggling the checkbox has the anticipated effects. | 632 // Test that toggling the checkbox has the anticipated effects. |
| 643 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) { | 633 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) { |
| 644 // Disable malware reports. | 634 // Disable malware reports. |
| 645 Profile* profile = Profile::FromBrowserContext( | 635 Profile* profile = Profile::FromBrowserContext( |
| 646 web_contents()->GetBrowserContext()); | 636 web_contents()->GetBrowserContext()); |
| 647 profile->GetPrefs()->SetBoolean( | 637 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), false); |
| 648 prefs::kSafeBrowsingExtendedReportingEnabled, false); | |
| 649 | 638 |
| 650 // Start a load. | 639 // Start a load. |
| 651 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 640 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 652 ui::PAGE_TRANSITION_TYPED, std::string()); | 641 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 653 | 642 |
| 654 // Simulate the load causing a safe browsing interstitial to be shown. | 643 // Simulate the load causing a safe browsing interstitial to be shown. |
| 655 ShowInterstitial(false, kBadURL); | 644 ShowInterstitial(false, kBadURL); |
| 656 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 645 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 657 ASSERT_TRUE(sb_interstitial); | 646 ASSERT_TRUE(sb_interstitial); |
| 658 EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption()); | 647 EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption()); |
| 659 | 648 |
| 660 base::RunLoop().RunUntilIdle(); | 649 base::RunLoop().RunUntilIdle(); |
| 661 | 650 |
| 662 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 651 EXPECT_FALSE(IsExtendedReportingEnabled(*profile->GetPrefs())); |
| 663 prefs::kSafeBrowsingExtendedReportingEnabled)); | |
| 664 | 652 |
| 665 // Simulate the user check the report agreement checkbox. | 653 // Simulate the user check the report agreement checkbox. |
| 666 sb_interstitial->controller()->SetReportingPreference(true); | 654 sb_interstitial->controller()->SetReportingPreference(true); |
| 667 | 655 |
| 668 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( | 656 EXPECT_TRUE(IsExtendedReportingEnabled(*profile->GetPrefs())); |
| 669 prefs::kSafeBrowsingExtendedReportingEnabled)); | |
| 670 | 657 |
| 671 // Simulate the user uncheck the report agreement checkbox. | 658 // Simulate the user uncheck the report agreement checkbox. |
| 672 sb_interstitial->controller()->SetReportingPreference(false); | 659 sb_interstitial->controller()->SetReportingPreference(false); |
| 673 | 660 |
| 674 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 661 EXPECT_FALSE(IsExtendedReportingEnabled(*profile->GetPrefs())); |
| 675 prefs::kSafeBrowsingExtendedReportingEnabled)); | |
| 676 } | 662 } |
| 677 | 663 |
| 678 // Test that extended reporting option is not shown on blocking an HTTPS main | 664 // Test that extended reporting option is not shown on blocking an HTTPS main |
| 679 // page, and no report is sent. | 665 // page, and no report is sent. |
| 680 TEST_F(SafeBrowsingBlockingPageTest, ExtendedReportingNotShownOnSecurePage) { | 666 TEST_F(SafeBrowsingBlockingPageTest, ExtendedReportingNotShownOnSecurePage) { |
| 681 // Enable malware details. | 667 // Enable malware details. |
| 682 Profile* profile = Profile::FromBrowserContext( | 668 Profile* profile = Profile::FromBrowserContext( |
| 683 web_contents()->GetBrowserContext()); | 669 web_contents()->GetBrowserContext()); |
| 684 profile->GetPrefs()->SetBoolean( | 670 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 685 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 686 | 671 |
| 687 // Start a load. | 672 // Start a load. |
| 688 controller().LoadURL(GURL(kBadHTTPSURL), content::Referrer(), | 673 controller().LoadURL(GURL(kBadHTTPSURL), content::Referrer(), |
| 689 ui::PAGE_TRANSITION_TYPED, std::string()); | 674 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 690 | 675 |
| 691 // Simulate the load causing a safe browsing interstitial to be shown. | 676 // Simulate the load causing a safe browsing interstitial to be shown. |
| 692 ShowInterstitial(false, kBadHTTPSURL); | 677 ShowInterstitial(false, kBadHTTPSURL); |
| 693 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 678 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 694 ASSERT_TRUE(sb_interstitial); | 679 ASSERT_TRUE(sb_interstitial); |
| 695 EXPECT_FALSE(sb_interstitial->CanShowThreatDetailsOption()); | 680 EXPECT_FALSE(sb_interstitial->CanShowThreatDetailsOption()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 708 ui_manager_->GetThreatDetails()->clear(); | 693 ui_manager_->GetThreatDetails()->clear(); |
| 709 } | 694 } |
| 710 | 695 |
| 711 // Test that extended reporting option is not shown on blocking an HTTPS | 696 // Test that extended reporting option is not shown on blocking an HTTPS |
| 712 // subresource on an HTTPS page, and no report is sent. | 697 // subresource on an HTTPS page, and no report is sent. |
| 713 TEST_F(SafeBrowsingBlockingPageTest, | 698 TEST_F(SafeBrowsingBlockingPageTest, |
| 714 ExtendedReportingNotShownOnSecurePageWithSecureSubresource) { | 699 ExtendedReportingNotShownOnSecurePageWithSecureSubresource) { |
| 715 // Enable malware details. | 700 // Enable malware details. |
| 716 Profile* profile = Profile::FromBrowserContext( | 701 Profile* profile = Profile::FromBrowserContext( |
| 717 web_contents()->GetBrowserContext()); | 702 web_contents()->GetBrowserContext()); |
| 718 profile->GetPrefs()->SetBoolean( | 703 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 719 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 720 | 704 |
| 721 // Commit a load. | 705 // Commit a load. |
| 722 content::WebContentsTester::For(web_contents()) | 706 content::WebContentsTester::For(web_contents()) |
| 723 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); | 707 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); |
| 724 | 708 |
| 725 // Simulate a subresource load causing a safe browsing interstitial to be | 709 // Simulate a subresource load causing a safe browsing interstitial to be |
| 726 // shown. | 710 // shown. |
| 727 ShowInterstitial(true, kBadHTTPSURL); | 711 ShowInterstitial(true, kBadHTTPSURL); |
| 728 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 712 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 729 ASSERT_TRUE(sb_interstitial); | 713 ASSERT_TRUE(sb_interstitial); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 743 ui_manager_->GetThreatDetails()->clear(); | 727 ui_manager_->GetThreatDetails()->clear(); |
| 744 } | 728 } |
| 745 | 729 |
| 746 // Test that extended reporting option is not shown on blocking an HTTP | 730 // Test that extended reporting option is not shown on blocking an HTTP |
| 747 // subresource on an HTTPS page, and no report is sent. | 731 // subresource on an HTTPS page, and no report is sent. |
| 748 TEST_F(SafeBrowsingBlockingPageTest, | 732 TEST_F(SafeBrowsingBlockingPageTest, |
| 749 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource) { | 733 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource) { |
| 750 // Enable malware details. | 734 // Enable malware details. |
| 751 Profile* profile = Profile::FromBrowserContext( | 735 Profile* profile = Profile::FromBrowserContext( |
| 752 web_contents()->GetBrowserContext()); | 736 web_contents()->GetBrowserContext()); |
| 753 profile->GetPrefs()->SetBoolean( | 737 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 754 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 755 | 738 |
| 756 // Commit a load. | 739 // Commit a load. |
| 757 content::WebContentsTester::For(web_contents()) | 740 content::WebContentsTester::For(web_contents()) |
| 758 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); | 741 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); |
| 759 | 742 |
| 760 // Simulate a subresource load causing a safe browsing interstitial to be | 743 // Simulate a subresource load causing a safe browsing interstitial to be |
| 761 // shown. | 744 // shown. |
| 762 ShowInterstitial(true, kBadURL); | 745 ShowInterstitial(true, kBadURL); |
| 763 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 746 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 764 ASSERT_TRUE(sb_interstitial); | 747 ASSERT_TRUE(sb_interstitial); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 778 ui_manager_->GetThreatDetails()->clear(); | 761 ui_manager_->GetThreatDetails()->clear(); |
| 779 } | 762 } |
| 780 | 763 |
| 781 // Test that extended reporting option is shown on blocking an HTTPS | 764 // Test that extended reporting option is shown on blocking an HTTPS |
| 782 // subresource on an HTTP page. | 765 // subresource on an HTTP page. |
| 783 TEST_F(SafeBrowsingBlockingPageTest, | 766 TEST_F(SafeBrowsingBlockingPageTest, |
| 784 ExtendedReportingOnInsecurePageWithSecureSubresource) { | 767 ExtendedReportingOnInsecurePageWithSecureSubresource) { |
| 785 // Enable malware details. | 768 // Enable malware details. |
| 786 Profile* profile = Profile::FromBrowserContext( | 769 Profile* profile = Profile::FromBrowserContext( |
| 787 web_contents()->GetBrowserContext()); | 770 web_contents()->GetBrowserContext()); |
| 788 profile->GetPrefs()->SetBoolean( | 771 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 789 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 790 | 772 |
| 791 // Commit a load. | 773 // Commit a load. |
| 792 content::WebContentsTester::For(web_contents()) | 774 content::WebContentsTester::For(web_contents()) |
| 793 ->NavigateAndCommit(GURL(kGoodURL)); | 775 ->NavigateAndCommit(GURL(kGoodURL)); |
| 794 | 776 |
| 795 // Simulate a subresource load causing a safe browsing interstitial to be | 777 // Simulate a subresource load causing a safe browsing interstitial to be |
| 796 // shown. | 778 // shown. |
| 797 ShowInterstitial(true, kBadHTTPSURL); | 779 ShowInterstitial(true, kBadHTTPSURL); |
| 798 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 780 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 799 ASSERT_TRUE(sb_interstitial); | 781 ASSERT_TRUE(sb_interstitial); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 814 } | 796 } |
| 815 | 797 |
| 816 // Test that extended reporting option is not shown on blocking an HTTPS | 798 // Test that extended reporting option is not shown on blocking an HTTPS |
| 817 // subresource on an HTTPS page while there is a pending load for an HTTP page, | 799 // subresource on an HTTPS page while there is a pending load for an HTTP page, |
| 818 // and no report is sent. | 800 // and no report is sent. |
| 819 TEST_F(SafeBrowsingBlockingPageTest, | 801 TEST_F(SafeBrowsingBlockingPageTest, |
| 820 ExtendedReportingNotShownOnSecurePageWithPendingInsecureLoad) { | 802 ExtendedReportingNotShownOnSecurePageWithPendingInsecureLoad) { |
| 821 // Enable malware details. | 803 // Enable malware details. |
| 822 Profile* profile = Profile::FromBrowserContext( | 804 Profile* profile = Profile::FromBrowserContext( |
| 823 web_contents()->GetBrowserContext()); | 805 web_contents()->GetBrowserContext()); |
| 824 profile->GetPrefs()->SetBoolean( | 806 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); |
| 825 prefs::kSafeBrowsingExtendedReportingEnabled, true); | |
| 826 | 807 |
| 827 // Commit a load. | 808 // Commit a load. |
| 828 content::WebContentsTester::For(web_contents()) | 809 content::WebContentsTester::For(web_contents()) |
| 829 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); | 810 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); |
| 830 | 811 |
| 831 GURL pending_url("http://slow.example.com"); | 812 GURL pending_url("http://slow.example.com"); |
| 832 | 813 |
| 833 // Start a pending load. | 814 // Start a pending load. |
| 834 content::WebContentsTester::For(web_contents())->StartNavigation(pending_url); | 815 content::WebContentsTester::For(web_contents())->StartNavigation(pending_url); |
| 835 | 816 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 853 | 834 |
| 854 // No report should have been sent. | 835 // No report should have been sent. |
| 855 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 836 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
| 856 ui_manager_->GetThreatDetails()->clear(); | 837 ui_manager_->GetThreatDetails()->clear(); |
| 857 } | 838 } |
| 858 | 839 |
| 859 // TODO(mattm): Add test for extended reporting not shown or sent in incognito | 840 // TODO(mattm): Add test for extended reporting not shown or sent in incognito |
| 860 // window. | 841 // window. |
| 861 | 842 |
| 862 } // namespace safe_browsing | 843 } // namespace safe_browsing |
| OLD | NEW |