Commit e66f8cbe authored by Maxim Kolosovskiy's avatar Maxim Kolosovskiy Committed by Commit Bot

[Password Manager] Let the "show-autofill-signatures" flag mark the fields for

password generation

An HTML tag "password_creation_field" will be added to a password field suitable for generation.
The fields that are not suitable for generation will be unchanged.

The flag is used mostly for debugging, testing, collecting train data.

Bug: 824793

Change-Id: I3c38843eb92617f0060ead0fa0dd6047c2d1d889
Reviewed-on: https://chromium-review.googlesource.com/975161
Commit-Queue: Maxim Kolosovskiy <kolos@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545399}
parent 9c10df35
...@@ -1339,7 +1339,8 @@ const char kShowAllDialogsWithViewsToolkitDescription[] = ...@@ -1339,7 +1339,8 @@ const char kShowAllDialogsWithViewsToolkitDescription[] =
const char kShowAutofillSignaturesName[] = "Show autofill signatures."; const char kShowAutofillSignaturesName[] = "Show autofill signatures.";
const char kShowAutofillSignaturesDescription[] = const char kShowAutofillSignaturesDescription[] =
"Annotates web forms with Autofill signatures as HTML attributes."; "Annotates web forms with Autofill signatures as HTML attributes. Also "
"marks password fields suitable for password generation.";
const char kShowAutofillTypePredictionsName[] = "Show Autofill predictions"; const char kShowAutofillTypePredictionsName[] = "Show Autofill predictions";
const char kShowAutofillTypePredictionsDescription[] = const char kShowAutofillTypePredictionsDescription[] =
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "components/autofill/content/renderer/autofill_agent.h" #include "components/autofill/content/renderer/autofill_agent.h"
#include "components/autofill/content/renderer/form_autofill_util.h" #include "components/autofill/content/renderer/form_autofill_util.h"
#include "components/autofill/content/renderer/test_password_generation_agent.h" #include "components/autofill/content/renderer/test_password_generation_agent.h"
#include "components/autofill/core/common/autofill_switches.h"
#include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/password_generation_util.h" #include "components/autofill/core/common/password_generation_util.h"
#include "components/password_manager/core/common/password_manager_features.h" #include "components/password_manager/core/common/password_manager_features.h"
...@@ -150,6 +151,21 @@ class PasswordGenerationAgentTest : public ChromeRenderViewTest { ...@@ -150,6 +151,21 @@ class PasswordGenerationAgentTest : public ChromeRenderViewTest {
DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgentTest); DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgentTest);
}; };
class PasswordGenerationAgentTestForHtmlAnnotation
: public PasswordGenerationAgentTest {
public:
PasswordGenerationAgentTestForHtmlAnnotation() {}
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kShowAutofillSignatures);
PasswordGenerationAgentTest::SetUp();
}
private:
DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgentTestForHtmlAnnotation);
};
const char kSigninFormHTML[] = const char kSigninFormHTML[] =
"<FORM name = 'blah' action = 'http://www.random.com/'> " "<FORM name = 'blah' action = 'http://www.random.com/'> "
" <INPUT type = 'text' id = 'username'/> " " <INPUT type = 'text' id = 'username'/> "
...@@ -159,7 +175,7 @@ const char kSigninFormHTML[] = ...@@ -159,7 +175,7 @@ const char kSigninFormHTML[] =
"</FORM>"; "</FORM>";
const char kAccountCreationFormHTML[] = const char kAccountCreationFormHTML[] =
"<FORM name = 'blah' action = 'http://www.random.com/pa/th?q=1&p=3#first'> " "<FORM id = 'blah' action = 'http://www.random.com/pa/th?q=1&p=3#first'> "
" <INPUT type = 'text' id = 'username'/> " " <INPUT type = 'text' id = 'username'/> "
" <INPUT type = 'password' id = 'first_password' size = 5/>" " <INPUT type = 'password' id = 'first_password' size = 5/>"
" <INPUT type = 'password' id = 'second_password' size = 5/> " " <INPUT type = 'password' id = 'second_password' size = 5/> "
...@@ -890,4 +906,45 @@ TEST_F(PasswordGenerationAgentTest, AutofillToGenerationField) { ...@@ -890,4 +906,45 @@ TEST_F(PasswordGenerationAgentTest, AutofillToGenerationField) {
EXPECT_FALSE(fake_driver_.called_password_no_longer_generated()); EXPECT_FALSE(fake_driver_.called_password_no_longer_generated());
} }
TEST_F(PasswordGenerationAgentTestForHtmlAnnotation, AnnotateForm) {
LoadHTMLWithUserGesture(kAccountCreationFormHTML);
SetNotBlacklistedMessage(password_generation_, kAccountCreationFormHTML);
SetAccountCreationFormsDetectedMessage(password_generation_,
GetMainFrame()->GetDocument(), 0, 1);
ExpectGenerationAvailable("first_password", true);
WebDocument document = GetMainFrame()->GetDocument();
// Check the form signature is set.
blink::WebElement form_element =
document.GetElementById(blink::WebString::FromUTF8("blah"));
ASSERT_FALSE(form_element.IsNull());
blink::WebString form_signature =
form_element.GetAttribute(blink::WebString::FromUTF8("form_signature"));
ASSERT_FALSE(form_signature.IsNull());
EXPECT_EQ("3524919054660658462", form_signature.Ascii());
// Check field signatures are set.
blink::WebElement username_element =
document.GetElementById(blink::WebString::FromUTF8("username"));
ASSERT_FALSE(username_element.IsNull());
blink::WebString username_signature = username_element.GetAttribute(
blink::WebString::FromUTF8("field_signature"));
ASSERT_FALSE(username_signature.IsNull());
EXPECT_EQ("239111655", username_signature.Ascii());
blink::WebElement password_element =
document.GetElementById(blink::WebString::FromUTF8("first_password"));
ASSERT_FALSE(password_element.IsNull());
blink::WebString password_signature = password_element.GetAttribute(
blink::WebString::FromUTF8("field_signature"));
ASSERT_FALSE(password_signature.IsNull());
EXPECT_EQ("3933215845", password_signature.Ascii());
// Check the generation element is marked.
blink::WebString generation_mark = password_element.GetAttribute(
blink::WebString::FromUTF8("password_creation_field"));
ASSERT_FALSE(generation_mark.IsNull());
EXPECT_EQ("1", generation_mark.Utf8());
}
} // namespace autofill } // namespace autofill
...@@ -164,6 +164,9 @@ PasswordGenerationAgent::PasswordGenerationAgent( ...@@ -164,6 +164,9 @@ PasswordGenerationAgent::PasswordGenerationAgent(
editing_popup_shown_(false), editing_popup_shown_(false),
enabled_(password_generation::IsPasswordGenerationEnabled()), enabled_(password_generation::IsPasswordGenerationEnabled()),
form_classifier_enabled_(false), form_classifier_enabled_(false),
mark_generation_element_(
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kShowAutofillSignatures)),
password_agent_(password_agent), password_agent_(password_agent),
binding_(this) { binding_(this) {
LogBoolean(Logger::STRING_GENERATION_RENDERER_ENABLED, enabled_); LogBoolean(Logger::STRING_GENERATION_RENDERER_ENABLED, enabled_);
...@@ -464,6 +467,8 @@ void PasswordGenerationAgent::DetermineGenerationElement() { ...@@ -464,6 +467,8 @@ void PasswordGenerationAgent::DetermineGenerationElement() {
generation_form_data_.reset(new AccountCreationFormData( generation_form_data_.reset(new AccountCreationFormData(
possible_form_data.form, std::move(password_elements))); possible_form_data.form, std::move(password_elements)));
generation_element_ = generation_form_data_->password_elements[0]; generation_element_ = generation_form_data_->password_elements[0];
if (mark_generation_element_)
generation_element_.SetAttribute("password_creation_field", "1");
generation_element_.SetAttribute("aria-autocomplete", "list"); generation_element_.SetAttribute("aria-autocomplete", "list");
password_generation::LogPasswordGenerationEvent( password_generation::LogPasswordGenerationEvent(
password_generation::GENERATION_AVAILABLE); password_generation::GENERATION_AVAILABLE);
......
...@@ -199,6 +199,10 @@ class PasswordGenerationAgent : public content::RenderFrameObserver, ...@@ -199,6 +199,10 @@ class PasswordGenerationAgent : public content::RenderFrameObserver,
// If the form classifier should run. // If the form classifier should run.
bool form_classifier_enabled_; bool form_classifier_enabled_;
// True iff the generation element should be marked with special HTML
// attribute (only for experimental purposes).
bool mark_generation_element_;
// Unowned pointer. Used to notify PassowrdAutofillAgent when values // Unowned pointer. Used to notify PassowrdAutofillAgent when values
// in password fields are updated. // in password fields are updated.
PasswordAutofillAgent* password_agent_; PasswordAutofillAgent* password_agent_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment