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)); | |
sadrul
2016/06/23 16:38:37
What is the purpose of this?
majidvp
2016/06/24 19:40:56
If I recall correctly, there was an assert somewhe
| |
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 // TestRenderViewHost's destruction assumes that its view is a | 253 // TestRenderViewHost's destruction assumes that its view is a |
245 // TestRenderWidgetHostView, so store its view and reset it back to the | 254 // TestRenderWidgetHostView, so store its view and reset it back to the |
246 // stored view in |TearDown()|. | 255 // stored view in |TearDown()|. |
247 old_rwhv_ = rvh()->GetWidget()->GetView(); | 256 old_rwhv_ = rvh()->GetWidget()->GetView(); |
248 | 257 |
249 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa_|. | 258 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa_|. |
250 rwhv_mac_ = new RenderWidgetHostViewMac(rvh()->GetWidget(), false); | 259 rwhv_mac_ = new RenderWidgetHostViewMac(rvh()->GetWidget(), false); |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. | 1246 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. |
1238 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); | 1247 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); |
1239 [view->cocoa_view() scrollWheel:wheelEvent]; | 1248 [view->cocoa_view() scrollWheel:wheelEvent]; |
1240 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); | 1249 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); |
1241 | 1250 |
1242 // Clean up. | 1251 // Clean up. |
1243 host->ShutdownAndDestroyWidget(true); | 1252 host->ShutdownAndDestroyWidget(true); |
1244 } | 1253 } |
1245 | 1254 |
1246 } // namespace content | 1255 } // namespace content |
OLD | NEW |