Chromium Code Reviews| 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/observers/page_load_metrics_observer_ test_harness.h" | 5 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_ test_harness.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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/run_loop.h" | |
| 12 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface. h" | 13 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface. h" |
| 13 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 14 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| 15 #include "chrome/common/page_load_metrics/page_load_metrics.mojom.h" | |
| 14 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" | 16 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "content/public/test/web_contents_tester.h" | 20 #include "content/public/test/web_contents_tester.h" |
| 19 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 21 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 20 | 22 |
| 21 namespace page_load_metrics { | 23 namespace page_load_metrics { |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 const PageLoadTiming& timing) { | 141 const PageLoadTiming& timing) { |
| 140 SimulateTimingAndMetadataUpdate(timing, PageLoadMetadata()); | 142 SimulateTimingAndMetadataUpdate(timing, PageLoadMetadata()); |
| 141 } | 143 } |
| 142 | 144 |
| 143 void PageLoadMetricsObserverTestHarness::SimulateTimingAndMetadataUpdate( | 145 void PageLoadMetricsObserverTestHarness::SimulateTimingAndMetadataUpdate( |
| 144 const PageLoadTiming& timing, | 146 const PageLoadTiming& timing, |
| 145 const PageLoadMetadata& metadata) { | 147 const PageLoadMetadata& metadata) { |
| 146 observer_->OnMessageReceived(PageLoadMetricsMsg_TimingUpdated( | 148 observer_->OnMessageReceived(PageLoadMetricsMsg_TimingUpdated( |
| 147 observer_->routing_id(), timing, metadata), | 149 observer_->routing_id(), timing, metadata), |
| 148 web_contents()->GetMainFrame()); | 150 web_contents()->GetMainFrame()); |
| 151 observer_->page_load_metrics_binding_for_testing() | |
| 152 .SetCurrentTargetFrameForTesting(web_contents()->GetMainFrame()); | |
| 153 mojo::Binding<page_load_metrics::mojom::PageLoadMetrics> binding(observer_); | |
| 154 mojom::PageLoadMetricsPtr ptr; | |
| 155 mojom::PageLoadMetricsRequest request = MakeRequest(&ptr); | |
| 156 binding.Bind(std::move(request)); | |
| 157 ptr->UpdateTiming(timing, metadata); | |
|
Zhen Wang
2017/04/19 21:52:47
Same comment as the one in metrics_web_contents_ob
| |
| 158 base::RunLoop().RunUntilIdle(); | |
| 149 } | 159 } |
| 150 | 160 |
| 151 void PageLoadMetricsObserverTestHarness::SimulateLoadedResource( | 161 void PageLoadMetricsObserverTestHarness::SimulateLoadedResource( |
| 152 const ExtraRequestInfo& info) { | 162 const ExtraRequestInfo& info) { |
| 153 observer_->OnRequestComplete( | 163 observer_->OnRequestComplete( |
| 154 content::GlobalRequestID(), content::RESOURCE_TYPE_SCRIPT, | 164 content::GlobalRequestID(), content::RESOURCE_TYPE_SCRIPT, |
| 155 info.was_cached, info.data_reduction_proxy_used, info.raw_body_bytes, | 165 info.was_cached, info.data_reduction_proxy_used, info.raw_body_bytes, |
| 156 info.original_network_content_length, base::TimeTicks::Now()); | 166 info.original_network_content_length, base::TimeTicks::Now()); |
| 157 } | 167 } |
| 158 | 168 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 184 } | 194 } |
| 185 | 195 |
| 186 void PageLoadMetricsObserverTestHarness::NavigateWithPageTransitionAndCommit( | 196 void PageLoadMetricsObserverTestHarness::NavigateWithPageTransitionAndCommit( |
| 187 const GURL& url, | 197 const GURL& url, |
| 188 ui::PageTransition transition) { | 198 ui::PageTransition transition) { |
| 189 controller().LoadURL(url, content::Referrer(), transition, std::string()); | 199 controller().LoadURL(url, content::Referrer(), transition, std::string()); |
| 190 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 200 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 191 } | 201 } |
| 192 | 202 |
| 193 } // namespace page_load_metrics | 203 } // namespace page_load_metrics |
| OLD | NEW |