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

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: Remove comments 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 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, IsOptedInPermissionActionReportingSignInCheck) {
kcarattini 2016/07/06 01:44:34 Can you add comments before each test fixture sayi
stefanocs 2016/07/06 04:25:45 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) {
112 base::CommandLine::ForCurrentProcess()->AppendSwitch(
113 switches::kEnablePermissionActionReporting);
114 SetSafeBrowsing(true);
115 FakeSignIn();
116
117 GetProfileSyncService()->OnUserChoseDatatypes(
118 false, syncer::ModelTypeSet(syncer::PROXY_TABS));
119 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
120
121 GetProfileSyncService()->OnUserChoseDatatypes(
122 false, syncer::ModelTypeSet(syncer::PREFERENCES));
123 EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
124
125 GetProfileSyncService()->OnUserChoseDatatypes(
126 false, syncer::ModelTypeSet(syncer::PROXY_TABS, syncer::PREFERENCES));
127 EXPECT_TRUE(IsOptedInPermissionActionReporting(profile()));
128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698