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/strings/string16.h" | 5 #include "base/strings/string16.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/public/browser/native_web_keyboard_event.h" | 8 #include "content/public/browser/native_web_keyboard_event.h" |
9 #include "content/public/common/web_preferences.h" | 9 #include "content/public/common/web_preferences.h" |
10 #include "content/public/test/render_view_test.h" | 10 #include "content/public/test/render_view_test.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // First test when javascript does not eat keypresses -- should scroll. | 96 // First test when javascript does not eat keypresses -- should scroll. |
97 view->set_send_content_state_immediately(true); | 97 view->set_send_content_state_immediately(true); |
98 LoadHTML(kRawHtml); | 98 LoadHTML(kRawHtml); |
99 render_thread_->sink().ClearMessages(); | 99 render_thread_->sink().ClearMessages(); |
100 | 100 |
101 const char* kArrowDownScrollDown = "40,false,false,true,false\n10144\np1"; | 101 const char* kArrowDownScrollDown = "40,false,false,true,false\n10144\np1"; |
102 view->OnSetEditCommandsForNextKeyEvent( | 102 view->OnSetEditCommandsForNextKeyEvent( |
103 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); | 103 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); |
104 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); | 104 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); |
105 ProcessPendingMessages(); | 105 ProcessPendingMessages(); |
106 ExecuteJavaScript("scroll.textContent = window.pageYOffset"); | 106 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
107 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 107 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
108 EXPECT_EQ(kArrowDownScrollDown, base::UTF16ToASCII(output)); | 108 EXPECT_EQ(kArrowDownScrollDown, base::UTF16ToASCII(output)); |
109 | 109 |
110 const char* kArrowUpScrollUp = "38,false,false,true,false\n0\np1"; | 110 const char* kArrowUpScrollUp = "38,false,false,true,false\n0\np1"; |
111 view->OnSetEditCommandsForNextKeyEvent( | 111 view->OnSetEditCommandsForNextKeyEvent( |
112 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 112 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
113 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 113 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
114 ProcessPendingMessages(); | 114 ProcessPendingMessages(); |
115 ExecuteJavaScript("scroll.textContent = window.pageYOffset"); | 115 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
116 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 116 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
117 EXPECT_EQ(kArrowUpScrollUp, base::UTF16ToASCII(output)); | 117 EXPECT_EQ(kArrowUpScrollUp, base::UTF16ToASCII(output)); |
118 | 118 |
119 // Now let javascript eat the key events -- no scrolling should happen. | 119 // Now let javascript eat the key events -- no scrolling should happen. |
120 // Set a scroll position slightly down the page to ensure that it does not | 120 // Set a scroll position slightly down the page to ensure that it does not |
121 // move. | 121 // move. |
122 ExecuteJavaScript("allowKeyEvents = false; window.scrollTo(0, 100)"); | 122 ExecuteJavaScriptForTests("allowKeyEvents = false; window.scrollTo(0, 100)"); |
123 | 123 |
124 const char* kArrowDownNoScroll = "40,false,false,true,false\n100\np1"; | 124 const char* kArrowDownNoScroll = "40,false,false,true,false\n100\np1"; |
125 view->OnSetEditCommandsForNextKeyEvent( | 125 view->OnSetEditCommandsForNextKeyEvent( |
126 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); | 126 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); |
127 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); | 127 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); |
128 ProcessPendingMessages(); | 128 ProcessPendingMessages(); |
129 ExecuteJavaScript("scroll.textContent = window.pageYOffset"); | 129 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
130 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 130 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
131 EXPECT_EQ(kArrowDownNoScroll, base::UTF16ToASCII(output)); | 131 EXPECT_EQ(kArrowDownNoScroll, base::UTF16ToASCII(output)); |
132 | 132 |
133 const char* kArrowUpNoScroll = "38,false,false,true,false\n100\np1"; | 133 const char* kArrowUpNoScroll = "38,false,false,true,false\n100\np1"; |
134 view->OnSetEditCommandsForNextKeyEvent( | 134 view->OnSetEditCommandsForNextKeyEvent( |
135 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 135 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
136 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 136 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
137 ProcessPendingMessages(); | 137 ProcessPendingMessages(); |
138 ExecuteJavaScript("scroll.textContent = window.pageYOffset"); | 138 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
139 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 139 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
140 EXPECT_EQ(kArrowUpNoScroll, base::UTF16ToASCII(output)); | 140 EXPECT_EQ(kArrowUpNoScroll, base::UTF16ToASCII(output)); |
141 } | 141 } |
142 | 142 |
143 } // namespace content | 143 } // namespace content |
OLD | NEW |