0

[Pixel Diff Ash] Refactor the signature of the image comp API

Currently, the pixel test developers are expected to include the
revision number in the screenshot name with the form such
as "rev_0". However, developers are easy to forget this rule.

To solve this problem, this CL adds an additional parameter called
`revision_number` to the function
`CompareUiComponentsOnPrimaryScreen()`. A developer has to specify
the revision number in the test code.

The function definition guarantees to use the revision number
specified by the parameter and generate the same image name with
the current one. This CL should not bring any noticeable UI changes.

Change-Id: Ibef85e87f1ae2410abe7364eea974af4ddded71f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4195894
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1097501}
This commit is contained in:
andrewxu
2023-01-26 18:23:39 +00:00
committed by Chromium LUCI CQ
parent 9eedd0cced
commit df34418647
17 changed files with 120 additions and 77 deletions

@ -44,6 +44,6 @@ TEST_F(AmbientInfoViewTest, ShowAmbientInfoView) {
FastForwardToRefreshWeather();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"ambient_info_view.rev_0", GetAmbientInfoView()));
"ambient_info_view", /*revision_number=*/0, GetAmbientInfoView()));
}
} // namespace ash

@ -51,7 +51,8 @@ TEST_F(MediaStringViewTest, ShowMediaStringViewWithShortText) {
}
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"media_string_view_with_short_text.rev_0", GetMediaStringView()));
"media_string_view_with_short_text", /*revision_number=*/0,
GetMediaStringView()));
}
TEST_F(MediaStringViewTest, ShowMediaStringViewWithShortTextDarkMode) {
@ -72,8 +73,8 @@ TEST_F(MediaStringViewTest, ShowMediaStringViewWithShortTextDarkMode) {
}
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"media_string_view_with_short_text_dark_mode.rev_0",
GetMediaStringView()));
"media_string_view_with_short_text_dark_mode",
/*revision_number=*/0, GetMediaStringView()));
}
TEST_F(MediaStringViewTest, ShowMediaStringViewWithLongText) {
@ -96,6 +97,7 @@ TEST_F(MediaStringViewTest, ShowMediaStringViewWithLongText) {
}
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"media_string_view_with_long_text.rev_1", GetMediaStringView()));
"media_string_view_with_long_text", /*revision_number=*/1,
GetMediaStringView()));
}
} // namespace ash

@ -97,8 +97,9 @@ class AppListItemViewPixelTest : public AshTestBase,
AppListItemView* GetItemViewAt(size_t index) {
auto* const helper = GetAppListTestHelper();
if (use_tablet_mode())
if (use_tablet_mode()) {
return helper->GetRootPagedAppsGridView()->GetItemViewAt(index);
}
return helper->GetScrollableAppsGridView()->GetItemViewAt(index);
}
@ -110,8 +111,7 @@ class AppListItemViewPixelTest : public AshTestBase,
has_notification() ? "has_notification=true"
: "has_notification=false"},
"|");
return base::JoinString({"app_list_item_view", stringified_params, "rev_0"},
".");
return base::JoinString({"app_list_item_view", stringified_params}, ".");
}
bool use_tablet_mode() const { return std::get<0>(GetParam()); }
@ -141,7 +141,8 @@ TEST_P(AppListItemViewPixelTest, AppListItemView) {
ShowAppList();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
GenerateScreenshotName(), GetItemViewAt(0), GetItemViewAt(1)));
GenerateScreenshotName(), /*revision_number=*/0, GetItemViewAt(0),
GetItemViewAt(1)));
}
// Verifies the layout of the item icons inside a folder.
@ -158,8 +159,8 @@ TEST_P(AppListItemViewPixelTest, AppListFolderItemsLayoutInIcon) {
ShowAppList();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
GenerateScreenshotName(), GetItemViewAt(0), GetItemViewAt(1),
GetItemViewAt(2), GetItemViewAt(3)));
GenerateScreenshotName(), /*revision_number=*/0, GetItemViewAt(0),
GetItemViewAt(1), GetItemViewAt(2), GetItemViewAt(3)));
}
// Verifies the folder icon is extended when an app is dragged upon it.
@ -189,8 +190,8 @@ TEST_P(AppListItemViewPixelTest, AppListFolderIconExtendedState) {
}
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
GenerateScreenshotName(), GetItemViewAt(0), GetItemViewAt(1),
GetItemViewAt(2), GetItemViewAt(3)));
GenerateScreenshotName(), /*revision_number=*/0, GetItemViewAt(0),
GetItemViewAt(1), GetItemViewAt(2), GetItemViewAt(3)));
// Reset the states.
for (int i = 0; i < max_items_in_folder; ++i) {
@ -239,6 +240,7 @@ TEST_P(AppListItemViewPixelTest, DraggedAppListFolderIcon) {
std::string filename = base::NumberToString(i + 1) + "_items_folder";
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
base::JoinString({GenerateScreenshotName(), filename}, "."),
/*revision_number=*/0,
apps_grid_view->app_drag_icon_proxy_for_test()->GetWidgetForTesting()));
// Release the drag.

