Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover_unittest.cc

Issue 2184823007: Add a feature which, when enabled, blocks permissions after X prompt dismissals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nits Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/browsing_data/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data/browsing_data_remover.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 23 matching lines...) Expand all
34 #include "chrome/browser/browsing_data/browsing_data_helper.h" 34 #include "chrome/browser/browsing_data/browsing_data_helper.h"
35 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 35 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
36 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 36 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
37 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" 37 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
38 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 38 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
39 #include "chrome/browser/domain_reliability/service_factory.h" 39 #include "chrome/browser/domain_reliability/service_factory.h"
40 #include "chrome/browser/download/chrome_download_manager_delegate.h" 40 #include "chrome/browser/download/chrome_download_manager_delegate.h"
41 #include "chrome/browser/favicon/favicon_service_factory.h" 41 #include "chrome/browser/favicon/favicon_service_factory.h"
42 #include "chrome/browser/history/history_service_factory.h" 42 #include "chrome/browser/history/history_service_factory.h"
43 #include "chrome/browser/password_manager/password_store_factory.h" 43 #include "chrome/browser/password_manager/password_store_factory.h"
44 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
44 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 45 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
45 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
46 #include "chrome/test/base/testing_browser_process.h" 47 #include "chrome/test/base/testing_browser_process.h"
47 #include "chrome/test/base/testing_profile.h" 48 #include "chrome/test/base/testing_profile.h"
48 #include "components/autofill/core/browser/autofill_profile.h" 49 #include "components/autofill/core/browser/autofill_profile.h"
49 #include "components/autofill/core/browser/autofill_test_utils.h" 50 #include "components/autofill/core/browser/autofill_test_utils.h"
50 #include "components/autofill/core/browser/credit_card.h" 51 #include "components/autofill/core/browser/credit_card.h"
51 #include "components/autofill/core/browser/personal_data_manager.h" 52 #include "components/autofill/core/browser/personal_data_manager.h"
52 #include "components/autofill/core/browser/personal_data_manager_observer.h" 53 #include "components/autofill/core/browser/personal_data_manager_observer.h"
53 #include "components/autofill/core/common/autofill_constants.h" 54 #include "components/autofill/core/common/autofill_constants.h"
(...skipping 11 matching lines...) Expand all
65 #include "components/omnibox/browser/omnibox_pref_names.h" 66 #include "components/omnibox/browser/omnibox_pref_names.h"
66 #include "components/os_crypt/os_crypt_mocker.h" 67 #include "components/os_crypt/os_crypt_mocker.h"
67 #include "components/password_manager/core/browser/mock_password_store.h" 68 #include "components/password_manager/core/browser/mock_password_store.h"
68 #include "components/password_manager/core/browser/password_manager_test_utils.h " 69 #include "components/password_manager/core/browser/password_manager_test_utils.h "
69 #include "components/password_manager/core/browser/password_store_consumer.h" 70 #include "components/password_manager/core/browser/password_store_consumer.h"
70 #include "components/prefs/testing_pref_service.h" 71 #include "components/prefs/testing_pref_service.h"
71 #include "content/public/browser/browser_context.h" 72 #include "content/public/browser/browser_context.h"
72 #include "content/public/browser/cookie_store_factory.h" 73 #include "content/public/browser/cookie_store_factory.h"
73 #include "content/public/browser/dom_storage_context.h" 74 #include "content/public/browser/dom_storage_context.h"
74 #include "content/public/browser/local_storage_usage_info.h" 75 #include "content/public/browser/local_storage_usage_info.h"
76 #include "content/public/browser/permission_type.h"
75 #include "content/public/browser/storage_partition.h" 77 #include "content/public/browser/storage_partition.h"
76 #include "content/public/test/mock_download_manager.h" 78 #include "content/public/test/mock_download_manager.h"
77 #include "content/public/test/test_browser_thread.h" 79 #include "content/public/test/test_browser_thread.h"
78 #include "content/public/test/test_browser_thread_bundle.h" 80 #include "content/public/test/test_browser_thread_bundle.h"
79 #include "content/public/test/test_utils.h" 81 #include "content/public/test/test_utils.h"
80 #include "net/cookies/cookie_store.h" 82 #include "net/cookies/cookie_store.h"
81 #include "net/ssl/channel_id_service.h" 83 #include "net/ssl/channel_id_service.h"
82 #include "net/ssl/channel_id_store.h" 84 #include "net/ssl/channel_id_store.h"
83 #include "net/ssl/ssl_client_cert_type.h" 85 #include "net/ssl/ssl_client_cert_type.h"
84 #include "net/url_request/url_request_context.h" 86 #include "net/url_request/url_request_context.h"
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 ~RemovePasswordsTester() { OSCryptMocker::TearDown(); } 1016 ~RemovePasswordsTester() { OSCryptMocker::TearDown(); }
1015 1017
1016 password_manager::MockPasswordStore* store() { return store_; } 1018 password_manager::MockPasswordStore* store() { return store_; }
1017 1019
1018 private: 1020 private:
1019 password_manager::MockPasswordStore* store_; 1021 password_manager::MockPasswordStore* store_;
1020 1022
1021 DISALLOW_COPY_AND_ASSIGN(RemovePasswordsTester); 1023 DISALLOW_COPY_AND_ASSIGN(RemovePasswordsTester);
1022 }; 1024 };
1023 1025
1026 class RemovePermissionPromptCountsTest {
1027 public:
1028 explicit RemovePermissionPromptCountsTest(TestingProfile* profile)
1029 : blocker_(new PermissionDecisionAutoBlocker(profile)) {}
1030
1031 int GetDismissCount(const GURL& url, content::PermissionType permission) {
1032 return blocker_->GetActionCountForTest(url, permission,
1033 PermissionDecisionAutoBlocker::kPromptDismissCountKey);
1034 }
1035
1036 int GetIgnoreCount(const GURL& url, content::PermissionType permission) {
1037 return blocker_->GetActionCountForTest(url, permission,
1038 PermissionDecisionAutoBlocker::kPromptIgnoreCountKey);
1039 }
1040
1041 int RecordIgnore(const GURL& url, content::PermissionType permission) {
1042 return blocker_->RecordIgnore(url, permission);
1043 }
1044
1045 bool ShouldChangeDismissalToBlock(const GURL& url,
1046 content::PermissionType permission) {
1047 return blocker_->ShouldChangeDismissalToBlock(url, permission);
1048 }
1049
1050 private:
1051 std::unique_ptr<PermissionDecisionAutoBlocker> blocker_;
1052
1053 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest);
1054 };
1055
1024 // Test Class ---------------------------------------------------------------- 1056 // Test Class ----------------------------------------------------------------
1025 1057
1026 class BrowsingDataRemoverTest : public testing::Test { 1058 class BrowsingDataRemoverTest : public testing::Test {
1027 public: 1059 public:
1028 BrowsingDataRemoverTest() 1060 BrowsingDataRemoverTest()
1029 : profile_(new TestingProfile()), 1061 : profile_(new TestingProfile()),
1030 clear_domain_reliability_tester_(GetProfile()) { 1062 clear_domain_reliability_tester_(GetProfile()) {
1031 remover_ = 1063 remover_ =
1032 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); 1064 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get());
1033 1065
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 host_content_settings_map, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, 2624 host_content_settings_map, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
2593 base::Bind(&MatchPrimaryPattern, http_pattern)); 2625 base::Bind(&MatchPrimaryPattern, http_pattern));
2594 // Verify we only have one, and it's url1. 2626 // Verify we only have one, and it's url1.
2595 host_content_settings_map->GetSettingsForOneType( 2627 host_content_settings_map->GetSettingsForOneType(
2596 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); 2628 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
2597 EXPECT_EQ(1u, host_settings.size()); 2629 EXPECT_EQ(1u, host_settings.size());
2598 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), 2630 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1),
2599 host_settings[0].primary_pattern); 2631 host_settings[0].primary_pattern);
2600 } 2632 }
2601 2633
2634 TEST_F(BrowsingDataRemoverTest, ClearPermissionPromptCounts) {
2635 RemovePermissionPromptCountsTest tester(GetProfile());
2636
2637 RegistrableDomainFilterBuilder filter_builder_1(
2638 RegistrableDomainFilterBuilder::WHITELIST);
2639 filter_builder_1.AddRegisterableDomain(kTestRegisterableDomain1);
2640
2641 RegistrableDomainFilterBuilder filter_builder_2(
2642 RegistrableDomainFilterBuilder::BLACKLIST);
2643 filter_builder_2.AddRegisterableDomain(kTestRegisterableDomain1);
2644
2645 {
2646 // Test REMOVE_HISTORY.
2647 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2648 content::PermissionType::GEOLOCATION));
2649 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1,
2650 content::PermissionType::GEOLOCATION));
2651 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2652 content::PermissionType::NOTIFICATIONS));
2653 tester.ShouldChangeDismissalToBlock(kOrigin1,
2654 content::PermissionType::MIDI_SYSEX);
2655 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2,
2656 content::PermissionType::DURABLE_STORAGE));
2657 tester.ShouldChangeDismissalToBlock(kOrigin2,
2658 content::PermissionType::NOTIFICATIONS);
2659
2660 BlockUntilOriginDataRemoved(browsing_data::LAST_HOUR,
2661 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2662 filter_builder_1);
2663
2664 // kOrigin1 should be gone, but kOrigin2 remains.
2665 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2666 content::PermissionType::GEOLOCATION));
2667 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2668 content::PermissionType::NOTIFICATIONS));
2669 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
2670 content::PermissionType::MIDI_SYSEX));
2671 EXPECT_EQ(1, tester.GetIgnoreCount(
2672 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2673 EXPECT_EQ(1, tester.GetDismissCount(
2674 kOrigin2, content::PermissionType::NOTIFICATIONS));
2675
2676 BlockUntilBrowsingDataRemoved(browsing_data::LAST_HOUR,
2677 BrowsingDataRemover::REMOVE_HISTORY, false);
2678
2679 // Everything should be gone.
2680 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2681 content::PermissionType::GEOLOCATION));
2682 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2683 content::PermissionType::NOTIFICATIONS));
2684 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
2685 content::PermissionType::MIDI_SYSEX));
2686 EXPECT_EQ(0, tester.GetIgnoreCount(
2687 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2688 EXPECT_EQ(0, tester.GetDismissCount(
2689 kOrigin2, content::PermissionType::NOTIFICATIONS));
2690 }
2691 {
2692 // Test REMOVE_SITE_DATA.
2693 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2694 content::PermissionType::GEOLOCATION));
2695 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1,
2696 content::PermissionType::GEOLOCATION));
2697 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2698 content::PermissionType::NOTIFICATIONS));
2699 tester.ShouldChangeDismissalToBlock(kOrigin1,
2700 content::PermissionType::MIDI_SYSEX);
2701 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2,
2702 content::PermissionType::DURABLE_STORAGE));
2703 tester.ShouldChangeDismissalToBlock(kOrigin2,
2704 content::PermissionType::NOTIFICATIONS);
2705
2706 BlockUntilOriginDataRemoved(browsing_data::LAST_HOUR,
2707 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2708 filter_builder_2);
2709
2710 // kOrigin2 should be gone, but kOrigin1 remains.
2711 EXPECT_EQ(2, tester.GetIgnoreCount(kOrigin1,
2712 content::PermissionType::GEOLOCATION));
2713 EXPECT_EQ(1, tester.GetIgnoreCount(kOrigin1,
2714 content::PermissionType::NOTIFICATIONS));
2715 EXPECT_EQ(1, tester.GetDismissCount(kOrigin1,
2716 content::PermissionType::MIDI_SYSEX));
2717 EXPECT_EQ(0, tester.GetIgnoreCount(
2718 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2719 EXPECT_EQ(0, tester.GetDismissCount(
2720 kOrigin2, content::PermissionType::NOTIFICATIONS));
2721
2722 BlockUntilBrowsingDataRemoved(browsing_data::LAST_HOUR,
2723 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2724 false);
2725
2726 // Everything should be gone.
2727 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2728 content::PermissionType::GEOLOCATION));
2729 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2730 content::PermissionType::NOTIFICATIONS));
2731 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
2732 content::PermissionType::MIDI_SYSEX));
2733 EXPECT_EQ(0, tester.GetIgnoreCount(
2734 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2735 EXPECT_EQ(0, tester.GetDismissCount(
2736 kOrigin2, content::PermissionType::NOTIFICATIONS));
2737 }
2738 }
2739
2602 class MultipleTasksObserver { 2740 class MultipleTasksObserver {
2603 public: 2741 public:
2604 // A simple implementation of BrowsingDataRemover::Observer. 2742 // A simple implementation of BrowsingDataRemover::Observer.
2605 // MultipleTasksObserver will use several instances of Target to test 2743 // MultipleTasksObserver will use several instances of Target to test
2606 // that completion callbacks are returned to the correct one. 2744 // that completion callbacks are returned to the correct one.
2607 class Target : public BrowsingDataRemover::Observer { 2745 class Target : public BrowsingDataRemover::Observer {
2608 public: 2746 public:
2609 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) 2747 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover)
2610 : parent_(parent), 2748 : parent_(parent),
2611 observer_(this) { 2749 observer_(this) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 EXPECT_TRUE(remover->is_removing()); 2925 EXPECT_TRUE(remover->is_removing());
2788 2926
2789 // Add one more deletion and wait for it. 2927 // Add one more deletion and wait for it.
2790 BlockUntilBrowsingDataRemoved( 2928 BlockUntilBrowsingDataRemoved(
2791 browsing_data::ALL_TIME, 2929 browsing_data::ALL_TIME,
2792 BrowsingDataRemover::REMOVE_COOKIES, 2930 BrowsingDataRemover::REMOVE_COOKIES,
2793 BrowsingDataHelper::UNPROTECTED_WEB); 2931 BrowsingDataHelper::UNPROTECTED_WEB);
2794 2932
2795 EXPECT_FALSE(remover->is_removing()); 2933 EXPECT_FALSE(remover->is_removing());
2796 } 2934 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698