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

Unified Diff: components/data_reduction_proxy/core/common/data_reduction_proxy_util_unittest.cc

Issue 2025443002: Refactoring data reduction proxy some methods to common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
Index: components/data_reduction_proxy/core/common/data_reduction_proxy_util_unittest.cc
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_util_unittest.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5d2dcff3d267ac2ade8f4a1398b4b2f5e225f74b
--- /dev/null
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_util_unittest.cc
@@ -0,0 +1,94 @@
+// Copyright 2015 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 "components/data_reduction_proxy/core/common/data_reduction_proxy_util.h"
+
+#include <stdint.h>
+
+#include <string>
+
+#include "base/time/time.h"
+#include "components/data_reduction_proxy/proto/client_config.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace data_reduction_proxy {
+
+namespace {
+
+const char kFutureTime[] = "31 Dec 2020 23:59:59.001";
+
+} // namespace
+
+class DataReductionProxyClientProtobufParserTest : public testing::Test {
+ protected:
+ void SetUp() override {
+ EXPECT_TRUE(base::Time::FromUTCString(kFutureTime, &future_time_));
+ }
+
+ const base::Time& GetFutureTime() { return future_time_; }
tbansal1 2016/05/27 23:01:59 const method.
RyanSturm 2016/05/31 20:10:51 Done.
+
+ private:
+ base::Time future_time_;
+};
+
+TEST_F(DataReductionProxyClientProtobufParserTest, TimeDeltaToFromDuration) {
+ const struct {
+ std::string test_name;
+ base::TimeDelta time_delta;
+ int64_t seconds;
+ int32_t nanos;
+ } tests[] = {
+ {
+ "Second", base::TimeDelta::FromSeconds(1), 1, 0,
+ },
+ {
+ "-1 Second", base::TimeDelta::FromSeconds(-1), -1, 0,
+ },
+ {
+ "1.5 Seconds", base::TimeDelta::FromMilliseconds(1500), 1,
+ base::Time::kNanosecondsPerSecond / 2,
+ },
+ };
+
+ for (const auto& test : tests) {
+ Duration duration;
+ protobuf_parser::TimeDeltatoDuration(test.time_delta, &duration);
+ EXPECT_EQ(test.seconds, duration.seconds()) << test.test_name;
+ EXPECT_EQ(test.nanos, duration.nanos()) << test.test_name;
+ duration.set_seconds(test.seconds);
+ duration.set_nanos(test.nanos);
+ EXPECT_EQ(test.time_delta, protobuf_parser::DurationToTimeDelta(duration))
+ << test.test_name;
+ }
+}
+
+TEST_F(DataReductionProxyClientProtobufParserTest, TimeStampToFromTime) {
+ const struct {
+ std::string test_name;
+ base::Time time;
+ int64_t seconds;
+ int32_t nanos;
+ } tests[] = {
+ {
+ "Second", base::Time::FromJsTime(1000), 1, 0,
+ },
+ {
+ "1.5 Seconds", base::Time::FromJsTime(1500), 1,
+ base::Time::kNanosecondsPerSecond / 2,
+ },
+ };
+
+ for (const auto& test : tests) {
+ Timestamp timestamp;
+ protobuf_parser::TimetoTimestamp(test.time, &timestamp);
+ EXPECT_EQ(test.seconds, timestamp.seconds()) << test.test_name;
+ EXPECT_EQ(test.nanos, timestamp.nanos()) << test.test_name;
+ timestamp.set_seconds(test.seconds);
+ timestamp.set_nanos(test.nanos);
+ EXPECT_EQ(test.time, protobuf_parser::TimestamptoTime(timestamp))
+ << test.test_name;
+ }
+}
+
+} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698