@ -122,8 +122,8 @@ TEST_P(AppListViewPixelRTLTest, AnswerCardSearchResult) {
HideCursor();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"bubble_launcher_answer_card_search_results.rev_0",
GetAppListTestHelper()->GetBubbleView(),
"bubble_launcher_answer_card_search_results",
/*revision_number=*/0, GetAppListTestHelper()->GetBubbleView(),
GetPrimaryShelf()->navigation_widget()));
}
@ -144,8 +144,8 @@ TEST_P(AppListViewPixelRTLTest, URLSearchResult) {
HideCursor();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"bubble_launcher_url_search_results.rev_0",
GetAppListTestHelper()->GetBubbleView(),
"bubble_launcher_url_search_results",
/*revision_number=*/0, GetAppListTestHelper()->GetBubbleView(),
GetPrimaryShelf()->navigation_widget()));
}
@ -157,7 +157,8 @@ TEST_P(AppListViewPixelRTLTest, Basics) {
ShowAppList();
HideCursor();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"bubble_launcher_basics.rev_0", GetAppListTestHelper()->GetBubbleView(),
"bubble_launcher_basics",
/*revision_number=*/0, GetAppListTestHelper()->GetBubbleView(),
GetPrimaryShelf()->navigation_widget()));
}
@ -177,8 +178,8 @@ TEST_P(AppListViewPixelRTLTest, GradientZone) {
/*position=*/20);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"bubble_launcher_gradient_zone.rev_0",
GetAppListTestHelper()->GetBubbleView(),
"bubble_launcher_gradient_zone",
/*revision_number=*/0, GetAppListTestHelper()->GetBubbleView(),
GetPrimaryShelf()->navigation_widget()));
}
@ -212,8 +213,8 @@ INSTANTIATE_TEST_SUITE_P(RTL, AppListViewTabletPixelTest, testing::Bool());
// Verifies the default layout for tablet mode launcher.
TEST_P(AppListViewTabletPixelTest, Basic) {
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"tablet_launcher_basics.rev_0",
GetAppListTestHelper()->GetAppsContainerView()));
"tablet_launcher_basics",
/*revision_number=*/0, GetAppListTestHelper()->GetAppsContainerView()));
}
// Verifies that the top gradient zone of the tablet mode launcher works
@ -233,8 +234,8 @@ TEST_P(AppListViewTabletPixelTest, TopGradientZone) {
generator->MoveTouchBy(0, -40);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"tablet_launcher_top_gradient_zone.rev_0",
GetAppListTestHelper()->GetAppsContainerView()));
"tablet_launcher_top_gradient_zone",
/*revision_number=*/0, GetAppListTestHelper()->GetAppsContainerView()));
}
// Verifies that the bottom gradient zone of the tablet mode launcher works
@ -254,8 +255,8 @@ TEST_P(AppListViewTabletPixelTest, BottomGradientZone) {
generator->MoveTouchBy(0, -90);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"tablet_launcher_bottom_gradient_zone.rev_0",
GetAppListTestHelper()->GetAppsContainerView()));
"tablet_launcher_bottom_gradient_zone",
/*revision_number=*/0, GetAppListTestHelper()->GetAppsContainerView()));
}
} // namespace ash

