| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
| 8 #include "components/autofill/content/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
| 9 #include "components/autofill/content/renderer/autofill_agent.h" | 9 #include "components/autofill/content/renderer/autofill_agent.h" |
| 10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 using base::UTF16ToUTF8; | 30 using base::UTF16ToUTF8; |
| 31 using blink::WebDocument; | 31 using blink::WebDocument; |
| 32 using blink::WebElement; | 32 using blink::WebElement; |
| 33 using blink::WebFrame; | 33 using blink::WebFrame; |
| 34 using blink::WebInputElement; | 34 using blink::WebInputElement; |
| 35 using blink::WebString; | 35 using blink::WebString; |
| 36 using blink::WebView; | 36 using blink::WebView; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const int kPasswordFillFormDataId = 1234; |
| 41 |
| 40 // The name of the username/password element in the form. | 42 // The name of the username/password element in the form. |
| 41 const char kUsernameName[] = "username"; | 43 const char kUsernameName[] = "username"; |
| 42 const char kPasswordName[] = "password"; | 44 const char kPasswordName[] = "password"; |
| 43 | 45 |
| 44 const char kAliceUsername[] = "alice"; | 46 const char kAliceUsername[] = "alice"; |
| 45 const char kAlicePassword[] = "password"; | 47 const char kAlicePassword[] = "password"; |
| 46 const char kBobUsername[] = "bob"; | 48 const char kBobUsername[] = "bob"; |
| 47 const char kBobPassword[] = "secret"; | 49 const char kBobPassword[] = "secret"; |
| 48 const char kCarolUsername[] = "Carol"; | 50 const char kCarolUsername[] = "Carol"; |
| 49 const char kCarolPassword[] = "test"; | 51 const char kCarolPassword[] = "test"; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 class PasswordAutofillAgentTest : public ChromeRenderViewTest { | 171 class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
| 170 public: | 172 public: |
| 171 PasswordAutofillAgentTest() { | 173 PasswordAutofillAgentTest() { |
| 172 } | 174 } |
| 173 | 175 |
| 174 // Simulates the fill password form message being sent to the renderer. | 176 // Simulates the fill password form message being sent to the renderer. |
| 175 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 177 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
| 176 // protected. | 178 // protected. |
| 177 void SimulateOnFillPasswordForm( | 179 void SimulateOnFillPasswordForm( |
| 178 const PasswordFormFillData& fill_data) { | 180 const PasswordFormFillData& fill_data) { |
| 179 AutofillMsg_FillPasswordForm msg(0, fill_data); | 181 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); |
| 180 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 182 static_cast<content::RenderViewObserver*>(password_autofill_agent_) |
| 181 ->OnMessageReceived(msg); | 183 ->OnMessageReceived(msg); |
| 182 } | 184 } |
| 183 | 185 |
| 184 void SendVisiblePasswordForms() { | 186 void SendVisiblePasswordForms() { |
| 185 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 187 static_cast<content::RenderViewObserver*>(password_autofill_agent_) |
| 186 ->DidFinishLoad(GetMainFrame()); | 188 ->DidFinishLoad(GetMainFrame()); |
| 187 } | 189 } |
| 188 | 190 |
| 189 void SetUp() override { | 191 void SetUp() override { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 421 |
| 420 // Checks the message sent to PasswordAutofillManager to build the suggestion | 422 // Checks the message sent to PasswordAutofillManager to build the suggestion |
| 421 // list. |username| is the expected username field value, and |show_all| is | 423 // list. |username| is the expected username field value, and |show_all| is |
| 422 // the expected flag for the PasswordAutofillManager, whether to show all | 424 // the expected flag for the PasswordAutofillManager, whether to show all |
| 423 // suggestions, or only those starting with |username|. | 425 // suggestions, or only those starting with |username|. |
| 424 void CheckSuggestions(const std::string& username, bool show_all) { | 426 void CheckSuggestions(const std::string& username, bool show_all) { |
| 425 const IPC::Message* message = | 427 const IPC::Message* message = |
| 426 render_thread_->sink().GetFirstMessageMatching( | 428 render_thread_->sink().GetFirstMessageMatching( |
| 427 AutofillHostMsg_ShowPasswordSuggestions::ID); | 429 AutofillHostMsg_ShowPasswordSuggestions::ID); |
| 428 EXPECT_TRUE(message); | 430 EXPECT_TRUE(message); |
| 429 Tuple4<autofill::FormFieldData, base::string16, bool, gfx::RectF> args; | 431 Tuple5<int, base::i18n::TextDirection, base::string16, bool, gfx::RectF> |
| 432 args; |
| 430 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); | 433 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); |
| 431 EXPECT_EQ(2u, fill_data_.basic_data.fields.size()); | 434 EXPECT_EQ(2u, fill_data_.basic_data.fields.size()); |
| 432 EXPECT_EQ(fill_data_.basic_data.fields[0].name, args.a.name); | 435 EXPECT_EQ(kPasswordFillFormDataId, args.a); |
| 433 EXPECT_EQ(ASCIIToUTF16(username), args.a.value); | 436 EXPECT_EQ(ASCIIToUTF16(username), args.c); |
| 434 EXPECT_EQ(ASCIIToUTF16(username), args.b); | 437 EXPECT_EQ(show_all, args.d); |
| 435 EXPECT_EQ(show_all, args.c); | |
| 436 | 438 |
| 437 render_thread_->sink().ClearMessages(); | 439 render_thread_->sink().ClearMessages(); |
| 438 } | 440 } |
| 439 | 441 |
| 440 void ExpectFormSubmittedWithPasswords(const std::string& password_value, | 442 void ExpectFormSubmittedWithPasswords(const std::string& password_value, |
| 441 const std::string& new_password_value) { | 443 const std::string& new_password_value) { |
| 442 const IPC::Message* message = | 444 const IPC::Message* message = |
| 443 render_thread_->sink().GetFirstMessageMatching( | 445 render_thread_->sink().GetFirstMessageMatching( |
| 444 AutofillHostMsg_PasswordFormSubmitted::ID); | 446 AutofillHostMsg_PasswordFormSubmitted::ID); |
| 445 ASSERT_TRUE(message); | 447 ASSERT_TRUE(message); |
| (...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 password_element_, | 1603 password_element_, |
| 1602 /*is_user_input=*/true); | 1604 /*is_user_input=*/true); |
| 1603 | 1605 |
| 1604 // Simulate the user typing a stored username. | 1606 // Simulate the user typing a stored username. |
| 1605 SimulateUsernameChange(kAliceUsername, true); | 1607 SimulateUsernameChange(kAliceUsername, true); |
| 1606 // The autofileld password should replace the typed one. | 1608 // The autofileld password should replace the typed one. |
| 1607 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 1609 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
| 1608 } | 1610 } |
| 1609 | 1611 |
| 1610 } // namespace autofill | 1612 } // namespace autofill |
| OLD | NEW |