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..64cbe6c284d6c8909a6ecda4a91adf43d3bd7ac1 100644 |
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
@@ -2,10 +2,9 @@ |
// 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/password_generation_test_utils.h" |
@@ -23,6 +22,9 @@ |
#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 "mojo/public/cpp/bindings/binding_set.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,157 @@ void SetElementReadOnly(WebInputElement& element, bool read_only) { |
read_only ? WebString::fromUTF8("true") : WebString()); |
} |
+class FakeContentPasswordManagerDriver |
+ : public autofill::mojom::PasswordManagerDriver { |
+ public: |
+ FakeContentPasswordManagerDriver() {} |
+ |
+ ~FakeContentPasswordManagerDriver() override {} |
+ |
+ void BindRequest(autofill::mojom::PasswordManagerDriverRequest request) { |
+ bindings_.AddBinding(this, std::move(request)); |
+ } |
+ |
+ bool called_show_pw_suggestions() const { |
+ return called_show_pw_suggestions_; |
+ } |
+ |
+ int show_pw_suggestions_key() const { return show_pw_suggestions_key_; } |
+ |
+ const base::Optional<base::string16>& show_pw_suggestions_username() const { |
+ return show_pw_suggestions_username_; |
+ } |
+ |
+ int show_pw_suggestions_options() const { |
+ return show_pw_suggestions_options_; |
+ } |
+ |
+ void reset_show_pw_suggestions() { |
+ called_show_pw_suggestions_ = false; |
+ show_pw_suggestions_key_ = -1; |
+ show_pw_suggestions_username_ = base::nullopt; |
+ show_pw_suggestions_options_ = -1; |
+ } |
+ |
+ bool called_password_form_submitted() const { |
+ return called_password_form_submitted_; |
+ } |
+ |
+ const base::Optional<autofill::PasswordForm>& password_form_submitted() |
+ const { |
+ return password_form_submitted_; |
+ } |
+ |
+ bool called_inpage_navigation() const { return called_inpage_navigation_; } |
+ |
+ const base::Optional<autofill::PasswordForm>& |
+ password_form_inpage_navigation() const { |
+ return password_form_inpage_navigation_; |
+ } |
+ |
+ bool called_password_forms_rendered() const { |
+ return called_password_forms_rendered_; |
+ } |
+ |
+ const base::Optional<std::vector<autofill::PasswordForm>>& |
+ password_forms_rendered() const { |
+ return password_forms_rendered_; |
+ } |
+ |
+ void reset_password_forms_rendered() { |
+ called_password_forms_rendered_ = false; |
+ password_forms_rendered_ = base::nullopt; |
+ } |
+ |
+ bool called_record_save_progress() const { |
+ return called_record_save_progress_; |
+ } |
+ |
+ bool called_agent_constructed() const { return called_agent_constructed_; } |
+ |
+ private: |
+ // mojom::PasswordManagerDriver: |
+ void PasswordFormsParsed( |
+ const std::vector<autofill::PasswordForm>& forms) override {} |
+ |
+ void PasswordFormsRendered( |
+ const std::vector<autofill::PasswordForm>& visible_forms, |
+ bool did_stop_loading) override { |
+ called_password_forms_rendered_ = true; |
+ password_forms_rendered_ = visible_forms; |
+ } |
+ |
+ void PasswordFormSubmitted( |
+ const autofill::PasswordForm& password_form) override { |
+ called_password_form_submitted_ = true; |
+ password_form_submitted_ = password_form; |
+ } |
+ |
+ void InPageNavigation(const autofill::PasswordForm& password_form) override { |
+ called_inpage_navigation_ = true; |
+ password_form_inpage_navigation_ = password_form; |
+ } |
+ |
+ void PresaveGeneratedPassword( |
+ const autofill::PasswordForm& password_form) override {} |
+ |
+ void PasswordNoLongerGenerated( |
+ const autofill::PasswordForm& password_form) override {} |
+ |
+ void ShowPasswordSuggestions(int key, |
+ base::i18n::TextDirection text_direction, |
+ const base::string16& typed_username, |
+ int options, |
+ const gfx::RectF& bounds) override { |
+ called_show_pw_suggestions_ = true; |
+ show_pw_suggestions_key_ = key; |
+ show_pw_suggestions_username_ = typed_username; |
+ show_pw_suggestions_options_ = options; |
+ } |
+ |
+ void PasswordAutofillAgentConstructed() override { |
+ called_agent_constructed_ = true; |
+ } |
+ |
+ void RecordSavePasswordProgress(const std::string& log) override { |
+ called_record_save_progress_ = true; |
+ } |
+ |
+ void SaveGenerationFieldDetectedByClassifier( |
+ const autofill::PasswordForm& password_form, |
+ const base::string16& generation_field) override {} |
+ |
+ // Records whether ShowPasswordSuggestions() gets called. |
+ bool called_show_pw_suggestions_ = false; |
+ // Records data received via ShowPasswordSuggestions() call. |
+ int show_pw_suggestions_key_ = -1; |
+ base::Optional<base::string16> show_pw_suggestions_username_; |
+ int show_pw_suggestions_options_ = -1; |
+ // Records whether PasswordFormSubmitted() gets called. |
+ bool called_password_form_submitted_ = false; |
+ // Records data received via PasswordFormSubmitted() call. |
+ base::Optional<autofill::PasswordForm> password_form_submitted_; |
+ // Records whether InPageNavigation() gets called. |
+ bool called_inpage_navigation_ = false; |
+ // Records data received via InPageNavigation() call. |
+ base::Optional<autofill::PasswordForm> password_form_inpage_navigation_; |
+ // Records whether PasswordFormsRendered() gets called. |
+ bool called_password_forms_rendered_ = false; |
+ // Records data received via PasswordFormsRendered() call. |
+ base::Optional<std::vector<autofill::PasswordForm>> password_forms_rendered_; |
+ // Records whether RecordSavePasswordProgress() gets called. |
+ bool called_record_save_progress_ = false; |
+ // Records whether PasswordAutofillAgentConstructed() gets called. |
+ bool called_agent_constructed_ = false; |
+ |
+ mojo::BindingSet<autofill::mojom::PasswordManagerDriver> bindings_; |
+}; |
+ |
+enum PasswordFormSourceType { |
+ PasswordFormSubmitted, |
+ PasswordFormInPageNavigation, |
+}; |
+ |
} // namespace |
namespace autofill { |
@@ -242,17 +395,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 +469,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 +537,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 +609,55 @@ 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(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)); |
+ 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(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(fake_driver_.password_form_submitted()); |
+ form = *(fake_driver_.password_form_submitted()); |
+ } else if (expected_type == PasswordFormInPageNavigation) { |
+ ASSERT_TRUE(fake_driver_.called_inpage_navigation()); |
+ ASSERT_TRUE(fake_driver_.password_form_inpage_navigation()); |
+ form = *(fake_driver_.password_form_inpage_navigation()); |
+ } else { |
+ ASSERT_TRUE(false); |
+ } |
size_t unchecked_masks = expected_properties_masks.size(); |
for (const FormFieldData& field : form.form_data.fields) { |
@@ -513,18 +676,23 @@ 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(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 +985,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(fake_driver_.password_forms_rendered()); |
+ EXPECT_TRUE(fake_driver_.password_forms_rendered()->size()); |
+ |
+ 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(fake_driver_.password_forms_rendered()); |
+ EXPECT_FALSE(fake_driver_.password_forms_rendered()->size()); |
- 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(fake_driver_.password_forms_rendered()); |
+ EXPECT_FALSE(fake_driver_.password_forms_rendered()->size()); |
} |
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 +1381,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 +1450,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 +1458,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 +1482,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 +1516,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 +1536,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 +1685,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 +1706,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 +1945,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 +2002,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 +2075,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 +2116,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 +2178,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 +2197,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 +2225,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 +2284,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 +2532,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 +2554,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 +2569,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. |