Commit 2dfa5d00 authored by Yiming Zhou's avatar Yiming Zhou Committed by Commit Bot

Set pre-recorded autofill profiles in Captured Site Tests.

This change adds support for pre-recorded address and payment in
Autofill Capture Site Tests. A recent change,
5e3e7faf, allows the Action Recorder
Extension to record a user's saved address and payment information when
recording a test recipe. This change completes the cycle by allowing the
automation test framework to set up the saved address and payment
information contained in a test recipe.

Bug: 847905
Change-Id: I6a5b9cc246dc59cbab4e4e0c6362c148e1820a14
Reviewed-on: https://chromium-review.googlesource.com/1241756Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Commit-Queue: Yiming Zhou <uwyiming@google.com>
Cr-Commit-Position: refs/heads/master@{#594404}
parent 3bcbe725
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <string>
#include "base/command_line.h"
......@@ -153,17 +154,59 @@ class AutofillCapturedSitesInteractiveTest
return false;
}
bool AddAutofillProfileInfo(const std::string& field_type,
const std::string& field_value) override {
ServerFieldType type;
if (!StringToFieldType(field_type, &type)) {
ADD_FAILURE() << "Unable to recognize autofill field type '" << field_type
<< "'!";
return false;
}
if (base::StartsWith(field_type, "HTML_TYPE_CREDIT_CARD_",
base::CompareCase::INSENSITIVE_ASCII) ||
base::StartsWith(field_type, "CREDIT_CARD_",
base::CompareCase::INSENSITIVE_ASCII)) {
card_.SetRawInfo(type, base::UTF8ToUTF16(field_value));
} else {
profile_.SetRawInfo(type, base::UTF8ToUTF16(field_value));
}
return true;
}
bool SetupAutofillProfile() override {
AddTestAutofillData(browser(), profile(), credit_card());
return true;
}
protected:
AutofillCapturedSitesInteractiveTest()
: profile_(test::GetFullProfile()),
card_(CreditCard(base::GenerateGUID(), "http://www.example.com")) {}
card_(CreditCard(base::GenerateGUID(), "http://www.example.com")) {
for (size_t i = NO_SERVER_DATA; i < MAX_VALID_FIELD_TYPE; ++i) {
ServerFieldType field_type = static_cast<ServerFieldType>(i);
string_to_field_type_map_[AutofillType(field_type).ToString()] =
field_type;
}
for (size_t i = HTML_TYPE_UNSPECIFIED; i < HTML_TYPE_UNRECOGNIZED; ++i) {
AutofillType field_type(static_cast<HtmlFieldType>(i), HTML_MODE_NONE);
string_to_field_type_map_[field_type.ToString()] =
field_type.GetStorableType();
}
// Initialize the credit card with default values, in case the test recipe
// file does not contain pre-saved credit card info.
test::SetCreditCardInfo(&card_, "Buddy Holly", "5187654321098765", "10",
"2998", "1");
}
~AutofillCapturedSitesInteractiveTest() override {}
// InProcessBrowserTest:
void SetUpOnMainThread() override {
AutofillUiTest::SetUpOnMainThread();
SetupTestProfile();
recipe_replayer_ =
std::make_unique<captured_sites_test_utils::TestRecipeReplayer>(
browser(), this);
......@@ -195,15 +238,6 @@ class AutofillCapturedSitesInteractiveTest
const AutofillProfile profile() { return profile_; }
private:
void SetupTestProfile() {
test::SetCreditCardInfo(&card_, "Milton Waddams", "9621327911759602", "5",
"2027", "1");
test::SetProfileInfo(&profile_, "Milton", "C.", "Waddams",
"red.swingline@initech.com", "Initech",
"4120 Freidrich Lane", "Apt 8", "Austin", "Texas",
"78744", "US", "5125551234");
AddTestAutofillData(browser(), profile_, card_);
}
bool ShowAutofillSuggestion(content::RenderFrameHost* frame,
const std::string& target_element_xpath) {
......@@ -229,10 +263,18 @@ class AutofillCapturedSitesInteractiveTest
autofill_wait_for_action_interval);
}
bool StringToFieldType(const std::string& str, ServerFieldType* type) {
if (string_to_field_type_map_.count(str) == 0)
return false;
*type = string_to_field_type_map_[str];
return true;
}
AutofillProfile profile_;
CreditCard card_;
std::unique_ptr<captured_sites_test_utils::TestRecipeReplayer>
recipe_replayer_;
std::map<const std::string, ServerFieldType> string_to_field_type_map_;
base::test::ScopedFeatureList feature_list_;
};
......
......@@ -546,6 +546,14 @@ bool TestRecipeReplayer::ReplayRecordedActions(
// JSON object.
bool TestRecipeReplayer::InitializeBrowserToExecuteRecipe(
std::unique_ptr<base::DictionaryValue>& recipe) {
// Setup any saved address and credit card at the start of the test.
const base::Value* autofill_profile_container =
recipe->FindKey("autofillProfile");
if (autofill_profile_container &&
!SetupSavedAutofillProfile(*autofill_profile_container))
return false;
// Setup any saved passwords at the start of the test.
const base::Value* saved_password_container =
recipe->FindKey("passwordManagerProfiles");
......@@ -1412,6 +1420,45 @@ bool TestRecipeReplayer::HasChromeStoredCredential(
return true;
}
bool TestRecipeReplayer::SetupSavedAutofillProfile(
const base::Value& saved_autofill_profile_container) {
if (base::Value::Type::LIST != saved_autofill_profile_container.type()) {
ADD_FAILURE() << "Save Autofill Profile is not a list!";
return false;
}
const base::Value::ListStorage& profile_entries_list =
saved_autofill_profile_container.GetList();
for (base::ListValue::const_iterator it_entry = profile_entries_list.begin();
it_entry != profile_entries_list.end(); ++it_entry) {
const base::DictionaryValue* entry;
if (!it_entry->GetAsDictionary(&entry)) {
ADD_FAILURE() << "Failed to extract an entry!";
return false;
}
const base::Value* type_container = entry->FindKey("type");
if (base::Value::Type::STRING != type_container->type()) {
ADD_FAILURE() << "Type is not a string!";
return false;
}
const std::string type = type_container->GetString();
const base::Value* value_container = entry->FindKey("value");
if (base::Value::Type::STRING != value_container->type()) {
ADD_FAILURE() << "Value is not a string!";
return false;
}
const std::string value = value_container->GetString();
if (!feature_action_executor()->AddAutofillProfileInfo(type, value)) {
return false;
}
}
return feature_action_executor()->SetupAutofillProfile();
}
bool TestRecipeReplayer::SetupSavedPasswords(
const base::Value& saved_password_list_container) {
if (base::Value::Type::LIST != saved_password_list_container.type()) {
......@@ -1474,6 +1521,20 @@ bool TestRecipeReplayChromeFeatureActionExecutor::AutofillForm(
return false;
}
bool TestRecipeReplayChromeFeatureActionExecutor::AddAutofillProfileInfo(
const std::string& field_type,
const std::string& field_value) {
ADD_FAILURE() << "TestRecipeReplayChromeFeatureActionExecutor"
"::AddAutofillProfileInfo is not implemented!";
return false;
}
bool TestRecipeReplayChromeFeatureActionExecutor::SetupAutofillProfile() {
ADD_FAILURE() << "TestRecipeReplayChromeFeatureActionExecutor"
"::SetupAutofillProfile is not implemented!";
return false;
}
bool TestRecipeReplayChromeFeatureActionExecutor::AddCredential(
const std::string& origin,
const std::string& username,
......
......@@ -148,6 +148,9 @@ class TestRecipeReplayChromeFeatureActionExecutor {
virtual bool AutofillForm(content::RenderFrameHost* frame,
const std::string& focus_element_css_selector,
const int attempts = 1);
virtual bool AddAutofillProfileInfo(const std::string& field_type,
const std::string& field_value);
virtual bool SetupAutofillProfile();
// Chrome Password Manager feature methods.
virtual bool AddCredential(const std::string& origin,
const std::string& username,
......@@ -272,6 +275,8 @@ class TestRecipeReplayer {
void NavigateAwayAndDismissBeforeUnloadDialog();
bool HasChromeStoredCredential(const base::DictionaryValue& action,
bool* stored_cred);
bool SetupSavedAutofillProfile(
const base::Value& saved_autofill_profile_container);
bool SetupSavedPasswords(const base::Value& saved_password_list_container);
Browser* browser_;
......
{
"name": "Amazon.com: The Path to Power (The Years of Lyndon Johnson, Volume 1) (9780679729457): Robert A. Caro: Books",
"startingURL": "https://www.amazon.com/Path-Power-Years-Lyndon-Johnson/dp/0679729453/ref=sr_1_1?_encoding=UTF8&ref_=nav_ya_signin&",
"autofillProfile": [
{
"type": "ADDRESS_HOME_CITY",
"value": "Austin"
},
{
"type": "ADDRESS_HOME_LINE1",
"value": "4120 Freidrich Lane"
},
{
"type": "ADDRESS_HOME_LINE2",
"value": "Apt 8"
},
{
"type": "ADDRESS_HOME_STATE",
"value": "Texas"
},
{
"type": "ADDRESS_HOME_ZIP",
"value": "78744"
},
{
"type": "EMAIL_ADDRESS",
"value": "red.swingline@initech.com"
},
{
"type": "HTML_TYPE_CREDIT_CARD_EXP_MONTH",
"value": "05"
},
{
"type": "HTML_TYPE_CREDIT_CARD_EXP_YEAR",
"value": "2027"
},
{
"type": "CREDIT_CARD_NAME_FULL",
"value": "Milton Waddams"
},
{
"type": "HTML_TYPE_CREDIT_CARD_NUMBER",
"value": "9621327911759602"
},
{
"type": "NAME_FULL",
"value": "Milton C. Waddams"
},
{
"type": "PHONE_HOME_CITY_AND_NUMBER",
"value": "5125551234"
}
],
"actions": [
{
"selectorType": "xpath",
......
{
"name": "Bag - Apple",
"startingURL": "https://www.apple.com/shop/bag",
"autofillProfile": [
{
"type": "ADDRESS_HOME_CITY",
"value": "Austin"
},
{
"type": "ADDRESS_HOME_COUNTRY",
"value": "US"
},
{
"type": "ADDRESS_HOME_LINE1",
"value": "4120 Freidrich Lane"
},
{
"type": "ADDRESS_HOME_LINE2",
"value": "Apt 8"
},
{
"type": "ADDRESS_HOME_STATE",
"value": "TX"
},
{
"type": "ADDRESS_HOME_ZIP",
"value": "78744"
},
{
"type": "COMPANY_NAME",
"value": "Initech"
},
{
"type": "CREDIT_CARD_EXP_MONTH",
"value": "05"
},
{
"type": "CREDIT_CARD_EXP_4_DIGIT_YEAR",
"value": "2027"
},
{
"type": "CREDIT_CARD_NUMBER",
"value": "9621327911759602"
},
{
"type": "EMAIL_ADDRESS",
"value": "red.swingline@initech.com"
},
{
"type": "NAME_FIRST",
"value": "Milton"
},
{
"type": "NAME_LAST",
"value": "Waddams"
},
{
"type": "PHONE_HOME_CITY_AND_NUMBER",
"value": "5125551234"
},
{
"type": "PHONE_HOME_CITY_CODE",
"value": "512"
},
{
"type": "PHONE_HOME_NUMBER",
"value": "5551234"
}
],
"actions": [
{
"selectorType": "xpath",
......
{
"name": "Means of Ascent: The Years of Lyndon Johnson II by Robert A. Caro 9780394528359 | eBay",
"startingURL": "https://www.ebay.com/itm/Means-of-Ascent-The-Years-of-Lyndon-Johnson-II-by-Robert-A-Caro/302335419820?epid=245345&hash=item46649865ac:g:XzcAAOSwuMZZL65R",
"autofillProfile": [
{
"type": "ADDRESS_HOME_CITY",
"value": "Austin"
},
{
"type": "ADDRESS_HOME_LINE1",
"value": "4120 Freidrich Lane"
},
{
"type": "ADDRESS_HOME_LINE2",
"value": "Apt 8"
},
{
"type": "ADDRESS_HOME_STATE",
"value": "TX"
},
{
"type": "ADDRESS_HOME_ZIP",
"value": "78744"
},
{
"type": "EMAIL_ADDRESS",
"value": "red.swingline@initech.com"
},
{
"type": "HTML_TYPE_CREDIT_CARD_EXP_MONTH",
"value": "05"
},
{
"type": "HTML_TYPE_CREDIT_CARD_EXP_YEAR",
"value": "2027"
},
{
"type": "HTML_TYPE_CREDIT_CARD_NUMBER",
"value": "9621327911759602"
},
{
"type": "NAME_FIRST",
"value": "Milton"
},
{
"type": "NAME_LAST",
"value": "Waddams"
},
{
"type": "PHONE_HOME_CITY_AND_NUMBER",
"value": "5125551234"
}
],
"actions": [
{
"selectorType": "xpath",
......
{
"name": "Sign In",
"startingURL": "https://www.walmart.com/checkout/#/sign-in",
"autofillProfile": [
{
"type": "ADDRESS_HOME_CITY",
"value": "Austin"
},
{
"type": "ADDRESS_HOME_LINE1",
"value": "4120 Freidrich Lane"
},
{
"type": "ADDRESS_HOME_LINE2",
"value": "Apt 8"
},
{
"type": "ADDRESS_HOME_STATE",
"value": "TX"
},
{
"type": "ADDRESS_HOME_ZIP",
"value": "78744"
},
{
"type": "EMAIL_ADDRESS",
"value": "red.swingline@initech.com"
},
{
"type": "HTML_TYPE_CREDIT_CARD_EXP_MONTH",
"value": "05"
},
{
"type": "HTML_TYPE_CREDIT_CARD_EXP_YEAR",
"value": "2027"
},
{
"type": "HTML_TYPE_CREDIT_CARD_NUMBER",
"value": "9621327911759602"
},
{
"type": "NAME_FIRST",
"value": "Milton"
},
{
"type": "NAME_LAST",
"value": "Waddams"
},
{
"type": "PHONE_HOME_CITY_AND_NUMBER",
"value": "5125551234"
}
],
"actions": [
{
"selectorType": "xpath",
......@@ -10,18 +60,6 @@
},
"type": "click"
},
{
"context": {
"isIframe": false
},
"type": "waitFor",
"assertions": [
"return automation_helper.isElementWithXpathReady(`//div[@aria-label='Select your shipping option']`);",
"return automation_helper.isElementWithXpathReady(`//div[@aria-label='Select your pickup option']`);",
"return automation_helper.isElementWithXpathReady(`//label[@data-automation-id='shipMethod-EXPEDITED']`);",
"return automation_helper.isElementWithXpathReady(`//div[@class='persistent-order-summary']`);"
]
},
{
"selectorType": "xpath",
"selector": "//button[@aria-label='Continue to Shipping Address']",
......
{
"name": "Online Shoes, Clothing, Always Shipped FREE | Zappos.com",
"startingURL": "https://www.zappos.com/marty/cart",
"autofillProfile": [
{
"type": "ADDRESS_HOME_CITY",
"value": "Austin"
},
{
"type": "ADDRESS_HOME_LINE1",
"value": "4120 Freidrich Lane"
},
{
"type": "ADDRESS_HOME_LINE2",
"value": "Apt 8"
},
{
"type": "ADDRESS_HOME_STATE",
"value": "TX"
},
{
"type": "ADDRESS_HOME_ZIP",
"value": "78744"
},
{
"type": "EMAIL_ADDRESS",
"value": "red.swingline@initech.com"
},
{
"type": "HTML_TYPE_CREDIT_CARD_EXP_MONTH",
"value": "05"
},
{
"type": "HTML_TYPE_CREDIT_CARD_EXP_YEAR",
"value": "2027"
},
{
"type": "HTML_TYPE_CREDIT_CARD_NUMBER",
"value": "9621327911759602"
},
{
"type": "NAME_FULL",
"value": "Milton C. Waddams"
},
{
"type": "PHONE_HOME_WHOLE_NUMBER",
"value": "5125551234"
}
],
"actions": [
{
"selectorType": "xpath",
......
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