summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-29 03:56:51 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-29 03:56:51 +0000
commit507b33eab2acbb4e360b5b6eb9f2e666079d0e3b (patch)
tree6fd3dd864e9da3e68efc7ded0dbaf96b597fcd3c /chrome/renderer
parent529338471fec2ab9b07bac9b07e3477b20e0ae28 (diff)
downloadchromium_src-507b33eab2acbb4e360b5b6eb9f2e666079d0e3b.zip
chromium_src-507b33eab2acbb4e360b5b6eb9f2e666079d0e3b.tar.gz
chromium_src-507b33eab2acbb4e360b5b6eb9f2e666079d0e3b.tar.bz2
Fix cmd-up/cmd-down.
The approach is to special-case moveToBeginningOfDocument and moveToEndOfDocument in WebFrameImpl::executeCommand(). With this (and the cocoa keyboard bindings patch being landed), the special-case code in WebViewImpl::ScrollViewWithKeyboard() can be removed. Also add a test for cmd-up/down. Change chrome.gyp so that it supports osx-only unit tests (_unittest_mac.mm). Move OnPrintPageAsBitmap to the other printing tests. BUG=22585 TEST=Go to a page with both text box and scrollbar (e.g. http://en.wikipedia.org ). Pressing cmd-down should scroll to end of page, cmd-up back to start. Clicking the text box and trying some emacs shortcuts should work (ctrl-a jumps to start of line, cmd-h acts as backspace, etc). Review URL: http://codereview.chromium.org/254002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27464 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/render_view.cc7
-rw-r--r--chrome/renderer/render_view.h3
-rw-r--r--chrome/renderer/render_view_unittest.cc84
-rw-r--r--chrome/renderer/render_view_unittest_mac.mm132
4 files changed, 183 insertions, 43 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 66ac3bf..8d9b3dd 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1511,13 +1511,18 @@ bool RenderView::handleCurrentKeyboardEvent() {
EditCommands::iterator it = edit_commands_.begin();
EditCommands::iterator end = edit_commands_.end();
+ bool did_execute_command = false;
for (; it != end; ++it) {
+ // In gtk, it's possible to bind multiple edit commands to one key (but it's
+ // the exception). Once one edit command is not executed, it seems safest to
+ // not execute the rest.
if (!frame->executeCommand(WebString::fromUTF8(it->name),
WebString::fromUTF8(it->value)))
break;
+ did_execute_command = true;
}
- return true;
+ return did_execute_command;
}
void RenderView::spellCheck(
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index decad59..ae0732a 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -448,6 +448,9 @@ class RenderView : public RenderWidget,
FRIEND_TEST(RenderViewTest, PrintLayoutTest);
FRIEND_TEST(RenderViewTest, OnHandleKeyboardEvent);
FRIEND_TEST(RenderViewTest, InsertCharacters);
+#if defined(OS_MACOSX)
+ FRIEND_TEST(RenderViewTest, MacTestCmdUp);
+#endif
explicit RenderView(RenderThreadBase* render_thread,
const WebPreferences& webkit_preferences);
diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc
index 5e10179..3119996 100644
--- a/chrome/renderer/render_view_unittest.cc
+++ b/chrome/renderer/render_view_unittest.cc
@@ -496,6 +496,48 @@ TEST_F(RenderViewTest, PrintLayoutTest) {
#endif
}
+// Print page as bitmap test.
+TEST_F(RenderViewTest, OnPrintPageAsBitmap) {
+#if defined(OS_WIN)
+ // Lets simulate a print pages with Hello world.
+ LoadHTML("<body><p>Hello world!</p></body>");
+
+ // Grab the printer settings from the printer.
+ ViewMsg_Print_Params print_settings;
+ MockPrinter* printer(render_thread_.printer());
+ printer->GetDefaultPrintSettings(&print_settings);
+ ViewMsg_PrintPage_Params page_params = ViewMsg_PrintPage_Params();
+ page_params.params = print_settings;
+ page_params.page_number = 0;
+
+ // Fetch the image data from the web frame.
+ std::vector<unsigned char> data;
+ view_->print_helper()->PrintPageAsJPEG(page_params,
+ view_->webview()->GetMainFrame(),
+ 1.0f,
+ &data);
+ std::vector<unsigned char> decoded;
+ int w, h;
+ EXPECT_TRUE(JPEGCodec::Decode(&data[0], data.size(), JPEGCodec::FORMAT_RGBA,
+ &decoded, &w, &h));
+
+ // Check if its not 100% white.
+ bool is_white = true;
+ for (int y = 0; y < h; y++) {
+ for (int x = 0; x < w; x++) {
+ unsigned char* px = &decoded[(y * w + x) * 4];
+ if (px[0] != 0xFF && px[1] != 0xFF && px[2] != 0xFF) {
+ is_white = false;
+ break;
+ }
+ }
+ }
+ ASSERT_TRUE(!is_white);
+#else
+ NOTIMPLEMENTED();
+#endif
+}
+
// Test that we can receive correct DOM events when we send input events
// through the RenderWidget::OnHandleInputEvent() function.
TEST_F(RenderViewTest, OnHandleKeyboardEvent) {
@@ -868,45 +910,3 @@ TEST_F(RenderViewTest, DidFailProvisionalLoadWithErrorForCancellation) {
// Frame should stay in view-source mode.
EXPECT_TRUE(web_frame->isViewSourceModeEnabled());
}
-
-// Print page as bitmap test.
-TEST_F(RenderViewTest, OnPrintPageAsBitmap) {
-#if defined(OS_WIN)
- // Lets simulate a print pages with Hello world.
- LoadHTML("<body><p>Hello world!</p></body>");
-
- // Grab the printer settings from the printer.
- ViewMsg_Print_Params print_settings;
- MockPrinter* printer(render_thread_.printer());
- printer->GetDefaultPrintSettings(&print_settings);
- ViewMsg_PrintPage_Params page_params = ViewMsg_PrintPage_Params();
- page_params.params = print_settings;
- page_params.page_number = 0;
-
- // Fetch the image data from the web frame.
- std::vector<unsigned char> data;
- view_->print_helper()->PrintPageAsJPEG(page_params,
- view_->webview()->GetMainFrame(),
- 1.0f,
- &data);
- std::vector<unsigned char> decoded;
- int w, h;
- EXPECT_TRUE(JPEGCodec::Decode(&data[0], data.size(), JPEGCodec::FORMAT_RGBA,
- &decoded, &w, &h));
-
- // Check if its not 100% white.
- bool is_white = true;
- for (int y = 0; y < h; y++) {
- for (int x = 0; x < w; x++) {
- unsigned char* px = &decoded[(y * w + x) * 4];
- if (px[0] != 0xFF && px[1] != 0xFF && px[2] != 0xFF) {
- is_white = false;
- break;
- }
- }
- }
- ASSERT_TRUE(!is_white);
-#else
- NOTIMPLEMENTED();
-#endif
-}
diff --git a/chrome/renderer/render_view_unittest_mac.mm b/chrome/renderer/render_view_unittest_mac.mm
new file mode 100644
index 0000000..e978626
--- /dev/null
+++ b/chrome/renderer/render_view_unittest_mac.mm
@@ -0,0 +1,132 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/native_web_keyboard_event.h"
+#include "chrome/common/render_messages.h"
+#include "chrome/test/render_view_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/api/public/WebString.h"
+
+#include <Cocoa/Cocoa.h>
+#include <Carbon/Carbon.h> // for the kVK_* constants.
+
+NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) {
+
+ UniChar uniChar;
+ switch(code) {
+ case kVK_UpArrow: uniChar = NSUpArrowFunctionKey; break;
+ case kVK_DownArrow: uniChar = NSDownArrowFunctionKey; break;
+ default: CHECK(false);
+ }
+ NSString* s = [NSString stringWithFormat:@"%C", uniChar];
+
+ return [NSEvent keyEventWithType:type
+ location:NSMakePoint(0, 0)
+ modifierFlags:NSCommandKeyMask
+ timestamp:0.0
+ windowNumber:0
+ context:nil
+ characters:s
+ charactersIgnoringModifiers:s
+ isARepeat:NO
+ keyCode:code];
+}
+
+// Test that cmd-up/down scrolls the page exactly if it is not intercepted by
+// javascript.
+TEST_F(RenderViewTest, MacTestCmdUp) {
+
+ // Some preprocessor trickery so that we can have literal html in our source,
+ // makes it easier to copy html to and from an html file for testing (the
+ // preprocessor will remove the newlines at the line ends, turning this into
+ // a single long line).
+ #define HTML(s) #s
+ const char* kRawHtml = HTML(
+ <html>
+ <head><title></title>
+ <script type='text/javascript' language='javascript'>
+ function OnKeyEvent(ev) {
+ var result = document.getElementById(ev.type);
+ result.innerText = (ev.which || ev.keyCode) + ',' +
+ ev.shiftKey + ',' +
+ ev.ctrlKey + ',' +
+ ev.metaKey + ',' +
+ ev.altKey;
+ return %s; /* Replace with "return true;" when testing in an html file. */
+ }
+ function OnScroll(ev) {
+ var result = document.getElementById("scroll");
+ result.innerText = window.pageYOffset;
+ return true;
+ }
+ </script>
+ <style type="text/css">
+ p { border-bottom:5000px solid black; } /* enforce vertical scroll bar */
+ </style>
+ </head>
+ <body
+ onscroll='return OnScroll(event);'
+ onkeydown='return OnKeyEvent(event);'>
+ <div id='keydown' contenteditable='true'> </div>
+ <div id='scroll' contenteditable='true'> </div>
+ <p>p1
+ <p>p2
+ </body>
+ </html>
+ );
+ #undef HTML
+
+ const int kMaxOutputCharacters = 1024;
+ string16 output;
+ char htmlBuffer[2048];
+
+ NSEvent* arrowDownKeyDown = CmdDeadKeyEvent(NSKeyDown, kVK_DownArrow);
+ NSEvent* arrowUpKeyDown = CmdDeadKeyEvent(NSKeyDown, kVK_UpArrow);
+
+ // First test when javascript does not eat keypresses -- should scroll.
+ sprintf(htmlBuffer, kRawHtml, "true");
+ view_->set_delay_seconds_for_form_state_sync(0);
+ LoadHTML(htmlBuffer);
+ render_thread_.sink().ClearMessages();
+
+ const char* kArrowDownScrollDown =
+ "40,false,false,true,false\n1936\np1\n\np2";
+ view_->OnSetEditCommandsForNextKeyEvent(
+ EditCommands(1, EditCommand("moveToEndOfDocument", "")));
+ SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown));
+ output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
+ EXPECT_EQ(kArrowDownScrollDown, UTF16ToASCII(output));
+
+ const char* kArrowUpScrollUp =
+ "38,false,false,true,false\n0\np1\n\np2";
+ view_->OnSetEditCommandsForNextKeyEvent(
+ EditCommands(1, EditCommand("moveToBeginningOfDocument", "")));
+ SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown));
+ output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
+ EXPECT_EQ(kArrowUpScrollUp, UTF16ToASCII(output));
+
+
+ // Now let javascript eat the key events -- no scrolling should happen
+ sprintf(htmlBuffer, kRawHtml, "false");
+ view_->set_delay_seconds_for_form_state_sync(0);
+ LoadHTML(htmlBuffer);
+ render_thread_.sink().ClearMessages();
+
+ const char* kArrowDownNoScroll =
+ "40,false,false,true,false\np1\n\np2";
+ view_->OnSetEditCommandsForNextKeyEvent(
+ EditCommands(1, EditCommand("moveToEndOfDocument", "")));
+ SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown));
+ output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
+ EXPECT_EQ(kArrowDownNoScroll, UTF16ToASCII(output));
+
+ const char* kArrowUpNoScroll =
+ "38,false,false,true,false\np1\n\np2";
+ view_->OnSetEditCommandsForNextKeyEvent(
+ EditCommands(1, EditCommand("moveToBeginningOfDocument", "")));
+ SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown));
+ output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
+ EXPECT_EQ(kArrowUpNoScroll, UTF16ToASCII(output));
+}
+