| 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" |
| 11 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" | 13 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" |
| 14 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 14 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 15 #include "third_party/WebKit/public/web/WebView.h" | |
| 16 | 15 |
| 17 #include <Carbon/Carbon.h> // for the kVK_* constants. | 16 #include <Carbon/Carbon.h> // for the kVK_* constants. |
| 18 #include <Cocoa/Cocoa.h> | 17 #include <Cocoa/Cocoa.h> |
| 19 | 18 |
| 20 using blink::WebFrameContentDumper; | 19 using blink::WebFrameContentDumper; |
| 21 | 20 |
| 22 namespace content { | 21 namespace content { |
| 23 | 22 |
| 24 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { | 23 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { |
| 25 UniChar uniChar = 0; | 24 UniChar uniChar = 0; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 view->set_send_content_state_immediately(true); | 100 view->set_send_content_state_immediately(true); |
| 102 LoadHTML(kRawHtml); | 101 LoadHTML(kRawHtml); |
| 103 render_thread_->sink().ClearMessages(); | 102 render_thread_->sink().ClearMessages(); |
| 104 | 103 |
| 105 const char* kArrowDownScrollDown = "40,false,false,true,false\n10144\np1"; | 104 const char* kArrowDownScrollDown = "40,false,false,true,false\n10144\np1"; |
| 106 view->OnSetEditCommandsForNextKeyEvent( | 105 view->OnSetEditCommandsForNextKeyEvent( |
| 107 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); | 106 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); |
| 108 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); | 107 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); |
| 109 ProcessPendingMessages(); | 108 ProcessPendingMessages(); |
| 110 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); | 109 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
| 111 view->GetWebView()->updateAllLifecyclePhases(); | |
| 112 output = WebFrameContentDumper::dumpFrameTreeAsText(GetMainFrame(), | 110 output = WebFrameContentDumper::dumpFrameTreeAsText(GetMainFrame(), |
| 113 kMaxOutputCharacters); | 111 kMaxOutputCharacters); |
| 114 EXPECT_EQ(kArrowDownScrollDown, base::UTF16ToASCII(output)); | 112 EXPECT_EQ(kArrowDownScrollDown, base::UTF16ToASCII(output)); |
| 115 | 113 |
| 116 const char* kArrowUpScrollUp = "38,false,false,true,false\n0\np1"; | 114 const char* kArrowUpScrollUp = "38,false,false,true,false\n0\np1"; |
| 117 view->OnSetEditCommandsForNextKeyEvent( | 115 view->OnSetEditCommandsForNextKeyEvent( |
| 118 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 116 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
| 119 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 117 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
| 120 ProcessPendingMessages(); | 118 ProcessPendingMessages(); |
| 121 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); | 119 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
| 122 view->GetWebView()->updateAllLifecyclePhases(); | |
| 123 output = WebFrameContentDumper::dumpFrameTreeAsText(GetMainFrame(), | 120 output = WebFrameContentDumper::dumpFrameTreeAsText(GetMainFrame(), |
| 124 kMaxOutputCharacters); | 121 kMaxOutputCharacters); |
| 125 EXPECT_EQ(kArrowUpScrollUp, base::UTF16ToASCII(output)); | 122 EXPECT_EQ(kArrowUpScrollUp, base::UTF16ToASCII(output)); |
| 126 | 123 |
| 127 // Now let javascript eat the key events -- no scrolling should happen. | 124 // Now let javascript eat the key events -- no scrolling should happen. |
| 128 // Set a scroll position slightly down the page to ensure that it does not | 125 // Set a scroll position slightly down the page to ensure that it does not |
| 129 // move. | 126 // move. |
| 130 ExecuteJavaScriptForTests("allowKeyEvents = false; window.scrollTo(0, 100)"); | 127 ExecuteJavaScriptForTests("allowKeyEvents = false; window.scrollTo(0, 100)"); |
| 131 | 128 |
| 132 const char* kArrowDownNoScroll = "40,false,false,true,false\n100\np1"; | 129 const char* kArrowDownNoScroll = "40,false,false,true,false\n100\np1"; |
| 133 view->OnSetEditCommandsForNextKeyEvent( | 130 view->OnSetEditCommandsForNextKeyEvent( |
| 134 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); | 131 EditCommands(1, EditCommand("moveToEndOfDocument", ""))); |
| 135 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); | 132 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown)); |
| 136 ProcessPendingMessages(); | 133 ProcessPendingMessages(); |
| 137 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); | 134 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
| 138 view->GetWebView()->updateAllLifecyclePhases(); | |
| 139 output = WebFrameContentDumper::dumpFrameTreeAsText(GetMainFrame(), | 135 output = WebFrameContentDumper::dumpFrameTreeAsText(GetMainFrame(), |
| 140 kMaxOutputCharacters); | 136 kMaxOutputCharacters); |
| 141 EXPECT_EQ(kArrowDownNoScroll, base::UTF16ToASCII(output)); | 137 EXPECT_EQ(kArrowDownNoScroll, base::UTF16ToASCII(output)); |
| 142 | 138 |
| 143 const char* kArrowUpNoScroll = "38,false,false,true,false\n100\np1"; | 139 const char* kArrowUpNoScroll = "38,false,false,true,false\n100\np1"; |
| 144 view->OnSetEditCommandsForNextKeyEvent( | 140 view->OnSetEditCommandsForNextKeyEvent( |
| 145 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 141 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
| 146 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 142 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
| 147 ProcessPendingMessages(); | 143 ProcessPendingMessages(); |
| 148 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); | 144 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
| 149 view->GetWebView()->updateAllLifecyclePhases(); | |
| 150 output = WebFrameContentDumper::dumpFrameTreeAsText(GetMainFrame(), | 145 output = WebFrameContentDumper::dumpFrameTreeAsText(GetMainFrame(), |
| 151 kMaxOutputCharacters); | 146 kMaxOutputCharacters); |
| 152 EXPECT_EQ(kArrowUpNoScroll, base::UTF16ToASCII(output)); | 147 EXPECT_EQ(kArrowUpNoScroll, base::UTF16ToASCII(output)); |
| 153 } | 148 } |
| 154 | 149 |
| 155 } // namespace content | 150 } // namespace content |
| OLD | NEW |