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" |
(...skipping 213 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(GetExtendedReportingPrefName(), true); | 234 SetExtendedReportingPref(profile->GetPrefs(), true); |
235 | 235 |
236 // Start a load. | 236 // Start a load. |
237 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 237 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
238 ui::PAGE_TRANSITION_TYPED, std::string()); | 238 ui::PAGE_TRANSITION_TYPED, std::string()); |
239 | 239 |
240 | 240 |
241 // Simulate the load causing a safe browsing interstitial to be shown. | 241 // Simulate the load causing a safe browsing interstitial to be shown. |
242 ShowInterstitial(false, kBadURL); | 242 ShowInterstitial(false, kBadURL); |
243 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 243 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
244 ASSERT_TRUE(sb_interstitial); | 244 ASSERT_TRUE(sb_interstitial); |
(...skipping 13 matching lines...) Expand all Loading... |
258 // A report should have been sent. | 258 // A report should have been sent. |
259 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); | 259 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
260 ui_manager_->GetThreatDetails()->clear(); | 260 ui_manager_->GetThreatDetails()->clear(); |
261 } | 261 } |
262 | 262 |
263 // 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. |
264 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { | 264 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { |
265 // Enable malware reports. | 265 // Enable malware reports. |
266 Profile* profile = Profile::FromBrowserContext( | 266 Profile* profile = Profile::FromBrowserContext( |
267 web_contents()->GetBrowserContext()); | 267 web_contents()->GetBrowserContext()); |
268 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 268 SetExtendedReportingPref(profile->GetPrefs(), true); |
269 | 269 |
270 // Start a load. | 270 // Start a load. |
271 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 271 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
272 ui::PAGE_TRANSITION_TYPED, std::string()); | 272 ui::PAGE_TRANSITION_TYPED, std::string()); |
273 int pending_id = controller().GetPendingEntry()->GetUniqueID(); | 273 int pending_id = controller().GetPendingEntry()->GetUniqueID(); |
274 | 274 |
275 // Simulate the load causing a safe browsing interstitial to be shown. | 275 // Simulate the load causing a safe browsing interstitial to be shown. |
276 ShowInterstitial(false, kBadURL); | 276 ShowInterstitial(false, kBadURL); |
277 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 277 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
278 ASSERT_TRUE(sb_interstitial); | 278 ASSERT_TRUE(sb_interstitial); |
(...skipping 12 matching lines...) Expand all Loading... |
291 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); | 291 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
292 ui_manager_->GetThreatDetails()->clear(); | 292 ui_manager_->GetThreatDetails()->clear(); |
293 } | 293 } |
294 | 294 |
295 // 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 |
296 // and not proceeding. | 296 // and not proceeding. |
297 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { | 297 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { |
298 // Enable malware reports. | 298 // Enable malware reports. |
299 Profile* profile = Profile::FromBrowserContext( | 299 Profile* profile = Profile::FromBrowserContext( |
300 web_contents()->GetBrowserContext()); | 300 web_contents()->GetBrowserContext()); |
301 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 301 SetExtendedReportingPref(profile->GetPrefs(), true); |
302 | 302 |
303 // Navigate somewhere. | 303 // Navigate somewhere. |
304 Navigate(kGoogleURL, 0, true); | 304 Navigate(kGoogleURL, 0, true); |
305 | 305 |
306 // Navigate somewhere else. | 306 // Navigate somewhere else. |
307 Navigate(kGoodURL, 0, true); | 307 Navigate(kGoodURL, 0, true); |
308 | 308 |
309 // Simulate that page loading a bad-resource triggering an interstitial. | 309 // Simulate that page loading a bad-resource triggering an interstitial. |
310 ShowInterstitial(true, kBadURL); | 310 ShowInterstitial(true, kBadURL); |
311 | 311 |
(...skipping 14 matching lines...) Expand all Loading... |
326 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); | 326 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
327 ui_manager_->GetThreatDetails()->clear(); | 327 ui_manager_->GetThreatDetails()->clear(); |
328 } | 328 } |
329 | 329 |
330 // 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 |
331 // and proceeding. | 331 // and proceeding. |
332 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { | 332 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { |
333 // Enable malware reports. | 333 // Enable malware reports. |
334 Profile* profile = Profile::FromBrowserContext( | 334 Profile* profile = Profile::FromBrowserContext( |
335 web_contents()->GetBrowserContext()); | 335 web_contents()->GetBrowserContext()); |
336 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 336 SetExtendedReportingPref(profile->GetPrefs(), true); |
337 | 337 |
338 // Navigate somewhere. | 338 // Navigate somewhere. |
339 Navigate(kGoodURL, 0, true); | 339 Navigate(kGoodURL, 0, true); |
340 | 340 |
341 // Simulate that page loading a bad-resource triggering an interstitial. | 341 // Simulate that page loading a bad-resource triggering an interstitial. |
342 ShowInterstitial(true, kBadURL); | 342 ShowInterstitial(true, kBadURL); |
343 | 343 |
344 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 344 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
345 ASSERT_TRUE(sb_interstitial); | 345 ASSERT_TRUE(sb_interstitial); |
346 | 346 |
(...skipping 12 matching lines...) Expand all Loading... |
359 } | 359 } |
360 | 360 |
361 // 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 |
362 // subresources and not proceeding. This just tests that the extra malware | 362 // subresources and not proceeding. This just tests that the extra malware |
363 // subresources (which trigger queued interstitial pages) do not break anything. | 363 // subresources (which trigger queued interstitial pages) do not break anything. |
364 TEST_F(SafeBrowsingBlockingPageTest, | 364 TEST_F(SafeBrowsingBlockingPageTest, |
365 PageWithMultipleMalwareResourceDontProceed) { | 365 PageWithMultipleMalwareResourceDontProceed) { |
366 // Enable malware reports. | 366 // Enable malware reports. |
367 Profile* profile = Profile::FromBrowserContext( | 367 Profile* profile = Profile::FromBrowserContext( |
368 web_contents()->GetBrowserContext()); | 368 web_contents()->GetBrowserContext()); |
369 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 369 SetExtendedReportingPref(profile->GetPrefs(), true); |
370 | 370 |
371 // Navigate somewhere. | 371 // Navigate somewhere. |
372 Navigate(kGoogleURL, 0, true); | 372 Navigate(kGoogleURL, 0, true); |
373 | 373 |
374 // Navigate somewhere else. | 374 // Navigate somewhere else. |
375 Navigate(kGoodURL, 0, true); | 375 Navigate(kGoodURL, 0, true); |
376 | 376 |
377 // Simulate that page loading a bad-resource triggering an interstitial. | 377 // Simulate that page loading a bad-resource triggering an interstitial. |
378 ShowInterstitial(true, kBadURL); | 378 ShowInterstitial(true, kBadURL); |
379 | 379 |
(...skipping 20 matching lines...) Expand all Loading... |
400 ui_manager_->GetThreatDetails()->clear(); | 400 ui_manager_->GetThreatDetails()->clear(); |
401 } | 401 } |
402 | 402 |
403 // 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 |
404 // subresources and proceeding through the first interstitial, but not the next. | 404 // subresources and proceeding through the first interstitial, but not the next. |
405 TEST_F(SafeBrowsingBlockingPageTest, | 405 TEST_F(SafeBrowsingBlockingPageTest, |
406 PageWithMultipleMalwareResourceProceedThenDontProceed) { | 406 PageWithMultipleMalwareResourceProceedThenDontProceed) { |
407 // Enable malware reports. | 407 // Enable malware reports. |
408 Profile* profile = Profile::FromBrowserContext( | 408 Profile* profile = Profile::FromBrowserContext( |
409 web_contents()->GetBrowserContext()); | 409 web_contents()->GetBrowserContext()); |
410 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 410 SetExtendedReportingPref(profile->GetPrefs(), true); |
411 | 411 |
412 // Navigate somewhere. | 412 // Navigate somewhere. |
413 Navigate(kGoogleURL, 0, true); | 413 Navigate(kGoogleURL, 0, true); |
414 | 414 |
415 // Navigate somewhere else. | 415 // Navigate somewhere else. |
416 Navigate(kGoodURL, 0, true); | 416 Navigate(kGoodURL, 0, true); |
417 | 417 |
418 // Simulate that page loading a bad-resource triggering an interstitial. | 418 // Simulate that page loading a bad-resource triggering an interstitial. |
419 ShowInterstitial(true, kBadURL); | 419 ShowInterstitial(true, kBadURL); |
420 | 420 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 456 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
457 ui_manager_->GetThreatDetails()->clear(); | 457 ui_manager_->GetThreatDetails()->clear(); |
458 } | 458 } |
459 | 459 |
460 // 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 |
461 // subresources and proceeding through the multiple interstitials. | 461 // subresources and proceeding through the multiple interstitials. |
462 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { | 462 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { |
463 // Enable malware reports. | 463 // Enable malware reports. |
464 Profile* profile = Profile::FromBrowserContext( | 464 Profile* profile = Profile::FromBrowserContext( |
465 web_contents()->GetBrowserContext()); | 465 web_contents()->GetBrowserContext()); |
466 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 466 SetExtendedReportingPref(profile->GetPrefs(), true); |
467 | 467 |
468 // Navigate somewhere else. | 468 // Navigate somewhere else. |
469 Navigate(kGoodURL, 0, true); | 469 Navigate(kGoodURL, 0, true); |
470 | 470 |
471 // Simulate that page loading a bad-resource triggering an interstitial. | 471 // Simulate that page loading a bad-resource triggering an interstitial. |
472 ShowInterstitial(true, kBadURL); | 472 ShowInterstitial(true, kBadURL); |
473 | 473 |
474 // More bad resources loading causing more interstitials. The new | 474 // More bad resources loading causing more interstitials. The new |
475 // interstitials should be queued. | 475 // interstitials should be queued. |
476 ShowInterstitial(true, kBadURL2); | 476 ShowInterstitial(true, kBadURL2); |
(...skipping 30 matching lines...) Expand all Loading... |
507 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 507 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
508 ui_manager_->GetThreatDetails()->clear(); | 508 ui_manager_->GetThreatDetails()->clear(); |
509 } | 509 } |
510 | 510 |
511 // 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 |
512 // controller entries are OK. http://crbug.com/17627 | 512 // controller entries are OK. http://crbug.com/17627 |
513 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { | 513 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { |
514 // Enable malware reports. | 514 // Enable malware reports. |
515 Profile* profile = Profile::FromBrowserContext( | 515 Profile* profile = Profile::FromBrowserContext( |
516 web_contents()->GetBrowserContext()); | 516 web_contents()->GetBrowserContext()); |
517 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 517 SetExtendedReportingPref(profile->GetPrefs(), true); |
518 | 518 |
519 // Navigate somewhere. | 519 // Navigate somewhere. |
520 Navigate(kGoodURL, 0, true); | 520 Navigate(kGoodURL, 0, true); |
521 | 521 |
522 // Now navigate to a bad page triggerring an interstitial. | 522 // Now navigate to a bad page triggerring an interstitial. |
523 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 523 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
524 ui::PAGE_TRANSITION_TYPED, std::string()); | 524 ui::PAGE_TRANSITION_TYPED, std::string()); |
525 int pending_id = controller().GetPendingEntry()->GetUniqueID(); | 525 int pending_id = controller().GetPendingEntry()->GetUniqueID(); |
526 ShowInterstitial(false, kBadURL); | 526 ShowInterstitial(false, kBadURL); |
527 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 527 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
(...skipping 30 matching lines...) Expand all Loading... |
558 EXPECT_EQ(2u, ui_manager_->GetThreatDetails()->size()); | 558 EXPECT_EQ(2u, ui_manager_->GetThreatDetails()->size()); |
559 ui_manager_->GetThreatDetails()->clear(); | 559 ui_manager_->GetThreatDetails()->clear(); |
560 } | 560 } |
561 | 561 |
562 // 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 |
563 // cause problems. http://crbug.com/30079 | 563 // cause problems. http://crbug.com/30079 |
564 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { | 564 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { |
565 // Enable malware reports. | 565 // Enable malware reports. |
566 Profile* profile = Profile::FromBrowserContext( | 566 Profile* profile = Profile::FromBrowserContext( |
567 web_contents()->GetBrowserContext()); | 567 web_contents()->GetBrowserContext()); |
568 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 568 SetExtendedReportingPref(profile->GetPrefs(), true); |
569 | 569 |
570 // Start a load. | 570 // Start a load. |
571 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 571 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
572 ui::PAGE_TRANSITION_TYPED, std::string()); | 572 ui::PAGE_TRANSITION_TYPED, std::string()); |
573 | 573 |
574 // Simulate the load causing a safe browsing interstitial to be shown. | 574 // Simulate the load causing a safe browsing interstitial to be shown. |
575 ShowInterstitial(false, kBadURL); | 575 ShowInterstitial(false, kBadURL); |
576 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 576 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
577 ASSERT_TRUE(sb_interstitial); | 577 ASSERT_TRUE(sb_interstitial); |
578 | 578 |
(...skipping 14 matching lines...) Expand all Loading... |
593 // Only one report should have been sent. | 593 // Only one report should have been sent. |
594 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); | 594 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
595 ui_manager_->GetThreatDetails()->clear(); | 595 ui_manager_->GetThreatDetails()->clear(); |
596 } | 596 } |
597 | 597 |
598 // 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. |
599 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { | 599 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { |
600 // Disable malware reports. | 600 // Disable malware reports. |
601 Profile* profile = Profile::FromBrowserContext( | 601 Profile* profile = Profile::FromBrowserContext( |
602 web_contents()->GetBrowserContext()); | 602 web_contents()->GetBrowserContext()); |
603 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), false); | 603 SetExtendedReportingPref(profile->GetPrefs(), 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 ui::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 = GetSafeBrowsingBlockingPage(); | 611 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
612 ASSERT_TRUE(sb_interstitial); | 612 ASSERT_TRUE(sb_interstitial); |
613 EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption()); | 613 EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption()); |
(...skipping 13 matching lines...) Expand all Loading... |
627 // No report should have been sent. | 627 // No report should have been sent. |
628 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 628 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
629 ui_manager_->GetThreatDetails()->clear(); | 629 ui_manager_->GetThreatDetails()->clear(); |
630 } | 630 } |
631 | 631 |
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(GetExtendedReportingPrefName(), false); | 637 SetExtendedReportingPref(profile->GetPrefs(), false); |
638 | 638 |
639 // Start a load. | 639 // Start a load. |
640 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 640 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
641 ui::PAGE_TRANSITION_TYPED, std::string()); | 641 ui::PAGE_TRANSITION_TYPED, std::string()); |
642 | 642 |
643 // Simulate the load causing a safe browsing interstitial to be shown. | 643 // Simulate the load causing a safe browsing interstitial to be shown. |
644 ShowInterstitial(false, kBadURL); | 644 ShowInterstitial(false, kBadURL); |
645 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 645 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
646 ASSERT_TRUE(sb_interstitial); | 646 ASSERT_TRUE(sb_interstitial); |
647 EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption()); | 647 EXPECT_TRUE(sb_interstitial->CanShowThreatDetailsOption()); |
(...skipping 12 matching lines...) Expand all Loading... |
660 | 660 |
661 EXPECT_FALSE(IsExtendedReportingEnabled(*profile->GetPrefs())); | 661 EXPECT_FALSE(IsExtendedReportingEnabled(*profile->GetPrefs())); |
662 } | 662 } |
663 | 663 |
664 // 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 |
665 // page, and no report is sent. | 665 // page, and no report is sent. |
666 TEST_F(SafeBrowsingBlockingPageTest, ExtendedReportingNotShownOnSecurePage) { | 666 TEST_F(SafeBrowsingBlockingPageTest, ExtendedReportingNotShownOnSecurePage) { |
667 // Enable malware details. | 667 // Enable malware details. |
668 Profile* profile = Profile::FromBrowserContext( | 668 Profile* profile = Profile::FromBrowserContext( |
669 web_contents()->GetBrowserContext()); | 669 web_contents()->GetBrowserContext()); |
670 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 670 SetExtendedReportingPref(profile->GetPrefs(), true); |
671 | 671 |
672 // Start a load. | 672 // Start a load. |
673 controller().LoadURL(GURL(kBadHTTPSURL), content::Referrer(), | 673 controller().LoadURL(GURL(kBadHTTPSURL), content::Referrer(), |
674 ui::PAGE_TRANSITION_TYPED, std::string()); | 674 ui::PAGE_TRANSITION_TYPED, std::string()); |
675 | 675 |
676 // Simulate the load causing a safe browsing interstitial to be shown. | 676 // Simulate the load causing a safe browsing interstitial to be shown. |
677 ShowInterstitial(false, kBadHTTPSURL); | 677 ShowInterstitial(false, kBadHTTPSURL); |
678 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 678 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
679 ASSERT_TRUE(sb_interstitial); | 679 ASSERT_TRUE(sb_interstitial); |
680 EXPECT_FALSE(sb_interstitial->CanShowThreatDetailsOption()); | 680 EXPECT_FALSE(sb_interstitial->CanShowThreatDetailsOption()); |
(...skipping 12 matching lines...) Expand all Loading... |
693 ui_manager_->GetThreatDetails()->clear(); | 693 ui_manager_->GetThreatDetails()->clear(); |
694 } | 694 } |
695 | 695 |
696 // 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 |
697 // subresource on an HTTPS page, and no report is sent. | 697 // subresource on an HTTPS page, and no report is sent. |
698 TEST_F(SafeBrowsingBlockingPageTest, | 698 TEST_F(SafeBrowsingBlockingPageTest, |
699 ExtendedReportingNotShownOnSecurePageWithSecureSubresource) { | 699 ExtendedReportingNotShownOnSecurePageWithSecureSubresource) { |
700 // Enable malware details. | 700 // Enable malware details. |
701 Profile* profile = Profile::FromBrowserContext( | 701 Profile* profile = Profile::FromBrowserContext( |
702 web_contents()->GetBrowserContext()); | 702 web_contents()->GetBrowserContext()); |
703 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 703 SetExtendedReportingPref(profile->GetPrefs(), true); |
704 | 704 |
705 // Commit a load. | 705 // Commit a load. |
706 content::WebContentsTester::For(web_contents()) | 706 content::WebContentsTester::For(web_contents()) |
707 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); | 707 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); |
708 | 708 |
709 // Simulate a subresource load causing a safe browsing interstitial to be | 709 // Simulate a subresource load causing a safe browsing interstitial to be |
710 // shown. | 710 // shown. |
711 ShowInterstitial(true, kBadHTTPSURL); | 711 ShowInterstitial(true, kBadHTTPSURL); |
712 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 712 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
713 ASSERT_TRUE(sb_interstitial); | 713 ASSERT_TRUE(sb_interstitial); |
(...skipping 13 matching lines...) Expand all Loading... |
727 ui_manager_->GetThreatDetails()->clear(); | 727 ui_manager_->GetThreatDetails()->clear(); |
728 } | 728 } |
729 | 729 |
730 // 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 |
731 // subresource on an HTTPS page, and no report is sent. | 731 // subresource on an HTTPS page, and no report is sent. |
732 TEST_F(SafeBrowsingBlockingPageTest, | 732 TEST_F(SafeBrowsingBlockingPageTest, |
733 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource) { | 733 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource) { |
734 // Enable malware details. | 734 // Enable malware details. |
735 Profile* profile = Profile::FromBrowserContext( | 735 Profile* profile = Profile::FromBrowserContext( |
736 web_contents()->GetBrowserContext()); | 736 web_contents()->GetBrowserContext()); |
737 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 737 SetExtendedReportingPref(profile->GetPrefs(), true); |
738 | 738 |
739 // Commit a load. | 739 // Commit a load. |
740 content::WebContentsTester::For(web_contents()) | 740 content::WebContentsTester::For(web_contents()) |
741 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); | 741 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); |
742 | 742 |
743 // Simulate a subresource load causing a safe browsing interstitial to be | 743 // Simulate a subresource load causing a safe browsing interstitial to be |
744 // shown. | 744 // shown. |
745 ShowInterstitial(true, kBadURL); | 745 ShowInterstitial(true, kBadURL); |
746 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 746 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
747 ASSERT_TRUE(sb_interstitial); | 747 ASSERT_TRUE(sb_interstitial); |
(...skipping 13 matching lines...) Expand all Loading... |
761 ui_manager_->GetThreatDetails()->clear(); | 761 ui_manager_->GetThreatDetails()->clear(); |
762 } | 762 } |
763 | 763 |
764 // Test that extended reporting option is shown on blocking an HTTPS | 764 // Test that extended reporting option is shown on blocking an HTTPS |
765 // subresource on an HTTP page. | 765 // subresource on an HTTP page. |
766 TEST_F(SafeBrowsingBlockingPageTest, | 766 TEST_F(SafeBrowsingBlockingPageTest, |
767 ExtendedReportingOnInsecurePageWithSecureSubresource) { | 767 ExtendedReportingOnInsecurePageWithSecureSubresource) { |
768 // Enable malware details. | 768 // Enable malware details. |
769 Profile* profile = Profile::FromBrowserContext( | 769 Profile* profile = Profile::FromBrowserContext( |
770 web_contents()->GetBrowserContext()); | 770 web_contents()->GetBrowserContext()); |
771 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 771 SetExtendedReportingPref(profile->GetPrefs(), true); |
772 | 772 |
773 // Commit a load. | 773 // Commit a load. |
774 content::WebContentsTester::For(web_contents()) | 774 content::WebContentsTester::For(web_contents()) |
775 ->NavigateAndCommit(GURL(kGoodURL)); | 775 ->NavigateAndCommit(GURL(kGoodURL)); |
776 | 776 |
777 // Simulate a subresource load causing a safe browsing interstitial to be | 777 // Simulate a subresource load causing a safe browsing interstitial to be |
778 // shown. | 778 // shown. |
779 ShowInterstitial(true, kBadHTTPSURL); | 779 ShowInterstitial(true, kBadHTTPSURL); |
780 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 780 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
781 ASSERT_TRUE(sb_interstitial); | 781 ASSERT_TRUE(sb_interstitial); |
(...skipping 14 matching lines...) Expand all Loading... |
796 } | 796 } |
797 | 797 |
798 // 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 |
799 // 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, |
800 // and no report is sent. | 800 // and no report is sent. |
801 TEST_F(SafeBrowsingBlockingPageTest, | 801 TEST_F(SafeBrowsingBlockingPageTest, |
802 ExtendedReportingNotShownOnSecurePageWithPendingInsecureLoad) { | 802 ExtendedReportingNotShownOnSecurePageWithPendingInsecureLoad) { |
803 // Enable malware details. | 803 // Enable malware details. |
804 Profile* profile = Profile::FromBrowserContext( | 804 Profile* profile = Profile::FromBrowserContext( |
805 web_contents()->GetBrowserContext()); | 805 web_contents()->GetBrowserContext()); |
806 profile->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(), true); | 806 SetExtendedReportingPref(profile->GetPrefs(), true); |
807 | 807 |
808 // Commit a load. | 808 // Commit a load. |
809 content::WebContentsTester::For(web_contents()) | 809 content::WebContentsTester::For(web_contents()) |
810 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); | 810 ->NavigateAndCommit(GURL(kGoodHTTPSURL)); |
811 | 811 |
812 GURL pending_url("http://slow.example.com"); | 812 GURL pending_url("http://slow.example.com"); |
813 | 813 |
814 // Start a pending load. | 814 // Start a pending load. |
815 content::WebContentsTester::For(web_contents())->StartNavigation(pending_url); | 815 content::WebContentsTester::For(web_contents())->StartNavigation(pending_url); |
816 | 816 |
(...skipping 17 matching lines...) Expand all Loading... |
834 | 834 |
835 // No report should have been sent. | 835 // No report should have been sent. |
836 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 836 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
837 ui_manager_->GetThreatDetails()->clear(); | 837 ui_manager_->GetThreatDetails()->clear(); |
838 } | 838 } |
839 | 839 |
840 // 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 |
841 // window. | 841 // window. |
842 | 842 |
843 } // namespace safe_browsing | 843 } // namespace safe_browsing |
OLD | NEW |