0

[gtm] Add pixeltests for glanceables time management

Bug: b/333770880
Change-Id: I6bb1d2fc1fb9451f8b12266c34c3c9d2898343c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5710533
Reviewed-by: Artsiom Mitrokhin <amitrokhin@chromium.org>
Commit-Queue: Wen-Chien Wang <wcwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1329020}
This commit is contained in:
Wen-Chien Wang
2024-07-17 18:51:47 +00:00
committed by Chromium LUCI CQ
parent 5b37e24f96
commit 49852bdeda

@ -7,6 +7,8 @@
#include "ash/api/tasks/fake_tasks_client.h"
#include "ash/constants/ash_features.h"
#include "ash/glanceables/classroom/fake_glanceables_classroom_client.h"
#include "ash/glanceables/common/glanceables_view_id.h"
#include "ash/glanceables/glanceables_controller.h"
#include "ash/glanceables/tasks/test/glanceables_tasks_test_util.h"
#include "ash/shelf/shelf.h"
@ -19,16 +21,17 @@
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "base/time/time_override.h"
#include "ui/views/controls/scroll_view.h"
namespace {
constexpr char due_date[] = "2 Aug 2025 10:00 GMT";
constexpr char kDueDate[] = "2 Aug 2025 10:00 GMT";
}
namespace ash {
class GlanceablesPixelTest : public AshTestBase {
class GlanceablesTasksPixelTest : public AshTestBase {
public:
GlanceablesPixelTest() {
GlanceablesTasksPixelTest() {
time_override_ = std::make_unique<base::subtle::ScopedTimeClockOverrides>(
[]() {
base::Time date;
@ -46,7 +49,7 @@ class GlanceablesPixelTest : public AshTestBase {
SimulateUserLogin(account_id_);
base::Time date;
ASSERT_TRUE(base::Time::FromString(due_date, &date));
ASSERT_TRUE(base::Time::FromString(kDueDate, &date));
fake_glanceables_tasks_client_ =
glanceables_tasks_test_util::InitializeFakeTasksClient(date);
Shell::Get()->glanceables_controller()->UpdateClientsRegistration(
@ -71,25 +74,113 @@ class GlanceablesPixelTest : public AshTestBase {
return GetPrimaryShelf()->GetStatusAreaWidget()->date_tray();
}
void OpenGlanceables() { LeftClickOn(GetDateTray()); }
void ToggleGlanceables() { LeftClickOn(GetDateTray()); }
protected:
const AccountId account_id_ =
AccountId::FromUserEmailGaiaId("test_user@gmail.com", "123456");
std::unique_ptr<api::FakeTasksClient> fake_glanceables_tasks_client_;
private:
base::test::ScopedFeatureList features_{
ash::features::kGlanceablesTimeManagementTasksView};
std::unique_ptr<base::subtle::ScopedTimeClockOverrides> time_override_;
AccountId account_id_ =
AccountId::FromUserEmailGaiaId("test_user@gmail.com", "123456");
std::unique_ptr<api::FakeTasksClient> fake_glanceables_tasks_client_;
};
// Pixel test for default / basic glanceables functionality.
TEST_F(GlanceablesPixelTest, Smoke) {
TEST_F(GlanceablesTasksPixelTest, Smoke) {
ASSERT_FALSE(GetDateTray()->is_active());
OpenGlanceables();
ToggleGlanceables();
ASSERT_TRUE(GetDateTray()->is_active());
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"glanceables_smoke", /*revision_number=*/4,
"glanceables_smoke", /*revision_number=*/0,
GetDateTray()->glanceables_bubble_for_test()->GetBubbleView()));
}
class GlanceablesTimeManagementPixelTest : public GlanceablesTasksPixelTest {
public:
GlanceablesTimeManagementPixelTest() {
features_.InitWithFeatures(
/*enabled_features=*/
{features::kGlanceablesTimeManagementTasksView,
features::kGlanceablesTimeManagementClassroomStudentView},
/*disabled_features=*/{});
}
// AshTestBase:
void SetUp() override {
GlanceablesTasksPixelTest::SetUp();
base::Time date;
ASSERT_TRUE(base::Time::FromString(kDueDate, &date));
// tasks client was initialized in GlanceablesTasksPixelTest.
classroom_client_ = std::make_unique<FakeGlanceablesClassroomClient>();
Shell::Get()->glanceables_controller()->UpdateClientsRegistration(
account_id_, GlanceablesController::ClientsRegistration{
.classroom_client = classroom_client_.get(),
.tasks_client = fake_glanceables_tasks_client_.get()});
ASSERT_TRUE(Shell::Get()->glanceables_controller()->GetClassroomClient());
ASSERT_TRUE(Shell::Get()->glanceables_controller()->GetTasksClient());
GetDateTray()->ShowGlanceableBubble(/*from_keyboard=*/false);
view_ = views::AsViewClass<GlanceableTrayBubbleView>(
GetDateTray()->glanceables_bubble_for_test()->GetBubbleView());
}
void TearDown() override {
GetDateTray()->HideGlanceableBubble();
view_ = nullptr;
GlanceablesTasksPixelTest::TearDown();
}
GlanceablesTasksView* GetTasksView() const {
return views::AsViewClass<GlanceablesTasksView>(view_->GetTasksView());
}
views::ScrollView* GetTasksScrollView() const {
return views::AsViewClass<views::ScrollView>(GetTasksView()->GetViewByID(
base::to_underlying(GlanceablesViewId::kContentsScrollView)));
}
GlanceablesClassroomStudentView* GetClassroomView() const {
return views::AsViewClass<GlanceablesClassroomStudentView>(
view_->GetClassroomStudentView());
}
views::ScrollView* GetClassroomScrollView() const {
return views::AsViewClass<views::ScrollView>(
GetClassroomView()->GetViewByID(
base::to_underlying(GlanceablesViewId::kContentsScrollView)));
}
private:
base::test::ScopedFeatureList features_;
std::unique_ptr<FakeGlanceablesClassroomClient> classroom_client_;
raw_ptr<GlanceableTrayBubbleView> view_ = nullptr;
};
// Pixel test for default / basic glanceables functionality.
TEST_F(GlanceablesTimeManagementPixelTest, Smoke) {
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"expanded_tasks_top", /*revision_number=*/0,
GetDateTray()->glanceables_bubble_for_test()->GetBubbleView()));
GetTasksScrollView()->ScrollToPosition(
GetTasksScrollView()->vertical_scroll_bar(), INT_MAX);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"expanded_tasks_bottom", /*revision_number=*/0,
GetDateTray()->glanceables_bubble_for_test()->GetBubbleView()));
GetClassroomView()->SetExpandState(true);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"expanded_classroom_top", /*revision_number=*/0,
GetDateTray()->glanceables_bubble_for_test()->GetBubbleView()));
GetClassroomScrollView()->ScrollToPosition(
GetClassroomScrollView()->vertical_scroll_bar(), INT_MAX);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"expanded_classroom_bottom", /*revision_number=*/0,
GetDateTray()->glanceables_bubble_for_test()->GetBubbleView()));
}