Commit 310e38dd authored by Alex Ilin's avatar Alex Ilin Committed by Chromium LUCI CQ

Reland "[profiles] Don't show a profile being created in the picker and menu"

This reverts commit e23f231d.

Reason for revert: crash https://crbug.com/1169047 that was caused by the original version of this CL was fixed

Original change's description:
> Revert "[profiles] Don't show a profile being created in the picker and menu"
>
> This reverts commit e2de939b.
>
> Reason for revert: causes crash https://crbug.com/1169047
>
> Original change's description:
> > [profiles] Don't show a profile being created in the picker and menu
> >
> > This CL leverages the already existing kIsOmittedFromProfileListKey
> > preference in ProfileAttributesEntry to mark profiles that shouldn't
> > be shown to the user.
> >
> > kIsOmittedFromProfileListKey was created for profiles in the middle of
> > being set up as new legacy supervised users. The preference was dead
> > because it was never set to true. This CL revives it and adds additional
> > checks to profile_picker_handler.cc and profile_menu_view.cc to not
> > display omitted profiles.
> >
> > Bug: 1126913, 1166809
> > Change-Id: Ieb05f31d8951f2971201351bead7c108eb874473
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2632752
> > Commit-Queue: Alex Ilin <alexilin@chromium.org>
> > Reviewed-by: David Roger <droger@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#845372}
>
> TBR=droger@chromium.org,alexilin@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com
>
> Change-Id: I5133c4502f02b68c4e707fa7c86072bdabce4ff2
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 1126913
> Bug: 1166809
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2642328
> Reviewed-by: Alex Ilin <alexilin@chromium.org>
> Commit-Queue: Alex Ilin <alexilin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#845616}

TBR=droger@chromium.org,alexilin@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com

# Not skipping CQ checks because this is a reland.

