Commit 04d2f0db authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[MFill Android] Use password in PSL labels

By adding the password to PSL labels, we make more clear that we fill
not only username but also passwords when tapping a chip.

Bug: 982784
Change-Id: Iea3fb6a537a47b16a32ea39c4ca4baa435885191
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695269
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676491}
parent 5141b97c
......@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
#include "components/autofill/core/browser/ui/popup_item_ids.h"
......@@ -17,6 +18,22 @@
namespace autofill {
constexpr base::char16 kLabelSeparator = ' ';
constexpr size_t kMaxBulletCount = 8;
namespace {
base::string16 CreateLabel(const Suggestion& suggestion) {
base::string16 password =
suggestion.additional_label.substr(0, kMaxBulletCount);
// The label contains the signon_realm or is empty. The additional_label can
// never be empty since it must contain a password.
if (suggestion.label.empty())
return password;
return suggestion.label + kLabelSeparator + password;
}
} // namespace
AutofillKeyboardAccessoryAdapter::AutofillKeyboardAccessoryAdapter(
AutofillPopupController* controller,
unsigned int animation_duration_millis,
......@@ -49,12 +66,15 @@ void AutofillKeyboardAccessoryAdapter::OnSuggestionsChanged() {
DCHECK(controller_) << "Call OnSuggestionsChanged only from its owner!";
DCHECK(view_) << "OnSuggestionsChanged called before a View was set!";
labels_.clear();
front_element_ = base::nullopt;
for (int i = 0; i < GetLineCount(); ++i) {
const Suggestion& suggestion = controller_->GetSuggestionAt(i);
if (suggestion.frontend_id != POPUP_ITEM_ID_CLEAR_FORM &&
suggestion.frontend_id != POPUP_ITEM_ID_CREATE_HINT)
suggestion.frontend_id != POPUP_ITEM_ID_CREATE_HINT) {
labels_.push_back(CreateLabel(suggestion));
continue;
}
DCHECK(!front_element_.has_value()) << "Additional front item at: " << i;
front_element_ = base::Optional<int>(i);
}
......@@ -88,11 +108,7 @@ const base::string16& AutofillKeyboardAccessoryAdapter::GetElidedValueAt(
const base::string16& AutofillKeyboardAccessoryAdapter::GetElidedLabelAt(
int row) const {
DCHECK(controller_) << "Call OnSuggestionsChanged only from its owner!";
const base::string16& label =
controller_->GetElidedLabelAt(OffsetIndexFor(row));
if (label.empty())
return GetSuggestionAt(row).additional_label;
return label;
return labels_[row];
}
bool AutofillKeyboardAccessoryAdapter::GetRemovalConfirmationText(
......
......@@ -100,6 +100,9 @@ class AutofillKeyboardAccessoryAdapter : public AutofillPopupView,
AutofillPopupController* controller_; // weak.
std::unique_ptr<AutofillKeyboardAccessoryAdapter::AccessoryView> view_;
// The labels to be used for the input chips.
std::vector<base::string16> labels_;
// If 0, don't animate suggestion view.
const unsigned int animation_duration_millis_;
......
......@@ -5,6 +5,7 @@
#include <cstddef>
#include <memory>
#include <string>
#include <utility>
#include <vector>
......@@ -51,13 +52,20 @@ class MockAccessoryView
DISALLOW_COPY_AND_ASSIGN(MockAccessoryView);
};
Suggestion createPasswordEntry(std::string password,
std::string username,
std::string psl_origin) {
Suggestion s(/*value=*/username, /*label=*/psl_origin, /*icon=*/"",
PopupItemId::POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
s.additional_label = ASCIIToUTF16(password);
return s;
}
std::vector<Suggestion> createSuggestions() {
std::vector<Suggestion> suggestions = {
Suggestion("*", "A", "", PopupItemId::POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY),
Suggestion("**", "", "", PopupItemId::POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY),
Suggestion("***", "C", "",
PopupItemId::POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY)};
suggestions[1].additional_label = ASCIIToUTF16("B");
createPasswordEntry("****************", "Alf", ""),
createPasswordEntry("****************", "Berta", "psl.origin.eg"),
createPasswordEntry("***", "Carl", "")};
return suggestions;
}
......@@ -174,14 +182,19 @@ TEST_F(AutofillKeyboardAccessoryAdapterTest, ReorderUpdatedSuggestions) {
}
TEST_F(AutofillKeyboardAccessoryAdapterTest, UseAdditionalLabelForElidedLabel) {
controller()->set_suggestions(createSuggestions());
controller()->set_suggestions(createSuggestions(/*clearItemOffset=*/1));
NotifyAboutSuggestions();
// If there is a label, use it.
EXPECT_EQ(adapter_as_controller()->GetElidedLabelAt(0), ASCIIToUTF16("A"));
// If there is a label, use it but cap at 8 bullets.
EXPECT_EQ(adapter_as_controller()->GetElidedLabelAt(0),
ASCIIToUTF16("********"));
// If the label is empty, use the additional label:
EXPECT_EQ(adapter_as_controller()->GetElidedLabelAt(1), ASCIIToUTF16("B"));
EXPECT_EQ(adapter_as_controller()->GetElidedLabelAt(1),
ASCIIToUTF16("psl.origin.eg ********"));
// If the password has less than 8 bullets, show the exact amount.
EXPECT_EQ(adapter_as_controller()->GetElidedLabelAt(2), ASCIIToUTF16("***"));
}
TEST_F(AutofillKeyboardAccessoryAdapterTest, ProvideReorderedSuggestions) {
......
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