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

Side by Side Diff: webkit/glue/weburlloader_impl_unittest.cc

Issue 7602023: Use a monotonic clock (TimeTicks) to report network times to WebCore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add explanation Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 initiation_time;
18 int64 start_time;
19 int64 end_time;
20 int64 callback_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.initiation_time),
43 TimeTicks::FromInternalValue(params.start_time),
44 TimeTicks::FromInternalValue(params.end_time),
45 TimeTicks::FromInternalValue(params.callback_time));
46 }
47
48 TEST(PopulateWebURLLoadTiming, NoSkew) {
49 // All times are monotonic, so no adjustment should occur.
50 TestParams p;
51 p.initiation_time = 0;
52 p.start_time = 1;
53 p.end_time = 4;
54 p.callback_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 // |start_time| occurs before |initiation_time| and |end_time| occurs after
64 // |callback_time|. We must adjust both bounds and scale down the delta.
65 // |net_base_time| is on the midpoint, so it doesn't change. The ratio of
66 // local time to network time is 1:2, so we scale |net_test_delta| by half.
67 TestParams p;
68 p.initiation_time = 2;
69 p.start_time = 0;
70 p.end_time = 8;
71 p.callback_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 // |end_time| is coherent, but |start_time| is not. So we adjust the lower
81 // bound and move |net_base_time| out. The scale factor is 2:3, but since we
82 // use integers, the numbers truncate from 3.33 to 3 and 1.33 to 1.
83 TestParams p;
84 p.initiation_time = 2;
85 p.start_time = 0;
86 p.end_time = 6;
87 p.callback_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 |start_time| is coherent and |end_time| is
97 // skewed.
98 TestParams p;
99 p.initiation_time = 0;
100 p.start_time = 0;
101 p.end_time = 6;
102 p.callback_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 |start_time| and |end_time| have the same
112 // value. No adjustments should be made and no divide-by-zero errors should
113 // occur.
114 TestParams p;
115 p.initiation_time = 0;
116 p.start_time = 1;
117 p.end_time = 1;
118 p.callback_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 // |initiation_time| and |callback_time| are the same. No matter what the
128 // other values are, they must fit withing [iniation_time, callback_time]. So,
129 // all of the values should be adjusted so they are exactly that value.
130 TestParams p;
131 p.initiation_time = 1;
132 p.start_time = 2;
133 p.end_time = 2;
134 p.callback_time = 1;
135 p.net_base_time = 2;
136 p.net_test_delta = 1;
137 WebURLLoadTiming timing = RunTest(p);
138 EXPECT_EQ(1.0e-6, timing.requestTime());
139 EXPECT_EQ(0, timing.proxyStart());
140 }
141
142 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698