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

Side by Side Diff: chrome/renderer/page_load_metrics/fake_page_load_metrics.h

Issue 2823523003: [Page Load Metrics] PageLoadMetrics Mojofication. (Closed)
Patch Set: update Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/renderer/BUILD.gn ('k') | chrome/renderer/page_load_metrics/fake_page_load_metrics.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_RENDERER_PAGE_LOAD_METRICS_FAKE_PAGE_LOAD_METRICS_H_
6 #define CHROME_RENDERER_PAGE_LOAD_METRICS_FAKE_PAGE_LOAD_METRICS_H_
7
8 #include <vector>
9
10 #include "chrome/common/page_load_metrics/page_load_metrics.mojom.h"
11 #include "chrome/common/page_load_metrics/page_load_timing.h"
12 #include "mojo/public/cpp/bindings/binding.h"
13
14 namespace page_load_metrics {
15
16 // mojom::PageLoadMetrics implementation for use in tests.
17 // Allows for setting and verifying basic expectations when sending
18 // PageLoadTiming through mojo. By default, FakePageLoadMetrics will verify that
19 // expected and actual PageLoadTimings match on each invocation to
20 // ExpectPageLoadTiming() and UpdateTiming(), as well as in the destructor.
21 // Tests can force additional validations by calling VerifyExpectedTimings.
22 //
23 // Expected PageLoadTimings are specified via ExpectPageLoadTiming, and actual
24 // PageLoadTimings are dispatched through UpdateTiming(). When UpdateTiming() is
25 // called, we verify that the actual PageLoadTimings dipatched through
26 // UpdateTiming() match the expected PageLoadTimings provided via
27 // ExpectPageLoadTiming.
28 //
29 // Normally, gmock would be used in place of this class, but gmock is not
30 // compatible with structures that use aligned memory, and PageLoadTiming will
31 // soon use base::Optional which uses aligned memory, so we're forced to roll
32 // our own implementation here. See
33 // https://groups.google.com/forum/#!topic/googletestframework/W-Hud3j_c6I for
34 // more details.
35 class FakePageLoadMetricsImpl : public mojom::PageLoadMetrics {
36 public:
37 FakePageLoadMetricsImpl();
38 ~FakePageLoadMetricsImpl() override;
39
40 void Bind(mojom::PageLoadMetricsRequest request);
41
42 // PageLoadTimings that are expected to be sent through Send() should be
43 // passed to ExpectPageLoadTiming.
44 void ExpectPageLoadTiming(const PageLoadTiming& timing);
45
46 // Forces verification that actual timings sent through Send match
47 // expected timings provided via ExpectPageLoadTiming.
48 void VerifyExpectedTimings() const;
49
50 const std::vector<PageLoadTiming>& expected_timings() const {
51 return expected_timings_;
52 }
53 const std::vector<PageLoadTiming>& actual_timings() const {
54 return actual_timings_;
55 }
56
57 private:
58 // Implementation of PageLoadMetrics.
59 // Collect PageLoadTiming that sent from sender.
60 // This method will verify that all PageLoadTiming collected so far
61 // match with the expected PageLoadTimings passed to ExpectPageLoadTiming.
62 void UpdateTiming(const PageLoadTiming& timing,
63 const PageLoadMetadata& metadata) override;
64
65 std::vector<PageLoadTiming> expected_timings_;
66 std::vector<PageLoadTiming> actual_timings_;
67 mojo::Binding<mojom::PageLoadMetrics> binding_;
68 };
69
70 } // namespace page_load_metrics
71
72 #endif // CHROME_RENDERER_PAGE_LOAD_METRICS_FAKE_PAGE_LOAD_METRICS_H_
OLDNEW
« no previous file with comments | « chrome/renderer/BUILD.gn ('k') | chrome/renderer/page_load_metrics/fake_page_load_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698