Bug: 1126913
Bug: 1166809
Change-Id: I8aba3d3ffef4e01a51228d449e7e0bac24b8f7f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2642329Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845667}
parent 226653e9
...@@ -381,7 +381,7 @@ bool ProfileAttributesEntry::IsLegacySupervised() const { ...@@ -381,7 +381,7 @@ bool ProfileAttributesEntry::IsLegacySupervised() const {
} }
bool ProfileAttributesEntry::IsOmitted() const { bool ProfileAttributesEntry::IsOmitted() const {
return GetBool(kIsOmittedFromProfileListKey); return is_omitted_ || GetBool(kIsOmittedFromProfileListKey);
} }
bool ProfileAttributesEntry::IsSigninRequired() const { bool ProfileAttributesEntry::IsSigninRequired() const {
...@@ -516,7 +516,13 @@ void ProfileAttributesEntry::SetActiveTimeToNow() { ...@@ -516,7 +516,13 @@ void ProfileAttributesEntry::SetActiveTimeToNow() {
} }
void ProfileAttributesEntry::SetIsOmitted(bool is_omitted) { void ProfileAttributesEntry::SetIsOmitted(bool is_omitted) {
if (SetBool(kIsOmittedFromProfileListKey, is_omitted)) bool old_value = IsOmitted();
// Set the in-memory bool as the only source of truth.
ClearValue(kIsOmittedFromProfileListKey);
is_omitted_ = is_omitted;
// Send a notification only if the value has really changed.
if (old_value != is_omitted_)
profile_info_cache_->NotifyProfileIsOmittedChanged(GetPath()); profile_info_cache_->NotifyProfileIsOmittedChanged(GetPath());
} }
......
...@@ -114,6 +114,8 @@ class ProfileAttributesEntry { ...@@ -114,6 +114,8 @@ class ProfileAttributesEntry {
bool IsChild() const; bool IsChild() const;
// Returns true if the profile is a supervised user but not a child account. // Returns true if the profile is a supervised user but not a child account.
bool IsLegacySupervised() const; bool IsLegacySupervised() const;
// Returns true if the profile should not be displayed to the user in the
// list of profiles.
bool IsOmitted() const; bool IsOmitted() const;
bool IsSigninRequired() const; bool IsSigninRequired() const;
// Gets the supervised user ID of the profile's signed in account, if it's a // Gets the supervised user ID of the profile's signed in account, if it's a
...@@ -212,6 +214,7 @@ class ProfileAttributesEntry { ...@@ -212,6 +214,7 @@ class ProfileAttributesEntry {
// TODO(crbug/1155729): Check it is not used anymore for deprecated supervised // TODO(crbug/1155729): Check it is not used anymore for deprecated supervised
// users and remove it. // users and remove it.
static const char kSupervisedUserId[]; static const char kSupervisedUserId[];
// DEPRECATED: IsOmitted pref was moved to in memory only, see `is_omitted_`.
static const char kIsOmittedFromProfileListKey[]; static const char kIsOmittedFromProfileListKey[];
static const char kAvatarIconKey[]; static const char kAvatarIconKey[];
static const char kBackgroundAppsKey[]; static const char kBackgroundAppsKey[];
...@@ -323,6 +326,14 @@ class ProfileAttributesEntry { ...@@ -323,6 +326,14 @@ class ProfileAttributesEntry {
// memory only and can be easily reset once the policy is turned off. // memory only and can be easily reset once the policy is turned off.
bool is_force_signin_profile_locked_ = false; bool is_force_signin_profile_locked_ = false;
bool is_force_signin_enabled_; bool is_force_signin_enabled_;
// Indicates whether the profile should not be displayed to the user in the
// list of profiles. This flag is intended to work only with ephemeral
// profiles which get removed after the browser restart. Thus, this flag is
// stored in memory only. Storing in memory also allows to avoid the risk of
// having permanent profiles that the user cannot see or delete, in case the
// ephemeral profile deletion fails.
bool is_omitted_ = false;
}; };
#endif // CHROME_BROWSER_PROFILES_PROFILE_ATTRIBUTES_ENTRY_H_ #endif // CHROME_BROWSER_PROFILES_PROFILE_ATTRIBUTES_ENTRY_H_
...@@ -339,9 +339,12 @@ TEST_F(ProfileAttributesStorageTest, EntryAccessors) { ...@@ -339,9 +339,12 @@ TEST_F(ProfileAttributesStorageTest, EntryAccessors) {
TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingGAIAPicture); TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingGAIAPicture);
VerifyAndResetCallExpectations(); VerifyAndResetCallExpectations();
// IsOmitted() should be set only on ephemeral profiles.
entry->SetIsEphemeral(true);
EXPECT_CALL(observer(), OnProfileIsOmittedChanged(path)).Times(2); EXPECT_CALL(observer(), OnProfileIsOmittedChanged(path)).Times(2);
TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsOmitted); TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsOmitted);
VerifyAndResetCallExpectations(); VerifyAndResetCallExpectations();
entry->SetIsEphemeral(false);
EXPECT_CALL(observer(), OnProfileHostedDomainChanged(path)).Times(2); EXPECT_CALL(observer(), OnProfileHostedDomainChanged(path)).Times(2);
TEST_STRING_ACCESSORS(ProfileAttributesEntry, entry, HostedDomain); TEST_STRING_ACCESSORS(ProfileAttributesEntry, entry, HostedDomain);
......
...@@ -698,6 +698,8 @@ void ProfileMenuView::BuildSelectableProfiles() { ...@@ -698,6 +698,8 @@ void ProfileMenuView::BuildSelectableProfiles() {
// The current profile is excluded. // The current profile is excluded.
if (profile_entry->GetPath() == browser()->profile()->GetPath()) if (profile_entry->GetPath() == browser()->profile()->GetPath())
continue; continue;
if (profile_entry->IsOmitted())
continue;
AddSelectableProfile( AddSelectableProfile(
ui::ImageModel::FromImage( ui::ImageModel::FromImage(
......
...@@ -500,6 +500,9 @@ void ProfilePickerView::OnProfileForSigninCreated( ...@@ -500,6 +500,9 @@ void ProfilePickerView::OnProfileForSigninCreated(
// Mark this profile ephemeral so that it is deleted upon next startup if the // Mark this profile ephemeral so that it is deleted upon next startup if the
// browser crashes before finishing the flow. // browser crashes before finishing the flow.
entry->SetIsEphemeral(true); entry->SetIsEphemeral(true);
// Mark this profile as omitted so that it is not displayed in the list of
// profiles.
entry->SetIsOmitted(true);
// Record that the sign in process starts (its end is recorded automatically // Record that the sign in process starts (its end is recorded automatically
// by the instance of DiceTurnSyncOnHelper constructed later on). // by the instance of DiceTurnSyncOnHelper constructed later on).
...@@ -926,6 +929,7 @@ void ProfilePickerView::FinishSignedInCreationFlowImpl( ...@@ -926,6 +929,7 @@ void ProfilePickerView::FinishSignedInCreationFlowImpl(
return; return;
} }
entry->SetIsOmitted(false);
if (!signed_in_profile_being_created_->GetPrefs()->GetBoolean( if (!signed_in_profile_being_created_->GetPrefs()->GetBoolean(
prefs::kForceEphemeralProfiles)) { prefs::kForceEphemeralProfiles)) {
// Unmark this profile ephemeral so that it isn't deleted upon next startup. // Unmark this profile ephemeral so that it isn't deleted upon next startup.
......
...@@ -803,6 +803,7 @@ IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest, ...@@ -803,6 +803,7 @@ IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest,
.GetProfileAttributesWithPath( .GetProfileAttributesWithPath(
profile_being_created->GetPath(), &entry)); profile_being_created->GetPath(), &entry));
EXPECT_TRUE(entry->IsEphemeral()); EXPECT_TRUE(entry->IsEphemeral());
EXPECT_TRUE(entry->IsOmitted());
// Add an account - simulate a successful Gaia sign-in. // Add an account - simulate a successful Gaia sign-in.
signin::IdentityManager* identity_manager = signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_being_created); IdentityManagerFactory::GetForProfile(profile_being_created);
...@@ -830,6 +831,7 @@ IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest, ...@@ -830,6 +831,7 @@ IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest,
EXPECT_EQ(entry->GetLocalProfileName(), base::UTF8ToUTF16("Joe")); EXPECT_EQ(entry->GetLocalProfileName(), base::UTF8ToUTF16("Joe"));
// The profile is no longer ephemeral, unless the policy is enabled. // The profile is no longer ephemeral, unless the policy is enabled.
EXPECT_EQ(entry->IsEphemeral(), AreEphemeralProfilesForced()); EXPECT_EQ(entry->IsEphemeral(), AreEphemeralProfilesForced());
EXPECT_FALSE(entry->IsOmitted());
// The preference is consistent with the policy. // The preference is consistent with the policy.
CheckPolicyApplied(profile_being_created); CheckPolicyApplied(profile_being_created);
} }
...@@ -867,6 +869,7 @@ IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest, ...@@ -867,6 +869,7 @@ IN_PROC_BROWSER_TEST_P(ProfilePickerCreationFlowEphemeralProfileBrowserTest,
.GetProfileAttributesWithPath( .GetProfileAttributesWithPath(
profile_being_created->GetPath(), &entry)); profile_being_created->GetPath(), &entry));
EXPECT_TRUE(entry->IsEphemeral()); EXPECT_TRUE(entry->IsEphemeral());
EXPECT_TRUE(entry->IsOmitted());
// Exit Chrome while still in the signin flow. // Exit Chrome while still in the signin flow.
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/util/values/values_util.h" #include "base/util/values/values_util.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
...@@ -621,21 +622,20 @@ void ProfilePickerHandler::SetProfilesOrder( ...@@ -621,21 +622,20 @@ void ProfilePickerHandler::SetProfilesOrder(
profiles_order_.clear(); profiles_order_.clear();
size_t index = 0; size_t index = 0;
for (const ProfileAttributesEntry* entry : entries) { for (const ProfileAttributesEntry* entry : entries) {
if (entry->IsGuest())
continue;
profiles_order_[entry->GetPath()] = index++; profiles_order_[entry->GetPath()] = index++;
} }
} }
std::vector<ProfileAttributesEntry*> std::vector<ProfileAttributesEntry*>
ProfilePickerHandler::GetProfileAttributes() { ProfilePickerHandler::GetProfileAttributes() {
size_t number_of_profiles =
g_browser_process->profile_manager()->GetNumberOfProfiles();
std::vector<ProfileAttributesEntry*> ordered_entries = std::vector<ProfileAttributesEntry*> ordered_entries =
g_browser_process->profile_manager() g_browser_process->profile_manager()
->GetProfileAttributesStorage() ->GetProfileAttributesStorage()
.GetAllProfilesAttributesSortedByLocalProfilName(); .GetAllProfilesAttributesSortedByLocalProfilName();
base::EraseIf(ordered_entries, [](const ProfileAttributesEntry* entry) {
return entry->IsGuest() || entry->IsOmitted();
});
size_t number_of_profiles = ordered_entries.size();
if (profiles_order_.size() != number_of_profiles) { if (profiles_order_.size() != number_of_profiles) {
// Should only happen the first time the function is called. // Should only happen the first time the function is called.
...@@ -688,11 +688,36 @@ base::Value ProfilePickerHandler::GetProfilesList() { ...@@ -688,11 +688,36 @@ base::Value ProfilePickerHandler::GetProfilesList() {
return std::move(profiles_list); return std::move(profiles_list);
} }
void ProfilePickerHandler::OnProfileAdded(const base::FilePath& profile_path) { void ProfilePickerHandler::AddProfileToList(
if (profile_path == ProfileManager::GetGuestProfilePath()) const base::FilePath& profile_path) {
return;
size_t number_of_profiles = profiles_order_.size(); size_t number_of_profiles = profiles_order_.size();
profiles_order_[profile_path] = number_of_profiles; profiles_order_[profile_path] = number_of_profiles;
}
bool ProfilePickerHandler::RemoveProfileFromList(
const base::FilePath& profile_path) {
auto remove_it = profiles_order_.find(profile_path);
// Guest and omitted profiles aren't added to the list.
if (remove_it == profiles_order_.end())
return false;
size_t index = remove_it->second;
profiles_order_.erase(remove_it);
for (auto& it : profiles_order_) {
if (it.second > index)
--it.second;
}
return true;
}
void ProfilePickerHandler::OnProfileAdded(const base::FilePath& profile_path) {
ProfileAttributesEntry* entry;
CHECK(g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile_path, &entry));
if (entry->IsGuest() || entry->IsOmitted())
return;
AddProfileToList(profile_path);
PushProfilesList(); PushProfilesList();
} }
...@@ -700,15 +725,25 @@ void ProfilePickerHandler::OnProfileWasRemoved( ...@@ -700,15 +725,25 @@ void ProfilePickerHandler::OnProfileWasRemoved(
const base::FilePath& profile_path, const base::FilePath& profile_path,
const base::string16& profile_name) { const base::string16& profile_name) {
DCHECK(IsJavascriptAllowed()); DCHECK(IsJavascriptAllowed());
if (RemoveProfileFromList(profile_path))
FireWebUIListener("profile-removed", util::FilePathToValue(profile_path));
}
void ProfilePickerHandler::OnProfileIsOmittedChanged(
const base::FilePath& profile_path) {
if (profile_path == ProfileManager::GetGuestProfilePath()) if (profile_path == ProfileManager::GetGuestProfilePath())
return; return;
size_t index = profiles_order_[profile_path]; ProfileAttributesEntry* entry;
profiles_order_.erase(profile_path); CHECK(g_browser_process->profile_manager()
for (auto it : profiles_order_) { ->GetProfileAttributesStorage()
if (it.second > index) .GetProfileAttributesWithPath(profile_path, &entry));
profiles_order_[it.first] = it.second - 1; if (entry->IsOmitted()) {
if (RemoveProfileFromList(profile_path))
PushProfilesList();
} else {
AddProfileToList(profile_path);
PushProfilesList();
} }
FireWebUIListener("profile-removed", util::FilePathToValue(profile_path));
} }
void ProfilePickerHandler::OnProfileAvatarChanged( void ProfilePickerHandler::OnProfileAvatarChanged(
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <unordered_map> #include <unordered_map>
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
...@@ -34,6 +35,8 @@ class ProfilePickerHandler : public content::WebUIMessageHandler, ...@@ -34,6 +35,8 @@ class ProfilePickerHandler : public content::WebUIMessageHandler,
void OnJavascriptDisallowed() override; void OnJavascriptDisallowed() override;
private: private:
friend class ProfilePickerHandlerTest;
void HandleMainViewInitialize(const base::ListValue* args); void HandleMainViewInitialize(const base::ListValue* args);
void HandleLaunchSelectedProfile(bool open_settings, void HandleLaunchSelectedProfile(bool open_settings,
const base::ListValue* args); const base::ListValue* args);
...@@ -70,11 +73,17 @@ class ProfilePickerHandler : public content::WebUIMessageHandler, ...@@ -70,11 +73,17 @@ class ProfilePickerHandler : public content::WebUIMessageHandler,
Profile* profile); Profile* profile);
void PushProfilesList(); void PushProfilesList();
base::Value GetProfilesList(); base::Value GetProfilesList();
// Adds a profile with `profile_path` to `profiles_order_`.
void AddProfileToList(const base::FilePath& profile_path);
// Removes a profile with `profile_path` from `profiles_order_`. Returns
// true if the profile was found and removed. Otherwise, returns false.
bool RemoveProfileFromList(const base::FilePath& profile_path);
// ProfileAttributesStorage::Observer: // ProfileAttributesStorage::Observer:
void OnProfileAdded(const base::FilePath& profile_path) override; void OnProfileAdded(const base::FilePath& profile_path) override;
void OnProfileWasRemoved(const base::FilePath& profile_path, void OnProfileWasRemoved(const base::FilePath& profile_path,
const base::string16& profile_name) override; const base::string16& profile_name) override;
void OnProfileIsOmittedChanged(const base::FilePath& profile_path) override;
void OnProfileAvatarChanged(const base::FilePath& profile_path) override; void OnProfileAvatarChanged(const base::FilePath& profile_path) override;
void OnProfileHighResAvatarLoaded( void OnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) override; const base::FilePath& profile_path) override;
......
// Copyright 2021 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 "chrome/browser/ui/webui/signin/profile_picker_handler.h"
#include "base/strings/utf_string_conversions.h"
#include "base/util/values/values_util.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_ui.h"
#include "testing/gtest/include/gtest/gtest.h"
void VerifyProfileEntry(const base::Value& value,
ProfileAttributesEntry* entry) {
EXPECT_EQ(*value.FindKey("profilePath"),
util::FilePathToValue(entry->GetPath()));
EXPECT_EQ(*value.FindStringKey("localProfileName"),
base::UTF16ToUTF8(entry->GetLocalProfileName()));
EXPECT_EQ(value.FindBoolKey("isSyncing"),
entry->GetSigninState() ==
SigninState::kSignedInWithConsentedPrimaryAccount);
EXPECT_EQ(value.FindBoolKey("needsSignin"), entry->IsSigninRequired());
EXPECT_EQ(*value.FindStringKey("gaiaName"),
base::UTF16ToUTF8(entry->GetGAIANameToDisplay()));
EXPECT_EQ(*value.FindStringKey("userName"),
base::UTF16ToUTF8(entry->GetUserName()));
EXPECT_EQ(value.FindBoolKey("isManaged"),
AccountInfo::IsManaged(entry->GetHostedDomain()));
}
class ProfilePickerHandlerTest : public testing::Test {
public:
ProfilePickerHandlerTest()
: profile_manager_(TestingBrowserProcess::GetGlobal()) {}
void SetUp() override {
ASSERT_TRUE(profile_manager_.SetUp());
handler_.set_web_ui(&web_ui_);
}
void VerifyProfileListWasPushed(
const std::vector<ProfileAttributesEntry*>& ordered_profile_entries) {
ASSERT_TRUE(!web_ui()->call_data().empty());
const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
ASSERT_EQ("cr.webUIListenerCallback", data.function_name());
ASSERT_EQ("profiles-list-changed", data.arg1()->GetString());
size_t size = data.arg2()->GetList().size();
ASSERT_EQ(size, ordered_profile_entries.size());
for (size_t i = 0; i < size; ++i) {
VerifyProfileEntry(data.arg2()->GetList()[i], ordered_profile_entries[i]);
}
}
void VerifyProfileWasRemoved(const base::FilePath& profile_path) {
ASSERT_TRUE(!web_ui()->call_data().empty());
const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
ASSERT_EQ("cr.webUIListenerCallback", data.function_name());
ASSERT_EQ("profile-removed", data.arg1()->GetString());
ASSERT_EQ(*data.arg2(), util::FilePathToValue(profile_path));
}
void InitializeMainViewAndVerifyProfileList(
const std::vector<ProfileAttributesEntry*>& ordered_profile_entries) {
base::ListValue empty_args;
handler()->HandleMainViewInitialize(&empty_args);
VerifyProfileListWasPushed(ordered_profile_entries);
}
// Creates a new testing profile and returns its `ProfileAttributesEntry`.
ProfileAttributesEntry* CreateTestingProfile(
const std::string& profile_name) {
auto* profile = profile_manager()->CreateTestingProfile(profile_name);
ProfileAttributesEntry* entry = nullptr;
CHECK(profile_manager()
->profile_attributes_storage()
->GetProfileAttributesWithPath(profile->GetPath(), &entry));
return entry;
}
TestingProfileManager* profile_manager() { return &profile_manager_; }
content::TestWebUI* web_ui() { return &web_ui_; }
ProfilePickerHandler* handler() { return &handler_; }
private:
content::BrowserTaskEnvironment task_environment_;
TestingProfileManager profile_manager_;
content::TestWebUI web_ui_;
ProfilePickerHandler handler_;
};
TEST_F(ProfilePickerHandlerTest, OrderedAlphabeticallyOnInit) {
ProfileAttributesEntry* profile_a = CreateTestingProfile("A");
ProfileAttributesEntry* profile_d = CreateTestingProfile("D");
ProfileAttributesEntry* profile_c = CreateTestingProfile("C");
ProfileAttributesEntry* profile_b = CreateTestingProfile("B");
InitializeMainViewAndVerifyProfileList(
{profile_a, profile_b, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
}
TEST_F(ProfilePickerHandlerTest, AddProfile) {
ProfileAttributesEntry* profile_a = CreateTestingProfile("A");
ProfileAttributesEntry* profile_c = CreateTestingProfile("C");
ProfileAttributesEntry* profile_d = CreateTestingProfile("D");
InitializeMainViewAndVerifyProfileList({profile_a, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
// A new profile should be added to the end of the list.
ProfileAttributesEntry* profile_b = CreateTestingProfile("B");
VerifyProfileListWasPushed({profile_a, profile_c, profile_d, profile_b});
web_ui()->ClearTrackedCalls();
}
TEST_F(ProfilePickerHandlerTest, AddProfileToEmptyList) {
InitializeMainViewAndVerifyProfileList({});
web_ui()->ClearTrackedCalls();
ProfileAttributesEntry* profile = CreateTestingProfile("Profile");
VerifyProfileListWasPushed({profile});
web_ui()->ClearTrackedCalls();
}
TEST_F(ProfilePickerHandlerTest, RenameProfile) {
ProfileAttributesEntry* profile_a = CreateTestingProfile("A");
ProfileAttributesEntry* profile_b = CreateTestingProfile("B");
ProfileAttributesEntry* profile_c = CreateTestingProfile("C");
ProfileAttributesEntry* profile_d = CreateTestingProfile("D");
InitializeMainViewAndVerifyProfileList(
{profile_a, profile_b, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
// The profile list doesn't get re-ordered after a rename.
profile_b->SetLocalProfileName(base::UTF8ToUTF16("X"), false);
VerifyProfileListWasPushed({profile_a, profile_b, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
}
TEST_F(ProfilePickerHandlerTest, RemoveProfile) {
ProfileAttributesEntry* profile_a = CreateTestingProfile("A");
ProfileAttributesEntry* profile_b = CreateTestingProfile("B");
ProfileAttributesEntry* profile_c = CreateTestingProfile("C");
ProfileAttributesEntry* profile_d = CreateTestingProfile("D");
InitializeMainViewAndVerifyProfileList(
{profile_a, profile_b, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
base::FilePath b_path = profile_b->GetPath();
profile_manager()->DeleteTestingProfile("B");
VerifyProfileWasRemoved(b_path);
web_ui()->ClearTrackedCalls();
// Verify that the next profile push is correct.
ProfileAttributesEntry* profile_e = CreateTestingProfile("E");
VerifyProfileListWasPushed({profile_a, profile_c, profile_d, profile_e});
web_ui()->ClearTrackedCalls();
}
TEST_F(ProfilePickerHandlerTest, RemoveOmittedProfile) {
ProfileAttributesEntry* profile_a = CreateTestingProfile("A");
ProfileAttributesEntry* profile_d = CreateTestingProfile("D");
ProfileAttributesEntry* profile_c = CreateTestingProfile("C");
ProfileAttributesEntry* profile_b = CreateTestingProfile("B");
profile_b->SetIsOmitted(true);
InitializeMainViewAndVerifyProfileList({profile_a, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
profile_manager()->DeleteTestingProfile("B");
// No callbacks should be called.
ASSERT_TRUE(web_ui()->call_data().empty());
web_ui()->ClearTrackedCalls();
// Verify that the next profile push is correct.
ProfileAttributesEntry* profile_e = CreateTestingProfile("E");
VerifyProfileListWasPushed({profile_a, profile_c, profile_d, profile_e});
web_ui()->ClearTrackedCalls();
}
TEST_F(ProfilePickerHandlerTest, MarkProfileAsOmitted) {
ProfileAttributesEntry* profile_a = CreateTestingProfile("A");
ProfileAttributesEntry* profile_b = CreateTestingProfile("B");
ProfileAttributesEntry* profile_c = CreateTestingProfile("C");
ProfileAttributesEntry* profile_d = CreateTestingProfile("D");
InitializeMainViewAndVerifyProfileList(
{profile_a, profile_b, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
profile_b->SetIsOmitted(true);
VerifyProfileListWasPushed({profile_a, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
// Omitted profile is appended to the end of the profile list.
profile_b->SetIsOmitted(false);
VerifyProfileListWasPushed({profile_a, profile_c, profile_d, profile_b});
web_ui()->ClearTrackedCalls();
}
TEST_F(ProfilePickerHandlerTest, OmittedProfileOnInit) {
ProfileAttributesEntry* profile_a = CreateTestingProfile("A");
ProfileAttributesEntry* profile_b = CreateTestingProfile("B");
ProfileAttributesEntry* profile_c = CreateTestingProfile("C");
ProfileAttributesEntry* profile_d = CreateTestingProfile("D");
profile_b->SetIsOmitted(true);
InitializeMainViewAndVerifyProfileList({profile_a, profile_c, profile_d});
web_ui()->ClearTrackedCalls();
profile_b->SetIsOmitted(false);
VerifyProfileListWasPushed({profile_a, profile_c, profile_d, profile_b});
web_ui()->ClearTrackedCalls();
}
...@@ -4697,6 +4697,7 @@ test("unit_tests") { ...@@ -4697,6 +4697,7 @@ test("unit_tests") {
"../browser/ui/webui/settings/site_settings_handler_unittest.cc", "../browser/ui/webui/settings/site_settings_handler_unittest.cc",
"../browser/ui/webui/settings/site_settings_helper_unittest.cc", "../browser/ui/webui/settings/site_settings_helper_unittest.cc",
"../browser/ui/webui/signin/login_ui_service_unittest.cc", "../browser/ui/webui/signin/login_ui_service_unittest.cc",
"../browser/ui/webui/signin/profile_picker_handler_unittest.cc",
"../browser/ui/webui/sync_internals/sync_internals_message_handler_unittest.cc", "../browser/ui/webui/sync_internals/sync_internals_message_handler_unittest.cc",
"../browser/ui/webui/tab_search/tab_search_page_handler_unittest.cc", "../browser/ui/webui/tab_search/tab_search_page_handler_unittest.cc",
"../browser/ui/webui/theme_source_unittest.cc", "../browser/ui/webui/theme_source_unittest.cc",
...@@ -4936,6 +4937,7 @@ test("unit_tests") { ...@@ -4936,6 +4937,7 @@ test("unit_tests") {
"../browser/signin/chrome_signin_status_metrics_provider_delegate_unittest.cc", "../browser/signin/chrome_signin_status_metrics_provider_delegate_unittest.cc",
"../browser/ui/passwords/account_storage_auth_helper_unittest.cc", "../browser/ui/passwords/account_storage_auth_helper_unittest.cc",
"../browser/ui/webui/settings/settings_manage_profile_handler_unittest.cc", "../browser/ui/webui/settings/settings_manage_profile_handler_unittest.cc",
"../browser/ui/webui/signin/profile_picker_handler_unittest.cc",
# Chrome OS uses window_sizer_chromeos_unittest.cc # Chrome OS uses window_sizer_chromeos_unittest.cc
"../browser/ui/window_sizer/window_sizer_unittest.cc", "../browser/ui/window_sizer/window_sizer_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment