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