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

Unified Diff: webkit/renderer/compositor_bindings/webkit_time_unittest.cc

Issue 192433002: Creating utility for converting TimeTicks to WebKit double and use it in the Chrome compositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reworking webkit_time, adding other users. Created 6 years, 9 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: webkit/renderer/compositor_bindings/webkit_time_unittest.cc
diff --git a/webkit/renderer/compositor_bindings/webkit_time_unittest.cc b/webkit/renderer/compositor_bindings/webkit_time_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..04dc94c3655cbf3e9e329963eb628fdc599cfbc1
--- /dev/null
+++ b/webkit/renderer/compositor_bindings/webkit_time_unittest.cc
@@ -0,0 +1,65 @@
+// 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 "webkit/renderer/compositor_bindings/webkit_time.h"
+
+#include <cmath>
+#include <limits>
+
+#include "base/time/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using base::TimeTicks;
+
+TEST(WebKitTime, Conversion) {
+ double double_zero = 0;
+ double double_max = std::numeric_limits<double>::max();
+ double double_min = std::numeric_limits<double>::lowest();
+ double double_positive_inf = std::numeric_limits<double>::infinity();
+ double double_negative_inf = -std::numeric_limits<double>::infinity();
+
+ base::TimeTicks ticks_null = base::TimeTicks();
+ base::TimeTicks ticks_min =
+ base::TimeTicks::FromInternalValue(std::numeric_limits<int64>::min());
+ base::TimeTicks ticks_max =
+ base::TimeTicks::FromInternalValue(std::numeric_limits<int64>::max());
+
+#if ENABLE_DCHECK
+ EXPECT_EQ(double_zero, webkit::ToWebKitMonotonicTime(ticks_null));
+ EXPECT_EQ(ticks_null, webkit::ToWebKitMonotonicTime(double_zero));
+#else
+ ASSERT_DEATH(webkit::FromWebKitMonotonicTime(double_zero), "Check failed");
+ ASSERT_DEATH(webkit::FromWebKitMonotonicTime(double_max), "Check failed");
+ ASSERT_DEATH(webkit::FromWebKitMonotonicTime(double_min), "Check failed");
+ ASSERT_DEATH(webkit::FromWebKitMonotonicTime(double_positive_inf),
+ "Check failed");
+ ASSERT_DEATH(webkit::FromWebKitMonotonicTime(double_negative_inf),
+ "Check failed");
+
+ ASSERT_DEATH(webkit::ToWebKitMonotonicTime(ticks_null), "Check failed");
+ ASSERT_DEATH(webkit::ToWebKitMonotonicTime(ticks_min), "Check failed");
+ ASSERT_DEATH(webkit::ToWebKitMonotonicTime(ticks_max), "Check failed");
+#endif
+
+ // Round trip some values
+ // Outside of 2**53 the int64->double->int64 round trip isn't exact.
+ for (int i = -52; i < 52; i++) {
+ if (!i)
+ continue;
+
+ SCOPED_TRACE(i);
+ double i_abs = abs(static_cast<double>(i));
+
+ base::TimeTicks ticks_value = base::TimeTicks::FromInternalValue(
+ static_cast<int64>((i / i_abs) * pow(2.0, i_abs)));
+ EXPECT_EQ(webkit::FromWebKitMonotonicTime(
+ webkit::ToWebKitMonotonicTime(ticks_value)),
+ ticks_value);
+
+ double double_value = (i / i_abs) * pow(2.0, i_abs) / 1e6;
+ EXPECT_EQ(webkit::ToWebKitMonotonicTime(
+ webkit::FromWebKitMonotonicTime(double_value)),
+ double_value);
+ }
+}
« cc/trees/layer_tree_host_impl.cc ('K') | « webkit/renderer/compositor_bindings/webkit_time.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698