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

Side by Side Diff: components/copresence/timed_map_unittest.cc

Issue 1178423008: Provision to start base::SimpleTestTickClock at initial ticks Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 12 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/test/simple_test_tick_clock.h" 7 #include "base/test/simple_test_tick_clock.h"
8 #include "components/copresence/timed_map.h" 8 #include "components/copresence/timed_map.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 EXPECT_FALSE(two_element_map.HasKey(0x1337)); 91 EXPECT_FALSE(two_element_map.HasKey(0x1337));
92 EXPECT_EQ(0, two_element_map.GetValue(0x1337).value); 92 EXPECT_EQ(0, two_element_map.GetValue(0x1337).value);
93 } 93 }
94 94
95 TEST_F(TimedMapTest, TimedEvict) { 95 TEST_F(TimedMapTest, TimedEvict) {
96 const int kLargeTimeValueSeconds = 9999; 96 const int kLargeTimeValueSeconds = 9999;
97 Map map(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds), 2); 97 Map map(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds), 2);
98 98
99 // The map takes ownership of the clock, but we retain a pointer. 99 // The map takes ownership of the clock, but we retain a pointer.
100 base::SimpleTestTickClock* clock = new base::SimpleTestTickClock; 100 base::SimpleTestTickClock* clock =
101 new base::SimpleTestTickClock(base::TimeTicks());
101 map.set_clock_for_testing(make_scoped_ptr<base::TickClock>(clock)); 102 map.set_clock_for_testing(make_scoped_ptr<base::TickClock>(clock));
102 103
103 // Add value at T=0. 104 // Add value at T=0.
104 map.Add(0x1337, Value(0x7331)); 105 map.Add(0x1337, Value(0x7331));
105 EXPECT_TRUE(map.HasKey(0x1337)); 106 EXPECT_TRUE(map.HasKey(0x1337));
106 EXPECT_EQ(0x7331, map.GetValue(0x1337).value); 107 EXPECT_EQ(0x7331, map.GetValue(0x1337).value);
107 108
108 // Add value at T=kLargeTimeValueSeconds-1. 109 // Add value at T=kLargeTimeValueSeconds-1.
109 clock->Advance(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds - 1)); 110 clock->Advance(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds - 1));
110 map.Add(0xbaad, Value(0xf00d)); 111 map.Add(0xbaad, Value(0xf00d));
111 112
112 // Check values at T=kLargeTimeValueSeconds-1. 113 // Check values at T=kLargeTimeValueSeconds-1.
113 EXPECT_TRUE(map.HasKey(0xbaad)); 114 EXPECT_TRUE(map.HasKey(0xbaad));
114 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value); 115 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value);
115 EXPECT_TRUE(map.HasKey(0x1337)); 116 EXPECT_TRUE(map.HasKey(0x1337));
116 EXPECT_EQ(0x7331, map.GetValue(0x1337).value); 117 EXPECT_EQ(0x7331, map.GetValue(0x1337).value);
117 118
118 // Check values at T=kLargeTimeValueSeconds. 119 // Check values at T=kLargeTimeValueSeconds.
119 clock->Advance(base::TimeDelta::FromSeconds(1)); 120 clock->Advance(base::TimeDelta::FromSeconds(1));
120 EXPECT_FALSE(map.HasKey(0x1337)); 121 EXPECT_FALSE(map.HasKey(0x1337));
121 EXPECT_EQ(0, map.GetValue(0x1337).value); 122 EXPECT_EQ(0, map.GetValue(0x1337).value);
122 EXPECT_TRUE(map.HasKey(0xbaad)); 123 EXPECT_TRUE(map.HasKey(0xbaad));
123 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value); 124 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value);
124 125
125 // Check values at T=2*kLargeTimeValueSeconds 126 // Check values at T=2*kLargeTimeValueSeconds
126 clock->Advance(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds)); 127 clock->Advance(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds));
127 EXPECT_FALSE(map.HasKey(0xbaad)); 128 EXPECT_FALSE(map.HasKey(0xbaad));
128 EXPECT_EQ(0, map.GetValue(0xbaad).value); 129 EXPECT_EQ(0, map.GetValue(0xbaad).value);
129 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698