ash_pixel_diff_test_helper.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/test/ash_pixel_diff_test_helper.h"
  5. #include "ash/root_window_controller.h"
  6. #include "ash/shelf/shelf.h"
  7. #include "ash/shell.h"
  8. namespace ash {
  9. namespace {
  10. Shelf* GetPrimaryShelf() {
  11. return Shell::GetPrimaryRootWindowController()->shelf();
  12. }
  13. gfx::Rect GetShelfWidgetScreenBounds() {
  14. return GetPrimaryShelf()->GetWindow()->GetBoundsInScreen();
  15. }
  16. } // namespace
  17. AshPixelDiffTestHelper::AshPixelDiffTestHelper() = default;
  18. AshPixelDiffTestHelper::~AshPixelDiffTestHelper() = default;
  19. bool AshPixelDiffTestHelper::ComparePrimaryFullScreen(
  20. const std::string& screenshot_name) {
  21. aura::Window* primary_root_window = Shell::Get()->GetPrimaryRootWindow();
  22. return ComparePrimaryScreenshotWithBoundsInScreen(
  23. screenshot_name, primary_root_window->bounds());
  24. }
  25. bool AshPixelDiffTestHelper::CompareUiComponentScreenshot(
  26. const std::string& screenshot_name,
  27. UiComponent ui_component) {
  28. return ComparePrimaryScreenshotWithBoundsInScreen(
  29. screenshot_name, GetUiComponentBoundsInScreen(ui_component));
  30. }
  31. bool AshPixelDiffTestHelper::ComparePrimaryScreenshotWithBoundsInScreen(
  32. const std::string& screenshot_name,
  33. const gfx::Rect& screen_bounds) {
  34. aura::Window* primary_root_window = Shell::Get()->GetPrimaryRootWindow();
  35. return pixel_diff_.CompareNativeWindowScreenshot(
  36. screenshot_name, primary_root_window, screen_bounds);
  37. }
  38. void AshPixelDiffTestHelper::InitSkiaGoldPixelDiff(
  39. const std::string& screenshot_prefix,
  40. const std::string& corpus) {
  41. pixel_diff_.Init(screenshot_prefix, corpus);
  42. }
  43. gfx::Rect AshPixelDiffTestHelper::GetUiComponentBoundsInScreen(
  44. UiComponent ui_component) const {
  45. switch (ui_component) {
  46. case UiComponent::kShelfWidget:
  47. return GetShelfWidgetScreenBounds();
  48. }
  49. }
  50. } // namespace ash