Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Unified Diff: components/page_load_metrics/renderer/metrics_render_frame_observer_unittest.cc

Issue 2056153002: Convert PageLoadMetrics to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gyp build deps Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/page_load_metrics/renderer/metrics_render_frame_observer_unittest.cc
diff --git a/components/page_load_metrics/renderer/metrics_render_frame_observer_unittest.cc b/components/page_load_metrics/renderer/metrics_render_frame_observer_unittest.cc
index 7ef1d3922365eeb0cd8239aef52c32c86d793155..19ef86068da1c78f55ff2a3207be5b9d3b9b8571 100644
--- a/components/page_load_metrics/renderer/metrics_render_frame_observer_unittest.cc
+++ b/components/page_load_metrics/renderer/metrics_render_frame_observer_unittest.cc
@@ -8,10 +8,13 @@
#include <utility>
#include "base/memory/ptr_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/time/time.h"
#include "base/timer/mock_timer.h"
#include "components/page_load_metrics/common/page_load_timing.h"
-#include "components/page_load_metrics/renderer/fake_page_timing_metrics_ipc_sender.h"
+#include "components/page_load_metrics/renderer/fake_page_load_metrics.h"
+#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace page_load_metrics {
@@ -21,7 +24,10 @@ namespace page_load_metrics {
// the rest of the class more testable.
class TestMetricsRenderFrameObserver : public MetricsRenderFrameObserver {
public:
- TestMetricsRenderFrameObserver() : MetricsRenderFrameObserver(nullptr) {}
+ TestMetricsRenderFrameObserver(mojom::PageLoadMetricsPtr page_load_metrics,
+ FakePageLoadMetrics* fake_page_load_metrics)
+ : MetricsRenderFrameObserver(nullptr, std::move(page_load_metrics)),
+ fake_page_load_metrics_(fake_page_load_metrics) {}
std::unique_ptr<base::Timer> CreateTimer() const override {
if (!mock_timer_)
@@ -29,44 +35,48 @@ class TestMetricsRenderFrameObserver : public MetricsRenderFrameObserver {
return std::move(mock_timer_);
}
- // We intercept sent messages and dispatch them to our
- // FakePageTimingMetricsIPCSender, which we use to verify that the expected
- // IPC messages get sent.
- bool Send(IPC::Message* message) override {
- return fake_timing_ipc_sender_.Send(message);
- }
-
void set_mock_timer(std::unique_ptr<base::Timer> timer) {
ASSERT_EQ(nullptr, mock_timer_);
mock_timer_ = std::move(timer);
}
void ExpectPageLoadTiming(const PageLoadTiming& timing) {
- fake_timing_ipc_sender_.ExpectPageLoadTiming(timing);
+ fake_page_load_metrics_->ExpectPageLoadTiming(timing);
}
PageLoadTiming GetTiming() const override {
- return fake_timing_ipc_sender_.expected_timings().empty()
+ return fake_page_load_metrics_->expected_timings().empty()
? PageLoadTiming()
- : fake_timing_ipc_sender_.expected_timings().back();
+ : fake_page_load_metrics_->expected_timings().back();
}
void VerifyExpectedTimings() const {
- fake_timing_ipc_sender_.VerifyExpectedTimings();
+ fake_page_load_metrics_->VerifyExpectedTimings();
}
bool ShouldSendMetrics() const override { return true; }
bool HasNoRenderFrame() const override { return false; }
private:
- FakePageTimingMetricsIPCSender fake_timing_ipc_sender_;
mutable std::unique_ptr<base::Timer> mock_timer_;
+ FakePageLoadMetrics* fake_page_load_metrics_;
};
-typedef testing::Test MetricsRenderFrameObserverTest;
+class MetricsRenderFrameObserverTest : public testing::Test {
+ public:
+ MetricsRenderFrameObserverTest() : binding_(&fake_page_load_metrics_) {}
+ void SetUp() override { binding_.Bind(mojo::GetProxy(&page_load_metrics_)); }
+
+ protected:
+ base::MessageLoop loop_;
+ mojom::PageLoadMetricsPtr page_load_metrics_;
+ FakePageLoadMetrics fake_page_load_metrics_;
+ mojo::Binding<mojom::PageLoadMetrics> binding_;
+};
TEST_F(MetricsRenderFrameObserverTest, NoMetrics) {
- TestMetricsRenderFrameObserver observer;
+ TestMetricsRenderFrameObserver observer(std::move(page_load_metrics_),
+ &fake_page_load_metrics_);
base::MockTimer* mock_timer = new base::MockTimer(false, false);
observer.set_mock_timer(base::WrapUnique(mock_timer));
@@ -78,7 +88,8 @@ TEST_F(MetricsRenderFrameObserverTest, SingleMetric) {
base::Time nav_start = base::Time::FromDoubleT(10);
base::TimeDelta first_layout = base::TimeDelta::FromMillisecondsD(10);
- TestMetricsRenderFrameObserver observer;
+ TestMetricsRenderFrameObserver observer(std::move(page_load_metrics_),
+ &fake_page_load_metrics_);
base::MockTimer* mock_timer = new base::MockTimer(false, false);
observer.set_mock_timer(base::WrapUnique(mock_timer));
@@ -87,12 +98,14 @@ TEST_F(MetricsRenderFrameObserverTest, SingleMetric) {
observer.ExpectPageLoadTiming(timing);
observer.DidCommitProvisionalLoad(true, false);
mock_timer->Fire();
+ base::RunLoop().RunUntilIdle();
timing.first_layout = first_layout;
observer.ExpectPageLoadTiming(timing);
observer.DidChangePerformanceTiming();
mock_timer->Fire();
+ base::RunLoop().RunUntilIdle();
}
TEST_F(MetricsRenderFrameObserverTest, MultipleMetrics) {
@@ -101,7 +114,8 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleMetrics) {
base::TimeDelta dom_event = base::TimeDelta::FromMillisecondsD(2);
base::TimeDelta load_event = base::TimeDelta::FromMillisecondsD(2);
- TestMetricsRenderFrameObserver observer;
+ TestMetricsRenderFrameObserver observer(std::move(page_load_metrics_),
+ &fake_page_load_metrics_);
base::MockTimer* mock_timer = new base::MockTimer(false, false);
observer.set_mock_timer(base::WrapUnique(mock_timer));
@@ -110,6 +124,7 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleMetrics) {
observer.ExpectPageLoadTiming(timing);
observer.DidCommitProvisionalLoad(true, false);
mock_timer->Fire();
+ base::RunLoop().RunUntilIdle();
timing.first_layout = first_layout;
timing.dom_content_loaded_event_start = dom_event;
@@ -117,6 +132,7 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleMetrics) {
observer.DidChangePerformanceTiming();
mock_timer->Fire();
+ base::RunLoop().RunUntilIdle();
// At this point, we should have triggered the generation of two metrics.
// Verify and reset the observer's expectations before moving on to the next
@@ -128,6 +144,7 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleMetrics) {
observer.DidChangePerformanceTiming();
mock_timer->Fire();
+ base::RunLoop().RunUntilIdle();
// Verify and reset the observer's expectations before moving on to the next
// part of the test.
@@ -147,7 +164,8 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleNavigations) {
base::TimeDelta dom_event = base::TimeDelta::FromMillisecondsD(2);
base::TimeDelta load_event = base::TimeDelta::FromMillisecondsD(2);
- TestMetricsRenderFrameObserver observer;
+ TestMetricsRenderFrameObserver observer(std::move(page_load_metrics_),
+ &fake_page_load_metrics_);
base::MockTimer* mock_timer = new base::MockTimer(false, false);
observer.set_mock_timer(base::WrapUnique(mock_timer));
@@ -156,6 +174,7 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleNavigations) {
observer.ExpectPageLoadTiming(timing);
observer.DidCommitProvisionalLoad(true, false);
mock_timer->Fire();
+ base::RunLoop().RunUntilIdle();
timing.first_layout = first_layout;
timing.dom_content_loaded_event_start = dom_event;
@@ -163,6 +182,7 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleNavigations) {
observer.ExpectPageLoadTiming(timing);
observer.DidChangePerformanceTiming();
mock_timer->Fire();
+ base::RunLoop().RunUntilIdle();
// At this point, we should have triggered the generation of two metrics.
// Verify and reset the observer's expectations before moving on to the next
@@ -182,6 +202,7 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleNavigations) {
observer.ExpectPageLoadTiming(timing_2);
observer.DidCommitProvisionalLoad(true, false);
mock_timer2->Fire();
+ base::RunLoop().RunUntilIdle();
timing_2.first_layout = first_layout_2;
timing_2.dom_content_loaded_event_start = dom_event_2;
@@ -190,6 +211,7 @@ TEST_F(MetricsRenderFrameObserverTest, MultipleNavigations) {
observer.DidChangePerformanceTiming();
mock_timer2->Fire();
+ base::RunLoop().RunUntilIdle();
}
} // namespace page_load_metrics

Powered by Google App Engine
This is Rietveld 408576698