OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/time.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoadTiming.h" |
| 8 #include "webkit/glue/resource_loader_bridge.h" |
| 9 #include "webkit/glue/weburlloader_impl.h" |
| 10 |
| 11 using base::TimeTicks; |
| 12 using WebKit::WebURLLoadTiming; |
| 13 |
| 14 namespace webkit_glue { |
| 15 |
| 16 struct TestParams { |
| 17 int64 ipc_request_time; |
| 18 int64 net_start_time; |
| 19 int64 net_end_time; |
| 20 int64 ipc_response_time; |
| 21 int64 net_base_time; |
| 22 int64 net_test_delta; |
| 23 }; |
| 24 |
| 25 WebURLLoadTiming RunTest(const TestParams& params) { |
| 26 ResourceLoadTimingInfo timing_info; |
| 27 timing_info.base_ticks = TimeTicks::FromInternalValue(params.net_base_time); |
| 28 timing_info.proxy_start = params.net_test_delta; |
| 29 timing_info.proxy_end = 0; |
| 30 timing_info.dns_start = 0; |
| 31 timing_info.dns_end = 0; |
| 32 timing_info.connect_start = 0; |
| 33 timing_info.connect_end = 0; |
| 34 timing_info.ssl_start = 0; |
| 35 timing_info.ssl_end = 0; |
| 36 timing_info.send_start = 0; |
| 37 timing_info.send_end = 0; |
| 38 timing_info.receive_headers_end = 0; |
| 39 |
| 40 return PopulateWebURLLoadTiming( |
| 41 timing_info, |
| 42 TimeTicks::FromInternalValue(params.ipc_request_time), |
| 43 TimeTicks::FromInternalValue(params.net_start_time), |
| 44 TimeTicks::FromInternalValue(params.net_end_time), |
| 45 TimeTicks::FromInternalValue(params.ipc_response_time)); |
| 46 } |
| 47 |
| 48 TEST(PopulateWebURLLoadTiming, NoSkew) { |
| 49 // All times are monotonic, so no adjustment should occur. |
| 50 TestParams p; |
| 51 p.ipc_request_time = 0; |
| 52 p.net_start_time = 1; |
| 53 p.net_end_time = 4; |
| 54 p.ipc_response_time = 5; |
| 55 p.net_base_time = 2; |
| 56 p.net_test_delta = 1; |
| 57 WebURLLoadTiming timing = RunTest(p); |
| 58 EXPECT_EQ(2.0e-6, timing.requestTime()); |
| 59 EXPECT_EQ(1, timing.proxyStart()); |
| 60 } |
| 61 |
| 62 TEST(PopulateWebURLLoadTiming, DoubleEndedSkew) { |
| 63 // |net_start_time| occurs before |ipc_request_time| and |net_end_time| occurs |
| 64 // after |ipc_response_time|. We must adjust both bounds and scale down the |
| 65 // delta. |net_base_time| is on the midpoint, so it doesn't change. The ratio |
| 66 // of local time to network time is 1:2, so we scale |net_test_delta| by half. |
| 67 TestParams p; |
| 68 p.ipc_request_time = 2; |
| 69 p.net_start_time = 0; |
| 70 p.net_end_time = 8; |
| 71 p.ipc_response_time = 6; |
| 72 p.net_base_time = 4; |
| 73 p.net_test_delta = 2; |
| 74 WebURLLoadTiming timing = RunTest(p); |
| 75 EXPECT_EQ(4.0e-6, timing.requestTime()); |
| 76 EXPECT_EQ(1, timing.proxyStart()); |
| 77 } |
| 78 |
| 79 TEST(PopulateWebURLLoadTiming, FrontEndSkew) { |
| 80 // |net_end_time| is coherent, but |net_start_time| is not. So we adjust the |
| 81 // lower bound and move |net_base_time| out. The scale factor is 2:3, but |
| 82 // since we use integers, the numbers truncate from 3.33 to 3 and 1.33 to 1. |
| 83 TestParams p; |
| 84 p.ipc_request_time = 2; |
| 85 p.net_start_time = 0; |
| 86 p.net_end_time = 6; |
| 87 p.ipc_response_time = 6; |
| 88 p.net_base_time = 2; |
| 89 p.net_test_delta = 2; |
| 90 WebURLLoadTiming timing = RunTest(p); |
| 91 EXPECT_EQ(3.0e-6, timing.requestTime()); |
| 92 EXPECT_EQ(1, timing.proxyStart()); |
| 93 } |
| 94 |
| 95 TEST(PopulateWebURLLoadTiming, BackEndSkew) { |
| 96 // Like the previous test, but |net_start_time| is coherent and |net_end_time| |
| 97 // is skewed. |
| 98 TestParams p; |
| 99 p.ipc_request_time = 0; |
| 100 p.net_start_time = 0; |
| 101 p.net_end_time = 6; |
| 102 p.ipc_response_time = 4; |
| 103 p.net_base_time = 2; |
| 104 p.net_test_delta = 2; |
| 105 WebURLLoadTiming timing = RunTest(p); |
| 106 EXPECT_EQ(1.0e-6, timing.requestTime()); |
| 107 EXPECT_EQ(1, timing.proxyStart()); |
| 108 } |
| 109 |
| 110 TEST(PopulateWebURLLoadTiming, Instantaneous) { |
| 111 // The bounds are all okay, but the |net_start_time| and |net_end_time| have |
| 112 // the same value. No adjustments should be made and no divide-by-zero errors |
| 113 // should occur. |
| 114 TestParams p; |
| 115 p.ipc_request_time = 0; |
| 116 p.net_start_time = 1; |
| 117 p.net_end_time = 1; |
| 118 p.ipc_response_time = 2; |
| 119 p.net_base_time = 1; |
| 120 p.net_test_delta = 0; |
| 121 WebURLLoadTiming timing = RunTest(p); |
| 122 EXPECT_EQ(1.0e-6, timing.requestTime()); |
| 123 EXPECT_EQ(0, timing.proxyStart()); |
| 124 } |
| 125 |
| 126 TEST(PopulateWebURLLoadTiming, DisjointInstantaneous) { |
| 127 // |ipc_request_time| and |ipc_response_time| are the same. No matter what the |
| 128 // other values are, they must fit within [ipc_request_time, |
| 129 // ipc_response_time]. So, all of the values should be adjusted so they are |
| 130 // exactly that value. |
| 131 TestParams p; |
| 132 p.ipc_request_time = 1; |
| 133 p.net_start_time = 2; |
| 134 p.net_end_time = 2; |
| 135 p.ipc_response_time = 1; |
| 136 p.net_base_time = 2; |
| 137 p.net_test_delta = 1; |
| 138 WebURLLoadTiming timing = RunTest(p); |
| 139 EXPECT_EQ(1.0e-6, timing.requestTime()); |
| 140 EXPECT_EQ(0, timing.proxyStart()); |
| 141 } |
| 142 |
| 143 } // namespace webkit_glue |
OLD | NEW |