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

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 Vaclav's review comments. 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
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 password1_ = ASCIIToUTF16(kAlicePassword); 194 password1_ = ASCIIToUTF16(kAlicePassword);
195 username2_ = ASCIIToUTF16(kBobUsername); 195 username2_ = ASCIIToUTF16(kBobUsername);
196 password2_ = ASCIIToUTF16(kBobPassword); 196 password2_ = ASCIIToUTF16(kBobPassword);
197 username3_ = ASCIIToUTF16(kCarolUsername); 197 username3_ = ASCIIToUTF16(kCarolUsername);
198 password3_ = ASCIIToUTF16(kCarolPassword); 198 password3_ = ASCIIToUTF16(kCarolPassword);
199 alternate_username3_ = ASCIIToUTF16(kCarolAlternateUsername); 199 alternate_username3_ = ASCIIToUTF16(kCarolAlternateUsername);
200 200
201 FormFieldData username_field; 201 FormFieldData username_field;
202 username_field.name = ASCIIToUTF16(kUsernameName); 202 username_field.name = ASCIIToUTF16(kUsernameName);
203 username_field.value = username1_; 203 username_field.value = username1_;
204 fill_data_.basic_data.fields.push_back(username_field); 204 fill_data_.username_field = username_field;
205 205
206 FormFieldData password_field; 206 FormFieldData password_field;
207 password_field.name = ASCIIToUTF16(kPasswordName); 207 password_field.name = ASCIIToUTF16(kPasswordName);
208 password_field.value = password1_; 208 password_field.value = password1_;
209 password_field.form_control_type = "password"; 209 password_field.form_control_type = "password";
210 fill_data_.basic_data.fields.push_back(password_field); 210 fill_data_.password_field = password_field;
211 211
212 PasswordAndRealm password2; 212 PasswordAndRealm password2;
213 password2.password = password2_; 213 password2.password = password2_;
214 fill_data_.additional_logins[username2_] = password2; 214 fill_data_.additional_logins[username2_] = password2;
215 PasswordAndRealm password3; 215 PasswordAndRealm password3;
216 password3.password = password3_; 216 password3.password = password3_;
217 fill_data_.additional_logins[username3_] = password3; 217 fill_data_.additional_logins[username3_] = password3;
218 218
219 UsernamesCollectionKey key; 219 UsernamesCollectionKey key;
220 key.username = username3_; 220 key.username = username3_;
221 key.password = password3_; 221 key.password = password3_;
222 key.realm = "google.com"; 222 key.realm = "google.com";
223 fill_data_.other_possible_usernames[key].push_back(alternate_username3_); 223 fill_data_.other_possible_usernames[key].push_back(alternate_username3_);
224 224
225 // We need to set the origin so it matches the frame URL and the action so 225 // We need to set the origin so it matches the frame URL and the action so
226 // it matches the form action, otherwise we won't autocomplete. 226 // it matches the form action, otherwise we won't autocomplete.
227 UpdateOriginForHTML(kFormHTML); 227 UpdateOriginForHTML(kFormHTML);
228 fill_data_.basic_data.action = GURL("http://www.bidule.com"); 228 fill_data_.action = GURL("http://www.bidule.com");
229 229
230 LoadHTML(kFormHTML); 230 LoadHTML(kFormHTML);
231 231
232 // Now retrieve the input elements so the test can access them. 232 // Now retrieve the input elements so the test can access them.
233 UpdateUsernameAndPasswordElements(); 233 UpdateUsernameAndPasswordElements();
234 } 234 }
235 235
236 void TearDown() override { 236 void TearDown() override {
237 username_element_.reset(); 237 username_element_.reset();
238 password_element_.reset(); 238 password_element_.reset();
239 ChromeRenderViewTest::TearDown(); 239 ChromeRenderViewTest::TearDown();
240 } 240 }
241 241
242 void UpdateOriginForHTML(const std::string& html) { 242 void UpdateOriginForHTML(const std::string& html) {
243 std::string origin = "data:text/html;charset=utf-8," + html; 243 std::string origin = "data:text/html;charset=utf-8," + html;
244 fill_data_.basic_data.origin = GURL(origin); 244 fill_data_.origin = GURL(origin);
245 } 245 }
246 246
247 void UpdateUsernameAndPasswordElements() { 247 void UpdateUsernameAndPasswordElements() {
248 WebDocument document = GetMainFrame()->document(); 248 WebDocument document = GetMainFrame()->document();
249 WebElement element = 249 WebElement element =
250 document.getElementById(WebString::fromUTF8(kUsernameName)); 250 document.getElementById(WebString::fromUTF8(kUsernameName));
251 ASSERT_FALSE(element.isNull()); 251 ASSERT_FALSE(element.isNull());
252 username_element_ = element.to<blink::WebInputElement>(); 252 username_element_ = element.to<blink::WebInputElement>();
253 element = document.getElementById(WebString::fromUTF8(kPasswordName)); 253 element = document.getElementById(WebString::fromUTF8(kPasswordName));
254 ASSERT_FALSE(element.isNull()); 254 ASSERT_FALSE(element.isNull());
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 WebElement element = 538 WebElement element =
539 document.getElementById(WebString::fromUTF8(kUsernameName)); 539 document.getElementById(WebString::fromUTF8(kUsernameName));
540 ASSERT_FALSE(element.isNull()); 540 ASSERT_FALSE(element.isNull());
541 username_element_ = element.to<blink::WebInputElement>(); 541 username_element_ = element.to<blink::WebInputElement>();
542 element = document.getElementById(WebString::fromUTF8(kPasswordName)); 542 element = document.getElementById(WebString::fromUTF8(kPasswordName));
543 ASSERT_FALSE(element.isNull()); 543 ASSERT_FALSE(element.isNull());
544 password_element_ = element.to<blink::WebInputElement>(); 544 password_element_ = element.to<blink::WebInputElement>();
545 545
546 // Set the expected form origin and action URLs. 546 // Set the expected form origin and action URLs.
547 UpdateOriginForHTML(kEmptyActionFormHTML); 547 UpdateOriginForHTML(kEmptyActionFormHTML);
548 fill_data_.basic_data.action = fill_data_.basic_data.origin; 548 fill_data_.action = fill_data_.origin;
549 549
550 // Simulate the browser sending back the login info, it triggers the 550 // Simulate the browser sending back the login info, it triggers the
551 // autocomplete. 551 // autocomplete.
552 SimulateOnFillPasswordForm(fill_data_); 552 SimulateOnFillPasswordForm(fill_data_);
553 553
554 // The username and password should have been autocompleted. 554 // The username and password should have been autocompleted.
555 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 555 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
556 } 556 }
557 557
558 // Tests that if a password is marked as readonly, neither field is autofilled 558 // 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
898 std::string origin("data:text/html;charset=utf-8,"); 898 std::string origin("data:text/html;charset=utf-8,");
899 origin += kSimpleWebpage; 899 origin += kSimpleWebpage;
900 900
901 std::string page_html(kWebpageWithIframeStart); 901 std::string page_html(kWebpageWithIframeStart);
902 page_html += origin; 902 page_html += origin;
903 page_html += kWebpageWithIframeEnd; 903 page_html += kWebpageWithIframeEnd;
904 904
905 LoadHTML(page_html.c_str()); 905 LoadHTML(page_html.c_str());
906 906
907 // Set the expected form origin and action URLs. 907 // Set the expected form origin and action URLs.
908 fill_data_.basic_data.origin = GURL(origin); 908 fill_data_.origin = GURL(origin);
909 fill_data_.basic_data.action = GURL(origin); 909 fill_data_.action = GURL(origin);
910 910
911 SimulateOnFillPasswordForm(fill_data_); 911 SimulateOnFillPasswordForm(fill_data_);
912 912
913 // Retrieve the input elements from the iframe since that is where we want to 913 // Retrieve the input elements from the iframe since that is where we want to
914 // test the autofill. 914 // test the autofill.
915 WebFrame* iframe = GetMainFrame()->findChildByName(kIframeName); 915 WebFrame* iframe = GetMainFrame()->findChildByName(kIframeName);
916 ASSERT_TRUE(iframe); 916 ASSERT_TRUE(iframe);
917 WebDocument document = iframe->document(); 917 WebDocument document = iframe->document();
918 918
919 WebElement username_element = document.getElementById(kUsernameName); 919 WebElement username_element = document.getElementById(kUsernameName);
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 password_element_, 1631 password_element_,
1632 /*is_user_input=*/true); 1632 /*is_user_input=*/true);
1633 1633
1634 // Simulate the user typing a stored username. 1634 // Simulate the user typing a stored username.
1635 SimulateUsernameChange(kAliceUsername, true); 1635 SimulateUsernameChange(kAliceUsername, true);
1636 // The autofileld password should replace the typed one. 1636 // The autofileld password should replace the typed one.
1637 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1637 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1638 } 1638 }
1639 1639
1640 } // namespace autofill 1640 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698