Chromium Code Reviews| Index: chrome/test/base/chrome_render_view_test.cc |
| diff --git a/chrome/test/base/chrome_render_view_test.cc b/chrome/test/base/chrome_render_view_test.cc |
| index 4f47f69eb007c99a4b791220cd01c23e595b2ae5..f3f20e1a8ee4fad50b66a830c69b6a480692f9b3 100644 |
| --- a/chrome/test/base/chrome_render_view_test.cc |
| +++ b/chrome/test/base/chrome_render_view_test.cc |
| @@ -18,6 +18,7 @@ |
| #include "content/public/browser/native_web_keyboard_event.h" |
| #include "content/public/common/renderer_preferences.h" |
| #include "content/public/renderer/render_view.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| #include "third_party/WebKit/public/web/WebFrame.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| @@ -34,6 +35,8 @@ |
| #include "extensions/renderer/event_bindings.h" |
| #endif |
| +namespace { |
| + |
| using autofill::AutofillAgent; |
|
Lei Zhang
2015/05/15 22:49:14
these can be outside the anonymous namespace
please use gerrit instead
2015/05/16 00:08:09
Done.
|
| using autofill::PasswordAutofillAgent; |
| using autofill::PasswordGenerationAgent; |
| @@ -44,6 +47,32 @@ using blink::WebScriptController; |
| using blink::WebScriptSource; |
| using blink::WebString; |
| using blink::WebURLRequest; |
| +using content::RenderFrame; |
| +using testing::NiceMock; |
| +using testing::Return; |
| +using testing::_; |
| + |
| +// An autofill agent that treats all typing as user gesture. |
| +class MockAutofillAgent : public AutofillAgent { |
| + public: |
| + MockAutofillAgent(RenderFrame* render_frame, |
| + PasswordAutofillAgent* password_autofill_agent, |
| + PasswordGenerationAgent* password_generation_agent) |
| + : AutofillAgent(render_frame, |
| + password_autofill_agent, |
| + password_generation_agent) { |
| + ON_CALL(*this, IsUserGesture()).WillByDefault(Return(true)); |
| + } |
| + |
| + ~MockAutofillAgent() override {} |
| + |
| + MOCK_CONST_METHOD0(IsUserGesture, bool()); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MockAutofillAgent); |
| +}; |
| + |
| +} // namespace |
| ChromeRenderViewTest::ChromeRenderViewTest() |
| : password_autofill_agent_(NULL), |
| @@ -71,9 +100,9 @@ void ChromeRenderViewTest::SetUp() { |
| new autofill::TestPasswordAutofillAgent(view_->GetMainRenderFrame()); |
| password_generation_ = |
| new autofill::TestPasswordGenerationAgent(view_->GetMainRenderFrame()); |
| - autofill_agent_ = |
| - new AutofillAgent(view_->GetMainRenderFrame(), password_autofill_agent_, |
| - password_generation_); |
| + autofill_agent_ = new NiceMock<MockAutofillAgent>(view_->GetMainRenderFrame(), |
| + password_autofill_agent_, |
| + password_generation_); |
| } |
| void ChromeRenderViewTest::TearDown() { |
| @@ -96,12 +125,12 @@ content::ContentClient* ChromeRenderViewTest::CreateContentClient() { |
| } |
| content::ContentBrowserClient* |
| - ChromeRenderViewTest::CreateContentBrowserClient() { |
| +ChromeRenderViewTest::CreateContentBrowserClient() { |
| return new chrome::ChromeContentBrowserClient(); |
| } |
| content::ContentRendererClient* |
| - ChromeRenderViewTest::CreateContentRendererClient() { |
| +ChromeRenderViewTest::CreateContentRendererClient() { |
| ChromeContentRendererClient* client = new ChromeContentRendererClient(); |
| #if defined(ENABLE_EXTENSIONS) |
| extension_dispatcher_delegate_.reset( |
| @@ -114,3 +143,13 @@ content::ContentRendererClient* |
| #endif |
| return client; |
| } |
| + |
| +void ChromeRenderViewTest::EnableUserGestureSimulation() { |
| + EXPECT_CALL(*(static_cast<MockAutofillAgent*>(autofill_agent_)), |
| + IsUserGesture()).WillRepeatedly(Return(true)); |
| +} |
| + |
| +void ChromeRenderViewTest::DisableUserGestureSimulation() { |
| + EXPECT_CALL(*(static_cast<MockAutofillAgent*>(autofill_agent_)), |
| + IsUserGesture()).WillRepeatedly(Return(false)); |
| +} |