@ -21,7 +21,7 @@ class FullscreenPixelTest : public AshTestBase {
// Verifies the primary fullscreen of an active user session.
TEST_F(FullscreenPixelTest, VerifyDefaultPrimaryDisplay) {
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"primary_display.rev_0", Shell::GetPrimaryRootWindow()));
"primary_display", /*revision_number=*/0, Shell::GetPrimaryRootWindow()));
}
} // namespace ash

@ -61,26 +61,26 @@ TEST_F(LoginShelfViewPixelTest, FocusTraversalFromLockContents) {
aura::Window* primary_shelf_window = GetPrimaryShelf()->GetWindow();
PressAndReleaseKey(ui::VKEY_TAB);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"focus_on_login_user_expand_button.rev_0", primary_big_user_view_,
primary_shelf_window));
"focus_on_login_user_expand_button",
/*revision_number=*/0, primary_big_user_view_, primary_shelf_window));
// Trigger the tab key. Check that the login shelf shutdown button is focused.
PressAndReleaseKey(ui::VKEY_TAB);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"focus_on_shutdown_button.rev_0", primary_big_user_view_,
primary_shelf_window));
"focus_on_shutdown_button",
/*revision_number=*/0, primary_big_user_view_, primary_shelf_window));
// Trigger the tab key. Check that the browser as guest button is focused.
PressAndReleaseKey(ui::VKEY_TAB);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"focus_on_browser_as_guest_button.rev_0", primary_big_user_view_,
primary_shelf_window));
"focus_on_browser_as_guest_button",
/*revision_number=*/0, primary_big_user_view_, primary_shelf_window));
// Trigger the tab key. Check that the add person button is focused.
PressAndReleaseKey(ui::VKEY_TAB);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"focus_on_add_person_button.rev_0", primary_big_user_view_,
primary_shelf_window));
"focus_on_add_person_button",
/*revision_number=*/0, primary_big_user_view_, primary_shelf_window));
}
// Used to verify the login shelf features with a policy wallpaper.
@ -93,19 +93,22 @@ TEST_F(LoginShelfViewPixelTest, FocusTraversalWithinShelf) {
aura::Window* primary_shelf_window = GetPrimaryShelf()->GetWindow();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"focus_on_calendar_view.rev_0", primary_shelf_window));
"focus_on_calendar_view",
/*revision_number=*/0, primary_shelf_window));
// Focus on the time view.
PressAndReleaseKey(ui::VKEY_TAB);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"focus_on_time_view.rev_0", primary_shelf_window));
"focus_on_time_view.rev_0",
/*revision_number=*/0, primary_shelf_window));
PressAndReleaseKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN);
PressAndReleaseKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN);
// Move the focus back to the add person button.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"refocus_on_login_shelf.rev_0", primary_shelf_window));
"refocus_on_login_shelf",
/*revision_number=*/0, primary_shelf_window));
}
class LoginShelfWithPolicyWallpaperPixelTestWithRTL
@ -131,7 +134,8 @@ INSTANTIATE_TEST_SUITE_P(RTL,
TEST_P(LoginShelfWithPolicyWallpaperPixelTestWithRTL, FocusOnShutdownButton) {
FocusOnShutdownButton();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"focus_on_shutdown_button.rev_0", primary_big_user_view_,
"focus_on_shutdown_button",
/*revision_number=*/0, primary_big_user_view_,
GetPrimaryShelf()->GetWindow()));
}

