OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 #include "components/page_load_metrics/renderer/metrics_render_frame_observer.h" | 5 #include "components/page_load_metrics/renderer/metrics_render_frame_observer.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
8 #include "base/time/time.h" | 10 #include "base/time/time.h" |
9 #include "base/timer/mock_timer.h" | 11 #include "base/timer/mock_timer.h" |
10 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 12 #include "components/page_load_metrics/common/page_load_metrics_messages.h" |
11 #include "components/page_load_metrics/common/page_load_timing.h" | 13 #include "components/page_load_metrics/common/page_load_timing.h" |
12 #include "ipc/ipc_message_macros.h" | 14 #include "ipc/ipc_message_macros.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 using testing::NiceMock; | 18 using testing::NiceMock; |
(...skipping 22 matching lines...) Expand all Loading... |
39 class MockMetricsRenderFrameObserver : public MetricsRenderFrameObserver { | 41 class MockMetricsRenderFrameObserver : public MetricsRenderFrameObserver { |
40 public: | 42 public: |
41 MockMetricsRenderFrameObserver() : MetricsRenderFrameObserver(nullptr) { | 43 MockMetricsRenderFrameObserver() : MetricsRenderFrameObserver(nullptr) { |
42 ON_CALL(*this, ShouldSendMetrics()).WillByDefault(Return(true)); | 44 ON_CALL(*this, ShouldSendMetrics()).WillByDefault(Return(true)); |
43 ON_CALL(*this, HasNoRenderFrame()).WillByDefault(Return(false)); | 45 ON_CALL(*this, HasNoRenderFrame()).WillByDefault(Return(false)); |
44 } | 46 } |
45 | 47 |
46 scoped_ptr<base::Timer> CreateTimer() const override { | 48 scoped_ptr<base::Timer> CreateTimer() const override { |
47 if (!mock_timer_) | 49 if (!mock_timer_) |
48 ADD_FAILURE() << "CreateTimer() called, but no MockTimer available."; | 50 ADD_FAILURE() << "CreateTimer() called, but no MockTimer available."; |
49 return mock_timer_.Pass(); | 51 return std::move(mock_timer_); |
50 } | 52 } |
51 | 53 |
52 // We intercept sent messages and dispatch them to a MockIPCInterceptor, which | 54 // We intercept sent messages and dispatch them to a MockIPCInterceptor, which |
53 // we use to verify that the expected IPC messages get sent. | 55 // we use to verify that the expected IPC messages get sent. |
54 virtual bool Send(IPC::Message* message) { | 56 virtual bool Send(IPC::Message* message) { |
55 interceptor_.OnMessage(*message); | 57 interceptor_.OnMessage(*message); |
56 delete message; | 58 delete message; |
57 return true; | 59 return true; |
58 } | 60 } |
59 | 61 |
60 void set_mock_timer(scoped_ptr<base::Timer> timer) { | 62 void set_mock_timer(scoped_ptr<base::Timer> timer) { |
61 ASSERT_EQ(nullptr, mock_timer_); | 63 ASSERT_EQ(nullptr, mock_timer_); |
62 mock_timer_ = timer.Pass(); | 64 mock_timer_ = std::move(timer); |
63 } | 65 } |
64 | 66 |
65 MOCK_CONST_METHOD0(GetTiming, PageLoadTiming()); | 67 MOCK_CONST_METHOD0(GetTiming, PageLoadTiming()); |
66 MOCK_CONST_METHOD0(ShouldSendMetrics, bool()); | 68 MOCK_CONST_METHOD0(ShouldSendMetrics, bool()); |
67 MOCK_CONST_METHOD0(HasNoRenderFrame, bool()); | 69 MOCK_CONST_METHOD0(HasNoRenderFrame, bool()); |
68 MockIPCInterceptor* ipc_interceptor() { return &interceptor_; } | 70 MockIPCInterceptor* ipc_interceptor() { return &interceptor_; } |
69 | 71 |
70 private: | 72 private: |
71 StrictMock<MockIPCInterceptor> interceptor_; | 73 StrictMock<MockIPCInterceptor> interceptor_; |
72 mutable scoped_ptr<base::Timer> mock_timer_; | 74 mutable scoped_ptr<base::Timer> mock_timer_; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 190 |
189 base::MockTimer* mock_timer2 = new base::MockTimer(false, false); | 191 base::MockTimer* mock_timer2 = new base::MockTimer(false, false); |
190 observer.set_mock_timer(make_scoped_ptr(mock_timer2)); | 192 observer.set_mock_timer(make_scoped_ptr(mock_timer2)); |
191 observer.DidCommitProvisionalLoad(true, false); | 193 observer.DidCommitProvisionalLoad(true, false); |
192 EXPECT_CALL(*observer.ipc_interceptor(), OnTimingUpdated(timing)); | 194 EXPECT_CALL(*observer.ipc_interceptor(), OnTimingUpdated(timing)); |
193 observer.DidChangePerformanceTiming(); | 195 observer.DidChangePerformanceTiming(); |
194 mock_timer2->Fire(); | 196 mock_timer2->Fire(); |
195 } | 197 } |
196 | 198 |
197 } // namespace page_load_metrics | 199 } // namespace page_load_metrics |
OLD | NEW |