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..209af6869fa826f78b19afa2b2ede8baaca6847e 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, |
@@ -168,23 +168,30 @@ 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. |
+ // a |password_form|. If |with_user_input| == true it's considered that all |
+ // values in the form elements came from the user input. Note that ASSERT() |
vabr (Chromium)
2016/04/06 22:42:12
Actually, there seems to be no ASSERT in the metho
dvadym
2016/04/07 11:52:18
Thanks, it makes sense, the body of this function
|
+ // can only be used in void functions, this is why |password_form| is passed |
+ // in as a pointer to a unique_ptr. |
void LoadHTMLAndConvertForm(const std::string& html, |
std::unique_ptr<PasswordForm>* password_form, |
- FormsPredictionsMap* predictions) { |
+ 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); |
+ *password_form = 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 +244,16 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
ASSERT_TRUE(password_form); |
EXPECT_EQ("data:", password_form->signon_realm); |
@@ -264,16 +271,16 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, 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 +300,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 +321,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 +345,15 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), |
@@ -395,16 +404,16 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), |
@@ -456,17 +465,17 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), |
@@ -509,97 +518,313 @@ 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"); |
@@ -607,7 +832,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
std::unique_ptr<PasswordForm> password_form; |
ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
ASSERT_TRUE(password_form); |
// In the absence of username autocomplete attributes, the username should |
@@ -641,16 +866,16 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, 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 +889,17 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
@@ -693,7 +918,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, OnlyNonDisplayedLoginPair) { |
std::unique_ptr<PasswordForm> password_form; |
ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
ASSERT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16("username"), |
password_form->username_element); |
@@ -710,13 +935,13 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, 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 +954,14 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, 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,7 +973,7 @@ 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"); |
@@ -756,7 +981,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
std::unique_ptr<PasswordForm> password_form; |
ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
+ LoadHTMLAndConvertForm(html, &password_form, 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 +991,28 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
EXPECT_FALSE(password_form); |
} |
@@ -809,16 +1034,16 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
EXPECT_FALSE(password_form); |
} |
} |
@@ -826,17 +1051,17 @@ 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)); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
EXPECT_FALSE(password_form); |
} |
@@ -850,7 +1075,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationLogin) { |
std::unique_ptr<PasswordForm> login_form; |
ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(login_html, &login_form, nullptr)); |
+ LoadHTMLAndConvertForm(login_html, &login_form, nullptr, false)); |
ASSERT_TRUE(login_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, login_form->layout); |
} |
@@ -867,7 +1092,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationSignup) { |
std::unique_ptr<PasswordForm> signup_form; |
ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(signup_html, &signup_form, nullptr)); |
+ LoadHTMLAndConvertForm(signup_html, &signup_form, nullptr, false)); |
ASSERT_TRUE(signup_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, signup_form->layout); |
} |
@@ -884,7 +1109,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationChange) { |
std::unique_ptr<PasswordForm> change_form; |
ASSERT_NO_FATAL_FAILURE( |
- LoadHTMLAndConvertForm(change_html, &change_form, nullptr)); |
+ LoadHTMLAndConvertForm(change_html, &change_form, nullptr, false)); |
ASSERT_TRUE(change_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, change_form->layout); |
} |
@@ -905,7 +1130,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
std::unique_ptr<PasswordForm> login_plus_signup_form; |
ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( |
- login_plus_signup_html, &login_plus_signup_form, nullptr)); |
+ login_plus_signup_html, &login_plus_signup_form, nullptr, false)); |
ASSERT_TRUE(login_plus_signup_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
login_plus_signup_form->layout); |
@@ -927,7 +1152,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
std::unique_ptr<PasswordForm> login_plus_signup_form; |
ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( |
- login_plus_signup_html, &login_plus_signup_form, nullptr)); |
+ login_plus_signup_html, &login_plus_signup_form, nullptr, false)); |
ASSERT_TRUE(login_plus_signup_form); |
EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
login_plus_signup_form->layout); |
@@ -950,7 +1175,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
SetPredictions(html, &predictions, predictions_positions); |
std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, &predictions); |
+ LoadHTMLAndConvertForm(html, &password_form, &predictions, false); |
EXPECT_FALSE(password_form); |
} |
@@ -970,7 +1195,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
SetPredictions(html, &predictions, predictions_positions); |
std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, &predictions); |
+ LoadHTMLAndConvertForm(html, &password_form, &predictions, false); |
EXPECT_FALSE(password_form); |
} |
@@ -991,7 +1216,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
SetPredictions(html, &predictions, predictions_positions); |
std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, &predictions); |
+ LoadHTMLAndConvertForm(html, &password_form, &predictions, false); |
EXPECT_TRUE(password_form); |
} |
@@ -1011,7 +1236,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
SetPredictions(html, &predictions, predictions_positions); |
std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, &predictions); |
+ LoadHTMLAndConvertForm(html, &password_form, &predictions, false); |
EXPECT_TRUE(password_form); |
} |
@@ -1176,7 +1401,7 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
std::string html = builder.ProduceHTML(); |
std::unique_ptr<PasswordForm> password_form; |
- LoadHTMLAndConvertForm(html, &password_form, nullptr); |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false); |
EXPECT_TRUE(password_form); |
EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_username_element), |
@@ -1188,4 +1413,77 @@ 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(); |
+ |
+ std::unique_ptr<PasswordForm> password_form; |
+ // No user input, not considered as SignUp. |
+ ASSERT_NO_FATAL_FAILURE( |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_FALSE(password_form->does_look_like_signup_form); |
+ |
+ // With user input, considered as SignUp. |
+ ASSERT_NO_FATAL_FAILURE( |
+ LoadHTMLAndConvertForm(html, &password_form, 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(); |
+ |
+ std::unique_ptr<PasswordForm> password_form; |
+ // No user input, not considered as SignUp. |
+ ASSERT_NO_FATAL_FAILURE( |
vabr (Chromium)
2016/04/06 22:42:12
What would be the fatal failure which could happen
dvadym
2016/04/07 11:52:18
Done.
|
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_FALSE(password_form->does_look_like_signup_form); |
+ |
+ // With user input, considered as SignUp. |
+ ASSERT_NO_FATAL_FAILURE( |
+ LoadHTMLAndConvertForm(html, &password_form, 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; |
+ ASSERT_NO_FATAL_FAILURE( |
+ LoadHTMLAndConvertForm(html, &password_form, 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; |
+ ASSERT_NO_FATAL_FAILURE( |
+ LoadHTMLAndConvertForm(html, &password_form, nullptr, true)); |
+ ASSERT_TRUE(password_form); |
+ EXPECT_FALSE(password_form->does_look_like_signup_form); |
+} |
+ |
} // namespace autofill |