@ -40,7 +40,8 @@ INSTANTIATE_TEST_SUITE_P(RTL, ScrollableShelfViewPixelRTLTest, testing::Bool());
// Verifies the scrollable shelf under overflow.
TEST_P(ScrollableShelfViewPixelRTLTest, Basics) {
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"overflow.rev_0", GetPrimaryShelf()->GetWindow()));
"overflow",
/*revision_number=*/0, GetPrimaryShelf()->GetWindow()));
ASSERT_TRUE(scrollable_shelf_view_->right_arrow());
const gfx::Point right_arrow_center =
@ -50,17 +51,20 @@ TEST_P(ScrollableShelfViewPixelRTLTest, Basics) {
GetEventGenerator()->ClickLeftButton();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"overflow_end.rev_0", GetPrimaryShelf()->GetWindow()));
"overflow_end",
/*revision_number=*/0, GetPrimaryShelf()->GetWindow()));
}
TEST_P(ScrollableShelfViewPixelRTLTest, LeftRightShelfAlignment) {
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kLeft);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"left_shelf_alignment.rev_0", GetPrimaryShelf()->GetWindow()));
"left_shelf_alignment",
/*revision_number=*/0, GetPrimaryShelf()->GetWindow()));
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kRight);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"right_shelf_alignment.rev_0", GetPrimaryShelf()->GetWindow()));
"right_shelf_alignment",
/*revision_number=*/0, GetPrimaryShelf()->GetWindow()));
}
class ScrollableShelfViewWithGuestModePixelTest
@ -99,7 +103,8 @@ TEST_P(ScrollableShelfViewWithGuestModePixelTest, VerifyShelfContextMenu) {
// Verify the shelf context menu and the shelf.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"shelf_context_menu.rev_0",
"shelf_context_menu",
/*revision_number=*/0,
GetPrimaryShelf()
->shelf_widget()
->shelf_view_for_testing()

@ -48,13 +48,15 @@ TEST_P(ShelfLayoutManagerPixelRTLTest, AutohideShelfVisibility) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"shelf_no_auto_hide.rev_0", shelf->GetWindow(), shelf->hotseat_widget()));
"shelf_no_auto_hide",
/*revision_number=*/0, shelf->GetWindow(), shelf->hotseat_widget()));
// When the auto-hide is set and a window is shown fullscreen, the shelf
// should not be showing on the screen.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"shelf_auto_hide.rev_0", shelf->GetWindow(), shelf->hotseat_widget()));
"shelf_auto_hide",
/*revision_number=*/0, shelf->GetWindow(), shelf->hotseat_widget()));
// Show the shelf in auto-hide mode.
if (is_tablet_mode)
@ -63,8 +65,8 @@ TEST_P(ShelfLayoutManagerPixelRTLTest, AutohideShelfVisibility) {
MoveMouseToShowAutoHiddenShelf();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"shelf_show_with_auto_hide.rev_0", shelf->GetWindow(),
shelf->hotseat_widget()));
"shelf_show_with_auto_hide",
/*revision_number=*/0, shelf->GetWindow(), shelf->hotseat_widget()));
}
} // namespace ash

@ -35,7 +35,8 @@ TEST_F(AccessibilityDetailedViewPixelTest, Basics) {
ASSERT_TRUE(detailed_view);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"accessibility_detailed_view.rev_0", detailed_view));
"accessibility_detailed_view",
/*revision_number=*/0, detailed_view));
}
} // namespace ash

@ -91,7 +91,8 @@ TEST_F(BluetoothDetailedViewLegacyPixelTest, Basics) {
// Compare pixels.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"bluetooth_detailed_view_legacy.rev_0", detailed_view));
"bluetooth_detailed_view_legacy",
/*revision_number=*/0, detailed_view));
}
} // namespace ash

