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

Side by Side Diff: components/sync_driver/device_info_util_unittest.cc

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 years, 4 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 2016 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 "components/sync_driver/device_info_util.h"
6
7 #include <string>
8
9 #include "components/sync/protocol/sync.pb.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using base::Time;
13 using base::TimeDelta;
14 using sync_pb::DeviceInfoSpecifics;
15
16 namespace sync_driver {
17
18 namespace {
19
20 class DeviceInfoUtilTest : public testing::Test {
21 protected:
22 DeviceInfoUtilTest() {
23 // Test cases assume |small_| and |big_| are smaller and bigger,
24 // respectively,
25 // than both constants.
26 EXPECT_LT(small_, DeviceInfoUtil::kActiveThreshold);
27 EXPECT_LT(small_, DeviceInfoUtil::kPulseInterval);
28 EXPECT_GT(big_, DeviceInfoUtil::kActiveThreshold);
29 EXPECT_GT(big_, DeviceInfoUtil::kPulseInterval);
30 }
31
32 const Time now_ = Time::Now();
33 const TimeDelta small_ = TimeDelta::FromMilliseconds(1);
34 const TimeDelta big_ = TimeDelta::FromDays(1000);
35 };
36
37 } // namespace
38
39 TEST_F(DeviceInfoUtilTest, CalculatePulseDelaySame) {
40 EXPECT_EQ(DeviceInfoUtil::kPulseInterval,
41 DeviceInfoUtil::CalculatePulseDelay(Time(), Time()));
42 EXPECT_EQ(DeviceInfoUtil::kPulseInterval,
43 DeviceInfoUtil::CalculatePulseDelay(now_, now_));
44 EXPECT_EQ(DeviceInfoUtil::kPulseInterval,
45 DeviceInfoUtil::CalculatePulseDelay(now_ + big_, now_ + big_));
46 }
47
48 TEST_F(DeviceInfoUtilTest, CalculatePulseDelayMiddle) {
49 EXPECT_EQ(DeviceInfoUtil::kPulseInterval - small_,
50 DeviceInfoUtil::CalculatePulseDelay(Time(), Time() + small_));
51 EXPECT_EQ(small_,
52 DeviceInfoUtil::CalculatePulseDelay(
53 Time(), Time() + DeviceInfoUtil::kPulseInterval - small_));
54 }
55
56 TEST_F(DeviceInfoUtilTest, CalculatePulseDelayStale) {
57 EXPECT_EQ(TimeDelta(), DeviceInfoUtil::CalculatePulseDelay(
58 Time(), Time() + DeviceInfoUtil::kPulseInterval));
59 EXPECT_EQ(TimeDelta(),
60 DeviceInfoUtil::CalculatePulseDelay(
61 Time(), Time() + DeviceInfoUtil::kPulseInterval + small_));
62 EXPECT_EQ(TimeDelta(),
63 DeviceInfoUtil::CalculatePulseDelay(
64 Time(), Time() + DeviceInfoUtil::kPulseInterval + small_));
65 EXPECT_EQ(TimeDelta(), DeviceInfoUtil::CalculatePulseDelay(
66 now_, now_ + DeviceInfoUtil::kPulseInterval));
67 }
68
69 TEST_F(DeviceInfoUtilTest, CalculatePulseDelayFuture) {
70 EXPECT_EQ(DeviceInfoUtil::kPulseInterval,
71 DeviceInfoUtil::CalculatePulseDelay(Time() + small_, Time()));
72 EXPECT_EQ(DeviceInfoUtil::kPulseInterval,
73 DeviceInfoUtil::CalculatePulseDelay(
74 Time() + DeviceInfoUtil::kPulseInterval, Time()));
75 EXPECT_EQ(DeviceInfoUtil::kPulseInterval,
76 DeviceInfoUtil::CalculatePulseDelay(Time() + big_, Time()));
77 EXPECT_EQ(DeviceInfoUtil::kPulseInterval,
78 DeviceInfoUtil::CalculatePulseDelay(now_ + big_, now_));
79 }
80
81 TEST_F(DeviceInfoUtilTest, IsActive) {
82 EXPECT_TRUE(DeviceInfoUtil::IsActive(Time(), Time()));
83 EXPECT_TRUE(DeviceInfoUtil::IsActive(now_, now_));
84 EXPECT_TRUE(DeviceInfoUtil::IsActive(now_, now_ + small_));
85 EXPECT_TRUE(DeviceInfoUtil::IsActive(
86 now_, now_ + DeviceInfoUtil::kActiveThreshold - small_));
87 EXPECT_FALSE(
88 DeviceInfoUtil::IsActive(now_, now_ + DeviceInfoUtil::kActiveThreshold));
89 EXPECT_FALSE(DeviceInfoUtil::IsActive(
90 now_, now_ + DeviceInfoUtil::kActiveThreshold + small_));
91 EXPECT_FALSE(DeviceInfoUtil::IsActive(
92 now_, now_ + DeviceInfoUtil::kActiveThreshold + big_));
93 EXPECT_TRUE(DeviceInfoUtil::IsActive(now_ + small_, now_));
94 EXPECT_TRUE(DeviceInfoUtil::IsActive(now_ + big_, now_));
95 }
96
97 TEST_F(DeviceInfoUtilTest, TagRoundTrip) {
98 DeviceInfoSpecifics specifics;
99 ASSERT_EQ("", DeviceInfoUtil::TagToCacheGuid(
100 DeviceInfoUtil::SpecificsToTag(specifics)));
101
102 std::string cache_guid("guid");
103 specifics.set_cache_guid(cache_guid);
104 ASSERT_EQ(cache_guid, DeviceInfoUtil::TagToCacheGuid(
105 DeviceInfoUtil::SpecificsToTag(specifics)));
106
107 specifics.set_cache_guid(DeviceInfoUtil::kClientTagPrefix);
108 ASSERT_EQ(DeviceInfoUtil::kClientTagPrefix,
109 DeviceInfoUtil::TagToCacheGuid(
110 DeviceInfoUtil::SpecificsToTag(specifics)));
111 }
112
113 } // namespace sync_driver
OLDNEW
« no previous file with comments | « components/sync_driver/device_info_util.cc ('k') | components/sync_driver/directory_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698