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

Side by Side Diff: components/download/internal/proto_conversions_unittest.cc

Issue 2881173003: Download Service : Added leveldb proto layer (Closed)
Patch Set: Removed Model::Destroy Created 3 years, 7 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
« no previous file with comments | « components/download/internal/proto_conversions.cc ('k') | components/download/internal/store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility>
6
7 #include "base/guid.h"
8 #include "base/memory/ptr_util.h"
9 #include "components/download/internal/entry.h"
10 #include "components/download/internal/proto_conversions.h"
11 #include "components/download/internal/test/entry_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace {
15 std::string TEST_URL = "https://google.com";
16
17 } // namespace
18
19 namespace download {
20
21 class ProtoConversionsTest : public testing::Test, public ProtoConversions {
22 public:
23 ~ProtoConversionsTest() override {}
24 };
25
26 TEST_F(ProtoConversionsTest, StateConversion) {
27 Entry::State states[] = {Entry::State::NEW, Entry::State::AVAILABLE,
28 Entry::State::ACTIVE, Entry::State::PAUSED,
29 Entry::State::COMPLETE, Entry::State::WATCHDOG};
30 for (auto state : states) {
31 ASSERT_EQ(state, RequestStateFromProto(RequestStateToProto(state)));
32 }
33 }
34
35 TEST_F(ProtoConversionsTest, DownloadClientConversion) {
36 DownloadClient clients[] = {DownloadClient::INVALID, DownloadClient::TEST,
37 DownloadClient::OFFLINE_PAGE_PREFETCH,
38 DownloadClient::BOUNDARY};
39 for (auto client : clients) {
40 ASSERT_EQ(client, DownloadClientFromProto(DownloadClientToProto(client)));
41 }
42 }
43
44 TEST_F(ProtoConversionsTest, NetworkRequirementsConversion) {
45 SchedulingParams::NetworkRequirements values[] = {
46 SchedulingParams::NetworkRequirements::NONE,
47 SchedulingParams::NetworkRequirements::OPTIMISTIC,
48 SchedulingParams::NetworkRequirements::UNMETERED};
49 for (auto value : values) {
50 ASSERT_EQ(value,
51 NetworkRequirementsFromProto(NetworkRequirementsToProto(value)));
52 }
53 }
54
55 TEST_F(ProtoConversionsTest, BatteryRequirementsConversion) {
56 SchedulingParams::BatteryRequirements values[] = {
57 SchedulingParams::BatteryRequirements::BATTERY_INSENSITIVE,
58 SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE};
59 for (auto value : values) {
60 ASSERT_EQ(value,
61 BatteryRequirementsFromProto(BatteryRequirementsToProto(value)));
62 }
63 }
64
65 TEST_F(ProtoConversionsTest, SchedulingPriorityConversion) {
66 SchedulingParams::Priority values[] = {
67 SchedulingParams::Priority::LOW, SchedulingParams::Priority::NORMAL,
68 SchedulingParams::Priority::HIGH, SchedulingParams::Priority::UI,
69 SchedulingParams::Priority::DEFAULT};
70 for (auto value : values) {
71 ASSERT_EQ(value,
72 SchedulingPriorityFromProto(SchedulingPriorityToProto(value)));
73 }
74 }
75
76 TEST_F(ProtoConversionsTest, SchedulingParamsConversion) {
77 SchedulingParams expected;
78 expected.cancel_time = base::Time::Now();
79 expected.priority = SchedulingParams::Priority::DEFAULT;
80 expected.network_requirements =
81 SchedulingParams::NetworkRequirements::OPTIMISTIC;
82 expected.battery_requirements =
83 SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE;
84
85 protodb::SchedulingParams proto;
86 SchedulingParamsToProto(expected, &proto);
87 SchedulingParams actual = SchedulingParamsFromProto(proto);
88 EXPECT_EQ(expected.cancel_time, actual.cancel_time);
89 EXPECT_EQ(SchedulingParams::Priority::DEFAULT, actual.priority);
90 EXPECT_EQ(SchedulingParams::NetworkRequirements::OPTIMISTIC,
91 actual.network_requirements);
92 EXPECT_EQ(SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE,
93 actual.battery_requirements);
94 }
95
96 TEST_F(ProtoConversionsTest, RequestParamsWithHeadersConversion) {
97 RequestParams expected;
98 expected.url = GURL(TEST_URL);
99 expected.method = "GET";
100 expected.request_headers.SetHeader("key1", "value1");
101 expected.request_headers.SetHeader("key2", "value2");
102
103 protodb::RequestParams proto;
104 RequestParamsToProto(expected, &proto);
105 RequestParams actual = RequestParamsFromProto(proto);
106
107 EXPECT_EQ(expected.url, actual.url);
108 EXPECT_EQ(expected.method, actual.method);
109
110 std::string out;
111 actual.request_headers.GetHeader("key1", &out);
112 EXPECT_EQ("value1", out);
113 actual.request_headers.GetHeader("key2", &out);
114 EXPECT_EQ("value2", out);
115 EXPECT_EQ(expected.request_headers.ToString(),
116 actual.request_headers.ToString());
117 }
118
119 TEST_F(ProtoConversionsTest, EntryConversion) {
120 Entry expected = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
121 Entry actual = EntryFromProto(EntryToProto(expected));
122 EXPECT_TRUE(test::CompareEntry(&expected, &actual));
123
124 expected = test::BuildEntry(
125 DownloadClient::TEST, base::GenerateGUID(), base::Time::Now(),
126 SchedulingParams::NetworkRequirements::OPTIMISTIC,
127 SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE,
128 SchedulingParams::Priority::HIGH, GURL(TEST_URL), "GET",
129 Entry::State::ACTIVE);
130 actual = EntryFromProto(EntryToProto(expected));
131 EXPECT_TRUE(test::CompareEntry(&expected, &actual));
132 }
133
134 TEST_F(ProtoConversionsTest, EntryVectorConversion) {
135 std::vector<Entry> expected;
136 expected.push_back(
137 test::BuildEntry(DownloadClient::TEST, base::GenerateGUID()));
138 expected.push_back(test::BuildEntry(DownloadClient::OFFLINE_PAGE_PREFETCH,
139 base::GenerateGUID()));
140 expected.push_back(test::BuildEntry(
141 DownloadClient::TEST, base::GenerateGUID(), base::Time::Now(),
142 SchedulingParams::NetworkRequirements::OPTIMISTIC,
143 SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE,
144 SchedulingParams::Priority::HIGH, GURL(TEST_URL), "GET",
145 Entry::State::ACTIVE));
146
147 auto actual = EntryVectorFromProto(
148 EntryVectorToProto(base::MakeUnique<std::vector<Entry>>(expected)));
149 EXPECT_TRUE(test::CompareEntryList(expected, *actual));
150 }
151
152 } // namespace download
OLDNEW
« no previous file with comments | « components/download/internal/proto_conversions.cc ('k') | components/download/internal/store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698