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
ash / ambient / model / ambient_topic_queue_animation_delegate_unittest.cc [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/ambient/model/ambient_topic_queue_animation_delegate.h"
#include <optional>
#include <string_view>
#include <utility>
#include "ash/ambient/test/ambient_test_util.h"
#include "base/check.h"
#include "base/numerics/safe_conversions.h"
#include "cc/paint/skottie_resource_metadata.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
namespace ash {
namespace {
using ::testing::UnorderedElementsAre;
} // namespace
class AmbientTopicQueueAnimationDelegateTest : public ::testing::Test {
protected:
void RegisterAsset(std::string_view resource_id,
std::optional<gfx::Size> size) {
CHECK(resource_metadata_.RegisterAsset("test-path", "test-name",
resource_id, std::move(size)))
<< "Asset " << resource_id << " already registered";
}
cc::SkottieResourceMetadataMap resource_metadata_;
};
TEST_F(AmbientTopicQueueAnimationDelegateTest,
GetTopicSizesWithPortraitAndLandscape) {
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"A", /*idx=*/1),
gfx::Size(100, 50));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"B", /*idx=*/1),
gfx::Size(120, 40));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"C", /*idx=*/1),
gfx::Size(50, 100));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"D", /*idx=*/1),
gfx::Size(60, 80));
AmbientTopicQueueAnimationDelegate delegate(resource_metadata_);
EXPECT_THAT(
delegate.GetTopicSizes(),
UnorderedElementsAre(gfx::Size(125, 50),
gfx::Size(base::ClampRound<int>(62.5), 100)));
}
TEST_F(AmbientTopicQueueAnimationDelegateTest, GetTopicSizesWithOnlyPortrait) {
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"A", /*idx=*/1),
gfx::Size(60, 100));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"B", /*idx=*/1),
gfx::Size(100, 125));
AmbientTopicQueueAnimationDelegate delegate(resource_metadata_);
EXPECT_THAT(
delegate.GetTopicSizes(),
UnorderedElementsAre(gfx::Size(100, base::ClampRound<int>(100 / .7f))));
}
TEST_F(AmbientTopicQueueAnimationDelegateTest, GetTopicSizesWithOnlyLandscape) {
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"A", /*idx=*/1),
gfx::Size(200, 100));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"B", /*idx=*/1),
gfx::Size(120, 40));
AmbientTopicQueueAnimationDelegate delegate(resource_metadata_);
EXPECT_THAT(delegate.GetTopicSizes(),
UnorderedElementsAre(gfx::Size(250, 100)));
}
TEST_F(AmbientTopicQueueAnimationDelegateTest, GetTopicSizesWithSquare) {
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"A", /*idx=*/1),
gfx::Size(200, 100));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"B", /*idx=*/1),
gfx::Size(120, 40));
// Should be ignored when calculating the average aspect ratio.
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"C", /*idx=*/1),
gfx::Size(300, 300));
AmbientTopicQueueAnimationDelegate delegate(resource_metadata_);
EXPECT_THAT(delegate.GetTopicSizes(),
UnorderedElementsAre(gfx::Size(750, 300)));
}
TEST_F(AmbientTopicQueueAnimationDelegateTest, GetTopicSizesWithOnlySquare) {
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"A", /*idx=*/1),
gfx::Size(200, 200));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"B", /*idx=*/1),
gfx::Size(100, 100));
AmbientTopicQueueAnimationDelegate delegate(resource_metadata_);
EXPECT_THAT(delegate.GetTopicSizes(),
UnorderedElementsAre(gfx::Size(200, 200)));
}
TEST_F(AmbientTopicQueueAnimationDelegateTest, HandlesMissingAssetSize) {
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"A", /*idx=*/1),
gfx::Size(200, 100));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"B", /*idx=*/1),
gfx::Size(120, 40));
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"C", /*idx=*/1),
std::nullopt);
AmbientTopicQueueAnimationDelegate delegate(resource_metadata_);
EXPECT_THAT(delegate.GetTopicSizes(),
UnorderedElementsAre(gfx::Size(250, 100)));
}
TEST_F(AmbientTopicQueueAnimationDelegateTest, FiltersOutStaticImageAssets) {
RegisterAsset(
GenerateLottieDynamicAssetIdForTesting(/*position=*/"A", /*idx=*/1),
gfx::Size(200, 100));
RegisterAsset("static-image-asset-id", gfx::Size(120, 40));
AmbientTopicQueueAnimationDelegate delegate(resource_metadata_);
EXPECT_THAT(delegate.GetTopicSizes(),
UnorderedElementsAre(gfx::Size(200, 100)));
}
} // namespace ash