Chromium Code Reviews| Index: components/password_manager/content/browser/content_password_manager_driver_unittest.cc |
| diff --git a/components/password_manager/content/browser/content_password_manager_driver_unittest.cc b/components/password_manager/content/browser/content_password_manager_driver_unittest.cc |
| index 267aa3797ac7348c166682252865e2c2bc97265f..ae0ff904ed9370462a80e2ed1981162c55d2e7f7 100644 |
| --- a/components/password_manager/content/browser/content_password_manager_driver_unittest.cc |
| +++ b/components/password_manager/content/browser/content_password_manager_driver_unittest.cc |
| @@ -4,17 +4,16 @@ |
| #include "components/password_manager/content/browser/content_password_manager_driver.h" |
| -#include <stdint.h> |
| - |
| -#include <tuple> |
| - |
| #include "base/macros.h" |
| -#include "components/autofill/content/common/autofill_messages.h" |
| +#include "base/run_loop.h" |
| +#include "components/autofill/content/public/interfaces/autofill_agent.mojom.h" |
| #include "components/autofill/core/browser/test_autofill_client.h" |
| #include "components/password_manager/core/browser/stub_log_manager.h" |
| #include "components/password_manager/core/browser/stub_password_manager_client.h" |
| -#include "content/public/test/mock_render_process_host.h" |
| +#include "content/public/browser/web_contents.h" |
| #include "content/public/test/test_renderer_host.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "services/shell/public/cpp/interface_provider.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -40,6 +39,55 @@ class MockPasswordManagerClient : public StubPasswordManagerClient { |
| DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient); |
| }; |
| +class FakePasswordAutofillAgent |
| + : public autofill::mojom::PasswordAutofillAgent { |
| + public: |
| + FakePasswordAutofillAgent() |
| + : called_set_logging_state_(false), |
| + logging_state_active_(false), |
| + binding_(this) {} |
| + |
| + ~FakePasswordAutofillAgent() override {} |
| + |
| + void BindRequest(mojo::ScopedMessagePipeHandle handle) { |
| + binding_.Bind(mojo::MakeRequest<autofill::mojom::PasswordAutofillAgent>( |
| + std::move(handle))); |
| + } |
| + |
| + bool called_set_logging_state() { return called_set_logging_state_; } |
| + |
| + bool logging_state_active() { return logging_state_active_; } |
| + |
| + void reset_data() { |
| + called_set_logging_state_ = false; |
| + logging_state_active_ = false; |
| + } |
| + |
| + private: |
| + // autofill::mojom::PasswordAutofillAgent: |
| + void FillPasswordForm( |
| + int key, |
| + const autofill::PasswordFormFillData& form_data) override {} |
| + |
| + void SetLoggingState(bool active) override { |
| + called_set_logging_state_ = true; |
| + logging_state_active_ = active; |
| + } |
| + |
| + void AutofillUsernameAndPasswordDataReceived( |
| + const autofill::FormsPredictionsMap& predictions) override {} |
| + |
| + void FindFocusedPasswordForm( |
| + const FindFocusedPasswordFormCallback& callback) override {} |
| + |
| + // Records whether SetLoggingState() gets called. |
| + bool called_set_logging_state_; |
| + // Records data received via SetLoggingState() call. |
| + bool logging_state_active_; |
| + |
| + mojo::Binding<autofill::mojom::PasswordAutofillAgent> binding_; |
| +}; |
| + |
| } // namespace |
| class ContentPasswordManagerDriverTest |
| @@ -50,18 +98,24 @@ class ContentPasswordManagerDriverTest |
| content::RenderViewHostTestHarness::SetUp(); |
| ON_CALL(password_manager_client_, GetLogManager()) |
| .WillByDefault(Return(&log_manager_)); |
| + |
| + shell::InterfaceProvider* remote_interfaces = |
| + web_contents()->GetMainFrame()->GetRemoteInterfaces(); |
| + shell::InterfaceProvider::TestApi test_api(remote_interfaces); |
| + test_api.SetBinderForName( |
| + autofill::mojom::PasswordAutofillAgent::Name_, |
| + base::Bind(&FakePasswordAutofillAgent::BindRequest, |
| + base::Unretained(&fake_agent_))); |
| } |
| bool WasLoggingActivationMessageSent(bool* activation_flag) { |
| - const uint32_t kMsgID = AutofillMsg_SetLoggingState::ID; |
| - const IPC::Message* message = |
| - process()->sink().GetFirstMessageMatching(kMsgID); |
| - if (!message) |
| + base::RunLoop().RunUntilIdle(); |
| + if (!fake_agent_.called_set_logging_state()) |
| return false; |
| - std::tuple<bool> param; |
| - AutofillMsg_SetLoggingState::Read(message, ¶m); |
| - *activation_flag = std::get<0>(param); |
| - process()->sink().ClearMessages(); |
| + |
| + if (activation_flag) |
| + *activation_flag = fake_agent_.logging_state_active(); |
| + fake_agent_.reset_data(); |
| return true; |
| } |
| @@ -69,6 +123,8 @@ class ContentPasswordManagerDriverTest |
| MockLogManager log_manager_; |
| MockPasswordManagerClient password_manager_client_; |
| autofill::TestAutofillClient autofill_client_; |
| + |
| + FakePasswordAutofillAgent fake_agent_; |
| }; |
| TEST_P(ContentPasswordManagerDriverTest, |
| @@ -77,7 +133,6 @@ TEST_P(ContentPasswordManagerDriverTest, |
| std::unique_ptr<ContentPasswordManagerDriver> driver( |
| new ContentPasswordManagerDriver(main_rfh(), &password_manager_client_, |
| &autofill_client_)); |
| - process()->sink().ClearMessages(); |
| EXPECT_CALL(log_manager_, IsLoggingActive()) |
| .WillRepeatedly(Return(should_allow_logging)); |
| @@ -102,11 +157,10 @@ TEST_P(ContentPasswordManagerDriverTest, AnswerToIPCPingsAboutLoggingState) { |
| EXPECT_CALL(log_manager_, IsLoggingActive()) |
| .WillRepeatedly(Return(should_allow_logging)); |
| driver->SendLoggingAvailability(); |
| - process()->sink().ClearMessages(); |
| + WasLoggingActivationMessageSent(NULL); |
|
vabr (Chromium)
2016/08/09 17:36:18
nit: nullptr instead of NULL.
leonhsl(Using Gerrit)
2016/08/10 13:22:02
Done.
|
| // Ping the driver for logging activity update. |
| - AutofillHostMsg_PasswordAutofillAgentConstructed msg(0); |
| - driver->HandleMessage(msg); |
| + driver->PasswordAutofillAgentConstructed(); |
| bool logging_activated = false; |
| EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_activated)); |