OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/page_load_metrics/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/run_loop.h" | |
Bryan McQuade
2017/04/26 16:04:34
can remove this include
lpy
2017/04/27 10:58:35
Done.
| |
13 #include "base/test/histogram_tester.h" | 14 #include "base/test/histogram_tester.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "chrome/browser/page_load_metrics/metrics_navigation_throttle.h" | 16 #include "chrome/browser/page_load_metrics/metrics_navigation_throttle.h" |
16 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface. h" | 17 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface. h" |
17 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | 18 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
18 #include "chrome/browser/page_load_metrics/page_load_tracker.h" | 19 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
19 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" | 20 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
22 #include "content/public/browser/navigation_handle.h" | 23 #include "content/public/browser/navigation_handle.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 content::WebContentsTester::For(web_contents()) | 161 content::WebContentsTester::For(web_contents()) |
161 ->NavigateAndCommit(GURL(url::kAboutBlankURL)); | 162 ->NavigateAndCommit(GURL(url::kAboutBlankURL)); |
162 } | 163 } |
163 | 164 |
164 void SimulateTimingUpdate(const PageLoadTiming& timing) { | 165 void SimulateTimingUpdate(const PageLoadTiming& timing) { |
165 SimulateTimingUpdate(timing, web_contents()->GetMainFrame()); | 166 SimulateTimingUpdate(timing, web_contents()->GetMainFrame()); |
166 } | 167 } |
167 | 168 |
168 void SimulateTimingUpdate(const PageLoadTiming& timing, | 169 void SimulateTimingUpdate(const PageLoadTiming& timing, |
169 content::RenderFrameHost* render_frame_host) { | 170 content::RenderFrameHost* render_frame_host) { |
170 ASSERT_TRUE(observer_->OnMessageReceived( | 171 observer_->OnTimingUpdated(render_frame_host, timing, PageLoadMetadata()); |
171 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing, | |
172 PageLoadMetadata()), | |
173 render_frame_host)); | |
174 } | 172 } |
175 | 173 |
176 void AttachObserver() { | 174 void AttachObserver() { |
177 embedder_interface_ = new TestPageLoadMetricsEmbedderInterface(); | 175 embedder_interface_ = new TestPageLoadMetricsEmbedderInterface(); |
178 // Owned by the web_contents. Tests must be careful not to call | 176 // Owned by the web_contents. Tests must be careful not to call |
179 // SimulateTimingUpdate after they call DeleteContents() without also | 177 // SimulateTimingUpdate after they call DeleteContents() without also |
180 // calling AttachObserver() again. Otherwise they will use-after-free the | 178 // calling AttachObserver() again. Otherwise they will use-after-free the |
181 // observer_. | 179 // observer_. |
182 observer_ = MetricsWebContentsObserver::CreateForWebContents( | 180 observer_ = MetricsWebContentsObserver::CreateForWebContents( |
183 web_contents(), base::WrapUnique(embedder_interface_)); | 181 web_contents(), base::WrapUnique(embedder_interface_)); |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 664 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
667 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), | 665 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), |
668 completed_filtered_urls()); | 666 completed_filtered_urls()); |
669 | 667 |
670 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 668 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
671 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), | 669 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), |
672 completed_filtered_urls()); | 670 completed_filtered_urls()); |
673 } | 671 } |
674 | 672 |
675 } // namespace page_load_metrics | 673 } // namespace page_load_metrics |
OLD | NEW |