| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/base/render_view_test.h" | |
| 8 #include "content/common/native_web_keyboard_event.h" | 7 #include "content/common/native_web_keyboard_event.h" |
| 9 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.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; |
| 16 |
| 15 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { | 17 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { |
| 16 UniChar uniChar = 0; | 18 UniChar uniChar = 0; |
| 17 switch(code) { | 19 switch(code) { |
| 18 case kVK_UpArrow: | 20 case kVK_UpArrow: |
| 19 uniChar = NSUpArrowFunctionKey; | 21 uniChar = NSUpArrowFunctionKey; |
| 20 break; | 22 break; |
| 21 case kVK_DownArrow: | 23 case kVK_DownArrow: |
| 22 uniChar = NSDownArrowFunctionKey; | 24 uniChar = NSDownArrowFunctionKey; |
| 23 break; | 25 break; |
| 24 default: | 26 default: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 string16 output; | 93 string16 output; |
| 92 char htmlBuffer[2048]; | 94 char htmlBuffer[2048]; |
| 93 | 95 |
| 94 NSEvent* arrowDownKeyDown = CmdDeadKeyEvent(NSKeyDown, kVK_DownArrow); | 96 NSEvent* arrowDownKeyDown = CmdDeadKeyEvent(NSKeyDown, kVK_DownArrow); |
| 95 NSEvent* arrowUpKeyDown = CmdDeadKeyEvent(NSKeyDown, kVK_UpArrow); | 97 NSEvent* arrowUpKeyDown = CmdDeadKeyEvent(NSKeyDown, kVK_UpArrow); |
| 96 | 98 |
| 97 // First test when javascript does not eat keypresses -- should scroll. | 99 // First test when javascript does not eat keypresses -- should scroll. |
| 98 sprintf(htmlBuffer, kRawHtml, "true"); | 100 sprintf(htmlBuffer, kRawHtml, "true"); |
| 99 view->set_send_content_state_immediately(true); | 101 view->set_send_content_state_immediately(true); |
| 100 LoadHTML(htmlBuffer); | 102 LoadHTML(htmlBuffer); |
| 101 render_thread_.sink().ClearMessages(); | 103 render_thread_->sink().ClearMessages(); |
| 102 | 104 |
| 103 const char* kArrowDownScrollDown = | 105 const char* kArrowDownScrollDown = |
| 104 "40,false,false,true,false\n1936\np1\n\np2"; | 106 "40,false,false,true,false\n1936\np1\n\np2"; |
| 105 view->OnSetEditCommandsForNextKeyEvent( | 107 view->OnSetEditCommandsForNextKeyEvent( |
| 106 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); | 108 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); |
| 107 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); | 109 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); |
| 108 ProcessPendingMessages(); | 110 ProcessPendingMessages(); |
| 109 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 111 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
| 110 EXPECT_EQ(kArrowDownScrollDown, UTF16ToASCII(output)); | 112 EXPECT_EQ(kArrowDownScrollDown, UTF16ToASCII(output)); |
| 111 | 113 |
| 112 const char* kArrowUpScrollUp = | 114 const char* kArrowUpScrollUp = |
| 113 "38,false,false,true,false\n0\np1\n\np2"; | 115 "38,false,false,true,false\n0\np1\n\np2"; |
| 114 view->OnSetEditCommandsForNextKeyEvent( | 116 view->OnSetEditCommandsForNextKeyEvent( |
| 115 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 117 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
| 116 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 118 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
| 117 ProcessPendingMessages(); | 119 ProcessPendingMessages(); |
| 118 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 120 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
| 119 EXPECT_EQ(kArrowUpScrollUp, UTF16ToASCII(output)); | 121 EXPECT_EQ(kArrowUpScrollUp, UTF16ToASCII(output)); |
| 120 | 122 |
| 121 | 123 |
| 122 // Now let javascript eat the key events -- no scrolling should happen | 124 // Now let javascript eat the key events -- no scrolling should happen |
| 123 sprintf(htmlBuffer, kRawHtml, "false"); | 125 sprintf(htmlBuffer, kRawHtml, "false"); |
| 124 view->set_send_content_state_immediately(true); | 126 view->set_send_content_state_immediately(true); |
| 125 LoadHTML(htmlBuffer); | 127 LoadHTML(htmlBuffer); |
| 126 render_thread_.sink().ClearMessages(); | 128 render_thread_->sink().ClearMessages(); |
| 127 | 129 |
| 128 const char* kArrowDownNoScroll = | 130 const char* kArrowDownNoScroll = |
| 129 "40,false,false,true,false\np1\n\np2"; | 131 "40,false,false,true,false\np1\n\np2"; |
| 130 view->OnSetEditCommandsForNextKeyEvent( | 132 view->OnSetEditCommandsForNextKeyEvent( |
| 131 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); | 133 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); |
| 132 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); | 134 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); |
| 133 ProcessPendingMessages(); | 135 ProcessPendingMessages(); |
| 134 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 136 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
| 135 EXPECT_EQ(kArrowDownNoScroll, UTF16ToASCII(output)); | 137 EXPECT_EQ(kArrowDownNoScroll, UTF16ToASCII(output)); |
| 136 | 138 |
| 137 const char* kArrowUpNoScroll = | 139 const char* kArrowUpNoScroll = |
| 138 "38,false,false,true,false\np1\n\np2"; | 140 "38,false,false,true,false\np1\n\np2"; |
| 139 view->OnSetEditCommandsForNextKeyEvent( | 141 view->OnSetEditCommandsForNextKeyEvent( |
| 140 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 142 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
| 141 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 143 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
| 142 ProcessPendingMessages(); | 144 ProcessPendingMessages(); |
| 143 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 145 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
| 144 EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output)); | 146 EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output)); |
| 145 } | 147 } |
| 146 | 148 |
| OLD | NEW |