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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/download/internal/proto_conversions_unittest.cc
diff --git a/components/download/internal/proto_conversions_unittest.cc b/components/download/internal/proto_conversions_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..04198c5b54b34018237f09f87f4d8b3108c0ace8
--- /dev/null
+++ b/components/download/internal/proto_conversions_unittest.cc
@@ -0,0 +1,152 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <utility>
+
+#include "base/guid.h"
+#include "base/memory/ptr_util.h"
+#include "components/download/internal/entry.h"
+#include "components/download/internal/proto_conversions.h"
+#include "components/download/internal/test/entry_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+std::string TEST_URL = "https://google.com";
+
+} // namespace
+
+namespace download {
+
+class ProtoConversionsTest : public testing::Test, public ProtoConversions {
+ public:
+ ~ProtoConversionsTest() override {}
+};
+
+TEST_F(ProtoConversionsTest, StateConversion) {
+ Entry::State states[] = {Entry::State::NEW, Entry::State::AVAILABLE,
+ Entry::State::ACTIVE, Entry::State::PAUSED,
+ Entry::State::COMPLETE, Entry::State::WATCHDOG};
+ for (auto state : states) {
+ ASSERT_EQ(state, RequestStateFromProto(RequestStateToProto(state)));
+ }
+}
+
+TEST_F(ProtoConversionsTest, DownloadClientConversion) {
+ DownloadClient clients[] = {DownloadClient::INVALID, DownloadClient::TEST,
+ DownloadClient::OFFLINE_PAGE_PREFETCH,
+ DownloadClient::BOUNDARY};
+ for (auto client : clients) {
+ ASSERT_EQ(client, DownloadClientFromProto(DownloadClientToProto(client)));
+ }
+}
+
+TEST_F(ProtoConversionsTest, NetworkRequirementsConversion) {
+ SchedulingParams::NetworkRequirements values[] = {
+ SchedulingParams::NetworkRequirements::NONE,
+ SchedulingParams::NetworkRequirements::OPTIMISTIC,
+ SchedulingParams::NetworkRequirements::UNMETERED};
+ for (auto value : values) {
+ ASSERT_EQ(value,
+ NetworkRequirementsFromProto(NetworkRequirementsToProto(value)));
+ }
+}
+
+TEST_F(ProtoConversionsTest, BatteryRequirementsConversion) {
+ SchedulingParams::BatteryRequirements values[] = {
+ SchedulingParams::BatteryRequirements::BATTERY_INSENSITIVE,
+ SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE};
+ for (auto value : values) {
+ ASSERT_EQ(value,
+ BatteryRequirementsFromProto(BatteryRequirementsToProto(value)));
+ }
+}
+
+TEST_F(ProtoConversionsTest, SchedulingPriorityConversion) {
+ SchedulingParams::Priority values[] = {
+ SchedulingParams::Priority::LOW, SchedulingParams::Priority::NORMAL,
+ SchedulingParams::Priority::HIGH, SchedulingParams::Priority::UI,
+ SchedulingParams::Priority::DEFAULT};
+ for (auto value : values) {
+ ASSERT_EQ(value,
+ SchedulingPriorityFromProto(SchedulingPriorityToProto(value)));
+ }
+}
+
+TEST_F(ProtoConversionsTest, SchedulingParamsConversion) {
+ SchedulingParams expected;
+ expected.cancel_time = base::Time::Now();
+ expected.priority = SchedulingParams::Priority::DEFAULT;
+ expected.network_requirements =
+ SchedulingParams::NetworkRequirements::OPTIMISTIC;
+ expected.battery_requirements =
+ SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE;
+
+ protodb::SchedulingParams proto;
+ SchedulingParamsToProto(expected, &proto);
+ SchedulingParams actual = SchedulingParamsFromProto(proto);
+ EXPECT_EQ(expected.cancel_time, actual.cancel_time);
+ EXPECT_EQ(SchedulingParams::Priority::DEFAULT, actual.priority);
+ EXPECT_EQ(SchedulingParams::NetworkRequirements::OPTIMISTIC,
+ actual.network_requirements);
+ EXPECT_EQ(SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE,
+ actual.battery_requirements);
+}
+
+TEST_F(ProtoConversionsTest, RequestParamsWithHeadersConversion) {
+ RequestParams expected;
+ expected.url = GURL(TEST_URL);
+ expected.method = "GET";
+ expected.request_headers.SetHeader("key1", "value1");
+ expected.request_headers.SetHeader("key2", "value2");
+
+ protodb::RequestParams proto;
+ RequestParamsToProto(expected, &proto);
+ RequestParams actual = RequestParamsFromProto(proto);
+
+ EXPECT_EQ(expected.url, actual.url);
+ EXPECT_EQ(expected.method, actual.method);
+
+ std::string out;
+ actual.request_headers.GetHeader("key1", &out);
+ EXPECT_EQ("value1", out);
+ actual.request_headers.GetHeader("key2", &out);
+ EXPECT_EQ("value2", out);
+ EXPECT_EQ(expected.request_headers.ToString(),
+ actual.request_headers.ToString());
+}
+
+TEST_F(ProtoConversionsTest, EntryConversion) {
+ Entry expected = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
+ Entry actual = EntryFromProto(EntryToProto(expected));
+ EXPECT_TRUE(test::CompareEntry(&expected, &actual));
+
+ expected = test::BuildEntry(
+ DownloadClient::TEST, base::GenerateGUID(), base::Time::Now(),
+ SchedulingParams::NetworkRequirements::OPTIMISTIC,
+ SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE,
+ SchedulingParams::Priority::HIGH, GURL(TEST_URL), "GET",
+ Entry::State::ACTIVE);
+ actual = EntryFromProto(EntryToProto(expected));
+ EXPECT_TRUE(test::CompareEntry(&expected, &actual));
+}
+
+TEST_F(ProtoConversionsTest, EntryVectorConversion) {
+ std::vector<Entry> expected;
+ expected.push_back(
+ test::BuildEntry(DownloadClient::TEST, base::GenerateGUID()));
+ expected.push_back(test::BuildEntry(DownloadClient::OFFLINE_PAGE_PREFETCH,
+ base::GenerateGUID()));
+ expected.push_back(test::BuildEntry(
+ DownloadClient::TEST, base::GenerateGUID(), base::Time::Now(),
+ SchedulingParams::NetworkRequirements::OPTIMISTIC,
+ SchedulingParams::BatteryRequirements::BATTERY_SENSITIVE,
+ SchedulingParams::Priority::HIGH, GURL(TEST_URL), "GET",
+ Entry::State::ACTIVE));
+
+ auto actual = EntryVectorFromProto(
+ EntryVectorToProto(base::MakeUnique<std::vector<Entry>>(expected)));
+ EXPECT_TRUE(test::CompareEntryList(expected, *actual));
+}
+
+} // namespace download
« 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