Commit 4fa2728a authored by Rafał Godlewski's avatar Rafał Godlewski Committed by Commit Bot

Make key icon show when using only federated credentials

Currently when only federated credentials are saved on the site,
the key icon isn't showing up when we refresh the site.

Bug: 677111
Change-Id: I0188d001b59f2af081688acb89adf0928898ead5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1717301
Commit-Queue: Rafał Godlewski <rgod@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683215}
parent 22742113
...@@ -147,7 +147,8 @@ void ManagePasswordsState::OnPasswordAutofilled( ...@@ -147,7 +147,8 @@ void ManagePasswordsState::OnPasswordAutofilled(
password_form_map, password_form_map,
const GURL& origin, const GURL& origin,
const std::vector<const autofill::PasswordForm*>* federated_matches) { const std::vector<const autofill::PasswordForm*>* federated_matches) {
DCHECK(!password_form_map.empty()); DCHECK(!password_form_map.empty() ||
(federated_matches && !federated_matches->empty()));
ClearData(); ClearData();
local_credentials_forms_ = DeepCopyNonPSLMapToVector(password_form_map); local_credentials_forms_ = DeepCopyNonPSLMapToVector(password_form_map);
if (federated_matches) if (federated_matches)
......
...@@ -450,6 +450,19 @@ TEST_F(ManagePasswordsStateTest, PasswordAutofillWithSavedFederations) { ...@@ -450,6 +450,19 @@ TEST_F(ManagePasswordsStateTest, PasswordAutofillWithSavedFederations) {
EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state());
} }
TEST_F(ManagePasswordsStateTest, PasswordAutofillWithOnlyFederations) {
std::map<base::string16, const autofill::PasswordForm*> password_form_map;
const GURL origin(kTestOrigin);
std::vector<const autofill::PasswordForm*> federated;
federated.push_back(&test_local_federated_form());
passwords_data().OnPasswordAutofilled(password_form_map, origin, &federated);
EXPECT_THAT(passwords_data().GetCurrentForms(),
ElementsAre(Pointee(test_local_federated_form())));
EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state());
}
TEST_F(ManagePasswordsStateTest, ActiveOnMixedPSLAndNonPSLMatched) { TEST_F(ManagePasswordsStateTest, ActiveOnMixedPSLAndNonPSLMatched) {
std::map<base::string16, const autofill::PasswordForm*> password_form_map; std::map<base::string16, const autofill::PasswordForm*> password_form_map;
password_form_map[test_local_form().username_value] = &test_local_form(); password_form_map[test_local_form().username_value] = &test_local_form();
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
using testing::_; using testing::_;
using testing::ElementsAre; using testing::ElementsAre;
using testing::Pair;
using testing::Pointee; using testing::Pointee;
using testing::UnorderedElementsAre; using testing::UnorderedElementsAre;
...@@ -58,6 +59,11 @@ class MockPasswordManagerClient : public StubPasswordManagerClient { ...@@ -58,6 +59,11 @@ class MockPasswordManagerClient : public StubPasswordManagerClient {
bool(const std::vector<autofill::PasswordForm*>& local_forms, bool(const std::vector<autofill::PasswordForm*>& local_forms,
const GURL& origin, const GURL& origin,
const CredentialsCallback& callback)); const CredentialsCallback& callback));
MOCK_METHOD3(
PasswordWasAutofilled,
void(const std::map<base::string16, const autofill::PasswordForm*>&,
const GURL&,
const std::vector<const autofill::PasswordForm*>*));
explicit MockPasswordManagerClient(PasswordStore* store) explicit MockPasswordManagerClient(PasswordStore* store)
: store_(store), password_manager_(this) { : store_(store), password_manager_(this) {
...@@ -964,7 +970,6 @@ TEST_F(CredentialManagerImplTest, ...@@ -964,7 +970,6 @@ TEST_F(CredentialManagerImplTest,
std::vector<GURL> federations; std::vector<GURL> federations;
EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, false, ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, false,
federations); federations);
} }
...@@ -1615,4 +1620,33 @@ TEST_F(CredentialManagerImplTest, RespectBlacklistingFederatedCredential) { ...@@ -1615,4 +1620,33 @@ TEST_F(CredentialManagerImplTest, RespectBlacklistingFederatedCredential) {
EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
} }
TEST_F(CredentialManagerImplTest,
ManagePasswordsUICredentialsUpdatedUnconditionallyInSilentMediation) {
autofill::PasswordForm federated = origin_path_form_;
federated.federation_origin =
url::Origin::Create(GURL("https://google.com/"));
federated.signon_realm =
"federation://" + federated.origin.host() + "/google.com";
store_->AddLogin(federated);
form_.username_value = base::ASCIIToUTF16("username_value");
store_->AddLogin(form_);
EXPECT_CALL(*client_,
PasswordWasAutofilled(
ElementsAre(Pair(form_.username_value, Pointee(form_))), _,
Pointee(ElementsAre(Pointee(federated)))));
bool called = false;
CredentialManagerError error;
base::Optional<CredentialInfo> credential;
std::vector<GURL> federations;
federations.push_back(GURL("https://google.com/"));
CallGet(CredentialMediationRequirement::kSilent, true, federations,
base::BindOnce(&GetCredentialCallback, &called, &error, &credential));
RunAllPendingTasks();
}
} // namespace password_manager } // namespace password_manager
...@@ -196,6 +196,20 @@ void CredentialManagerPendingRequestTask::ProcessForms( ...@@ -196,6 +196,20 @@ void CredentialManagerPendingRequestTask::ProcessForms(
else else
get_result = metrics_util::CredentialManagerGetResult::kNoneFirstRun; get_result = metrics_util::CredentialManagerGetResult::kNoneFirstRun;
if (!local_results.empty()) {
std::map<base::string16, const autofill::PasswordForm*>
non_federated_matches;
std::vector<const autofill::PasswordForm*> federated_matches;
for (const auto& result : local_results) {
if (result->IsFederatedCredential()) {
federated_matches.emplace_back(result.get());
} else {
non_federated_matches.emplace(result->username_value, result.get());
}
}
delegate_->client()->PasswordWasAutofilled(non_federated_matches, origin_,
&federated_matches);
}
if (can_use_autosignin) { if (can_use_autosignin) {
// The user had credentials, but either chose not to share them with the // The user had credentials, but either chose not to share them with the
// site, or was prevented from doing so by lack of zero-click (or the // site, or was prevented from doing so by lack of zero-click (or the
...@@ -204,7 +218,6 @@ void CredentialManagerPendingRequestTask::ProcessForms( ...@@ -204,7 +218,6 @@ void CredentialManagerPendingRequestTask::ProcessForms(
delegate_->client()->NotifyUserCouldBeAutoSignedIn( delegate_->client()->NotifyUserCouldBeAutoSignedIn(
std::move(local_results[0])); std::move(local_results[0]));
} }
LogCredentialManagerGetResult(get_result, mediation_); LogCredentialManagerGetResult(get_result, mediation_);
delegate_->SendCredential(send_callback_, CredentialInfo()); delegate_->SendCredential(send_callback_, CredentialInfo());
return; return;
......
...@@ -742,13 +742,10 @@ void NewPasswordFormManager::Fill() { ...@@ -742,13 +742,10 @@ void NewPasswordFormManager::Fill() {
#endif #endif
} }
// TODO(https://crbug.com/831123): Implement correct treating of federated
// matches.
std::vector<const PasswordForm*> federated_matches;
SendFillInformationToRenderer(client_, driver_.get(), IsBlacklisted(), SendFillInformationToRenderer(client_, driver_.get(), IsBlacklisted(),
*observed_password_form.get(), best_matches_, *observed_password_form.get(), best_matches_,
federated_matches, preferred_match_, form_fetcher_->GetFederatedMatches(),
metrics_recorder_.get()); preferred_match_, metrics_recorder_.get());
} }
void NewPasswordFormManager::FillForm(const FormData& observed_form) { void NewPasswordFormManager::FillForm(const FormData& observed_form) {
......
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