| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" | 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 const char kDefaultTestUrl[] = "https://google.com/"; | 28 const char kDefaultTestUrl[] = "https://google.com/"; |
| 29 const char kDefaultTestUrlAnchor[] = "https://google.com/#samepage"; | 29 const char kDefaultTestUrlAnchor[] = "https://google.com/#samepage"; |
| 30 const char kDefaultTestUrl2[] = "https://whatever.com/"; | 30 const char kDefaultTestUrl2[] = "https://whatever.com/"; |
| 31 | 31 |
| 32 // Simple PageLoadMetricsObserver that copies observed PageLoadTimings into the | 32 // Simple PageLoadMetricsObserver that copies observed PageLoadTimings into the |
| 33 // provided std::vector, so they can be analyzed by unit tests. | 33 // provided std::vector, so they can be analyzed by unit tests. |
| 34 class TestPageLoadMetricsObserver : public PageLoadMetricsObserver { | 34 class TestPageLoadMetricsObserver : public PageLoadMetricsObserver { |
| 35 public: | 35 public: |
| 36 explicit TestPageLoadMetricsObserver( | 36 explicit TestPageLoadMetricsObserver( |
| 37 std::vector<PageLoadTiming>* observed_timings, | 37 std::vector<PageLoadTiming>* updated_timings, |
| 38 std::vector<PageLoadTiming>* complete_timings, |
| 38 std::vector<GURL>* observed_committed_urls) | 39 std::vector<GURL>* observed_committed_urls) |
| 39 : observed_timings_(observed_timings), | 40 : updated_timings_(updated_timings), |
| 41 complete_timings_(complete_timings), |
| 40 observed_committed_urls_(observed_committed_urls) {} | 42 observed_committed_urls_(observed_committed_urls) {} |
| 41 | 43 |
| 42 void OnStart(content::NavigationHandle* navigation_handle, | 44 void OnStart(content::NavigationHandle* navigation_handle, |
| 43 const GURL& currently_committed_url) override { | 45 const GURL& currently_committed_url) override { |
| 44 observed_committed_urls_->push_back(currently_committed_url); | 46 observed_committed_urls_->push_back(currently_committed_url); |
| 45 } | 47 } |
| 46 | 48 |
| 49 void OnTimingUpdate(const PageLoadTiming& timing, |
| 50 const PageLoadExtraInfo& extra_info) override { |
| 51 updated_timings_->push_back(timing); |
| 52 } |
| 53 |
| 47 void OnComplete(const PageLoadTiming& timing, | 54 void OnComplete(const PageLoadTiming& timing, |
| 48 const PageLoadExtraInfo& extra_info) override { | 55 const PageLoadExtraInfo& extra_info) override { |
| 49 observed_timings_->push_back(timing); | 56 complete_timings_->push_back(timing); |
| 50 } | 57 } |
| 51 | 58 |
| 52 private: | 59 private: |
| 53 std::vector<PageLoadTiming>* const observed_timings_; | 60 std::vector<PageLoadTiming>* const updated_timings_; |
| 61 std::vector<PageLoadTiming>* const complete_timings_; |
| 54 std::vector<GURL>* const observed_committed_urls_; | 62 std::vector<GURL>* const observed_committed_urls_; |
| 55 }; | 63 }; |
| 56 | 64 |
| 57 class TestPageLoadMetricsEmbedderInterface | 65 class TestPageLoadMetricsEmbedderInterface |
| 58 : public PageLoadMetricsEmbedderInterface { | 66 : public PageLoadMetricsEmbedderInterface { |
| 59 public: | 67 public: |
| 60 TestPageLoadMetricsEmbedderInterface() : is_prerendering_(false) {} | 68 TestPageLoadMetricsEmbedderInterface() : is_prerendering_(false) {} |
| 61 | 69 |
| 62 bool IsPrerendering(content::WebContents* web_contents) override { | 70 bool IsPrerendering(content::WebContents* web_contents) override { |
| 63 return is_prerendering_; | 71 return is_prerendering_; |
| 64 } | 72 } |
| 65 void set_is_prerendering(bool is_prerendering) { | 73 void set_is_prerendering(bool is_prerendering) { |
| 66 is_prerendering_ = is_prerendering; | 74 is_prerendering_ = is_prerendering; |
| 67 } | 75 } |
| 68 void RegisterObservers(PageLoadTracker* tracker) override { | 76 void RegisterObservers(PageLoadTracker* tracker) override { |
| 69 tracker->AddObserver(base::WrapUnique(new TestPageLoadMetricsObserver( | 77 tracker->AddObserver(base::WrapUnique(new TestPageLoadMetricsObserver( |
| 70 &observed_timings_, &observed_committed_urls_))); | 78 &updated_timings_, &complete_timings_, &observed_committed_urls_))); |
| 71 } | 79 } |
| 72 const std::vector<PageLoadTiming>& observed_timings() const { | 80 const std::vector<PageLoadTiming>& updated_timings() const { |
| 73 return observed_timings_; | 81 return updated_timings_; |
| 82 } |
| 83 const std::vector<PageLoadTiming>& complete_timings() const { |
| 84 return complete_timings_; |
| 74 } | 85 } |
| 75 | 86 |
| 76 // currently_committed_urls passed to OnStart(). | 87 // currently_committed_urls passed to OnStart(). |
| 77 const std::vector<GURL>& observed_committed_urls_from_on_start() const { | 88 const std::vector<GURL>& observed_committed_urls_from_on_start() const { |
| 78 return observed_committed_urls_; | 89 return observed_committed_urls_; |
| 79 } | 90 } |
| 80 | 91 |
| 81 private: | 92 private: |
| 82 std::vector<PageLoadTiming> observed_timings_; | 93 std::vector<PageLoadTiming> updated_timings_; |
| 94 std::vector<PageLoadTiming> complete_timings_; |
| 83 std::vector<GURL> observed_committed_urls_; | 95 std::vector<GURL> observed_committed_urls_; |
| 84 bool is_prerendering_; | 96 bool is_prerendering_; |
| 85 }; | 97 }; |
| 86 | 98 |
| 87 } // namespace | 99 } // namespace |
| 88 | 100 |
| 89 class MetricsWebContentsObserverTest | 101 class MetricsWebContentsObserverTest |
| 90 : public content::RenderViewHostTestHarness { | 102 : public content::RenderViewHostTestHarness { |
| 91 public: | 103 public: |
| 92 MetricsWebContentsObserverTest() : num_errors_(0) {} | 104 MetricsWebContentsObserverTest() : num_errors_(0) {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 122 | 134 |
| 123 void CheckTotalErrorEvents() { | 135 void CheckTotalErrorEvents() { |
| 124 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, num_errors_); | 136 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, num_errors_); |
| 125 } | 137 } |
| 126 | 138 |
| 127 void CheckNoErrorEvents() { | 139 void CheckNoErrorEvents() { |
| 128 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, 0); | 140 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, 0); |
| 129 } | 141 } |
| 130 | 142 |
| 131 void AssertNoNonEmptyTimingReported() { | 143 void AssertNoNonEmptyTimingReported() { |
| 132 ASSERT_FALSE(embedder_interface_->observed_timings().empty()); | 144 ASSERT_FALSE(embedder_interface_->complete_timings().empty()); |
| 133 for (const auto& timing : embedder_interface_->observed_timings()) { | 145 for (const auto& timing : embedder_interface_->complete_timings()) { |
| 134 ASSERT_TRUE(timing.IsEmpty()); | 146 ASSERT_TRUE(timing.IsEmpty()); |
| 135 } | 147 } |
| 136 } | 148 } |
| 137 | 149 |
| 138 void AssertNonEmptyTimingsReported(size_t expected_non_empty_timings) { | 150 void AssertNonEmptyTimingsReported(size_t expected_non_empty_timings) { |
| 139 ASSERT_GE(embedder_interface_->observed_timings().size(), | 151 ASSERT_GE(embedder_interface_->complete_timings().size(), |
| 140 expected_non_empty_timings); | 152 expected_non_empty_timings); |
| 141 size_t actual_non_empty_timings = 0; | 153 size_t actual_non_empty_timings = 0; |
| 142 for (const auto& timing : embedder_interface_->observed_timings()) { | 154 for (const auto& timing : embedder_interface_->complete_timings()) { |
| 143 if (!timing.IsEmpty()) { | 155 if (!timing.IsEmpty()) { |
| 144 ++actual_non_empty_timings; | 156 ++actual_non_empty_timings; |
| 145 } | 157 } |
| 146 } | 158 } |
| 147 ASSERT_EQ(expected_non_empty_timings, actual_non_empty_timings); | 159 ASSERT_EQ(expected_non_empty_timings, actual_non_empty_timings); |
| 160 ASSERT_GE(embedder_interface_->updated_timings().size(), |
| 161 actual_non_empty_timings); |
| 148 } | 162 } |
| 149 | 163 |
| 150 void AssertNoTimingReported() { | 164 int CountCompleteTimingReported() { |
| 151 ASSERT_TRUE(embedder_interface_->observed_timings().empty()); | 165 return embedder_interface_->complete_timings().size(); |
| 166 } |
| 167 int CountUpdatedTimingReported() { |
| 168 return embedder_interface_->updated_timings().size(); |
| 152 } | 169 } |
| 153 | 170 |
| 154 const std::vector<GURL>& observed_committed_urls_from_on_start() const { | 171 const std::vector<GURL>& observed_committed_urls_from_on_start() const { |
| 155 return embedder_interface_->observed_committed_urls_from_on_start(); | 172 return embedder_interface_->observed_committed_urls_from_on_start(); |
| 156 } | 173 } |
| 157 | 174 |
| 158 protected: | 175 protected: |
| 159 base::HistogramTester histogram_tester_; | 176 base::HistogramTester histogram_tester_; |
| 160 TestPageLoadMetricsEmbedderInterface* embedder_interface_; | 177 TestPageLoadMetricsEmbedderInterface* embedder_interface_; |
| 161 std::unique_ptr<MetricsWebContentsObserver> observer_; | 178 std::unique_ptr<MetricsWebContentsObserver> observer_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 timing.response_start = base::TimeDelta::FromMilliseconds(2); | 189 timing.response_start = base::TimeDelta::FromMilliseconds(2); |
| 173 | 190 |
| 174 content::WebContentsTester* web_contents_tester = | 191 content::WebContentsTester* web_contents_tester = |
| 175 content::WebContentsTester::For(web_contents()); | 192 content::WebContentsTester::For(web_contents()); |
| 176 | 193 |
| 177 ASSERT_TRUE(observed_committed_urls_from_on_start().empty()); | 194 ASSERT_TRUE(observed_committed_urls_from_on_start().empty()); |
| 178 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 195 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 179 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size()); | 196 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size()); |
| 180 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty()); | 197 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty()); |
| 181 | 198 |
| 199 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| 182 SimulateTimingUpdate(timing); | 200 SimulateTimingUpdate(timing); |
| 183 AssertNoTimingReported(); | 201 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 202 ASSERT_EQ(0, CountCompleteTimingReported()); |
| 184 | 203 |
| 185 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 204 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 186 AssertNonEmptyTimingsReported(1); | 205 AssertNonEmptyTimingsReported(1); |
| 187 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size()); | 206 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size()); |
| 188 ASSERT_EQ(kDefaultTestUrl, | 207 ASSERT_EQ(kDefaultTestUrl, |
| 189 observed_committed_urls_from_on_start().at(1).spec()); | 208 observed_committed_urls_from_on_start().at(1).spec()); |
| 209 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 190 | 210 |
| 191 CheckNoErrorEvents(); | 211 CheckNoErrorEvents(); |
| 192 } | 212 } |
| 193 | 213 |
| 194 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) { | 214 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) { |
| 195 PageLoadTiming timing; | 215 PageLoadTiming timing; |
| 196 timing.navigation_start = base::Time::FromDoubleT(1); | 216 timing.navigation_start = base::Time::FromDoubleT(1); |
| 197 | 217 |
| 198 content::WebContentsTester* web_contents_tester = | 218 content::WebContentsTester* web_contents_tester = |
| 199 content::WebContentsTester::For(web_contents()); | 219 content::WebContentsTester::For(web_contents()); |
| 200 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 220 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 201 | 221 |
| 202 content::RenderFrameHostTester* rfh_tester = | 222 content::RenderFrameHostTester* rfh_tester = |
| 203 content::RenderFrameHostTester::For(main_rfh()); | 223 content::RenderFrameHostTester::For(main_rfh()); |
| 204 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); | 224 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); |
| 205 | 225 |
| 206 content::RenderFrameHostTester* subframe_tester = | 226 content::RenderFrameHostTester* subframe_tester = |
| 207 content::RenderFrameHostTester::For(subframe); | 227 content::RenderFrameHostTester::For(subframe); |
| 208 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); | 228 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); |
| 209 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); | 229 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); |
| 210 SimulateTimingUpdate(timing, subframe); | 230 SimulateTimingUpdate(timing, subframe); |
| 211 subframe_tester->SimulateNavigationStop(); | 231 subframe_tester->SimulateNavigationStop(); |
| 212 | 232 |
| 213 // Navigate again to see if the timing updated for a subframe message. | 233 // Navigate again to see if the timing updated for a subframe message. |
| 214 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 234 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 215 | 235 |
| 236 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| 216 AssertNoNonEmptyTimingReported(); | 237 AssertNoNonEmptyTimingReported(); |
| 217 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1); | 238 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1); |
| 218 CheckTotalErrorEvents(); | 239 CheckTotalErrorEvents(); |
| 219 } | 240 } |
| 220 | 241 |
| 221 TEST_F(MetricsWebContentsObserverTest, SamePageNoTrigger) { | 242 TEST_F(MetricsWebContentsObserverTest, SamePageNoTrigger) { |
| 222 PageLoadTiming timing; | 243 PageLoadTiming timing; |
| 223 timing.navigation_start = base::Time::FromDoubleT(1); | 244 timing.navigation_start = base::Time::FromDoubleT(1); |
| 224 | 245 |
| 225 content::WebContentsTester* web_contents_tester = | 246 content::WebContentsTester* web_contents_tester = |
| 226 content::WebContentsTester::For(web_contents()); | 247 content::WebContentsTester::For(web_contents()); |
| 227 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 248 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 249 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| 228 SimulateTimingUpdate(timing); | 250 SimulateTimingUpdate(timing); |
| 251 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 229 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); | 252 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); |
| 230 // A same page navigation shouldn't trigger logging UMA for the original. | 253 // A same page navigation shouldn't trigger logging UMA for the original. |
| 254 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 231 AssertNoNonEmptyTimingReported(); | 255 AssertNoNonEmptyTimingReported(); |
| 232 CheckNoErrorEvents(); | 256 CheckNoErrorEvents(); |
| 233 } | 257 } |
| 234 | 258 |
| 235 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) { | 259 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) { |
| 236 PageLoadTiming timing; | 260 PageLoadTiming timing; |
| 237 timing.navigation_start = base::Time::FromDoubleT(1); | 261 timing.navigation_start = base::Time::FromDoubleT(1); |
| 238 | 262 |
| 239 content::WebContentsTester* web_contents_tester = | 263 content::WebContentsTester* web_contents_tester = |
| 240 content::WebContentsTester::For(web_contents()); | 264 content::WebContentsTester::For(web_contents()); |
| 241 embedder_interface_->set_is_prerendering(true); | 265 embedder_interface_->set_is_prerendering(true); |
| 242 | 266 |
| 243 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 267 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 244 SimulateTimingUpdate(timing); | 268 SimulateTimingUpdate(timing); |
| 245 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 269 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 246 AssertNoTimingReported(); | 270 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| 271 ASSERT_EQ(0, CountCompleteTimingReported()); |
| 247 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); | 272 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); |
| 248 CheckTotalErrorEvents(); | 273 CheckTotalErrorEvents(); |
| 249 } | 274 } |
| 250 | 275 |
| 251 TEST_F(MetricsWebContentsObserverTest, DontLogIrrelevantNavigation) { | 276 TEST_F(MetricsWebContentsObserverTest, DontLogIrrelevantNavigation) { |
| 252 PageLoadTiming timing; | 277 PageLoadTiming timing; |
| 253 timing.navigation_start = base::Time::FromDoubleT(10); | 278 timing.navigation_start = base::Time::FromDoubleT(10); |
| 254 | 279 |
| 255 content::WebContentsTester* web_contents_tester = | 280 content::WebContentsTester* web_contents_tester = |
| 256 content::WebContentsTester::For(web_contents()); | 281 content::WebContentsTester::For(web_contents()); |
| 257 | 282 |
| 258 GURL about_blank_url = GURL("about:blank"); | 283 GURL about_blank_url = GURL("about:blank"); |
| 259 web_contents_tester->NavigateAndCommit(about_blank_url); | 284 web_contents_tester->NavigateAndCommit(about_blank_url); |
| 260 SimulateTimingUpdate(timing); | 285 SimulateTimingUpdate(timing); |
| 286 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| 261 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 287 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 288 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| 289 ASSERT_EQ(0, CountCompleteTimingReported()); |
| 262 | 290 |
| 263 CheckErrorEvent(ERR_IPC_FROM_BAD_URL_SCHEME, 1); | 291 CheckErrorEvent(ERR_IPC_FROM_BAD_URL_SCHEME, 1); |
| 264 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); | 292 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); |
| 265 CheckTotalErrorEvents(); | 293 CheckTotalErrorEvents(); |
| 266 } | 294 } |
| 267 | 295 |
| 268 TEST_F(MetricsWebContentsObserverTest, NotInMainError) { | 296 TEST_F(MetricsWebContentsObserverTest, NotInMainError) { |
| 269 PageLoadTiming timing; | 297 PageLoadTiming timing; |
| 270 timing.navigation_start = base::Time::FromDoubleT(1); | 298 timing.navigation_start = base::Time::FromDoubleT(1); |
| 271 | 299 |
| 272 content::WebContentsTester* web_contents_tester = | 300 content::WebContentsTester* web_contents_tester = |
| 273 content::WebContentsTester::For(web_contents()); | 301 content::WebContentsTester::For(web_contents()); |
| 274 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 302 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 275 | 303 |
| 276 content::RenderFrameHostTester* rfh_tester = | 304 content::RenderFrameHostTester* rfh_tester = |
| 277 content::RenderFrameHostTester::For(main_rfh()); | 305 content::RenderFrameHostTester::For(main_rfh()); |
| 278 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); | 306 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); |
| 279 | 307 |
| 280 content::RenderFrameHostTester* subframe_tester = | 308 content::RenderFrameHostTester* subframe_tester = |
| 281 content::RenderFrameHostTester::For(subframe); | 309 content::RenderFrameHostTester::For(subframe); |
| 282 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); | 310 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); |
| 283 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); | 311 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); |
| 284 SimulateTimingUpdate(timing, subframe); | 312 SimulateTimingUpdate(timing, subframe); |
| 285 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1); | 313 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1); |
| 286 CheckTotalErrorEvents(); | 314 CheckTotalErrorEvents(); |
| 315 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| 316 ASSERT_EQ(0, CountCompleteTimingReported()); |
| 287 } | 317 } |
| 288 | 318 |
| 289 TEST_F(MetricsWebContentsObserverTest, BadIPC) { | 319 TEST_F(MetricsWebContentsObserverTest, BadIPC) { |
| 290 PageLoadTiming timing; | 320 PageLoadTiming timing; |
| 291 timing.navigation_start = base::Time::FromDoubleT(10); | 321 timing.navigation_start = base::Time::FromDoubleT(10); |
| 292 PageLoadTiming timing2; | 322 PageLoadTiming timing2; |
| 293 timing2.navigation_start = base::Time::FromDoubleT(100); | 323 timing2.navigation_start = base::Time::FromDoubleT(100); |
| 294 | 324 |
| 295 content::WebContentsTester* web_contents_tester = | 325 content::WebContentsTester* web_contents_tester = |
| 296 content::WebContentsTester::For(web_contents()); | 326 content::WebContentsTester::For(web_contents()); |
| 297 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 327 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 298 | 328 |
| 299 SimulateTimingUpdate(timing); | 329 SimulateTimingUpdate(timing); |
| 330 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 300 SimulateTimingUpdate(timing2); | 331 SimulateTimingUpdate(timing2); |
| 332 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 301 | 333 |
| 302 CheckErrorEvent(ERR_BAD_TIMING_IPC, 1); | 334 CheckErrorEvent(ERR_BAD_TIMING_IPC, 1); |
| 303 CheckTotalErrorEvents(); | 335 CheckTotalErrorEvents(); |
| 304 } | 336 } |
| 305 | 337 |
| 306 TEST_F(MetricsWebContentsObserverTest, ObservePartialNavigation) { | 338 TEST_F(MetricsWebContentsObserverTest, ObservePartialNavigation) { |
| 307 // Delete the observer for this test, add it once the navigation has started. | 339 // Delete the observer for this test, add it once the navigation has started. |
| 308 observer_.reset(); | 340 observer_.reset(); |
| 309 PageLoadTiming timing; | 341 PageLoadTiming timing; |
| 310 timing.navigation_start = base::Time::FromDoubleT(10); | 342 timing.navigation_start = base::Time::FromDoubleT(10); |
| 311 | 343 |
| 312 content::WebContentsTester* web_contents_tester = | 344 content::WebContentsTester* web_contents_tester = |
| 313 content::WebContentsTester::For(web_contents()); | 345 content::WebContentsTester::For(web_contents()); |
| 314 content::RenderFrameHostTester* rfh_tester = | 346 content::RenderFrameHostTester* rfh_tester = |
| 315 content::RenderFrameHostTester::For(main_rfh()); | 347 content::RenderFrameHostTester::For(main_rfh()); |
| 316 | 348 |
| 317 // Start the navigation, then start observing the web contents. This used to | 349 // Start the navigation, then start observing the web contents. This used to |
| 318 // crash us. Make sure we bail out and don't log histograms. | 350 // crash us. Make sure we bail out and don't log histograms. |
| 319 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); | 351 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); |
| 320 AttachObserver(); | 352 AttachObserver(); |
| 321 rfh_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl)); | 353 rfh_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl)); |
| 322 | 354 |
| 323 SimulateTimingUpdate(timing); | 355 SimulateTimingUpdate(timing); |
| 324 | 356 |
| 325 // Navigate again to force histogram logging. | 357 // Navigate again to force histogram logging. |
| 326 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 358 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 327 AssertNoTimingReported(); | 359 ASSERT_EQ(0, CountCompleteTimingReported()); |
| 360 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| 328 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); | 361 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); |
| 329 CheckTotalErrorEvents(); | 362 CheckTotalErrorEvents(); |
| 330 } | 363 } |
| 331 | 364 |
| 332 TEST_F(MetricsWebContentsObserverTest, DontLogAbortChains) { | 365 TEST_F(MetricsWebContentsObserverTest, DontLogAbortChains) { |
| 333 NavigateAndCommit(GURL(kDefaultTestUrl)); | 366 NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 334 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 367 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 335 NavigateAndCommit(GURL(kDefaultTestUrl)); | 368 NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 336 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNewNavigation, 0); | 369 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNewNavigation, 0); |
| 337 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 2); | 370 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 2); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 rfh_tester->SimulateNavigationStop(); | 441 rfh_tester->SimulateNavigationStop(); |
| 409 | 442 |
| 410 web_contents()->Stop(); | 443 web_contents()->Stop(); |
| 411 | 444 |
| 412 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNoCommit, 1); | 445 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNoCommit, 1); |
| 413 histogram_tester_.ExpectBucketCount(internal::kAbortChainSizeNoCommit, 3, | 446 histogram_tester_.ExpectBucketCount(internal::kAbortChainSizeNoCommit, 3, |
| 414 1); | 447 1); |
| 415 } | 448 } |
| 416 | 449 |
| 417 } // namespace page_load_metrics | 450 } // namespace page_load_metrics |
| OLD | NEW |