| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_RENDERER_FAKE_PAGE_TIMING_METRICS_IPC_SENDE
R_H_ | 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_RENDERER_FAKE_PAGE_LOAD_METRICS_H_ |
| 6 #define COMPONENTS_PAGE_LOAD_METRICS_RENDERER_FAKE_PAGE_TIMING_METRICS_IPC_SENDE
R_H_ | 6 #define COMPONENTS_PAGE_LOAD_METRICS_RENDERER_FAKE_PAGE_LOAD_METRICS_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "components/page_load_metrics/common/page_load_metrics.mojom.h" |
| 10 #include "components/page_load_metrics/common/page_load_timing.h" | 11 #include "components/page_load_metrics/common/page_load_timing.h" |
| 11 #include "ipc/ipc_sender.h" | |
| 12 | 12 |
| 13 namespace IPC { | 13 namespace IPC { |
| 14 class Message; | 14 class Message; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace page_load_metrics { | 17 namespace page_load_metrics { |
| 18 | 18 |
| 19 // IPC::Sender implementation for use in tests. Allows for setting and verifying | 19 // mojom::PageLoadMetrics implementation for use in tests. Allows for setting |
| 20 // basic expectations when sending PageLoadTiming IPCs. By default, | 20 // and verifying basic expectations when sending PageLoadTiming IPCs. By |
| 21 // FakePageTimingMetricsIPCSender will verify that expected and actual | 21 // default, FakePageLoadMetrics will verify that expected and actual |
| 22 // PageLoadTimings match on each invocation to ExpectPageLoadTiming() and | 22 // PageLoadTimings match on each invocation to ExpectPageLoadTiming() and |
| 23 // Send(), as well as in the destructor. Tests can force additional validations | 23 // Send(), as well as in the destructor. Tests can force additional validations |
| 24 // by calling VerifyExpectedTimings. | 24 // by calling VerifyExpectedTimings. |
| 25 // | 25 // |
| 26 // Expected PageLoadTimings are specified via ExpectPageLoadTiming, and actual | 26 // Expected PageLoadTimings are specified via ExpectPageLoadTiming, and actual |
| 27 // PageLoadTimings are dispatched through Send(). When Send() is called, we | 27 // PageLoadTimings are dispatched through TimingUpdated(). When TimingUpdated() |
| 28 // verify that the actual PageLoadTimings dipatched through Send() match the | 28 // is called, we verify that the actual PageLoadTimings dipatched through |
| 29 // expected PageLoadTimings provided via ExpectPageLoadTiming. | 29 // TimingUpdated() match the expected PageLoadTimings provided via |
| 30 // ExpectPageLoadTiming. |
| 30 // | 31 // |
| 31 // Normally, gmock would be used in place of this class, but gmock is not | 32 // Normally, gmock would be used in place of this class, but gmock is not |
| 32 // compatible with structures that use aligned memory, and PageLoadTiming will | 33 // compatible with structures that use aligned memory, and PageLoadTiming will |
| 33 // soon use base::Optional which uses aligned memory, so we're forced to roll | 34 // soon use base::Optional which uses aligned memory, so we're forced to roll |
| 34 // our own implementation here. See | 35 // our own implementation here. See |
| 35 // https://groups.google.com/forum/#!topic/googletestframework/W-Hud3j_c6I for | 36 // https://groups.google.com/forum/#!topic/googletestframework/W-Hud3j_c6I for |
| 36 // more details. | 37 // more details. |
| 37 class FakePageTimingMetricsIPCSender : public IPC::Sender { | 38 class FakePageLoadMetrics : public mojom::PageLoadMetrics { |
| 38 public: | 39 public: |
| 39 FakePageTimingMetricsIPCSender(); | 40 FakePageLoadMetrics(); |
| 40 ~FakePageTimingMetricsIPCSender() override; | 41 ~FakePageLoadMetrics() override; |
| 41 | |
| 42 // Implementation of IPC::Sender. PageLoadMetricsMsg_TimingUpdated IPCs that | |
| 43 // send updated PageLoadTimings should be dispatched through this method. This | |
| 44 // method will verify that all PageLoadTiming update IPCs dispatched so far | |
| 45 // match with the expected PageLoadTimings passed to ExpectPageLoadTiming. | |
| 46 bool Send(IPC::Message* message) override; | |
| 47 | 42 |
| 48 // PageLoadTimings that are expected to be sent through Send() should be | 43 // PageLoadTimings that are expected to be sent through Send() should be |
| 49 // passed to ExpectPageLoadTiming. | 44 // passed to ExpectPageLoadTiming. |
| 50 void ExpectPageLoadTiming(const PageLoadTiming& timing); | 45 void ExpectPageLoadTiming(const PageLoadTiming& timing); |
| 51 | 46 |
| 52 // Forces verification that actual timings sent through Send match | 47 // Forces verification that actual timings sent through Send match |
| 53 // expected timings provided via ExpectPageLoadTiming. | 48 // expected timings provided via ExpectPageLoadTiming. |
| 54 void VerifyExpectedTimings() const; | 49 void VerifyExpectedTimings() const; |
| 55 | 50 |
| 56 const std::vector<PageLoadTiming>& expected_timings() const { | 51 const std::vector<PageLoadTiming>& expected_timings() const { |
| 57 return expected_timings_; | 52 return expected_timings_; |
| 58 } | 53 } |
| 59 const std::vector<PageLoadTiming>& actual_timings() const { | 54 const std::vector<PageLoadTiming>& actual_timings() const { |
| 60 return actual_timings_; | 55 return actual_timings_; |
| 61 } | 56 } |
| 62 | 57 |
| 63 private: | 58 private: |
| 64 void OnTimingUpdated(const PageLoadTiming& timing, PageLoadMetadata metadata); | 59 void TimingUpdated(const PageLoadTiming& timing, |
| 60 const PageLoadMetadata& metadata) override; |
| 65 | 61 |
| 66 std::vector<PageLoadTiming> expected_timings_; | 62 std::vector<PageLoadTiming> expected_timings_; |
| 67 std::vector<PageLoadTiming> actual_timings_; | 63 std::vector<PageLoadTiming> actual_timings_; |
| 68 }; | 64 }; |
| 69 | 65 |
| 70 } // namespace page_load_metrics | 66 } // namespace page_load_metrics |
| 71 | 67 |
| 72 #endif // COMPONENTS_PAGE_LOAD_METRICS_RENDERER_FAKE_PAGE_TIMING_METRICS_IPC_SE
NDER_H_ | 68 #endif // COMPONENTS_PAGE_LOAD_METRICS_RENDERER_FAKE_PAGE_LOAD_METRICS_H_ |
| OLD | NEW |