@ -110,7 +110,8 @@ TEST_P(ChannelIndicatorQuickSettingsViewPixelTest, FeedbackButtonVisible) {
// Don't capture any part of the UI except for
// `ChannelIndicatorQuickSettingsView`.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"feedback_button_visible.rev_0", view()));
"feedback_button_visible",
/*revision_number=*/0, view()));
}
} // namespace ash

@ -22,11 +22,10 @@ constexpr char kLongTitleString[] =
"Very Very Very Very Very Very Very Very Very Very Very Very Very Very "
"Very Very Very Very Long Multiline Title";
constexpr char kShortTitleScreenshot[] = "ash_notification_short_title.rev_1";
constexpr char kShortTitleScreenshot[] = "ash_notification_short_title";
constexpr char kMediumTitleScreenshot[] =
"ash_notification_multiline_medium_title.rev_1";
constexpr char kLongTitleScreenshot[] =
"ash_notification_multiline_long_title.rev_1";
"ash_notification_multiline_medium_title";
constexpr char kLongTitleScreenshot[] = "ash_notification_multiline_long_title";
} // namespace
@ -91,7 +90,7 @@ TEST_P(AshNotificationViewTitlePixelTest, NotificationTitleTest) {
// Compare pixels.
const std::string screenshot = GetParam().second;
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
screenshot, notification_view));
screenshot, /*revision_number=*/1, notification_view));
}
} // namespace ash

@ -124,7 +124,8 @@ TEST_F(CalendarUpNextViewPixelTest,
CreateCalendarUpNextView(std::move(events));
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"calendar_up_next_single_upcoming_event.rev_1", Widget()));
"calendar_up_next_single_upcoming_event",
/*revision_number=*/1, Widget()));
}
TEST_F(CalendarUpNextViewPixelTest,
@ -147,7 +148,8 @@ TEST_F(CalendarUpNextViewPixelTest,
CreateCalendarUpNextView(std::move(events));
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"calendar_up_next_multiple_upcoming_events.rev_1", Widget()));
"calendar_up_next_multiple_upcoming_events",
/*revision_number=*/1, Widget()));
}
TEST_F(
@ -174,9 +176,8 @@ TEST_F(
PressScrollRightButton();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"calendar_up_next_multiple_upcoming_events_press_scroll_right_button.rev_"
"0",
Widget()));
"calendar_up_next_multiple_upcoming_events_press_scroll_right_button",
/*revision_number=*/0, Widget()));
}
} // namespace ash

