summaryrefslogtreecommitdiff
path: root/chromium/components/signin/core/browser/profile_management_switches_unittest.cc
blob: 5efa1cc3ef0e7aa9ebbdc6b16065e8e570ca4f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/signin/core/browser/profile_management_switches.h"

#include <memory>

#include "base/bind.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "build/buildflag.h"
#include "components/prefs/pref_member.h"
#include "components/signin/core/browser/scoped_account_consistency.h"
#include "components/signin/core/browser/scoped_unified_consent.h"
#include "components/signin/core/browser/signin_buildflags.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace signin {

#if BUILDFLAG(ENABLE_MIRROR)

TEST(ProfileManagementSwitchesTest, GetAccountConsistencyMethodMirror) {
  // Mirror is enabled by default on some platforms.
  EXPECT_EQ(AccountConsistencyMethod::kMirror, GetAccountConsistencyMethod());
  EXPECT_TRUE(IsAccountConsistencyMirrorEnabled());
  EXPECT_FALSE(IsDiceMigrationEnabled());
  EXPECT_FALSE(IsDiceFixAuthErrorsEnabled());
}

#else

TEST(ProfileManagementSwitchesTest, GetAccountConsistencyMethod) {
  SetGaiaOriginIsolatedCallback(base::Bind([] { return true; }));
  base::MessageLoop loop;
  sync_preferences::TestingPrefServiceSyncable pref_service;
  RegisterAccountConsistencyProfilePrefs(pref_service.registry());
  std::unique_ptr<BooleanPrefMember> dice_pref_member =
      CreateDicePrefMember(&pref_service);

// Check the default account consistency method.
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
  EXPECT_EQ(AccountConsistencyMethod::kDiceFixAuthErrors,
            GetAccountConsistencyMethod());
#else
  EXPECT_EQ(AccountConsistencyMethod::kDisabled, GetAccountConsistencyMethod());
  EXPECT_FALSE(IsAccountConsistencyMirrorEnabled());
  EXPECT_FALSE(IsDiceFixAuthErrorsEnabled());
  EXPECT_FALSE(IsDiceMigrationEnabled());
  EXPECT_FALSE(IsDicePrepareMigrationEnabled());
  EXPECT_FALSE(IsDiceEnabledForProfile(&pref_service));
  EXPECT_FALSE(IsDiceEnabled(dice_pref_member.get()));
#endif

  struct TestCase {
    AccountConsistencyMethod method;
    bool expect_mirror_enabled;
    bool expect_dice_fix_auth_errors;
    bool expect_dice_prepare_migration;
    bool expect_dice_prepare_migration_new_endpoint;
    bool expect_dice_migration;
    bool expect_dice_enabled_for_profile;
  } test_cases[] = {
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
    {AccountConsistencyMethod::kDiceFixAuthErrors, false, true, false, false,
     false, false},
    {AccountConsistencyMethod::kDicePrepareMigration, false, true, true, true,
     false, false},
    {AccountConsistencyMethod::kDiceMigration, false, true, true, true, true,
     false},
    {AccountConsistencyMethod::kDice, false, true, true, true, true, true},
#endif
    {AccountConsistencyMethod::kMirror, true, false, false, false, false, false}
  };

  for (const TestCase& test_case : test_cases) {
    ScopedAccountConsistency scoped_method(test_case.method);
    EXPECT_EQ(test_case.method, GetAccountConsistencyMethod());
    EXPECT_EQ(test_case.expect_mirror_enabled,
              IsAccountConsistencyMirrorEnabled());
    EXPECT_EQ(test_case.expect_dice_fix_auth_errors,
              IsDiceFixAuthErrorsEnabled());
    EXPECT_EQ(test_case.expect_dice_migration, IsDiceMigrationEnabled());
    EXPECT_EQ(test_case.expect_dice_prepare_migration_new_endpoint,
              IsDicePrepareMigrationEnabled());
    EXPECT_EQ(test_case.expect_dice_enabled_for_profile,
              IsDiceEnabledForProfile(&pref_service));
    EXPECT_EQ(test_case.expect_dice_enabled_for_profile,
              IsDiceEnabled(dice_pref_member.get()));
  }
}

#if BUILDFLAG(ENABLE_DICE_SUPPORT)
TEST(ProfileManagementSwitchesTest, DiceMigration) {
  base::MessageLoop loop;
  sync_preferences::TestingPrefServiceSyncable pref_service;
  RegisterAccountConsistencyProfilePrefs(pref_service.registry());
  std::unique_ptr<BooleanPrefMember> dice_pref_member =
      CreateDicePrefMember(&pref_service);

  {
    ScopedAccountConsistencyDiceMigration scoped_dice_migration;
    MigrateProfileToDice(&pref_service);
  }

  struct TestCase {
    AccountConsistencyMethod method;
    bool expect_dice_enabled_for_profile;
  } test_cases[] = {{AccountConsistencyMethod::kDiceFixAuthErrors, false},
                    {AccountConsistencyMethod::kDicePrepareMigration, false},
                    {AccountConsistencyMethod::kDiceMigration, true},
                    {AccountConsistencyMethod::kDice, true},
                    {AccountConsistencyMethod::kMirror, false}};

  for (const TestCase& test_case : test_cases) {
    ScopedAccountConsistency scoped_method(test_case.method);
    EXPECT_EQ(test_case.expect_dice_enabled_for_profile,
              IsDiceEnabledForProfile(&pref_service));
    EXPECT_EQ(test_case.expect_dice_enabled_for_profile,
              IsDiceEnabled(dice_pref_member.get()));
  }
}

// Tests that Dice is disabled when site isolation is disabled.
TEST(ProfileManagementSwitchesTest, GaiaSiteIsolation) {
  ScopedAccountConsistencyDicePrepareMigration scoped_dice;
  ASSERT_TRUE(IsDicePrepareMigrationEnabled());

  SetGaiaOriginIsolatedCallback(base::Bind([] { return false; }));
  EXPECT_FALSE(IsDicePrepareMigrationEnabled());
}
#endif  // BUILDFLAG(ENABLE_DICE_SUPPORT)

#endif  // BUILDFLAG(ENABLE_MIRROR)

TEST(ProfileManagementSwitchesTest, UnifiedConsent) {
  // Unified consent is disabled by default.
  EXPECT_EQ(UnifiedConsentFeatureState::kDisabled,
            GetUnifiedConsentFeatureState());

  for (UnifiedConsentFeatureState state :
       {UnifiedConsentFeatureState::kDisabled,
        UnifiedConsentFeatureState::kEnabledNoBump,
        UnifiedConsentFeatureState::kEnabledWithBump}) {
    ScopedUnifiedConsent scoped_state(state);
    EXPECT_EQ(state, GetUnifiedConsentFeatureState());
  }
}

}  // namespace signin