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

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

Issue 2047253002: Add hooks to permission layer for permission action reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-reporter-implementation
Patch Set: Resolve nits 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/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/signin/core/browser/fake_signin_manager.h"
18 #include "components/sync_driver/glue/sync_backend_host_mock.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 const char* kTestingGaiaId = "gaia_id";
25 const char* kTestingUsername = "fake_username";
26 } // namespace
27
28 class PermissionUmaUtilTest : public testing::Test {
29 protected:
30 PermissionUmaUtilTest() : profile_(new TestingProfile()) {}
31
32 static bool IsOptedIntoPermissionActionReporting(Profile* profile) {
33 return PermissionUmaUtil::IsOptedIntoPermissionActionReporting(profile);
34 }
35
36 void SetUp() override {
37 profile_.reset(new TestingProfile());
38 base::CommandLine::Reset();
39 base::CommandLine::Init(0, NULL);
40 }
41
42 void FakeSignIn() {
43 SigninManagerBase* signin_manager = static_cast<FakeSigninManager*>(
44 SigninManagerFactory::GetForProfile(profile()));
45 signin_manager->SetAuthenticatedAccountInfo(kTestingGaiaId,
46 kTestingUsername);
47 // Attach a sync backend to the profile sync service.
48 GetProfileSyncService()->backend_.reset(
49 new browser_sync::SyncBackendHostMock());
50 GetProfileSyncService()->backend_initialized_ = true;
51 }
52
53 void SetSafeBrowsing(bool enabled) {
54 PrefService* preferences = profile_->GetPrefs();
55 preferences->SetBoolean(prefs::kSafeBrowsingEnabled, enabled);
56 }
57
58 ProfileSyncService* GetProfileSyncService() {
59 return ProfileSyncServiceFactory::GetForProfile(profile());
60 }
61
62 Profile* profile() { return profile_.get(); }
63
64 private:
65 content::TestBrowserThreadBundle thread_bundle_;
66 std::unique_ptr<Profile> profile_;
67 };
68
69 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
70 // true if Safe Browsing is enabled, Permission Action Reporting flag is
71 // enabled, not in incognito mode and signed in with default sync preferences.
72 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingSignInCheck) {
kcarattini 2016/07/06 07:27:05 In all of these tests, you should first check that
stefanocs 2016/07/06 08:17:45 Done.
73 SetSafeBrowsing(true);
74 base::CommandLine::ForCurrentProcess()->AppendSwitch(
75 switches::kEnablePermissionActionReporting);
76 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
77
78 FakeSignIn();
79 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(
80 profile()->GetOffTheRecordProfile()));
81 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile()));
82 }
83
84 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
85 // false if Permission Action Reporting is not enabled.
86 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingFlagCheck) {
87 SetSafeBrowsing(true);
88 FakeSignIn();
89 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
90
91 base::CommandLine::ForCurrentProcess()->AppendSwitch(
92 switches::kDisablePermissionActionReporting);
93 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
94 }
95
96 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
97 // false if Safe Browsing is disabled.
98 TEST_F(PermissionUmaUtilTest,
99 IsOptedIntoPermissionActionReportingSafeBrowsingCheck) {
100 base::CommandLine::ForCurrentProcess()->AppendSwitch(
101 switches::kEnablePermissionActionReporting);
102 FakeSignIn();
103 SetSafeBrowsing(false);
104 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
105 }
106
107 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
108 // false if Safe Browsing is disabled.
109 TEST_F(PermissionUmaUtilTest,
110 IsOptedIntoPermissionActionReportingProfileSyncServiceCheck) {
111 base::CommandLine::ForCurrentProcess()->AppendSwitch(
112 switches::kEnablePermissionActionReporting);
113 SetSafeBrowsing(true);
114 FakeSignIn();
115 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync);
116 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
117 }
118
119 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns
120 // false if Tab Sync and Pref Sync are not both enabled.
121 TEST_F(PermissionUmaUtilTest,
122 IsOptedIntoPermissionActionReportingSyncPreferenceCheck) {
123 base::CommandLine::ForCurrentProcess()->AppendSwitch(
124 switches::kEnablePermissionActionReporting);
125 SetSafeBrowsing(true);
126 FakeSignIn();
127
128 GetProfileSyncService()->OnUserChoseDatatypes(
129 false, syncer::ModelTypeSet(syncer::PROXY_TABS));
130 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
131
132 GetProfileSyncService()->OnUserChoseDatatypes(
133 false, syncer::ModelTypeSet(syncer::PREFERENCES));
134 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile()));
135
136 GetProfileSyncService()->OnUserChoseDatatypes(
137 false, syncer::ModelTypeSet(syncer::PROXY_TABS, syncer::PREFERENCES));
138 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile()));
139 }
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