Commit 2e25175f authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

[MF Android] Adds enum describing data type

This CL adds an enum describing the type of data contained in a sheet.

Bug: 902425
Change-Id: I36a9b06465af839d324ad1d56dc629915d3e597e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1484811
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637828}
parent d76a70f7
......@@ -347,12 +347,10 @@ public class KeyboardAccessoryData {
/**
* Represents the contents of a accessory sheet tab below the keyboard accessory, which can
* correspond to passwords, credit cards, or profiles data. Created natively.
*
* TODO(crbug.com/902425): Add a field to indicate if this corresponds to password, profile, or
* credit card data.
*/
public final static class AccessorySheetData {
private final String mTitle;
private final @FallbackSheetType int mSheetType;
private final List<UserInfo> mUserInfoList = new ArrayList<>();
private final List<FooterCommand> mFooterCommands = new ArrayList<>();
......@@ -360,10 +358,15 @@ public class KeyboardAccessoryData {
* Creates the AccessorySheetData object.
* @param title The title of accessory sheet tab.
*/
public AccessorySheetData(String title) {
public AccessorySheetData(@FallbackSheetType int sheetType, String title) {
mSheetType = sheetType;
mTitle = title;
}
public @FallbackSheetType int getSheetType() {
return mSheetType;
}
/**
* Returns the title of the accessory sheet. This text is also used for accessibility.
*/
......
......@@ -101,8 +101,8 @@ class ManualFillingBridge {
}
@CalledByNative
private static Object createAccessorySheetData(String title) {
return new AccessorySheetData(title);
private static Object createAccessorySheetData(@FallbackSheetType int type, String title) {
return new AccessorySheetData(type, title);
}
@CalledByNative
......
......@@ -628,7 +628,8 @@ public class ManualFillingControllerTest {
}
private AccessorySheetData createPasswordData(String text) {
AccessorySheetData sheetData = new AccessorySheetData("Passwords");
AccessorySheetData sheetData =
new AccessorySheetData(FallbackSheetType.PASSWORD, "Passwords");
UserInfo userInfo = new UserInfo(null);
userInfo.addField(new UserInfo.Field("(No username)", "No username", false, null));
userInfo.addField(new UserInfo.Field(text, "Password", true, null));
......
......@@ -91,12 +91,14 @@ public class PasswordAccessorySheetControllerTest {
mCoordinator.registerDataProvider(testProvider);
// If the coordinator receives a set of initial items, the model should report an insertion.
testProvider.notifyObservers(new AccessorySheetData("Passwords"));
testProvider.notifyObservers(
new AccessorySheetData(FallbackSheetType.PASSWORD, "Passwords"));
verify(mMockItemListObserver).onItemRangeInserted(mSheetDataPieces, 0, 1);
assertThat(mSheetDataPieces.size(), is(1));
// If the coordinator receives a new set of items, the model should report a change.
testProvider.notifyObservers(new AccessorySheetData("Other Passwords"));
testProvider.notifyObservers(
new AccessorySheetData(FallbackSheetType.PASSWORD, "Other Passwords"));
verify(mMockItemListObserver).onItemRangeChanged(mSheetDataPieces, 0, 1, null);
assertThat(mSheetDataPieces.size(), is(1));
......@@ -114,7 +116,8 @@ public class PasswordAccessorySheetControllerTest {
public void testSplitsTabDataToList() {
setAutofillFeature(false);
final PropertyProvider<AccessorySheetData> testProvider = new PropertyProvider<>();
final AccessorySheetData testData = new AccessorySheetData("Passwords for this site");
final AccessorySheetData testData =
new AccessorySheetData(FallbackSheetType.PASSWORD, "Passwords for this site");
testData.getUserInfoList().add(new UserInfo(null));
testData.getUserInfoList().get(0).addField(new UserInfo.Field("Name", "Name", false, null));
testData.getUserInfoList().get(0).addField(
......@@ -137,7 +140,8 @@ public class PasswordAccessorySheetControllerTest {
public void testUsesTabTitleOnlyForEmptyListsForModernDesign() {
setAutofillFeature(true);
final PropertyProvider<AccessorySheetData> testProvider = new PropertyProvider<>();
final AccessorySheetData testData = new AccessorySheetData("No passwords for this");
final AccessorySheetData testData =
new AccessorySheetData(FallbackSheetType.PASSWORD, "No passwords for this");
mCoordinator.registerDataProvider(testProvider);
// Providing only FooterCommands and no User Info shows the title as empty state:
......@@ -183,7 +187,8 @@ public class PasswordAccessorySheetControllerTest {
assertThat(getSuggestionsImpressions(AccessoryTabType.ALL, 0), is(0));
// If the tab is shown without interactive item, log "0" samples.
AccessorySheetData accessorySheetData = new AccessorySheetData("No passwords!");
AccessorySheetData accessorySheetData =
new AccessorySheetData(FallbackSheetType.PASSWORD, "No passwords!");
accessorySheetData.getFooterCommands().add(new FooterCommand("Manage all passwords", null));
accessorySheetData.getFooterCommands().add(new FooterCommand("Generate password", null));
testProvider.notifyObservers(accessorySheetData);
......
......@@ -142,7 +142,8 @@ ManualFillingViewAndroid::ConvertAccessorySheetDataToJavaObject(
const AccessorySheetData& tab_data) {
ScopedJavaLocalRef<jobject> j_tab_data =
Java_ManualFillingBridge_createAccessorySheetData(
env, ConvertUTF16ToJavaString(env, tab_data.title()));
env, static_cast<int>(tab_data.get_sheet_type()),
ConvertUTF16ToJavaString(env, tab_data.title()));
for (const UserInfo& user_info : tab_data.user_info_list()) {
ScopedJavaLocalRef<jobject> j_user_info =
......
......@@ -82,6 +82,7 @@ class MockPasswordAccessoryView : public ManualFillingViewInterface {
autofill::AccessorySheetData dummy_accessory_sheet_data() {
constexpr char kExampleAccessorySheetDataTitle[] = "Example title";
return autofill::AccessorySheetData(
autofill::FallbackSheetType::CREDIT_CARD,
base::ASCIIToUTF16(kExampleAccessorySheetDataTitle));
}
......
......@@ -248,7 +248,8 @@ AccessorySheetData PasswordAccessoryControllerImpl::CreateAccessorySheetData(
? IDS_PASSWORD_MANAGER_ACCESSORY_PASSWORD_LIST_EMPTY_MESSAGE
: IDS_PASSWORD_MANAGER_ACCESSORY_PASSWORD_LIST_TITLE,
base::ASCIIToUTF16(origin.host()));
AccessorySheetData data(passwords_title_str);
AccessorySheetData data(autofill::FallbackSheetType::PASSWORD,
passwords_title_str);
// Create a username and a password element for every suggestion.
for (const SuggestionElementData& suggestion : suggestions) {
......
......@@ -64,7 +64,7 @@ constexpr int kIconSize = 75; // An example size for favicons (=> 3.5*20px).
class AccessorySheetDataBuilder {
public:
explicit AccessorySheetDataBuilder(const base::string16& title)
: accessory_sheet_data_(title) {}
: accessory_sheet_data_(autofill::FallbackSheetType::PASSWORD, title) {}
~AccessorySheetDataBuilder() = default;
......
......@@ -74,6 +74,7 @@ android_resources("autofill_java_resources") {
java_cpp_enum("autofill_core_browser_java_enums") {
sources = [
"../core/browser/accessory_sheet_data.h",
"../core/browser/popup_item_ids.h",
]
}
......
......@@ -67,8 +67,9 @@ bool FooterCommand::operator==(const FooterCommand& fc) const {
return display_text_ == fc.display_text_;
}
AccessorySheetData::AccessorySheetData(const base::string16& title)
: title_(title) {}
AccessorySheetData::AccessorySheetData(FallbackSheetType sheet_type,
const base::string16& title)
: sheet_type_(sheet_type), title_(title) {}
AccessorySheetData::AccessorySheetData(const AccessorySheetData& data) =
default;
......
......@@ -87,14 +87,20 @@ class FooterCommand {
base::string16 display_text_;
};
// GENERATED_JAVA_ENUM_PACKAGE: (
// org.chromium.chrome.browser.autofill.keyboard_accessory)
enum class FallbackSheetType {
// Indicates the data type to which an AccessorySheetData object corresponds.
PASSWORD,
CREDIT_CARD
};
// Represents the contents of a bottom sheet tab below the keyboard accessory,
// which can correspond to passwords, credit cards, or profiles data.
//
// TODO(crbug.com/902425): Add a field to indicate if this corresponds to
// password, profile, or credit card data.
class AccessorySheetData {
public:
explicit AccessorySheetData(const base::string16& title);
explicit AccessorySheetData(FallbackSheetType sheet_type,
const base::string16& title);
AccessorySheetData(const AccessorySheetData& data);
AccessorySheetData(AccessorySheetData&& data);
......@@ -104,6 +110,7 @@ class AccessorySheetData {
AccessorySheetData& operator=(AccessorySheetData&& data);
const base::string16& title() const { return title_; }
FallbackSheetType get_sheet_type() const { return sheet_type_; }
void add_user_info(UserInfo user_info) {
user_info_list_.emplace_back(std::move(user_info));
......@@ -126,6 +133,7 @@ class AccessorySheetData {
bool operator==(const AccessorySheetData& data) const;
private:
FallbackSheetType sheet_type_;
base::string16 title_;
std::vector<UserInfo> user_info_list_;
std::vector<FooterCommand> footer_commands_;
......
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