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

Unified Diff: chrome/renderer/page_load_metrics/page_timing_metrics_sender_unittest.cc

Issue 2823523003: [Page Load Metrics] PageLoadMetrics Mojofication. (Closed)
Patch Set: Addressed comments, remove unnecessary RunUntilIdle, call OnTimingUpdated directly in unit tests Created 3 years, 8 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: chrome/renderer/page_load_metrics/page_timing_metrics_sender_unittest.cc
diff --git a/chrome/renderer/page_load_metrics/page_timing_metrics_sender_unittest.cc b/chrome/renderer/page_load_metrics/page_timing_metrics_sender_unittest.cc
index 3756f33e770e4e1ae738afc5b3060a07513acdb1..2133029a35e15613db4a11656e31f96744e07b37 100644
--- a/chrome/renderer/page_load_metrics/page_timing_metrics_sender_unittest.cc
+++ b/chrome/renderer/page_load_metrics/page_timing_metrics_sender_unittest.cc
@@ -4,11 +4,15 @@
#include "chrome/renderer/page_load_metrics/page_timing_metrics_sender.h"
+#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "base/timer/mock_timer.h"
#include "chrome/common/page_load_metrics/page_load_timing.h"
+#include "chrome/renderer/page_load_metrics/fake_page_load_metrics.h"
#include "chrome/renderer/page_load_metrics/fake_page_timing_metrics_ipc_sender.h"
+#include "chrome/renderer/page_load_metrics/fake_page_timing_sender.h"
#include "ipc/ipc_message.h"
+#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace page_load_metrics {
@@ -18,10 +22,12 @@ namespace page_load_metrics {
class TestPageTimingMetricsSender : public PageTimingMetricsSender {
public:
explicit TestPageTimingMetricsSender(IPC::Sender* ipc_sender,
+ PageTimingSender* page_timing_sender,
const PageLoadTiming& initial_timing)
: PageTimingMetricsSender(
ipc_sender,
MSG_ROUTING_NONE,
+ page_timing_sender,
std::unique_ptr<base::Timer>(new base::MockTimer(false, false)),
initial_timing) {}
@@ -33,11 +39,23 @@ class TestPageTimingMetricsSender : public PageTimingMetricsSender {
class PageTimingMetricsSenderTest : public testing::Test {
public:
PageTimingMetricsSenderTest()
- : metrics_sender_(new TestPageTimingMetricsSender(&fake_ipc_sender_,
+ : binding_(&fake_page_load_metrics_),
+ metrics_sender_(new TestPageTimingMetricsSender(&fake_ipc_sender_,
+ &fake_sender_,
PageLoadTiming())) {}
protected:
+ void SetUp() override {
+ mojom::PageLoadMetricsRequest request =
+ MakeRequest(&fake_sender_.page_load_metrics_ptr());
+ fake_page_load_metrics_.Bind(std::move(request));
+ }
+
+ base::MessageLoop loop_;
+ FakePageLoadMetricsImpl fake_page_load_metrics_;
FakePageTimingMetricsIPCSender fake_ipc_sender_;
+ FakePageTimingSender fake_sender_;
+ mojo::Binding<mojom::PageLoadMetrics> binding_;
std::unique_ptr<TestPageTimingMetricsSender> metrics_sender_;
};
@@ -53,12 +71,14 @@ TEST_F(PageTimingMetricsSenderTest, Basic) {
// Firing the timer should trigger sending of an OnTimingUpdated IPC.
fake_ipc_sender_.ExpectPageLoadTiming(timing);
+ fake_page_load_metrics_.ExpectPageLoadTiming(timing);
ASSERT_TRUE(metrics_sender_->mock_timer()->IsRunning());
metrics_sender_->mock_timer()->Fire();
EXPECT_FALSE(metrics_sender_->mock_timer()->IsRunning());
// At this point, we should have triggered the send of the PageLoadTiming IPC.
fake_ipc_sender_.VerifyExpectedTimings();
+ fake_page_load_metrics_.VerifyExpectedTimings();
// Attempt to send the same timing instance again. The send should be
// suppressed, since the timing instance hasn't changed since the last send.
@@ -86,6 +106,7 @@ TEST_F(PageTimingMetricsSenderTest, CoalesceMultipleIPCs) {
// Firing the timer should trigger sending of the OnTimingUpdated IPC with
// the most recently provided PageLoadTiming instance.
fake_ipc_sender_.ExpectPageLoadTiming(timing);
+ fake_page_load_metrics_.ExpectPageLoadTiming(timing);
metrics_sender_->mock_timer()->Fire();
EXPECT_FALSE(metrics_sender_->mock_timer()->IsRunning());
}
@@ -102,9 +123,11 @@ TEST_F(PageTimingMetricsSenderTest, MultipleIPCs) {
metrics_sender_->Send(timing);
ASSERT_TRUE(metrics_sender_->mock_timer()->IsRunning());
fake_ipc_sender_.ExpectPageLoadTiming(timing);
+ fake_page_load_metrics_.ExpectPageLoadTiming(timing);
metrics_sender_->mock_timer()->Fire();
EXPECT_FALSE(metrics_sender_->mock_timer()->IsRunning());
fake_ipc_sender_.VerifyExpectedTimings();
+ fake_page_load_metrics_.VerifyExpectedTimings();
// Send an updated PageLoadTiming after the timer for the first send request
// has fired, and verify that a second IPC is sent.
@@ -112,6 +135,7 @@ TEST_F(PageTimingMetricsSenderTest, MultipleIPCs) {
metrics_sender_->Send(timing);
ASSERT_TRUE(metrics_sender_->mock_timer()->IsRunning());
fake_ipc_sender_.ExpectPageLoadTiming(timing);
+ fake_page_load_metrics_.ExpectPageLoadTiming(timing);
metrics_sender_->mock_timer()->Fire();
EXPECT_FALSE(metrics_sender_->mock_timer()->IsRunning());
}
@@ -126,6 +150,7 @@ TEST_F(PageTimingMetricsSenderTest, SendIPCOnDestructor) {
// is destroyed below.
metrics_sender_->Send(timing);
fake_ipc_sender_.ExpectPageLoadTiming(timing);
+ fake_page_load_metrics_.ExpectPageLoadTiming(timing);
ASSERT_TRUE(metrics_sender_->mock_timer()->IsRunning());
// Destroy |metrics_sender_|, in order to force its destructor to run.

Powered by Google App Engine
This is Rietveld 408576698