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
cc / paint / skottie_resource_metadata_unittest.cc [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/paint/skottie_resource_metadata.h"
#include "base/files/file_path.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
namespace cc {
namespace {
using ::testing::AllOf;
using ::testing::Eq;
using ::testing::FieldsAre;
using ::testing::Ne;
using ::testing::Optional;
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
TEST(SkottieResourceMetadataTest, SkottieResourceMetadataMapRegistersAssets) {
SkottieResourceMetadataMap resource_map;
ASSERT_TRUE(
resource_map.RegisterAsset("test-resource-path-1", "test-resource-name-1",
"test-resource-id-1", gfx::Size(100, 100)));
ASSERT_TRUE(resource_map.RegisterAsset("test-resource-path-2",
"test-resource-name-2",
"test-resource-id-2", std::nullopt));
EXPECT_THAT(
resource_map.asset_storage(),
UnorderedElementsAre(
Pair("test-resource-id-1",
FieldsAre(base::FilePath(
FILE_PATH_LITERAL(
"test-resource-path-1/test-resource-name-1"))
.NormalizePathSeparators(),
Optional(gfx::Size(100, 100)))),
Pair("test-resource-id-2",
FieldsAre(base::FilePath(
FILE_PATH_LITERAL(
"test-resource-path-2/test-resource-name-2"))
.NormalizePathSeparators(),
Eq(std::nullopt)))));
}
TEST(SkottieResourceMetadataTest,
SkottieResourceMetadataMapRejectsDuplicateAssets) {
SkottieResourceMetadataMap resource_map;
ASSERT_TRUE(resource_map.RegisterAsset("test-resource-path-1",
"test-resource-name-1",
"test-resource-id-1", std::nullopt));
EXPECT_FALSE(resource_map.RegisterAsset("test-resource-path-2",
"test-resource-name-2",
"test-resource-id-1", std::nullopt));
}
TEST(SkottieResourceMetadataTest,
SkottieResourceMetadataMapRejectsEmptyAssets) {
SkottieResourceMetadataMap resource_map;
EXPECT_FALSE(resource_map.RegisterAsset("test-resource-path",
"test-resource-name",
/*resource_id=*/"", std::nullopt));
}
TEST(SkottieResourceMetadataTest,
SkottieResourceMetadataMapRejectsAbsoluteResourceNames) {
SkottieResourceMetadataMap resource_map;
EXPECT_FALSE(resource_map.RegisterAsset("test-resource-path",
"/absolute-resource-name",
/*resource_id=*/"", std::nullopt));
}
TEST(SkottieResourceMetadataTest, HashSkottieResourceIdReturnsMatchingHashes) {
EXPECT_THAT(HashSkottieResourceId("test-resource-id-1"),
Eq(HashSkottieResourceId("test-resource-id-1")));
}
TEST(SkottieResourceMetadataTest, HashSkottieResourceIdReturnsDifferentHashes) {
EXPECT_THAT(HashSkottieResourceId("test-resource-id-1"),
Ne(HashSkottieResourceId("test-resource-id-2")));
}
} // namespace
} // namespace cc