"Fossies" - the Fresh Open Source Software Archive

Member "brave-core-1.30.89/chromium_src/chrome/browser/signin/account_consistency_disabled_unittest.cc" (10 Oct 2021, 4001 Bytes) of package /linux/www/brave-core-1.30.89.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "account_consistency_disabled_unittest.cc" see the Fossies "Dox" file reference documentation.

    1 // Copyright 2017 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/signin/account_consistency_mode_manager.h"
    6 
    7 #include <memory>
    8 #include <utility>
    9 
   10 #include "base/test/scoped_feature_list.h"
   11 #include "build/buildflag.h"
   12 #include "chrome/browser/prefs/browser_prefs.h"
   13 #include "chrome/browser/profiles/profile.h"
   14 #include "chrome/browser/supervised_user/supervised_user_constants.h"
   15 #include "chrome/test/base/testing_profile.h"
   16 #include "components/prefs/pref_notifier_impl.h"
   17 #include "components/prefs/testing_pref_store.h"
   18 #include "components/signin/public/base/account_consistency_method.h"
   19 #include "components/signin/public/base/signin_buildflags.h"
   20 #include "components/signin/public/base/signin_pref_names.h"
   21 #include "components/sync_preferences/testing_pref_service_syncable.h"
   22 #include "content/public/common/content_features.h"
   23 #include "content/public/test/browser_task_environment.h"
   24 #include "testing/gtest/include/gtest/gtest.h"
   25 
   26 #if BUILDFLAG(ENABLE_DICE_SUPPORT)
   27 // Checks that new profiles are migrated at creation.
   28 TEST(AccountConsistencyDisabledTest, NewProfile) {
   29   content::BrowserTaskEnvironment task_environment;
   30   // kSignInProcessIsolation used to be needed here but it has since been
   31   // turned on to 100% of the user base and is no longer needed.
   32   // See 36417aa39a5e8484b23f1ec927bfda23465f4f21
   33   TestingProfile::Builder profile_builder;
   34   profile_builder.SetIsNewProfile(true);
   35   {
   36     TestingPrefStore* user_prefs = new TestingPrefStore();
   37 
   38     // Set the read error so that Profile::IsNewProfile() returns true.
   39     user_prefs->set_read_error(PersistentPrefStore::PREF_READ_ERROR_NO_FILE);
   40 
   41     std::unique_ptr<sync_preferences::TestingPrefServiceSyncable> pref_service =
   42         std::make_unique<sync_preferences::TestingPrefServiceSyncable>(
   43             /*managed_prefs=*/new TestingPrefStore(),
   44             /*supervised_user_prefs=*/new TestingPrefStore(),
   45             /*extension_prefs=*/new TestingPrefStore(),
   46             user_prefs,
   47             /*recommended_prefs=*/new TestingPrefStore(),
   48             new user_prefs::PrefRegistrySyncable(),
   49             new PrefNotifierImpl());
   50     RegisterUserProfilePrefs(pref_service->registry());
   51     profile_builder.SetPrefService(std::move(pref_service));
   52   }
   53   std::unique_ptr<TestingProfile> profile = profile_builder.Build();
   54   ASSERT_TRUE(profile->IsNewProfile());
   55   EXPECT_TRUE(AccountConsistencyModeManager::IsDiceEnabledForProfile(
   56         profile.get()));
   57 }
   58 
   59 TEST(AccountConsistencyDisabledTest, DiceFixAuthErrorsForAllProfiles) {
   60   content::BrowserTaskEnvironment task_environment;
   61 
   62   {
   63     // Regular profile.
   64     TestingProfile profile;
   65     EXPECT_TRUE(
   66         AccountConsistencyModeManager::IsDiceEnabledForProfile(&profile));
   67     EXPECT_EQ(signin::AccountConsistencyMethod::kDice,
   68               AccountConsistencyModeManager::GetMethodForProfile(&profile));
   69 
   70     // Incognito profile.
   71     Profile* incognito_profile = profile.GetOffTheRecordProfile(
   72         Profile::OTRProfileID::PrimaryID(), /*create_if_needed=*/true);
   73     EXPECT_FALSE(AccountConsistencyModeManager::IsDiceEnabledForProfile(
   74         incognito_profile));
   75     EXPECT_FALSE(
   76         AccountConsistencyModeManager::GetForProfile(incognito_profile));
   77     EXPECT_EQ(
   78         signin::AccountConsistencyMethod::kDisabled,
   79         AccountConsistencyModeManager::GetMethodForProfile(incognito_profile));
   80   }
   81 
   82   {
   83     // Guest profile.
   84     TestingProfile::Builder profile_builder;
   85     profile_builder.SetGuestSession();
   86     std::unique_ptr<Profile> profile = profile_builder.Build();
   87     ASSERT_TRUE(profile->IsGuestSession());
   88     EXPECT_FALSE(
   89         AccountConsistencyModeManager::IsDiceEnabledForProfile(profile.get()));
   90     EXPECT_EQ(
   91         signin::AccountConsistencyMethod::kDisabled,
   92         AccountConsistencyModeManager::GetMethodForProfile(profile.get()));
   93   }
   94 }
   95 #endif  // BUILDFLAG(ENABLE_DICE_SUPPORT)