0

Adding managed icon for admin disables Google calendar integration.

Bug: b/255771093
Change-Id: I4c6ff633340546663026911ed46588692b1c9ad7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3984830
Reviewed-by: Alex Newcomer <newcomer@chromium.org>
Commit-Queue: Ramya Gopalan <ramyagopalan@google.com>
Reviewed-by: Jiaming Cheng <jiamingc@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1065047}
This commit is contained in:
Ramya Gopalan
2022-10-28 21:38:23 +00:00
committed by Chromium LUCI CQ
parent 1401b28855
commit 3b936253c8
6 changed files with 88 additions and 1 deletions

@ -4125,6 +4125,14 @@ Connect your device to power.
Date and time settings
</message>
<message name="IDS_ASH_CALENDAR_DISABLED_BY_ADMIN" desc="The label used in the managed button in the calendar view system settings.">
Disabled by admin
</message>
<message name="IDS_ASH_CALENDAR_DISABLED_BY_ADMIN_TOOLTIP" desc="The tooltip label used in the managed button in the calendar view system settings.">
Disabled by Admin
</message>
<message name="IDS_ASH_CLOSE_BUTTON_ACCESSIBLE_DESCRIPTION" desc="The accessible label used in the close button in the calendar event list view.">
Close event panel
</message>

@ -0,0 +1 @@
a0dcd32d7ee1b64cd1e0b2b984241f7fac135bf4

@ -0,0 +1 @@
a0dcd32d7ee1b64cd1e0b2b984241f7fac135bf4

@ -7,6 +7,7 @@
#include <memory>
#include "ash/public/cpp/ash_typography.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/icon_button.h"
#include "ash/style/pill_button.h"
@ -500,9 +501,20 @@ CalendarView::~CalendarView() {
}
void CalendarView::CreateExtraTitleRowButtons() {
DCHECK(!reset_to_today_button_);
tri_view()->SetContainerVisible(TriView::Container::END, /*visible=*/true);
if (calendar_utils::IsDisabledByAdmin()) {
DCHECK(!managed_button_);
managed_button_ = tri_view()->AddView(
TriView::Container::END,
std::make_unique<IconButton>(
base::BindRepeating(
&UnifiedSystemTrayController::HandleEnterpriseInfoAction,
base::Unretained(controller_)),
IconButton::Type::kSmall, &kSystemTrayManagedIcon,
IDS_ASH_CALENDAR_DISABLED_BY_ADMIN));
}
DCHECK(!reset_to_today_button_);
reset_to_today_button_ = CreateInfoButton(
base::BindRepeating(&CalendarView::ResetToTodayWithAnimation,
base::Unretained(this)),

@ -358,6 +358,7 @@ class ASH_EXPORT CalendarView : public CalendarModel::Observer,
CalendarHeaderView* temp_header_ = nullptr;
views::Button* reset_to_today_button_ = nullptr;
views::Button* settings_button_ = nullptr;
IconButton* managed_button_ = nullptr;
IconButton* up_button_ = nullptr;
IconButton* down_button_ = nullptr;
CalendarEventListView* event_list_view_ = nullptr;

@ -53,6 +53,7 @@ using ::google_apis::calendar::EventList;
constexpr char kTestUser[] = "user@test";
constexpr int kLoadingBarIndex = 2;
constexpr char kManagedPage[] = "ChromeOS.SystemTray.OpenHelpPageForManaged";
} // namespace
@ -178,6 +179,8 @@ class CalendarViewTest : public AshTestBase {
return calendar_view_->reset_to_today_button_;
}
views::Button* settings_button() { return calendar_view_->settings_button_; }
views::Button* managed_button() { return calendar_view_->managed_button_; }
IconButton* up_button() { return calendar_view_->up_button_; }
IconButton* down_button() { return calendar_view_->down_button_; }
views::View* close_button() {
@ -1222,6 +1225,67 @@ TEST_F(CalendarViewTest, EventListBoundsTest) {
EXPECT_EQ(bottom_of_scroll_view_visible_area, top_of_event_list_view);
}
TEST_F(CalendarViewTest, AdminDisabledTest) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
Shell::Get()->session_controller()->GetActivePrefService()->SetBoolean(
ash::prefs::kCalendarIntegrationEnabled, false);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Todays DateCellView should be focused on open.
ASSERT_TRUE(focus_manager->GetFocusedView()->GetClassName());
ASSERT_TRUE(focus_manager->GetFocusedView());
// Moves to the back button.
PressTab();
// Moves to the next focusable view - managed icon button.
PressTab();
EXPECT_EQ(managed_button(), focus_manager->GetFocusedView());
// Moves to the next focusable view. Today's button.
PressTab();
EXPECT_EQ(reset_to_today_button(), focus_manager->GetFocusedView());
// Moves to settings button.
PressTab();
EXPECT_EQ(settings_button(), focus_manager->GetFocusedView());
// Moves back to managed icon button.
PressShiftTab();
PressShiftTab();
EXPECT_EQ(managed_button(), focus_manager->GetFocusedView());
}
TEST_F(CalendarViewTest, ManagedButtonTest) {
base::HistogramTester histogram_tester;
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
Shell::Get()->session_controller()->GetActivePrefService()->SetBoolean(
ash::prefs::kCalendarIntegrationEnabled, false);
CreateCalendarView();
// Click on managed button to open chrome://management.
GestureTapOn(managed_button());
// Expect increment to UMA histogram count for managed page - enterprise.
histogram_tester.ExpectBucketCount(kManagedPage, 0, 1);
}
// A test class for testing animation. This class cannot set fake now since it's
// using `MOCK_TIME` to test the animations, and it can't inherit from
// CalendarAnimationTest due to the same reason.