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

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: Refactor tests Created 4 years, 6 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 IsOptedInPermissionActionReporting(Profile* profile) {
33 return PermissionUmaUtil::IsOptedInPermissionActionReporting(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_F(PermissionUmaUtilTest, IsOptedInPermissionActionReporting) {
raymes 2016/06/23 00:38:55 IsOptedInPermissionActionReportingSignIn ?
stefanocs 2016/06/23 01:04:15 Done.
70 SetSafeBrowsing(true);
71 base::CommandLine::ForCurrentProcess()->AppendSwitch(
72 switches::kEnablePermissionActionReporting);
73 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
74
75 FakeSignIn();
76 EXPECT_FALSE(
77 IsOptedInPermissionActionReporting(profile()->GetOffTheRecordProfile()));
78 EXPECT_TRUE(IsOptedInPermissionActionReporting(profile()));
79 }
80
81 TEST_F(PermissionUmaUtilTest, IsOptedInPermissionActionReportingFlagCheck) {
82 SetSafeBrowsing(true);
83 FakeSignIn();
84 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
85
86 base::CommandLine::ForCurrentProcess()->AppendSwitch(
87 switches::kDisablePermissionActionReporting);
88 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
89 }
90
91 TEST_F(PermissionUmaUtilTest,
92 IsOptedInPermissionActionReportingSafeBrowsingCheck) {
93 base::CommandLine::ForCurrentProcess()->AppendSwitch(
94 switches::kEnablePermissionActionReporting);
95 FakeSignIn();
96 SetSafeBrowsing(false);
97 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
98 }
99
100 TEST_F(PermissionUmaUtilTest,
101 IsOptedInPermissionActionReportingProfileSyncServiceCheck) {
102 base::CommandLine::ForCurrentProcess()->AppendSwitch(
103 switches::kEnablePermissionActionReporting);
104 SetSafeBrowsing(true);
105 FakeSignIn();
106 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync);
107 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
108 }
109
110 TEST_F(PermissionUmaUtilTest,
111 IsOptedInPermissionActionReportingSyncPreferenceCheck) {
stefanocs 2016/06/22 04:36:03 Is the right way to do the sync preference test?
112 base::CommandLine::ForCurrentProcess()->AppendSwitch(
113 switches::kEnablePermissionActionReporting);
114 SetSafeBrowsing(true);
115 FakeSignIn();
116
117 syncer::ModelTypeSet selectable_data_types = syncer::UserSelectableTypes();
raymes 2016/06/23 00:38:55 Maybe we should start with an empty set of sync ty
stefanocs 2016/06/23 01:04:15 Done.
118
119 selectable_data_types.Remove(syncer::PROXY_TABS);
120 GetProfileSyncService()->OnUserChoseDatatypes(false, selectable_data_types);
121 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
122 selectable_data_types.Put(syncer::PROXY_TABS);
123
124 selectable_data_types.Remove(syncer::PREFERENCES);
125 GetProfileSyncService()->OnUserChoseDatatypes(false, selectable_data_types);
126 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
127 selectable_data_types.Put(syncer::PREFERENCES);
128
129 GetProfileSyncService()->OnUserChoseDatatypes(true, selectable_data_types);
130 EXPECT_TRUE(IsOptedInPermissionActionReporting(profile()));
131 }
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