0

[ChromeOS] Hide pin_tab_strip_button_ in OnTask pod in unlocked mode

Bug: b:400842133
Change-Id: I7f4e3f36a2d22b0646c3ea8e301bca68ff1d8405
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6378841
Reviewed-by: Vignesh Shenvi <vshenvi@google.com>
Commit-Queue: Luke Cao <caott@google.com>
Cr-Commit-Position: refs/heads/main@{#1436207}
This commit is contained in:
caott
2025-03-21 12:00:08 -07:00
committed by Chromium LUCI CQ
parent 80847702e9
commit 745c10bb9b
5 changed files with 33 additions and 12 deletions

@ -140,13 +140,14 @@ void OnTaskPodView::AddShortcutButtons() {
gfx::Insets::VH(kSeparatorVerticalPadding, kSeparatorHorizontalPadding)));
right_separator_->SetColorId(cros_tokens::kCrosSysSeparator);
right_separator_->SetPreferredLength(kLabelButtonHeight);
right_separator_->SetVisible(pod_controller_->CanToggleTabStripVisibility());
pin_tab_strip_button_ = AddChildView(std::make_unique<PinTabStripButton>(
base::BindRepeating(&OnTaskPodView::UpdatePinTabStripButton,
base::Unretained(this)),
l10n_util::GetStringUTF16(
IDS_ON_TASK_POD_PIN_TAP_STRIP_ACCESSIBLE_NAME)));
pin_tab_strip_button_->SetEnabled(
pin_tab_strip_button_->SetVisible(
pod_controller_->CanToggleTabStripVisibility());
}
@ -192,8 +193,16 @@ void OnTaskPodView::OnPageNavigationContextUpdate() {
}
void OnTaskPodView::OnLockedModeUpdate() {
pin_tab_strip_button_->SetEnabled(
pod_controller_->CanToggleTabStripVisibility());
const bool can_toggle = pod_controller_->CanToggleTabStripVisibility();
right_separator_->SetVisible(can_toggle);
pin_tab_strip_button_->SetVisible(can_toggle);
if (can_toggle) {
// `should_show_tab_strip_` is set to true to ensure it is toggled in
// `UpdatePinTabStripButton()` to by default hide the tab strip when
// entering locked mode.
should_show_tab_strip_ = true;
UpdatePinTabStripButton();
}
}
BEGIN_METADATA(OnTaskPodView)

@ -78,7 +78,7 @@ class ASH_EXPORT OnTaskPodView : public views::BoxLayoutView {
// Adds shortcut buttons to the OnTask pod view.
void AddShortcutButtons();
// Update the color and text of the pin tab strip button, and the tab strip
// Update the color and text of the `pin_tab_strip_button_`, and the tab strip
// visibility.
void UpdatePinTabStripButton();

@ -111,29 +111,38 @@ TEST_F(OnTaskPodViewTest, ReloadTabButtonClickTriggersTabReload) {
}
TEST_F(OnTaskPodViewTest,
PinTabStripButtonDisabledWhenCannotEnableShowOrHideTabStrip) {
HidePinTabStripButtonWhenCannotEnableShowOrHideTabStrip) {
EXPECT_CALL(mock_on_task_pod_controller_, CanToggleTabStripVisibility())
.WillOnce(testing::Return(false));
on_task_pod_view_->OnLockedModeUpdate();
EXPECT_FALSE(
on_task_pod_view_->pin_tab_strip_button_for_testing()->GetEnabled());
on_task_pod_view_->pin_tab_strip_button_for_testing()->GetVisible());
}
TEST_F(OnTaskPodViewTest, PinTabStripButtonClickTriggersShowOrHideTabStrip) {
Sequence s;
EXPECT_CALL(mock_on_task_pod_controller_, CanToggleTabStripVisibility())
.WillOnce(testing::Return(true));
EXPECT_CALL(mock_on_task_pod_controller_, ToggleTabStripVisibility(false))
.Times(1)
.InSequence(s);
;
on_task_pod_view_->OnLockedModeUpdate();
ASSERT_TRUE(
on_task_pod_view_->pin_tab_strip_button_for_testing()->GetEnabled());
// Resize the widget to fit the contents view, and apply the new layout within
// the widget. Otherwise, we are not able to click on pin_tab_strip_button.
widget_->SetSize(on_task_pod_view_->GetPreferredSize());
widget_->LayoutRootViewIfNecessary();
auto* const pin_tab_strip_button =
on_task_pod_view_->pin_tab_strip_button_for_testing();
ASSERT_TRUE(pin_tab_strip_button->GetVisible());
EXPECT_CALL(mock_on_task_pod_controller_, ToggleTabStripVisibility(true))
.Times(1)
.InSequence(s);
EXPECT_CALL(mock_on_task_pod_controller_, ToggleTabStripVisibility(false))
.Times(1)
.InSequence(s);
auto* const pin_tab_strip_button =
on_task_pod_view_->pin_tab_strip_button_for_testing();
LeftClickOn(pin_tab_strip_button);
LeftClickOn(pin_tab_strip_button);
}

@ -140,6 +140,9 @@ void OnTaskPodControllerImpl::OnWindowBoundsChanged(
bool is_window_pinned = IsWindowPinned(window);
if (is_window_pinned_ != is_window_pinned) {
on_task_pod_view->OnLockedModeUpdate();
// Resize the widget to fit the contents view.
pod_widget_->SetSize(on_task_pod_view->GetPreferredSize());
}
is_window_pinned_ = is_window_pinned;
}

@ -462,7 +462,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskPodControllerImplBrowserTest, ReloadCurrentTab) {
}
IN_PROC_BROWSER_TEST_F(OnTaskPodControllerImplBrowserTest,
PinTabStripButtonDisabledWhenUnlocked) {
DisablePinTabStripFunctionalityWhenUnlocked) {
// Launch OnTask SWA.
base::test::TestFuture<bool> launch_future;
system_web_app_manager()->LaunchSystemWebAppAsync(
@ -490,7 +490,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskPodControllerImplBrowserTest,
}
IN_PROC_BROWSER_TEST_F(OnTaskPodControllerImplBrowserTest,
PinTabStripButtonEnabledWhenLocked) {
EnablePinTabStripFunctionalityWhenLocked) {
// Launch OnTask SWA.
base::test::TestFuture<bool> launch_future;
system_web_app_manager()->LaunchSystemWebAppAsync(