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 "base/string16.h" | 5 #include "base/string16.h" |
6 #include "chrome/common/native_web_keyboard_event.h" | 6 #include "chrome/common/native_web_keyboard_event.h" |
7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "chrome/test/render_view_test.h" | 8 #include "chrome/test/render_view_test.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 windowNumber:0 | 32 windowNumber:0 |
33 context:nil | 33 context:nil |
34 characters:s | 34 characters:s |
35 charactersIgnoringModifiers:s | 35 charactersIgnoringModifiers:s |
36 isARepeat:NO | 36 isARepeat:NO |
37 keyCode:code]; | 37 keyCode:code]; |
38 } | 38 } |
39 | 39 |
40 // 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 |
41 // javascript. | 41 // javascript. |
42 TEST_F(RenderViewTest, DISABLED_MacTestCmdUp) { | 42 TEST_F(RenderViewTest, MacTestCmdUp) { |
43 // 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, |
44 // 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 |
45 // 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 |
46 // a single long line). | 46 // a single long line). |
47 #define HTML(s) #s | 47 #define HTML(s) #s |
48 const char* kRawHtml = HTML( | 48 const char* kRawHtml = HTML( |
49 <html> | 49 <html> |
50 <head><title></title> | 50 <head><title></title> |
51 <script type='text/javascript' language='javascript'> | 51 <script type='text/javascript' language='javascript'> |
52 function OnKeyEvent(ev) { | 52 function OnKeyEvent(ev) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 sprintf(htmlBuffer, kRawHtml, "true"); | 91 sprintf(htmlBuffer, kRawHtml, "true"); |
92 view_->set_send_content_state_immediately(true); | 92 view_->set_send_content_state_immediately(true); |
93 LoadHTML(htmlBuffer); | 93 LoadHTML(htmlBuffer); |
94 render_thread_.sink().ClearMessages(); | 94 render_thread_.sink().ClearMessages(); |
95 | 95 |
96 const char* kArrowDownScrollDown = | 96 const char* kArrowDownScrollDown = |
97 "40,false,false,true,false\n1936\np1\n\np2"; | 97 "40,false,false,true,false\n1936\np1\n\np2"; |
98 view_->OnSetEditCommandsForNextKeyEvent( | 98 view_->OnSetEditCommandsForNextKeyEvent( |
99 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); | 99 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); |
100 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); | 100 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); |
| 101 ProcessPendingMessages(); |
101 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 102 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
102 EXPECT_EQ(kArrowDownScrollDown, UTF16ToASCII(output)); | 103 EXPECT_EQ(kArrowDownScrollDown, UTF16ToASCII(output)); |
103 | 104 |
104 const char* kArrowUpScrollUp = | 105 const char* kArrowUpScrollUp = |
105 "38,false,false,true,false\n0\np1\n\np2"; | 106 "38,false,false,true,false\n0\np1\n\np2"; |
106 view_->OnSetEditCommandsForNextKeyEvent( | 107 view_->OnSetEditCommandsForNextKeyEvent( |
107 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 108 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
108 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 109 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
| 110 ProcessPendingMessages(); |
109 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 111 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
110 EXPECT_EQ(kArrowUpScrollUp, UTF16ToASCII(output)); | 112 EXPECT_EQ(kArrowUpScrollUp, UTF16ToASCII(output)); |
111 | 113 |
112 | 114 |
113 // Now let javascript eat the key events -- no scrolling should happen | 115 // Now let javascript eat the key events -- no scrolling should happen |
114 sprintf(htmlBuffer, kRawHtml, "false"); | 116 sprintf(htmlBuffer, kRawHtml, "false"); |
115 view_->set_send_content_state_immediately(true); | 117 view_->set_send_content_state_immediately(true); |
116 LoadHTML(htmlBuffer); | 118 LoadHTML(htmlBuffer); |
117 render_thread_.sink().ClearMessages(); | 119 render_thread_.sink().ClearMessages(); |
118 | 120 |
119 const char* kArrowDownNoScroll = | 121 const char* kArrowDownNoScroll = |
120 "40,false,false,true,false\np1\n\np2"; | 122 "40,false,false,true,false\np1\n\np2"; |
121 view_->OnSetEditCommandsForNextKeyEvent( | 123 view_->OnSetEditCommandsForNextKeyEvent( |
122 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); | 124 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); |
123 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); | 125 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); |
| 126 ProcessPendingMessages(); |
124 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 127 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
125 EXPECT_EQ(kArrowDownNoScroll, UTF16ToASCII(output)); | 128 EXPECT_EQ(kArrowDownNoScroll, UTF16ToASCII(output)); |
126 | 129 |
127 const char* kArrowUpNoScroll = | 130 const char* kArrowUpNoScroll = |
128 "38,false,false,true,false\np1\n\np2"; | 131 "38,false,false,true,false\np1\n\np2"; |
129 view_->OnSetEditCommandsForNextKeyEvent( | 132 view_->OnSetEditCommandsForNextKeyEvent( |
130 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 133 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
131 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 134 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
| 135 ProcessPendingMessages(); |
132 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 136 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
133 EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output)); | 137 EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output)); |
134 } | 138 } |
135 | 139 |
OLD | NEW |