Commit ba4b62e9 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[MF Android] Extract AccessorySheetDataBuilder for tests

This CL generalizes helper functions used in the following tests
* PasswordAccessoryControllerTest,
* AddressAccessoryControllerTest (https://crrev.com/c/1614200), and
* CreditCardAccessoryControllerTest (https://crrev.com/c/1599927)

Bug: None.
Change-Id: Ief1ad6cb78e14d558e2202cf874d8dbbaa54e9fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1615464
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662212}
parent 76ad58f2
...@@ -71,9 +71,9 @@ void CreditCardAccessoryControllerImpl::RefreshSuggestionsForField() { ...@@ -71,9 +71,9 @@ void CreditCardAccessoryControllerImpl::RefreshSuggestionsForField() {
bool has_suggestions = !info_to_add.empty(); bool has_suggestions = !info_to_add.empty();
GetManualFillingController()->RefreshSuggestionsForField( GetManualFillingController()->RefreshSuggestionsForField(
/*is_fillable=*/true, /*is_fillable=*/true,
autofill::CreateAccessorySheetData(GetTitle(has_suggestions), autofill::CreateAccessorySheetData(
std::move(info_to_add), FallbackSheetType::CREDIT_CARD, GetTitle(has_suggestions),
std::move(footer_commands))); std::move(info_to_add), std::move(footer_commands)));
} }
void CreditCardAccessoryControllerImpl::SetManualFillingControllerForTesting( void CreditCardAccessoryControllerImpl::SetManualFillingControllerForTesting(
......
...@@ -7,16 +7,28 @@ ...@@ -7,16 +7,28 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autofill/mock_manual_filling_controller.h" #include "chrome/browser/autofill/mock_manual_filling_controller.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/credit_card.h" #include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/test_personal_data_manager.h" #include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
using testing::_; using testing::_;
using testing::SaveArg; using testing::SaveArg;
namespace autofill { namespace autofill {
namespace {
AccessorySheetData::Builder CreditCardAccessorySheetDataBuilder() {
return AccessorySheetData::Builder(
FallbackSheetType::CREDIT_CARD,
l10n_util::GetStringUTF16(IDS_MANUAL_FILLING_CREDIT_CARD_SHEET_TITLE));
}
} // namespace
class CreditCardAccessoryControllerTest : public testing::Test { class CreditCardAccessoryControllerTest : public testing::Test {
public: public:
...@@ -44,13 +56,7 @@ class CreditCardAccessoryControllerTest : public testing::Test { ...@@ -44,13 +56,7 @@ class CreditCardAccessoryControllerTest : public testing::Test {
}; };
TEST_F(CreditCardAccessoryControllerTest, RefreshSuggestionsForField) { TEST_F(CreditCardAccessoryControllerTest, RefreshSuggestionsForField) {
autofill::CreditCard card; autofill::CreditCard card = test::GetCreditCard();
card.SetNumber(base::ASCIIToUTF16("4111111111111111"));
card.SetExpirationMonth(04);
card.SetExpirationYear(39);
card.SetRawInfo(autofill::CREDIT_CARD_NAME_FULL,
base::ASCIIToUTF16("Kirby Puckett"));
data_manager_.AddCreditCard(card); data_manager_.AddCreditCard(card);
autofill::AccessorySheetData result(autofill::FallbackSheetType::PASSWORD, autofill::AccessorySheetData result(autofill::FallbackSheetType::PASSWORD,
...@@ -62,17 +68,14 @@ TEST_F(CreditCardAccessoryControllerTest, RefreshSuggestionsForField) { ...@@ -62,17 +68,14 @@ TEST_F(CreditCardAccessoryControllerTest, RefreshSuggestionsForField) {
controller_.RefreshSuggestionsForField(); controller_.RefreshSuggestionsForField();
ASSERT_EQ(1u, result.user_info_list().size()); ASSERT_EQ(result, CreditCardAccessorySheetDataBuilder()
auto info = result.user_info_list().at(0); .AddUserInfo()
ASSERT_EQ(4u, info.fields().size()); .AppendSimpleField(card.ObfuscatedLastFourDigits())
base::string16 expected_cc_string = .AppendSimpleField(card.ExpirationMonthAsString())
autofill::internal::GetObfuscatedStringForCardDigits( .AppendSimpleField(card.Expiration4DigitYearAsString())
base::ASCIIToUTF16("1111")); .AppendSimpleField(
EXPECT_EQ(expected_cc_string, info.fields().at(0).display_text()); card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL))
EXPECT_EQ(base::ASCIIToUTF16("04"), info.fields().at(1).display_text()); .Build());
EXPECT_EQ(base::ASCIIToUTF16("2039"), info.fields().at(2).display_text());
EXPECT_EQ(base::ASCIIToUTF16("Kirby Puckett"),
info.fields().at(3).display_text());
} }
} // namespace autofill } // namespace autofill
...@@ -5,15 +5,16 @@ ...@@ -5,15 +5,16 @@
#include "chrome/browser/autofill/manual_filling_utils.h" #include "chrome/browser/autofill/manual_filling_utils.h"
#include <utility> #include <utility>
#include <vector>
namespace autofill { namespace autofill {
AccessorySheetData CreateAccessorySheetData( AccessorySheetData CreateAccessorySheetData(
FallbackSheetType type,
base::string16 title, base::string16 title,
std::vector<UserInfo> user_info, std::vector<UserInfo> user_info,
std::vector<FooterCommand> footer_commands) { std::vector<FooterCommand> footer_commands) {
// TODO(crbug.com/902425): Remove hard-coded enum value AccessorySheetData data(type, std::move(title));
AccessorySheetData data(FallbackSheetType::PASSWORD, std::move(title));
for (auto& i : user_info) { for (auto& i : user_info) {
data.add_user_info(std::move(i)); data.add_user_info(std::move(i));
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_AUTOFILL_MANUAL_FILLING_UTILS_H_ #ifndef CHROME_BROWSER_AUTOFILL_MANUAL_FILLING_UTILS_H_
#define CHROME_BROWSER_AUTOFILL_MANUAL_FILLING_UTILS_H_ #define CHROME_BROWSER_AUTOFILL_MANUAL_FILLING_UTILS_H_
#include <vector>
#include "components/autofill/core/browser/ui/accessory_sheet_data.h" #include "components/autofill/core/browser/ui/accessory_sheet_data.h"
namespace autofill { namespace autofill {
...@@ -12,6 +14,7 @@ namespace autofill { ...@@ -12,6 +14,7 @@ namespace autofill {
// Creates an AccessorySheetData defining the data to be shown in the filling // Creates an AccessorySheetData defining the data to be shown in the filling
// UI. // UI.
AccessorySheetData CreateAccessorySheetData( AccessorySheetData CreateAccessorySheetData(
FallbackSheetType type,
base::string16 title, base::string16 title,
std::vector<UserInfo> user_info, std::vector<UserInfo> user_info,
std::vector<FooterCommand> footer_commands); std::vector<FooterCommand> footer_commands);
......
...@@ -212,6 +212,7 @@ void PasswordAccessoryControllerImpl::RefreshSuggestionsForField( ...@@ -212,6 +212,7 @@ void PasswordAccessoryControllerImpl::RefreshSuggestionsForField(
GetManualFillingController()->RefreshSuggestionsForField( GetManualFillingController()->RefreshSuggestionsForField(
is_fillable, is_fillable,
autofill::CreateAccessorySheetData( autofill::CreateAccessorySheetData(
autofill::FallbackSheetType::PASSWORD,
GetTitle(has_suggestions, GetFocusedFrameOrigin()), GetTitle(has_suggestions, GetFocusedFrameOrigin()),
std::move(info_to_add), std::move(footer_commands_to_add))); std::move(info_to_add), std::move(footer_commands_to_add)));
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <ostream>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "base/callback.h" #include "base/callback.h"
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
namespace { namespace {
using autofill::AccessorySheetData; using autofill::AccessorySheetData;
using autofill::FallbackSheetType;
using autofill::FillingStatus; using autofill::FillingStatus;
using autofill::FooterCommand; using autofill::FooterCommand;
using autofill::PasswordForm; using autofill::PasswordForm;
...@@ -48,56 +49,6 @@ constexpr char kExampleSite[] = "https://example.com"; ...@@ -48,56 +49,6 @@ constexpr char kExampleSite[] = "https://example.com";
constexpr char kExampleDomain[] = "example.com"; constexpr char kExampleDomain[] = "example.com";
constexpr int kIconSize = 75; // An example size for favicons (=> 3.5*20px). constexpr int kIconSize = 75; // An example size for favicons (=> 3.5*20px).
// Helper class for AccessorySheetData objects creation.
//
// Example that creates a AccessorySheetData object with two UserInfo objects;
// the former has two fields, whereas the latter has three fields:
// AccessorySheetData data = AccessorySheetDataBuilder(title)
// .AddUserInfo()
// .AppendField(...)
// .AppendField(...)
// .AddUserInfo()
// .AppendField(...)
// .AppendField(...)
// .AppendField(...)
// .Build();
class AccessorySheetDataBuilder {
public:
explicit AccessorySheetDataBuilder(const base::string16& title)
: accessory_sheet_data_(autofill::FallbackSheetType::PASSWORD, title) {}
~AccessorySheetDataBuilder() = default;
// Adds a new UserInfo object to |accessory_sheet_data_|.
AccessorySheetDataBuilder& AddUserInfo() {
accessory_sheet_data_.add_user_info(UserInfo());
return *this;
}
// Appends a field to the last UserInfo object.
AccessorySheetDataBuilder& AppendField(const base::string16& display_text,
const base::string16& a11y_description,
bool is_obfuscated,
bool selectable) {
accessory_sheet_data_.mutable_user_info_list().back().add_field(
UserInfo::Field(display_text, a11y_description, is_obfuscated,
selectable));
return *this;
}
// Appends a new footer command to |accessory_sheet_data_|.
AccessorySheetDataBuilder& AppendFooterCommand(
const base::string16& display_text) {
accessory_sheet_data_.add_footer_command(FooterCommand(display_text));
return *this;
}
const AccessorySheetData& Build() { return accessory_sheet_data_; }
private:
AccessorySheetData accessory_sheet_data_;
};
// Creates a new map entry in the |first| element of the returned pair. The // Creates a new map entry in the |first| element of the returned pair. The
// |second| element holds the PasswordForm that the |first| element points to. // |second| element holds the PasswordForm that the |first| element points to.
// That way, the pointer only points to a valid address in the called scope. // That way, the pointer only points to a valid address in the called scope.
...@@ -150,57 +101,14 @@ base::string16 generate_password_str() { ...@@ -150,57 +101,14 @@ base::string16 generate_password_str() {
// Creates a AccessorySheetDataBuilder object with a "Manage passwords..." // Creates a AccessorySheetDataBuilder object with a "Manage passwords..."
// footer. // footer.
AccessorySheetDataBuilder PasswordAccessorySheetDataBuilder( AccessorySheetData::Builder PasswordAccessorySheetDataBuilder(
const base::string16& title) { const base::string16& title) {
AccessorySheetDataBuilder builder(title); return AccessorySheetData::Builder(FallbackSheetType::PASSWORD, title)
builder.AppendFooterCommand(manage_passwords_str()); .AppendFooterCommand(manage_passwords_str());
return builder;
} }
} // namespace } // namespace
// Automagically used to pretty-print UserInfo::Field. Must be in same
// namespace.
void PrintTo(const UserInfo::Field& field, std::ostream* os) {
*os << "(display text: \"" << base::UTF16ToUTF8(field.display_text())
<< "\", a11y_description: \""
<< base::UTF16ToUTF8(field.a11y_description()) << "\", is "
<< (field.is_obfuscated() ? "" : "not ") << "obfuscated, is "
<< (field.selectable() ? "" : "not ") << "selectable)";
}
// Automagically used to pretty-print UserInfo. Must be in same namespace.
void PrintTo(const UserInfo& user_info, std::ostream* os) {
*os << "[";
for (const UserInfo::Field& field : user_info.fields()) {
PrintTo(field, os);
*os << ", ";
}
*os << "]";
}
// Automagically used to pretty-print FooterCommand. Must be in same namespace.
void PrintTo(const FooterCommand& footer_command, std::ostream* os) {
*os << "(display text: \"" << base::UTF16ToUTF8(footer_command.display_text())
<< "\")";
}
// Automagically used to pretty-print AccessorySheetData. Must be in same
// namespace.
void PrintTo(const AccessorySheetData& data, std::ostream* os) {
*os << "has title: \"" << data.title() << "\", has user info list: [";
for (const UserInfo& user_info : data.user_info_list()) {
PrintTo(user_info, os);
*os << ", ";
}
*os << "], has footer commands: [";
for (const FooterCommand& footer_command : data.footer_commands()) {
PrintTo(footer_command, os);
*os << ", ";
}
*os << "]";
}
class PasswordAccessoryControllerTest : public ChromeRenderViewHostTestHarness { class PasswordAccessoryControllerTest : public ChromeRenderViewHostTestHarness {
public: public:
PasswordAccessoryControllerTest() PasswordAccessoryControllerTest()
...@@ -750,12 +658,13 @@ TEST_F(PasswordAccessoryControllerTest, NoFaviconCallbacksWhenOriginChanges) { ...@@ -750,12 +658,13 @@ TEST_F(PasswordAccessoryControllerTest, NoFaviconCallbacksWhenOriginChanges) {
TEST_F(PasswordAccessoryControllerTest, AddsGenerationCommandWhenAvailable) { TEST_F(PasswordAccessoryControllerTest, AddsGenerationCommandWhenAvailable) {
controller()->SavePasswordsForOrigin({}, controller()->SavePasswordsForOrigin({},
url::Origin::Create(GURL(kExampleSite))); url::Origin::Create(GURL(kExampleSite)));
AccessorySheetDataBuilder data_builder(passwords_empty_str(kExampleDomain)); AccessorySheetData::Builder data_builder(FallbackSheetType::PASSWORD,
passwords_empty_str(kExampleDomain));
data_builder.AppendFooterCommand(generate_password_str()) data_builder.AppendFooterCommand(generate_password_str())
.AppendFooterCommand(manage_passwords_str()); .AppendFooterCommand(manage_passwords_str());
EXPECT_CALL(mock_manual_filling_controller_, EXPECT_CALL(mock_manual_filling_controller_,
RefreshSuggestionsForField( RefreshSuggestionsForField(
/*is_fillable=*/true, data_builder.Build())); /*is_fillable=*/true, std::move(data_builder).Build()));
EXPECT_CALL(mock_manual_filling_controller_, EXPECT_CALL(mock_manual_filling_controller_,
ShowWhenKeyboardIsVisible(FillingSource::PASSWORD_FALLBACKS)); ShowWhenKeyboardIsVisible(FillingSource::PASSWORD_FALLBACKS));
controller()->RefreshSuggestionsForField( controller()->RefreshSuggestionsForField(
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "components/autofill/core/browser/ui/accessory_sheet_data.h" #include "components/autofill/core/browser/ui/accessory_sheet_data.h"
#include "base/strings/string_piece.h"
namespace autofill { namespace autofill {
UserInfo::Field::Field(const base::string16& display_text, UserInfo::Field::Field(const base::string16& display_text,
...@@ -32,6 +34,14 @@ bool UserInfo::Field::operator==(const UserInfo::Field& field) const { ...@@ -32,6 +34,14 @@ bool UserInfo::Field::operator==(const UserInfo::Field& field) const {
selectable_ == field.selectable_; selectable_ == field.selectable_;
} }
std::ostream& operator<<(std::ostream& os, const UserInfo::Field& field) {
os << "(display text: \"" << field.display_text() << "\", "
<< "a11y_description: \"" << field.a11y_description() << "\", "
<< "is " << (field.selectable() ? "" : "not ") << "selectable, "
<< "is " << (field.is_obfuscated() ? "" : "not ") << "obfuscated)";
return os;
}
UserInfo::UserInfo() = default; UserInfo::UserInfo() = default;
UserInfo::UserInfo(const UserInfo& user_info) = default; UserInfo::UserInfo(const UserInfo& user_info) = default;
...@@ -48,6 +58,14 @@ bool UserInfo::operator==(const UserInfo& user_info) const { ...@@ -48,6 +58,14 @@ bool UserInfo::operator==(const UserInfo& user_info) const {
return fields_ == user_info.fields_; return fields_ == user_info.fields_;
} }
std::ostream& operator<<(std::ostream& os, const UserInfo& user_info) {
os << "[\n";
for (const UserInfo::Field& field : user_info.fields()) {
os << field << ", \n";
}
return os << "]";
}
FooterCommand::FooterCommand(const base::string16& display_text) FooterCommand::FooterCommand(const base::string16& display_text)
: display_text_(display_text) {} : display_text_(display_text) {}
...@@ -67,6 +85,22 @@ bool FooterCommand::operator==(const FooterCommand& fc) const { ...@@ -67,6 +85,22 @@ bool FooterCommand::operator==(const FooterCommand& fc) const {
return display_text_ == fc.display_text_; return display_text_ == fc.display_text_;
} }
std::ostream& operator<<(std::ostream& os, const FooterCommand& fc) {
return os << "(display text: \"" << fc.display_text() << "\")";
}
std::ostream& operator<<(std::ostream& os, const FallbackSheetType& type) {
switch (type) {
case FallbackSheetType::PASSWORD:
return os << "Passwords sheet";
case FallbackSheetType::CREDIT_CARD:
return os << "Payments sheet";
case FallbackSheetType::ADDRESS:
return os << "Address sheet";
}
return os;
}
AccessorySheetData::AccessorySheetData(FallbackSheetType sheet_type, AccessorySheetData::AccessorySheetData(FallbackSheetType sheet_type,
const base::string16& title) const base::string16& title)
: sheet_type_(sheet_type), title_(title) {} : sheet_type_(sheet_type), title_(title) {}
...@@ -90,4 +124,81 @@ bool AccessorySheetData::operator==(const AccessorySheetData& data) const { ...@@ -90,4 +124,81 @@ bool AccessorySheetData::operator==(const AccessorySheetData& data) const {
footer_commands_ == data.footer_commands_; footer_commands_ == data.footer_commands_;
} }
std::ostream& operator<<(std::ostream& os, const AccessorySheetData& data) {
os << data.get_sheet_type() << " with title: \"" << data.title()
<< "\", user info list: [";
for (const UserInfo& user_info : data.user_info_list()) {
os << user_info << ", ";
}
os << "], footer commands: [";
for (const FooterCommand& footer_command : data.footer_commands()) {
os << footer_command << ", ";
}
return os << "]";
}
AccessorySheetData::Builder::Builder(FallbackSheetType type,
const base::string16& title)
: accessory_sheet_data_(type, title) {}
AccessorySheetData::Builder::~Builder() = default;
AccessorySheetData::Builder&& AccessorySheetData::Builder::AddUserInfo() && {
// Calls AddUserInfo()& since |this| is an lvalue.
return std::move(AddUserInfo());
}
AccessorySheetData::Builder& AccessorySheetData::Builder::AddUserInfo() & {
accessory_sheet_data_.add_user_info(UserInfo());
return *this;
}
AccessorySheetData::Builder&& AccessorySheetData::Builder::AppendSimpleField(
const base::string16& text) && {
// Calls AppendSimpleField(...)& since |this| is an lvalue.
return std::move(AppendSimpleField(text));
}
AccessorySheetData::Builder& AccessorySheetData::Builder::AppendSimpleField(
const base::string16& text) & {
return AppendField(text, text, false, true);
}
AccessorySheetData::Builder&& AccessorySheetData::Builder::AppendField(
const base::string16& display_text,
const base::string16& a11y_description,
bool is_obfuscated,
bool selectable) && {
// Calls AppendField(...)& since |this| is an lvalue.
return std::move(
AppendField(display_text, a11y_description, is_obfuscated, selectable));
}
AccessorySheetData::Builder& AccessorySheetData::Builder::AppendField(
const base::string16& display_text,
const base::string16& a11y_description,
bool is_obfuscated,
bool selectable) & {
accessory_sheet_data_.mutable_user_info_list().back().add_field(
UserInfo::Field(display_text, a11y_description, is_obfuscated,
selectable));
return *this;
}
AccessorySheetData::Builder&& AccessorySheetData::Builder::AppendFooterCommand(
const base::string16& display_text) && {
// Calls AppendFooterCommand(...)& since |this| is an lvalue.
return std::move(AppendFooterCommand(display_text));
}
AccessorySheetData::Builder& AccessorySheetData::Builder::AppendFooterCommand(
const base::string16& display_text) & {
accessory_sheet_data_.add_footer_command(FooterCommand(display_text));
return *this;
}
AccessorySheetData&& AccessorySheetData::Builder::Build() && {
return std::move(accessory_sheet_data_);
}
} // namespace autofill } // namespace autofill
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_UI_ACCESSORY_SHEET_DATA_H_ #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_UI_ACCESSORY_SHEET_DATA_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_UI_ACCESSORY_SHEET_DATA_H_ #define COMPONENTS_AUTOFILL_CORE_BROWSER_UI_ACCESSORY_SHEET_DATA_H_
#include <utility>
#include <vector> #include <vector>
#include "base/strings/string16.h" #include "base/strings/string16.h"
...@@ -57,7 +58,7 @@ class UserInfo { ...@@ -57,7 +58,7 @@ class UserInfo {
UserInfo& operator=(const UserInfo& user_info); UserInfo& operator=(const UserInfo& user_info);
UserInfo& operator=(UserInfo&& user_info); UserInfo& operator=(UserInfo&& user_info);
void add_field(Field field) { fields_.emplace_back(std::move(field)); } void add_field(Field field) { fields_.push_back(std::move(field)); }
const std::vector<Field>& fields() const { return fields_; } const std::vector<Field>& fields() const { return fields_; }
...@@ -67,6 +68,9 @@ class UserInfo { ...@@ -67,6 +68,9 @@ class UserInfo {
std::vector<Field> fields_; std::vector<Field> fields_;
}; };
std::ostream& operator<<(std::ostream& out, const UserInfo::Field& field);
std::ostream& operator<<(std::ostream& out, const UserInfo& user_info);
// Represents a command below the suggestions, such as "Manage password...". // Represents a command below the suggestions, such as "Manage password...".
class FooterCommand { class FooterCommand {
public: public:
...@@ -87,6 +91,8 @@ class FooterCommand { ...@@ -87,6 +91,8 @@ class FooterCommand {
base::string16 display_text_; base::string16 display_text_;
}; };
std::ostream& operator<<(std::ostream& out, const FooterCommand& fc);
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.keyboard_accessory // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.keyboard_accessory
enum class FallbackSheetType { enum class FallbackSheetType {
// Indicates the data type to which an AccessorySheetData object corresponds. // Indicates the data type to which an AccessorySheetData object corresponds.
...@@ -95,10 +101,14 @@ enum class FallbackSheetType { ...@@ -95,10 +101,14 @@ enum class FallbackSheetType {
ADDRESS ADDRESS
}; };
std::ostream& operator<<(std::ostream& out, const FallbackSheetType& type);
// Represents the contents of a bottom sheet tab below the keyboard accessory, // Represents the contents of a bottom sheet tab below the keyboard accessory,
// which can correspond to passwords, credit cards, or profiles data. // which can correspond to passwords, credit cards, or profiles data.
class AccessorySheetData { class AccessorySheetData {
public: public:
class Builder;
explicit AccessorySheetData(FallbackSheetType sheet_type, explicit AccessorySheetData(FallbackSheetType sheet_type,
const base::string16& title); const base::string16& title);
AccessorySheetData(const AccessorySheetData& data); AccessorySheetData(const AccessorySheetData& data);
...@@ -139,6 +149,59 @@ class AccessorySheetData { ...@@ -139,6 +149,59 @@ class AccessorySheetData {
std::vector<FooterCommand> footer_commands_; std::vector<FooterCommand> footer_commands_;
}; };
std::ostream& operator<<(std::ostream& out, const AccessorySheetData& data);
// Helper class for AccessorySheetData objects creation.
//
// Example that creates a AccessorySheetData object with two UserInfo objects;
// the former has two fields, whereas the latter has three fields:
// AccessorySheetData data = AccessorySheetData::Builder(title)
// .AddUserInfo()
// .AppendField(...)
// .AppendField(...)
// .AddUserInfo()
// .AppendField(...)
// .AppendField(...)
// .AppendField(...)
// .Build();
class AccessorySheetData::Builder {
public:
Builder(FallbackSheetType type, const base::string16& title);
~Builder();
// Adds a new UserInfo object to |accessory_sheet_data_|.
Builder&& AddUserInfo() &&;
Builder& AddUserInfo() &;
// Appends a selectable, non-obfuscated field to the last UserInfo object.
Builder&& AppendSimpleField(const base::string16& text) &&;
Builder& AppendSimpleField(const base::string16& text) &;
// Appends a field to the last UserInfo object.
Builder&& AppendField(const base::string16& display_text,
const base::string16& a11y_description,
bool is_obfuscated,
bool selectable) &&;
Builder& AppendField(const base::string16& display_text,
const base::string16& a11y_description,
bool is_obfuscated,
bool selectable) &;
// Appends a new footer command to |accessory_sheet_data_|.
Builder&& AppendFooterCommand(const base::string16& display_text) &&;
Builder& AppendFooterCommand(const base::string16& display_text) &;
// This class returns the constructed AccessorySheetData object. Since this
// would render the builder unusable, it's required to destroy the object
// afterwards. So if you hold the class in a variable, invoke like this:
// AccessorySheetData::Builder b(title);
// std::move(b).Build();
AccessorySheetData&& Build() &&;
private:
AccessorySheetData accessory_sheet_data_;
};
} // namespace autofill } // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_UI_ACCESSORY_SHEET_DATA_H_ #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_UI_ACCESSORY_SHEET_DATA_H_
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