| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <list> | 5 #include <list> |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/safe_browsing/malware_details.h" | 10 #include "chrome/browser/safe_browsing/malware_details.h" |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 657 |
| 658 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( | 658 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( |
| 659 prefs::kSafeBrowsingExtendedReportingEnabled)); | 659 prefs::kSafeBrowsingExtendedReportingEnabled)); |
| 660 | 660 |
| 661 // Simulate the user uncheck the report agreement checkbox. | 661 // Simulate the user uncheck the report agreement checkbox. |
| 662 sb_interstitial->SetReportingPreference(false); | 662 sb_interstitial->SetReportingPreference(false); |
| 663 | 663 |
| 664 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 664 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( |
| 665 prefs::kSafeBrowsingExtendedReportingEnabled)); | 665 prefs::kSafeBrowsingExtendedReportingEnabled)); |
| 666 } | 666 } |
| 667 | |
| 668 // Test that the transition from old to new preference works. | |
| 669 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsTransitionEnabled) { | |
| 670 // The old pref is enabled. | |
| 671 Profile* profile = Profile::FromBrowserContext( | |
| 672 web_contents()->GetBrowserContext()); | |
| 673 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | |
| 674 | |
| 675 // Start a load. | |
| 676 controller().LoadURL(GURL(kBadURL), content::Referrer(), | |
| 677 content::PAGE_TRANSITION_TYPED, std::string()); | |
| 678 | |
| 679 // Simulate the load causing a safe browsing interstitial to be shown. | |
| 680 ShowInterstitial(false, kBadURL); | |
| 681 SafeBrowsingBlockingPage* sb_interstitial = | |
| 682 GetSafeBrowsingBlockingPage(); | |
| 683 ASSERT_TRUE(sb_interstitial); | |
| 684 | |
| 685 base::RunLoop().RunUntilIdle(); | |
| 686 | |
| 687 // At this point, nothing should have changed yet. | |
| 688 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | |
| 689 prefs::kSafeBrowsingExtendedReportingEnabled)); | |
| 690 | |
| 691 ProceedThroughInterstitial(sb_interstitial); | |
| 692 | |
| 693 // Since the user has proceeded without changing the checkbox, the new pref | |
| 694 // has been updated. | |
| 695 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( | |
| 696 prefs::kSafeBrowsingExtendedReportingEnabled)); | |
| 697 } | |
| 698 | |
| 699 // Test that the transition from old to new preference still respects the | |
| 700 // user's checkbox preferences. | |
| 701 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsTransitionDisabled) { | |
| 702 // The old pref is enabled. | |
| 703 Profile* profile = Profile::FromBrowserContext( | |
| 704 web_contents()->GetBrowserContext()); | |
| 705 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | |
| 706 | |
| 707 // Start a load. | |
| 708 controller().LoadURL(GURL(kBadURL), content::Referrer(), | |
| 709 content::PAGE_TRANSITION_TYPED, std::string()); | |
| 710 | |
| 711 // Simulate the load causing a safe browsing interstitial to be shown. | |
| 712 ShowInterstitial(false, kBadURL); | |
| 713 SafeBrowsingBlockingPage* sb_interstitial = | |
| 714 GetSafeBrowsingBlockingPage(); | |
| 715 ASSERT_TRUE(sb_interstitial); | |
| 716 | |
| 717 base::RunLoop().RunUntilIdle(); | |
| 718 | |
| 719 // At this point, nothing should have changed yet. | |
| 720 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | |
| 721 prefs::kSafeBrowsingExtendedReportingEnabled)); | |
| 722 | |
| 723 // Simulate the user uncheck the report agreement checkbox. | |
| 724 sb_interstitial->SetReportingPreference(false); | |
| 725 | |
| 726 ProceedThroughInterstitial(sb_interstitial); | |
| 727 | |
| 728 // The new pref is turned off. | |
| 729 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | |
| 730 prefs::kSafeBrowsingExtendedReportingEnabled)); | |
| 731 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | |
| 732 prefs::kSafeBrowsingReportingEnabled)); | |
| 733 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | |
| 734 prefs::kSafeBrowsingDownloadFeedbackEnabled)); | |
| 735 } | |
| OLD | NEW |