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

Side by Side Diff: chrome/browser/permissions/permission_uma_util_unittest.cc

Issue 2150903002: Reland add hooks to permission layer for permission action reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wrap sync pref with std::unique_ptr Created 4 years, 5 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
(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_uma_util.h"
6
7 #include "base/test/scoped_command_line.h"
8 #include "chrome/browser/signin/fake_signin_manager_builder.h"
9 #include "chrome/browser/signin/signin_manager_factory.h"
10 #include "chrome/browser/sync/profile_sync_service_factory.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "components/browser_sync/browser/profile_sync_service.h"
15 #include "components/browser_sync/common/browser_sync_switches.h"
16 #include "components/prefs/pref_service.h"
17 #include "components/sync_driver/glue/sync_backend_host_mock.h"
18 #include "components/sync_driver/sync_prefs.h"
19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "sync/internal_api/public/base/model_type.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 namespace {
24 constexpr char kTestingGaiaId[] = "gaia_id";
25 constexpr char kTestingUsername[] = "fake_username";
26 } // namespace
27
28 class PermissionUmaUtilTest : public testing::Test {
29 protected:
30 PermissionUmaUtilTest() {}
31
32 static bool IsOptedIntoPermissionActionReporting(Profile* profile) {
33 return PermissionUmaUtil::IsOptedIntoPermissionActionReporting(profile);
34 }
35
36 void SetUp() override {
37 TestingProfile::Builder builder;
38 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
39 BuildFakeSigninManagerBase);
40 profile_ = builder.Build();
41 }
42
43 void FakeSignIn() {
44 SigninManagerBase* signin_manager =
45 static_cast<FakeSigninManagerForTesting*>(
46 SigninManagerFactory::GetForProfile(profile()));
47 signin_manager->SetAuthenticatedAccountInfo(kTestingGaiaId,
48 kTestingUsername);
49 }
50
51 void SetSafeBrowsing(bool enabled) {
52 PrefService* preferences = profile_->GetPrefs();
53 preferences->SetBoolean(prefs::kSafeBrowsingEnabled, enabled);
54 }
55
56 ProfileSyncService* GetProfileSyncService() {
57 return ProfileSyncServiceFactory::GetForProfile(profile());
58 }
59
60 Profile* profile() { return profile_.get(); }
61
62 private:
63 content::TestBrowserThreadBundle thread_bundle_;
64 std::unique_ptr<TestingProfile> profile_;
65 };
66
67 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
68 // true if Safe Browsing is enabled, Permission Action Reporting flag is
69 // enabled, not in incognito mode and signed in with default sync preferences.
70 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingSignInCheck) {
71 base::test::ScopedCommandLine scoped_command_line;
72 SetSafeBrowsing(true);
73 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
74 switches::kEnablePermissionActionReporting);
75 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
76
77 FakeSignIn();
78 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(
79 profile()->GetOffTheRecordProfile()));
80 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile()));
81 }
82
83 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
84 // false if Permission Action Reporting is not enabled.
85 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingFlagCheck) {
86 SetSafeBrowsing(true);
87 FakeSignIn();
88 {
89 base::test::ScopedCommandLine scoped_command_line;
90 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
91 switches::kEnablePermissionActionReporting);
92 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile()));
93 } // Reset the command line.
94
95 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
96
97 base::test::ScopedCommandLine scoped_command_line;
98 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
99 switches::kDisablePermissionActionReporting);
100 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
101 }
102
103 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
104 // false if Safe Browsing is disabled.
105 TEST_F(PermissionUmaUtilTest,
106 IsOptedIntoPermissionActionReportingSafeBrowsingCheck) {
107 base::test::ScopedCommandLine scoped_command_line;
108 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
109 switches::kEnablePermissionActionReporting);
110 FakeSignIn();
111 SetSafeBrowsing(true);
112 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile()));
113
114 SetSafeBrowsing(false);
115 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
116 }
117
118 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
119 // false if Sync is disabled.
120 TEST_F(PermissionUmaUtilTest,
121 IsOptedIntoPermissionActionReportingProfileSyncServiceCheck) {
122 base::test::ScopedCommandLine scoped_command_line;
123 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
124 switches::kEnablePermissionActionReporting);
125 SetSafeBrowsing(true);
126 FakeSignIn();
127 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile()));
128
129 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
130 switches::kDisableSync);
131 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
132 }
133
134 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
135 // false if Tab Sync and Pref Sync are not both enabled.
136 TEST_F(PermissionUmaUtilTest,
137 IsOptedIntoPermissionActionReportingSyncPreferenceCheck) {
138 base::test::ScopedCommandLine scoped_command_line;
139 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
140 switches::kEnablePermissionActionReporting);
141 SetSafeBrowsing(true);
142 FakeSignIn();
143 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile()));
144
145 std::unique_ptr<sync_driver::SyncPrefs> sync_pref(
pavely 2016/07/18 05:21:55 nit: You don't need to allocate SyncPrefs object f
stefanocs 2016/07/18 05:45:59 Done.
146 new sync_driver::SyncPrefs(profile()->GetPrefs()));
147 const syncer::ModelTypeSet registered_types =
148 GetProfileSyncService()->GetRegisteredDataTypes();
149 sync_pref->SetKeepEverythingSynced(false);
150
151 sync_pref->SetPreferredDataTypes(
152 registered_types, syncer::ModelTypeSet(syncer::PROXY_TABS));
153 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
154
155 sync_pref->SetPreferredDataTypes(
156 registered_types, syncer::ModelTypeSet(syncer::PRIORITY_PREFERENCES));
157 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
158
159 sync_pref->SetPreferredDataTypes(
160 registered_types,
161 syncer::ModelTypeSet(syncer::PROXY_TABS, syncer::PRIORITY_PREFERENCES));
162 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile()));
163 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_uma_util.cc ('k') | chrome/browser/permissions/permission_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698