#include "chrome/browser/ui/views/profiles/profile_picker_view.h"
#include <optional>
#include <set>
#include "base/barrier_closure.h"
#include "base/cfi_buildflags.h"
#include "base/files/file_path.h"
#include "base/json/values_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/chrome_browser_main_extra_parts.h"
#include "chrome/browser/enterprise/util/managed_browser_utils.h"
#include "chrome/browser/feature_engagement/tracker_factory.h"
#include "chrome/browser/interstitials/chrome_settings_page_helper.h"
#include "chrome/browser/lifetime/browser_shutdown.h"
#include "chrome/browser/metrics/first_web_contents_profiler_base.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service_test_util.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_builder.h"
#include "chrome/browser/profiles/keep_alive/profile_keep_alive_types.h"
#include "chrome/browser/profiles/nuke_profile_directory_utils.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_test_util.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/chrome_signin_client_test_util.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/sync/sync_startup_tracker.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/trusted_vault/trusted_vault_encryption_keys_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/profiles/profile_customization_util.h"
#include "chrome/browser/ui/profiles/profile_ui_test_utils.h"
#include "chrome/browser/ui/startup/first_run_service.h"
#include "chrome/browser/ui/tab_dialogs.h"
#include "chrome/browser/ui/views/profiles/avatar_toolbar_button.h"
#include "chrome/browser/ui/views/profiles/profile_picker_dice_reauth_provider.h"
#include "chrome/browser/ui/views/profiles/profile_picker_test_base.h"
#include "chrome/browser/ui/views/user_education/browser_feature_promo_controller.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/browser/ui/webui/signin/managed_user_profile_notice_handler.h"
#include "chrome/browser/ui/webui/signin/managed_user_profile_notice_ui.h"
#include "chrome/browser/ui/webui/signin/profile_customization_handler.h"
#include "chrome/browser/ui/webui/signin/profile_customization_ui.h"
#include "chrome/browser/ui/webui/signin/profile_picker_handler.h"
#include "chrome/browser/ui/webui/signin/profile_picker_ui.h"
#include "chrome/browser/ui/webui/signin/signin_url_utils.h"
#include "chrome/browser/ui/webui/signin/signin_utils.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/profile_deletion_observer.h"
#include "chrome/test/base/profile_destruction_waiter.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/user_education/interactive_feature_promo_test.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/tracker.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/base/signin_buildflags.h"
#include "components/signin/public/base/signin_metrics.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/signin/public/identity_manager/primary_account_mutator.h"
#include "components/sync/base/pref_names.h"
#include "components/sync/service/sync_service.h"
#include "components/sync/service/sync_user_settings.h"
#include "components/sync/test/test_sync_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/test_navigation_observer.h"
#include "extensions/common/extension_id.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "services/network/test/test_url_loader_factory.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event_constants.h"
#include "ui/views/widget/widget_delegate.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
#include "components/policy/core/common/management/management_service.h"
#include "components/policy/core/common/management/scoped_management_service_override_for_testing.h"
#elif BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/browser/lacros/account_manager/fake_account_manager_ui_dialog_waiter.h"
#include "components/account_manager_core/chromeos/account_manager.h"
#include "components/account_manager_core/chromeos/account_manager_facade_factory.h"
#include "components/account_manager_core/chromeos/account_manager_mojo_service.h"
#endif
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
#include "chrome/browser/signin/dice_tab_helper.h"
#include "chrome/browser/signin/process_dice_header_delegate_impl.h"
#endif
namespace {
const SkColor kProfileColor = …;
enum class ForceEphemeralProfilesPolicy { … };
const char16_t kOriginalProfileName[] = …;
const char kGaiaId[] = …;
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
const char16_t kWork[] = …;
#endif
#if !BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS)
const char kReauthResultHistogramName[] = "ProfilePicker.ReauthResult";
#endif
AccountInfo FillAccountInfo(
const CoreAccountInfo& core_info,
const std::string& given_name,
const std::string& hosted_domain = kNoHostedDomainFound) { … }
GURL GetSyncConfirmationURL() { … }
class BrowserAddedWaiter : public BrowserListObserver { … };
class TestTabDialogs : public TabDialogs { … };
class PageNonEmptyPaintObserver : public content::WebContentsObserver { … };
void WaitForFirstNonEmptyPaint(const GURL& url, content::WebContents* target) { … }
}
class ProfilePickerViewBrowserTest : public ProfilePickerTestBase { … };
IN_PROC_BROWSER_TEST_F(ProfilePickerViewBrowserTest,
ShowScreen_DoesNotFinishForErrorOnInternalNavigation) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerViewBrowserTest,
ShowScreen_FinishesForErrorOnStandardNavigation) { … }
class ProfilePickerCreationFlowBrowserTest
: public InteractiveFeaturePromoTestT<ProfilePickerTestBase> { … };
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest, ShowPicker) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest, ShowChoice) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfile) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfileClosePicker) { … }
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_CreateForceSignedInProfile …
#else
#define MAYBE_CreateForceSignedInProfile …
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
MAYBE_CreateForceSignedInProfile) { … }
#if !BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS)
class ForceSigninProfilePickerCreationFlowBrowserTest
: public ProfilePickerCreationFlowBrowserTest {
public:
explicit ForceSigninProfilePickerCreationFlowBrowserTest(
bool force_signin_enabled = true)
: force_signin_setter_(force_signin_enabled) {}
void SimulateSuccesfulSignin(signin::IdentityManager* identity_manager,
const std::string& email) {
signin::MakeAccountAvailable(identity_manager, email);
}
bool IsForceSigninErrorDialogShown() {
EXPECT_TRUE(ProfilePicker::IsOpen());
const GURL main_profile_picker_url("chrome://profile-picker");
EXPECT_EQ(web_contents()->GetURL().GetWithEmptyPath(),
main_profile_picker_url);
WaitForLoadStop(main_profile_picker_url);
return content::EvalJs(
web_contents(),
"document.body.getElementsByTagName('profile-picker-app')[0]."
"shadowRoot.getElementById('mainView').shadowRoot."
"getElementById(\""
"forceSigninErrorDialog\").open")
.ExtractBool();
}
base::HistogramTester* histogram_tester() { return &histogram_tester_; }
private:
signin_util::ScopedForceSigninSetterForTesting force_signin_setter_;
base::HistogramTester histogram_tester_;
};
IN_PROC_BROWSER_TEST_F(ForceSigninProfilePickerCreationFlowBrowserTest,
ForceSigninSuccessful) {
size_t initial_browser_count = BrowserList::GetInstance()->size();
Profile* force_sign_in_profile =
SignInForNewProfile(GetSyncConfirmationURL(), "[email protected]",
"Joe", kNoHostedDomainFound, true);
ASSERT_EQ(chrome::GetBrowserCount(force_sign_in_profile), 0u);
ASSERT_TRUE(ProfilePicker::IsOpen());
ProfileAttributesEntry* entry =
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(force_sign_in_profile->GetPath());
EXPECT_EQ(entry->IsSigninRequired(), true);
EXPECT_EQ(entry->IsEphemeral(), true);
LoginUIServiceFactory::GetForProfile(force_sign_in_profile)
->SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS);
Browser* new_browser = BrowserAddedWaiter(initial_browser_count + 1u).Wait();
WaitForPickerClosed();
EXPECT_EQ(new_browser->profile(), force_sign_in_profile);
EXPECT_EQ(entry->IsSigninRequired(), false);
EXPECT_EQ(entry->IsEphemeral(), false);
}
IN_PROC_BROWSER_TEST_F(ForceSigninProfilePickerCreationFlowBrowserTest,
ForceSigninAbortedBySyncDeclined_ThenSigninAgain) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
size_t initial_profile_count = 1u;
ASSERT_EQ(profile_manager->GetNumberOfProfiles(), initial_profile_count);
Profile* force_sign_in_profile =
SignInForNewProfile(GetSyncConfirmationURL(), "[email protected]",
"Joe", kNoHostedDomainFound, true);
base::FilePath force_sign_in_profile_path = force_sign_in_profile->GetPath();
ASSERT_EQ(chrome::GetBrowserCount(force_sign_in_profile), 0u);
ASSERT_TRUE(ProfilePicker::IsOpen());
ProfileAttributesStorage& storage =
profile_manager->GetProfileAttributesStorage();
ProfileAttributesEntry* entry =
storage.GetProfileAttributesWithPath(force_sign_in_profile_path);
ASSERT_NE(entry, nullptr);
EXPECT_EQ(profile_manager->GetNumberOfProfiles(), initial_profile_count + 1);
EXPECT_EQ(entry->IsSigninRequired(), true);
EXPECT_EQ(entry->IsEphemeral(), true);
ProfileDeletionObserver deletion_observer;
LoginUIServiceFactory::GetForProfile(force_sign_in_profile)
->SyncConfirmationUIClosed(LoginUIService::ABORT_SYNC);
deletion_observer.Wait();
WaitForLoadStop(GURL("chrome://profile-picker"));
EXPECT_TRUE(ProfilePicker::IsOpen());
EXPECT_EQ(storage.GetProfileAttributesWithPath(force_sign_in_profile_path),
nullptr);
EXPECT_EQ(profile_manager->GetNumberOfProfiles(), initial_profile_count);
size_t initial_browser_count = BrowserList::GetInstance()->size();
Profile* force_sign_in_profile_2 =
SignInForNewProfile(GetSyncConfirmationURL(), "[email protected]",
"Joe", kNoHostedDomainFound, true);
LoginUIServiceFactory::GetForProfile(force_sign_in_profile_2)
->SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS);
Browser* new_browser = BrowserAddedWaiter(initial_browser_count + 1u).Wait();
WaitForPickerClosed();
EXPECT_EQ(new_browser->profile(), force_sign_in_profile_2);
}
IN_PROC_BROWSER_TEST_F(ForceSigninProfilePickerCreationFlowBrowserTest,
ForceSigninReauthSuccessful) {
size_t initial_browser_count = BrowserList::GetInstance()->size();
ASSERT_EQ(initial_browser_count, 0u);
const std::vector<Profile*> profiles =
g_browser_process->profile_manager()->GetLoadedProfiles();
ASSERT_GE(profiles.size(), 1u);
Profile* profile = profiles[0];
ProfileAttributesEntry* entry =
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile->GetPath());
ASSERT_TRUE(entry->IsSigninRequired());
ASSERT_TRUE(ProfilePicker::IsOpen());
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
const std::string email("[email protected]");
signin::MakePrimaryAccountAvailable(identity_manager, email,
signin::ConsentLevel::kSignin);
entry->SetUserAcceptedAccountManagement(true);
CoreAccountId primary_account =
identity_manager->GetPrimaryAccountId(signin::ConsentLevel::kSignin);
ASSERT_FALSE(primary_account.empty());
signin::SetInvalidRefreshTokenForPrimaryAccount(identity_manager);
OpenProfileFromPicker(entry->GetPath(), false);
WaitForLoadStop(GetChromeReauthURL(email));
SimulateSuccesfulSignin(identity_manager, email);
Browser* new_browser = BrowserAddedWaiter(initial_browser_count + 1u).Wait();
EXPECT_TRUE(new_browser);
EXPECT_EQ(new_browser->profile(), profile);
EXPECT_FALSE(entry->IsSigninRequired());
histogram_tester()->ExpectUniqueSample(
kReauthResultHistogramName, ProfilePickerReauthResult::kSuccess, 1);
}
IN_PROC_BROWSER_TEST_F(ForceSigninProfilePickerCreationFlowBrowserTest,
ForceSigninReauthWithAnotherAccount) {
size_t initial_browser_count = BrowserList::GetInstance()->size();
ASSERT_EQ(initial_browser_count, 0u);
const std::vector<Profile*> profiles =
g_browser_process->profile_manager()->GetLoadedProfiles();
ASSERT_GE(profiles.size(), 1u);
Profile* profile = profiles[0];
ProfileAttributesEntry* entry =
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile->GetPath());
ASSERT_TRUE(entry->IsSigninRequired());
ASSERT_TRUE(ProfilePicker::IsOpen());
ASSERT_FALSE(IsForceSigninErrorDialogShown());
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
const std::string email("[email protected]");
signin::MakePrimaryAccountAvailable(identity_manager, email,
signin::ConsentLevel::kSignin);
entry->SetUserAcceptedAccountManagement(true);
CoreAccountId primary_account =
identity_manager->GetPrimaryAccountId(signin::ConsentLevel::kSignin);
ASSERT_FALSE(primary_account.empty());
signin::SetInvalidRefreshTokenForPrimaryAccount(identity_manager);
OpenProfileFromPicker(entry->GetPath(), false);
WaitForLoadStop(GetChromeReauthURL(email));
const std::string different_email("[email protected]");
ASSERT_NE(email, different_email);
SimulateSuccesfulSignin(identity_manager, different_email);
WaitForLoadStop(GURL("chrome://profile-picker"));
EXPECT_TRUE(ProfilePicker::IsOpen());
EXPECT_TRUE(IsForceSigninErrorDialogShown());
EXPECT_EQ(BrowserList::GetInstance()->size(), initial_browser_count);
EXPECT_TRUE(entry->IsSigninRequired());
histogram_tester()->ExpectUniqueSample(
kReauthResultHistogramName, ProfilePickerReauthResult::kErrorUsedNewEmail,
1);
}
IN_PROC_BROWSER_TEST_F(ForceSigninProfilePickerCreationFlowBrowserTest,
ForceSigninReauthNavigateBackShouldAbort) {
size_t initial_browser_count = BrowserList::GetInstance()->size();
ASSERT_EQ(initial_browser_count, 0u);
const std::vector<Profile*> profiles =
g_browser_process->profile_manager()->GetLoadedProfiles();
ASSERT_GE(profiles.size(), 1u);
Profile* profile = profiles[0];
ProfileAttributesEntry* entry =
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile->GetPath());
ASSERT_TRUE(entry->IsSigninRequired());
ASSERT_TRUE(ProfilePicker::IsOpen());
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
const std::string email("[email protected]");
signin::MakePrimaryAccountAvailable(identity_manager, email,
signin::ConsentLevel::kSignin);
entry->SetUserAcceptedAccountManagement(true);
CoreAccountId primary_account =
identity_manager->GetPrimaryAccountId(signin::ConsentLevel::kSignin);
ASSERT_FALSE(primary_account.empty());
signin::SetInvalidRefreshTokenForPrimaryAccount(identity_manager);
OpenProfileFromPicker(entry->GetPath(), false);
WaitForLoadStop(GetChromeReauthURL(email));
EXPECT_TRUE(IsNativeToolbarVisible());
GURL redirect_url("https://www.google.com/");
web_contents()->GetController().LoadURL(redirect_url, content::Referrer(),
ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
WaitForLoadStop(redirect_url);
SimulateNavigateBack();
WaitForLoadStop(GetChromeReauthURL(email));
SimulateNavigateBack();
WaitForLoadStop(GURL("chrome://profile-picker"));
EXPECT_TRUE(ProfilePicker::IsOpen());
EXPECT_FALSE(IsNativeToolbarVisible());
EXPECT_EQ(BrowserList::GetInstance()->size(), initial_browser_count);
EXPECT_TRUE(entry->IsSigninRequired());
}
IN_PROC_BROWSER_TEST_F(ForceSigninProfilePickerCreationFlowBrowserTest,
ForceSigninLaunchInactiveDefaultProfile) {
size_t initial_browser_count = BrowserList::GetInstance()->size();
ASSERT_EQ(initial_browser_count, 0u);
ProfileManager* profile_manager = g_browser_process->profile_manager();
const std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
ASSERT_GE(profiles.size(), 1u);
Profile* default_profile = profiles[0];
ProfileAttributesEntry* default_profile_entry =
profile_manager->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(default_profile->GetPath());
ASSERT_TRUE(ProfilePicker::IsOpen());
ASSERT_EQ(default_profile_entry->GetPath(),
profiles::GetDefaultProfileDir(profile_manager->user_data_dir()));
ASSERT_EQ(default_profile_entry->GetActiveTime(), base::Time());
ASSERT_TRUE(default_profile_entry->IsSigninRequired());
OpenProfileFromPicker(default_profile_entry->GetPath(), false);
WaitForLoadStop(GetSigninChromeSyncDiceUrl());
FinishDiceSignIn(default_profile, "[email protected]", "Joe");
WaitForLoadStop(GetSyncConfirmationURL());
LoginUIServiceFactory::GetForProfile(default_profile)
->SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS);
Browser* new_browser = BrowserAddedWaiter(initial_browser_count + 1u).Wait();
EXPECT_TRUE(new_browser);
EXPECT_EQ(new_browser->profile(), default_profile);
EXPECT_FALSE(default_profile_entry->IsSigninRequired());
EXPECT_NE(default_profile_entry->GetActiveTime(), base::Time());
}
class ForceSigninProfilePickerCreationFlowBrowserTestWithPRE
: public ForceSigninProfilePickerCreationFlowBrowserTest {
public:
ForceSigninProfilePickerCreationFlowBrowserTestWithPRE()
: ForceSigninProfilePickerCreationFlowBrowserTest(
!content::IsPreTest()) {}
};
IN_PROC_BROWSER_TEST_F(ForceSigninProfilePickerCreationFlowBrowserTestWithPRE,
PRE_ProfileThatCannotBeManagedCannotBeOpened) {
ASSERT_FALSE(signin_util::IsForceSigninEnabled());
ProfileManager* profile_manager = g_browser_process->profile_manager();
ASSERT_EQ(1u, profile_manager->GetNumberOfProfiles());
CreateBrowser(profile_manager->GetLoadedProfiles()[0]);
}
IN_PROC_BROWSER_TEST_F(ForceSigninProfilePickerCreationFlowBrowserTestWithPRE,
ProfileThatCannotBeManagedCannotBeOpened) {
ASSERT_TRUE(signin_util::IsForceSigninEnabled());
size_t initial_browser_count = BrowserList::GetInstance()->size();
ASSERT_EQ(0u, initial_browser_count);
ProfileManager* profile_manager = g_browser_process->profile_manager();
std::vector<ProfileAttributesEntry*> entries =
profile_manager->GetProfileAttributesStorage().GetAllProfilesAttributes();
ASSERT_EQ(1u, entries.size());
ProfileAttributesEntry* existing_entry = entries[0];
ASSERT_NE(existing_entry->GetActiveTime(), base::Time());
ASSERT_TRUE(existing_entry->IsSigninRequired());
ASSERT_FALSE(existing_entry->CanBeManaged());
ASSERT_TRUE(ProfilePicker::IsOpen());
ASSERT_FALSE(IsForceSigninErrorDialogShown());
OpenProfileFromPicker(existing_entry->GetPath(), false);
EXPECT_EQ(initial_browser_count, BrowserList::GetInstance()->size());
EXPECT_TRUE(IsForceSigninErrorDialogShown());
EXPECT_TRUE(existing_entry->IsSigninRequired());
}
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfileWithSyncEncryptionKeys) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfileAfterCancellingFirstAttempt) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CancelWhileSigningIn) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CancelWhileSigningInBeforeProfileCreated) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
PRE_CancelWhileSigningInWithNoOtherWindow) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CancelWhileSigningInWithNoOtherWindow) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfileDiceReenter) { … }
#endif
#if ((BUILDFLAG(CFI_ICALL_CHECK) || !defined(NDEBUG)) && \
BUILDFLAG(IS_LINUX)) || \
(BUILDFLAG(IS_MAC) && defined(ADDRESS_SANITIZER))
#define MAYBE_CreateSignedInProfileSettings …
#else
#define MAYBE_CreateSignedInProfileSettings …
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
MAYBE_CreateSignedInProfileSettings) { … }
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfileOpenLink) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfileSecurityInterstitials) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfileExtendedInfoTimeout) { … }
#if BUILDFLAG(IS_LINUX) && defined(MEMORY_SANITIZER)
#define MAYBE_CreateSignedInProfileExtendedInfoDelayed …
#else
#define MAYBE_CreateSignedInProfileExtendedInfoDelayed …
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
MAYBE_CreateSignedInProfileExtendedInfoDelayed) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfileWithSAML) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
PRE_ProfileNameChangesOnProfileAdded) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
ProfileNameChangesOnProfileAdded) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
DiceSigninFailure) { … }
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
OpenPickerAndClose) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
OpenPickerWhileClosing) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest, ReShow) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_OpenProfile …
#else
#define MAYBE_OpenProfile …
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
MAYBE_OpenProfile) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
OpenProfileFromStartup) { … }
#if ((BUILDFLAG(CFI_ICALL_CHECK) || !defined(NDEBUG)) && \
BUILDFLAG(IS_LINUX)) || \
(BUILDFLAG(IS_MAC) && defined(ADDRESS_SANITIZER))
#define MAYBE_OpenProfile_Settings …
#else
#define MAYBE_OpenProfile_Settings …
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
MAYBE_OpenProfile_Settings) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
OpenURL_PickerClosed) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
OpenProfile_Guest) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CloseBrowserBeforeCreatingNewProfile) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateLocalProfile) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_CancelLocalProfileCreation …
#else
#define MAYBE_CancelLocalProfileCreation …
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
MAYBE_CancelLocalProfileCreation) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest, DeleteProfile) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
DeleteProfileFromOwnTab) { … }
class ProfilePickerEnterpriseCreationFlowBrowserTest
: public ProfilePickerCreationFlowBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ProfilePickerEnterpriseCreationFlowBrowserTest,
CreateSignedInProfile) { … }
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
IN_PROC_BROWSER_TEST_F(ProfilePickerEnterpriseCreationFlowBrowserTest,
CreateSignedInProfileWithSuggestedTwoFactorAuthSetup) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerEnterpriseCreationFlowBrowserTest,
CreateSignedInProfileWithSyncDisabled) { … }
#endif
#if BUILDFLAG(IS_LINUX)
#define MAYBE_CreateSignedInEnterpriseProfileSettings …
#else
#define MAYBE_CreateSignedInEnterpriseProfileSettings …
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerEnterpriseCreationFlowBrowserTest,
MAYBE_CreateSignedInEnterpriseProfileSettings) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerEnterpriseCreationFlowBrowserTest, Cancel) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerEnterpriseCreationFlowBrowserTest,
CancelFromPicker) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerEnterpriseCreationFlowBrowserTest,
CreateSignedInProfileSigninAlreadyExists_ConfirmSwitch) { … }
IN_PROC_BROWSER_TEST_F(ProfilePickerEnterpriseCreationFlowBrowserTest,
CreateSignedInProfileSigninAlreadyExists_CancelSwitch) { … }
class ProfilePickerCreationFlowEphemeralProfileBrowserTest
: public ProfilePickerCreationFlowBrowserTest,
public testing::WithParamInterface<ForceEphemeralProfilesPolicy> { … };
#if BUILDFLAG(IS_WIN)
#define MAYBE_PRE_Signin …
#define MAYBE_Signin …
#else
#define MAYBE_PRE_Signin …
#define MAYBE_Signin …
#endif
IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest,
MAYBE_PRE_Signin) { … }
IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest,
MAYBE_Signin) { … }
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
#if BUILDFLAG(IS_WIN)
#define MAYBE_PRE_ExitDuringSignin …
#define MAYBE_ExitDuringSignin …
#else
#define MAYBE_PRE_ExitDuringSignin …
#define MAYBE_ExitDuringSignin …
#endif
IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest,
MAYBE_PRE_ExitDuringSignin) { … }
IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest,
MAYBE_ExitDuringSignin) { … }
#endif
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
SyncConfirmationExitChromeTest) {
SignInForNewProfile(GetSyncConfirmationURL(), "[email protected]",
"Joe");
EXPECT_TRUE(ProfilePicker::IsOpen());
view()->AcceleratorPressed(ui::Accelerator(ui::VKEY_Q, ui::EF_COMMAND_DOWN));
WaitForPickerClosed();
EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
}
#endif
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
SyncConfirmationNavigateBackTest) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
class ProfilePickerLacrosFirstRunBrowserTestBase
: public ProfilePickerTestBase {
public:
void SetUpInProcessBrowserTestFixture() override {
ProfilePickerTestBase::SetUpInProcessBrowserTestFixture();
create_services_subscription_ =
BrowserContextDependencyManager::GetInstance()
->RegisterCreateServicesCallbackForTesting(base::BindRepeating(
&ProfilePickerLacrosFirstRunBrowserTestBase::
OnWillCreateBrowserContextServices,
base::Unretained(this)));
}
virtual void OnWillCreateBrowserContextServices(
content::BrowserContext* context) {
SyncServiceFactory::GetInstance()->SetTestingFactory(
context, base::BindRepeating([](content::BrowserContext* context)
-> std::unique_ptr<KeyedService> {
auto sync_service = std::make_unique<syncer::TestSyncService>();
sync_service->SetMaxTransportState(
syncer::SyncService::TransportState::INITIALIZING);
return sync_service;
}));
}
void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
ProfilePickerTestBase::SetUpDefaultCommandLine(command_line);
if (GetTestPreCount() <= 1) {
command_line->RemoveSwitch(switches::kNoFirstRun);
}
}
Profile* GetPrimaryProfile() {
ProfileManager* profile_manager = g_browser_process->profile_manager();
return profile_manager->GetProfile(
profile_manager->GetPrimaryUserProfilePath());
}
void GoThroughFirstRunFlow(bool quit_on_welcome,
std::optional<bool> quit_on_sync) {
Profile* profile = GetPrimaryProfile();
EXPECT_TRUE(ShouldOpenFirstRun(profile));
EXPECT_EQ(0u, BrowserList::GetInstance()->size());
EXPECT_TRUE(ProfilePicker::IsOpen());
sync_service()->SetMaxTransportState(
syncer::SyncService::TransportState::ACTIVE);
sync_service()->FireStateChanged();
WaitForPickerWidgetCreated();
WaitForLoadStop(GURL(chrome::kChromeUIIntroURL));
content::WebContents* contents = web_contents();
EXPECT_TRUE(contents);
base::OnceClosure complete_welcome =
base::BindLambdaForTesting([contents]() {
contents->GetWebUI()->ProcessWebUIMessage(
contents->GetURL(), "continueWithAccount", base::Value::List());
});
if (quit_on_welcome) {
ASSERT_FALSE(quit_on_sync.has_value());
} else {
std::move(complete_welcome).Run();
WaitForLoadStop(GetSyncConfirmationURL());
}
if (quit_on_welcome || quit_on_sync.value()) {
ProfilePicker::Hide();
} else {
LoginUIServiceFactory::GetForProfile(profile)->SyncConfirmationUIClosed(
LoginUIService::SYNC_WITH_DEFAULT_SETTINGS);
}
WaitForPickerClosed();
}
const base::HistogramTester& histogram_tester() { return histogram_tester_; }
syncer::TestSyncService* sync_service() {
return static_cast<syncer::TestSyncService*>(
SyncServiceFactory::GetForProfile(GetPrimaryProfile()));
}
private:
base::HistogramTester histogram_tester_;
base::CallbackListSubscription create_services_subscription_;
testing::ScopedSyncStartupTimeoutOverride sync_startup_timeout_{
std::optional<base::TimeDelta>()};
};
class ProfilePickerLacrosFirstRunBrowserTest
: public ProfilePickerLacrosFirstRunBrowserTestBase {
private:
profiles::testing::ScopedNonEnterpriseDomainSetterForTesting
non_enterprise_domain_setter_;
};
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest,
PRE_PRE_QuitEarly) {}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest, PRE_QuitEarly) {
GoThroughFirstRunFlow(
true,
std::nullopt);
EXPECT_EQ(0u, BrowserList::GetInstance()->size());
EXPECT_TRUE(ShouldOpenFirstRun(GetPrimaryProfile()));
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest, QuitEarly) {
EXPECT_TRUE(ShouldOpenFirstRun(GetPrimaryProfile()));
EXPECT_TRUE(ProfilePicker::IsOpen());
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest,
PRE_PRE_QuitAtEnd) {
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest, PRE_QuitAtEnd) {
Profile* profile = GetPrimaryProfile();
GoThroughFirstRunFlow(
false,
true);
EXPECT_FALSE(ShouldOpenFirstRun(profile));
EXPECT_EQ(0u, BrowserList::GetInstance()->size());
EXPECT_FALSE(enterprise_util::UserAcceptedAccountManagement(profile));
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest, QuitAtEnd) {
Profile* profile = GetPrimaryProfile();
EXPECT_FALSE(ShouldOpenFirstRun(profile));
EXPECT_FALSE(enterprise_util::UserAcceptedAccountManagement(profile));
EXPECT_FALSE(ProfilePicker::IsOpen());
EXPECT_EQ(1u, BrowserList::GetInstance()->size());
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest, PRE_PRE_OptIn) {}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest, PRE_OptIn) {
GoThroughFirstRunFlow(
false,
false);
EXPECT_FALSE(ShouldOpenFirstRun(GetPrimaryProfile()));
EXPECT_EQ(1u, BrowserList::GetInstance()->size());
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosFirstRunBrowserTest, OptIn) {
EXPECT_FALSE(ShouldOpenFirstRun(GetPrimaryProfile()));
EXPECT_FALSE(ProfilePicker::IsOpen());
EXPECT_EQ(1u, BrowserList::GetInstance()->size());
}
class ManagedProfileSetUpHelper : public ChromeBrowserMainExtraParts {
public:
void PostProfileInit(Profile* profile, bool is_initial_profile) override {
EXPECT_EQ(
profile->GetPath(),
g_browser_process->profile_manager()->GetPrimaryUserProfilePath());
profile->GetProfilePolicyConnector()->OverrideIsManagedForTesting(true);
}
};
class ProfilePickerLacrosManagedFirstRunBrowserTest
: public ProfilePickerLacrosFirstRunBrowserTestBase {
public:
void CreatedBrowserMainParts(content::BrowserMainParts* parts) override {
ProfilePickerLacrosFirstRunBrowserTestBase::CreatedBrowserMainParts(parts);
static_cast<ChromeBrowserMainParts*>(parts)->AddParts(
std::make_unique<ManagedProfileSetUpHelper>());
}
const base::UserActionTester& user_action_tester() {
return user_action_tester_;
}
private:
base::UserActionTester user_action_tester_;
};
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
PRE_PRE_QuitEarly) {}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
PRE_QuitEarly) {
Profile* profile = GetPrimaryProfile();
EXPECT_TRUE(enterprise_util::UserAcceptedAccountManagement(profile));
EXPECT_EQ(1, user_action_tester().GetActionCount(
"Signin_EnterpriseAccountPrompt_ImportData"));
GoThroughFirstRunFlow(
true,
std::nullopt);
EXPECT_EQ(0u, BrowserList::GetInstance()->size());
EXPECT_TRUE(ShouldOpenFirstRun(profile));
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
QuitEarly) {
Profile* profile = GetPrimaryProfile();
EXPECT_TRUE(enterprise_util::UserAcceptedAccountManagement(profile));
EXPECT_EQ(0, user_action_tester().GetActionCount(
"Signin_EnterpriseAccountPrompt_ImportData"));
GoThroughFirstRunFlow(
true,
std::nullopt);
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
PRE_PRE_QuitAtEnd) {}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
PRE_QuitAtEnd) {
Profile* profile = GetPrimaryProfile();
EXPECT_TRUE(enterprise_util::UserAcceptedAccountManagement(profile));
EXPECT_EQ(1, user_action_tester().GetActionCount(
"Signin_EnterpriseAccountPrompt_ImportData"));
GoThroughFirstRunFlow(
false,
true);
EXPECT_TRUE(enterprise_util::UserAcceptedAccountManagement(profile));
EXPECT_EQ(1, user_action_tester().GetActionCount(
"Signin_EnterpriseAccountPrompt_ImportData"));
EXPECT_EQ(0u, BrowserList::GetInstance()->size());
EXPECT_FALSE(ShouldOpenFirstRun(profile));
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
QuitAtEnd) {
Profile* profile = GetPrimaryProfile();
EXPECT_FALSE(ShouldOpenFirstRun(profile));
EXPECT_TRUE(enterprise_util::UserAcceptedAccountManagement(profile));
EXPECT_FALSE(ProfilePicker::IsOpen());
EXPECT_EQ(1u, BrowserList::GetInstance()->size());
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
PRE_PRE_SyncDisabled) {}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
PRE_SyncDisabled) {
Profile* profile = GetPrimaryProfile();
EXPECT_TRUE(enterprise_util::UserAcceptedAccountManagement(profile));
EXPECT_EQ(1, user_action_tester().GetActionCount(
"Signin_EnterpriseAccountPrompt_ImportData"));
EXPECT_TRUE(ProfilePicker::IsOpen());
EXPECT_EQ(0u, BrowserList::GetInstance()->size());
EXPECT_EQ(ProfilePickerView::State::kInitializing,
view()->state_for_testing());
sync_service()->SetAllowedByEnterprisePolicy(false);
sync_service()->FireStateChanged();
EXPECT_FALSE(ShouldOpenFirstRun(profile));
WaitForPickerClosed();
EXPECT_FALSE(ProfilePicker::IsOpen());
EXPECT_EQ(1u, BrowserList::GetInstance()->size());
}
IN_PROC_BROWSER_TEST_F(ProfilePickerLacrosManagedFirstRunBrowserTest,
SyncDisabled) {
Profile* profile = GetPrimaryProfile();
EXPECT_FALSE(ShouldOpenFirstRun(profile));
EXPECT_TRUE(enterprise_util::UserAcceptedAccountManagement(profile));
EXPECT_FALSE(ProfilePicker::IsOpen());
EXPECT_EQ(1u, BrowserList::GetInstance()->size());
}
#endif