Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: content/common/background_fetch/background_fetch_struct_traits_unittest.cc

Issue 2762573003: Implement BackgroundFetchManager.fetch() and struct traits (Closed)
Patch Set: First round of comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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
5 #include "content/common/background_fetch/background_fetch_struct_traits.h"
6
7 #include <utility>
8
9 #include "content/common/background_fetch/background_fetch_types.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace content {
13
14 namespace {
15
16 // Creates a new IconDefinition object for the given arguments.
17 IconDefinition CreateIconDefinition(std::string src,
18 std::string sizes,
19 std::string type) {
20 IconDefinition definition;
21 definition.src = std::move(src);
22 definition.sizes = std::move(sizes);
23 definition.type = std::move(type);
24
25 return definition;
26 }
27
28 // Returns whether the given IconDefinition objects are identical.
29 bool IconDefinitionsAreIdentical(const IconDefinition& left,
30 const IconDefinition& right) {
31 return left.src == right.src && left.sizes == right.sizes &&
32 left.type == right.type;
33 }
34
35 } // namespace
36
37 TEST(BackgroundFetchStructTraitsTest, BackgroundFetchOptionsRoundtrip) {
38 BackgroundFetchOptions options;
39 options.icons = {
40 CreateIconDefinition("my_icon.png", "256x256", "image/png"),
41 CreateIconDefinition("my_small_icon.jpg", "128x128", "image/jpg")};
42 options.title = "My Background Fetch";
43 options.total_download_size = 9001;
44
45 BackgroundFetchOptions roundtrip_options;
46 ASSERT_TRUE(blink::mojom::BackgroundFetchOptions::Deserialize(
47 blink::mojom::BackgroundFetchOptions::Serialize(&options),
48 &roundtrip_options));
49
50 ASSERT_EQ(roundtrip_options.icons.size(), options.icons.size());
51 for (size_t i = 0; i < options.icons.size(); ++i) {
52 EXPECT_TRUE(IconDefinitionsAreIdentical(options.icons[i],
53 roundtrip_options.icons[i]));
54 }
55
56 EXPECT_EQ(roundtrip_options.title, options.title);
57 EXPECT_EQ(roundtrip_options.total_download_size, options.total_download_size);
58 }
59
60 TEST(BackgroundFetchStructTraitsTest, BackgroundFetchRegistrationRoundTrip) {
61 BackgroundFetchRegistration registration;
62 registration.tag = "my_tag";
63 registration.icons = {
64 CreateIconDefinition("my_icon.png", "256x256", "image/png"),
65 CreateIconDefinition("my_small_icon.jpg", "128x128", "image/jpg")};
66 registration.title = "My Background Fetch";
67 registration.total_download_size = 9001;
68
69 BackgroundFetchRegistration roundtrip_registration;
70 ASSERT_TRUE(blink::mojom::BackgroundFetchRegistration::Deserialize(
71 blink::mojom::BackgroundFetchRegistration::Serialize(&registration),
72 &roundtrip_registration));
73
74 EXPECT_EQ(roundtrip_registration.tag, registration.tag);
75
76 ASSERT_EQ(roundtrip_registration.icons.size(), registration.icons.size());
77 for (size_t i = 0; i < registration.icons.size(); ++i) {
78 EXPECT_TRUE(IconDefinitionsAreIdentical(registration.icons[i],
79 roundtrip_registration.icons[i]));
80 }
81
82 EXPECT_EQ(roundtrip_registration.title, registration.title);
83 EXPECT_EQ(roundtrip_registration.total_download_size,
84 registration.total_download_size);
85 }
86
87 TEST(BackgroundFetchStructTraitsTest, IconDefinitionRoundtrip) {
88 IconDefinition definition =
89 CreateIconDefinition("my_icon.png", "256x256", "image/png");
90
91 IconDefinition roundtrip_definition;
92 ASSERT_TRUE(blink::mojom::IconDefinition::Deserialize(
93 blink::mojom::IconDefinition::Serialize(&definition),
94 &roundtrip_definition));
95
96 EXPECT_TRUE(IconDefinitionsAreIdentical(definition, roundtrip_definition));
97 }
98
99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698