Chromium Code Reviews| Index: chrome/browser/permissions/permission_uma_util_unittest.cc |
| diff --git a/chrome/browser/permissions/permission_uma_util_unittest.cc b/chrome/browser/permissions/permission_uma_util_unittest.cc |
| index 4d0d529f29387af014fcbb8c3748726f5fa47716..cf13ccb10980d6d29914a6af574a8ca1bc464e84 100644 |
| --- a/chrome/browser/permissions/permission_uma_util_unittest.cc |
| +++ b/chrome/browser/permissions/permission_uma_util_unittest.cc |
| @@ -8,10 +8,12 @@ |
| #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| #include "chrome/browser/signin/signin_manager_factory.h" |
| #include "chrome/browser/sync/profile_sync_service_factory.h" |
| +#include "chrome/browser/sync/profile_sync_test_util.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "components/browser_sync/browser/profile_sync_service.h" |
| +#include "components/browser_sync/browser/profile_sync_service_mock.h" |
| #include "components/browser_sync/common/browser_sync_switches.h" |
| #include "components/prefs/pref_service.h" |
| #include "components/sync/base/model_type.h" |
| @@ -57,6 +59,27 @@ class PermissionUmaUtilTest : public testing::Test { |
| return ProfileSyncServiceFactory::GetForProfile(profile()); |
| } |
| + ProfileSyncServiceMock* SetMockSyncService() { |
| + ProfileSyncServiceMock* mock_sync_service = |
| + static_cast<ProfileSyncServiceMock*>( |
| + ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| + profile(), BuildMockProfileSyncService)); |
| + EXPECT_CALL(*mock_sync_service, CanSyncStart()) |
| + .WillRepeatedly(testing::Return(true)); |
| + EXPECT_CALL(*mock_sync_service, IsSyncActive()) |
| + .WillRepeatedly(testing::Return(true)); |
| + EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
| + .WillRepeatedly(testing::Return(false)); |
| + |
| + syncer::ModelTypeSet preferred_types; |
| + preferred_types.Put(syncer::PROXY_TABS); |
| + preferred_types.Put(syncer::PRIORITY_PREFERENCES); |
| + EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) |
| + .WillRepeatedly(testing::Return(preferred_types)); |
| + |
| + return mock_sync_service; |
| + } |
| + |
| Profile* profile() { return profile_.get(); } |
| private: |
| @@ -75,6 +98,9 @@ TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingSignInCheck) { |
| EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| FakeSignIn(); |
| + EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| + |
| + SetMockSyncService(); |
| EXPECT_FALSE(IsOptedIntoPermissionActionReporting( |
| profile()->GetOffTheRecordProfile())); |
| EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| @@ -85,6 +111,7 @@ TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingSignInCheck) { |
| TEST_F(PermissionUmaUtilTest, IsOptedIntoPermissionActionReportingFlagCheck) { |
| SetSafeBrowsing(true); |
| FakeSignIn(); |
| + SetMockSyncService(); |
| { |
| base::test::ScopedCommandLine scoped_command_line; |
| scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| @@ -108,6 +135,7 @@ TEST_F(PermissionUmaUtilTest, |
| scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| switches::kEnablePermissionActionReporting); |
| FakeSignIn(); |
| + SetMockSyncService(); |
| SetSafeBrowsing(true); |
| EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| @@ -124,10 +152,11 @@ TEST_F(PermissionUmaUtilTest, |
| switches::kEnablePermissionActionReporting); |
| SetSafeBrowsing(true); |
| FakeSignIn(); |
| + ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); |
| EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| - scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| - switches::kDisableSync); |
| + EXPECT_CALL(*mock_sync_service, CanSyncStart()) |
| + .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.
|
| EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| } |
| @@ -140,23 +169,61 @@ TEST_F(PermissionUmaUtilTest, |
| switches::kEnablePermissionActionReporting); |
| SetSafeBrowsing(true); |
| FakeSignIn(); |
| + ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); |
| EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| - sync_driver::SyncPrefs sync_prefs(profile()->GetPrefs()); |
| - const syncer::ModelTypeSet registered_types = |
| - GetProfileSyncService()->GetRegisteredDataTypes(); |
| - sync_prefs.SetKeepEverythingSynced(false); |
| + // Reset the preferred types to return an empty set. The opted-in method will |
| + // return false because it needs both Tab and Pref Sync in the preferred types |
| + // in order to succeed. |
| + syncer::ModelTypeSet preferred_types; |
| + EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) |
| + .WillOnce(testing::Return(preferred_types)); |
| + EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| + |
| + // The opted-in method will be false with only Tab Sync on. |
| + preferred_types.Put(syncer::PROXY_TABS); |
| + EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) |
| + .WillOnce(testing::Return(preferred_types)); |
| + EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| - sync_prefs.SetPreferredDataTypes( |
| - registered_types, syncer::ModelTypeSet(syncer::PROXY_TABS)); |
| + // The opted-in method will be false with only Pref Sync on. |
| + preferred_types.Remove(syncer::PROXY_TABS); |
| + preferred_types.Put(syncer::PRIORITY_PREFERENCES); |
| + EXPECT_CALL(*mock_sync_service, GetPreferredDataTypes()) |
| + .WillOnce(testing::Return(preferred_types)); |
| EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| +} |
| + |
| +// Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| +// false if Sync is not active. |
| +TEST_F(PermissionUmaUtilTest, |
| + IsOptedIntoPermissionActionReportingProfileSyncServiceActiveCheck) { |
| + base::test::ScopedCommandLine scoped_command_line; |
| + scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| + switches::kEnablePermissionActionReporting); |
| + SetSafeBrowsing(true); |
| + FakeSignIn(); |
| + ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); |
| + EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| - sync_prefs.SetPreferredDataTypes( |
| - registered_types, syncer::ModelTypeSet(syncer::PRIORITY_PREFERENCES)); |
| + EXPECT_CALL(*mock_sync_service, IsSyncActive()) |
| + .WillOnce(testing::Return(false)); |
| EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| +} |
| - sync_prefs.SetPreferredDataTypes( |
| - registered_types, |
| - syncer::ModelTypeSet(syncer::PROXY_TABS, syncer::PRIORITY_PREFERENCES)); |
| +// Test that PermissionUmaUtil::IsOptedIntoPermissionActionReporting returns |
| +// false if a custom Sync passphrase is set. |
| +TEST_F(PermissionUmaUtilTest, |
| + IsOptedIntoPermissionActionReportingSyncPassphraseCheck) { |
| + base::test::ScopedCommandLine scoped_command_line; |
| + scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| + switches::kEnablePermissionActionReporting); |
| + SetSafeBrowsing(true); |
| + FakeSignIn(); |
| + ProfileSyncServiceMock* mock_sync_service = SetMockSyncService(); |
| EXPECT_TRUE(IsOptedIntoPermissionActionReporting(profile())); |
| + |
| + EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
| + .WillOnce(testing::Return(true)); |
| + EXPECT_FALSE(IsOptedIntoPermissionActionReporting(profile())); |
| } |