Commit 84cc2cc0 authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[profile-menu] Implement guest menu

Additionally, the spacing between menu components
is refactored.

Screenshot:
https://drive.google.com/file/d/1MipwvP17KP8bX3VMg2QFfxqE3J1tma2v/view?usp=sharing

Flag: profile-menu-revamp

Bug: 995720
Change-Id: Ie9a549a96577e7e386f352f95db2d8d0244e7467
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1819357Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698867}
parent 4ad0ec46
......@@ -169,13 +169,21 @@ void ProfileMenuView::BuildMenu() {
AddProfileMenuView(avatar_menu_.get());
return;
}
BuildIdentity();
BuildSyncInfo();
BuildAutofillButtons();
BuildAccountFeatureButtons();
Profile* profile = browser()->profile();
if (profile->IsGuestSession()) {
BuildGuestIdentity();
} else {
DCHECK(profile->IsRegularProfile());
BuildIdentity();
BuildSyncInfo();
BuildAccountFeatureButtons();
BuildAutofillButtons();
BuildProfileFeatureButtons();
}
BuildProfileHeading();
BuildSelectableProfiles();
BuildProfileFeatureButtons();
}
void ProfileMenuView::OnAvatarMenuChanged(
......@@ -412,6 +420,11 @@ void ProfileMenuView::BuildIdentity() {
}
}
void ProfileMenuView::BuildGuestIdentity() {
SetIdentityInfo(gfx::Image(ImageForMenu(kUserAccountAvatarIcon)),
l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME));
}
void ProfileMenuView::BuildAutofillButtons() {
AddShortcutFeatureButton(
ImageForMenu(kKeyIcon, kShortcutIconToImageRatio),
......
......@@ -101,6 +101,7 @@ class ProfileMenuView : public ProfileMenuViewBase, public AvatarMenuObserver {
// Helper methods for building the menu.
void BuildIdentity();
void BuildGuestIdentity();
void BuildAutofillButtons();
void BuildSyncInfo();
void BuildAccountFeatureButtons();
......
......@@ -222,14 +222,14 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::Image& image,
const base::string16& title,
const base::string16& subtitle) {
constexpr int kTopMargin = 16;
constexpr int kBottomMargin = 8;
constexpr int kImageToLabelSpacing = 4;
identity_info_container_->RemoveAllChildViews(/*delete_children=*/true);
identity_info_container_->SetLayoutManager(
CreateBoxLayout(views::BoxLayout::Orientation::kVertical,
views::BoxLayout::CrossAxisAlignment::kCenter));
identity_info_container_->SetBorder(
views::CreateEmptyBorder(kTopMargin, 0, 0, 0));
views::BoxLayout::CrossAxisAlignment::kCenter,
gfx::Insets(kTopMargin, 0, kBottomMargin, 0)));
views::ImageView* image_view = identity_info_container_->AddChildView(
std::make_unique<views::ImageView>());
......@@ -294,15 +294,15 @@ void ProfileMenuViewBase::AddShortcutFeatureButton(
const gfx::ImageSkia& icon,
const base::string16& text,
base::RepeatingClosure action) {
constexpr auto kMargins = gfx::Insets(8, 0);
constexpr int kBottomMargin = 8;
constexpr int kButtonSpacing = 6;
// Initialize layout if this is the first time a button is added.
if (!shortcut_features_container_->GetLayoutManager()) {
views::BoxLayout* layout = shortcut_features_container_->SetLayoutManager(
std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, kMargins,
kButtonSpacing));
views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(0, 0, kBottomMargin, 0), kButtonSpacing));
layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kCenter);
}
......@@ -353,14 +353,15 @@ void ProfileMenuViewBase::SetProfileHeading(const base::string16& heading) {
void ProfileMenuViewBase::AddSelectableProfile(const gfx::Image& image,
const base::string16& name,
base::RepeatingClosure action) {
constexpr auto kMargins = gfx::Insets(8, 0, 0, 0);
constexpr int kTopMargin = 8;
constexpr int kImageSize = 22;
// Initialize layout if this is the first time a button is added.
if (!selectable_profiles_container_->GetLayoutManager()) {
selectable_profiles_container_->SetLayoutManager(
std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, kMargins));
views::BoxLayout::Orientation::kVertical,
gfx::Insets(kTopMargin, 0, 0, 0)));
}
gfx::Image sized_image =
......
......@@ -97,7 +97,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
// API to build the profile menu.
void SetIdentityInfo(const gfx::Image& image,
const base::string16& title,
const base::string16& subtitle);
const base::string16& subtitle = base::string16());
void SetSyncInfo(const base::string16& description,
const base::string16& link_text,
base::RepeatingClosure action);
......
......@@ -620,10 +620,12 @@ class ProfileMenuClickTest : public InProcessBrowserTest,
GetExpectedActionableItemAtIndex(GetParam()), /*count=*/1);
}
void SetTargetBrowser(Browser* browser) { target_browser_ = browser; }
private:
void OpenProfileMenu() {
BrowserView* browser_view =
BrowserView::GetBrowserViewForBrowser(browser());
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(
target_browser_ ? target_browser_ : browser());
views::View* avatar_button =
browser_view->toolbar()->GetAvatarToolbarButton();
DCHECK(avatar_button);
......@@ -662,6 +664,8 @@ class ProfileMenuClickTest : public InProcessBrowserTest,
base::test::ScopedFeatureList scoped_feature_list_;
base::HistogramTester histogram_tester_;
Browser* target_browser_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ProfileMenuClickTest);
};
......@@ -837,3 +841,46 @@ INSTANTIATE_TEST_SUITE_P(
size_t(0),
base::size(ProfileMenuClickTest_WithUnconsentedPrimaryAccount::
kOrderedActionableItems)));
class ProfileMenuClickTest_GuestProfile : public ProfileMenuClickTest {
public:
// List of actionable items in the correct order as they appear in the menu.
// If a new button is added to the menu, it should also be added to this list.
static constexpr ProfileMenuView::ActionableItem kOrderedActionableItems[2] =
{ProfileMenuView::ActionableItem::kOtherProfileButton,
// The first button is added again to finish the cycle and test that
// there are no other buttons at the end.
ProfileMenuView::ActionableItem::kOtherProfileButton};
ProfileMenuClickTest_GuestProfile() = default;
ProfileMenuView::ActionableItem GetExpectedActionableItemAtIndex(
size_t index) override {
return kOrderedActionableItems[index];
}
DISALLOW_COPY_AND_ASSIGN(ProfileMenuClickTest_GuestProfile);
};
// static
constexpr ProfileMenuView::ActionableItem
ProfileMenuClickTest_GuestProfile::kOrderedActionableItems[];
IN_PROC_BROWSER_TEST_P(ProfileMenuClickTest_GuestProfile, SetupAndRunTest) {
profiles::SwitchToGuestProfile(ProfileManager::CreateCallback());
ui_test_utils::WaitForBrowserToOpen();
Profile* guest = g_browser_process->profile_manager()->GetProfileByPath(
ProfileManager::GetGuestProfilePath());
ASSERT_TRUE(guest);
SetTargetBrowser(chrome::FindAnyBrowser(guest, true));
RunTest();
}
INSTANTIATE_TEST_SUITE_P(
,
ProfileMenuClickTest_GuestProfile,
::testing::Range(
size_t(0),
base::size(
ProfileMenuClickTest_GuestProfile::kOrderedActionableItems)));
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