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 "chrome/browser/page_load_metrics/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" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "components/page_load_metrics/browser/page_load_metrics_observer.h" | 15 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
16 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 16 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" |
| 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
17 #include "content/public/browser/navigation_handle.h" | 18 #include "content/public/browser/navigation_handle.h" |
18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
19 #include "content/public/test/test_renderer_host.h" | 20 #include "content/public/test/test_renderer_host.h" |
20 #include "content/public/test/web_contents_tester.h" | 21 #include "content/public/test/web_contents_tester.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
23 | 24 |
24 namespace page_load_metrics { | 25 namespace page_load_metrics { |
25 | 26 |
26 namespace { | 27 namespace { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 private: | 97 private: |
97 std::vector<PageLoadTiming> updated_timings_; | 98 std::vector<PageLoadTiming> updated_timings_; |
98 std::vector<PageLoadTiming> complete_timings_; | 99 std::vector<PageLoadTiming> complete_timings_; |
99 std::vector<GURL> observed_committed_urls_; | 100 std::vector<GURL> observed_committed_urls_; |
100 bool is_prerendering_; | 101 bool is_prerendering_; |
101 bool is_ntp_; | 102 bool is_ntp_; |
102 }; | 103 }; |
103 | 104 |
104 } // namespace | 105 } // namespace |
105 | 106 |
106 class MetricsWebContentsObserverTest | 107 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness { |
107 : public content::RenderViewHostTestHarness { | |
108 public: | 108 public: |
109 MetricsWebContentsObserverTest() : num_errors_(0) {} | 109 MetricsWebContentsObserverTest() : num_errors_(0) {} |
110 | 110 |
111 void SetUp() override { | 111 void SetUp() override { |
112 RenderViewHostTestHarness::SetUp(); | 112 ChromeRenderViewHostTestHarness::SetUp(); |
113 AttachObserver(); | 113 AttachObserver(); |
114 } | 114 } |
115 | 115 |
116 void SimulateTimingUpdate(const PageLoadTiming& timing) { | 116 void SimulateTimingUpdate(const PageLoadTiming& timing) { |
117 SimulateTimingUpdate(timing, web_contents()->GetMainFrame()); | 117 SimulateTimingUpdate(timing, web_contents()->GetMainFrame()); |
118 } | 118 } |
119 | 119 |
120 void SimulateTimingUpdate(const PageLoadTiming& timing, | 120 void SimulateTimingUpdate(const PageLoadTiming& timing, |
121 content::RenderFrameHost* render_frame_host) { | 121 content::RenderFrameHost* render_frame_host) { |
122 ASSERT_TRUE(observer_->OnMessageReceived( | 122 ASSERT_TRUE(observer_->OnMessageReceived( |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl2), net::ERR_ABORTED); | 462 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl2), net::ERR_ABORTED); |
463 rfh_tester->SimulateNavigationStop(); | 463 rfh_tester->SimulateNavigationStop(); |
464 | 464 |
465 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); | 465 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); |
466 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), net::ERR_ABORTED); | 466 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), net::ERR_ABORTED); |
467 rfh_tester->SimulateNavigationStop(); | 467 rfh_tester->SimulateNavigationStop(); |
468 | 468 |
469 web_contents()->Stop(); | 469 web_contents()->Stop(); |
470 | 470 |
471 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNoCommit, 1); | 471 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNoCommit, 1); |
472 histogram_tester_.ExpectBucketCount(internal::kAbortChainSizeNoCommit, 3, | 472 histogram_tester_.ExpectBucketCount(internal::kAbortChainSizeNoCommit, 3, 1); |
473 1); | |
474 } | 473 } |
475 | 474 |
476 } // namespace page_load_metrics | 475 } // namespace page_load_metrics |
OLD | NEW |