Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/permissions/permission_prompt_decision_log.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 9 #include "chrome/test/base/testing_profile.h" | |
| 10 #include "content/public/browser/permission_type.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 bool FilterGoogle(const GURL& url) { | |
| 15 return url == GURL("https://www.google.com"); | |
| 16 } | |
| 17 | |
| 18 bool FilterAll(const GURL& url) { | |
| 19 return true; | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 class PermissionPromptDecisionLogUnitTest | |
| 25 : public ChromeRenderViewHostTestHarness { | |
| 26 protected: | |
| 27 int GetDismissalCount(const GURL& url, | |
| 28 content::PermissionType permission) { | |
| 29 return PermissionPromptDecisionLog::GetDismissalCount(profile(), url, | |
| 30 permission); | |
| 31 } | |
| 32 | |
| 33 int RecordDismissalCount(const GURL& url, | |
| 34 content::PermissionType permission) { | |
| 35 return PermissionPromptDecisionLog::RecordDismissalCount(profile(), url, | |
|
raymes
2016/08/05 03:27:48
nit: I think it's usually better to use the public
dominickn
2016/08/05 04:29:30
Done.
| |
| 36 permission); | |
| 37 } | |
| 38 | |
| 39 }; | |
| 40 | |
| 41 TEST_F(PermissionPromptDecisionLogUnitTest, RemoveCountsByUrl) { | |
| 42 GURL url1("https://www.google.com"); | |
| 43 GURL url2("https://www.example.com"); | |
| 44 EXPECT_EQ(1, | |
| 45 RecordDismissalCount(url1, content::PermissionType::GEOLOCATION)); | |
| 46 EXPECT_EQ(2, | |
| 47 RecordDismissalCount(url1, content::PermissionType::GEOLOCATION)); | |
| 48 EXPECT_EQ(3, | |
| 49 RecordDismissalCount(url1, content::PermissionType::GEOLOCATION)); | |
| 50 | |
| 51 EXPECT_EQ(1, | |
| 52 RecordDismissalCount(url1, content::PermissionType::NOTIFICATIONS)); | |
| 53 | |
| 54 EXPECT_EQ(1, | |
| 55 RecordDismissalCount(url2, content::PermissionType::GEOLOCATION)); | |
| 56 | |
| 57 PermissionPromptDecisionLog::RemoveCountsByUrl(profile(), | |
| 58 base::Bind(&FilterGoogle)); | |
| 59 | |
| 60 // Expect that url1's dismissals are gone, but url2's remain. | |
| 61 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::GEOLOCATION)); | |
| 62 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::NOTIFICATIONS)); | |
| 63 EXPECT_EQ(1, GetDismissalCount(url2, content::PermissionType::GEOLOCATION)); | |
| 64 | |
| 65 // Add some more dismissals. | |
| 66 EXPECT_EQ(1, | |
| 67 RecordDismissalCount(url1, content::PermissionType::GEOLOCATION)); | |
| 68 EXPECT_EQ(1, | |
| 69 RecordDismissalCount(url1, content::PermissionType::NOTIFICATIONS)); | |
| 70 EXPECT_EQ(2, | |
| 71 RecordDismissalCount(url2, content::PermissionType::GEOLOCATION)); | |
| 72 | |
| 73 // Remove everything and expect that it's all gone. | |
| 74 PermissionPromptDecisionLog::RemoveCountsByUrl(profile(), | |
| 75 base::Bind(&FilterAll)); | |
| 76 | |
| 77 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::GEOLOCATION)); | |
| 78 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::NOTIFICATIONS)); | |
| 79 EXPECT_EQ(0, GetDismissalCount(url2, content::PermissionType::GEOLOCATION)); | |
| 80 } | |
| OLD | NEW |