| Index: chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| diff --git a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| index 9b14dc096d85328e9b7a3c2d1e061187a1abc51c..0b3eb3d67f661185082aed994ec0f3bc9a111869 100644
|
| --- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| +++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| @@ -2,12 +2,12 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include <tuple>
|
| -
|
| #include "base/feature_list.h"
|
| #include "base/macros.h"
|
| +#include "base/run_loop.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/renderer/autofill/fake_content_password_manager_driver.h"
|
| #include "chrome/renderer/autofill/password_generation_test_utils.h"
|
| #include "chrome/test/base/chrome_render_view_test.h"
|
| #include "components/autofill/content/common/autofill_messages.h"
|
| @@ -23,6 +23,8 @@
|
| #include "components/autofill/core/common/password_form_field_prediction_map.h"
|
| #include "components/password_manager/core/common/password_manager_features.h"
|
| #include "content/public/renderer/render_frame.h"
|
| +#include "content/public/renderer/render_view.h"
|
| +#include "services/shell/public/cpp/interface_provider.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/WebKit/public/platform/WebString.h"
|
| #include "third_party/WebKit/public/platform/WebVector.h"
|
| @@ -228,6 +230,11 @@ void SetElementReadOnly(WebInputElement& element, bool read_only) {
|
| read_only ? WebString::fromUTF8("true") : WebString());
|
| }
|
|
|
| +enum PasswordFormSourceType {
|
| + PasswordFormSubmitted,
|
| + PasswordFormInPageNavigation,
|
| +};
|
| +
|
| } // namespace
|
|
|
| namespace autofill {
|
| @@ -242,17 +249,8 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| // protected.
|
| void SimulateOnFillPasswordForm(
|
| const PasswordFormFillData& fill_data) {
|
| - AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data);
|
| - static_cast<IPC::Listener*>(password_autofill_agent_)
|
| - ->OnMessageReceived(msg);
|
| - }
|
| -
|
| - // As above, but fills for an iframe.
|
| - void SimulateOnFillPasswordFormForFrame(
|
| - WebFrame* frame,
|
| - const PasswordFormFillData& fill_data) {
|
| - AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data);
|
| - content::RenderFrame::FromWebFrame(frame)->OnMessageReceived(msg);
|
| + password_autofill_agent_->FillPasswordForm(kPasswordFillFormDataId,
|
| + fill_data);
|
| }
|
|
|
| // Simulates the show initial password account suggestions message being sent
|
| @@ -325,6 +323,18 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| ChromeRenderViewTest::TearDown();
|
| }
|
|
|
| + void RegisterMainFrameRemoteInterfaces() override {
|
| + // We only use the fake driver for main frame
|
| + // because our test cases only involve the main frame.
|
| + shell::InterfaceProvider* remote_interfaces =
|
| + view_->GetMainRenderFrame()->GetRemoteInterfaces();
|
| + shell::InterfaceProvider::TestApi test_api(remote_interfaces);
|
| + test_api.SetBinderForName(
|
| + mojom::PasswordManagerDriver::Name_,
|
| + base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerDriver,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| void SetFillOnAccountSelect() {
|
| base::FeatureList::ClearInstanceForTesting();
|
| std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
|
| @@ -381,7 +391,6 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| const base::string16& password) {
|
| // This call is necessary to setup the autofill agent appropriate for the
|
| // user selection; simulates the menu actually popping up.
|
| - render_thread_->sink().ClearMessages();
|
| static_cast<autofill::PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(input, false);
|
|
|
| @@ -454,47 +463,56 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| // the expected flag for the PasswordAutofillManager, whether to show all
|
| // suggestions, or only those starting with |username|.
|
| void CheckSuggestions(const std::string& username, bool show_all) {
|
| - const IPC::Message* message =
|
| - render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_ShowPasswordSuggestions::ID);
|
| - ASSERT_TRUE(message);
|
| - std::tuple<int, base::i18n::TextDirection, base::string16, int, gfx::RectF>
|
| - args;
|
| - AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args);
|
| - EXPECT_EQ(kPasswordFillFormDataId, std::get<0>(args));
|
| - EXPECT_EQ(ASCIIToUTF16(username), std::get<2>(args));
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + ASSERT_TRUE(fake_driver_.called_show_pw_suggestions());
|
| + EXPECT_EQ(kPasswordFillFormDataId, fake_driver_.show_pw_suggestions_key());
|
| + ASSERT_TRUE(static_cast<bool>(fake_driver_.show_pw_suggestions_username()));
|
| + EXPECT_EQ(ASCIIToUTF16(username),
|
| + *(fake_driver_.show_pw_suggestions_username()));
|
| EXPECT_EQ(show_all,
|
| - static_cast<bool>(std::get<3>(args) & autofill::SHOW_ALL));
|
| + static_cast<bool>(fake_driver_.show_pw_suggestions_options() &
|
| + autofill::SHOW_ALL));
|
| +
|
| + fake_driver_.reset_show_pw_suggestions();
|
| + }
|
|
|
| - render_thread_->sink().ClearMessages();
|
| + bool GetCalledShowPasswordSuggestions() {
|
| + base::RunLoop().RunUntilIdle();
|
| + return fake_driver_.called_show_pw_suggestions();
|
| }
|
|
|
| void ExpectFormSubmittedWithUsernameAndPasswords(
|
| const std::string& username_value,
|
| const std::string& password_value,
|
| const std::string& new_password_value) {
|
| - const IPC::Message* message =
|
| - render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormSubmitted::ID);
|
| - ASSERT_TRUE(message);
|
| - std::tuple<autofill::PasswordForm> args;
|
| - AutofillHostMsg_PasswordFormSubmitted::Read(message, &args);
|
| - EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value);
|
| - EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value);
|
| - EXPECT_EQ(ASCIIToUTF16(new_password_value),
|
| - std::get<0>(args).new_password_value);
|
| + base::RunLoop().RunUntilIdle();
|
| + ASSERT_TRUE(fake_driver_.called_password_form_submitted());
|
| + ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted()));
|
| + const autofill::PasswordForm& form =
|
| + *(fake_driver_.password_form_submitted());
|
| + EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value);
|
| + EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value);
|
| + EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value);
|
| }
|
|
|
| void ExpectFieldPropertiesMasks(
|
| - uint32_t expected_message_id,
|
| + PasswordFormSourceType expected_type,
|
| const std::map<base::string16, FieldPropertiesMask>&
|
| expected_properties_masks) {
|
| - const IPC::Message* message =
|
| - render_thread_->sink().GetFirstMessageMatching(expected_message_id);
|
| - ASSERT_TRUE(message);
|
| - std::tuple<autofill::PasswordForm> args;
|
| - AutofillHostMsg_PasswordFormSubmitted::Read(message, &args);
|
| - const autofill::PasswordForm& form = std::get<0>(args);
|
| + base::RunLoop().RunUntilIdle();
|
| + autofill::PasswordForm form;
|
| + if (expected_type == PasswordFormSubmitted) {
|
| + ASSERT_TRUE(fake_driver_.called_password_form_submitted());
|
| + ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted()));
|
| + form = *(fake_driver_.password_form_submitted());
|
| + } else {
|
| + ASSERT_EQ(PasswordFormInPageNavigation, expected_type);
|
| + ASSERT_TRUE(fake_driver_.called_inpage_navigation());
|
| + ASSERT_TRUE(
|
| + static_cast<bool>(fake_driver_.password_form_inpage_navigation()));
|
| + form = *(fake_driver_.password_form_inpage_navigation());
|
| + }
|
|
|
| size_t unchecked_masks = expected_properties_masks.size();
|
| for (const FormFieldData& field : form.form_data.fields) {
|
| @@ -513,18 +531,24 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| const std::string& username_value,
|
| const std::string& password_value,
|
| const std::string& new_password_value) {
|
| - const IPC::Message* message =
|
| - render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_InPageNavigation::ID);
|
| - ASSERT_TRUE(message);
|
| - std::tuple<autofill::PasswordForm> args;
|
| - AutofillHostMsg_InPageNavigation::Read(message, &args);
|
| - EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value);
|
| - EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value);
|
| - EXPECT_EQ(ASCIIToUTF16(new_password_value),
|
| - std::get<0>(args).new_password_value);
|
| + base::RunLoop().RunUntilIdle();
|
| + ASSERT_TRUE(fake_driver_.called_inpage_navigation());
|
| + ASSERT_TRUE(
|
| + static_cast<bool>(fake_driver_.password_form_inpage_navigation()));
|
| + const autofill::PasswordForm& form =
|
| + *(fake_driver_.password_form_inpage_navigation());
|
| + EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value);
|
| + EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value);
|
| + EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value);
|
| }
|
|
|
| + void BindPasswordManagerDriver(mojo::ScopedMessagePipeHandle handle) {
|
| + fake_driver_.BindRequest(
|
| + mojo::MakeRequest<mojom::PasswordManagerDriver>(std::move(handle)));
|
| + }
|
| +
|
| + FakeContentPasswordManagerDriver fake_driver_;
|
| +
|
| base::string16 username1_;
|
| base::string16 username2_;
|
| base::string16 username3_;
|
| @@ -817,52 +841,48 @@ TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) {
|
| }
|
|
|
| TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) {
|
| - render_thread_->sink().ClearMessages();
|
| + fake_driver_.reset_password_forms_rendered();
|
| LoadHTML(kVisibleFormWithNoUsernameHTML);
|
| - const IPC::Message* message = render_thread_->sink()
|
| - .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID);
|
| - EXPECT_TRUE(message);
|
| - std::tuple<std::vector<autofill::PasswordForm>, bool> param;
|
| - AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m);
|
| - EXPECT_TRUE(std::get<0>(param).size());
|
| -
|
| - render_thread_->sink().ClearMessages();
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
|
| + ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered()));
|
| + EXPECT_FALSE(fake_driver_.password_forms_rendered()->empty());
|
| +
|
| + fake_driver_.reset_password_forms_rendered();
|
| LoadHTML(kEmptyFormHTML);
|
| - message = render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormsRendered::ID);
|
| - EXPECT_TRUE(message);
|
| - AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m);
|
| - EXPECT_FALSE(std::get<0>(param).size());
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
|
| + ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered()));
|
| + EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
|
|
|
| - render_thread_->sink().ClearMessages();
|
| + fake_driver_.reset_password_forms_rendered();
|
| LoadHTML(kNonVisibleFormHTML);
|
| - message = render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormsRendered::ID);
|
| - EXPECT_TRUE(message);
|
| - AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m);
|
| - EXPECT_FALSE(std::get<0>(param).size());
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
|
| + ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered()));
|
| + EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
|
| }
|
|
|
| TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) {
|
| - render_thread_->sink().ClearMessages();
|
| + fake_driver_.reset_password_forms_rendered();
|
| LoadHTML(kEmptyWebpage);
|
| - EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormsRendered::ID));
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_FALSE(fake_driver_.called_password_forms_rendered());
|
|
|
| - render_thread_->sink().ClearMessages();
|
| + fake_driver_.reset_password_forms_rendered();
|
| LoadHTML(kRedirectionWebpage);
|
| - EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormsRendered::ID));
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_FALSE(fake_driver_.called_password_forms_rendered());
|
|
|
| - render_thread_->sink().ClearMessages();
|
| + fake_driver_.reset_password_forms_rendered();
|
| LoadHTML(kSimpleWebpage);
|
| - EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormsRendered::ID));
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
|
|
|
| - render_thread_->sink().ClearMessages();
|
| + fake_driver_.reset_password_forms_rendered();
|
| LoadHTML(kWebpageWithDynamicContent);
|
| - EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormsRendered::ID));
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
|
| }
|
|
|
| // Tests that a password will only be filled as a suggested and will not be
|
| @@ -1217,52 +1237,37 @@ TEST_F(PasswordAutofillAgentTest,
|
|
|
| // Tests that logging is off by default.
|
| TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) {
|
| - render_thread_->sink().ClearMessages();
|
| SendVisiblePasswordForms();
|
| - const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_RecordSavePasswordProgress::ID);
|
| - EXPECT_FALSE(message);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_FALSE(fake_driver_.called_record_save_progress());
|
| }
|
|
|
| // Test that logging can be turned on by a message.
|
| TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) {
|
| // Turn the logging on.
|
| - AutofillMsg_SetLoggingState msg_activate(0, true);
|
| - // Up-cast to access OnMessageReceived, which is private in the agent.
|
| - EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
|
| - ->OnMessageReceived(msg_activate));
|
| + password_autofill_agent_->SetLoggingState(true);
|
|
|
| - render_thread_->sink().ClearMessages();
|
| SendVisiblePasswordForms();
|
| - const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_RecordSavePasswordProgress::ID);
|
| - EXPECT_TRUE(message);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_TRUE(fake_driver_.called_record_save_progress());
|
| }
|
|
|
| // Test that logging can be turned off by a message.
|
| TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) {
|
| // Turn the logging on and then off.
|
| - AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true);
|
| - // Up-cast to access OnMessageReceived, which is private in the agent.
|
| - EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
|
| - ->OnMessageReceived(msg_activate));
|
| - AutofillMsg_SetLoggingState msg_deactivate(0, /*active=*/false);
|
| - EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
|
| - ->OnMessageReceived(msg_deactivate));
|
| -
|
| - render_thread_->sink().ClearMessages();
|
| + password_autofill_agent_->SetLoggingState(true);
|
| + password_autofill_agent_->SetLoggingState(false);
|
| +
|
| SendVisiblePasswordForms();
|
| - const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_RecordSavePasswordProgress::ID);
|
| - EXPECT_FALSE(message);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_FALSE(fake_driver_.called_record_save_progress());
|
| }
|
|
|
| // Test that the agent sends an IPC call to get the current activity state of
|
| // password saving logging soon after construction.
|
| TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) {
|
| - const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordAutofillAgentConstructed::ID);
|
| - EXPECT_TRUE(message);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_TRUE(fake_driver_.called_agent_constructed());
|
| }
|
|
|
| // Tests that one user click on a username field is sufficient to bring up a
|
| @@ -1301,7 +1306,6 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
|
|
|
| // Simulate a user clicking on the username element. This should produce a
|
| // message with all the usernames.
|
| - render_thread_->sink().ClearMessages();
|
| static_cast<PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(username_element_, false);
|
| CheckSuggestions(std::string(), false);
|
| @@ -1310,7 +1314,6 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
|
| // clicking on the username element. This should also produce a message with
|
| // all the usernames.
|
| SimulateUsernameChange("baz");
|
| - render_thread_->sink().ClearMessages();
|
| static_cast<PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(username_element_, true);
|
| CheckSuggestions("baz", true);
|
| @@ -1335,11 +1338,10 @@ TEST_F(PasswordAutofillAgentTest,
|
|
|
| // Simulate a user clicking on the password element. This should produce no
|
| // message.
|
| - render_thread_->sink().ClearMessages();
|
| + fake_driver_.reset_show_pw_suggestions();
|
| static_cast<PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(password_element_, false);
|
| - EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_ShowPasswordSuggestions::ID));
|
| + EXPECT_TRUE(GetCalledShowPasswordSuggestions());
|
| }
|
|
|
| // Tests the autosuggestions that are given when a password element is clicked,
|
| @@ -1370,7 +1372,6 @@ TEST_F(PasswordAutofillAgentTest,
|
| // Simulate a user clicking on the password element. This should produce a
|
| // dropdown with suggestion of all available usernames and so username
|
| // filter will be the empty string.
|
| - render_thread_->sink().ClearMessages();
|
| static_cast<PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(password_element_, false);
|
| CheckSuggestions("", false);
|
| @@ -1391,11 +1392,10 @@ TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) {
|
|
|
| // Simulate a user clicking on the password element. This should produce no
|
| // message.
|
| - render_thread_->sink().ClearMessages();
|
| + fake_driver_.reset_show_pw_suggestions();
|
| static_cast<PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(password_element_, false);
|
| - EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_ShowPasswordSuggestions::ID));
|
| + EXPECT_TRUE(GetCalledShowPasswordSuggestions());
|
| }
|
|
|
| // The user types in a username and a password, but then just before sending
|
| @@ -1541,8 +1541,7 @@ TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnSubmit) {
|
| expected_properties_masks[ASCIIToUTF16("password")] =
|
| FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS;
|
|
|
| - ExpectFieldPropertiesMasks(AutofillHostMsg_PasswordFormSubmitted::ID,
|
| - expected_properties_masks);
|
| + ExpectFieldPropertiesMasks(PasswordFormSubmitted, expected_properties_masks);
|
| }
|
|
|
| TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) {
|
| @@ -1563,7 +1562,7 @@ TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) {
|
| expected_properties_masks[ASCIIToUTF16("password")] =
|
| FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS;
|
|
|
| - ExpectFieldPropertiesMasks(AutofillHostMsg_InPageNavigation::ID,
|
| + ExpectFieldPropertiesMasks(PasswordFormInPageNavigation,
|
| expected_properties_masks);
|
| }
|
|
|
| @@ -1802,8 +1801,7 @@ TEST_F(PasswordAutofillAgentTest, NotShowPopupPasswordField) {
|
|
|
| SimulateSuggestionChoiceOfUsernameAndPassword(
|
| password_element_, base::string16(), ASCIIToUTF16(kAlicePassword));
|
| - ASSERT_FALSE(render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_ShowPasswordSuggestions::ID));
|
| + ASSERT_FALSE(GetCalledShowPasswordSuggestions());
|
| }
|
|
|
| // Tests with fill-on-account-select enabled that if the username element is
|
| @@ -1860,9 +1858,8 @@ TEST_F(PasswordAutofillAgentTest, FindingFieldsWithAutofillPredictions) {
|
| std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions;
|
| predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME;
|
| predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD;
|
| - AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions);
|
| - static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
|
| - ->OnMessageReceived(msg);
|
| + password_autofill_agent_->AutofillUsernameAndPasswordDataReceived(
|
| + predictions);
|
|
|
| // The predictions should still match even if the form changes, as long
|
| // as the particular elements don't change.
|
| @@ -1934,8 +1931,7 @@ TEST_F(PasswordAutofillAgentTest,
|
| GetMainFrame()->document(), 0, 2);
|
|
|
| base::string16 password = base::ASCIIToUTF16("NewPass22");
|
| - AutofillMsg_GeneratedPasswordAccepted msg(0, password);
|
| - static_cast<IPC::Listener*>(password_generation_)->OnMessageReceived(msg);
|
| + password_generation_->GeneratedPasswordAccepted(password);
|
|
|
| static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
|
| ->WillSendSubmitEvent(username_element_.form());
|
| @@ -1976,9 +1972,7 @@ TEST_F(PasswordAutofillAgentTest, PasswordGenerationSupersedesAutofill) {
|
| // generation but not password autofill.
|
| SetFocused(password_element_);
|
| SimulateElementClick("new_password");
|
| - EXPECT_EQ(nullptr,
|
| - render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_ShowPasswordSuggestions::ID));
|
| + EXPECT_FALSE(GetCalledShowPasswordSuggestions());
|
| EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
|
| AutofillHostMsg_ShowPasswordGenerationPopup::ID));
|
| }
|
| @@ -2040,7 +2034,6 @@ TEST_F(PasswordAutofillAgentTest,
|
| SimulateOnFillPasswordForm(fill_data_);
|
| // Simulate a user clicking on the username element. This should produce a
|
| // message.
|
| - render_thread_->sink().ClearMessages();
|
| static_cast<PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(username_element_, true);
|
| CheckSuggestions("", true);
|
| @@ -2060,7 +2053,6 @@ TEST_F(PasswordAutofillAgentTest,
|
| SimulateOnFillPasswordForm(fill_data_);
|
| // Simulate a user clicking on the password element. This should produce a
|
| // message.
|
| - render_thread_->sink().ClearMessages();
|
| static_cast<PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(password_element_, true);
|
| CheckSuggestions("", false);
|
| @@ -2089,18 +2081,16 @@ TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) {
|
| // Simulate Autofill predictions: the third field is not a password.
|
| std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions;
|
| predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD;
|
| - AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions);
|
| - static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
|
| - ->OnMessageReceived(msg);
|
| + password_autofill_agent_->AutofillUsernameAndPasswordDataReceived(
|
| + predictions);
|
|
|
| static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
|
| ->WillSendSubmitEvent(form_element);
|
| static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
|
| ->WillSubmitForm(form_element);
|
|
|
| - const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormSubmitted::ID);
|
| - ASSERT_FALSE(message);
|
| + base::RunLoop().RunUntilIdle();
|
| + ASSERT_FALSE(fake_driver_.called_password_form_submitted());
|
| }
|
|
|
| // Tests that only the password field is autocompleted when the browser sends
|
| @@ -2150,10 +2140,8 @@ TEST_F(PasswordAutofillAgentTest,
|
|
|
| password_autofill_agent_->AJAXSucceeded();
|
|
|
| - const IPC::Message* message =
|
| - render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_PasswordFormSubmitted::ID);
|
| - ASSERT_FALSE(message);
|
| + base::RunLoop().RunUntilIdle();
|
| + ASSERT_FALSE(fake_driver_.called_password_form_submitted());
|
| }
|
|
|
| // Tests that credential suggestions are autofilled on a password (and change
|
| @@ -2400,7 +2388,6 @@ TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) {
|
|
|
| // Simulate a user clicking on the password element. This should produce a
|
| // dropdown with suggestion of all available usernames.
|
| - render_thread_->sink().ClearMessages();
|
| static_cast<PageClickListener*>(autofill_agent_)
|
| ->FormControlElementClicked(password_element_, false);
|
| CheckSuggestions("", false);
|
| @@ -2423,7 +2410,6 @@ TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) {
|
|
|
| // Simulate a user clicking on the password elements. This should produce
|
| // dropdowns with suggestion of all available usernames.
|
| - render_thread_->sink().ClearMessages();
|
| SimulateElementClick("password");
|
| CheckSuggestions("", false);
|
|
|
| @@ -2439,13 +2425,11 @@ TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) {
|
| ASCIIToUTF16(kAlicePassword)));
|
|
|
| // Simulate a user clicking on not autofilled password fields. This should
|
| - // produce
|
| - // no suggestion dropdowns.
|
| - render_thread_->sink().ClearMessages();
|
| + // produce no suggestion dropdowns.
|
| + fake_driver_.reset_show_pw_suggestions();
|
| SimulateElementClick("newpassword");
|
| SimulateElementClick("confirmpassword");
|
| - EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
|
| - AutofillHostMsg_ShowPasswordSuggestions::ID));
|
| + EXPECT_FALSE(GetCalledShowPasswordSuggestions());
|
|
|
| // But when the user clicks on the autofilled password field again it should
|
| // still produce a suggestion dropdown.
|
|
|