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 "chrome/browser/page_load_metrics/observers/tab_restore_page_load_metri
cs_observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/tab_restore_page_load_metri
cs_observer.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 }; | 41 }; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 class TabRestorePageLoadMetricsObserverTest | 45 class TabRestorePageLoadMetricsObserverTest |
46 : public page_load_metrics::PageLoadMetricsObserverTestHarness { | 46 : public page_load_metrics::PageLoadMetricsObserverTestHarness { |
47 public: | 47 public: |
48 TabRestorePageLoadMetricsObserverTest() {} | 48 TabRestorePageLoadMetricsObserverTest() {} |
49 | 49 |
50 void ResetTest() { | 50 void ResetTest() { |
| 51 page_load_metrics::InitPageLoadTimingForTest(&timing_); |
51 // Reset to the default testing state. Does not reset histogram state. | 52 // Reset to the default testing state. Does not reset histogram state. |
52 timing_.navigation_start = base::Time::FromDoubleT(1); | 53 timing_.navigation_start = base::Time::FromDoubleT(1); |
53 timing_.response_start = base::TimeDelta::FromSeconds(2); | 54 timing_.response_start = base::TimeDelta::FromSeconds(2); |
54 timing_.parse_timing.parse_start = base::TimeDelta::FromSeconds(3); | 55 timing_.parse_timing->parse_start = base::TimeDelta::FromSeconds(3); |
55 timing_.paint_timing.first_contentful_paint = | 56 timing_.paint_timing->first_contentful_paint = |
56 base::TimeDelta::FromSeconds(4); | 57 base::TimeDelta::FromSeconds(4); |
57 timing_.paint_timing.first_image_paint = base::TimeDelta::FromSeconds(5); | 58 timing_.paint_timing->first_image_paint = base::TimeDelta::FromSeconds(5); |
58 timing_.paint_timing.first_text_paint = base::TimeDelta::FromSeconds(6); | 59 timing_.paint_timing->first_text_paint = base::TimeDelta::FromSeconds(6); |
59 timing_.document_timing.load_event_start = base::TimeDelta::FromSeconds(7); | 60 timing_.document_timing->load_event_start = base::TimeDelta::FromSeconds(7); |
60 PopulateRequiredTimingFields(&timing_); | 61 PopulateRequiredTimingFields(&timing_); |
61 | 62 |
62 network_bytes_ = 0; | 63 network_bytes_ = 0; |
63 cache_bytes_ = 0; | 64 cache_bytes_ = 0; |
64 } | 65 } |
65 | 66 |
66 void SimulatePageLoad(bool is_restore, bool simulate_app_background) { | 67 void SimulatePageLoad(bool is_restore, bool simulate_app_background) { |
67 is_restore_ = is_restore; | 68 is_restore_ = is_restore; |
68 NavigateAndCommit(GURL(kDefaultTestUrl)); | 69 NavigateAndCommit(GURL(kDefaultTestUrl)); |
69 SimulateTimingUpdate(timing_); | 70 SimulateTimingUpdate(timing_); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 tracker->AddObserver(base::WrapUnique( | 119 tracker->AddObserver(base::WrapUnique( |
119 new TestTabRestorePageLoadMetricsObserver(is_restore_.value()))); | 120 new TestTabRestorePageLoadMetricsObserver(is_restore_.value()))); |
120 } | 121 } |
121 | 122 |
122 // Simulated byte usage since the last time the test was reset. | 123 // Simulated byte usage since the last time the test was reset. |
123 int64_t network_bytes_; | 124 int64_t network_bytes_; |
124 int64_t cache_bytes_; | 125 int64_t cache_bytes_; |
125 | 126 |
126 private: | 127 private: |
127 base::Optional<bool> is_restore_; | 128 base::Optional<bool> is_restore_; |
128 page_load_metrics::PageLoadTiming timing_; | 129 page_load_metrics::mojom::PageLoadTiming timing_; |
129 | 130 |
130 DISALLOW_COPY_AND_ASSIGN(TabRestorePageLoadMetricsObserverTest); | 131 DISALLOW_COPY_AND_ASSIGN(TabRestorePageLoadMetricsObserverTest); |
131 }; | 132 }; |
132 | 133 |
133 TEST_F(TabRestorePageLoadMetricsObserverTest, NotRestored) { | 134 TEST_F(TabRestorePageLoadMetricsObserverTest, NotRestored) { |
134 ResetTest(); | 135 ResetTest(); |
135 SimulatePageLoad(false /* is_restore */, false /* simulate_app_background */); | 136 SimulatePageLoad(false /* is_restore */, false /* simulate_app_background */); |
136 histogram_tester().ExpectTotalCount( | 137 histogram_tester().ExpectTotalCount( |
137 "PageLoad.Clients.TabRestore.Experimental.Bytes.Network", 0); | 138 "PageLoad.Clients.TabRestore.Experimental.Bytes.Network", 0); |
138 histogram_tester().ExpectTotalCount( | 139 histogram_tester().ExpectTotalCount( |
(...skipping 22 matching lines...) Expand all Loading... |
161 histogram_tester().ExpectUniqueSample( | 162 histogram_tester().ExpectUniqueSample( |
162 "PageLoad.Clients.TabRestore.Experimental.Bytes.Network", | 163 "PageLoad.Clients.TabRestore.Experimental.Bytes.Network", |
163 static_cast<int>(network_bytes_ / 1024), 1); | 164 static_cast<int>(network_bytes_ / 1024), 1); |
164 histogram_tester().ExpectUniqueSample( | 165 histogram_tester().ExpectUniqueSample( |
165 "PageLoad.Clients.TabRestore.Experimental.Bytes.Cache", | 166 "PageLoad.Clients.TabRestore.Experimental.Bytes.Cache", |
166 static_cast<int>(cache_bytes_ / 1024), 1); | 167 static_cast<int>(cache_bytes_ / 1024), 1); |
167 histogram_tester().ExpectUniqueSample( | 168 histogram_tester().ExpectUniqueSample( |
168 "PageLoad.Clients.TabRestore.Experimental.Bytes.Total", | 169 "PageLoad.Clients.TabRestore.Experimental.Bytes.Total", |
169 static_cast<int>((network_bytes_ + cache_bytes_) / 1024), 1); | 170 static_cast<int>((network_bytes_ + cache_bytes_) / 1024), 1); |
170 } | 171 } |
OLD | NEW |