| 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 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_PAGE_LOAD_METRICS_OBSERVER_TE
ST_HARNESS_H_ | 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_PAGE_LOAD_METRICS_OBSERVER_TE
ST_HARNESS_H_ |
| 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_PAGE_LOAD_METRICS_OBSERVER_TE
ST_HARNESS_H_ | 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_PAGE_LOAD_METRICS_OBSERVER_TE
ST_HARNESS_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 9 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| 11 #include "base/timer/mock_timer.h" |
| 10 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 12 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
| 11 #include "chrome/browser/page_load_metrics/page_load_tracker.h" | 13 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
| 12 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "content/public/test/web_contents_tester.h" | 16 #include "content/public/test/web_contents_tester.h" |
| 15 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 17 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 16 #include "ui/base/page_transition_types.h" | 18 #include "ui/base/page_transition_types.h" |
| 17 | 19 |
| 18 namespace page_load_metrics { | 20 namespace page_load_metrics { |
| 19 | 21 |
| 20 // This class can be used to drive tests of PageLoadMetricsObservers. To hook up | 22 // This class can be used to drive tests of PageLoadMetricsObservers. To hook up |
| 21 // an observer, override RegisterObservers and call tracker->AddObserver. This | 23 // an observer, override RegisterObservers and call tracker->AddObserver. This |
| 22 // will attach the observer to all main frame navigations. | 24 // will attach the observer to all main frame navigations. |
| 23 class PageLoadMetricsObserverTestHarness | 25 class PageLoadMetricsObserverTestHarness |
| 24 : public ChromeRenderViewHostTestHarness { | 26 : public ChromeRenderViewHostTestHarness { |
| 25 public: | 27 public: |
| 28 class WeakMockTimer : public base::MockTimer, |
| 29 public base::SupportsWeakPtr<WeakMockTimer> { |
| 30 public: |
| 31 WeakMockTimer() |
| 32 : MockTimer(false /* retain_user_task */, false /* is_repeating */) {} |
| 33 }; |
| 34 |
| 26 PageLoadMetricsObserverTestHarness(); | 35 PageLoadMetricsObserverTestHarness(); |
| 27 ~PageLoadMetricsObserverTestHarness() override; | 36 ~PageLoadMetricsObserverTestHarness() override; |
| 28 | 37 |
| 29 // Helper that fills in any timing fields that MWCO requires but that are | 38 // Helper that fills in any timing fields that MWCO requires but that are |
| 30 // currently missing. | 39 // currently missing. |
| 31 static void PopulateRequiredTimingFields(mojom::PageLoadTiming* inout_timing); | 40 static void PopulateRequiredTimingFields(mojom::PageLoadTiming* inout_timing); |
| 32 | 41 |
| 33 void SetUp() override; | 42 void SetUp() override; |
| 34 | 43 |
| 35 virtual void RegisterObservers(PageLoadTracker* tracker) {} | 44 virtual void RegisterObservers(PageLoadTracker* tracker) {} |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Simulate playing a media element. | 80 // Simulate playing a media element. |
| 72 void SimulateMediaPlayed(); | 81 void SimulateMediaPlayed(); |
| 73 | 82 |
| 74 const base::HistogramTester& histogram_tester() const; | 83 const base::HistogramTester& histogram_tester() const; |
| 75 | 84 |
| 76 MetricsWebContentsObserver* observer() const; | 85 MetricsWebContentsObserver* observer() const; |
| 77 | 86 |
| 78 // Gets the PageLoadExtraInfo for the committed_load_ in observer_. | 87 // Gets the PageLoadExtraInfo for the committed_load_ in observer_. |
| 79 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad(); | 88 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad(); |
| 80 | 89 |
| 90 // Gets the timer most recently created by the |
| 91 // PageLoadMetricsEmbedderInterface. |
| 92 base::MockTimer* GetMostRecentTimer() { return most_recent_timer_.get(); } |
| 93 void SetMostRecentTimer(base::WeakPtr<WeakMockTimer> timer) { |
| 94 most_recent_timer_ = timer; |
| 95 } |
| 96 |
| 81 private: | 97 private: |
| 82 base::HistogramTester histogram_tester_; | 98 base::HistogramTester histogram_tester_; |
| 83 MetricsWebContentsObserver* observer_; | 99 MetricsWebContentsObserver* observer_; |
| 100 base::WeakPtr<WeakMockTimer> most_recent_timer_; |
| 84 | 101 |
| 85 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsObserverTestHarness); | 102 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsObserverTestHarness); |
| 86 }; | 103 }; |
| 87 | 104 |
| 88 } // namespace page_load_metrics | 105 } // namespace page_load_metrics |
| 89 | 106 |
| 90 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_PAGE_LOAD_METRICS_OBSERVER
_TEST_HARNESS_H_ | 107 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_PAGE_LOAD_METRICS_OBSERVER
_TEST_HARNESS_H_ |
| OLD | NEW |