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

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

Issue 2823523003: [Page Load Metrics] PageLoadMetrics Mojofication. (Closed)
Patch Set: rebase 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
OLDNEW
(Empty)
1 // Copyright (c) 2017 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_TIMING_SENDER_H_
6 #define CHROME_RENDERER_PAGE_LOAD_METRICS_FAKE_PAGE_TIMING_SENDER_H_
7
8 #include "chrome/common/page_load_metrics/page_load_metrics.mojom.h"
9 #include "chrome/common/page_load_metrics/page_load_timing.h"
10 #include "chrome/renderer/page_load_metrics/page_timing_sender.h"
11
12 namespace page_load_metrics {
13
14 // PageTimingSender implementation for use in tests. Allows for setting and
15 // verifying basic expectations when sending PageLoadTiming. By default,
16 // FakePageTimingSender will verify that expected and actual
17 // PageLoadTimings match on each invocation to ExpectPageLoadTiming() and
18 // SendTiming(), as well as in the destructor. Tests can force additional
19 // validations by calling VerifyExpectedTimings.
20 //
21 // Expected PageLoadTimings are specified via ExpectPageLoadTiming, and actual
22 // PageLoadTimings are dispatched through SendTiming(). When SendTiming() is
23 // called, we verify that the actual PageLoadTimings dipatched through
24 // SendTiming() match the expected PageLoadTimings provided via
25 // ExpectPageLoadTiming.
26 //
27 // Normally, gmock would be used in place of this class, but gmock is not
28 // compatible with structures that use aligned memory, and PageLoadTiming uses
29 // base::Optional which uses aligned memory, so we're forced to roll
30 // our own implementation here. See
31 // https://groups.google.com/forum/#!topic/googletestframework/W-Hud3j_c6I for
32 // more details.
33 class FakePageTimingSender : public PageTimingSender {
34 public:
35 class PageTimingValidator {
36 public:
37 PageTimingValidator();
38 ~PageTimingValidator();
39 // PageLoadTimings that are expected to be sent through SendTiming() should
40 // be passed to ExpectPageLoadTiming.
41 void ExpectPageLoadTiming(const mojom::PageLoadTiming& timing);
42
43 // Forces verification that actual timings sent through SendTiming() match
44 // expected timings provided via ExpectPageLoadTiming.
45 void VerifyExpectedTimings() const;
46
47 const std::vector<mojom::PageLoadTimingPtr>& expected_timings() const {
48 return expected_timings_;
49 }
50 const std::vector<mojom::PageLoadTimingPtr>& actual_timings() const {
51 return actual_timings_;
52 }
53
54 void UpdateTiming(const mojom::PageLoadTimingPtr& timing,
55 const mojom::PageLoadMetadataPtr& metadata);
56
57 private:
58 std::vector<mojom::PageLoadTimingPtr> expected_timings_;
59 std::vector<mojom::PageLoadTimingPtr> actual_timings_;
60 DISALLOW_COPY_AND_ASSIGN(PageTimingValidator);
61 };
62
63 explicit FakePageTimingSender(PageTimingValidator* validator);
64 ~FakePageTimingSender() override;
65 void SendTiming(const mojom::PageLoadTimingPtr& timing,
66 const mojom::PageLoadMetadataPtr& metadata) override;
67
68 private:
69 PageTimingValidator* const validator_;
70 DISALLOW_COPY_AND_ASSIGN(FakePageTimingSender);
71 };
72
73 } // namespace page_load_metrics
74
75 #endif // CHROME_RENDERER_PAGE_LOAD_METRICS_FAKE_PAGE_TIMING_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698