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 18 matching lines...) Expand all Loading... |
29 using base::UTF16ToUTF8; | 29 using base::UTF16ToUTF8; |
30 using blink::WebDocument; | 30 using blink::WebDocument; |
31 using blink::WebElement; | 31 using blink::WebElement; |
32 using blink::WebFrame; | 32 using blink::WebFrame; |
33 using blink::WebInputElement; | 33 using blink::WebInputElement; |
34 using blink::WebString; | 34 using blink::WebString; |
35 using blink::WebView; | 35 using blink::WebView; |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
| 39 const int kPasswordFillFormDataId = 1234; |
| 40 |
39 // The name of the username/password element in the form. | 41 // The name of the username/password element in the form. |
40 const char kUsernameName[] = "username"; | 42 const char kUsernameName[] = "username"; |
41 const char kPasswordName[] = "password"; | 43 const char kPasswordName[] = "password"; |
42 | 44 |
43 const char kAliceUsername[] = "alice"; | 45 const char kAliceUsername[] = "alice"; |
44 const char kAlicePassword[] = "password"; | 46 const char kAlicePassword[] = "password"; |
45 const char kBobUsername[] = "bob"; | 47 const char kBobUsername[] = "bob"; |
46 const char kBobPassword[] = "secret"; | 48 const char kBobPassword[] = "secret"; |
47 const char kCarolUsername[] = "Carol"; | 49 const char kCarolUsername[] = "Carol"; |
48 const char kCarolPassword[] = "test"; | 50 const char kCarolPassword[] = "test"; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 class PasswordAutofillAgentTest : public ChromeRenderViewTest { | 170 class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
169 public: | 171 public: |
170 PasswordAutofillAgentTest() { | 172 PasswordAutofillAgentTest() { |
171 } | 173 } |
172 | 174 |
173 // Simulates the fill password form message being sent to the renderer. | 175 // Simulates the fill password form message being sent to the renderer. |
174 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 176 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
175 // protected. | 177 // protected. |
176 void SimulateOnFillPasswordForm( | 178 void SimulateOnFillPasswordForm( |
177 const PasswordFormFillData& fill_data) { | 179 const PasswordFormFillData& fill_data) { |
178 AutofillMsg_FillPasswordForm msg(0, fill_data); | 180 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); |
179 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 181 static_cast<content::RenderViewObserver*>(password_autofill_agent_) |
180 ->OnMessageReceived(msg); | 182 ->OnMessageReceived(msg); |
181 } | 183 } |
182 | 184 |
183 void SendVisiblePasswordForms() { | 185 void SendVisiblePasswordForms() { |
184 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 186 static_cast<content::RenderViewObserver*>(password_autofill_agent_) |
185 ->DidFinishLoad(GetMainFrame()); | 187 ->DidFinishLoad(GetMainFrame()); |
186 } | 188 } |
187 | 189 |
188 void SetUp() override { | 190 void SetUp() override { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 389 |
388 // Checks the message sent to PasswordAutofillManager to build the suggestion | 390 // Checks the message sent to PasswordAutofillManager to build the suggestion |
389 // list. |username| is the expected username field value, and |show_all| is | 391 // list. |username| is the expected username field value, and |show_all| is |
390 // the expected flag for the PasswordAutofillManager, whether to show all | 392 // the expected flag for the PasswordAutofillManager, whether to show all |
391 // suggestions, or only those starting with |username|. | 393 // suggestions, or only those starting with |username|. |
392 void CheckSuggestions(const std::string& username, bool show_all) { | 394 void CheckSuggestions(const std::string& username, bool show_all) { |
393 const IPC::Message* message = | 395 const IPC::Message* message = |
394 render_thread_->sink().GetFirstMessageMatching( | 396 render_thread_->sink().GetFirstMessageMatching( |
395 AutofillHostMsg_ShowPasswordSuggestions::ID); | 397 AutofillHostMsg_ShowPasswordSuggestions::ID); |
396 EXPECT_TRUE(message); | 398 EXPECT_TRUE(message); |
397 Tuple4<autofill::FormFieldData, base::string16, bool, gfx::RectF> args; | 399 Tuple5<int, base::i18n::TextDirection, base::string16, bool, gfx::RectF> |
| 400 args; |
398 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); | 401 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); |
399 EXPECT_EQ(2u, fill_data_.basic_data.fields.size()); | 402 EXPECT_EQ(2u, fill_data_.basic_data.fields.size()); |
400 EXPECT_EQ(fill_data_.basic_data.fields[0].name, args.a.name); | 403 EXPECT_EQ(kPasswordFillFormDataId, args.a); |
401 EXPECT_EQ(ASCIIToUTF16(username), args.a.value); | 404 EXPECT_EQ(ASCIIToUTF16(username), args.c); |
402 EXPECT_EQ(ASCIIToUTF16(username), args.b); | 405 EXPECT_EQ(show_all, args.d); |
403 EXPECT_EQ(show_all, args.c); | |
404 | 406 |
405 render_thread_->sink().ClearMessages(); | 407 render_thread_->sink().ClearMessages(); |
406 } | 408 } |
407 | 409 |
408 void ExpectFormSubmittedWithPasswords(const std::string& password_value, | 410 void ExpectFormSubmittedWithPasswords(const std::string& password_value, |
409 const std::string& new_password_value) { | 411 const std::string& new_password_value) { |
410 const IPC::Message* message = | 412 const IPC::Message* message = |
411 render_thread_->sink().GetFirstMessageMatching( | 413 render_thread_->sink().GetFirstMessageMatching( |
412 AutofillHostMsg_PasswordFormSubmitted::ID); | 414 AutofillHostMsg_PasswordFormSubmitted::ID); |
413 ASSERT_TRUE(message); | 415 ASSERT_TRUE(message); |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 password_element_, | 1514 password_element_, |
1513 /*is_user_input=*/true); | 1515 /*is_user_input=*/true); |
1514 | 1516 |
1515 // Simulate the user typing a stored username. | 1517 // Simulate the user typing a stored username. |
1516 SimulateUsernameChange(kAliceUsername, true); | 1518 SimulateUsernameChange(kAliceUsername, true); |
1517 // The autofileld password should replace the typed one. | 1519 // The autofileld password should replace the typed one. |
1518 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 1520 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
1519 } | 1521 } |
1520 | 1522 |
1521 } // namespace autofill | 1523 } // namespace autofill |
OLD | NEW |