chrome_render_view_test.cc revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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 3// found in the LICENSE file. 4 5#include "chrome/test/base/chrome_render_view_test.h" 6 7#include "base/debug/leak_annotations.h" 8#include "chrome/browser/chrome_content_browser_client.h" 9#include "chrome/common/chrome_content_client.h" 10#include "chrome/common/render_messages.h" 11#include "chrome/renderer/chrome_content_renderer_client.h" 12#include "chrome/renderer/extensions/dispatcher.h" 13#include "chrome/renderer/spellchecker/spellcheck.h" 14#include "chrome/test/base/chrome_unit_test_suite.h" 15#include "components/autofill/content/renderer/autofill_agent.h" 16#include "components/autofill/content/renderer/password_autofill_agent.h" 17#include "components/autofill/content/renderer/test_password_autofill_agent.h" 18#include "components/autofill/content/renderer/test_password_generation_agent.h" 19#include "content/public/browser/native_web_keyboard_event.h" 20#include "content/public/common/renderer_preferences.h" 21#include "content/public/renderer/render_view.h" 22#include "extensions/browser/extension_function_dispatcher.h" 23#include "extensions/common/extension.h" 24#include "extensions/renderer/event_bindings.h" 25#include "third_party/WebKit/public/platform/WebURLRequest.h" 26#include "third_party/WebKit/public/web/WebFrame.h" 27#include "third_party/WebKit/public/web/WebInputEvent.h" 28#include "third_party/WebKit/public/web/WebKit.h" 29#include "third_party/WebKit/public/web/WebScriptController.h" 30#include "third_party/WebKit/public/web/WebScriptSource.h" 31#include "third_party/WebKit/public/web/WebView.h" 32 33using blink::WebFrame; 34using blink::WebInputEvent; 35using blink::WebMouseEvent; 36using blink::WebScriptController; 37using blink::WebScriptSource; 38using blink::WebString; 39using blink::WebURLRequest; 40using autofill::AutofillAgent; 41using autofill::PasswordAutofillAgent; 42using autofill::PasswordGenerationAgent; 43 44ChromeRenderViewTest::ChromeRenderViewTest() 45 : password_autofill_(NULL), 46 password_generation_(NULL), 47 autofill_agent_(NULL), 48 chrome_render_thread_(NULL) { 49} 50 51ChromeRenderViewTest::~ChromeRenderViewTest() { 52} 53 54void ChromeRenderViewTest::SetUp() { 55 ChromeUnitTestSuite::InitializeProviders(); 56 ChromeUnitTestSuite::InitializeResourceBundle(); 57 58 chrome_render_thread_ = new ChromeMockRenderThread(); 59 render_thread_.reset(chrome_render_thread_); 60 61 content::RenderViewTest::SetUp(); 62 63 // RenderView doesn't expose its Agent objects, because it has no need to 64 // store them directly (they're stored as RenderViewObserver*). So just 65 // create another set. 66 password_autofill_ = new autofill::TestPasswordAutofillAgent(view_); 67 password_generation_ = new autofill::TestPasswordGenerationAgent(view_); 68 autofill_agent_ = 69 new AutofillAgent(view_, password_autofill_, password_generation_); 70} 71 72void ChromeRenderViewTest::TearDown() { 73 ChromeContentRendererClient* client = 74 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); 75 client->GetExtensionDispatcherForTest()->OnRenderProcessShutdown(); 76 77#if defined(LEAK_SANITIZER) 78 // Do this before shutting down V8 in RenderViewTest::TearDown(). 79 // http://crbug.com/328552 80 __lsan_do_leak_check(); 81#endif 82 content::RenderViewTest::TearDown(); 83} 84 85content::ContentClient* ChromeRenderViewTest::CreateContentClient() { 86 return new ChromeContentClient(); 87} 88 89content::ContentBrowserClient* 90 ChromeRenderViewTest::CreateContentBrowserClient() { 91 return new chrome::ChromeContentBrowserClient(); 92} 93 94content::ContentRendererClient* 95 ChromeRenderViewTest::CreateContentRendererClient() { 96 ChromeContentRendererClient* client = new ChromeContentRendererClient(); 97 client->SetExtensionDispatcherForTest(new extensions::Dispatcher); 98#if defined(ENABLE_SPELLCHECK) 99 client->SetSpellcheck(new SpellCheck()); 100#endif 101 return client; 102} 103