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

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

Issue 2640033006: Convert AutoBlocker static class to KeyedService. (Closed)
Patch Set: Remove ShouldChangeDismissalToBlock Created 3 years, 11 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 10 matching lines...) Expand all
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/memory/ptr_util.h" 23 #include "base/memory/ptr_util.h"
24 #include "base/message_loop/message_loop.h" 24 #include "base/message_loop/message_loop.h"
25 #include "base/run_loop.h" 25 #include "base/run_loop.h"
26 #include "base/single_thread_task_runner.h" 26 #include "base/single_thread_task_runner.h"
27 #include "base/strings/string_number_conversions.h" 27 #include "base/strings/string_number_conversions.h"
28 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
29 #include "base/task/cancelable_task_tracker.h" 29 #include "base/task/cancelable_task_tracker.h"
30 #include "base/threading/thread_task_runner_handle.h" 30 #include "base/threading/thread_task_runner_handle.h"
31 #include "base/time/time.h"
31 #include "build/build_config.h" 32 #include "build/build_config.h"
32 #include "chrome/browser/autofill/personal_data_manager_factory.h" 33 #include "chrome/browser/autofill/personal_data_manager_factory.h"
33 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 34 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
34 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" 35 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
35 #include "chrome/browser/browsing_data/browsing_data_helper.h" 36 #include "chrome/browser/browsing_data/browsing_data_helper.h"
36 #include "chrome/browser/browsing_data/browsing_data_remover.h" 37 #include "chrome/browser/browsing_data/browsing_data_remover.h"
37 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 38 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
38 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" 39 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h"
39 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 40 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
40 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" 41 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 password_manager::MockPasswordStore* store() { return store_; } 1051 password_manager::MockPasswordStore* store() { return store_; }
1051 1052
1052 private: 1053 private:
1053 password_manager::MockPasswordStore* store_; 1054 password_manager::MockPasswordStore* store_;
1054 1055
1055 DISALLOW_COPY_AND_ASSIGN(RemovePasswordsTester); 1056 DISALLOW_COPY_AND_ASSIGN(RemovePasswordsTester);
1056 }; 1057 };
1057 1058
1058 class RemovePermissionPromptCountsTest { 1059 class RemovePermissionPromptCountsTest {
1059 public: 1060 public:
1060 explicit RemovePermissionPromptCountsTest(TestingProfile* profile) 1061 explicit RemovePermissionPromptCountsTest(TestingProfile* profile) {
1061 : profile_(profile) {} 1062 autoblocker_ = PermissionDecisionAutoBlocker::GetForProfile(profile);
1063 }
1062 1064
1063 int GetDismissCount(const GURL& url, content::PermissionType permission) { 1065 int GetDismissCount(const GURL& url, content::PermissionType permission) {
1064 return PermissionDecisionAutoBlocker::GetDismissCount( 1066 return autoblocker_->GetDismissCount(url, permission);
1065 url, permission, profile_);
1066 } 1067 }
1067 1068
1068 int GetIgnoreCount(const GURL& url, content::PermissionType permission) { 1069 int GetIgnoreCount(const GURL& url, content::PermissionType permission) {
1069 return PermissionDecisionAutoBlocker::GetIgnoreCount( 1070 return autoblocker_->GetIgnoreCount(url, permission);
1070 url, permission, profile_);
1071 } 1071 }
1072 1072
1073 int RecordIgnore(const GURL& url, content::PermissionType permission) { 1073 int RecordIgnore(const GURL& url, content::PermissionType permission) {
1074 return PermissionDecisionAutoBlocker::RecordIgnore(url, permission, 1074 return autoblocker_->RecordIgnore(url, permission);
1075 profile_);
1076 } 1075 }
1077 1076
1078 bool ShouldChangeDismissalToBlock(const GURL& url, 1077 bool RecordDismissAndEmbargo(const GURL& url,
1079 content::PermissionType permission) { 1078 content::PermissionType permission) {
1080 return PermissionDecisionAutoBlocker::ShouldChangeDismissalToBlock( 1079 return autoblocker_->RecordDismissAndEmbargo(url, permission,
1081 url, permission, profile_); 1080 base::Time::Now());
1082 } 1081 }
1083 1082
1084 private: 1083 private:
1085 TestingProfile* profile_; 1084 PermissionDecisionAutoBlocker* autoblocker_;
1086 1085
1087 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest); 1086 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest);
1088 }; 1087 };
1089 1088
1090 #if BUILDFLAG(ENABLE_PLUGINS) 1089 #if BUILDFLAG(ENABLE_PLUGINS)
1091 // A small modification to MockBrowsingDataFlashLSOHelper so that it responds 1090 // A small modification to MockBrowsingDataFlashLSOHelper so that it responds
1092 // immediately and does not wait for the Notify() call. Otherwise it would 1091 // immediately and does not wait for the Notify() call. Otherwise it would
1093 // deadlock BrowsingDataRemoverImpl::RemoveImpl. 1092 // deadlock BrowsingDataRemoverImpl::RemoveImpl.
1094 class TestBrowsingDataFlashLSOHelper : public MockBrowsingDataFlashLSOHelper { 1093 class TestBrowsingDataFlashLSOHelper : public MockBrowsingDataFlashLSOHelper {
1095 public: 1094 public:
(...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after
2756 filter_builder_2.AddRegisterableDomain(kTestRegisterableDomain1); 2755 filter_builder_2.AddRegisterableDomain(kTestRegisterableDomain1);
2757 2756
2758 { 2757 {
2759 // Test REMOVE_HISTORY. 2758 // Test REMOVE_HISTORY.
2760 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, 2759 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2761 content::PermissionType::GEOLOCATION)); 2760 content::PermissionType::GEOLOCATION));
2762 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1, 2761 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1,
2763 content::PermissionType::GEOLOCATION)); 2762 content::PermissionType::GEOLOCATION));
2764 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, 2763 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2765 content::PermissionType::NOTIFICATIONS)); 2764 content::PermissionType::NOTIFICATIONS));
2766 tester.ShouldChangeDismissalToBlock(kOrigin1, 2765 tester.RecordDismissAndEmbargo(kOrigin1,
2767 content::PermissionType::MIDI_SYSEX); 2766 content::PermissionType::MIDI_SYSEX);
dominickn 2017/01/20 04:03:47 Nit: indentation
meredithl 2017/01/20 04:21:33 Done.
2768 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2, 2767 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2,
2769 content::PermissionType::DURABLE_STORAGE)); 2768 content::PermissionType::DURABLE_STORAGE));
2770 tester.ShouldChangeDismissalToBlock(kOrigin2, 2769 tester.RecordDismissAndEmbargo(kOrigin2,
dominickn 2017/01/20 04:03:47 Nit: indentation
meredithl 2017/01/20 04:21:33 Done.
2771 content::PermissionType::NOTIFICATIONS); 2770 content::PermissionType::NOTIFICATIONS);
2772 2771
2773 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), 2772 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
2774 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, 2773 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2775 filter_builder_1); 2774 filter_builder_1);
2776 2775
2777 // kOrigin1 should be gone, but kOrigin2 remains. 2776 // kOrigin1 should be gone, but kOrigin2 remains.
2778 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, 2777 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2779 content::PermissionType::GEOLOCATION)); 2778 content::PermissionType::GEOLOCATION));
2780 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, 2779 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
(...skipping 21 matching lines...) Expand all
2802 kOrigin2, content::PermissionType::NOTIFICATIONS)); 2801 kOrigin2, content::PermissionType::NOTIFICATIONS));
2803 } 2802 }
2804 { 2803 {
2805 // Test REMOVE_SITE_DATA. 2804 // Test REMOVE_SITE_DATA.
2806 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, 2805 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2807 content::PermissionType::GEOLOCATION)); 2806 content::PermissionType::GEOLOCATION));
2808 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1, 2807 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1,
2809 content::PermissionType::GEOLOCATION)); 2808 content::PermissionType::GEOLOCATION));
2810 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, 2809 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2811 content::PermissionType::NOTIFICATIONS)); 2810 content::PermissionType::NOTIFICATIONS));
2812 tester.ShouldChangeDismissalToBlock(kOrigin1, 2811 tester.RecordDismissAndEmbargo(kOrigin1,
dominickn 2017/01/20 04:03:46 Nit: indentation
meredithl 2017/01/20 04:21:33 Done.
2813 content::PermissionType::MIDI_SYSEX); 2812 content::PermissionType::MIDI_SYSEX);
2814 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2, 2813 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2,
2815 content::PermissionType::DURABLE_STORAGE)); 2814 content::PermissionType::DURABLE_STORAGE));
2816 tester.ShouldChangeDismissalToBlock(kOrigin2, 2815 tester.RecordDismissAndEmbargo(kOrigin2,
dominickn 2017/01/20 04:03:47 Nit: indentation
meredithl 2017/01/20 04:21:33 Done.
2817 content::PermissionType::NOTIFICATIONS); 2816 content::PermissionType::NOTIFICATIONS);
2818 2817
2819 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), 2818 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
2820 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, 2819 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2821 filter_builder_2); 2820 filter_builder_2);
2822 2821
2823 // kOrigin2 should be gone, but kOrigin1 remains. 2822 // kOrigin2 should be gone, but kOrigin1 remains.
2824 EXPECT_EQ(2, tester.GetIgnoreCount(kOrigin1, 2823 EXPECT_EQ(2, tester.GetIgnoreCount(kOrigin1,
2825 content::PermissionType::GEOLOCATION)); 2824 content::PermissionType::GEOLOCATION));
2826 EXPECT_EQ(1, tester.GetIgnoreCount(kOrigin1, 2825 EXPECT_EQ(1, tester.GetIgnoreCount(kOrigin1,
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
3129 completion_observer.BlockUntilCompletion(); 3128 completion_observer.BlockUntilCompletion();
3130 3129
3131 // There should be only 1 recently visited bookmarks. 3130 // There should be only 1 recently visited bookmarks.
3132 std::vector<const bookmarks::BookmarkNode*> remaining_nodes = 3131 std::vector<const bookmarks::BookmarkNode*> remaining_nodes =
3133 ntp_snippets::GetRecentlyVisitedBookmarks( 3132 ntp_snippets::GetRecentlyVisitedBookmarks(
3134 bookmark_model, 3, base::Time::UnixEpoch(), 3133 bookmark_model, 3, base::Time::UnixEpoch(),
3135 /*consider_visits_from_desktop=*/true); 3134 /*consider_visits_from_desktop=*/true);
3136 EXPECT_THAT(remaining_nodes, SizeIs(1)); 3135 EXPECT_THAT(remaining_nodes, SizeIs(1));
3137 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/")); 3136 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/"));
3138 } 3137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698