Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "content/common/background_fetch/background_fetch_types.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace content { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 // Creates a new IconDefinition object for the given arguments. | |
| 15 IconDefinition CreateIconDefinition(std::string src, | |
|
dcheng
2017/03/21 07:03:20
FWIW, it's still more common to pass by ref and ju
Peter Beverloo
2017/03/21 13:46:27
That's good to know, thanks. I'll look at some dis
| |
| 16 std::string sizes, | |
| 17 std::string type) { | |
| 18 IconDefinition definition; | |
| 19 definition.src = std::move(src); | |
|
dcheng
2017/03/21 07:03:20
Nit: #include <utility>
Peter Beverloo
2017/03/21 13:46:27
Done.
| |
| 20 definition.sizes = std::move(sizes); | |
| 21 definition.type = std::move(type); | |
| 22 | |
| 23 return definition; | |
| 24 } | |
| 25 | |
| 26 // Returns whether the given IconDefinition objects are identical. | |
| 27 bool IconDefinitionsAreIdentical(const IconDefinition& left, | |
| 28 const IconDefinition& right) { | |
| 29 return left.src == right.src && left.sizes == right.sizes && | |
| 30 left.type == right.type; | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 TEST(BackgroundFetchStructTraitsTest, BackgroundFetchOptionsRoundtrip) { | |
| 36 BackgroundFetchOptions options; | |
| 37 options.icons = { | |
| 38 CreateIconDefinition("my_icon.png", "256x256", "image/png"), | |
| 39 CreateIconDefinition("my_small_icon.jpg", "128x128", "image/jpg")}; | |
| 40 options.title = "My Background Fetch"; | |
| 41 options.total_download_size = 9001; | |
| 42 | |
| 43 BackgroundFetchOptions roundtrip_options; | |
| 44 ASSERT_TRUE(blink::mojom::BackgroundFetchOptions::Deserialize( | |
| 45 blink::mojom::BackgroundFetchOptions::Serialize(&options), | |
| 46 &roundtrip_options)); | |
| 47 | |
| 48 ASSERT_EQ(roundtrip_options.icons.size(), options.icons.size()); | |
| 49 for (size_t i = 0; i < options.icons.size(); ++i) { | |
| 50 EXPECT_TRUE(IconDefinitionsAreIdentical(options.icons[i], | |
| 51 roundtrip_options.icons[i])); | |
| 52 } | |
| 53 | |
| 54 EXPECT_EQ(roundtrip_options.title, options.title); | |
| 55 EXPECT_EQ(roundtrip_options.total_download_size, options.total_download_size); | |
| 56 } | |
| 57 | |
| 58 TEST(BackgroundFetchStructTraitsTest, BackgroundFetchRegistrationRoundTrip) { | |
| 59 BackgroundFetchRegistration registration; | |
| 60 registration.tag = "my_tag"; | |
| 61 registration.icons = { | |
| 62 CreateIconDefinition("my_icon.png", "256x256", "image/png"), | |
| 63 CreateIconDefinition("my_small_icon.jpg", "128x128", "image/jpg")}; | |
| 64 registration.title = "My Background Fetch"; | |
| 65 registration.total_download_size = 9001; | |
| 66 | |
| 67 BackgroundFetchRegistration roundtrip_registration; | |
| 68 ASSERT_TRUE(blink::mojom::BackgroundFetchRegistration::Deserialize( | |
| 69 blink::mojom::BackgroundFetchRegistration::Serialize(®istration), | |
| 70 &roundtrip_registration)); | |
| 71 | |
| 72 EXPECT_EQ(roundtrip_registration.tag, registration.tag); | |
| 73 | |
| 74 ASSERT_EQ(roundtrip_registration.icons.size(), registration.icons.size()); | |
| 75 for (size_t i = 0; i < registration.icons.size(); ++i) { | |
| 76 EXPECT_TRUE(IconDefinitionsAreIdentical(registration.icons[i], | |
| 77 roundtrip_registration.icons[i])); | |
| 78 } | |
| 79 | |
| 80 EXPECT_EQ(roundtrip_registration.title, registration.title); | |
| 81 EXPECT_EQ(roundtrip_registration.total_download_size, | |
| 82 registration.total_download_size); | |
| 83 } | |
| 84 | |
| 85 TEST(BackgroundFetchStructTraitsTest, IconDefinitionRoundtrip) { | |
| 86 IconDefinition definition = | |
| 87 CreateIconDefinition("my_icon.png", "256x256", "image/png"); | |
| 88 | |
| 89 IconDefinition roundtrip_definition; | |
| 90 ASSERT_TRUE(blink::mojom::IconDefinition::Deserialize( | |
| 91 blink::mojom::IconDefinition::Serialize(&definition), | |
| 92 &roundtrip_definition)); | |
| 93 | |
| 94 EXPECT_TRUE(IconDefinitionsAreIdentical(definition, roundtrip_definition)); | |
| 95 } | |
| 96 | |
| 97 } // namespace content | |
| OLD | NEW |