1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- // Copyright 2022 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "ash/test/ash_pixel_diff_test_helper.h"
- #include "ash/root_window_controller.h"
- #include "ash/shelf/shelf.h"
- #include "ash/shell.h"
- namespace ash {
- namespace {
- Shelf* GetPrimaryShelf() {
- return Shell::GetPrimaryRootWindowController()->shelf();
- }
- gfx::Rect GetShelfWidgetScreenBounds() {
- return GetPrimaryShelf()->GetWindow()->GetBoundsInScreen();
- }
- } // namespace
- AshPixelDiffTestHelper::AshPixelDiffTestHelper() = default;
- AshPixelDiffTestHelper::~AshPixelDiffTestHelper() = default;
- bool AshPixelDiffTestHelper::ComparePrimaryFullScreen(
- const std::string& screenshot_name) {
- aura::Window* primary_root_window = Shell::Get()->GetPrimaryRootWindow();
- return ComparePrimaryScreenshotWithBoundsInScreen(
- screenshot_name, primary_root_window->bounds());
- }
- bool AshPixelDiffTestHelper::CompareUiComponentScreenshot(
- const std::string& screenshot_name,
- UiComponent ui_component) {
- return ComparePrimaryScreenshotWithBoundsInScreen(
- screenshot_name, GetUiComponentBoundsInScreen(ui_component));
- }
- bool AshPixelDiffTestHelper::ComparePrimaryScreenshotWithBoundsInScreen(
- const std::string& screenshot_name,
- const gfx::Rect& screen_bounds) {
- aura::Window* primary_root_window = Shell::Get()->GetPrimaryRootWindow();
- return pixel_diff_.CompareNativeWindowScreenshot(
- screenshot_name, primary_root_window, screen_bounds);
- }
- void AshPixelDiffTestHelper::InitSkiaGoldPixelDiff(
- const std::string& screenshot_prefix,
- const std::string& corpus) {
- pixel_diff_.Init(screenshot_prefix, corpus);
- }
- gfx::Rect AshPixelDiffTestHelper::GetUiComponentBoundsInScreen(
- UiComponent ui_component) const {
- switch (ui_component) {
- case UiComponent::kShelfWidget:
- return GetShelfWidgetScreenBounds();
- }
- }
- } // namespace ash
|