Index: webkit/glue/weburlloader_impl_unittest.cc |
diff --git a/webkit/glue/weburlloader_impl_unittest.cc b/webkit/glue/weburlloader_impl_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0bd4774f69e0ff71b4fe526aceb4535dd8e67737 |
--- /dev/null |
+++ b/webkit/glue/weburlloader_impl_unittest.cc |
@@ -0,0 +1,143 @@ |
+// Copyright (c) 2011 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/time.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoadTiming.h" |
+#include "webkit/glue/resource_loader_bridge.h" |
+#include "webkit/glue/weburlloader_impl.h" |
+ |
+using base::TimeTicks; |
+using WebKit::WebURLLoadTiming; |
+ |
+namespace webkit_glue { |
+ |
+struct TestParams { |
+ int64 ipc_request_time; |
+ int64 net_start_time; |
+ int64 net_end_time; |
+ int64 ipc_response_time; |
+ int64 net_base_time; |
+ int64 net_test_delta; |
+}; |
+ |
+WebURLLoadTiming RunTest(const TestParams& params) { |
+ ResourceLoadTimingInfo timing_info; |
+ timing_info.base_ticks = TimeTicks::FromInternalValue(params.net_base_time); |
+ timing_info.proxy_start = params.net_test_delta; |
+ timing_info.proxy_end = 0; |
+ timing_info.dns_start = 0; |
+ timing_info.dns_end = 0; |
+ timing_info.connect_start = 0; |
+ timing_info.connect_end = 0; |
+ timing_info.ssl_start = 0; |
+ timing_info.ssl_end = 0; |
+ timing_info.send_start = 0; |
+ timing_info.send_end = 0; |
+ timing_info.receive_headers_end = 0; |
+ |
+ return PopulateWebURLLoadTiming( |
+ timing_info, |
+ TimeTicks::FromInternalValue(params.ipc_request_time), |
+ TimeTicks::FromInternalValue(params.net_start_time), |
+ TimeTicks::FromInternalValue(params.net_end_time), |
+ TimeTicks::FromInternalValue(params.ipc_response_time)); |
+} |
+ |
+TEST(PopulateWebURLLoadTiming, NoSkew) { |
+ // All times are monotonic, so no adjustment should occur. |
+ TestParams p; |
+ p.ipc_request_time = 0; |
+ p.net_start_time = 1; |
+ p.net_end_time = 4; |
+ p.ipc_response_time = 5; |
+ p.net_base_time = 2; |
+ p.net_test_delta = 1; |
+ WebURLLoadTiming timing = RunTest(p); |
+ EXPECT_EQ(2.0e-6, timing.requestTime()); |
+ EXPECT_EQ(1, timing.proxyStart()); |
+} |
+ |
+TEST(PopulateWebURLLoadTiming, DoubleEndedSkew) { |
+ // |net_start_time| occurs before |ipc_request_time| and |net_end_time| occurs |
+ // after |ipc_response_time|. We must adjust both bounds and scale down the |
+ // delta. |net_base_time| is on the midpoint, so it doesn't change. The ratio |
+ // of local time to network time is 1:2, so we scale |net_test_delta| by half. |
+ TestParams p; |
+ p.ipc_request_time = 2; |
+ p.net_start_time = 0; |
+ p.net_end_time = 8; |
+ p.ipc_response_time = 6; |
+ p.net_base_time = 4; |
+ p.net_test_delta = 2; |
+ WebURLLoadTiming timing = RunTest(p); |
+ EXPECT_EQ(4.0e-6, timing.requestTime()); |
+ EXPECT_EQ(1, timing.proxyStart()); |
+} |
+ |
+TEST(PopulateWebURLLoadTiming, FrontEndSkew) { |
+ // |net_end_time| is coherent, but |net_start_time| is not. So we adjust the |
+ // lower bound and move |net_base_time| out. The scale factor is 2:3, but |
+ // since we use integers, the numbers truncate from 3.33 to 3 and 1.33 to 1. |
+ TestParams p; |
+ p.ipc_request_time = 2; |
+ p.net_start_time = 0; |
+ p.net_end_time = 6; |
+ p.ipc_response_time = 6; |
+ p.net_base_time = 2; |
+ p.net_test_delta = 2; |
+ WebURLLoadTiming timing = RunTest(p); |
+ EXPECT_EQ(3.0e-6, timing.requestTime()); |
+ EXPECT_EQ(1, timing.proxyStart()); |
+} |
+ |
+TEST(PopulateWebURLLoadTiming, BackEndSkew) { |
+ // Like the previous test, but |net_start_time| is coherent and |net_end_time| |
+ // is skewed. |
+ TestParams p; |
+ p.ipc_request_time = 0; |
+ p.net_start_time = 0; |
+ p.net_end_time = 6; |
+ p.ipc_response_time = 4; |
+ p.net_base_time = 2; |
+ p.net_test_delta = 2; |
+ WebURLLoadTiming timing = RunTest(p); |
+ EXPECT_EQ(1.0e-6, timing.requestTime()); |
+ EXPECT_EQ(1, timing.proxyStart()); |
+} |
+ |
+TEST(PopulateWebURLLoadTiming, Instantaneous) { |
+ // The bounds are all okay, but the |net_start_time| and |net_end_time| have |
+ // the same value. No adjustments should be made and no divide-by-zero errors |
+ // should occur. |
+ TestParams p; |
+ p.ipc_request_time = 0; |
+ p.net_start_time = 1; |
+ p.net_end_time = 1; |
+ p.ipc_response_time = 2; |
+ p.net_base_time = 1; |
+ p.net_test_delta = 0; |
+ WebURLLoadTiming timing = RunTest(p); |
+ EXPECT_EQ(1.0e-6, timing.requestTime()); |
+ EXPECT_EQ(0, timing.proxyStart()); |
+} |
+ |
+TEST(PopulateWebURLLoadTiming, DisjointInstantaneous) { |
+ // |ipc_request_time| and |ipc_response_time| are the same. No matter what the |
+ // other values are, they must fit within [ipc_request_time, |
+ // ipc_response_time]. So, all of the values should be adjusted so they are |
+ // exactly that value. |
+ TestParams p; |
+ p.ipc_request_time = 1; |
+ p.net_start_time = 2; |
+ p.net_end_time = 2; |
+ p.ipc_response_time = 1; |
+ p.net_base_time = 2; |
+ p.net_test_delta = 1; |
+ WebURLLoadTiming timing = RunTest(p); |
+ EXPECT_EQ(1.0e-6, timing.requestTime()); |
+ EXPECT_EQ(0, timing.proxyStart()); |
+} |
+ |
+} // namespace webkit_glue |