OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chrome_render_view_test.h" | 5 #include "chrome/test/base/chrome_render_view_test.h" |
6 | 6 |
7 #include "base/debug/leak_annotations.h" | 7 #include "base/debug/leak_annotations.h" |
8 #include "chrome/browser/chrome_content_browser_client.h" | 8 #include "chrome/browser/chrome_content_browser_client.h" |
9 #include "chrome/common/chrome_content_client.h" | 9 #include "chrome/common/chrome_content_client.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
11 #include "chrome/renderer/chrome_content_renderer_client.h" | 11 #include "chrome/renderer/chrome_content_renderer_client.h" |
12 #include "chrome/renderer/spellchecker/spellcheck.h" | 12 #include "chrome/renderer/spellchecker/spellcheck.h" |
13 #include "chrome/test/base/chrome_unit_test_suite.h" | 13 #include "chrome/test/base/chrome_unit_test_suite.h" |
14 #include "components/autofill/content/renderer/autofill_agent.h" | 14 #include "components/autofill/content/renderer/autofill_agent.h" |
15 #include "components/autofill/content/renderer/password_autofill_agent.h" | 15 #include "components/autofill/content/renderer/password_autofill_agent.h" |
16 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 16 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
17 #include "components/autofill/content/renderer/test_password_generation_agent.h" | 17 #include "components/autofill/content/renderer/test_password_generation_agent.h" |
18 #include "content/public/browser/native_web_keyboard_event.h" | 18 #include "content/public/browser/native_web_keyboard_event.h" |
19 #include "content/public/common/renderer_preferences.h" | 19 #include "content/public/common/renderer_preferences.h" |
20 #include "content/public/renderer/render_view.h" | 20 #include "content/public/renderer/render_view.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | |
22 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 21 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 22 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "third_party/WebKit/public/web/WebInputEvent.h" | 23 #include "third_party/WebKit/public/web/WebInputEvent.h" |
25 #include "third_party/WebKit/public/web/WebKit.h" | 24 #include "third_party/WebKit/public/web/WebKit.h" |
26 #include "third_party/WebKit/public/web/WebScriptController.h" | 25 #include "third_party/WebKit/public/web/WebScriptController.h" |
27 #include "third_party/WebKit/public/web/WebScriptSource.h" | 26 #include "third_party/WebKit/public/web/WebScriptSource.h" |
28 #include "third_party/WebKit/public/web/WebView.h" | 27 #include "third_party/WebKit/public/web/WebView.h" |
29 | 28 |
30 #if defined(ENABLE_EXTENSIONS) | 29 #if defined(ENABLE_EXTENSIONS) |
31 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" | 30 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" |
32 #include "extensions/browser/extension_function_dispatcher.h" | 31 #include "extensions/browser/extension_function_dispatcher.h" |
33 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
34 #include "extensions/renderer/dispatcher.h" | 33 #include "extensions/renderer/dispatcher.h" |
35 #include "extensions/renderer/event_bindings.h" | 34 #include "extensions/renderer/event_bindings.h" |
36 #endif | 35 #endif |
37 | 36 |
38 using autofill::AutofillAgent; | 37 using autofill::AutofillAgent; |
39 using autofill::PasswordAutofillAgent; | 38 using autofill::PasswordAutofillAgent; |
40 using autofill::PasswordGenerationAgent; | 39 using autofill::PasswordGenerationAgent; |
41 using blink::WebFrame; | 40 using blink::WebFrame; |
42 using blink::WebInputEvent; | 41 using blink::WebInputEvent; |
43 using blink::WebMouseEvent; | 42 using blink::WebMouseEvent; |
44 using blink::WebScriptController; | 43 using blink::WebScriptController; |
45 using blink::WebScriptSource; | 44 using blink::WebScriptSource; |
46 using blink::WebString; | 45 using blink::WebString; |
47 using blink::WebURLRequest; | 46 using blink::WebURLRequest; |
48 using content::RenderFrame; | |
49 using testing::NiceMock; | |
50 using testing::Return; | |
51 using testing::_; | |
52 | |
53 namespace { | |
54 | |
55 // An autofill agent that treats all typing as user gesture. | |
56 class MockAutofillAgent : public AutofillAgent { | |
57 public: | |
58 MockAutofillAgent(RenderFrame* render_frame, | |
59 PasswordAutofillAgent* password_autofill_agent, | |
60 PasswordGenerationAgent* password_generation_agent) | |
61 : AutofillAgent(render_frame, | |
62 password_autofill_agent, | |
63 password_generation_agent) { | |
64 ON_CALL(*this, IsUserGesture()).WillByDefault(Return(true)); | |
65 } | |
66 | |
67 ~MockAutofillAgent() override {} | |
68 | |
69 MOCK_CONST_METHOD0(IsUserGesture, bool()); | |
70 | |
71 private: | |
72 DISALLOW_COPY_AND_ASSIGN(MockAutofillAgent); | |
73 }; | |
74 | |
75 } // namespace | |
76 | 47 |
77 ChromeRenderViewTest::ChromeRenderViewTest() | 48 ChromeRenderViewTest::ChromeRenderViewTest() |
78 : password_autofill_agent_(NULL), | 49 : password_autofill_agent_(NULL), |
79 password_generation_(NULL), | 50 password_generation_(NULL), |
80 autofill_agent_(NULL), | 51 autofill_agent_(NULL), |
81 chrome_render_thread_(NULL) { | 52 chrome_render_thread_(NULL) { |
82 } | 53 } |
83 | 54 |
84 ChromeRenderViewTest::~ChromeRenderViewTest() { | 55 ChromeRenderViewTest::~ChromeRenderViewTest() { |
85 } | 56 } |
86 | 57 |
87 void ChromeRenderViewTest::SetUp() { | 58 void ChromeRenderViewTest::SetUp() { |
88 ChromeUnitTestSuite::InitializeProviders(); | 59 ChromeUnitTestSuite::InitializeProviders(); |
89 ChromeUnitTestSuite::InitializeResourceBundle(); | 60 ChromeUnitTestSuite::InitializeResourceBundle(); |
90 | 61 |
91 chrome_render_thread_ = new ChromeMockRenderThread(); | 62 chrome_render_thread_ = new ChromeMockRenderThread(); |
92 render_thread_.reset(chrome_render_thread_); | 63 render_thread_.reset(chrome_render_thread_); |
93 | 64 |
94 content::RenderViewTest::SetUp(); | 65 content::RenderViewTest::SetUp(); |
95 | 66 |
96 // RenderFrame doesn't expose its Agent objects, because it has no need to | 67 // RenderFrame doesn't expose its Agent objects, because it has no need to |
97 // store them directly (they're stored as RenderFrameObserver*). So just | 68 // store them directly (they're stored as RenderFrameObserver*). So just |
98 // create another set. | 69 // create another set. |
99 password_autofill_agent_ = | 70 password_autofill_agent_ = |
100 new autofill::TestPasswordAutofillAgent(view_->GetMainRenderFrame()); | 71 new autofill::TestPasswordAutofillAgent(view_->GetMainRenderFrame()); |
101 password_generation_ = | 72 password_generation_ = |
102 new autofill::TestPasswordGenerationAgent(view_->GetMainRenderFrame()); | 73 new autofill::TestPasswordGenerationAgent(view_->GetMainRenderFrame()); |
103 autofill_agent_ = new NiceMock<MockAutofillAgent>(view_->GetMainRenderFrame(), | 74 autofill_agent_ = |
104 password_autofill_agent_, | 75 new AutofillAgent(view_->GetMainRenderFrame(), password_autofill_agent_, |
105 password_generation_); | 76 password_generation_); |
106 } | 77 } |
107 | 78 |
108 void ChromeRenderViewTest::TearDown() { | 79 void ChromeRenderViewTest::TearDown() { |
109 #if defined(ENABLE_EXTENSIONS) | 80 #if defined(ENABLE_EXTENSIONS) |
110 ChromeContentRendererClient* client = | 81 ChromeContentRendererClient* client = |
111 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); | 82 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); |
112 client->GetExtensionDispatcherForTest()->OnRenderProcessShutdown(); | 83 client->GetExtensionDispatcherForTest()->OnRenderProcessShutdown(); |
113 #endif | 84 #endif |
114 | 85 |
115 #if defined(LEAK_SANITIZER) | 86 #if defined(LEAK_SANITIZER) |
116 // Do this before shutting down V8 in RenderViewTest::TearDown(). | 87 // Do this before shutting down V8 in RenderViewTest::TearDown(). |
117 // http://crbug.com/328552 | 88 // http://crbug.com/328552 |
118 __lsan_do_leak_check(); | 89 __lsan_do_leak_check(); |
119 #endif | 90 #endif |
120 content::RenderViewTest::TearDown(); | 91 content::RenderViewTest::TearDown(); |
121 } | 92 } |
122 | 93 |
123 content::ContentClient* ChromeRenderViewTest::CreateContentClient() { | 94 content::ContentClient* ChromeRenderViewTest::CreateContentClient() { |
124 return new ChromeContentClient(); | 95 return new ChromeContentClient(); |
125 } | 96 } |
126 | 97 |
127 content::ContentBrowserClient* | 98 content::ContentBrowserClient* |
128 ChromeRenderViewTest::CreateContentBrowserClient() { | 99 ChromeRenderViewTest::CreateContentBrowserClient() { |
129 return new chrome::ChromeContentBrowserClient(); | 100 return new chrome::ChromeContentBrowserClient(); |
130 } | 101 } |
131 | 102 |
132 content::ContentRendererClient* | 103 content::ContentRendererClient* |
133 ChromeRenderViewTest::CreateContentRendererClient() { | 104 ChromeRenderViewTest::CreateContentRendererClient() { |
134 ChromeContentRendererClient* client = new ChromeContentRendererClient(); | 105 ChromeContentRendererClient* client = new ChromeContentRendererClient(); |
135 #if defined(ENABLE_EXTENSIONS) | 106 #if defined(ENABLE_EXTENSIONS) |
136 extension_dispatcher_delegate_.reset( | 107 extension_dispatcher_delegate_.reset( |
137 new ChromeExtensionsDispatcherDelegate()); | 108 new ChromeExtensionsDispatcherDelegate()); |
138 client->SetExtensionDispatcherForTest( | 109 client->SetExtensionDispatcherForTest( |
139 new extensions::Dispatcher(extension_dispatcher_delegate_.get())); | 110 new extensions::Dispatcher(extension_dispatcher_delegate_.get())); |
140 #endif | 111 #endif |
141 #if defined(ENABLE_SPELLCHECK) | 112 #if defined(ENABLE_SPELLCHECK) |
142 client->SetSpellcheck(new SpellCheck()); | 113 client->SetSpellcheck(new SpellCheck()); |
143 #endif | 114 #endif |
144 return client; | 115 return client; |
145 } | 116 } |
146 | |
147 void ChromeRenderViewTest::EnableUserGestureSimulationForAutofill() { | |
148 EXPECT_CALL(*(static_cast<MockAutofillAgent*>(autofill_agent_)), | |
149 IsUserGesture()).WillRepeatedly(Return(true)); | |
150 } | |
151 | |
152 void ChromeRenderViewTest::DisableUserGestureSimulationForAutofill() { | |
153 EXPECT_CALL(*(static_cast<MockAutofillAgent*>(autofill_agent_)), | |
154 IsUserGesture()).WillRepeatedly(Return(false)); | |
155 } | |
OLD | NEW |