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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/string16.h" | 6 #include "base/string16.h" |
7 #include "content/public/browser/native_web_keyboard_event.h" | 7 #include "content/public/browser/native_web_keyboard_event.h" |
8 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
9 #include "content/test/render_view_test.h" | 9 #include "content/test/render_view_test.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 #include <Cocoa/Cocoa.h> | 12 #include <Cocoa/Cocoa.h> |
13 #include <Carbon/Carbon.h> // for the kVK_* constants. | 13 #include <Carbon/Carbon.h> // for the kVK_* constants. |
14 | 14 |
15 using content::RenderViewTest; | 15 using content::RenderViewTest; |
16 | 16 |
17 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { | 17 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { |
18 UniChar uniChar = 0; | 18 UniChar uniChar = 0; |
19 switch(code) { | 19 switch(code) { |
20 case kVK_UpArrow: | 20 case kVK_UpArrow: |
21 uniChar = NSUpArrowFunctionKey; | 21 uniChar = NSUpArrowFunctionKey; |
22 break; | 22 break; |
23 case kVK_DownArrow: | 23 case kVK_DownArrow: |
24 uniChar = NSDownArrowFunctionKey; | 24 uniChar = NSDownArrowFunctionKey; |
25 break; | 25 break; |
26 default: | 26 default: |
27 CHECK(false); | 27 CHECK(false); |
28 } | 28 } |
29 // TODO(thakis): Remove this once clang is smarter, http://crbug.com/111861 | |
30 #pragma clang diagnostic push | |
31 #pragma clang diagnostic ignored "-Wformat" | |
32 NSString* s = [NSString stringWithFormat:@"%C", uniChar]; | 29 NSString* s = [NSString stringWithFormat:@"%C", uniChar]; |
33 #pragma clang diagnostic pop | |
34 | 30 |
35 return [NSEvent keyEventWithType:type | 31 return [NSEvent keyEventWithType:type |
36 location:NSMakePoint(0, 0) | 32 location:NSMakePoint(0, 0) |
37 modifierFlags:NSCommandKeyMask | 33 modifierFlags:NSCommandKeyMask |
38 timestamp:0.0 | 34 timestamp:0.0 |
39 windowNumber:0 | 35 windowNumber:0 |
40 context:nil | 36 context:nil |
41 characters:s | 37 characters:s |
42 charactersIgnoringModifiers:s | 38 charactersIgnoringModifiers:s |
43 isARepeat:NO | 39 isARepeat:NO |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const char* kArrowUpNoScroll = | 139 const char* kArrowUpNoScroll = |
144 "38,false,false,true,false\np1\n\np2"; | 140 "38,false,false,true,false\np1\n\np2"; |
145 view->OnSetEditCommandsForNextKeyEvent( | 141 view->OnSetEditCommandsForNextKeyEvent( |
146 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 142 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
147 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 143 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
148 ProcessPendingMessages(); | 144 ProcessPendingMessages(); |
149 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 145 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
150 EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output)); | 146 EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output)); |
151 } | 147 } |
152 | 148 |
OLD | NEW |