Index: chrome/renderer/page_load_metrics/fake_page_load_metrics.h |
diff --git a/chrome/renderer/page_load_metrics/fake_page_load_metrics.h b/chrome/renderer/page_load_metrics/fake_page_load_metrics.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f881e7f6559ed8e273f30646822d0bbfac0ea24a |
--- /dev/null |
+++ b/chrome/renderer/page_load_metrics/fake_page_load_metrics.h |
@@ -0,0 +1,72 @@ |
+// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_RENDERER_PAGE_LOAD_METRICS_FAKE_PAGE_LOAD_METRICS_H_ |
+#define CHROME_RENDERER_PAGE_LOAD_METRICS_FAKE_PAGE_LOAD_METRICS_H_ |
+ |
+#include <vector> |
+ |
+#include "chrome/common/page_load_metrics/page_load_metrics.mojom.h" |
+#include "chrome/common/page_load_metrics/page_load_timing.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
+ |
+namespace page_load_metrics { |
+ |
+// mojom::PageLoadMetrics implementation for use in tests. |
+// Allows for setting and verifying basic expectations when sending |
+// PageLoadTiming through mojo. By default, FakePageLoadMetrics will verify that |
+// expected and actual PageLoadTimings match on each invocation to |
+// ExpectPageLoadTiming() and UpdateTiming(), as well as in the destructor. |
+// Tests can force additional validations by calling VerifyExpectedTimings. |
+// |
+// Expected PageLoadTimings are specified via ExpectPageLoadTiming, and actual |
+// PageLoadTimings are dispatched through UpdateTiming(). When UpdateTiming() is |
+// called, we verify that the actual PageLoadTimings dipatched through |
+// UpdateTiming() match the expected PageLoadTimings provided via |
+// ExpectPageLoadTiming. |
+// |
+// Normally, gmock would be used in place of this class, but gmock is not |
+// compatible with structures that use aligned memory, and PageLoadTiming will |
+// soon use base::Optional which uses aligned memory, so we're forced to roll |
+// our own implementation here. See |
+// https://groups.google.com/forum/#!topic/googletestframework/W-Hud3j_c6I for |
+// more details. |
+class FakePageLoadMetricsImpl : public mojom::PageLoadMetrics { |
+ public: |
+ FakePageLoadMetricsImpl(); |
+ ~FakePageLoadMetricsImpl() override; |
+ |
+ void Bind(mojom::PageLoadMetricsRequest request); |
+ |
+ // PageLoadTimings that are expected to be sent through Send() should be |
+ // passed to ExpectPageLoadTiming. |
+ void ExpectPageLoadTiming(const PageLoadTiming& timing); |
+ |
+ // Forces verification that actual timings sent through Send match |
+ // expected timings provided via ExpectPageLoadTiming. |
+ void VerifyExpectedTimings() const; |
+ |
+ const std::vector<PageLoadTiming>& expected_timings() const { |
+ return expected_timings_; |
+ } |
+ const std::vector<PageLoadTiming>& actual_timings() const { |
+ return actual_timings_; |
+ } |
+ |
+ private: |
+ // Implementation of PageLoadMetrics. |
+ // Collect PageLoadTiming that sent from sender. |
+ // This method will verify that all PageLoadTiming collected so far |
+ // match with the expected PageLoadTimings passed to ExpectPageLoadTiming. |
+ void UpdateTiming(const PageLoadTiming& timing, |
+ const PageLoadMetadata& metadata) override; |
+ |
+ std::vector<PageLoadTiming> expected_timings_; |
+ std::vector<PageLoadTiming> actual_timings_; |
+ mojo::Binding<mojom::PageLoadMetrics> binding_; |
+}; |
+ |
+} // namespace page_load_metrics |
+ |
+#endif // CHROME_RENDERER_PAGE_LOAD_METRICS_FAKE_PAGE_LOAD_METRICS_H_ |