OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <Cocoa/Cocoa.h> | 5 #include <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/simple_test_tick_clock.h" |
13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/render_widget_host.h" | 19 #include "content/public/browser/render_widget_host.h" |
19 #include "content/public/browser/render_widget_host_view.h" | 20 #include "content/public/browser/render_widget_host_view.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
22 #import "third_party/ocmock/OCMock/OCMock.h" | 23 #import "third_party/ocmock/OCMock/OCMock.h" |
23 #import "third_party/ocmock/ocmock_extensions.h" | 24 #import "third_party/ocmock/ocmock_extensions.h" |
| 25 #include "ui/events/base_event_utils.h" |
24 #include "url/gurl.h" | 26 #include "url/gurl.h" |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 // Refers to how the event is going to be sent to the NSView. There are 3 | 30 // Refers to how the event is going to be sent to the NSView. There are 3 |
29 // relevant sets of APIs. The current code relies on all three sets of APIs. | 31 // relevant sets of APIs. The current code relies on all three sets of APIs. |
30 // There is significant information duplication between the three sets of APIs, | 32 // There is significant information duplication between the three sets of APIs, |
31 // but the timing of the callbacks of the three APIs differ significantly. | 33 // but the timing of the callbacks of the three APIs differ significantly. |
32 enum Deployment { | 34 enum Deployment { |
33 // -[NSView touchesBeganWithEvent:] | 35 // -[NSView touchesBeganWithEvent:] |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 88 |
87 void SetUpOnMainThread() override { | 89 void SetUpOnMainThread() override { |
88 event_queue_.reset([[NSMutableArray alloc] init]); | 90 event_queue_.reset([[NSMutableArray alloc] init]); |
89 touch_ = CGPointMake(0.5, 0.5); | 91 touch_ = CGPointMake(0.5, 0.5); |
90 | 92 |
91 // Ensure that the navigation stack is not empty. | 93 // Ensure that the navigation stack is not empty. |
92 ui_test_utils::NavigateToURL(browser(), url1_); | 94 ui_test_utils::NavigateToURL(browser(), url1_); |
93 ASSERT_EQ(url1_, GetWebContents()->GetURL()); | 95 ASSERT_EQ(url1_, GetWebContents()->GetURL()); |
94 ui_test_utils::NavigateToURL(browser(), url2_); | 96 ui_test_utils::NavigateToURL(browser(), url2_); |
95 ASSERT_EQ(url2_, GetWebContents()->GetURL()); | 97 ASSERT_EQ(url2_, GetWebContents()->GetURL()); |
| 98 |
| 99 std::unique_ptr<base::SimpleTestTickClock> mock_clock( |
| 100 new base::SimpleTestTickClock()); |
| 101 mock_clock->Advance(base::TimeDelta::FromMilliseconds(100)); |
| 102 ui::SetEventTickClockForTesting(std::move(mock_clock)); |
96 } | 103 } |
97 | 104 |
98 void TearDownOnMainThread() override { event_queue_.reset(); } | 105 void TearDownOnMainThread() override { event_queue_.reset(); } |
99 | 106 |
100 protected: | 107 protected: |
101 // Returns the active web contents. | 108 // Returns the active web contents. |
102 content::WebContents* GetWebContents() { | 109 content::WebContents* GetWebContents() { |
103 return browser()->tab_strip_model()->GetActiveWebContents(); | 110 return browser()->tab_strip_model()->GetActiveWebContents(); |
104 } | 111 } |
105 | 112 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 CGEventSetIntegerValueField(cg_event, kCGScrollWheelEventIsContinuous, 1); | 160 CGEventSetIntegerValueField(cg_event, kCGScrollWheelEventIsContinuous, 1); |
154 CGEventSetIntegerValueField( | 161 CGEventSetIntegerValueField( |
155 cg_event, kCGScrollWheelEventPointDeltaAxis2, delta.x); | 162 cg_event, kCGScrollWheelEventPointDeltaAxis2, delta.x); |
156 CGEventSetIntegerValueField( | 163 CGEventSetIntegerValueField( |
157 cg_event, kCGScrollWheelEventPointDeltaAxis1, delta.y); | 164 cg_event, kCGScrollWheelEventPointDeltaAxis1, delta.y); |
158 NSEvent* event = [NSEvent eventWithCGEvent:cg_event]; | 165 NSEvent* event = [NSEvent eventWithCGEvent:cg_event]; |
159 CFRelease(cg_event); | 166 CFRelease(cg_event); |
160 | 167 |
161 id mock_event = [OCMockObject partialMockForObject:event]; | 168 id mock_event = [OCMockObject partialMockForObject:event]; |
162 [[[mock_event stub] andReturnBool:NO] isDirectionInvertedFromDevice]; | 169 [[[mock_event stub] andReturnBool:NO] isDirectionInvertedFromDevice]; |
| 170 NSTimeInterval timestamp = 0; |
| 171 [(NSEvent*)[[mock_event stub] |
| 172 andReturnValue:OCMOCK_VALUE(timestamp)] timestamp]; |
163 [(NSEvent*)[[mock_event stub] andReturnValue:OCMOCK_VALUE(type)] type]; | 173 [(NSEvent*)[[mock_event stub] andReturnValue:OCMOCK_VALUE(type)] type]; |
164 | 174 |
165 return mock_event; | 175 return mock_event; |
166 } | 176 } |
167 | 177 |
168 // Returns a scroll wheel event with the given parameters. | 178 // Returns a scroll wheel event with the given parameters. |
169 id ScrollWheelEventWithPhase(NSEventPhase phase, | 179 id ScrollWheelEventWithPhase(NSEventPhase phase, |
170 NSEventPhase momentum_phase, | 180 NSEventPhase momentum_phase, |
171 CGFloat scrolling_delta_x, | 181 CGFloat scrolling_delta_x, |
172 CGFloat scrolling_delta_y) { | 182 CGFloat scrolling_delta_y) { |
173 id event = MockScrollWheelEvent( | 183 id event = MockScrollWheelEvent( |
174 NSMakePoint(scrolling_delta_x, scrolling_delta_y), NSScrollWheel); | 184 NSMakePoint(scrolling_delta_x, scrolling_delta_y), NSScrollWheel); |
175 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(phase)] phase]; | 185 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(phase)] phase]; |
176 [(NSEvent*)[[event stub] | 186 [(NSEvent*)[[event stub] |
177 andReturnValue:OCMOCK_VALUE(momentum_phase)] momentumPhase]; | 187 andReturnValue:OCMOCK_VALUE(momentum_phase)] momentumPhase]; |
178 [(NSEvent*)[[event stub] | 188 [(NSEvent*)[[event stub] |
179 andReturnValue:OCMOCK_VALUE(scrolling_delta_x)] scrollingDeltaX]; | 189 andReturnValue:OCMOCK_VALUE(scrolling_delta_x)] scrollingDeltaX]; |
180 [(NSEvent*)[[event stub] | 190 [(NSEvent*)[[event stub] |
181 andReturnValue:OCMOCK_VALUE(scrolling_delta_y)] scrollingDeltaY]; | 191 andReturnValue:OCMOCK_VALUE(scrolling_delta_y)] scrollingDeltaY]; |
182 NSUInteger modifierFlags = 0; | 192 NSUInteger modifierFlags = 0; |
183 [(NSEvent*)[[event stub] | 193 [(NSEvent*)[[event stub] |
184 andReturnValue:OCMOCK_VALUE(modifierFlags)] modifierFlags]; | 194 andReturnValue:OCMOCK_VALUE(modifierFlags)] modifierFlags]; |
| 195 NSTimeInterval timestamp = 0; |
| 196 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(timestamp)] timestamp]; |
| 197 |
185 NSView* view = GetWebContents() | 198 NSView* view = GetWebContents() |
186 ->GetRenderViewHost() | 199 ->GetRenderViewHost() |
187 ->GetWidget() | 200 ->GetWidget() |
188 ->GetView() | 201 ->GetView() |
189 ->GetNativeView(); | 202 ->GetNativeView(); |
190 NSWindow* window = [view window]; | 203 NSWindow* window = [view window]; |
191 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(window)] window]; | 204 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(window)] window]; |
192 | 205 |
193 return event; | 206 return event; |
194 } | 207 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 id event = [OCMockObject mockForClass:[NSEvent class]]; | 247 id event = [OCMockObject mockForClass:[NSEvent class]]; |
235 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; | 248 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; |
236 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(subtype)] subtype]; | 249 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(subtype)] subtype]; |
237 | 250 |
238 id mock_touch = [OCMockObject mockForClass:[NSTouch class]]; | 251 id mock_touch = [OCMockObject mockForClass:[NSTouch class]]; |
239 [[[mock_touch stub] andReturnNSPoint:NSMakePoint(x, y)] normalizedPosition]; | 252 [[[mock_touch stub] andReturnNSPoint:NSMakePoint(x, y)] normalizedPosition]; |
240 NSArray* touches = @[ mock_touch ]; | 253 NSArray* touches = @[ mock_touch ]; |
241 [[[event stub] andReturn:touches] touchesMatchingPhase:NSTouchPhaseAny | 254 [[[event stub] andReturn:touches] touchesMatchingPhase:NSTouchPhaseAny |
242 inView:[OCMArg any]]; | 255 inView:[OCMArg any]]; |
243 [[[event stub] andReturnBool:NO] isDirectionInvertedFromDevice]; | 256 [[[event stub] andReturnBool:NO] isDirectionInvertedFromDevice]; |
| 257 NSTimeInterval timestamp = 0; |
| 258 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(timestamp)] timestamp]; |
| 259 |
244 QueueEvent(event, deployment, run_message_loop); | 260 QueueEvent(event, deployment, run_message_loop); |
245 } | 261 } |
246 | 262 |
247 // Convenience methods for event queuing ------------------------------------- | 263 // Convenience methods for event queuing ------------------------------------- |
248 | 264 |
249 // Trackpad scroll events are roughly related to touch events. Given a | 265 // Trackpad scroll events are roughly related to touch events. Given a |
250 // trackpad scroll delta, approximate the change to the touch event. | 266 // trackpad scroll delta, approximate the change to the touch event. |
251 void UpdateTouchLocationFromTrackpadScroll(int dx, int dy) { | 267 void UpdateTouchLocationFromTrackpadScroll(int dx, int dy) { |
252 touch_.x -= dx * 0.001; | 268 touch_.x -= dx * 0.001; |
253 touch_.y -= dy * 0.001; | 269 touch_.y -= dy * 0.001; |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 QueueTouch( | 762 QueueTouch( |
747 DEPLOYMENT_TOUCHES_MOVED, NSEventTypeEndGesture, NSMouseEventSubtype, NO); | 763 DEPLOYMENT_TOUCHES_MOVED, NSEventTypeEndGesture, NSMouseEventSubtype, NO); |
748 QueueGestureEnd(); | 764 QueueGestureEnd(); |
749 QueueTouch( | 765 QueueTouch( |
750 DEPLOYMENT_TOUCHES_ENDED, NSEventTypeEndGesture, NSMouseEventSubtype, NO); | 766 DEPLOYMENT_TOUCHES_ENDED, NSEventTypeEndGesture, NSMouseEventSubtype, NO); |
751 QueueTrackpadScroll(0, 0, NSEventPhaseEnded, YES); | 767 QueueTrackpadScroll(0, 0, NSEventPhaseEnded, YES); |
752 | 768 |
753 RunQueuedEvents(); | 769 RunQueuedEvents(); |
754 ExpectUrlAndOffset(url1_, 0); | 770 ExpectUrlAndOffset(url1_, 0); |
755 } | 771 } |
OLD | NEW |