| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/native_web_keyboard_event.h" | 5 #include "chrome/common/native_web_keyboard_event.h" |
| 6 #include "chrome/common/render_messages.h" | 6 #include "chrome/common/render_messages.h" |
| 7 #include "chrome/test/render_view_test.h" | 7 #include "chrome/test/render_view_test.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "webkit/api/public/WebString.h" | 9 #include "webkit/api/public/WebString.h" |
| 10 | 10 |
| 11 #include <Cocoa/Cocoa.h> | 11 #include <Cocoa/Cocoa.h> |
| 12 #include <Carbon/Carbon.h> // for the kVK_* constants. | 12 #include <Carbon/Carbon.h> // for the kVK_* constants. |
| 13 | 13 |
| 14 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { | 14 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { |
| 15 | |
| 16 UniChar uniChar = 0; | 15 UniChar uniChar = 0; |
| 17 switch(code) { | 16 switch(code) { |
| 18 case kVK_UpArrow: uniChar = NSUpArrowFunctionKey; break; | 17 case kVK_UpArrow: |
| 19 case kVK_DownArrow: uniChar = NSDownArrowFunctionKey; break; | 18 uniChar = NSUpArrowFunctionKey; |
| 20 default: CHECK(false); | 19 break; |
| 20 case kVK_DownArrow: |
| 21 uniChar = NSDownArrowFunctionKey; |
| 22 break; |
| 23 default: |
| 24 CHECK(false); |
| 21 } | 25 } |
| 22 NSString* s = [NSString stringWithFormat:@"%C", uniChar]; | 26 NSString* s = [NSString stringWithFormat:@"%C", uniChar]; |
| 23 | 27 |
| 24 return [NSEvent keyEventWithType:type | 28 return [NSEvent keyEventWithType:type |
| 25 location:NSMakePoint(0, 0) | 29 location:NSMakePoint(0, 0) |
| 26 modifierFlags:NSCommandKeyMask | 30 modifierFlags:NSCommandKeyMask |
| 27 timestamp:0.0 | 31 timestamp:0.0 |
| 28 windowNumber:0 | 32 windowNumber:0 |
| 29 context:nil | 33 context:nil |
| 30 characters:s | 34 characters:s |
| 31 charactersIgnoringModifiers:s | 35 charactersIgnoringModifiers:s |
| 32 isARepeat:NO | 36 isARepeat:NO |
| 33 keyCode:code]; | 37 keyCode:code]; |
| 34 } | 38 } |
| 35 | 39 |
| 36 // Test that cmd-up/down scrolls the page exactly if it is not intercepted by | 40 // Test that cmd-up/down scrolls the page exactly if it is not intercepted by |
| 37 // javascript. | 41 // javascript. |
| 38 TEST_F(RenderViewTest, MacTestCmdUp) { | 42 TEST_F(RenderViewTest, MacTestCmdUp) { |
| 39 | |
| 40 // Some preprocessor trickery so that we can have literal html in our source, | 43 // Some preprocessor trickery so that we can have literal html in our source, |
| 41 // makes it easier to copy html to and from an html file for testing (the | 44 // makes it easier to copy html to and from an html file for testing (the |
| 42 // preprocessor will remove the newlines at the line ends, turning this into | 45 // preprocessor will remove the newlines at the line ends, turning this into |
| 43 // a single long line). | 46 // a single long line). |
| 44 #define HTML(s) #s | 47 #define HTML(s) #s |
| 45 const char* kRawHtml = HTML( | 48 const char* kRawHtml = HTML( |
| 46 <html> | 49 <html> |
| 47 <head><title></title> | 50 <head><title></title> |
| 48 <script type='text/javascript' language='javascript'> | 51 <script type='text/javascript' language='javascript'> |
| 49 function OnKeyEvent(ev) { | 52 function OnKeyEvent(ev) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 126 |
| 124 const char* kArrowUpNoScroll = | 127 const char* kArrowUpNoScroll = |
| 125 "38,false,false,true,false\np1\n\np2"; | 128 "38,false,false,true,false\np1\n\np2"; |
| 126 view_->OnSetEditCommandsForNextKeyEvent( | 129 view_->OnSetEditCommandsForNextKeyEvent( |
| 127 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 130 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
| 128 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 131 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
| 129 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 132 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
| 130 EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output)); | 133 EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output)); |
| 131 } | 134 } |
| 132 | 135 |
| OLD | NEW |