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

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

Issue 1153023004: Prepare the infrastructure for password overrides. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the test. Created 5 years, 6 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
« no previous file with comments | « no previous file | components/autofill.gypi » ('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"
11 #include "components/autofill/content/renderer/password_autofill_agent.h" 11 #include "components/autofill/content/renderer/password_autofill_agent.h"
12 #include "components/autofill/content/renderer/test_password_autofill_agent.h" 12 #include "components/autofill/content/renderer/test_password_autofill_agent.h"
13 #include "components/autofill/core/common/autofill_constants.h" 13 #include "components/autofill/core/common/autofill_constants.h"
14 #include "components/autofill/core/common/autofill_switches.h" 14 #include "components/autofill/core/common/autofill_switches.h"
15 #include "components/autofill/core/common/form_data.h" 15 #include "components/autofill/core/common/form_data.h"
16 #include "components/autofill/core/common/form_field_data.h" 16 #include "components/autofill/core/common/form_field_data.h"
17 #include "components/autofill/core/common/password_form_field_prediction_map.h"
17 #include "content/public/renderer/render_frame.h" 18 #include "content/public/renderer/render_frame.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/platform/WebString.h" 20 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/platform/WebVector.h" 21 #include "third_party/WebKit/public/platform/WebVector.h"
21 #include "third_party/WebKit/public/web/WebDocument.h" 22 #include "third_party/WebKit/public/web/WebDocument.h"
22 #include "third_party/WebKit/public/web/WebElement.h" 23 #include "third_party/WebKit/public/web/WebElement.h"
23 #include "third_party/WebKit/public/web/WebFormControlElement.h" 24 #include "third_party/WebKit/public/web/WebFormControlElement.h"
24 #include "third_party/WebKit/public/web/WebFormElement.h" 25 #include "third_party/WebKit/public/web/WebFormElement.h"
25 #include "third_party/WebKit/public/web/WebInputElement.h" 26 #include "third_party/WebKit/public/web/WebInputElement.h"
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" 27 #include "third_party/WebKit/public/web/WebLocalFrame.h"
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1811 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1811 ->WillSendSubmitEvent(username_element_.form()); 1812 ->WillSendSubmitEvent(username_element_.form());
1812 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1813 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1813 ->WillSubmitForm(username_element_.form()); 1814 ->WillSubmitForm(username_element_.form());
1814 1815
1815 // Observe that the PasswordAutofillAgent identifies the second field (e-mail) 1816 // Observe that the PasswordAutofillAgent identifies the second field (e-mail)
1816 // as username. 1817 // as username.
1817 ExpectFormSubmittedWithUsernameAndPasswords("temp@google.com", "random", ""); 1818 ExpectFormSubmittedWithUsernameAndPasswords("temp@google.com", "random", "");
1818 } 1819 }
1819 1820
1820 // Tests that username predictions are followed when identifying the username 1821 // Tests that field predictions are followed when identifying the username
1821 // in a password form with two plain text fields. 1822 // and password in a password form with two plain text fields.
1822 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithAutofillPredictions) { 1823 TEST_F(PasswordAutofillAgentTest, FindingFieldsWithAutofillPredictions) {
1823 LoadHTML(kFormHTMLWithTwoTextFields); 1824 LoadHTML(kFormHTMLWithTwoTextFields);
1824 UpdateUsernameAndPasswordElements(); 1825 UpdateUsernameAndPasswordElements();
1825 blink::WebInputElement email_element = GetInputElementByID(kEmailName); 1826 blink::WebInputElement email_element = GetInputElementByID(kEmailName);
1826 SimulateUsernameChange("temp"); 1827 SimulateUsernameChange("temp");
1827 SimulateUserInputChangeForElement(&email_element, "temp@google.com"); 1828 SimulateUserInputChangeForElement(&email_element, "temp@google.com");
1828 SimulatePasswordChange("random"); 1829 SimulatePasswordChange("random");
1829 // Find FormData for visible password form. 1830 // Find FormData for visible password form.
1830 blink::WebFormElement form_element = username_element_.form(); 1831 blink::WebFormElement form_element = username_element_.form();
1831 FormData form_data; 1832 FormData form_data;
1832 ASSERT_TRUE(WebFormElementToFormData(form_element, 1833 ASSERT_TRUE(WebFormElementToFormData(form_element,
1833 blink::WebFormControlElement(), 1834 blink::WebFormControlElement(),
1834 EXTRACT_NONE, &form_data, nullptr)); 1835 EXTRACT_NONE, &form_data, nullptr));
1835 // Simulate Autofill predictions: the first field is username. 1836 // Simulate Autofill predictions: the first field is username, the third
1836 std::map<autofill::FormData, autofill::FormFieldData> predictions; 1837 // one is password.
1837 predictions[form_data] = form_data.fields[0]; 1838 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions;
1838 AutofillMsg_AutofillUsernameDataReceived msg(0, predictions); 1839 predictions[form_data][PREDICTION_USERNAME] = form_data.fields[0];
1840 predictions[form_data][PREDICTION_NEW_PASSWORD] = form_data.fields[2];
1841 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions);
1839 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1842 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1840 ->OnMessageReceived(msg); 1843 ->OnMessageReceived(msg);
1841 1844
1842 // The prediction should still match even if the form changes, as long 1845 // The predictions should still match even if the form changes, as long
1843 // as the particular element doesn't change. 1846 // as the particular elements don't change.
1844 std::string add_field_to_form = 1847 std::string add_field_to_form =
1845 "var form = document.getElementById('LoginTestForm');" 1848 "var form = document.getElementById('LoginTestForm');"
1846 "var new_input = document.createElement('input');" 1849 "var new_input = document.createElement('input');"
1847 "new_input.setAttribute('type', 'text');" 1850 "new_input.setAttribute('type', 'text');"
1848 "new_input.setAttribute('id', 'other_field');" 1851 "new_input.setAttribute('id', 'other_field');"
1849 "form.appendChild(new_input);"; 1852 "form.appendChild(new_input);";
1850 ExecuteJavaScript(add_field_to_form.c_str()); 1853 ExecuteJavaScript(add_field_to_form.c_str());
1851 1854
1852 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1855 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1853 ->WillSendSubmitEvent(username_element_.form()); 1856 ->WillSendSubmitEvent(username_element_.form());
1854 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1857 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1855 ->WillSubmitForm(username_element_.form()); 1858 ->WillSubmitForm(username_element_.form());
1856 1859
1857 // Observe that the PasswordAutofillAgent identifies the first field as 1860 // Observe that the PasswordAutofillAgent identifies the first field as
1858 // username. 1861 // username.
1862 // TODO(msramek): We should also test that adding another password field
1863 // won't override the password field prediction either. However, the password
1864 // field predictions are not taken into account yet.
1859 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); 1865 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", "");
1860 } 1866 }
1861 1867
1862 // The user types in a username and a password. Then JavaScript changes password 1868 // The user types in a username and a password. Then JavaScript changes password
1863 // field to readonly state before submit. PasswordAutofillAgent can correctly 1869 // field to readonly state before submit. PasswordAutofillAgent can correctly
1864 // process readonly password field. This test models behaviour of gmail.com. 1870 // process readonly password field. This test models behaviour of gmail.com.
1865 TEST_F(PasswordAutofillAgentTest, ReadonlyPasswordFieldOnSubmit) { 1871 TEST_F(PasswordAutofillAgentTest, ReadonlyPasswordFieldOnSubmit) {
1866 SimulateUsernameChange("temp"); 1872 SimulateUsernameChange("temp");
1867 SimulatePasswordChange("random"); 1873 SimulatePasswordChange("random");
1868 1874
1869 // Simulate that JavaScript makes password field readonly. 1875 // Simulate that JavaScript makes password field readonly.
1870 SetElementReadOnly(password_element_, true); 1876 SetElementReadOnly(password_element_, true);
1871 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1877 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1872 ->WillSubmitForm(username_element_.form()); 1878 ->WillSubmitForm(username_element_.form());
1873 1879
1874 // Observe that the PasswordAutofillAgent can correctly process submitted 1880 // Observe that the PasswordAutofillAgent can correctly process submitted
1875 // form. 1881 // form.
1876 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); 1882 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", "");
1877 } 1883 }
1878 1884
1879 } // namespace autofill 1885 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698