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> |
10 | 11 |
11 namespace blink { | 12 namespace blink { |
12 | 13 |
13 class DocumentLoadTimingTest : public testing::Test { | 14 class DocumentLoadTimingTest : public testing::Test { |
14 }; | 15 }; |
15 | 16 |
16 TEST_F(DocumentLoadTimingTest, ensureValidNavigationStartAfterEmbedder) | 17 TEST_F(DocumentLoadTimingTest, ensureValidNavigationStartAfterEmbedder) |
17 { | 18 { |
18 OwnPtr<DummyPageHolder> dummyPage = DummyPageHolder::create(); | 19 std::unique_ptr<DummyPageHolder> dummyPage = DummyPageHolder::create(); |
19 DocumentLoadTiming timing(*(dummyPage->document().loader())); | 20 DocumentLoadTiming timing(*(dummyPage->document().loader())); |
20 | 21 |
21 double delta = -1000; | 22 double delta = -1000; |
22 double embedderNavigationStart = monotonicallyIncreasingTime() + delta; | 23 double embedderNavigationStart = monotonicallyIncreasingTime() + delta; |
23 timing.setNavigationStart(embedderNavigationStart); | 24 timing.setNavigationStart(embedderNavigationStart); |
24 | 25 |
25 double realWallTime = currentTime(); | 26 double realWallTime = currentTime(); |
26 double adjustedWallTime = timing.monotonicTimeToPseudoWallTime(timing.naviga
tionStart()); | 27 double adjustedWallTime = timing.monotonicTimeToPseudoWallTime(timing.naviga
tionStart()); |
27 | 28 |
28 EXPECT_NEAR(adjustedWallTime, realWallTime + delta, .001); | 29 EXPECT_NEAR(adjustedWallTime, realWallTime + delta, .001); |
29 } | 30 } |
30 | 31 |
31 TEST_F(DocumentLoadTimingTest, correctTimingDeltas) | 32 TEST_F(DocumentLoadTimingTest, correctTimingDeltas) |
32 { | 33 { |
33 OwnPtr<DummyPageHolder> dummyPage = DummyPageHolder::create(); | 34 std::unique_ptr<DummyPageHolder> dummyPage = DummyPageHolder::create(); |
34 DocumentLoadTiming timing(*(dummyPage->document().loader())); | 35 DocumentLoadTiming timing(*(dummyPage->document().loader())); |
35 | 36 |
36 double navigationStartDelta = -456; | 37 double navigationStartDelta = -456; |
37 double currentMonotonicTime = monotonicallyIncreasingTime(); | 38 double currentMonotonicTime = monotonicallyIncreasingTime(); |
38 double embedderNavigationStart = currentMonotonicTime + navigationStartDelta
; | 39 double embedderNavigationStart = currentMonotonicTime + navigationStartDelta
; |
39 | 40 |
40 timing.setNavigationStart(embedderNavigationStart); | 41 timing.setNavigationStart(embedderNavigationStart); |
41 | 42 |
42 // Super quick load! Expect the wall time reported by this event to be | 43 // Super quick load! Expect the wall time reported by this event to be |
43 // dominated by the navigationStartDelta, but similar to currentTime(). | 44 // dominated by the navigationStartDelta, but similar to currentTime(). |
44 timing.markLoadEventEnd(); | 45 timing.markLoadEventEnd(); |
45 double realWallLoadEventEnd = currentTime(); | 46 double realWallLoadEventEnd = currentTime(); |
46 double adjustedLoadEventEnd = timing.monotonicTimeToPseudoWallTime(timing.lo
adEventEnd()); | 47 double adjustedLoadEventEnd = timing.monotonicTimeToPseudoWallTime(timing.lo
adEventEnd()); |
47 | 48 |
48 EXPECT_NEAR(adjustedLoadEventEnd, realWallLoadEventEnd, .001); | 49 EXPECT_NEAR(adjustedLoadEventEnd, realWallLoadEventEnd, .001); |
49 | 50 |
50 double adjustedNavigationStart = timing.monotonicTimeToPseudoWallTime(timing
.navigationStart()); | 51 double adjustedNavigationStart = timing.monotonicTimeToPseudoWallTime(timing
.navigationStart()); |
51 EXPECT_NEAR(adjustedLoadEventEnd - adjustedNavigationStart, -navigationStart
Delta, .001); | 52 EXPECT_NEAR(adjustedLoadEventEnd - adjustedNavigationStart, -navigationStart
Delta, .001); |
52 } | 53 } |
53 | 54 |
54 } // namespace blink | 55 } // namespace blink |
OLD | NEW |