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 | |
112 id MockGestureEvent(NSEventType type, double magnification) { | 96 id MockGestureEvent(NSEventType type, double magnification) { |
113 id event = [OCMockObject mockForClass:[NSEvent class]]; | 97 id event = [OCMockObject mockForClass:[NSEvent class]]; |
114 NSPoint locationInWindow = NSMakePoint(0, 0); | 98 NSPoint locationInWindow = NSMakePoint(0, 0); |
115 CGFloat deltaX = 0; | 99 CGFloat deltaX = 0; |
116 CGFloat deltaY = 0; | 100 CGFloat deltaY = 0; |
117 NSTimeInterval timestamp = 1; | 101 NSTimeInterval timestamp = 1; |
118 NSUInteger modifierFlags = 0; | 102 NSUInteger modifierFlags = 0; |
119 | 103 |
120 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; | 104 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; |
121 [(NSEvent*)[[event stub] | 105 [(NSEvent*)[[event stub] |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 324 |
341 // Command-ESC will destroy the view, while the window is still in | 325 // Command-ESC will destroy the view, while the window is still in |
342 // |-performKeyEquivalent:|. There are other cases where this can | 326 // |-performKeyEquivalent:|. There are other cases where this can |
343 // happen, Command-ESC is the easiest to trigger. | 327 // happen, Command-ESC is the easiest to trigger. |
344 [[view->cocoa_view() window] performKeyEquivalent: | 328 [[view->cocoa_view() window] performKeyEquivalent: |
345 cocoa_test_event_utils::KeyEventWithKeyCode( | 329 cocoa_test_event_utils::KeyEventWithKeyCode( |
346 53, 27, NSKeyDown, NSCommandKeyMask)]; | 330 53, 27, NSKeyDown, NSCommandKeyMask)]; |
347 observer.Wait(); | 331 observer.Wait(); |
348 } | 332 } |
349 | 333 |
350 // Test that NSEvent of private use character won't generate keypress event | |
351 // http://crbug.com/459089 | |
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 but shouldn't | |
364 // fire keypress event | |
365 process_host->sink().ClearMessages(); | |
366 EXPECT_EQ(0U, process_host->sink().message_count()); | |
367 [view->cocoa_view() keyEvent: | |
368 cocoa_test_event_utils::KeyEventWithKeyCode( | |
369 0x7B, 0xF70F, NSKeyDown, NSControlKeyMask)]; | |
370 EXPECT_EQ(1U, process_host->sink().message_count()); | |
371 EXPECT_EQ("RawKeyDown", GetInputMessageTypes(process_host)); | |
372 | |
373 // Simulate ctrl+delete, will produce a private use character but shouldn't | |
374 // fire keypress event | |
375 process_host->sink().ClearMessages(); | |
376 EXPECT_EQ(0U, process_host->sink().message_count()); | |
377 [view->cocoa_view() keyEvent: | |
378 cocoa_test_event_utils::KeyEventWithKeyCode( | |
379 0x2E, 0xF728, NSKeyDown, NSControlKeyMask)]; | |
380 EXPECT_EQ(1U, process_host->sink().message_count()); | |
381 EXPECT_EQ("RawKeyDown", GetInputMessageTypes(process_host)); | |
382 | |
383 // Simulate a printable char, should generate keypress event | |
384 process_host->sink().ClearMessages(); | |
385 EXPECT_EQ(0U, process_host->sink().message_count()); | |
386 [view->cocoa_view() keyEvent: | |
387 cocoa_test_event_utils::KeyEventWithKeyCode( | |
388 0x58, 'x', NSKeyDown, NSControlKeyMask)]; | |
389 EXPECT_EQ(2U, process_host->sink().message_count()); | |
390 EXPECT_EQ("RawKeyDown Char", GetInputMessageTypes(process_host)); | |
391 | |
392 // Clean up. | |
393 host->Shutdown(); | |
394 } | |
395 | |
396 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { | 334 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { |
397 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); | 335 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); |
398 const size_t kDummyOffset = 0; | 336 const size_t kDummyOffset = 0; |
399 | 337 |
400 gfx::Rect caret_rect(10, 11, 0, 10); | 338 gfx::Rect caret_rect(10, 11, 0, 10); |
401 gfx::Range caret_range(0, 0); | 339 gfx::Range caret_range(0, 0); |
402 ViewHostMsg_SelectionBounds_Params params; | 340 ViewHostMsg_SelectionBounds_Params params; |
403 | 341 |
404 NSRect rect; | 342 NSRect rect; |
405 NSRange actual_range; | 343 NSRange actual_range; |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 EXPECT_EQ(1U, process_host_->sink().message_count()); | 1055 EXPECT_EQ(1U, process_host_->sink().message_count()); |
1118 process_host_->sink().ClearMessages(); | 1056 process_host_->sink().ClearMessages(); |
1119 } | 1057 } |
1120 | 1058 |
1121 // Clean up. | 1059 // Clean up. |
1122 host->Shutdown(); | 1060 host->Shutdown(); |
1123 } | 1061 } |
1124 | 1062 |
1125 | 1063 |
1126 } // namespace content | 1064 } // namespace content |
OLD | NEW |