OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/permissions/permission_decision_auto_blocker.h" | 5 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
10 #include "content/public/browser/permission_type.h" | 10 #include "content/public/browser/permission_type.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 bool FilterGoogle(const GURL& url) { | 14 bool FilterGoogle(const GURL& url) { |
15 return url == GURL("https://www.google.com"); | 15 return url == GURL("https://www.google.com"); |
16 } | 16 } |
17 | 17 |
18 bool FilterAll(const GURL& url) { | 18 bool FilterAll(const GURL& url) { |
19 return true; | 19 return true; |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 class PermissionDecisionAutoBlockerUnitTest | 24 class PermissionDecisionAutoBlockerUnitTest |
25 : public ChromeRenderViewHostTestHarness { | 25 : public ChromeRenderViewHostTestHarness { |
26 protected: | 26 protected: |
27 int GetDismissalCount(const GURL& url, | 27 int GetDismissalCount(const GURL& url, |
28 content::PermissionType permission) { | 28 content::PermissionType permission) { |
29 return PermissionDecisionAutoBlocker(profile()).GetActionCountForTest( | 29 return PermissionDecisionAutoBlocker::GetDismissCount( |
30 url, permission, PermissionDecisionAutoBlocker::kPromptDismissCountKey); | 30 url, permission, profile()); |
31 } | 31 } |
32 | 32 |
33 int GetIgnoreCount(const GURL& url, content::PermissionType permission) { | 33 int GetIgnoreCount(const GURL& url, content::PermissionType permission) { |
34 return PermissionDecisionAutoBlocker(profile()).GetActionCountForTest( | 34 return PermissionDecisionAutoBlocker::GetIgnoreCount( |
35 url, permission, PermissionDecisionAutoBlocker::kPromptIgnoreCountKey); | 35 url, permission, profile()); |
36 } | 36 } |
37 | 37 |
38 int RecordDismiss(const GURL& url, content::PermissionType permission) { | 38 int RecordDismiss(const GURL& url, content::PermissionType permission) { |
39 PermissionDecisionAutoBlocker blocker(profile()); | 39 PermissionDecisionAutoBlocker blocker(profile()); |
40 blocker.ShouldChangeDismissalToBlock(url, permission); | 40 blocker.ShouldChangeDismissalToBlock(url, permission); |
41 return blocker.GetActionCountForTest( | 41 return PermissionDecisionAutoBlocker::GetDismissCount( |
42 url, permission, PermissionDecisionAutoBlocker::kPromptDismissCountKey); | 42 url, permission, profile()); |
43 } | 43 } |
44 | 44 |
45 int RecordIgnore(const GURL& url, content::PermissionType permission) { | 45 int RecordIgnore(const GURL& url, content::PermissionType permission) { |
46 return PermissionDecisionAutoBlocker(profile()).RecordIgnore(url, | 46 return PermissionDecisionAutoBlocker(profile()).RecordIgnore(url, |
47 permission); | 47 permission); |
48 } | 48 } |
49 }; | 49 }; |
50 | 50 |
51 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { | 51 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { |
52 GURL url1("https://www.google.com"); | 52 GURL url1("https://www.google.com"); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::GEOLOCATION)); | 95 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::GEOLOCATION)); |
96 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::NOTIFICATIONS)); | 96 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::NOTIFICATIONS)); |
97 EXPECT_EQ(0, GetDismissalCount(url2, content::PermissionType::GEOLOCATION)); | 97 EXPECT_EQ(0, GetDismissalCount(url2, content::PermissionType::GEOLOCATION)); |
98 | 98 |
99 EXPECT_EQ(0, GetIgnoreCount(url1, content::PermissionType::GEOLOCATION)); | 99 EXPECT_EQ(0, GetIgnoreCount(url1, content::PermissionType::GEOLOCATION)); |
100 EXPECT_EQ(0, GetIgnoreCount(url1, content::PermissionType::NOTIFICATIONS)); | 100 EXPECT_EQ(0, GetIgnoreCount(url1, content::PermissionType::NOTIFICATIONS)); |
101 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::GEOLOCATION)); | 101 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::GEOLOCATION)); |
102 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::DURABLE_STORAGE)); | 102 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::DURABLE_STORAGE)); |
103 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::MIDI_SYSEX)); | 103 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::MIDI_SYSEX)); |
104 } | 104 } |
OLD | NEW |