Commit fef3d83e authored by mathp's avatar mathp Committed by Commit bot

[Autofill] Control using Variations the sending of Autofill field metadata

We default most tests to having the trial enabled because that is the expected way forward. Nevertheless we put the trial so we can control rollout or kill it after the fact.

BUG=488602
TBR=asvitkine
TEST=FormStructureTest*,AutofillServerTest*

Review URL: https://codereview.chromium.org/1141133003

Cr-Commit-Position: refs/heads/master@{#330601}
parent 7923e436
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/command_line.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/core/browser/autofill_profile.h" #include "components/autofill/core/browser/autofill_profile.h"
...@@ -93,6 +95,12 @@ class WindowedNetworkObserver : public net::TestURLFetcher::DelegateForTests { ...@@ -93,6 +95,12 @@ class WindowedNetworkObserver : public net::TestURLFetcher::DelegateForTests {
class AutofillServerTest : public InProcessBrowserTest { class AutofillServerTest : public InProcessBrowserTest {
public: public:
void SetUpCommandLine(base::CommandLine* command_line) override {
// Enable finch experiment for sending field metadata.
command_line->AppendSwitchASCII(
::switches::kForceFieldTrials, "AutofillFieldMetadata/Enabled/");
}
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
// Disable interactions with the Mac Keychain. // Disable interactions with the Mac Keychain.
PrefService* pref_service = browser()->profile()->GetPrefs(); PrefService* pref_service = browser()->profile()->GetPrefs();
......
...@@ -4,6 +4,7 @@ include_rules = [ ...@@ -4,6 +4,7 @@ include_rules = [
"+components/signin/core/browser", "+components/signin/core/browser",
"+components/signin/core/common", "+components/signin/core/common",
"+components/sync_driver", "+components/sync_driver",
"+components/variations",
"+components/webdata/common", "+components/webdata/common",
"+components/webdata_services", "+components/webdata_services",
"+crypto/random.h", "+crypto/random.h",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/i18n/case_conversion.h" #include "base/i18n/case_conversion.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/sha1.h" #include "base/sha1.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -65,6 +66,13 @@ const char kIgnorePatternInFieldName[] = "\\d{5,}+"; ...@@ -65,6 +66,13 @@ const char kIgnorePatternInFieldName[] = "\\d{5,}+";
// mismatches exceeds this threshold. // mismatches exceeds this threshold.
const int kNumberOfMismatchesThreshold = 3; const int kNumberOfMismatchesThreshold = 3;
// Returns whether sending autofill field metadata to the server is enabled.
bool IsAutofillFieldMetadataEnabled() {
const std::string group_name =
base::FieldTrialList::FindFullName("AutofillFieldMetadata");
return StartsWithASCII(group_name, "Enabled", true);
}
// Helper for |EncodeUploadRequest()| that creates a bit field corresponding to // Helper for |EncodeUploadRequest()| that creates a bit field corresponding to
// |available_field_types| and returns the hex representation as a string. // |available_field_types| and returns the hex representation as a string.
std::string EncodeFieldTypes(const ServerFieldTypeSet& available_field_types) { std::string EncodeFieldTypes(const ServerFieldTypeSet& available_field_types) {
...@@ -111,12 +119,14 @@ buzz::XmlElement* EncodeFieldForQuery(const AutofillField& field, ...@@ -111,12 +119,14 @@ buzz::XmlElement* EncodeFieldForQuery(const AutofillField& field,
buzz::QName(kXMLElementField)); buzz::QName(kXMLElementField));
field_element->SetAttr(buzz::QName(kAttributeSignature), field_element->SetAttr(buzz::QName(kAttributeSignature),
field.FieldSignature()); field.FieldSignature());
if (IsAutofillFieldMetadataEnabled()) {
if (!field.name.empty()) { if (!field.name.empty()) {
field_element->SetAttr(buzz::QName(kAttributeName), field_element->SetAttr(buzz::QName(kAttributeName),
base::UTF16ToUTF8(field.name)); base::UTF16ToUTF8(field.name));
} }
field_element->SetAttr(buzz::QName(kAttributeControlType), field_element->SetAttr(buzz::QName(kAttributeControlType),
field.form_control_type); field.form_control_type);
}
parent->AddElement(field_element); parent->AddElement(field_element);
return field_element; return field_element;
} }
...@@ -136,6 +146,7 @@ void EncodeFieldForUpload(const AutofillField& field, ...@@ -136,6 +146,7 @@ void EncodeFieldForUpload(const AutofillField& field,
// We use the same field elements as the query and add a few more below. // We use the same field elements as the query and add a few more below.
buzz::XmlElement* field_element = EncodeFieldForQuery(field, parent); buzz::XmlElement* field_element = EncodeFieldForQuery(field, parent);
if (IsAutofillFieldMetadataEnabled()) {
if (!field.autocomplete_attribute.empty()) { if (!field.autocomplete_attribute.empty()) {
field_element->SetAttr(buzz::QName(kAttributeAutocomplete), field_element->SetAttr(buzz::QName(kAttributeAutocomplete),
field.autocomplete_attribute); field.autocomplete_attribute);
...@@ -143,6 +154,7 @@ void EncodeFieldForUpload(const AutofillField& field, ...@@ -143,6 +154,7 @@ void EncodeFieldForUpload(const AutofillField& field,
field_element->SetAttr(buzz::QName(kAttributeAutofillType), field_element->SetAttr(buzz::QName(kAttributeAutofillType),
base::IntToString(*field_type)); base::IntToString(*field_type));
} }
}
} }
// Helper for |EncodeFormRequest()| that creates XmlElements for the given field // Helper for |EncodeFormRequest()| that creates XmlElements for the given field
......
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