diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-04 02:27:14 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-04 02:27:14 +0000 |
commit | 899617f02fadb9caa43a51fd05a92d1be76bf35a (patch) | |
tree | 36033c3d0fd933f42050fccca2fcc021a34a187f | |
parent | e97882f3de584815e5b6af4491131aa8e318bc57 (diff) | |
download | chromium_src-899617f02fadb9caa43a51fd05a92d1be76bf35a.zip chromium_src-899617f02fadb9caa43a51fd05a92d1be76bf35a.tar.gz chromium_src-899617f02fadb9caa43a51fd05a92d1be76bf35a.tar.bz2 |
Move render_view_test.h header from content\test to content\public\test. This way we can enforce that internal content headers don't leak to embedders.
I moved the SendKeyEvent from RenderViewTest to RenderViewImplTest, which was the only class it was used in. This way we don't have to expose mock_keyboard.h as well.
BUG=98716
TBR=phajdan.jr
Review URL: https://chromiumcodereview.appspot.com/10497013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140255 0039d316-1c4b-4281-b951-d872f2087c98
16 files changed, 237 insertions, 210 deletions
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc index d806a88..52a1576 100644 --- a/chrome/browser/notifications/desktop_notifications_unittest.cc +++ b/chrome/browser/notifications/desktop_notifications_unittest.cc @@ -92,7 +92,7 @@ DesktopNotificationsTest::~DesktopNotificationsTest() { void DesktopNotificationsTest::SetUp() { #if defined(USE_ASH) - WebKit::initialize(&webkit_platform_support_); + WebKit::initialize(webkit_platform_support_.Get()); // MockBalloonCollection retrieves information about the screen on creation. // So it is necessary to make sure the desktop gets created first. ash::Shell::CreateInstance(NULL); diff --git a/chrome/browser/notifications/desktop_notifications_unittest.h b/chrome/browser/notifications/desktop_notifications_unittest.h index 7d82ec7..4f24508 100644 --- a/chrome/browser/notifications/desktop_notifications_unittest.h +++ b/chrome/browser/notifications/desktop_notifications_unittest.h @@ -17,7 +17,7 @@ #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/test/base/testing_pref_service.h" #include "chrome/test/base/testing_profile.h" -#include "content/test/render_view_test.h" +#include "content/public/test/render_view_test.h" #include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/sessions/tab_restore_service_browsertest.cc b/chrome/browser/sessions/tab_restore_service_browsertest.cc index 104e7eb..33c3ca3 100644 --- a/chrome/browser/sessions/tab_restore_service_browsertest.cc +++ b/chrome/browser/sessions/tab_restore_service_browsertest.cc @@ -21,7 +21,7 @@ #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" -#include "content/test/render_view_test.h" +#include "content/public/test/render_view_test.h" #include "content/test/web_contents_tester.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" @@ -62,7 +62,7 @@ class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { protected: // testing::Test overrides virtual void SetUp() { - WebKit::initialize(&webkit_platform_support_); + WebKit::initialize(webkit_platform_support_.Get()); ChromeRenderViewHostTestHarness::SetUp(); time_factory_ = new TabRestoreTimeFactory(); service_.reset(new TabRestoreService(profile(), time_factory_)); diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc index 14dcc7c..c25372f 100644 --- a/chrome/browser/translate/translate_manager_browsertest.cc +++ b/chrome/browser/translate/translate_manager_browsertest.cc @@ -36,7 +36,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/test/mock_notification_observer.h" #include "content/public/test/mock_render_process_host.h" -#include "content/test/render_view_test.h" +#include "content/public/test/render_view_test.h" #include "content/public/test/test_browser_thread.h" #include "content/test/test_renderer_host.h" #include "content/test/test_renderer_host.h" @@ -167,7 +167,7 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, protected: virtual void SetUp() { - WebKit::initialize(&webkit_platform_support_); + WebKit::initialize(webkit_platform_support_.Get()); // Access the TranslateManager singleton so it is created before we call // TabContentsWrapperTestHarness::SetUp() to match what's done in Chrome, // where the TranslateManager is created before the WebContents. This diff --git a/chrome/browser/ui/views/ash/window_positioner_unittest.cc b/chrome/browser/ui/views/ash/window_positioner_unittest.cc index d8a122d..dca79c3 100644 --- a/chrome/browser/ui/views/ash/window_positioner_unittest.cc +++ b/chrome/browser/ui/views/ash/window_positioner_unittest.cc @@ -15,7 +15,7 @@ #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/test_browser_window.h" #include "content/public/browser/browser_thread.h" -#include "content/test/render_view_test.h" +#include "content/public/test/render_view_test.h" #include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" diff --git a/chrome/browser/ui/window_sizer_ash_unittest.cc b/chrome/browser/ui/window_sizer_ash_unittest.cc index ed56208..03343da 100644 --- a/chrome/browser/ui/window_sizer_ash_unittest.cc +++ b/chrome/browser/ui/window_sizer_ash_unittest.cc @@ -18,7 +18,7 @@ #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/test_browser_window.h" #include "content/public/browser/browser_thread.h" -#include "content/test/render_view_test.h" +#include "content/public/test/render_view_test.h" #include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" diff --git a/chrome/renderer/automation/automation_renderer_helper_browsertest.cc b/chrome/renderer/automation/automation_renderer_helper_browsertest.cc index f69268c..02e7a6e 100644 --- a/chrome/renderer/automation/automation_renderer_helper_browsertest.cc +++ b/chrome/renderer/automation/automation_renderer_helper_browsertest.cc @@ -7,6 +7,7 @@ #include "base/json/json_reader.h" #include "base/md5.h" #include "base/utf_string_conversions.h" +#include "base/values.h" #include "chrome/common/automation_constants.h" #include "chrome/common/automation_events.h" #include "chrome/test/base/chrome_render_view_test.h" diff --git a/chrome/test/base/chrome_render_view_test.h b/chrome/test/base/chrome_render_view_test.h index 9bb6985..ae2094c 100644 --- a/chrome/test/base/chrome_render_view_test.h +++ b/chrome/test/base/chrome_render_view_test.h @@ -11,7 +11,7 @@ #include "chrome/renderer/autofill/autofill_agent.h" #include "chrome/renderer/chrome_mock_render_thread.h" #include "chrome/renderer/chrome_content_renderer_client.h" -#include "content/test/render_view_test.h" +#include "content/public/test/render_view_test.h" class ExtensionDispatcher; diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 3edae37..4977fb6 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -36,6 +36,7 @@ 'public/test/mock_render_thread.h', 'public/test/mock_resource_context.h', 'public/test/render_view_fake_resources_test.h', + 'public/test/render_view_test.h', 'public/test/test_browser_thread.h', 'public/test/test_navigation_observer.h', # TODO(phajdan.jr): All of those files should live in content/test (if @@ -91,7 +92,6 @@ 'test/net/url_request_abort_on_end_job.h', 'test/render_view_fake_resources_test.cc', 'test/render_view_test.cc', - 'test/render_view_test.h', 'test/test_browser_context.cc', 'test/test_browser_context.h', 'test/test_browser_thread.cc', diff --git a/content/test/render_view_test.h b/content/public/test/render_view_test.h index d48cdc9..5dfb670 100644 --- a/content/test/render_view_test.h +++ b/content/public/test/render_view_test.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_TEST_RENDER_VIEW_TEST_H_ -#define CONTENT_TEST_RENDER_VIEW_TEST_H_ +#ifndef CONTENT_PUBLIC_TEST_RENDER_VIEW_TEST_H_ +#define CONTENT_PUBLIC_TEST_RENDER_VIEW_TEST_H_ #pragma once #include <string> @@ -14,10 +14,8 @@ #include "base/string16.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/common/main_function_params.h" +#include "content/public/renderer/content_renderer_client.h" #include "content/public/test/mock_render_thread.h" -#include "content/renderer/mock_content_renderer_client.h" -#include "content/renderer/renderer_webkitplatformsupport_impl.h" -#include "content/test/mock_keyboard.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" @@ -26,29 +24,31 @@ class RendererMainPlatformDelegate; namespace WebKit { class WebHistoryItem; +class WebKitPlatformSupport; class WebWidget; } -namespace content { -class RenderView; -} - namespace gfx { class Rect; } namespace content { +class RendererWebKitPlatformSupportImplNoSandboxImpl; + class RenderViewTest : public testing::Test { public: // A special WebKitPlatformSupportImpl class for getting rid off the // dependency to the sandbox, which is not available in RenderViewTest. - class RendererWebKitPlatformSupportImplNoSandbox : - public RendererWebKitPlatformSupportImpl { + class RendererWebKitPlatformSupportImplNoSandbox { public: - virtual WebKit::WebSandboxSupport* sandboxSupport() { - return NULL; - } + RendererWebKitPlatformSupportImplNoSandbox(); + ~RendererWebKitPlatformSupportImplNoSandbox(); + WebKit::WebKitPlatformSupport* Get(); + + private: + scoped_ptr<RendererWebKitPlatformSupportImplNoSandboxImpl> + webkit_platform_support_; }; RenderViewTest(); @@ -81,12 +81,6 @@ class RenderViewTest : public testing::Test { void GoBack(const WebKit::WebHistoryItem& item); void GoForward(const WebKit::WebHistoryItem& item); - // Sends IPC messages that emulates a key-press event. - int SendKeyEvent(MockKeyboard::Layout layout, - int key_code, - MockKeyboard::Modifiers key_modifiers, - string16* output); - // Sends one native key event over IPC. void SendNativeKeyEvent(const content::NativeWebKeyboardEvent& key_event); @@ -134,8 +128,7 @@ class RenderViewTest : public testing::Test { // the embedder's namespace. content::RenderView* view_; RendererWebKitPlatformSupportImplNoSandbox webkit_platform_support_; - MockContentRendererClient mock_content_renderer_client_; - scoped_ptr<MockKeyboard> mock_keyboard_; + ContentRendererClient content_renderer_client_; scoped_ptr<MockRenderThread> render_thread_; // Used to setup the process so renderers can run. @@ -149,4 +142,4 @@ class RenderViewTest : public testing::Test { } // namespace content -#endif // CONTENT_TEST_RENDER_VIEW_TEST_H_ +#endif // CONTENT_PUBLIC_TEST_RENDER_VIEW_TEST_H_ diff --git a/content/renderer/external_popup_menu_browsertest.cc b/content/renderer/external_popup_menu_browsertest.cc index 1f40dbf..296d39d 100644 --- a/content/renderer/external_popup_menu_browsertest.cc +++ b/content/renderer/external_popup_menu_browsertest.cc @@ -4,8 +4,8 @@ #include "base/utf_string_conversions.h" #include "content/common/view_messages.h" +#include "content/public/test/render_view_test.h" #include "content/renderer/render_view_impl.h" -#include "content/test/render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" diff --git a/content/renderer/mouse_lock_dispatcher_browsertest.cc b/content/renderer/mouse_lock_dispatcher_browsertest.cc index 0b3a3c2..7c872ce 100644 --- a/content/renderer/mouse_lock_dispatcher_browsertest.cc +++ b/content/renderer/mouse_lock_dispatcher_browsertest.cc @@ -5,9 +5,9 @@ #include <string> #include "content/common/view_messages.h" +#include "content/public/test/render_view_test.h" #include "content/renderer/mouse_lock_dispatcher.h" #include "content/renderer/render_view_impl.h" -#include "content/test/render_view_test.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc index faa6d3b..45dcff0 100644 --- a/content/renderer/render_view_browsertest.cc +++ b/content/renderer/render_view_browsertest.cc @@ -11,8 +11,9 @@ #include "content/common/view_messages.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/common/bindings_policy.h" +#include "content/public/test/render_view_test.h" #include "content/renderer/render_view_impl.h" -#include "content/test/render_view_test.h" +#include "content/test/mock_keyboard.h" #include "net/base/net_errors.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" @@ -25,18 +26,195 @@ #include "ui/gfx/codec/jpeg_codec.h" #include "webkit/glue/web_io_operators.h" +#if defined(OS_LINUX) && !defined(USE_AURA) +#include "ui/base/gtk/event_synthesis_gtk.h" +#endif + +#if defined(USE_AURA) +#include "ui/aura/event.h" +#endif + +#if defined(USE_AURA) && defined(USE_X11) +#include <X11/Xlib.h> +#include "ui/base/events.h" +#include "ui/base/keycodes/keyboard_code_conversion.h" +#include "ui/base/x/x11_util.h" +#endif + using WebKit::WebFrame; using WebKit::WebInputEvent; using WebKit::WebMouseEvent; using WebKit::WebString; using WebKit::WebTextDirection; using WebKit::WebURLError; +using content::NativeWebKeyboardEvent; + +namespace { +#if defined(USE_AURA) && defined(USE_X11) +// Converts MockKeyboard::Modifiers to ui::EventFlags. +int ConvertMockKeyboardModifier(MockKeyboard::Modifiers modifiers) { + static struct ModifierMap { + MockKeyboard::Modifiers src; + int dst; + } kModifierMap[] = { + { MockKeyboard::LEFT_SHIFT, ui::EF_SHIFT_DOWN }, + { MockKeyboard::RIGHT_SHIFT, ui::EF_SHIFT_DOWN }, + { MockKeyboard::LEFT_CONTROL, ui::EF_CONTROL_DOWN }, + { MockKeyboard::RIGHT_CONTROL, ui::EF_CONTROL_DOWN }, + { MockKeyboard::LEFT_ALT, ui::EF_ALT_DOWN }, + { MockKeyboard::RIGHT_ALT, ui::EF_ALT_DOWN }, + }; + int flags = 0; + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kModifierMap); ++i) { + if (kModifierMap[i].src & modifiers) { + flags |= kModifierMap[i].dst; + } + } + return flags; +} +#endif +} class RenderViewImplTest : public content::RenderViewTest { public: + RenderViewImplTest() { + // Attach a pseudo keyboard device to this object. + mock_keyboard_.reset(new MockKeyboard()); + } + RenderViewImpl* view() { return static_cast<RenderViewImpl*>(view_); } + + // Sends IPC messages that emulates a key-press event. + int SendKeyEvent(MockKeyboard::Layout layout, + int key_code, + MockKeyboard::Modifiers modifiers, + string16* output) { +#if defined(OS_WIN) + // Retrieve the Unicode character for the given tuple (keyboard-layout, + // key-code, and modifiers). + // Exit when a keyboard-layout driver cannot assign a Unicode character to + // the tuple to prevent sending an invalid key code to the RenderView object. + CHECK(mock_keyboard_.get()); + CHECK(output); + int length = mock_keyboard_->GetCharacters(layout, key_code, modifiers, + output); + if (length != 1) + return -1; + + // Create IPC messages from Windows messages and send them to our + // back-end. + // A keyboard event of Windows consists of three Windows messages: + // WM_KEYDOWN, WM_CHAR, and WM_KEYUP. + // WM_KEYDOWN and WM_KEYUP sends virtual-key codes. On the other hand, + // WM_CHAR sends a composed Unicode character. + MSG msg1 = { NULL, WM_KEYDOWN, key_code, 0 }; +#if defined(USE_AURA) + aura::KeyEvent evt1(msg1, false); + NativeWebKeyboardEvent keydown_event(&evt1); +#else + NativeWebKeyboardEvent keydown_event(msg1); +#endif + SendNativeKeyEvent(keydown_event); + + MSG msg2 = { NULL, WM_CHAR, (*output)[0], 0 }; +#if defined(USE_AURA) + aura::KeyEvent evt2(msg2, true); + NativeWebKeyboardEvent char_event(&evt2); +#else + NativeWebKeyboardEvent char_event(msg2); +#endif + SendNativeKeyEvent(char_event); + + MSG msg3 = { NULL, WM_KEYUP, key_code, 0 }; +#if defined(USE_AURA) + aura::KeyEvent evt3(msg3, false); + NativeWebKeyboardEvent keyup_event(&evt3); +#else + NativeWebKeyboardEvent keyup_event(msg3); +#endif + SendNativeKeyEvent(keyup_event); + + return length; +#elif defined(USE_AURA) && defined(USE_X11) + // We ignore |layout|, which means we are only testing the layout of the + // current locale. TODO(mazda): fix this to respect |layout|. + CHECK(output); + const int flags = ConvertMockKeyboardModifier(modifiers); + + XEvent xevent1; + InitXKeyEventForTesting(ui::ET_KEY_PRESSED, + static_cast<ui::KeyboardCode>(key_code), + flags, + &xevent1); + aura::KeyEvent event1(&xevent1, false); + NativeWebKeyboardEvent keydown_event(&event1); + SendNativeKeyEvent(keydown_event); + + XEvent xevent2; + InitXKeyEventForTesting(ui::ET_KEY_PRESSED, + static_cast<ui::KeyboardCode>(key_code), + flags, + &xevent2); + aura::KeyEvent event2(&xevent2, true); + NativeWebKeyboardEvent char_event(&event2); + SendNativeKeyEvent(char_event); + + XEvent xevent3; + InitXKeyEventForTesting(ui::ET_KEY_RELEASED, + static_cast<ui::KeyboardCode>(key_code), + flags, + &xevent3); + aura::KeyEvent event3(&xevent3, false); + NativeWebKeyboardEvent keyup_event(&event3); + SendNativeKeyEvent(keyup_event); + + long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code), + flags); + output->assign(1, static_cast<char16>(c)); + return 1; +#elif defined(OS_LINUX) + // We ignore |layout|, which means we are only testing the layout of the + // current locale. TODO(estade): fix this to respect |layout|. + std::vector<GdkEvent*> events; + ui::SynthesizeKeyPressEvents( + NULL, static_cast<ui::KeyboardCode>(key_code), + modifiers & (MockKeyboard::LEFT_CONTROL | MockKeyboard::RIGHT_CONTROL), + modifiers & (MockKeyboard::LEFT_SHIFT | MockKeyboard::RIGHT_SHIFT), + modifiers & (MockKeyboard::LEFT_ALT | MockKeyboard::RIGHT_ALT), + &events); + + guint32 unicode_key = 0; + for (size_t i = 0; i < events.size(); ++i) { + // Only send the up/down events for key press itself (skip the up/down + // events for the modifier keys). + if ((i + 1) == (events.size() / 2) || i == (events.size() / 2)) { + unicode_key = gdk_keyval_to_unicode(events[i]->key.keyval); + NativeWebKeyboardEvent webkit_event(events[i]); + SendNativeKeyEvent(webkit_event); + + // Need to add a char event after the key down. + if (webkit_event.type == WebKit::WebInputEvent::RawKeyDown) { + NativeWebKeyboardEvent char_event = webkit_event; + char_event.type = WebKit::WebInputEvent::Char; + char_event.skip_in_browser = true; + SendNativeKeyEvent(char_event); + } + } + gdk_event_free(events[i]); + } + + output->assign(1, static_cast<char16>(unicode_key)); + return 1; +#else + NOTIMPLEMENTED(); + return L'\0'; +#endif + } + + private: + scoped_ptr<MockKeyboard> mock_keyboard_; }; // Test that we get form state change notifications when input fields change. diff --git a/content/renderer/render_view_browsertest_mac.mm b/content/renderer/render_view_browsertest_mac.mm index 3860449..d46fd8b 100644 --- a/content/renderer/render_view_browsertest_mac.mm +++ b/content/renderer/render_view_browsertest_mac.mm @@ -5,8 +5,8 @@ #include "base/string_util.h" #include "base/string16.h" #include "content/public/browser/native_web_keyboard_event.h" +#include "content/public/test/render_view_test.h" #include "content/renderer/render_view_impl.h" -#include "content/test/render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include <Cocoa/Cocoa.h> diff --git a/content/test/render_view_test.cc b/content/test/render_view_test.cc index 76e2c0e..bc216acd 100644 --- a/content/test/render_view_test.cc +++ b/content/test/render_view_test.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/test/render_view_test.h" +#include "content/public/test/render_view_test.h" #include "content/common/view_messages.h" #include "content/public/browser/native_web_keyboard_event.h" @@ -10,6 +10,7 @@ #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" #include "content/renderer/renderer_main_platform_delegate.h" +#include "content/renderer/renderer_webkitplatformsupport_impl.h" #include "content/test/mock_render_process.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" @@ -23,21 +24,6 @@ #include "webkit/glue/glue_serialize.h" #include "webkit/glue/webkit_glue.h" -#if defined(OS_LINUX) && !defined(USE_AURA) -#include "ui/base/gtk/event_synthesis_gtk.h" -#endif - -#if defined(USE_AURA) -#include "ui/aura/event.h" -#endif - -#if defined(USE_AURA) && defined(USE_X11) -#include <X11/Xlib.h> -#include "ui/base/events.h" -#include "ui/base/keycodes/keyboard_code_conversion.h" -#include "ui/base/x/x11_util.h" -#endif - using WebKit::WebFrame; using WebKit::WebInputEvent; using WebKit::WebMouseEvent; @@ -53,33 +39,33 @@ const int32 kRouteId = 5; const int32 kNewWindowRouteId = 6; const int32 kSurfaceId = 42; -#if defined(USE_AURA) && defined(USE_X11) -// Converts MockKeyboard::Modifiers to ui::EventFlags. -int ConvertMockKeyboardModifier(MockKeyboard::Modifiers modifiers) { - static struct ModifierMap { - MockKeyboard::Modifiers src; - int dst; - } kModifierMap[] = { - { MockKeyboard::LEFT_SHIFT, ui::EF_SHIFT_DOWN }, - { MockKeyboard::RIGHT_SHIFT, ui::EF_SHIFT_DOWN }, - { MockKeyboard::LEFT_CONTROL, ui::EF_CONTROL_DOWN }, - { MockKeyboard::RIGHT_CONTROL, ui::EF_CONTROL_DOWN }, - { MockKeyboard::LEFT_ALT, ui::EF_ALT_DOWN }, - { MockKeyboard::RIGHT_ALT, ui::EF_ALT_DOWN }, - }; - int flags = 0; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kModifierMap); ++i) { - if (kModifierMap[i].src & modifiers) { - flags |= kModifierMap[i].dst; - } - } - return flags; -} -#endif } // namespace namespace content { +class RendererWebKitPlatformSupportImplNoSandboxImpl : + public RendererWebKitPlatformSupportImpl { + public: + virtual WebKit::WebSandboxSupport* sandboxSupport() { + return NULL; + } +}; + +RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox:: + RendererWebKitPlatformSupportImplNoSandbox() { + webkit_platform_support_.reset( + new RendererWebKitPlatformSupportImplNoSandboxImpl()); +} + +RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox:: + ~RendererWebKitPlatformSupportImplNoSandbox() { +} + +WebKit::WebKitPlatformSupport* + RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox::Get() { + return webkit_platform_support_.get(); +} + RenderViewTest::RenderViewTest() : view_(NULL) { } @@ -138,7 +124,7 @@ void RenderViewTest::SetUp() { // Subclasses can set the ContentClient's renderer before calling // RenderViewTest::SetUp(). if (!GetContentClient()->renderer()) - GetContentClient()->set_renderer(&mock_content_renderer_client_); + GetContentClient()->set_renderer(&content_renderer_client_); // Subclasses can set render_thread_ with their own implementation before // calling RenderViewTest::SetUp(). @@ -156,7 +142,7 @@ void RenderViewTest::SetUp() { // Setting flags and really doing anything with WebKit is fairly fragile and // hacky, but this is the world we live in... webkit_glue::SetJavaScriptFlags(" --expose-gc"); - WebKit::initialize(&webkit_platform_support_); + WebKit::initialize(webkit_platform_support_.Get()); // Ensure that we register any necessary schemes when initializing WebKit, // since we are using a MockRenderThread. @@ -182,9 +168,6 @@ void RenderViewTest::SetUp() { AccessibilityModeOff); view->AddRef(); view_ = view; - - // Attach a pseudo keyboard device to this object. - mock_keyboard_.reset(new MockKeyboard()); } void RenderViewTest::TearDown() { @@ -206,140 +189,12 @@ void RenderViewTest::TearDown() { WebKit::shutdown(); - mock_keyboard_.reset(); - platform_->PlatformUninitialize(); platform_.reset(); params_.reset(); command_line_.reset(); } -int RenderViewTest::SendKeyEvent(MockKeyboard::Layout layout, - int key_code, - MockKeyboard::Modifiers modifiers, - string16* output) { -#if defined(OS_WIN) - // Retrieve the Unicode character for the given tuple (keyboard-layout, - // key-code, and modifiers). - // Exit when a keyboard-layout driver cannot assign a Unicode character to - // the tuple to prevent sending an invalid key code to the RenderView object. - CHECK(mock_keyboard_.get()); - CHECK(output); - int length = mock_keyboard_->GetCharacters(layout, key_code, modifiers, - output); - if (length != 1) - return -1; - - // Create IPC messages from Windows messages and send them to our - // back-end. - // A keyboard event of Windows consists of three Windows messages: - // WM_KEYDOWN, WM_CHAR, and WM_KEYUP. - // WM_KEYDOWN and WM_KEYUP sends virtual-key codes. On the other hand, - // WM_CHAR sends a composed Unicode character. - MSG msg1 = { NULL, WM_KEYDOWN, key_code, 0 }; -#if defined(USE_AURA) - aura::KeyEvent evt1(msg1, false); - NativeWebKeyboardEvent keydown_event(&evt1); -#else - NativeWebKeyboardEvent keydown_event(msg1); -#endif - SendNativeKeyEvent(keydown_event); - - MSG msg2 = { NULL, WM_CHAR, (*output)[0], 0 }; -#if defined(USE_AURA) - aura::KeyEvent evt2(msg2, true); - NativeWebKeyboardEvent char_event(&evt2); -#else - NativeWebKeyboardEvent char_event(msg2); -#endif - SendNativeKeyEvent(char_event); - - MSG msg3 = { NULL, WM_KEYUP, key_code, 0 }; -#if defined(USE_AURA) - aura::KeyEvent evt3(msg3, false); - NativeWebKeyboardEvent keyup_event(&evt3); -#else - NativeWebKeyboardEvent keyup_event(msg3); -#endif - SendNativeKeyEvent(keyup_event); - - return length; -#elif defined(USE_AURA) && defined(USE_X11) - // We ignore |layout|, which means we are only testing the layout of the - // current locale. TODO(mazda): fix this to respect |layout|. - CHECK(output); - const int flags = ConvertMockKeyboardModifier(modifiers); - - XEvent xevent1; - InitXKeyEventForTesting(ui::ET_KEY_PRESSED, - static_cast<ui::KeyboardCode>(key_code), - flags, - &xevent1); - aura::KeyEvent event1(&xevent1, false); - NativeWebKeyboardEvent keydown_event(&event1); - SendNativeKeyEvent(keydown_event); - - XEvent xevent2; - InitXKeyEventForTesting(ui::ET_KEY_PRESSED, - static_cast<ui::KeyboardCode>(key_code), - flags, - &xevent2); - aura::KeyEvent event2(&xevent2, true); - NativeWebKeyboardEvent char_event(&event2); - SendNativeKeyEvent(char_event); - - XEvent xevent3; - InitXKeyEventForTesting(ui::ET_KEY_RELEASED, - static_cast<ui::KeyboardCode>(key_code), - flags, - &xevent3); - aura::KeyEvent event3(&xevent3, false); - NativeWebKeyboardEvent keyup_event(&event3); - SendNativeKeyEvent(keyup_event); - - long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code), - flags); - output->assign(1, static_cast<char16>(c)); - return 1; -#elif defined(OS_LINUX) - // We ignore |layout|, which means we are only testing the layout of the - // current locale. TODO(estade): fix this to respect |layout|. - std::vector<GdkEvent*> events; - ui::SynthesizeKeyPressEvents( - NULL, static_cast<ui::KeyboardCode>(key_code), - modifiers & (MockKeyboard::LEFT_CONTROL | MockKeyboard::RIGHT_CONTROL), - modifiers & (MockKeyboard::LEFT_SHIFT | MockKeyboard::RIGHT_SHIFT), - modifiers & (MockKeyboard::LEFT_ALT | MockKeyboard::RIGHT_ALT), - &events); - - guint32 unicode_key = 0; - for (size_t i = 0; i < events.size(); ++i) { - // Only send the up/down events for key press itself (skip the up/down - // events for the modifier keys). - if ((i + 1) == (events.size() / 2) || i == (events.size() / 2)) { - unicode_key = gdk_keyval_to_unicode(events[i]->key.keyval); - NativeWebKeyboardEvent webkit_event(events[i]); - SendNativeKeyEvent(webkit_event); - - // Need to add a char event after the key down. - if (webkit_event.type == WebKit::WebInputEvent::RawKeyDown) { - NativeWebKeyboardEvent char_event = webkit_event; - char_event.type = WebKit::WebInputEvent::Char; - char_event.skip_in_browser = true; - SendNativeKeyEvent(char_event); - } - } - gdk_event_free(events[i]); - } - - output->assign(1, static_cast<char16>(unicode_key)); - return 1; -#else - NOTIMPLEMENTED(); - return L'\0'; -#endif -} - void RenderViewTest::SendNativeKeyEvent( const NativeWebKeyboardEvent& key_event) { SendWebKeyboardEvent(key_event); diff --git a/content/test/render_widget_browsertest.h b/content/test/render_widget_browsertest.h index cb06a28..e9c60cc 100644 --- a/content/test/render_widget_browsertest.h +++ b/content/test/render_widget_browsertest.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "base/file_path.h" -#include "content/test/render_view_test.h" +#include "content/public/test/render_view_test.h" class SkBitmap; |