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 | 8 |
9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 - (BOOL)canRubberbandRight:(NSView*)view { | 86 - (BOOL)canRubberbandRight:(NSView*)view { |
87 return true; | 87 return true; |
88 } | 88 } |
89 | 89 |
90 @end | 90 @end |
91 | 91 |
92 namespace content { | 92 namespace content { |
93 | 93 |
94 namespace { | 94 namespace { |
95 | 95 |
| 96 std::string GetInputMessageTypes(MockRenderProcessHost* process) { |
| 97 std::string result; |
| 98 for (size_t i = 0; i < process->sink().message_count(); ++i) { |
| 99 const IPC::Message* message = process->sink().GetMessageAt(i); |
| 100 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); |
| 101 InputMsg_HandleInputEvent::Param params; |
| 102 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); |
| 103 const blink::WebInputEvent* event = base::get<0>(params); |
| 104 if (i != 0) |
| 105 result += " "; |
| 106 result += WebInputEventTraits::GetName(event->type); |
| 107 } |
| 108 process->sink().ClearMessages(); |
| 109 return result; |
| 110 } |
| 111 |
96 id MockGestureEvent(NSEventType type, double magnification) { | 112 id MockGestureEvent(NSEventType type, double magnification) { |
97 id event = [OCMockObject mockForClass:[NSEvent class]]; | 113 id event = [OCMockObject mockForClass:[NSEvent class]]; |
98 NSPoint locationInWindow = NSMakePoint(0, 0); | 114 NSPoint locationInWindow = NSMakePoint(0, 0); |
99 CGFloat deltaX = 0; | 115 CGFloat deltaX = 0; |
100 CGFloat deltaY = 0; | 116 CGFloat deltaY = 0; |
101 NSTimeInterval timestamp = 1; | 117 NSTimeInterval timestamp = 1; |
102 NSUInteger modifierFlags = 0; | 118 NSUInteger modifierFlags = 0; |
103 | 119 |
104 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; | 120 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; |
105 [(NSEvent*)[[event stub] | 121 [(NSEvent*)[[event stub] |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 340 |
325 // Command-ESC will destroy the view, while the window is still in | 341 // Command-ESC will destroy the view, while the window is still in |
326 // |-performKeyEquivalent:|. There are other cases where this can | 342 // |-performKeyEquivalent:|. There are other cases where this can |
327 // happen, Command-ESC is the easiest to trigger. | 343 // happen, Command-ESC is the easiest to trigger. |
328 [[view->cocoa_view() window] performKeyEquivalent: | 344 [[view->cocoa_view() window] performKeyEquivalent: |
329 cocoa_test_event_utils::KeyEventWithKeyCode( | 345 cocoa_test_event_utils::KeyEventWithKeyCode( |
330 53, 27, NSKeyDown, NSCommandKeyMask)]; | 346 53, 27, NSKeyDown, NSCommandKeyMask)]; |
331 observer.Wait(); | 347 observer.Wait(); |
332 } | 348 } |
333 | 349 |
| 350 // Test that NSEvent of private use character won't generate keypress event |
| 351 // http://crbug.com/459089, ctrl+delete will be filtered in WebInputEventConvers
ion.cpp |
| 352 TEST_F(RenderWidgetHostViewMacTest, FilterNonPrintableCharacter) { |
| 353 TestBrowserContext browser_context; |
| 354 MockRenderProcessHost* process_host = |
| 355 new MockRenderProcessHost(&browser_context); |
| 356 process_host->Init(); |
| 357 MockRenderWidgetHostDelegate delegate; |
| 358 int32 routing_id = process_host->GetNextRoutingID(); |
| 359 MockRenderWidgetHostImpl* host = |
| 360 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); |
| 361 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); |
| 362 |
| 363 // Simulate ctrl+F12, will produce a private use character |
| 364 process_host->sink().ClearMessages(); |
| 365 EXPECT_EQ(0U, process_host->sink().message_count()); |
| 366 [view->cocoa_view() keyEvent: |
| 367 cocoa_test_event_utils::KeyEventWithKeyCode( |
| 368 111, 0xF70F, NSKeyDown, NSControlKeyMask)]; |
| 369 EXPECT_EQ(1U, process_host->sink().message_count()); |
| 370 EXPECT_EQ("RawKeyDown", GetInputMessageTypes(process_host)); |
| 371 |
| 372 // Simulate a printable char, should generate keypress event |
| 373 process_host->sink().ClearMessages(); |
| 374 EXPECT_EQ(0U, process_host->sink().message_count()); |
| 375 [view->cocoa_view() keyEvent: |
| 376 cocoa_test_event_utils::KeyEventWithKeyCode( |
| 377 0x78, 'x', NSKeyDown, NSControlKeyMask)]; |
| 378 EXPECT_EQ(2U, process_host->sink().message_count()); |
| 379 EXPECT_EQ("RawKeyDown Char", GetInputMessageTypes(process_host)); |
| 380 |
| 381 // Clean up. |
| 382 host->Shutdown(); |
| 383 } |
| 384 |
334 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { | 385 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { |
335 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); | 386 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); |
336 const size_t kDummyOffset = 0; | 387 const size_t kDummyOffset = 0; |
337 | 388 |
338 gfx::Rect caret_rect(10, 11, 0, 10); | 389 gfx::Rect caret_rect(10, 11, 0, 10); |
339 gfx::Range caret_range(0, 0); | 390 gfx::Range caret_range(0, 0); |
340 ViewHostMsg_SelectionBounds_Params params; | 391 ViewHostMsg_SelectionBounds_Params params; |
341 | 392 |
342 NSRect rect; | 393 NSRect rect; |
343 NSRange actual_range; | 394 NSRange actual_range; |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 EXPECT_EQ(1U, process_host_->sink().message_count()); | 1106 EXPECT_EQ(1U, process_host_->sink().message_count()); |
1056 process_host_->sink().ClearMessages(); | 1107 process_host_->sink().ClearMessages(); |
1057 } | 1108 } |
1058 | 1109 |
1059 // Clean up. | 1110 // Clean up. |
1060 host->Shutdown(); | 1111 host->Shutdown(); |
1061 } | 1112 } |
1062 | 1113 |
1063 | 1114 |
1064 } // namespace content | 1115 } // namespace content |
OLD | NEW |