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

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

Issue 2706403003: [Autofill] Fix of crashes caused by show-autofill-signatures flag (Closed)
Patch Set: Added an entry to histograms.xml Created 3 years, 10 months 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 "components/autofill/content/renderer/password_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "base/test/scoped_feature_list.h" 12 #include "base/test/scoped_feature_list.h"
12 #include "chrome/renderer/autofill/fake_content_password_manager_driver.h" 13 #include "chrome/renderer/autofill/fake_content_password_manager_driver.h"
13 #include "chrome/renderer/autofill/fake_password_manager_client.h" 14 #include "chrome/renderer/autofill/fake_password_manager_client.h"
14 #include "chrome/renderer/autofill/password_generation_test_utils.h" 15 #include "chrome/renderer/autofill/password_generation_test_utils.h"
15 #include "chrome/test/base/chrome_render_view_test.h" 16 #include "chrome/test/base/chrome_render_view_test.h"
16 #include "components/autofill/content/renderer/autofill_agent.h" 17 #include "components/autofill/content/renderer/autofill_agent.h"
17 #include "components/autofill/content/renderer/form_autofill_util.h" 18 #include "components/autofill/content/renderer/form_autofill_util.h"
18 #include "components/autofill/content/renderer/test_password_autofill_agent.h" 19 #include "components/autofill/content/renderer/test_password_autofill_agent.h"
19 #include "components/autofill/content/renderer/test_password_generation_agent.h" 20 #include "components/autofill/content/renderer/test_password_generation_agent.h"
20 #include "components/autofill/core/common/autofill_constants.h" 21 #include "components/autofill/core/common/autofill_constants.h"
22 #include "components/autofill/core/common/autofill_switches.h"
21 #include "components/autofill/core/common/form_data.h" 23 #include "components/autofill/core/common/form_data.h"
22 #include "components/autofill/core/common/form_field_data.h" 24 #include "components/autofill/core/common/form_field_data.h"
23 #include "components/autofill/core/common/password_form.h" 25 #include "components/autofill/core/common/password_form.h"
24 #include "components/autofill/core/common/password_form_field_prediction_map.h" 26 #include "components/autofill/core/common/password_form_field_prediction_map.h"
25 #include "components/password_manager/core/common/password_manager_features.h" 27 #include "components/password_manager/core/common/password_manager_features.h"
26 #include "content/public/common/associated_interface_provider.h" 28 #include "content/public/common/associated_interface_provider.h"
27 #include "content/public/renderer/render_frame.h" 29 #include "content/public/renderer/render_frame.h"
28 #include "content/public/renderer/render_view.h" 30 #include "content/public/renderer/render_view.h"
29 #include "services/service_manager/public/cpp/interface_provider.h" 31 #include "services/service_manager/public/cpp/interface_provider.h"
30 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
31 #include "third_party/WebKit/public/platform/WebString.h" 33 #include "third_party/WebKit/public/platform/WebString.h"
32 #include "third_party/WebKit/public/platform/WebVector.h" 34 #include "third_party/WebKit/public/platform/WebVector.h"
33 #include "third_party/WebKit/public/web/WebDocument.h" 35 #include "third_party/WebKit/public/web/WebDocument.h"
34 #include "third_party/WebKit/public/web/WebElement.h" 36 #include "third_party/WebKit/public/web/WebElement.h"
35 #include "third_party/WebKit/public/web/WebFormControlElement.h" 37 #include "third_party/WebKit/public/web/WebFormControlElement.h"
36 #include "third_party/WebKit/public/web/WebFormElement.h" 38 #include "third_party/WebKit/public/web/WebFormElement.h"
37 #include "third_party/WebKit/public/web/WebInputElement.h" 39 #include "third_party/WebKit/public/web/WebInputElement.h"
38 #include "third_party/WebKit/public/web/WebLocalFrame.h" 40 #include "third_party/WebKit/public/web/WebLocalFrame.h"
39 #include "third_party/WebKit/public/web/WebNode.h" 41 #include "third_party/WebKit/public/web/WebNode.h"
40 #include "third_party/WebKit/public/web/WebView.h" 42 #include "third_party/WebKit/public/web/WebView.h"
41 #include "ui/events/keycodes/keyboard_codes.h" 43 #include "ui/events/keycodes/keyboard_codes.h"
42 44
43 using autofill::PasswordForm; 45 using autofill::PasswordForm;
44 using base::ASCIIToUTF16; 46 using base::ASCIIToUTF16;
45 using base::UTF16ToUTF8; 47 using base::UTF16ToUTF8;
46 using blink::WebDocument; 48 using blink::WebDocument;
47 using blink::WebElement; 49 using blink::WebElement;
50 using blink::WebFormElement;
48 using blink::WebFrame; 51 using blink::WebFrame;
49 using blink::WebInputElement; 52 using blink::WebInputElement;
50 using blink::WebString; 53 using blink::WebString;
51 using blink::WebView; 54 using blink::WebView;
52 55
53 namespace { 56 namespace {
54 57
55 const int kPasswordFillFormDataId = 1234; 58 const int kPasswordFillFormDataId = 1234;
56 59
57 // The name of the username/password element in the form. 60 // The name of the username/password element in the form.
58 const char kUsernameName[] = "username"; 61 const char kUsernameName[] = "username";
59 const char kPasswordName[] = "password"; 62 const char kPasswordName[] = "password";
60 const char kEmailName[] = "email"; 63 const char kEmailName[] = "email";
61 const char kCreditCardOwnerName[] = "creditcardowner"; 64 const char kCreditCardOwnerName[] = "creditcardowner";
62 const char kCreditCardNumberName[] = "creditcardnumber"; 65 const char kCreditCardNumberName[] = "creditcardnumber";
63 const char kCreditCardVerificationName[] = "cvc"; 66 const char kCreditCardVerificationName[] = "cvc";
64 67
65 const char kAliceUsername[] = "alice"; 68 const char kAliceUsername[] = "alice";
66 const char kAlicePassword[] = "password"; 69 const char kAlicePassword[] = "password";
67 const char kBobUsername[] = "bob"; 70 const char kBobUsername[] = "bob";
68 const char kBobPassword[] = "secret"; 71 const char kBobPassword[] = "secret";
69 const char kCarolUsername[] = "Carol"; 72 const char kCarolUsername[] = "Carol";
70 const char kCarolPassword[] = "test"; 73 const char kCarolPassword[] = "test";
71 const char kCarolAlternateUsername[] = "RealCarolUsername"; 74 const char kCarolAlternateUsername[] = "RealCarolUsername";
72 75
73 const char kFormHTML[] = 76 const char kFormHTML[] =
74 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" 77 "<FORM id='LoginTestForm' action='http://www.bidule.com'>"
75 " <INPUT type='text' id='random_field'/>" 78 " <INPUT type='text' id='random_field'/>"
76 " <INPUT type='text' id='username'/>" 79 " <INPUT type='text' id='username'/>"
77 " <INPUT type='password' id='password'/>" 80 " <INPUT type='password' id='password'/>"
78 " <INPUT type='submit' value='Login'/>" 81 " <INPUT type='submit' value='Login'/>"
79 "</FORM>"; 82 "</FORM>";
80 83
81 const char kVisibleFormWithNoUsernameHTML[] = 84 const char kVisibleFormWithNoUsernameHTML[] =
82 "<head> <style> form {display: inline;} </style> </head>" 85 "<head> <style> form {display: inline;} </style> </head>"
83 "<body>" 86 "<body>"
84 " <form name='LoginTestForm' action='http://www.bidule.com'>" 87 " <form name='LoginTestForm' action='http://www.bidule.com'>"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 mojom::PasswordManagerClient::Name_, 347 mojom::PasswordManagerClient::Name_,
345 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerClient, 348 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerClient,
346 base::Unretained(this))); 349 base::Unretained(this)));
347 } 350 }
348 351
349 void SetFillOnAccountSelect() { 352 void SetFillOnAccountSelect() {
350 scoped_feature_list_.InitAndEnableFeature( 353 scoped_feature_list_.InitAndEnableFeature(
351 password_manager::features::kFillOnAccountSelect); 354 password_manager::features::kFillOnAccountSelect);
352 } 355 }
353 356
357 void EnableShowAutofillSignatures() {
358 base::CommandLine::ForCurrentProcess()->AppendSwitch(
359 switches::kShowAutofillSignatures);
360 }
361
354 void UpdateOriginForHTML(const std::string& html) { 362 void UpdateOriginForHTML(const std::string& html) {
355 std::string origin = "data:text/html;charset=utf-8," + html; 363 std::string origin = "data:text/html;charset=utf-8," + html;
356 fill_data_.origin = GURL(origin); 364 fill_data_.origin = GURL(origin);
357 } 365 }
358 366
359 void UpdateUsernameAndPasswordElements() { 367 void UpdateUsernameAndPasswordElements() {
360 WebDocument document = GetMainFrame()->document(); 368 WebDocument document = GetMainFrame()->document();
361 WebElement element = 369 WebElement element =
362 document.getElementById(WebString::fromUTF8(kUsernameName)); 370 document.getElementById(WebString::fromUTF8(kUsernameName));
363 ASSERT_FALSE(element.isNull()); 371 ASSERT_FALSE(element.isNull());
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 813
806 SimulateUsernameChange(kAliceUsername); 814 SimulateUsernameChange(kAliceUsername);
807 // Change focus in between to make sure blur events don't trigger filling. 815 // Change focus in between to make sure blur events don't trigger filling.
808 SetFocused(password_element_); 816 SetFocused(password_element_);
809 SetFocused(username_element_); 817 SetFocused(username_element_);
810 // No autocomplete should happen when text is entered in the username. 818 // No autocomplete should happen when text is entered in the username.
811 CheckTextFieldsState(kAliceUsername, false, std::string(), false); 819 CheckTextFieldsState(kAliceUsername, false, std::string(), false);
812 } 820 }
813 821
814 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) { 822 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) {
815 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3; 823 blink::WebVector<WebFormElement> forms1, forms2, forms3;
816 blink::WebFrame* frame; 824 blink::WebFrame* frame;
817 825
818 LoadHTML(kVisibleFormWithNoUsernameHTML); 826 LoadHTML(kVisibleFormWithNoUsernameHTML);
819 frame = GetMainFrame(); 827 frame = GetMainFrame();
820 frame->document().forms(forms1); 828 frame->document().forms(forms1);
821 ASSERT_EQ(1u, forms1.size()); 829 ASSERT_EQ(1u, forms1.size());
822 EXPECT_TRUE(form_util::IsWebNodeVisible(forms1[0])); 830 EXPECT_TRUE(form_util::IsWebNodeVisible(forms1[0]));
823 831
824 LoadHTML(kEmptyFormHTML); 832 LoadHTML(kEmptyFormHTML);
825 frame = GetMainFrame(); 833 frame = GetMainFrame();
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1865 // Tests that field predictions are followed when identifying the username 1873 // Tests that field predictions are followed when identifying the username
1866 // and password in a password form with two plain text fields. 1874 // and password in a password form with two plain text fields.
1867 TEST_F(PasswordAutofillAgentTest, FindingFieldsWithAutofillPredictions) { 1875 TEST_F(PasswordAutofillAgentTest, FindingFieldsWithAutofillPredictions) {
1868 LoadHTML(kFormHTMLWithTwoTextFields); 1876 LoadHTML(kFormHTMLWithTwoTextFields);
1869 UpdateUsernameAndPasswordElements(); 1877 UpdateUsernameAndPasswordElements();
1870 blink::WebInputElement email_element = GetInputElementByID(kEmailName); 1878 blink::WebInputElement email_element = GetInputElementByID(kEmailName);
1871 SimulateUsernameChange("temp"); 1879 SimulateUsernameChange("temp");
1872 SimulateUserInputChangeForElement(&email_element, "temp@google.com"); 1880 SimulateUserInputChangeForElement(&email_element, "temp@google.com");
1873 SimulatePasswordChange("random"); 1881 SimulatePasswordChange("random");
1874 // Find FormData for visible password form. 1882 // Find FormData for visible password form.
1875 blink::WebFormElement form_element = username_element_.form(); 1883 WebFormElement form_element = username_element_.form();
1876 FormData form_data; 1884 FormData form_data;
1877 ASSERT_TRUE(WebFormElementToFormData( 1885 ASSERT_TRUE(WebFormElementToFormData(
1878 form_element, blink::WebFormControlElement(), nullptr, 1886 form_element, blink::WebFormControlElement(), nullptr,
1879 form_util::EXTRACT_NONE, &form_data, nullptr)); 1887 form_util::EXTRACT_NONE, &form_data, nullptr));
1880 // Simulate Autofill predictions: the first field is username, the third 1888 // Simulate Autofill predictions: the first field is username, the third
1881 // one is password. 1889 // one is password.
1882 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; 1890 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions;
1883 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; 1891 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME;
1884 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; 1892 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD;
1885 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( 1893 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived(
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 GetInputElementByID(kCreditCardOwnerName); 2097 GetInputElementByID(kCreditCardOwnerName);
2090 blink::WebInputElement credit_card_number_element = 2098 blink::WebInputElement credit_card_number_element =
2091 GetInputElementByID(kCreditCardNumberName); 2099 GetInputElementByID(kCreditCardNumberName);
2092 blink::WebInputElement credit_card_verification_element = 2100 blink::WebInputElement credit_card_verification_element =
2093 GetInputElementByID(kCreditCardVerificationName); 2101 GetInputElementByID(kCreditCardVerificationName);
2094 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); 2102 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith");
2095 SimulateUserInputChangeForElement(&credit_card_number_element, 2103 SimulateUserInputChangeForElement(&credit_card_number_element,
2096 "1234123412341234"); 2104 "1234123412341234");
2097 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); 2105 SimulateUserInputChangeForElement(&credit_card_verification_element, "123");
2098 // Find FormData for visible form. 2106 // Find FormData for visible form.
2099 blink::WebFormElement form_element = credit_card_number_element.form(); 2107 WebFormElement form_element = credit_card_number_element.form();
2100 FormData form_data; 2108 FormData form_data;
2101 ASSERT_TRUE(WebFormElementToFormData( 2109 ASSERT_TRUE(WebFormElementToFormData(
2102 form_element, blink::WebFormControlElement(), nullptr, 2110 form_element, blink::WebFormControlElement(), nullptr,
2103 form_util::EXTRACT_NONE, &form_data, nullptr)); 2111 form_util::EXTRACT_NONE, &form_data, nullptr));
2104 // Simulate Autofill predictions: the third field is not a password. 2112 // Simulate Autofill predictions: the third field is not a password.
2105 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; 2113 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions;
2106 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; 2114 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD;
2107 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( 2115 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived(
2108 predictions); 2116 predictions);
2109 2117
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 << ", fill_data_username_field_name: " 2286 << ", fill_data_username_field_name: "
2279 << test_case.fill_data_username_field_name 2287 << test_case.fill_data_username_field_name
2280 << ", fill_data_password_field_name: " 2288 << ", fill_data_password_field_name: "
2281 << test_case.fill_data_password_field_name); 2289 << test_case.fill_data_password_field_name);
2282 2290
2283 // Load a password form. 2291 // Load a password form.
2284 LoadHTML(test_case.html_form); 2292 LoadHTML(test_case.html_form);
2285 2293
2286 // Get the username and password form input elelments. 2294 // Get the username and password form input elelments.
2287 blink::WebDocument document = GetMainFrame()->document(); 2295 blink::WebDocument document = GetMainFrame()->document();
2288 blink::WebVector<blink::WebFormElement> forms; 2296 blink::WebVector<WebFormElement> forms;
2289 document.forms(forms); 2297 document.forms(forms);
2290 blink::WebFormElement form_element = forms[0]; 2298 WebFormElement form_element = forms[0];
2291 std::vector<blink::WebFormControlElement> control_elements = 2299 std::vector<blink::WebFormControlElement> control_elements =
2292 form_util::ExtractAutofillableElementsInForm(form_element); 2300 form_util::ExtractAutofillableElementsInForm(form_element);
2293 bool has_fillable_username = 2301 bool has_fillable_username =
2294 (kEmpty != test_case.fill_data_username_field_name); 2302 (kEmpty != test_case.fill_data_username_field_name);
2295 if (has_fillable_username) { 2303 if (has_fillable_username) {
2296 username_element_ = control_elements[0].to<blink::WebInputElement>(); 2304 username_element_ = control_elements[0].to<blink::WebInputElement>();
2297 password_element_ = control_elements[1].to<blink::WebInputElement>(); 2305 password_element_ = control_elements[1].to<blink::WebInputElement>();
2298 } else { 2306 } else {
2299 password_element_ = control_elements[0].to<blink::WebInputElement>(); 2307 password_element_ = control_elements[0].to<blink::WebInputElement>();
2300 } 2308 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 SimulateElementClick("newpassword"); 2461 SimulateElementClick("newpassword");
2454 SimulateElementClick("confirmpassword"); 2462 SimulateElementClick("confirmpassword");
2455 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); 2463 EXPECT_FALSE(GetCalledShowPasswordSuggestions());
2456 2464
2457 // But when the user clicks on the autofilled password field again it should 2465 // But when the user clicks on the autofilled password field again it should
2458 // still produce a suggestion dropdown. 2466 // still produce a suggestion dropdown.
2459 SimulateElementClick("password"); 2467 SimulateElementClick("password");
2460 CheckSuggestions("", false); 2468 CheckSuggestions("", false);
2461 } 2469 }
2462 2470
2471 TEST_F(PasswordAutofillAgentTest, ShowAutofillSignaturesFlag) {
2472 const bool kFalseTrue[] = {false, true};
2473 for (bool show_signatures : kFalseTrue) {
2474 if (show_signatures)
2475 EnableShowAutofillSignatures();
2476
2477 LoadHTML(kFormHTML);
2478 WebDocument document = GetMainFrame()->document();
2479 WebFormElement form_element =
2480 document.getElementById(WebString::fromASCII("LoginTestForm"))
2481 .to<WebFormElement>();
2482 ASSERT_FALSE(form_element.isNull());
2483 FormData form_data;
2484 ASSERT_TRUE(WebFormElementToFormData(
2485 form_element, blink::WebFormControlElement(), nullptr,
2486 form_util::EXTRACT_NONE, &form_data, nullptr));
2487
2488 // Check form signature.
2489 WebString form_signature_attribute =
2490 WebString::fromASCII(kDebugAttributeForFormSignature);
2491 ASSERT_EQ(form_element.hasAttribute(form_signature_attribute),
2492 show_signatures);
2493 if (show_signatures) {
2494 EXPECT_EQ(form_element.getAttribute(form_signature_attribute),
2495 blink::WebString::fromUTF8(
2496 base::Uint64ToString(CalculateFormSignature(form_data))));
2497 }
2498
2499 // Check field signatures.
2500 WebString field_signature_attribute =
2501 WebString::fromASCII(kDebugAttributeForFieldSignature);
2502 blink::WebVector<blink::WebFormControlElement> control_elements;
2503 form_element.getFormControlElements(control_elements);
2504 for (size_t i = 0; i < control_elements.size(); ++i) {
2505 const blink::WebFormControlElement field_element = control_elements[i];
2506 bool expect_signature_for_field =
2507 show_signatures && form_util::IsAutofillableElement(field_element);
2508 ASSERT_EQ(field_element.hasAttribute(field_signature_attribute),
2509 expect_signature_for_field);
2510 if (expect_signature_for_field) {
2511 EXPECT_EQ(field_element.getAttribute(field_signature_attribute),
2512 blink::WebString::fromUTF8(base::Uint64ToString(
2513 CalculateFieldSignatureForField(form_data.fields[i]))));
2514 }
2515 }
2516 }
2517 }
2518
2463 } // namespace autofill 2519 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | components/autofill/content/renderer/password_autofill_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698