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

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 614023002: [Password manager] Relplace the FormFieldData vector from autofill::FormData with named fields… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated nit from Vaclav's review. Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 password1_ = ASCIIToUTF16(kAlicePassword); 195 password1_ = ASCIIToUTF16(kAlicePassword);
196 username2_ = ASCIIToUTF16(kBobUsername); 196 username2_ = ASCIIToUTF16(kBobUsername);
197 password2_ = ASCIIToUTF16(kBobPassword); 197 password2_ = ASCIIToUTF16(kBobPassword);
198 username3_ = ASCIIToUTF16(kCarolUsername); 198 username3_ = ASCIIToUTF16(kCarolUsername);
199 password3_ = ASCIIToUTF16(kCarolPassword); 199 password3_ = ASCIIToUTF16(kCarolPassword);
200 alternate_username3_ = ASCIIToUTF16(kCarolAlternateUsername); 200 alternate_username3_ = ASCIIToUTF16(kCarolAlternateUsername);
201 201
202 FormFieldData username_field; 202 FormFieldData username_field;
203 username_field.name = ASCIIToUTF16(kUsernameName); 203 username_field.name = ASCIIToUTF16(kUsernameName);
204 username_field.value = username1_; 204 username_field.value = username1_;
205 fill_data_.basic_data.fields.push_back(username_field); 205 fill_data_.username_field = username_field;
206 206
207 FormFieldData password_field; 207 FormFieldData password_field;
208 password_field.name = ASCIIToUTF16(kPasswordName); 208 password_field.name = ASCIIToUTF16(kPasswordName);
209 password_field.value = password1_; 209 password_field.value = password1_;
210 password_field.form_control_type = "password"; 210 password_field.form_control_type = "password";
211 fill_data_.basic_data.fields.push_back(password_field); 211 fill_data_.password_field = password_field;
212 212
213 PasswordAndRealm password2; 213 PasswordAndRealm password2;
214 password2.password = password2_; 214 password2.password = password2_;
215 fill_data_.additional_logins[username2_] = password2; 215 fill_data_.additional_logins[username2_] = password2;
216 PasswordAndRealm password3; 216 PasswordAndRealm password3;
217 password3.password = password3_; 217 password3.password = password3_;
218 fill_data_.additional_logins[username3_] = password3; 218 fill_data_.additional_logins[username3_] = password3;
219 219
220 UsernamesCollectionKey key; 220 UsernamesCollectionKey key;
221 key.username = username3_; 221 key.username = username3_;
222 key.password = password3_; 222 key.password = password3_;
223 key.realm = "google.com"; 223 key.realm = "google.com";
224 fill_data_.other_possible_usernames[key].push_back(alternate_username3_); 224 fill_data_.other_possible_usernames[key].push_back(alternate_username3_);
225 225
226 // We need to set the origin so it matches the frame URL and the action so 226 // We need to set the origin so it matches the frame URL and the action so
227 // it matches the form action, otherwise we won't autocomplete. 227 // it matches the form action, otherwise we won't autocomplete.
228 UpdateOriginForHTML(kFormHTML); 228 UpdateOriginForHTML(kFormHTML);
229 fill_data_.basic_data.action = GURL("http://www.bidule.com"); 229 fill_data_.action = GURL("http://www.bidule.com");
230 230
231 LoadHTML(kFormHTML); 231 LoadHTML(kFormHTML);
232 232
233 // Now retrieve the input elements so the test can access them. 233 // Now retrieve the input elements so the test can access them.
234 UpdateUsernameAndPasswordElements(); 234 UpdateUsernameAndPasswordElements();
235 } 235 }
236 236
237 void TearDown() override { 237 void TearDown() override {
238 username_element_.reset(); 238 username_element_.reset();
239 password_element_.reset(); 239 password_element_.reset();
240 ChromeRenderViewTest::TearDown(); 240 ChromeRenderViewTest::TearDown();
241 } 241 }
242 242
243 void UpdateOriginForHTML(const std::string& html) { 243 void UpdateOriginForHTML(const std::string& html) {
244 std::string origin = "data:text/html;charset=utf-8," + html; 244 std::string origin = "data:text/html;charset=utf-8," + html;
245 fill_data_.basic_data.origin = GURL(origin); 245 fill_data_.origin = GURL(origin);
246 } 246 }
247 247
248 void UpdateUsernameAndPasswordElements() { 248 void UpdateUsernameAndPasswordElements() {
249 WebDocument document = GetMainFrame()->document(); 249 WebDocument document = GetMainFrame()->document();
250 WebElement element = 250 WebElement element =
251 document.getElementById(WebString::fromUTF8(kUsernameName)); 251 document.getElementById(WebString::fromUTF8(kUsernameName));
252 ASSERT_FALSE(element.isNull()); 252 ASSERT_FALSE(element.isNull());
253 username_element_ = element.to<blink::WebInputElement>(); 253 username_element_ = element.to<blink::WebInputElement>();
254 element = document.getElementById(WebString::fromUTF8(kPasswordName)); 254 element = document.getElementById(WebString::fromUTF8(kPasswordName));
255 ASSERT_FALSE(element.isNull()); 255 ASSERT_FALSE(element.isNull());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // the expected flag for the PasswordAutofillManager, whether to show all 392 // the expected flag for the PasswordAutofillManager, whether to show all
393 // suggestions, or only those starting with |username|. 393 // suggestions, or only those starting with |username|.
394 void CheckSuggestions(const std::string& username, bool show_all) { 394 void CheckSuggestions(const std::string& username, bool show_all) {
395 const IPC::Message* message = 395 const IPC::Message* message =
396 render_thread_->sink().GetFirstMessageMatching( 396 render_thread_->sink().GetFirstMessageMatching(
397 AutofillHostMsg_ShowPasswordSuggestions::ID); 397 AutofillHostMsg_ShowPasswordSuggestions::ID);
398 EXPECT_TRUE(message); 398 EXPECT_TRUE(message);
399 Tuple5<int, base::i18n::TextDirection, base::string16, bool, gfx::RectF> 399 Tuple5<int, base::i18n::TextDirection, base::string16, bool, gfx::RectF>
400 args; 400 args;
401 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); 401 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args);
402 EXPECT_EQ(2u, fill_data_.basic_data.fields.size());
403 EXPECT_EQ(kPasswordFillFormDataId, args.a); 402 EXPECT_EQ(kPasswordFillFormDataId, args.a);
404 EXPECT_EQ(ASCIIToUTF16(username), args.c); 403 EXPECT_EQ(ASCIIToUTF16(username), args.c);
405 EXPECT_EQ(show_all, args.d); 404 EXPECT_EQ(show_all, args.d);
406 405
407 render_thread_->sink().ClearMessages(); 406 render_thread_->sink().ClearMessages();
408 } 407 }
409 408
410 void ExpectFormSubmittedWithPasswords(const std::string& password_value, 409 void ExpectFormSubmittedWithPasswords(const std::string& password_value,
411 const std::string& new_password_value) { 410 const std::string& new_password_value) {
412 const IPC::Message* message = 411 const IPC::Message* message =
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 WebElement element = 482 WebElement element =
484 document.getElementById(WebString::fromUTF8(kUsernameName)); 483 document.getElementById(WebString::fromUTF8(kUsernameName));
485 ASSERT_FALSE(element.isNull()); 484 ASSERT_FALSE(element.isNull());
486 username_element_ = element.to<blink::WebInputElement>(); 485 username_element_ = element.to<blink::WebInputElement>();
487 element = document.getElementById(WebString::fromUTF8(kPasswordName)); 486 element = document.getElementById(WebString::fromUTF8(kPasswordName));
488 ASSERT_FALSE(element.isNull()); 487 ASSERT_FALSE(element.isNull());
489 password_element_ = element.to<blink::WebInputElement>(); 488 password_element_ = element.to<blink::WebInputElement>();
490 489
491 // Set the expected form origin and action URLs. 490 // Set the expected form origin and action URLs.
492 UpdateOriginForHTML(kEmptyActionFormHTML); 491 UpdateOriginForHTML(kEmptyActionFormHTML);
493 fill_data_.basic_data.action = fill_data_.basic_data.origin; 492 fill_data_.action = fill_data_.origin;
494 493
495 // Simulate the browser sending back the login info, it triggers the 494 // Simulate the browser sending back the login info, it triggers the
496 // autocomplete. 495 // autocomplete.
497 SimulateOnFillPasswordForm(fill_data_); 496 SimulateOnFillPasswordForm(fill_data_);
498 497
499 // The username and password should have been autocompleted. 498 // The username and password should have been autocompleted.
500 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 499 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
501 } 500 }
502 501
503 // Tests that if a password is marked as readonly, neither field is autofilled 502 // Tests that if a password is marked as readonly, neither field is autofilled
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 std::string origin("data:text/html;charset=utf-8,"); 842 std::string origin("data:text/html;charset=utf-8,");
844 origin += kSimpleWebpage; 843 origin += kSimpleWebpage;
845 844
846 std::string page_html(kWebpageWithIframeStart); 845 std::string page_html(kWebpageWithIframeStart);
847 page_html += origin; 846 page_html += origin;
848 page_html += kWebpageWithIframeEnd; 847 page_html += kWebpageWithIframeEnd;
849 848
850 LoadHTML(page_html.c_str()); 849 LoadHTML(page_html.c_str());
851 850
852 // Set the expected form origin and action URLs. 851 // Set the expected form origin and action URLs.
853 fill_data_.basic_data.origin = GURL(origin); 852 fill_data_.origin = GURL(origin);
854 fill_data_.basic_data.action = GURL(origin); 853 fill_data_.action = GURL(origin);
855 854
856 SimulateOnFillPasswordForm(fill_data_); 855 SimulateOnFillPasswordForm(fill_data_);
857 856
858 // Retrieve the input elements from the iframe since that is where we want to 857 // Retrieve the input elements from the iframe since that is where we want to
859 // test the autofill. 858 // test the autofill.
860 WebFrame* iframe = GetMainFrame()->findChildByName(kIframeName); 859 WebFrame* iframe = GetMainFrame()->findChildByName(kIframeName);
861 ASSERT_TRUE(iframe); 860 ASSERT_TRUE(iframe);
862 WebDocument document = iframe->document(); 861 WebDocument document = iframe->document();
863 862
864 WebElement username_element = document.getElementById(kUsernameName); 863 WebElement username_element = document.getElementById(kUsernameName);
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 password_element_, 1513 password_element_,
1515 /*is_user_input=*/true); 1514 /*is_user_input=*/true);
1516 1515
1517 // Simulate the user typing a stored username. 1516 // Simulate the user typing a stored username.
1518 SimulateUsernameChange(kAliceUsername, true); 1517 SimulateUsernameChange(kAliceUsername, true);
1519 // The autofileld password should replace the typed one. 1518 // The autofileld password should replace the typed one.
1520 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1519 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1521 } 1520 }
1522 1521
1523 } // namespace autofill 1522 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698