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, OffsetMidpoints) { |
| 63 // All times are monotonic, but not centered. Adjust the |net_*| times so they |
| 64 // are centered within the |ipc_*| times. |
| 65 TestParams p; |
| 66 p.ipc_request_time = 0; |
| 67 p.net_start_time = 2; |
| 68 p.net_end_time = 5; |
| 69 p.ipc_response_time = 5; |
| 70 p.net_base_time = 3; |
| 71 p.net_test_delta = 1; |
| 72 WebURLLoadTiming timing = RunTest(p); |
| 73 EXPECT_EQ(2.0e-6, timing.requestTime()); |
| 74 EXPECT_EQ(1, timing.proxyStart()); |
| 75 } |
| 76 |
| 77 TEST(PopulateWebURLLoadTiming, DoubleEndedSkew) { |
| 78 // |net_start_time| occurs before |ipc_request_time| and |net_end_time| occurs |
| 79 // after |ipc_response_time|. We must adjust both bounds and scale down the |
| 80 // delta. |net_base_time| is on the midpoint, so it doesn't change. The ratio |
| 81 // of local time to network time is 1:2, so we scale |net_test_delta| by half. |
| 82 TestParams p; |
| 83 p.ipc_request_time = 2; |
| 84 p.net_start_time = 0; |
| 85 p.net_end_time = 8; |
| 86 p.ipc_response_time = 6; |
| 87 p.net_base_time = 4; |
| 88 p.net_test_delta = 2; |
| 89 WebURLLoadTiming timing = RunTest(p); |
| 90 EXPECT_EQ(4.0e-6, timing.requestTime()); |
| 91 EXPECT_EQ(1, timing.proxyStart()); |
| 92 } |
| 93 |
| 94 TEST(PopulateWebURLLoadTiming, FrontEndSkew) { |
| 95 // |net_end_time| is coherent, but |net_start_time| is not. So we adjust the |
| 96 // lower bound and move |net_base_time| out. The scale factor is 2:3, but |
| 97 // since we use integers, the numbers truncate from 3.33 to 3 and 1.33 to 1. |
| 98 TestParams p; |
| 99 p.ipc_request_time = 2; |
| 100 p.net_start_time = 0; |
| 101 p.net_end_time = 6; |
| 102 p.ipc_response_time = 6; |
| 103 p.net_base_time = 2; |
| 104 p.net_test_delta = 2; |
| 105 WebURLLoadTiming timing = RunTest(p); |
| 106 EXPECT_EQ(3.0e-6, timing.requestTime()); |
| 107 EXPECT_EQ(1, timing.proxyStart()); |
| 108 } |
| 109 |
| 110 TEST(PopulateWebURLLoadTiming, BackEndSkew) { |
| 111 // Like the previous test, but |net_start_time| is coherent and |net_end_time| |
| 112 // is skewed. |
| 113 TestParams p; |
| 114 p.ipc_request_time = 0; |
| 115 p.net_start_time = 0; |
| 116 p.net_end_time = 6; |
| 117 p.ipc_response_time = 4; |
| 118 p.net_base_time = 2; |
| 119 p.net_test_delta = 2; |
| 120 WebURLLoadTiming timing = RunTest(p); |
| 121 EXPECT_EQ(1.0e-6, timing.requestTime()); |
| 122 EXPECT_EQ(1, timing.proxyStart()); |
| 123 } |
| 124 |
| 125 TEST(PopulateWebURLLoadTiming, Instantaneous) { |
| 126 // The bounds are all okay, but the |net_start_time| and |net_end_time| have |
| 127 // the same value. No adjustments should be made and no divide-by-zero errors |
| 128 // should occur. |
| 129 TestParams p; |
| 130 p.ipc_request_time = 0; |
| 131 p.net_start_time = 1; |
| 132 p.net_end_time = 1; |
| 133 p.ipc_response_time = 2; |
| 134 p.net_base_time = 1; |
| 135 p.net_test_delta = 0; |
| 136 WebURLLoadTiming timing = RunTest(p); |
| 137 EXPECT_EQ(1.0e-6, timing.requestTime()); |
| 138 EXPECT_EQ(0, timing.proxyStart()); |
| 139 } |
| 140 |
| 141 TEST(PopulateWebURLLoadTiming, OffsetInstantaneous) { |
| 142 // The bounds are all okay, but the |net_start_time| and |net_end_time| have |
| 143 // the same value and are offset from the midpoint of |ipc_request_time| and |
| 144 // |ipc_response_time|. An offset should be applied to make the midpoints line |
| 145 // up. |
| 146 TestParams p; |
| 147 p.ipc_request_time = 0; |
| 148 p.net_start_time = 2; |
| 149 p.net_end_time = 2; |
| 150 p.ipc_response_time = 2; |
| 151 p.net_base_time = 2; |
| 152 p.net_test_delta = 0; |
| 153 WebURLLoadTiming timing = RunTest(p); |
| 154 EXPECT_EQ(1.0e-6, timing.requestTime()); |
| 155 EXPECT_EQ(0, timing.proxyStart()); |
| 156 } |
| 157 |
| 158 TEST(PopulateWebURLLoadTiming, DisjointInstantaneous) { |
| 159 // |ipc_request_time| and |ipc_response_time| are the same. No matter what the |
| 160 // other values are, they must fit within [ipc_request_time, |
| 161 // ipc_response_time]. So, all of the values should be adjusted so they are |
| 162 // exactly that value. |
| 163 TestParams p; |
| 164 p.ipc_request_time = 1; |
| 165 p.net_start_time = 2; |
| 166 p.net_end_time = 2; |
| 167 p.ipc_response_time = 1; |
| 168 p.net_base_time = 2; |
| 169 p.net_test_delta = 0; |
| 170 WebURLLoadTiming timing = RunTest(p); |
| 171 EXPECT_EQ(1.0e-6, timing.requestTime()); |
| 172 EXPECT_EQ(0, timing.proxyStart()); |
| 173 } |
| 174 |
| 175 TEST(PopulateWebURLLoadTiming, RoundingNearEdges) { |
| 176 // Verify that rounding never causes a value to appear outside the given |
| 177 // |ipc_*| range. |
| 178 const int kMaxRange = 100; |
| 179 for (int i = 0; i < kMaxRange; ++i) { |
| 180 for (int j = 0; j < kMaxRange; ++j) { |
| 181 TestParams p; |
| 182 p.ipc_request_time = 0; |
| 183 p.net_start_time = 0; |
| 184 p.net_end_time = j; |
| 185 p.ipc_response_time = i; |
| 186 p.net_base_time = 0; |
| 187 p.net_test_delta = j; |
| 188 WebURLLoadTiming timing = RunTest(p); |
| 189 EXPECT_LE(0.0e-6, timing.requestTime()); |
| 190 EXPECT_GE(i, timing.proxyStart()); |
| 191 } |
| 192 } |
| 193 } |
| 194 |
| 195 } // namespace webkit_glue |
OLD | NEW |