| 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 "chrome/test/render_view_test.h" | 5 #include "chrome/test/render_view_test.h" |
| 6 | 6 |
| 7 #include "chrome/common/native_web_keyboard_event.h" |
| 7 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 8 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 9 #include "chrome/renderer/extensions/event_bindings.h" | 10 #include "chrome/renderer/extensions/event_bindings.h" |
| 10 #include "chrome/renderer/extensions/extension_process_bindings.h" | 11 #include "chrome/renderer/extensions/extension_process_bindings.h" |
| 11 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 12 #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
| 12 #include "chrome/renderer/js_only_v8_extensions.h" | 13 #include "chrome/renderer/js_only_v8_extensions.h" |
| 14 #include "WebKit/api/public/WebInputEvent.h" |
| 13 #include "webkit/api/public/WebKit.h" | 15 #include "webkit/api/public/WebKit.h" |
| 14 #include "webkit/api/public/WebScriptSource.h" | 16 #include "webkit/api/public/WebScriptSource.h" |
| 15 #include "webkit/glue/weburlrequest.h" | 17 #include "webkit/glue/weburlrequest.h" |
| 16 #include "webkit/glue/webview.h" | 18 #include "webkit/glue/webview.h" |
| 17 | 19 |
| 18 using WebKit::WebScriptSource; | 20 using WebKit::WebScriptSource; |
| 19 using WebKit::WebString; | 21 using WebKit::WebString; |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 ExtensionProcessBindings::SetFunctionNames(names); | 69 ExtensionProcessBindings::SetFunctionNames(names); |
| 68 | 70 |
| 69 mock_process_.reset(new MockProcess()); | 71 mock_process_.reset(new MockProcess()); |
| 70 | 72 |
| 71 render_thread_.set_routing_id(kRouteId); | 73 render_thread_.set_routing_id(kRouteId); |
| 72 | 74 |
| 73 // This needs to pass the mock render thread to the view. | 75 // This needs to pass the mock render thread to the view. |
| 74 view_ = RenderView::Create(&render_thread_, NULL, NULL, kOpenerId, | 76 view_ = RenderView::Create(&render_thread_, NULL, NULL, kOpenerId, |
| 75 WebPreferences(), | 77 WebPreferences(), |
| 76 new SharedRenderViewCounter(0), kRouteId); | 78 new SharedRenderViewCounter(0), kRouteId); |
| 79 |
| 80 // Attach a pseudo keyboard device to this object. |
| 81 mock_keyboard_.reset(new MockKeyboard()); |
| 77 } | 82 } |
| 78 void RenderViewTest::TearDown() { | 83 void RenderViewTest::TearDown() { |
| 79 render_thread_.SendCloseMessage(); | 84 render_thread_.SendCloseMessage(); |
| 80 | 85 |
| 81 // Run the loop so the release task from the renderwidget executes. | 86 // Run the loop so the release task from the renderwidget executes. |
| 82 ProcessPendingMessages(); | 87 ProcessPendingMessages(); |
| 83 | 88 |
| 84 EventBindings::SetRenderThread(NULL); | 89 EventBindings::SetRenderThread(NULL); |
| 85 | 90 |
| 86 view_ = NULL; | 91 view_ = NULL; |
| 87 | 92 |
| 88 mock_process_.reset(); | 93 mock_process_.reset(); |
| 89 WebKit::shutdown(); | 94 WebKit::shutdown(); |
| 90 | 95 |
| 91 msg_loop_.RunAllPending(); | 96 msg_loop_.RunAllPending(); |
| 97 |
| 98 mock_keyboard_.reset(); |
| 92 } | 99 } |
| 100 |
| 101 int RenderViewTest::SendKeyEvent(MockKeyboard::Layout layout, |
| 102 int key_code, |
| 103 MockKeyboard::Modifiers modifiers, |
| 104 std::wstring* output) { |
| 105 #if defined(OS_WIN) |
| 106 // Retrieve the Unicode character for the given tuple (keyboard-layout, |
| 107 // key-code, and modifiers). |
| 108 // Exit when a keyboard-layout driver cannot assign a Unicode character to |
| 109 // the tuple to prevent sending an invalid key code to the RenderView object. |
| 110 CHECK(mock_keyboard_.get()); |
| 111 CHECK(output); |
| 112 int length = mock_keyboard_->GetCharacters(layout, key_code, modifiers, |
| 113 output); |
| 114 if (length != 1) |
| 115 return -1; |
| 116 |
| 117 // Create IPC messages from Windows messages and send them to our |
| 118 // back-end. |
| 119 // A keyboard event of Windows consists of three Windows messages: |
| 120 // WM_KEYDOWN, WM_CHAR, and WM_KEYUP. |
| 121 // WM_KEYDOWN and WM_KEYUP sends virtual-key codes. On the other hand, |
| 122 // WM_CHAR sends a composed Unicode character. |
| 123 NativeWebKeyboardEvent keydown_event(NULL, WM_KEYDOWN, key_code, 0); |
| 124 scoped_ptr<IPC::Message> keydown_message(new ViewMsg_HandleInputEvent(0)); |
| 125 keydown_message->WriteData(reinterpret_cast<const char*>(&keydown_event), |
| 126 sizeof(WebKit::WebKeyboardEvent)); |
| 127 view_->OnHandleInputEvent(*keydown_message); |
| 128 |
| 129 NativeWebKeyboardEvent char_event(NULL, WM_CHAR, (*output)[0], 0); |
| 130 scoped_ptr<IPC::Message> char_message(new ViewMsg_HandleInputEvent(0)); |
| 131 char_message->WriteData(reinterpret_cast<const char*>(&char_event), |
| 132 sizeof(WebKit::WebKeyboardEvent)); |
| 133 view_->OnHandleInputEvent(*char_message); |
| 134 |
| 135 NativeWebKeyboardEvent keyup_event(NULL, WM_KEYUP, key_code, 0); |
| 136 scoped_ptr<IPC::Message> keyup_message(new ViewMsg_HandleInputEvent(0)); |
| 137 keyup_message->WriteData(reinterpret_cast<const char*>(&keyup_event), |
| 138 sizeof(WebKit::WebKeyboardEvent)); |
| 139 view_->OnHandleInputEvent(*keyup_message); |
| 140 |
| 141 return length; |
| 142 #else |
| 143 NOTIMPLEMENTED(); |
| 144 return L'\0'; |
| 145 #endif |
| 146 } |
| OLD | NEW |