| 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" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 content::TestBrowserThreadBundle thread_bundle_; | 86 content::TestBrowserThreadBundle thread_bundle_; |
| 87 std::unique_ptr<TestingProfile> profile_; | 87 std::unique_ptr<TestingProfile> profile_; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 90 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 91 // true if Safe Browsing is enabled, Permission Action Reporting flag is | 91 // true if Safe Browsing is enabled, Permission Action Reporting flag is |
| 92 // 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. |
| 93 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingSignInCheck) { | 93 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingSignInCheck) { |
| 94 base::test::ScopedCommandLine scoped_command_line; | |
| 95 SetSafeBrowsing(true); | 94 SetSafeBrowsing(true); |
| 96 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | |
| 97 switches::kEnablePermissionActionReporting); | |
| 98 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 95 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 99 | 96 |
| 100 FakeSignIn(); | 97 FakeSignIn(); |
| 101 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 98 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 102 | 99 |
| 103 SetMockSyncService(); | 100 SetMockSyncService(); |
| 104 EXPECT_FALSE(IsOptedIntoPermissionActionReporting( | 101 EXPECT_FALSE(IsOptedIntoPermissionActionReporting( |
| 105 profile()->GetOffTheRecordProfile())); | 102 profile()->GetOffTheRecordProfile())); |
| 106 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 103 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 107 } | 104 } |
| 108 | 105 |
| 109 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 106 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 110 // false if Permission Action Reporting is not enabled. | 107 // false if Permission Action Reporting is not enabled. |
| 111 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingFlagCheck) { | 108 TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingFlagCheck) { |
| 112 SetSafeBrowsing(true); | 109 SetSafeBrowsing(true); |
| 113 FakeSignIn(); | 110 FakeSignIn(); |
| 114 SetMockSyncService(); | 111 SetMockSyncService(); |
| 112 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 115 { | 113 { |
| 116 base::test::ScopedCommandLine scoped_command_line; | 114 base::test::ScopedCommandLine scoped_command_line; |
| 117 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 115 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 118 switches::kEnablePermissionActionReporting); | 116 switches::kDisablePermissionActionReporting); |
| 119 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 117 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 120 } // Reset the command line. | 118 } // Reset the command line. |
| 121 | 119 |
| 122 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 120 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 123 | 121 |
| 124 base::test::ScopedCommandLine scoped_command_line; | 122 base::test::ScopedCommandLine scoped_command_line; |
| 125 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 123 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 126 switches::kDisablePermissionActionReporting); | 124 switches::kEnablePermissionActionReporting); |
| 127 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 125 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 128 } | 126 } |
| 129 | 127 |
| 130 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 128 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 131 // false if Safe Browsing is disabled. | 129 // false if Safe Browsing is disabled. |
| 132 TEST_F(PermissionUmaUtilTest, | 130 TEST_F(PermissionUmaUtilTest, |
| 133 IsOptedIntoPermissionActionReportingSafeBrowsingCheck) { | 131 IsOptedIntoPermissionActionReportingSafeBrowsingCheck) { |
| 134 base::test::ScopedCommandLine scoped_command_line; | |
| 135 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | |
| 136 switches::kEnablePermissionActionReporting); | |
| 137 FakeSignIn(); | 132 FakeSignIn(); |
| 138 SetMockSyncService(); | 133 SetMockSyncService(); |
| 139 SetSafeBrowsing(true); | 134 SetSafeBrowsing(true); |
| 140 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 135 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 141 | 136 |
| 142 SetSafeBrowsing(false); | 137 SetSafeBrowsing(false); |
| 143 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 138 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 144 } | 139 } |
| 145 | 140 |
| 146 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 141 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 147 // false if Sync is disabled. | 142 // false if Sync is disabled. |
| 148 TEST_F(PermissionUmaUtilTest, | 143 TEST_F(PermissionUmaUtilTest, |
| 149 IsOptedIntoPermissionActionReportingProfileSyncServiceCheck) { | 144 IsOptedIntoPermissionActionReportingProfileSyncServiceCheck) { |
| 150 base::test::ScopedCommandLine scoped_command_line; | |
| 151 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | |
| 152 switches::kEnablePermissionActionReporting); | |
| 153 SetSafeBrowsing(true); | 145 SetSafeBrowsing(true); |
| 154 FakeSignIn(); | 146 FakeSignIn(); |
| 155 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); | 147 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); |
| 156 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 148 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 157 | 149 |
| 158 EXPECT_CALL(*mock_sync_service, CanSyncStart()) | 150 EXPECT_CALL(*mock_sync_service, CanSyncStart()) |
| 159 .WillOnce(testing::Return(false)); | 151 .WillOnce(testing::Return(false)); |
| 160 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 152 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 161 } | 153 } |
| 162 | 154 |
| 163 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 155 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 164 // false if Tab Sync and Pref Sync are not both enabled. | 156 // false if Tab Sync and Pref Sync are not both enabled. |
| 165 TEST_F(PermissionUmaUtilTest, | 157 TEST_F(PermissionUmaUtilTest, |
| 166 IsOptedIntoPermissionActionReportingSyncPreferenceCheck) { | 158 IsOptedIntoPermissionActionReportingSyncPreferenceCheck) { |
| 167 base::test::ScopedCommandLine scoped_command_line; | |
| 168 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | |
| 169 switches::kEnablePermissionActionReporting); | |
| 170 SetSafeBrowsing(true); | 159 SetSafeBrowsing(true); |
| 171 FakeSignIn(); | 160 FakeSignIn(); |
| 172 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); | 161 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); |
| 173 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 162 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 174 | 163 |
| 175 // Reset the preferred types to return an empty set. The opted-in method will | 164 // Reset the preferred types to return an empty set. The opted-in method will |
| 176 // return false because it needs both Tab and Pref Sync in the preferred types | 165 // return false because it needs both Tab and Pref Sync in the preferred types |
| 177 // in order to succeed. | 166 // in order to succeed. |
| 178 syncer::ModelTypeSet preferred_types; | 167 syncer::ModelTypeSet preferred_types; |
| 179 EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) | 168 EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 191 preferred_types.Put(syncer::PRIORITY_PREFERENCES); | 180 preferred_types.Put(syncer::PRIORITY_PREFERENCES); |
| 192 EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) | 181 EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) |
| 193 .WillOnce(testing::Return(preferred_types)); | 182 .WillOnce(testing::Return(preferred_types)); |
| 194 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 183 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 195 } | 184 } |
| 196 | 185 |
| 197 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 186 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 198 // false if Sync is not active. | 187 // false if Sync is not active. |
| 199 TEST_F(PermissionUmaUtilTest, | 188 TEST_F(PermissionUmaUtilTest, |
| 200 IsOptedIntoPermissionActionReportingProfileSyncServiceActiveCheck) { | 189 IsOptedIntoPermissionActionReportingProfileSyncServiceActiveCheck) { |
| 201 base::test::ScopedCommandLine scoped_command_line; | |
| 202 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | |
| 203 switches::kEnablePermissionActionReporting); | |
| 204 SetSafeBrowsing(true); | 190 SetSafeBrowsing(true); |
| 205 FakeSignIn(); | 191 FakeSignIn(); |
| 206 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); | 192 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); |
| 207 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 193 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 208 | 194 |
| 209 EXPECT_CALL(*mock_sync_service, IsSyncActive()) | 195 EXPECT_CALL(*mock_sync_service, IsSyncActive()) |
| 210 .WillOnce(testing::Return(false)); | 196 .WillOnce(testing::Return(false)); |
| 211 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 197 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 212 } | 198 } |
| 213 | 199 |
| 214 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns | 200 // Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| 215 // false if a custom Sync passphrase is set. | 201 // false if a custom Sync passphrase is set. |
| 216 TEST_F(PermissionUmaUtilTest, | 202 TEST_F(PermissionUmaUtilTest, |
| 217 IsOptedIntoPermissionActionReportingSyncPassphraseCheck) { | 203 IsOptedIntoPermissionActionReportingSyncPassphraseCheck) { |
| 218 base::test::ScopedCommandLine scoped_command_line; | |
| 219 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | |
| 220 switches::kEnablePermissionActionReporting); | |
| 221 SetSafeBrowsing(true); | 204 SetSafeBrowsing(true); |
| 222 FakeSignIn(); | 205 FakeSignIn(); |
| 223 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); | 206 ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); |
| 224 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); | 207 EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| 225 | 208 |
| 226 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | 209 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
| 227 .WillOnce(testing::Return(true)); | 210 .WillOnce(testing::Return(true)); |
| 228 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); | 211 EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| 229 } | 212 } |
| OLD | NEW |