Index: components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc |
diff --git a/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc b/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc |
index 46969b4e4775c8e99197c9d69081c6852f049b9e..dc790c1df82697a7bd95269b876eadda270f9d62 100644 |
--- a/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc |
+++ b/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc |
@@ -49,7 +49,7 @@ class PasswordFormBuilder { |
// Appends a new text-type field at the end of the form, having the specified |
// |name_and_id|, |value|, and |autocomplete| attributes. The |autocomplete| |
// argument can take two special values, namely: |
- // 1.) NULL, causing no autocomplete attribute to be added, |
+ // 1.) nullptr, causing no autocomplete attribute to be added, |
// 2.) "", causing an empty attribute (i.e. autocomplete="") to be added. |
void AddTextField(const char* name_and_id, |
const char* value, |
@@ -167,24 +167,29 @@ class MAYBE_PasswordFormConversionUtilsTest : public content::RenderViewTest { |
protected: |
// Loads the given |html|, retrieves the sole WebFormElement from it, and then |
- // calls CreatePasswordForm(), passing it the |predictions| to convert it into |
- // a |password_form|. Note that ASSERT() can only be used in void functions, |
- // this is why |password_form| is passed in as a pointer to a scoped_ptr. |
- void LoadHTMLAndConvertForm(const std::string& html, |
- std::unique_ptr<PasswordForm>* password_form, |
- FormsPredictionsMap* predictions) { |
+ // calls CreatePasswordForm(), passing it the |predictions| to convert it to |
+ // a PasswordForm. If |with_user_input| == true it's considered that all |
+ // values in the form elements came from the user input. |
+ std::unique_ptr<PasswordForm> LoadHTMLAndConvertForm( |
+ const std::string& html, |
+ FormsPredictionsMap* predictions, |
+ bool with_user_input) { |
WebFormElement form; |
LoadWebFormFromHTML(html, &form); |
WebVector<WebFormControlElement> control_elements; |
form.getFormControlElements(control_elements); |
+ ModifiedValues user_input; |
for (size_t i = 0; i < control_elements.size(); ++i) { |
WebInputElement* input_element = toWebInputElement(&control_elements[i]); |
if (input_element->hasAttribute("set-activated-submit")) |
input_element->setActivatedSubmit(true); |
+ if (with_user_input) |
+ user_input[*input_element] = input_element->value(); |
} |
- *password_form = CreatePasswordFormFromWebForm(form, nullptr, predictions); |
+ return CreatePasswordFormFromWebForm( |
+ form, with_user_input ? &user_input : nullptr, predictions); |
} |
// Iterates on the form generated by the |html| and adds the fields and type |
@@ -237,16 +242,15 @@ class MAYBE_PasswordFormConversionUtilsTest : public content::RenderViewTest { |
TEST_F(MAYBE_PasswordFormConversionUtilsTest, BasicFormAttributes) { |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddTextField("username", "johnsmith", NULL); |
+ builder.AddTextField("username", "johnsmith", nullptr); |
builder.AddSubmitButton("inactive_submit"); |
builder.AddSubmitButton("active_submit"); |
builder.AddSubmitButton("inactive_submit2"); |
- builder.AddPasswordField("password", "secret", NULL); |
+ builder.AddPasswordField("password", "secret", nullptr); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ("data:", password_form->signon_realm); |
@@ -264,16 +268,15 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, BasicFormAttributes) { |
TEST_F(MAYBE_PasswordFormConversionUtilsTest, DisabledFieldsAreIgnored) { |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddTextField("username", "johnsmith", NULL); |
+ builder.AddTextField("username", "johnsmith", nullptr); |
builder.AddDisabledUsernameField(); |
builder.AddDisabledPasswordField(); |
- builder.AddPasswordField("password", "secret", NULL); |
+ builder.AddPasswordField("password", "secret", nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
@@ -293,18 +296,20 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { |
// When no elements are marked with autocomplete='username', the text-type |
// input field before the first password element should get selected as |
// the username, and the rest should be marked as alternatives. |
- {{NULL, NULL, NULL}, "username2", "William", "John+Smith"}, |
+ {{nullptr, nullptr, nullptr}, "username2", "William", "John+Smith"}, |
// When a sole element is marked with autocomplete='username', it should |
// be treated as the username for sure, with no other_possible_usernames. |
- {{"username", NULL, NULL}, "username1", "John", ""}, |
- {{NULL, "username", NULL}, "username2", "William", ""}, |
- {{NULL, NULL, "username"}, "username3", "Smith", ""}, |
+ {{"username", nullptr, nullptr}, "username1", "John", ""}, |
+ {{nullptr, "username", nullptr}, "username2", "William", ""}, |
+ {{nullptr, nullptr, "username"}, "username3", "Smith", ""}, |
// When >=2 elements have the attribute, the first should be selected as |
// the username, and the rest should go to other_possible_usernames. |
- {{"username", "username", NULL}, "username1", "John", "William"}, |
- {{NULL, "username", "username"}, "username2", "William", "Smith"}, |
- {{"username", NULL, "username"}, "username1", "John", "Smith"}, |
- {{"username", "username", "username"}, "username1", "John", |
+ {{"username", "username", nullptr}, "username1", "John", "William"}, |
+ {{nullptr, "username", "username"}, "username2", "William", "Smith"}, |
+ {{"username", nullptr, "username"}, "username1", "John", "Smith"}, |
+ {{"username", "username", "username"}, |
+ "username1", |
+ "John", |
"William+Smith"}, |
// When there is an empty autocomplete attribute (i.e. autocomplete=""), |
// it should have the same effect as having no attribute whatsoever. |
@@ -312,8 +317,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { |
{{"", "", "username"}, "username3", "Smith", ""}, |
{{"username", "", "username"}, "username1", "John", "Smith"}, |
// It should not matter if attribute values are upper or mixed case. |
- {{"USERNAME", NULL, "uSeRNaMe"}, "username1", "John", "Smith"}, |
- {{"uSeRNaMe", NULL, "USERNAME"}, "username1", "John", "Smith"}}; |
+ {{"USERNAME", nullptr, "uSeRNaMe"}, "username1", "John", "Smith"}, |
+ {{"uSeRNaMe", nullptr, "USERNAME"}, "username1", "John", "Smith"}}; |
for (size_t i = 0; i < arraysize(cases); ++i) { |
for (size_t nonempty_username_fields = 0; nonempty_username_fields < 2; |
@@ -336,15 +341,14 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { |
PasswordFormBuilder builder(kTestFormActionURL); |
builder.AddTextField("username1", names[0], cases[i].autocomplete[0]); |
builder.AddTextField("username2", names[1], cases[i].autocomplete[1]); |
- builder.AddPasswordField("password", "secret", NULL); |
+ builder.AddPasswordField("password", "secret", nullptr); |
builder.AddTextField("username3", names[2], cases[i].autocomplete[2]); |
- builder.AddPasswordField("password2", "othersecret", NULL); |
+ builder.AddPasswordField("password2", "othersecret", nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), |
@@ -395,16 +399,15 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingTwoPasswordFields) { |
SCOPED_TRACE(testing::Message() << "Iteration " << i); |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddTextField("username1", "William", NULL); |
- builder.AddPasswordField("password1", cases[i].password_values[0], NULL); |
- builder.AddTextField("username2", "Smith", NULL); |
- builder.AddPasswordField("password2", cases[i].password_values[1], NULL); |
+ builder.AddTextField("username1", "William", nullptr); |
+ builder.AddPasswordField("password1", cases[i].password_values[0], nullptr); |
+ builder.AddTextField("username2", "Smith", nullptr); |
+ builder.AddPasswordField("password2", cases[i].password_values[1], nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), |
@@ -456,17 +459,16 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingThreePasswordFields) { |
SCOPED_TRACE(testing::Message() << "Iteration " << i); |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddTextField("username1", "William", NULL); |
- builder.AddPasswordField("password1", cases[i].password_values[0], NULL); |
- builder.AddPasswordField("password2", cases[i].password_values[1], NULL); |
- builder.AddTextField("username2", "Smith", NULL); |
- builder.AddPasswordField("password3", cases[i].password_values[2], NULL); |
+ builder.AddTextField("username1", "William", nullptr); |
+ builder.AddPasswordField("password1", cases[i].password_values[0], nullptr); |
+ builder.AddPasswordField("password2", cases[i].password_values[1], nullptr); |
+ builder.AddTextField("username2", "Smith", nullptr); |
+ builder.AddPasswordField("password3", cases[i].password_values[2], nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), |
@@ -509,105 +511,320 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
// Username is the element just before the first 'current-password' (even |
// if 'new-password' comes earlier). If no 'current-password', then the |
// element just before the first 'new-passwords'. |
- {{"current-password", NULL, NULL}, |
- "password1", "alpha", "", "", false, "username1", "William"}, |
- {{NULL, "current-password", NULL}, |
- "password2", "beta", "", "", false, "username2", "Smith"}, |
- {{NULL, NULL, "current-password"}, |
- "password3", "gamma", "", "", false, "username2", "Smith"}, |
- {{NULL, "current-password", "current-password"}, |
- "password2", "beta", "", "", false, "username2", "Smith"}, |
- {{"current-password", NULL, "current-password"}, |
- "password1", "alpha", "", "", false, "username1", "William"}, |
- {{"current-password", "current-password", NULL}, |
- "password1", "alpha", "", "", false, "username1", "William"}, |
+ {{"current-password", nullptr, nullptr}, |
+ "password1", |
+ "alpha", |
+ "", |
+ "", |
+ false, |
+ "username1", |
+ "William"}, |
+ {{nullptr, "current-password", nullptr}, |
+ "password2", |
+ "beta", |
+ "", |
+ "", |
+ false, |
+ "username2", |
+ "Smith"}, |
+ {{nullptr, nullptr, "current-password"}, |
+ "password3", |
+ "gamma", |
+ "", |
+ "", |
+ false, |
+ "username2", |
+ "Smith"}, |
+ {{nullptr, "current-password", "current-password"}, |
+ "password2", |
+ "beta", |
+ "", |
+ "", |
+ false, |
+ "username2", |
+ "Smith"}, |
+ {{"current-password", nullptr, "current-password"}, |
+ "password1", |
+ "alpha", |
+ "", |
+ "", |
+ false, |
+ "username1", |
+ "William"}, |
+ {{"current-password", "current-password", nullptr}, |
+ "password1", |
+ "alpha", |
+ "", |
+ "", |
+ false, |
+ "username1", |
+ "William"}, |
{{"current-password", "current-password", "current-password"}, |
- "password1", "alpha", "", "", false, "username1", "William"}, |
+ "password1", |
+ "alpha", |
+ "", |
+ "", |
+ false, |
+ "username1", |
+ "William"}, |
// The same goes vice versa for autocomplete='new-password'. |
- {{"new-password", NULL, NULL}, |
- "", "", "password1", "alpha", true, "username1", "William"}, |
- {{NULL, "new-password", NULL}, |
- "", "", "password2", "beta", true, "username2", "Smith"}, |
- {{NULL, NULL, "new-password"}, |
- "", "", "password3", "gamma", true, "username2", "Smith"}, |
- {{NULL, "new-password", "new-password"}, |
- "", "", "password2", "beta", true, "username2", "Smith"}, |
- {{"new-password", NULL, "new-password"}, |
- "", "", "password1", "alpha", true, "username1", "William"}, |
- {{"new-password", "new-password", NULL}, |
- "", "", "password1", "alpha", true, "username1", "William"}, |
+ {{"new-password", nullptr, nullptr}, |
+ "", |
+ "", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username1", |
+ "William"}, |
+ {{nullptr, "new-password", nullptr}, |
+ "", |
+ "", |
+ "password2", |
+ "beta", |
+ true, |
+ "username2", |
+ "Smith"}, |
+ {{nullptr, nullptr, "new-password"}, |
+ "", |
+ "", |
+ "password3", |
+ "gamma", |
+ true, |
+ "username2", |
+ "Smith"}, |
+ {{nullptr, "new-password", "new-password"}, |
+ "", |
+ "", |
+ "password2", |
+ "beta", |
+ true, |
+ "username2", |
+ "Smith"}, |
+ {{"new-password", nullptr, "new-password"}, |
+ "", |
+ "", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username1", |
+ "William"}, |
+ {{"new-password", "new-password", nullptr}, |
+ "", |
+ "", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username1", |
+ "William"}, |
{{"new-password", "new-password", "new-password"}, |
- "", "", "password1", "alpha", true, "username1", "William"}, |
+ "", |
+ "", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username1", |
+ "William"}, |
// When there is one element marked with autocomplete='current-password', |
// and one with 'new-password', just comply. Ignore the unmarked password |
// field(s) for the same reason as above. |
- {{"current-password", "new-password", NULL}, |
- "password1", "alpha", "password2", "beta", true, "username1", "William"}, |
- {{"current-password", NULL, "new-password"}, |
- "password1", "alpha", "password3", "gamma", true, "username1","William"}, |
- {{NULL, "current-password", "new-password"}, |
- "password2", "beta", "password3", "gamma", true, "username2", "Smith"}, |
- {{"new-password", "current-password", NULL}, |
- "password2", "beta", "password1", "alpha", true, "username2", "Smith"}, |
- {{"new-password", NULL, "current-password"}, |
- "password3", "gamma", "password1", "alpha", true, "username2","Smith"}, |
- {{NULL, "new-password", "current-password"}, |
- "password3", "gamma", "password2", "beta", true, "username2", "Smith"}, |
+ {{"current-password", "new-password", nullptr}, |
+ "password1", |
+ "alpha", |
+ "password2", |
+ "beta", |
+ true, |
+ "username1", |
+ "William"}, |
+ {{"current-password", nullptr, "new-password"}, |
+ "password1", |
+ "alpha", |
+ "password3", |
+ "gamma", |
+ true, |
+ "username1", |
+ "William"}, |
+ {{nullptr, "current-password", "new-password"}, |
+ "password2", |
+ "beta", |
+ "password3", |
+ "gamma", |
+ true, |
+ "username2", |
+ "Smith"}, |
+ {{"new-password", "current-password", nullptr}, |
+ "password2", |
+ "beta", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username2", |
+ "Smith"}, |
+ {{"new-password", nullptr, "current-password"}, |
+ "password3", |
+ "gamma", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username2", |
+ "Smith"}, |
+ {{nullptr, "new-password", "current-password"}, |
+ "password3", |
+ "gamma", |
+ "password2", |
+ "beta", |
+ true, |
+ "username2", |
+ "Smith"}, |
// In case of duplicated elements of either kind, go with the first one of |
// its kind. |
{{"current-password", "current-password", "new-password"}, |
- "password1", "alpha", "password3", "gamma", true, "username1","William"}, |
+ "password1", |
+ "alpha", |
+ "password3", |
+ "gamma", |
+ true, |
+ "username1", |
+ "William"}, |
{{"current-password", "new-password", "current-password"}, |
- "password1", "alpha", "password2", "beta", true, "username1", "William"}, |
+ "password1", |
+ "alpha", |
+ "password2", |
+ "beta", |
+ true, |
+ "username1", |
+ "William"}, |
{{"new-password", "current-password", "current-password"}, |
- "password2", "beta", "password1", "alpha", true, "username2", "Smith"}, |
+ "password2", |
+ "beta", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username2", |
+ "Smith"}, |
{{"current-password", "new-password", "new-password"}, |
- "password1", "alpha", "password2", "beta", true, "username1", "William"}, |
+ "password1", |
+ "alpha", |
+ "password2", |
+ "beta", |
+ true, |
+ "username1", |
+ "William"}, |
{{"new-password", "current-password", "new-password"}, |
- "password2", "beta", "password1", "alpha", true, "username2", "Smith"}, |
+ "password2", |
+ "beta", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username2", |
+ "Smith"}, |
{{"new-password", "new-password", "current-password"}, |
- "password3", "gamma", "password1", "alpha", true, "username2", "Smith"}, |
+ "password3", |
+ "gamma", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username2", |
+ "Smith"}, |
// When there is an empty autocomplete attribute (i.e. autocomplete=""), |
// it should have the same effect as having no attribute whatsoever. |
{{"current-password", "", ""}, |
- "password1", "alpha", "", "", false, "username1", "William"}, |
+ "password1", |
+ "alpha", |
+ "", |
+ "", |
+ false, |
+ "username1", |
+ "William"}, |
{{"", "", "new-password"}, |
- "", "", "password3", "gamma", true, "username2", "Smith"}, |
+ "", |
+ "", |
+ "password3", |
+ "gamma", |
+ true, |
+ "username2", |
+ "Smith"}, |
{{"", "new-password", ""}, |
- "", "", "password2", "beta", true, "username2", "Smith"}, |
+ "", |
+ "", |
+ "password2", |
+ "beta", |
+ true, |
+ "username2", |
+ "Smith"}, |
{{"", "current-password", "current-password"}, |
- "password2", "beta", "", "", false, "username2", "Smith"}, |
+ "password2", |
+ "beta", |
+ "", |
+ "", |
+ false, |
+ "username2", |
+ "Smith"}, |
{{"new-password", "", "new-password"}, |
- "", "", "password1", "alpha", true, "username1", "William"}, |
+ "", |
+ "", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username1", |
+ "William"}, |
{{"new-password", "", "current-password"}, |
- "password3", "gamma", "password1", "alpha", true, "username2","Smith"}, |
+ "password3", |
+ "gamma", |
+ "password1", |
+ "alpha", |
+ true, |
+ "username2", |
+ "Smith"}, |
// It should not matter if attribute values are upper or mixed case. |
- {{NULL, "current-password", NULL}, |
- "password2", "beta", "", "", false, "username2", "Smith"}, |
- {{NULL, "CURRENT-PASSWORD", NULL}, |
- "password2", "beta", "", "", false, "username2", "Smith"}, |
- {{NULL, "new-password", NULL}, |
- "", "", "password2", "beta", true, "username2", "Smith"}, |
- {{NULL, "nEw-PaSsWoRd", NULL}, |
- "", "", "password2", "beta", true, "username2", "Smith"}}; |
+ {{nullptr, "current-password", nullptr}, |
+ "password2", |
+ "beta", |
+ "", |
+ "", |
+ false, |
+ "username2", |
+ "Smith"}, |
+ {{nullptr, "CURRENT-PASSWORD", nullptr}, |
+ "password2", |
+ "beta", |
+ "", |
+ "", |
+ false, |
+ "username2", |
+ "Smith"}, |
+ {{nullptr, "new-password", nullptr}, |
+ "", |
+ "", |
+ "password2", |
+ "beta", |
+ true, |
+ "username2", |
+ "Smith"}, |
+ {{nullptr, "nEw-PaSsWoRd", nullptr}, |
+ "", |
+ "", |
+ "password2", |
+ "beta", |
+ true, |
+ "username2", |
+ "Smith"}}; |
for (size_t i = 0; i < arraysize(cases); ++i) { |
SCOPED_TRACE(testing::Message() << "Iteration " << i); |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddPasswordField("pin1", "123456", NULL); |
- builder.AddPasswordField("pin2", "789101", NULL); |
- builder.AddTextField("username1", "William", NULL); |
+ builder.AddPasswordField("pin1", "123456", nullptr); |
+ builder.AddPasswordField("pin2", "789101", nullptr); |
+ builder.AddTextField("username1", "William", nullptr); |
builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]); |
- builder.AddTextField("username2", "Smith", NULL); |
+ builder.AddTextField("username2", "Smith", nullptr); |
builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]); |
builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
// In the absence of username autocomplete attributes, the username should |
@@ -641,16 +858,15 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedTextFields) { |
PasswordFormBuilder builder(kTestFormActionURL); |
builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); |
- builder.AddTextField("username", "johnsmith", NULL); |
+ builder.AddTextField("username", "johnsmith", nullptr); |
builder.AddNonDisplayedTextField("nondisplayed2", "nodispalyed_value2"); |
- builder.AddPasswordField("password", "secret", NULL); |
- builder.AddPasswordField("password", "secret", NULL); |
+ builder.AddPasswordField("password", "secret", nullptr); |
+ builder.AddPasswordField("password", "secret", nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
@@ -664,17 +880,16 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedLoginPairs) { |
builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); |
builder.AddNonDisplayedPasswordField("nondisplayed2", "nodispalyed_value2"); |
- builder.AddTextField("username", "johnsmith", NULL); |
+ builder.AddTextField("username", "johnsmith", nullptr); |
builder.AddNonDisplayedTextField("nondisplayed3", "nodispalyed_value3"); |
builder.AddNonDisplayedPasswordField("nondisplayed4", "nodispalyed_value4"); |
- builder.AddPasswordField("password", "secret", NULL); |
- builder.AddPasswordField("password", "secret", NULL); |
+ builder.AddPasswordField("password", "secret", nullptr); |
+ builder.AddPasswordField("password", "secret", nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
@@ -691,9 +906,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, OnlyNonDisplayedLoginPair) { |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), |
password_form->username_element); |
@@ -710,13 +924,12 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
PasswordFormBuilder builder(kTestFormActionURL); |
builder.AddNonDisplayedTextField("username", "William"); |
- builder.AddPasswordField("password", "secret", NULL); |
+ builder.AddPasswordField("password", "secret", nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
@@ -729,14 +942,13 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
PasswordFormBuilder builder(kTestFormActionURL); |
builder.AddNonDisplayedTextField("search", "query"); |
- builder.AddTextField("username", "William", NULL); |
+ builder.AddTextField("username", "William", nullptr); |
builder.AddNonDisplayedPasswordField("password", "secret"); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
@@ -748,15 +960,14 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
InvisiblePassword_LatestUsernameIsInvisible) { |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddTextField("search", "query", NULL); |
+ builder.AddTextField("search", "query", nullptr); |
builder.AddNonDisplayedTextField("username", "William"); |
builder.AddNonDisplayedPasswordField("password", "secret"); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
@@ -766,28 +977,26 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
TEST_F(MAYBE_PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) { |
PasswordFormBuilder builder("invalid_target"); |
- builder.AddTextField("username", "JohnSmith", NULL); |
+ builder.AddTextField("username", "JohnSmith", nullptr); |
builder.AddSubmitButton("submit"); |
- builder.AddPasswordField("password", "secret", NULL); |
+ builder.AddPasswordField("password", "secret", nullptr); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
EXPECT_FALSE(password_form); |
} |
TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
InvalidFormDueToNoPasswordFields) { |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddTextField("username1", "John", NULL); |
- builder.AddTextField("username2", "Smith", NULL); |
+ builder.AddTextField("username1", "John", nullptr); |
+ builder.AddTextField("username2", "Smith", nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
EXPECT_FALSE(password_form); |
} |
@@ -809,16 +1018,15 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
SCOPED_TRACE(testing::Message() << "Iteration " << i); |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddTextField("username1", "John", NULL); |
- builder.AddPasswordField("password1", cases[i][0], NULL); |
- builder.AddPasswordField("password2", cases[i][1], NULL); |
- builder.AddPasswordField("password3", cases[i][2], NULL); |
+ builder.AddTextField("username1", "John", nullptr); |
+ builder.AddPasswordField("password1", cases[i][0], nullptr); |
+ builder.AddPasswordField("password2", cases[i][1], nullptr); |
+ builder.AddPasswordField("password3", cases[i][2], nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
EXPECT_FALSE(password_form); |
} |
} |
@@ -826,17 +1034,16 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
InvalidFormDueToTooManyPasswordFieldsWithoutAutocompleteAttributes) { |
PasswordFormBuilder builder(kTestFormActionURL); |
- builder.AddTextField("username1", "John", NULL); |
- builder.AddPasswordField("password1", "alpha", NULL); |
- builder.AddPasswordField("password2", "alpha", NULL); |
- builder.AddPasswordField("password3", "alpha", NULL); |
- builder.AddPasswordField("password4", "alpha", NULL); |
+ builder.AddTextField("username1", "John", nullptr); |
+ builder.AddPasswordField("password1", "alpha", nullptr); |
+ builder.AddPasswordField("password2", "alpha", nullptr); |
+ builder.AddPasswordField("password3", "alpha", nullptr); |
+ builder.AddPasswordField("password4", "alpha", nullptr); |
builder.AddSubmitButton("submit"); |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
EXPECT_FALSE(password_form); |
} |
@@ -848,9 +1055,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationLogin) { |
builder.AddSubmitButton("submit"); |
std::string login_html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> login_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(login_html, &login_form, nullptr)); |
+ std::unique_ptr<PasswordForm> login_form = |
+ LoadHTMLAndConvertForm(login_html, nullptr, false); |
ASSERT_TRUE(login_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, login_form->layout); |
} |
@@ -865,9 +1071,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationSignup) { |
builder.AddSubmitButton("submit"); |
std::string signup_html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> signup_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(signup_html, &signup_form, nullptr)); |
+ std::unique_ptr<PasswordForm> signup_form = |
+ LoadHTMLAndConvertForm(signup_html, nullptr, false); |
ASSERT_TRUE(signup_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, signup_form->layout); |
} |
@@ -882,9 +1087,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationChange) { |
builder.AddSubmitButton("submit"); |
std::string change_html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> change_form; |
- ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(change_html, &change_form, nullptr)); |
+ std::unique_ptr<PasswordForm> change_form = |
+ LoadHTMLAndConvertForm(change_html, nullptr, false); |
ASSERT_TRUE(change_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, change_form->layout); |
} |
@@ -903,9 +1107,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
builder.AddSubmitButton("submit"); |
std::string login_plus_signup_html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> login_plus_signup_form; |
- ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( |
- login_plus_signup_html, &login_plus_signup_form, nullptr)); |
+ std::unique_ptr<PasswordForm> login_plus_signup_form = |
+ LoadHTMLAndConvertForm(login_plus_signup_html, nullptr, false); |
ASSERT_TRUE(login_plus_signup_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
login_plus_signup_form->layout); |
@@ -925,9 +1128,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
builder.AddSubmitButton("submit"); |
std::string login_plus_signup_html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> login_plus_signup_form; |
- ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( |
- login_plus_signup_html, &login_plus_signup_form, nullptr)); |
+ std::unique_ptr<PasswordForm> login_plus_signup_form = |
+ LoadHTMLAndConvertForm(login_plus_signup_html, nullptr, false); |
ASSERT_TRUE(login_plus_signup_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
login_plus_signup_form->layout); |
@@ -949,8 +1151,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
FormsPredictionsMap predictions; |
SetPredictions(html, &predictions, predictions_positions); |
- std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, &predictions); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, &predictions, false); |
EXPECT_FALSE(password_form); |
} |
@@ -969,8 +1171,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
FormsPredictionsMap predictions; |
SetPredictions(html, &predictions, predictions_positions); |
- std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, &predictions); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, &predictions, false); |
EXPECT_FALSE(password_form); |
} |
@@ -990,8 +1192,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
FormsPredictionsMap predictions; |
SetPredictions(html, &predictions, predictions_positions); |
- std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, &predictions); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, &predictions, false); |
EXPECT_TRUE(password_form); |
} |
@@ -1010,8 +1212,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
FormsPredictionsMap predictions; |
SetPredictions(html, &predictions, predictions_positions); |
- std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, &predictions); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, &predictions, false); |
EXPECT_TRUE(password_form); |
} |
@@ -1175,8 +1377,8 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
} |
std::string html = builder.ProduceHTML(); |
- std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, nullptr); |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
EXPECT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_username_element), |
@@ -1188,4 +1390,71 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
} |
} |
+TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
+ ProbablySignUpFormTwoTextOnePassword) { |
+ PasswordFormBuilder builder(kTestFormActionURL); |
+ builder.AddTextField("email", "johnsmith@gmail.com", nullptr); |
+ builder.AddTextField("username", "johnsmith", nullptr); |
+ builder.AddPasswordField("password", "secret", nullptr); |
+ std::string html = builder.ProduceHTML(); |
+ |
+ // No user input, not considered as SignUp. |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_FALSE(password_form->does_look_like_signup_form); |
+ |
+ // With user input, considered as SignUp. |
+ password_form = LoadHTMLAndConvertForm(html, nullptr, true); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_TRUE(password_form->does_look_like_signup_form); |
+} |
+ |
+TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
+ ProbablySignUpFormOneTextNewAndConfirmPassword) { |
+ PasswordFormBuilder builder(kTestFormActionURL); |
+ builder.AddTextField("username", "johnsmith", nullptr); |
+ builder.AddPasswordField("new_password", "secret", nullptr); |
+ builder.AddPasswordField("confirm_password", "secret", nullptr); |
+ std::string html = builder.ProduceHTML(); |
+ |
+ // No user input, not considered as SignUp. |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, false); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_FALSE(password_form->does_look_like_signup_form); |
+ |
+ // With user input, considered as SignUp. |
+ password_form = LoadHTMLAndConvertForm(html, nullptr, true); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_TRUE(password_form->does_look_like_signup_form); |
+} |
+ |
+TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
+ NotProbablySignUpFormOneTextCurrentAndNewPassword) { |
+ PasswordFormBuilder builder(kTestFormActionURL); |
+ builder.AddTextField("username", "johnsmith", nullptr); |
+ builder.AddPasswordField("password", "secret", nullptr); |
+ builder.AddPasswordField("new_password", "new_secret", nullptr); |
+ std::string html = builder.ProduceHTML(); |
+ |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, true); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_FALSE(password_form->does_look_like_signup_form); |
+} |
+ |
+TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
+ NotProbablySignUpFormForSignInForm) { |
+ PasswordFormBuilder builder(kTestFormActionURL); |
+ builder.AddTextField("username", "johnsmith", nullptr); |
+ builder.AddPasswordField("password", "secret", nullptr); |
+ std::string html = builder.ProduceHTML(); |
+ |
+ std::unique_ptr<PasswordForm> password_form = |
+ LoadHTMLAndConvertForm(html, nullptr, true); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_FALSE(password_form->does_look_like_signup_form); |
+} |
+ |
} // namespace autofill |