Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: components/password_manager/content/browser/content_password_manager_driver_unittest.cc

Issue 2216463002: [Autofill] Migrate ContentPasswordManagerDriver<-->Password{Autofill,Generation}Agent IPCs to mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nit from Vaclav Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..06e21b397ded4a8bfb76854026bbb627bbb84071 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, &param);
- *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(nullptr);
// 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));

Powered by Google App Engine
This is Rietveld 408576698