| 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..c8741ceb48d3dc1105f98e4b5ea7d670bcb803f8
|
| --- /dev/null
|
| +++ b/webkit/glue/weburlloader_impl_unittest.cc
|
| @@ -0,0 +1,142 @@
|
| +// 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 initiation_time;
|
| + int64 start_time;
|
| + int64 end_time;
|
| + int64 callback_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.initiation_time),
|
| + TimeTicks::FromInternalValue(params.start_time),
|
| + TimeTicks::FromInternalValue(params.end_time),
|
| + TimeTicks::FromInternalValue(params.callback_time));
|
| +}
|
| +
|
| +TEST(PopulateWebURLLoadTiming, NoSkew) {
|
| + // All times are monotonic, so no adjustment should occur.
|
| + TestParams p;
|
| + p.initiation_time = 0;
|
| + p.start_time = 1;
|
| + p.end_time = 4;
|
| + p.callback_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) {
|
| + // |start_time| occurs before |initiation_time| and |end_time| occurs after
|
| + // |callback_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.initiation_time = 2;
|
| + p.start_time = 0;
|
| + p.end_time = 8;
|
| + p.callback_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) {
|
| + // |end_time| is coherent, but |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.initiation_time = 2;
|
| + p.start_time = 0;
|
| + p.end_time = 6;
|
| + p.callback_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 |start_time| is coherent and |end_time| is
|
| + // skewed.
|
| + TestParams p;
|
| + p.initiation_time = 0;
|
| + p.start_time = 0;
|
| + p.end_time = 6;
|
| + p.callback_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 |start_time| and |end_time| have the same
|
| + // value. No adjustments should be made and no divide-by-zero errors should
|
| + // occur.
|
| + TestParams p;
|
| + p.initiation_time = 0;
|
| + p.start_time = 1;
|
| + p.end_time = 1;
|
| + p.callback_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) {
|
| + // |initiation_time| and |callback_time| are the same. No matter what the
|
| + // other values are, they must fit withing [iniation_time, callback_time]. So,
|
| + // all of the values should be adjusted so they are exactly that value.
|
| + TestParams p;
|
| + p.initiation_time = 1;
|
| + p.start_time = 2;
|
| + p.end_time = 2;
|
| + p.callback_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
|
|
|