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

Unified Diff: chrome/browser/metrics/variations/network_time_tracker_unittest.cc

Issue 12096096: Give access to a network time kept in the variation service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 2nd round of CR comments, new file and tests. Created 7 years, 10 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: chrome/browser/metrics/variations/network_time_tracker_unittest.cc
diff --git a/chrome/browser/metrics/variations/network_time_tracker_unittest.cc b/chrome/browser/metrics/variations/network_time_tracker_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea69196c89e939d5b64609ef49d277dc2468259a
--- /dev/null
+++ b/chrome/browser/metrics/variations/network_time_tracker_unittest.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2013 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 "base/threading/platform_thread.h"
+#include "chrome/browser/metrics/variations/network_time_tracker.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// These are all in milliseconds.
+const int64 kLatency1 = 50;
+const int64 kLatency2 = 500;
+
+// Can not be smaller than 15, it's the NowFromSystemTime() resolution.
+const int64 kResolution1 = 17;
+const int64 kResolution2 = 177;
+
+const int64 kSleepTime1 = 500;
+const int64 kSleepTime2 = 333;
+
+void ValidateCurrentTime(const NetworkTimeTracker& network_time_tracker) {
+ base::Time expected_time = base::Time::NowFromSystemTime();
+ base::Time network_time;
+ base::TimeDelta uncertainty;
+ EXPECT_TRUE(network_time_tracker.GetNetworkTime(&network_time,
+ &uncertainty));
+ EXPECT_LE(abs(expected_time.ToInternalValue() -
+ network_time.ToInternalValue()), uncertainty.ToInternalValue());
+}
+
+}
Alexei Svitkine (slow) 2013/02/04 21:23:18 Nit: Add "// namespace".
MAD 2013/02/05 01:05:55 Done.
+
+TEST(NetworkTimeTrackerTest, ProperTimeTracking) {
+ NetworkTimeTracker network_time_tracker;
+
+ // Should not return a value before UpdateNetworkTime gets called.
+ base::Time network_time;
+ base::TimeDelta uncertainty;
+ EXPECT_FALSE(network_time_tracker.GetNetworkTime(&network_time,
+ &uncertainty));
+
+ // Update the time based on NowFromSystemTime and kLatency1.
+ network_time_tracker.UpdateNetworkTime(
+ base::Time::NowFromSystemTime(),
+ base::TimeDelta::FromMilliseconds(kResolution1),
+ base::TimeDelta::FromMilliseconds(kLatency1));
+ ValidateCurrentTime(network_time_tracker);
+
+ // Wait for kSleepTime1 to make sure we keep tracking.
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kSleepTime1));
Alexei Svitkine (slow) 2013/02/04 21:23:18 Instead of making the test sleep (which makes the
MAD 2013/02/05 01:05:55 Done.
+ ValidateCurrentTime(network_time_tracker);
+
+ // Update the time with a new NowFromSystemTime value and kLatency2.
+ network_time_tracker.UpdateNetworkTime(
+ base::Time::NowFromSystemTime(),
+ base::TimeDelta::FromMilliseconds(kResolution2),
+ base::TimeDelta::FromMilliseconds(kLatency2));
+
+ // Wait for kSleepTime2 to make sure we keep tracking still.
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kSleepTime2));
+ ValidateCurrentTime(network_time_tracker);
+}

Powered by Google App Engine
This is Rietveld 408576698