OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/loader/DocumentLoadTiming.h" | 5 #include "core/loader/DocumentLoadTiming.h" |
6 | 6 |
7 #include "core/loader/DocumentLoader.h" | 7 #include "core/loader/DocumentLoader.h" |
8 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include <memory> | |
11 | 10 |
12 namespace blink { | 11 namespace blink { |
13 | 12 |
14 class DocumentLoadTimingTest : public testing::Test { | 13 class DocumentLoadTimingTest : public testing::Test { |
15 }; | 14 }; |
16 | 15 |
17 TEST_F(DocumentLoadTimingTest, ensureValidNavigationStartAfterEmbedder) | 16 TEST_F(DocumentLoadTimingTest, ensureValidNavigationStartAfterEmbedder) |
18 { | 17 { |
19 std::unique_ptr<DummyPageHolder> dummyPage = DummyPageHolder::create(); | 18 OwnPtr<DummyPageHolder> dummyPage = DummyPageHolder::create(); |
20 DocumentLoadTiming timing(*(dummyPage->document().loader())); | 19 DocumentLoadTiming timing(*(dummyPage->document().loader())); |
21 | 20 |
22 double delta = -1000; | 21 double delta = -1000; |
23 double embedderNavigationStart = monotonicallyIncreasingTime() + delta; | 22 double embedderNavigationStart = monotonicallyIncreasingTime() + delta; |
24 timing.setNavigationStart(embedderNavigationStart); | 23 timing.setNavigationStart(embedderNavigationStart); |
25 | 24 |
26 double realWallTime = currentTime(); | 25 double realWallTime = currentTime(); |
27 double adjustedWallTime = timing.monotonicTimeToPseudoWallTime(timing.naviga
tionStart()); | 26 double adjustedWallTime = timing.monotonicTimeToPseudoWallTime(timing.naviga
tionStart()); |
28 | 27 |
29 EXPECT_NEAR(adjustedWallTime, realWallTime + delta, .001); | 28 EXPECT_NEAR(adjustedWallTime, realWallTime + delta, .001); |
30 } | 29 } |
31 | 30 |
32 TEST_F(DocumentLoadTimingTest, correctTimingDeltas) | 31 TEST_F(DocumentLoadTimingTest, correctTimingDeltas) |
33 { | 32 { |
34 std::unique_ptr<DummyPageHolder> dummyPage = DummyPageHolder::create(); | 33 OwnPtr<DummyPageHolder> dummyPage = DummyPageHolder::create(); |
35 DocumentLoadTiming timing(*(dummyPage->document().loader())); | 34 DocumentLoadTiming timing(*(dummyPage->document().loader())); |
36 | 35 |
37 double navigationStartDelta = -456; | 36 double navigationStartDelta = -456; |
38 double currentMonotonicTime = monotonicallyIncreasingTime(); | 37 double currentMonotonicTime = monotonicallyIncreasingTime(); |
39 double embedderNavigationStart = currentMonotonicTime + navigationStartDelta
; | 38 double embedderNavigationStart = currentMonotonicTime + navigationStartDelta
; |
40 | 39 |
41 timing.setNavigationStart(embedderNavigationStart); | 40 timing.setNavigationStart(embedderNavigationStart); |
42 | 41 |
43 // Super quick load! Expect the wall time reported by this event to be | 42 // Super quick load! Expect the wall time reported by this event to be |
44 // dominated by the navigationStartDelta, but similar to currentTime(). | 43 // dominated by the navigationStartDelta, but similar to currentTime(). |
45 timing.markLoadEventEnd(); | 44 timing.markLoadEventEnd(); |
46 double realWallLoadEventEnd = currentTime(); | 45 double realWallLoadEventEnd = currentTime(); |
47 double adjustedLoadEventEnd = timing.monotonicTimeToPseudoWallTime(timing.lo
adEventEnd()); | 46 double adjustedLoadEventEnd = timing.monotonicTimeToPseudoWallTime(timing.lo
adEventEnd()); |
48 | 47 |
49 EXPECT_NEAR(adjustedLoadEventEnd, realWallLoadEventEnd, .001); | 48 EXPECT_NEAR(adjustedLoadEventEnd, realWallLoadEventEnd, .001); |
50 | 49 |
51 double adjustedNavigationStart = timing.monotonicTimeToPseudoWallTime(timing
.navigationStart()); | 50 double adjustedNavigationStart = timing.monotonicTimeToPseudoWallTime(timing
.navigationStart()); |
52 EXPECT_NEAR(adjustedLoadEventEnd - adjustedNavigationStart, -navigationStart
Delta, .001); | 51 EXPECT_NEAR(adjustedLoadEventEnd - adjustedNavigationStart, -navigationStart
Delta, .001); |
53 } | 52 } |
54 | 53 |
55 } // namespace blink | 54 } // namespace blink |
OLD | NEW |