File: ambient_slideshow_pixeltest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (143 lines) | stat: -rw-r--r-- 4,982 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <array>
#include <optional>
#include <tuple>

#include "ash/ambient/test/ambient_ash_test_base.h"
#include "ash/ambient/ui/media_string_view.h"
#include "ash/public/cpp/ambient/ambient_ui_model.h"
#include "ash/public/cpp/style/dark_light_mode_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/test/pixel/ash_pixel_differ.h"
#include "ash/webui/personalization_app/mojom/personalization_app.mojom-shared.h"
#include "base/strings/strcat.h"
#include "services/media_session/public/cpp/media_metadata.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/display/display.h"

namespace ash {

namespace {

using TestParams = std::tuple<std::optional<media_session::MediaMetadata>,
                              /*dark_mode=*/bool,
                              /*rtl=*/bool>;

std::array<std::optional<media_session::MediaMetadata>, 3>
GetMediaMedataVariations() {
  media_session::MediaMetadata short_metadata;
  short_metadata.artist = u"artist";
  short_metadata.title = u"title";

  media_session::MediaMetadata long_metadata;
  long_metadata.artist = u"A super duper long artist name";
  long_metadata.title = u"A super duper long title";

  return {std::move(short_metadata), std::move(long_metadata), std::nullopt};
}

bool IsDarkMode(const TestParams& param) {
  return std::get<1>(param);
}

bool IsRtl(const TestParams& param) {
  return std::get<2>(param);
}

const std::optional<media_session::MediaMetadata>& GetMediaMetadata(
    const TestParams& param) {
  return std::get<std::optional<media_session::MediaMetadata>>(param);
}

std::string GetName(const testing::TestParamInfo<TestParams>& param_info) {
  const std::optional<media_session::MediaMetadata>& metadata =
      GetMediaMetadata(param_info.param);
  std::string metadata_description_text;
  if (!metadata.has_value()) {
    metadata_description_text = "Nomedia";
  } else if (metadata->artist == u"artist") {
    metadata_description_text = "Shortmedia";
  } else {
    metadata_description_text = "Longmedia";
  }
  std::vector<std::string> attributes = {
      metadata_description_text,
      IsDarkMode(param_info.param) ? "Dark" : "Light",
      IsRtl(param_info.param) ? "Rtl" : "Ltr"};

  return base::StrCat(attributes);
}

}  // namespace

class AmbientSlideshowPixelTest
    : public AmbientAshTestBase,
      public testing::WithParamInterface<TestParams> {
 public:
  std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
      const override {
    pixel_test::InitParams pixel_test_init_params;
    pixel_test_init_params.under_rtl = IsRtl(GetParam());
    return pixel_test_init_params;
  }

  void SetUp() override {
    AmbientAshTestBase::SetUp();
    SetAmbientTheme(personalization_app::mojom::AmbientTheme::kSlideshow);
    GetSessionControllerClient()->set_show_lock_screen_views(true);
    DarkLightModeController::Get()->SetDarkModeEnabledForTest(
        IsDarkMode(GetParam()));
    // Required for decoded image parameters below to exactly reflect what the
    // ambient photo pipeline produces.
    UseLosslessPhotoCompression(true);
    SetNextDecodedPhotoColor(SK_ColorGREEN);
    gfx::Size display_size = GetPrimaryDisplay().size();
    // Simplifies rendering to be consistent for pixel testing.
    SetDecodedPhotoSize(display_size.width(), display_size.height());
    // Set a very long photo refresh interval so the view we are looking
    // at does not animate out while screen capturing. By default two photo
    // views animate in/out to transition between photos every 60 seconds.
    AmbientUiModel::Get()->SetPhotoRefreshInterval(base::Hours(1));
    // Stop the clock and media info from moving around.
    DisableJitter();
  }

  void TearDown() override {
    CloseAmbientScreen();
    AmbientAshTestBase::TearDown();
  }
};

INSTANTIATE_TEST_SUITE_P(
    All,
    AmbientSlideshowPixelTest,
    testing::Combine(::testing::ValuesIn(GetMediaMedataVariations()),
                     /*dark_mode=*/testing::Bool(),
                     /*rtl=*/testing::Bool()),
    &GetName);

TEST_P(AmbientSlideshowPixelTest, ShowMediaStringView) {
  SetAmbientShownAndWaitForWidgets();

  const std::optional<media_session::MediaMetadata>& media_metadata =
      GetMediaMetadata(GetParam());

  if (media_metadata.has_value()) {
    SimulateMediaMetadataChanged(media_metadata.value());
    SimulateMediaPlaybackStateChanged(
        media_session::mojom::MediaPlaybackState::kPlaying);
  }

  // https://crbug.com/346918516, increase revision number for slight
  // font rendering pixel changes when moving to Fontations.
  EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
      "AmbientSlideshow",
      /*revision_number=*/2, ash::Shell::GetPrimaryRootWindow()));
}

}  // namespace ash