Chromium Code Reviews| Index: sync/engine/throttled_data_type_tracker_unittest.cc |
| diff --git a/sync/engine/throttled_data_type_tracker_unittest.cc b/sync/engine/throttled_data_type_tracker_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7948d1db70e0da551bac83ebf2d0a18ae329002a |
| --- /dev/null |
| +++ b/sync/engine/throttled_data_type_tracker_unittest.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright (c) 2012 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 "sync/engine/throttled_data_type_tracker.h" |
| + |
| +#include "sync/internal_api/public/syncable/model_type.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using base::TimeDelta; |
| +using base::TimeTicks; |
| + |
| +namespace browser_sync { |
| + |
| +TEST(ThrottledDataTypeTrackerTest, AddUnthrottleTimeTest) { |
| + const syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::PASSWORDS); |
| + |
| + ThrottledDataTypeTracker throttler(NULL); |
| + TimeTicks now = TimeTicks::Now(); |
| + throttler.SetUnthrottleTime(types, now); |
| + |
| + EXPECT_EQ(throttler.unthrottle_times_.size(), 2U); |
| + EXPECT_EQ(throttler.unthrottle_times_[syncable::BOOKMARKS], now); |
| + EXPECT_EQ(throttler.unthrottle_times_[syncable::PASSWORDS], now); |
| +} |
| + |
| +TEST(ThrottledDataTypeTrackerTest, GetCurrentlyThrottledTypesTest) { |
| + const syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::PASSWORDS); |
| + |
| + ThrottledDataTypeTracker throttler(NULL); |
| + TimeTicks now = TimeTicks::Now(); |
| + |
| + // Now update the throttled types with time set to 10 seconds earlier from |
| + // now. |
| + throttler.SetUnthrottleTime(types, now - TimeDelta::FromSeconds(10)); |
| + throttler.PruneUnthrottledTypes(TimeTicks::Now()); |
| + EXPECT_TRUE(throttler.GetThrottledTypes().Empty()); |
| + |
| + // Now update the throttled types with time set to 2 hours from now. |
| + throttler.SetUnthrottleTime(types, now + TimeDelta::FromSeconds(1200)); |
| + throttler.PruneUnthrottledTypes(TimeTicks::Now()); |
| + EXPECT_TRUE(throttler.GetThrottledTypes().Equals(types)); |
| +} |
| + |
| +// Have two data types whose throttling is set to expire at different times. |
| +// For an extra degree of difficulty, we try to trick the throttler into |
| +// overwriting the BOOKMARKS type's long throttle time with a shorter one. |
| +TEST(ThrottledDataTypeTrackerTest, DISABLED_UnthrottleSomeTypesTest) { |
|
rlarocque
2012/06/11 23:28:51
This test had to be disabled because it was failin
tim (not reviewing)
2012/06/12 00:12:20
Hmm. On one hand, I could see the logic being "ser
rlarocque
2012/06/12 18:11:43
The client code was written in a way that suggests
|
| + const syncable::ModelTypeSet long_throttled(syncable::BOOKMARKS); |
| + const syncable::ModelTypeSet short_throttled(syncable::BOOKMARKS, |
| + syncable::PASSWORDS); |
| + |
| + const TimeTicks start_time = TimeTicks::Now(); |
| + const TimeTicks short_throttle_time = start_time + TimeDelta::FromSeconds(1); |
| + const TimeTicks long_throttle_time = start_time + TimeDelta::FromSeconds(20); |
| + const TimeTicks in_between_time = start_time + TimeDelta::FromSeconds(5); |
| + |
| + ThrottledDataTypeTracker throttler(NULL); |
| + |
| + throttler.SetUnthrottleTime(long_throttled, long_throttle_time); |
| + throttler.SetUnthrottleTime(short_throttled, short_throttle_time); |
| + EXPECT_TRUE(throttler.GetThrottledTypes().Equals( |
| + Union(short_throttled, long_throttled))); |
| + |
| + throttler.PruneUnthrottledTypes(in_between_time); |
| + EXPECT_TRUE(throttler.GetThrottledTypes().Equals(long_throttled)); |
| +} |
| + |
| +} // namespace browser_sync |
| + |