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

Unified Diff: chrome/browser/page_load_metrics/page_load_metrics_browsertest.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/browser/page_load_metrics/page_load_metrics_browsertest.cc
diff --git a/chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc b/chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc
index 8d69c71e8ddf51c0cebb4c566fda09100271e219..5f07695c7bf2063d189a45b57ba5c820b807126d 100644
--- a/chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc
+++ b/chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc
@@ -29,12 +29,15 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
+#include "content/public/test/web_contents_binding_set_test_binder.h"
+#include "mojo/public/cpp/bindings/associated_binding.h"
#include "net/http/failing_http_transaction_factory.h"
#include "net/http/http_cache.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/url_request/url_request_failed_job.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
+#include "testing/gmock/include/gmock/gmock.h"
namespace {
@@ -157,6 +160,46 @@ class TimingUpdatedObserver : public content::BrowserMessageFilter {
} // namespace
+namespace page_load_metrics {
+
+class MockPageLoadMetrics : public mojom::PageLoadMetrics {
+ public:
+ MockPageLoadMetrics() {}
+ ~MockPageLoadMetrics() override {}
+ MOCK_METHOD2(UpdateTiming,
+ void(const PageLoadTiming&, const PageLoadMetadata&));
+};
+
+} // namespace page_load_metrics
+
+namespace {
+
+class FakePageLoadMetricsBinder
+ : public content::WebContentsBindingSetTestBinder<
+ page_load_metrics::mojom::PageLoadMetrics> {
+ public:
+ FakePageLoadMetricsBinder(
+ page_load_metrics::mojom::PageLoadMetrics* page_load_metrics)
+ : page_load_metrics_(page_load_metrics) {}
+ ~FakePageLoadMetricsBinder() override {}
+
+ void BindRequest(content::RenderFrameHost* frame_host,
+ page_load_metrics::mojom::PageLoadMetricsAssociatedRequest
+ request) override {
+ bindings_.AddBinding(page_load_metrics_, std::move(request), frame_host);
+ }
+
+ private:
+ page_load_metrics::mojom::PageLoadMetrics* page_load_metrics_;
+ mojo::AssociatedBindingSet<page_load_metrics::mojom::PageLoadMetrics,
+ content::RenderFrameHost*>
+ bindings_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakePageLoadMetricsBinder);
+};
+
+} // namespace
+
class PageLoadMetricsBrowserTest : public InProcessBrowserTest {
public:
PageLoadMetricsBrowserTest() {}
@@ -181,11 +224,21 @@ class PageLoadMetricsBrowserTest : public InProcessBrowserTest {
scoped_refptr<TimingUpdatedObserver> CreateTimingUpdatedObserver() {
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
+ if (!mock_page_load_metrics_) {
Bryan McQuade 2017/04/26 16:04:34 just so i better understand, why is this needed in
lpy 2017/04/27 10:58:35 Done, I forgot to remove this part. As I mentione
+ mock_page_load_metrics_.reset(
+ new page_load_metrics::MockPageLoadMetrics());
+ content::WebContentsBindingSet::GetForWebContents<
+ page_load_metrics::mojom::PageLoadMetrics>(web_contents)
+ ->SetBinderForTesting(base::MakeUnique<FakePageLoadMetricsBinder>(
+ mock_page_load_metrics_.get()));
+ }
scoped_refptr<TimingUpdatedObserver> observer(new TimingUpdatedObserver(
web_contents->GetRenderViewHost()->GetWidget()));
return observer;
}
+ std::unique_ptr<page_load_metrics::MockPageLoadMetrics>
+ mock_page_load_metrics_;
base::HistogramTester histogram_tester_;
private:

Powered by Google App Engine
This is Rietveld 408576698