OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #include <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <tuple> | 10 #include <tuple> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/mac/scoped_nsautorelease_pool.h" | 13 #include "base/mac/scoped_nsautorelease_pool.h" |
14 #include "base/mac/sdk_forward_declarations.h" | 14 #include "base/mac/sdk_forward_declarations.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 19 #include "base/test/simple_test_tick_clock.h" |
19 #include "content/browser/browser_thread_impl.h" | 20 #include "content/browser/browser_thread_impl.h" |
20 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 21 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
21 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 22 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
22 #include "content/browser/gpu/compositor_util.h" | 23 #include "content/browser/gpu/compositor_util.h" |
23 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 24 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
24 #include "content/common/input_messages.h" | 25 #include "content/common/input_messages.h" |
25 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
26 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
27 #include "content/public/browser/render_widget_host_view_mac_delegate.h" | 28 #include "content/public/browser/render_widget_host_view_mac_delegate.h" |
28 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
29 #include "content/public/test/mock_render_process_host.h" | 30 #include "content/public/test/mock_render_process_host.h" |
30 #include "content/public/test/test_browser_context.h" | 31 #include "content/public/test/test_browser_context.h" |
31 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
32 #include "content/test/test_render_view_host.h" | 33 #include "content/test/test_render_view_host.h" |
33 #include "gpu/ipc/common/gpu_messages.h" | 34 #include "gpu/ipc/common/gpu_messages.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "testing/gtest_mac.h" | 37 #include "testing/gtest_mac.h" |
37 #import "third_party/ocmock/OCMock/OCMock.h" | 38 #import "third_party/ocmock/OCMock/OCMock.h" |
38 #import "third_party/ocmock/ocmock_extensions.h" | 39 #import "third_party/ocmock/ocmock_extensions.h" |
| 40 #include "ui/events/base_event_utils.h" |
39 #include "ui/events/latency_info.h" | 41 #include "ui/events/latency_info.h" |
40 #include "ui/events/test/cocoa_test_event_utils.h" | 42 #include "ui/events/test/cocoa_test_event_utils.h" |
41 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 43 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
42 | 44 |
43 // Helper class with methods used to mock -[NSEvent phase], used by | 45 // Helper class with methods used to mock -[NSEvent phase], used by |
44 // |MockScrollWheelEventWithPhase()|. | 46 // |MockScrollWheelEventWithPhase()|. |
45 @interface MockPhaseMethods : NSObject { | 47 @interface MockPhaseMethods : NSObject { |
46 } | 48 } |
47 | 49 |
48 - (NSEventPhase)phaseBegan; | 50 - (NSEventPhase)phaseBegan; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 origin.y() + line_no * size.height(), | 220 origin.y() + line_no * size.height(), |
219 range.length() * size.width(), | 221 range.length() * size.width(), |
220 size.height()); | 222 size.height()); |
221 } | 223 } |
222 | 224 |
223 // Returns NSScrollWheel event that mocks -phase. |mockPhaseSelector| should | 225 // Returns NSScrollWheel event that mocks -phase. |mockPhaseSelector| should |
224 // correspond to a method in |MockPhaseMethods| that returns the desired phase. | 226 // correspond to a method in |MockPhaseMethods| that returns the desired phase. |
225 NSEvent* MockScrollWheelEventWithPhase(SEL mockPhaseSelector, int32_t delta) { | 227 NSEvent* MockScrollWheelEventWithPhase(SEL mockPhaseSelector, int32_t delta) { |
226 CGEventRef cg_event = | 228 CGEventRef cg_event = |
227 CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, 1, delta, 0); | 229 CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, 1, delta, 0); |
| 230 CGEventTimestamp timestamp = 0; |
| 231 CGEventSetTimestamp(cg_event, timestamp); |
228 NSEvent* event = [NSEvent eventWithCGEvent:cg_event]; | 232 NSEvent* event = [NSEvent eventWithCGEvent:cg_event]; |
229 CFRelease(cg_event); | 233 CFRelease(cg_event); |
230 method_setImplementation( | 234 method_setImplementation( |
231 class_getInstanceMethod([NSEvent class], @selector(phase)), | 235 class_getInstanceMethod([NSEvent class], @selector(phase)), |
232 [MockPhaseMethods instanceMethodForSelector:mockPhaseSelector]); | 236 [MockPhaseMethods instanceMethodForSelector:mockPhaseSelector]); |
233 return event; | 237 return event; |
234 } | 238 } |
235 | 239 |
236 } // namespace | 240 } // namespace |
237 | 241 |
238 class RenderWidgetHostViewMacTest : public RenderViewHostImplTestHarness { | 242 class RenderWidgetHostViewMacTest : public RenderViewHostImplTestHarness { |
239 public: | 243 public: |
240 RenderWidgetHostViewMacTest() : old_rwhv_(NULL), rwhv_mac_(NULL) {} | 244 RenderWidgetHostViewMacTest() : old_rwhv_(NULL), rwhv_mac_(NULL) { |
| 245 std::unique_ptr<base::SimpleTestTickClock> mock_clock( |
| 246 new base::SimpleTestTickClock()); |
| 247 mock_clock->Advance(base::TimeDelta::FromMilliseconds(100)); |
| 248 ui::SetEventTickClockForTesting(std::move(mock_clock)); |
| 249 } |
241 | 250 |
242 void SetUp() override { | 251 void SetUp() override { |
243 RenderViewHostImplTestHarness::SetUp(); | 252 RenderViewHostImplTestHarness::SetUp(); |
244 ImageTransportFactory::InitializeForUnitTests( | 253 ImageTransportFactory::InitializeForUnitTests( |
245 std::unique_ptr<ImageTransportFactory>( | 254 std::unique_ptr<ImageTransportFactory>( |
246 new NoTransportImageTransportFactory)); | 255 new NoTransportImageTransportFactory)); |
247 | 256 |
248 // TestRenderViewHost's destruction assumes that its view is a | 257 // TestRenderViewHost's destruction assumes that its view is a |
249 // TestRenderWidgetHostView, so store its view and reset it back to the | 258 // TestRenderWidgetHostView, so store its view and reset it back to the |
250 // stored view in |TearDown()|. | 259 // stored view in |TearDown()|. |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. | 1251 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. |
1243 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); | 1252 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); |
1244 [view->cocoa_view() scrollWheel:wheelEvent]; | 1253 [view->cocoa_view() scrollWheel:wheelEvent]; |
1245 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); | 1254 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); |
1246 | 1255 |
1247 // Clean up. | 1256 // Clean up. |
1248 host->ShutdownAndDestroyWidget(true); | 1257 host->ShutdownAndDestroyWidget(true); |
1249 } | 1258 } |
1250 | 1259 |
1251 } // namespace content | 1260 } // namespace content |
OLD | NEW |