Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/permissions/permission_uma_util.h" | 5 #include "chrome/browser/permissions/permission_uma_util.h" |
| 6 | 6 |
| 7 #include "base/test/scoped_command_line.h" | 7 #include "base/test/scoped_command_line.h" |
| 8 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 8 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | 9 #include "chrome/browser/signin/signin_manager_factory.h" |
| 10 #include "chrome/browser/sync/profile_sync_service_factory.h" | 10 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 11 #include "chrome/browser/sync/profile_sync_test_util.h" | |
| 11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/browser_sync/browser/profile_sync_service.h" | 15 #include "components/browser_sync/browser/profile_sync_service.h" |
| 16 #include "components/browser_sync/browser/profile_sync_service_mock.h" | |
| 15 #include "components/browser_sync/common/browser_sync_switches.h" | 17 #include "components/browser_sync/common/browser_sync_switches.h" |
| 16 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 17 #include "components/sync/base/model_type.h" | 19 #include "components/sync/base/model_type.h" |
| 18 #include "components/sync/driver/glue/sync_backend_host_mock.h" | 20 #include "components/sync/driver/glue/sync_backend_host_mock.h" |
| 19 #include "components/sync/driver/sync_prefs.h" | 21 #include "components/sync/driver/sync_prefs.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 constexpr char kTestingGaiaId[] = "gaia_id"; | 26 constexpr char kTestingGaiaId[] = "gaia_id"; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 50 | 52 |
| 51 void SetSafeBrowsing(bool enabled) { | 53 void SetSafeBrowsing(bool enabled) { |
| 52 PrefService* preferences = profile_->GetPrefs(); | 54 PrefService* preferences = profile_->GetPrefs(); |
| 53 preferences->SetBoolean(prefs::kSafeBrowsingEnabled, enabled); | 55 preferences->SetBoolean(prefs::kSafeBrowsingEnabled, enabled); |
| 54 } | 56 } |
| 55 | 57 |
| 56 ProfileSyncService* GetProfileSyncService() { | 58 ProfileSyncService* GetProfileSyncService() { |
| 57 return ProfileSyncServiceFactory::GetForProfile(profile()); | 59 return ProfileSyncServiceFactory::GetForProfile(profile()); |
| 58 } | 60 } |
| 59 | 61 |
| 62 ProfileSyncServiceMock* SetMockSyncService() { | |
| 63 ProfileSyncServiceMock* mock_sync_service = | |
| 64 static_cast<ProfileSyncServiceMock*>( | |
| 65 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 66 profile(), BuildMockProfileSyncService)); | |
| 67 EXPECT_CALL(*mock_sync_service, CanSyncStart()) | |
| 68 .WillRepeatedly(testing::Return(true)); | |
| 69 EXPECT_CALL(*mock_sync_service, IsSyncActive()) | |
| 70 .WillRepeatedly(testing::Return(true)); | |
| 71 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | |
| 72 .WillRepeatedly(testing::Return(false)); | |
| 73 | |
| 74 syncer::ModelTypeSet preferred_types; | |
| 75 preferred_types.Put(syncer::PROXY_TABS); | |
| 76 preferred_types.Put(syncer::PRIORITY_PREFERENCES); | |
| 77 EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) | |
| 78 .WillRepeatedly(testing::Return(preferred_types)); | |
| 79 | |
| 80 return mock_sync_service; | |
| 81 } | |
| 82 | |
| 60 Profile* profile() { return profile_.get(); } | 83 Profile* profile() { return profile_.get(); } |
| 61 | 84 |
| 62 private: | 85 private: |
| 63 content::TestBrowserThreadBundle thread_bundle_; | 86 content::TestBrowserThreadBundle thread_bundle_; |
| 64 std::unique_ptr<TestingProfile> profile_; | 87 std::unique_ptr<TestingProfile> profile_; |
| 65 }; | 88 }; |
| 66 | 89 |
| 67 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 90 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 68 // true if Safe Browsing is enabled, Permission Action Reporting flag is | 91 // true if Safe Browsing is enabled, Permission Action Reporting flag is |
| 69 // enabled, not in incognito mode and signed in with default sync preferences. | 92 // enabled, not in incognito mode and signed in with default sync preferences. |
| 70 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingSignInCheck) { | 93 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingSignInCheck) { |
| 71 base::test::ScopedCommandLine scoped_command_line; | 94 base::test::ScopedCommandLine scoped_command_line; |
| 72 SetSafeBrowsing(true); | 95 SetSafeBrowsing(true); |
| 73 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 96 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 74 switches::kEnablePermissionActionReporting); | 97 switches::kEnablePermissionActionReporting); |
| 75 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 98 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 76 | 99 |
| 77 FakeSignIn(); | 100 FakeSignIn(); |
| 101 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | |
| 102 | |
| 103 SetMockSyncService(); | |
| 78 EXPECT_FALSE(IsOptedIntoPermissionActionReporting( | 104 EXPECT_FALSE(IsOptedIntoPermissionActionReporting( |
| 79 profile()->GetOffTheRecordProfile())); | 105 profile()->GetOffTheRecordProfile())); |
| 80 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 106 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 81 } | 107 } |
| 82 | 108 |
| 83 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 109 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 84 // false if Permission Action Reporting is not enabled. | 110 // false if Permission Action Reporting is not enabled. |
| 85 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingFlagCheck) { | 111 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingFlagCheck) { |
| 86 SetSafeBrowsing(true); | 112 SetSafeBrowsing(true); |
| 87 FakeSignIn(); | 113 FakeSignIn(); |
| 114 SetMockSyncService(); | |
| 88 { | 115 { |
| 89 base::test::ScopedCommandLine scoped_command_line; | 116 base::test::ScopedCommandLine scoped_command_line; |
| 90 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 117 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 91 switches::kEnablePermissionActionReporting); | 118 switches::kEnablePermissionActionReporting); |
| 92 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 119 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 93 } // Reset the command line. | 120 } // Reset the command line. |
| 94 | 121 |
| 95 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 122 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 96 | 123 |
| 97 base::test::ScopedCommandLine scoped_command_line; | 124 base::test::ScopedCommandLine scoped_command_line; |
| 98 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 125 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 99 switches::kDisablePermissionActionReporting); | 126 switches::kDisablePermissionActionReporting); |
| 100 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 127 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 101 } | 128 } |
| 102 | 129 |
| 103 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 130 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 104 // false if Safe Browsing is disabled. | 131 // false if Safe Browsing is disabled. |
| 105 TEST_F(PermissionUmaUtilTest, | 132 TEST_F(PermissionUmaUtilTest, |
| 106 IsOptedIntoPermissionActionReportingSafeBrowsingCheck) { | 133 IsOptedIntoPermissionActionReportingSafeBrowsingCheck) { |
| 107 base::test::ScopedCommandLine scoped_command_line; | 134 base::test::ScopedCommandLine scoped_command_line; |
| 108 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 135 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 109 switches::kEnablePermissionActionReporting); | 136 switches::kEnablePermissionActionReporting); |
| 110 FakeSignIn(); | 137 FakeSignIn(); |
| 138 SetMockSyncService(); | |
| 111 SetSafeBrowsing(true); | 139 SetSafeBrowsing(true); |
| 112 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 140 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 113 | 141 |
| 114 SetSafeBrowsing(false); | 142 SetSafeBrowsing(false); |
| 115 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 143 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 116 } | 144 } |
| 117 | 145 |
| 118 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 146 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 119 // false if Sync is disabled. | 147 // false if Sync is disabled. |
| 120 TEST_F(PermissionUmaUtilTest, | 148 TEST_F(PermissionUmaUtilTest, |
| 121 IsOptedIntoPermissionActionReportingProfileSyncServiceCheck) { | 149 IsOptedIntoPermissionActionReportingProfileSyncServiceCheck) { |
| 122 base::test::ScopedCommandLine scoped_command_line; | 150 base::test::ScopedCommandLine scoped_command_line; |
| 123 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 151 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 124 switches::kEnablePermissionActionReporting); | 152 switches::kEnablePermissionActionReporting); |
| 125 SetSafeBrowsing(true); | 153 SetSafeBrowsing(true); |
| 126 FakeSignIn(); | 154 FakeSignIn(); |
| 155 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); | |
| 127 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 156 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 128 | 157 |
| 129 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 158 EXPECT_CALL(*mock_sync_service, CanSyncStart()) |
| 130 switches::kDisableSync); | 159 .WillOnce(testing::Return(false)); |
|
Nathan Parker
2016/08/19 00:08:48
Does this work? (I assume so). Like, it override
kcarattini
2016/08/19 01:05:45
Yup.
| |
| 131 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 160 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 132 } | 161 } |
| 133 | 162 |
| 134 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 163 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 135 // false if Tab Sync and Pref Sync are not both enabled. | 164 // false if Tab Sync and Pref Sync are not both enabled. |
| 136 TEST_F(PermissionUmaUtilTest, | 165 TEST_F(PermissionUmaUtilTest, |
| 137 IsOptedIntoPermissionActionReportingSyncPreferenceCheck) { | 166 IsOptedIntoPermissionActionReportingSyncPreferenceCheck) { |
| 138 base::test::ScopedCommandLine scoped_command_line; | 167 base::test::ScopedCommandLine scoped_command_line; |
| 139 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 168 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 140 switches::kEnablePermissionActionReporting); | 169 switches::kEnablePermissionActionReporting); |
| 141 SetSafeBrowsing(true); | 170 SetSafeBrowsing(true); |
| 142 FakeSignIn(); | 171 FakeSignIn(); |
| 172 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); | |
| 143 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 173 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 144 | 174 |
| 145 sync_driver::SyncPrefs sync_prefs(profile()->GetPrefs()); | 175 // Reset the preferred types to return an empty set. The opted-in method will |
| 146 const syncer::ModelTypeSet registered_types = | 176 // return false because it needs both Tab and Pref Sync in the preferred types |
| 147 GetProfileSyncService()->GetRegisteredDataTypes(); | 177 // in order to succeed. |
| 148 sync_prefs.SetKeepEverythingSynced(false); | 178 syncer::ModelTypeSet preferred_types; |
| 149 | 179 EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) |
| 150 sync_prefs.SetPreferredDataTypes( | 180 .WillOnce(testing::Return(preferred_types)); |
| 151 registered_types, syncer::ModelTypeSet(syncer::PROXY_TABS)); | |
| 152 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 181 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 153 | 182 |
| 154 sync_prefs.SetPreferredDataTypes( | 183 // The opted-in method will be false with only Tab Sync on. |
| 155 registered_types, syncer::ModelTypeSet(syncer::PRIORITY_PREFERENCES)); | 184 preferred_types.Put(syncer::PROXY_TABS); |
| 185 EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) | |
| 186 .WillOnce(testing::Return(preferred_types)); | |
| 156 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 187 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 157 | 188 |
| 158 sync_prefs.SetPreferredDataTypes( | 189 // The opted-in method will be false with only Pref Sync on. |
| 159 registered_types, | 190 preferred_types.Remove(syncer::PROXY_TABS); |
| 160 syncer::ModelTypeSet(syncer::PROXY_TABS, syncer::PRIORITY_PREFERENCES)); | 191 preferred_types.Put(syncer::PRIORITY_PREFERENCES); |
| 192 EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) | |
| 193 .WillOnce(testing::Return(preferred_types)); | |
| 194 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | |
| 195 } | |
| 196 | |
| 197 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | |
| 198 // false if Sync is not active. | |
| 199 TEST_F(PermissionUmaUtilTest, | |
| 200 IsOptedIntoPermissionActionReportingProfileSyncServiceActiveCheck) { | |
| 201 base::test::ScopedCommandLine scoped_command_line; | |
| 202 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | |
| 203 switches::kEnablePermissionActionReporting); | |
| 204 SetSafeBrowsing(true); | |
| 205 FakeSignIn(); | |
| 206 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); | |
| 161 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 207 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 208 | |
| 209 EXPECT_CALL(*mock_sync_service, IsSyncActive()) | |
| 210 .WillOnce(testing::Return(false)); | |
| 211 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | |
| 162 } | 212 } |
| 213 | |
| 214 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | |
| 215 // false if a custom Sync passphrase is set. | |
| 216 TEST_F(PermissionUmaUtilTest, | |
| 217 IsOptedIntoPermissionActionReportingSyncPassphraseCheck) { | |
| 218 base::test::ScopedCommandLine scoped_command_line; | |
| 219 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | |
| 220 switches::kEnablePermissionActionReporting); | |
| 221 SetSafeBrowsing(true); | |
| 222 FakeSignIn(); | |
| 223 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); | |
| 224 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | |
| 225 | |
| 226 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | |
| 227 .WillOnce(testing::Return(true)); | |
| 228 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | |
| 229 } | |
| OLD | NEW |