@ -4,8 +4,11 @@
#include "ash/test/pixel/ash_pixel_differ.h"
#include <string>
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "base/strings/strcat.h"
namespace ash {
@ -18,7 +21,12 @@ AshPixelDiffer::~AshPixelDiffer() = default;
bool AshPixelDiffer::ComparePrimaryScreenshotInRects(
const std::string& screenshot_name,
size_t revision_number,
const std::vector<gfx::Rect>& rects_in_screen) {
// Calculate the full image name incorporating `revision_number`.
const std::string full_name = base::StrCat(
{screenshot_name, ".rev_", base::NumberToString(revision_number)});
aura::Window* primary_root_window = Shell::Get()->GetPrimaryRootWindow();
const aura::WindowTreeHost* host = primary_root_window->GetHost();
@ -27,7 +35,7 @@ bool AshPixelDiffer::ComparePrimaryScreenshotInRects(
if (fabs(host->device_scale_factor() - 1.f) <
std::numeric_limits<float>::epsilon()) {
return pixel_diff_.CompareNativeWindowScreenshotInRects(
screenshot_name, primary_root_window, primary_root_window->bounds(),
full_name, primary_root_window, primary_root_window->bounds(),
/*algorithm=*/nullptr, rects_in_screen);
}
@ -44,7 +52,7 @@ bool AshPixelDiffer::ComparePrimaryScreenshotInRects(
}
return pixel_diff_.CompareNativeWindowScreenshotInRects(
screenshot_name, primary_root_window, primary_root_window->bounds(),
full_name, primary_root_window, primary_root_window->bounds(),
/*algorithm=*/nullptr, rects_in_pixel);
}

@ -24,33 +24,46 @@ class AshPixelDiffer {
AshPixelDiffer& operator=(const AshPixelDiffer&) = delete;
~AshPixelDiffer();
// Takes a full primary screenshot then compares it with the benchmark image
// specified by `screenshot_name`. Only the pixels within the screen bounds of
// `ui_components` affect the comparison result. Returns the comparison
// result. The function caller has the duty to choose suitable `ui_components`
// in their tests to avoid unnecessary pixel comparisons. Otherwise, pixel
// tests could be fragile to the changes in production code. `ui_components`
// is a variadic argument list, consisting of view pointers, widget pointers
// or window pointers. `ui_components` can have the pointers of different
// categories. Example usages:
// Takes a full screenshot of the primary display then compares it with the
// benchmark image specified by the function parameters. Only the pixels
// within the screen bounds of `ui_components` affect the comparison result.
// The pixels outside of `ui_components` are blacked out. Returns the
// comparison result. The function caller has the duty to choose suitable
// `ui_components` in their tests to avoid unnecessary pixel comparisons.
// Otherwise, pixel tests could be fragile to the changes in production code.
//
// `revision_number` indicates the benchmark image version. `revision_number`
// and `screenshot_name` collectively specify the benchmark image to compare
// with. The initial `revision_number` of a new benchmark image should be "0".
// If there is any code change that updates the benchmark, `revision_number`
// should increase by 1.
//
// `ui_components` is a variadic argument list, consisting of view pointers,
// widget pointers or window pointers. `ui_components` can have the pointers
// of different categories. Example usages:
//
// views::View* view_ptr = ...;
// views::Widget* widget_ptr = ...;
// aura::Window* window_ptr = ...;
//
// CompareUiComponentsOnPrimaryScreen("foo_name1", view_ptr);
// CompareUiComponentsOnPrimaryScreen("foo_name1",
// /*revision_number=*/0,
// view_ptr);
//
// CompareUiComponentsOnPrimaryScreen("foo_name2",
// *revision_number=*/0,
// view_ptr,
// widget_ptr,
// window_ptr);
template <class... UiComponentTypes>
bool CompareUiComponentsOnPrimaryScreen(const std::string& screenshot_name,
size_t revision_number,
UiComponentTypes... ui_components) {
DCHECK_GT(sizeof...(ui_components), 0u);
std::vector<gfx::Rect> rects_in_screen;
PopulateUiComponentScreenBounds(&rects_in_screen, ui_components...);
return ComparePrimaryScreenshotInRects(screenshot_name, rects_in_screen);
return ComparePrimaryScreenshotInRects(screenshot_name, revision_number,
rects_in_screen);
}
private:
@ -58,6 +71,7 @@ class AshPixelDiffer {
// image. Only the pixels in `rects_in_screen` affect the comparison result.
bool ComparePrimaryScreenshotInRects(
const std::string& screenshot_name,
size_t revision_number,
const std::vector<gfx::Rect>& rects_in_screen);
// Used to take screenshots and upload images to the Skia Gold server to

@ -68,7 +68,8 @@ TEST_F(DemoAshPixelDiffTest, VerifyTopLevelWidgets) {
SK_ColorYELLOW);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"check_widgets.rev_0", widget1.get(), widget2.get(), widget3.get(),
"check_widgets",
/*revision_number=*/0, widget1.get(), widget2.get(), widget3.get(),
widget4.get()));
}

@ -87,8 +87,9 @@ TEST_F(WmPixelDiffTest, OverviewAndDesksBarBasic) {
GetOverviewItemForWindow(window3.get())->item_widget();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"overview_and_desks_bar_basic.rev_0", desk_widget, overview_widget1,
overview_widget2, overview_widget3));
"overview_and_desks_bar_basic",
/*revision_number=*/0, desk_widget, overview_widget1, overview_widget2,
overview_widget3));
}
} // namespace ash