| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/render_view_test.h" | 5 #include "content/test/render_view_test.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_function_dispatcher.h" | |
| 8 #include "chrome/common/extensions/extension.h" | |
| 9 #include "chrome/common/print_messages.h" | |
| 10 #include "chrome/common/render_messages.h" | |
| 11 #include "chrome/renderer/autofill/password_autofill_manager.h" | |
| 12 #include "chrome/renderer/extensions/chrome_v8_context_set.h" | |
| 13 #include "chrome/renderer/extensions/chrome_v8_extension.h" | |
| 14 #include "chrome/renderer/extensions/event_bindings.h" | |
| 15 #include "chrome/renderer/extensions/extension_dispatcher.h" | |
| 16 #include "chrome/renderer/extensions/extension_process_bindings.h" | |
| 17 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | |
| 18 #include "content/common/dom_storage_common.h" | 7 #include "content/common/dom_storage_common.h" |
| 19 #include "content/common/native_web_keyboard_event.h" | 8 #include "content/common/native_web_keyboard_event.h" |
| 20 #include "content/common/renderer_preferences.h" | 9 #include "content/common/renderer_preferences.h" |
| 21 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| 22 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.h" |
| 23 #include "content/renderer/renderer_main_platform_delegate.h" | 12 #include "content/renderer/renderer_main_platform_delegate.h" |
| 24 #include "content/test/mock_render_process.h" | 13 #include "content/test/mock_render_process.h" |
| 25 #include "grit/renderer_resources.h" | |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h
" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h
" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 33 #include "webkit/glue/webkit_glue.h" | 21 #include "webkit/glue/webkit_glue.h" |
| 34 | 22 |
| 35 #if defined(OS_LINUX) && !defined(USE_AURA) | 23 #if defined(OS_LINUX) && !defined(USE_AURA) |
| 36 #include "ui/base/gtk/event_synthesis_gtk.h" | 24 #include "ui/base/gtk/event_synthesis_gtk.h" |
| 37 #endif | 25 #endif |
| 38 | 26 |
| 39 using WebKit::WebFrame; | 27 using WebKit::WebFrame; |
| 40 using WebKit::WebInputEvent; | 28 using WebKit::WebInputEvent; |
| 41 using WebKit::WebMouseEvent; | 29 using WebKit::WebMouseEvent; |
| 42 using WebKit::WebScriptController; | 30 using WebKit::WebScriptController; |
| 43 using WebKit::WebScriptSource; | 31 using WebKit::WebScriptSource; |
| 44 using WebKit::WebString; | 32 using WebKit::WebString; |
| 45 using WebKit::WebURLRequest; | 33 using WebKit::WebURLRequest; |
| 46 using autofill::AutofillAgent; | |
| 47 using autofill::PasswordAutofillManager; | |
| 48 | 34 |
| 49 namespace { | 35 namespace { |
| 36 const int32 kOpenerId = 7; |
| 50 const int32 kRouteId = 5; | 37 const int32 kRouteId = 5; |
| 51 const int32 kOpenerId = 7; | |
| 52 } // namespace | 38 } // namespace |
| 53 | 39 |
| 54 RenderViewTest::RenderViewTest() : extension_dispatcher_(NULL), view_(NULL) { | 40 namespace content { |
| 41 |
| 42 RenderViewTest::RenderViewTest() : view_(NULL) { |
| 55 } | 43 } |
| 56 | 44 |
| 57 RenderViewTest::~RenderViewTest() { | 45 RenderViewTest::~RenderViewTest() { |
| 58 } | 46 } |
| 59 | 47 |
| 60 void RenderViewTest::ProcessPendingMessages() { | 48 void RenderViewTest::ProcessPendingMessages() { |
| 61 msg_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 49 msg_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 62 msg_loop_.Run(); | 50 msg_loop_.Run(); |
| 63 } | 51 } |
| 64 | 52 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 90 GURL url(url_str); | 78 GURL url(url_str); |
| 91 | 79 |
| 92 GetMainFrame()->loadRequest(WebURLRequest(url)); | 80 GetMainFrame()->loadRequest(WebURLRequest(url)); |
| 93 | 81 |
| 94 // The load actually happens asynchronously, so we pump messages to process | 82 // The load actually happens asynchronously, so we pump messages to process |
| 95 // the pending continuation. | 83 // the pending continuation. |
| 96 ProcessPendingMessages(); | 84 ProcessPendingMessages(); |
| 97 } | 85 } |
| 98 | 86 |
| 99 void RenderViewTest::SetUp() { | 87 void RenderViewTest::SetUp() { |
| 100 content::GetContentClient()->set_renderer(&chrome_content_renderer_client_); | 88 // Subclasses can set the ContentClient's renderer before calling |
| 101 extension_dispatcher_ = new ExtensionDispatcher(); | 89 // RenderViewTest::SetUp(). |
| 102 chrome_content_renderer_client_.SetExtensionDispatcher(extension_dispatcher_); | 90 if (!GetContentClient()->renderer()) |
| 91 GetContentClient()->set_renderer(&mock_content_renderer_client_); |
| 92 |
| 93 // Subclasses can set render_thread_ with their own implementation before |
| 94 // calling RenderViewTest::SetUp(). |
| 95 if (!render_thread_.get()) |
| 96 render_thread_.reset(new MockRenderThread()); |
| 97 render_thread_->set_routing_id(kRouteId); |
| 98 |
| 103 sandbox_init_wrapper_.reset(new SandboxInitWrapper()); | 99 sandbox_init_wrapper_.reset(new SandboxInitWrapper()); |
| 104 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 100 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
| 105 params_.reset(new MainFunctionParams(*command_line_, *sandbox_init_wrapper_, | 101 params_.reset(new MainFunctionParams(*command_line_, *sandbox_init_wrapper_, |
| 106 NULL)); | 102 NULL)); |
| 107 platform_.reset(new RendererMainPlatformDelegate(*params_)); | 103 platform_.reset(new RendererMainPlatformDelegate(*params_)); |
| 108 platform_->PlatformInitialize(); | 104 platform_->PlatformInitialize(); |
| 109 | 105 |
| 110 // Setting flags and really doing anything with WebKit is fairly fragile and | 106 // Setting flags and really doing anything with WebKit is fairly fragile and |
| 111 // hacky, but this is the world we live in... | 107 // hacky, but this is the world we live in... |
| 112 webkit_glue::SetJavaScriptFlags(" --expose-gc"); | 108 webkit_glue::SetJavaScriptFlags(" --expose-gc"); |
| 113 WebKit::initialize(&webkit_platform_support_); | 109 WebKit::initialize(&webkit_platform_support_); |
| 114 | 110 |
| 115 WebScriptController::registerExtension(new ChromeV8Extension( | |
| 116 "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL)); | |
| 117 WebScriptController::registerExtension(EventBindings::Get( | |
| 118 extension_dispatcher_)); | |
| 119 WebScriptController::registerExtension(RendererExtensionBindings::Get( | |
| 120 extension_dispatcher_)); | |
| 121 WebScriptController::registerExtension(ExtensionProcessBindings::Get( | |
| 122 extension_dispatcher_)); | |
| 123 WebScriptController::registerExtension(new ChromeV8Extension( | |
| 124 "extensions/apitest.js", IDR_EXTENSION_APITEST_JS, NULL)); | |
| 125 | |
| 126 mock_process_.reset(new MockRenderProcess); | 111 mock_process_.reset(new MockRenderProcess); |
| 127 | 112 |
| 128 render_thread_.set_routing_id(kRouteId); | |
| 129 | |
| 130 // This needs to pass the mock render thread to the view. | 113 // This needs to pass the mock render thread to the view. |
| 131 RenderViewImpl* view = RenderViewImpl::Create( | 114 RenderViewImpl* view = RenderViewImpl::Create( |
| 132 0, | 115 0, |
| 133 kOpenerId, | 116 kOpenerId, |
| 134 RendererPreferences(), | 117 RendererPreferences(), |
| 135 WebPreferences(), | 118 WebPreferences(), |
| 136 new SharedRenderViewCounter(0), | 119 new SharedRenderViewCounter(0), |
| 137 kRouteId, | 120 kRouteId, |
| 138 kInvalidSessionStorageNamespaceId, | 121 kInvalidSessionStorageNamespaceId, |
| 139 string16()); | 122 string16()); |
| 140 view->AddRef(); | 123 view->AddRef(); |
| 141 view_ = view; | 124 view_ = view; |
| 142 | 125 |
| 143 // Attach a pseudo keyboard device to this object. | 126 // Attach a pseudo keyboard device to this object. |
| 144 mock_keyboard_.reset(new MockKeyboard()); | 127 mock_keyboard_.reset(new MockKeyboard()); |
| 145 | |
| 146 // RenderView doesn't expose it's PasswordAutofillManager or | |
| 147 // AutofillAgent objects, because it has no need to store them directly | |
| 148 // (they're stored as RenderViewObserver*). So just create another set. | |
| 149 password_autofill_ = new PasswordAutofillManager(view_); | |
| 150 autofill_agent_ = new AutofillAgent(view_, password_autofill_); | |
| 151 } | 128 } |
| 152 | 129 |
| 153 void RenderViewTest::TearDown() { | 130 void RenderViewTest::TearDown() { |
| 154 // Try very hard to collect garbage before shutting down. | 131 // Try very hard to collect garbage before shutting down. |
| 155 GetMainFrame()->collectGarbage(); | 132 GetMainFrame()->collectGarbage(); |
| 156 GetMainFrame()->collectGarbage(); | 133 GetMainFrame()->collectGarbage(); |
| 157 | 134 |
| 158 render_thread_.SendCloseMessage(); | |
| 159 | |
| 160 // Run the loop so the release task from the renderwidget executes. | 135 // Run the loop so the release task from the renderwidget executes. |
| 161 ProcessPendingMessages(); | 136 ProcessPendingMessages(); |
| 162 | 137 |
| 163 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 138 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 164 impl->Release(); | 139 impl->Release(); |
| 165 view_ = NULL; | 140 view_ = NULL; |
| 166 | 141 |
| 167 mock_process_.reset(); | 142 mock_process_.reset(); |
| 168 | 143 |
| 169 // After resetting the view_ and mock_process_ we may get some new tasks | 144 // After resetting the view_ and mock_process_ we may get some new tasks |
| 170 // which need to be processed before shutting down WebKit | 145 // which need to be processed before shutting down WebKit |
| 171 // (http://crbug.com/21508). | 146 // (http://crbug.com/21508). |
| 172 msg_loop_.RunAllPending(); | 147 msg_loop_.RunAllPending(); |
| 173 | 148 |
| 174 WebKit::shutdown(); | 149 WebKit::shutdown(); |
| 175 | 150 |
| 176 mock_keyboard_.reset(); | 151 mock_keyboard_.reset(); |
| 177 | 152 |
| 178 platform_->PlatformUninitialize(); | 153 platform_->PlatformUninitialize(); |
| 179 platform_.reset(); | 154 platform_.reset(); |
| 180 params_.reset(); | 155 params_.reset(); |
| 181 command_line_.reset(); | 156 command_line_.reset(); |
| 182 sandbox_init_wrapper_.reset(); | 157 sandbox_init_wrapper_.reset(); |
| 183 | |
| 184 extension_dispatcher_->OnRenderProcessShutdown(); | |
| 185 extension_dispatcher_ = NULL; | |
| 186 } | 158 } |
| 187 | 159 |
| 188 int RenderViewTest::SendKeyEvent(MockKeyboard::Layout layout, | 160 int RenderViewTest::SendKeyEvent(MockKeyboard::Layout layout, |
| 189 int key_code, | 161 int key_code, |
| 190 MockKeyboard::Modifiers modifiers, | 162 MockKeyboard::Modifiers modifiers, |
| 191 std::wstring* output) { | 163 std::wstring* output) { |
| 192 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
| 193 // Retrieve the Unicode character for the given tuple (keyboard-layout, | 165 // Retrieve the Unicode character for the given tuple (keyboard-layout, |
| 194 // key-code, and modifiers). | 166 // key-code, and modifiers). |
| 195 // Exit when a keyboard-layout driver cannot assign a Unicode character to | 167 // Exit when a keyboard-layout driver cannot assign a Unicode character to |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 327 |
| 356 void RenderViewTest::SendContentStateImmediately() { | 328 void RenderViewTest::SendContentStateImmediately() { |
| 357 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 329 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 358 impl->set_send_content_state_immediately(true); | 330 impl->set_send_content_state_immediately(true); |
| 359 } | 331 } |
| 360 | 332 |
| 361 WebKit::WebWidget* RenderViewTest::GetWebWidget() { | 333 WebKit::WebWidget* RenderViewTest::GetWebWidget() { |
| 362 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 334 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 363 return impl->webwidget(); | 335 return impl->webwidget(); |
| 364 } | 336 } |
| 337 |
| 338 } // namespace content |
| OLD | NEW |