Commit 92758ce6 authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

[b4p] Add integration test for sign-out handing

This CL adds an integration test that checks that, if the user clicks
"Save" on the bubble introduced in crrev.com/c/2112360, the unsynced
credentials get saved in the profile store.

Bug: 1060132
Change-Id: I014515112abfaf1d3955c06a1d1567cd6e9d6fdb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207228
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772040}
parent 3fed180f
...@@ -92,6 +92,10 @@ class CustomManagePasswordsUIController : public ManagePasswordsUIController { ...@@ -92,6 +92,10 @@ class CustomManagePasswordsUIController : public ManagePasswordsUIController {
void DidFinishNavigation( void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override; content::NavigationHandle* navigation_handle) override;
// ManagePasswordsUIController:
void NotifyUnsyncedCredentialsWillBeDeleted(
const std::vector<autofill::PasswordForm>& unsynced_credentials) override;
// Should not be used for manual fallback events. // Should not be used for manual fallback events.
bool IsTargetStateObserved( bool IsTargetStateObserved(
const password_manager::ui::State target_state, const password_manager::ui::State target_state,
...@@ -233,6 +237,15 @@ void CustomManagePasswordsUIController::DidFinishNavigation( ...@@ -233,6 +237,15 @@ void CustomManagePasswordsUIController::DidFinishNavigation(
ProcessStateExpectations(GetState()); ProcessStateExpectations(GetState());
} }
void CustomManagePasswordsUIController::NotifyUnsyncedCredentialsWillBeDeleted(
const std::vector<autofill::PasswordForm>& unsynced_credentials) {
ManagePasswordsUIController::NotifyUnsyncedCredentialsWillBeDeleted(
unsynced_credentials);
was_prompt_automatically_shown_ = true;
ProcessStateExpectations(
password_manager::ui::WILL_DELETE_UNSYNCED_ACCOUNT_PASSWORDS_STATE);
}
bool CustomManagePasswordsUIController::IsTargetStateObserved( bool CustomManagePasswordsUIController::IsTargetStateObserved(
const password_manager::ui::State target_state, const password_manager::ui::State target_state,
const password_manager::ui::State current_state) const { const password_manager::ui::State current_state) const {
...@@ -342,6 +355,14 @@ void BubbleObserver::AcceptSavePrompt() const { ...@@ -342,6 +355,14 @@ void BubbleObserver::AcceptSavePrompt() const {
EXPECT_FALSE(IsSavePromptAvailable()); EXPECT_FALSE(IsSavePromptAvailable());
} }
void BubbleObserver::AcceptSaveUnsyncedCredentialsPrompt() const {
ASSERT_EQ(password_manager::ui::WILL_DELETE_UNSYNCED_ACCOUNT_PASSWORDS_STATE,
passwords_ui_controller_->GetState());
passwords_ui_controller_->SaveUnsyncedCredentialsInProfileStore();
EXPECT_NE(password_manager::ui::WILL_DELETE_UNSYNCED_ACCOUNT_PASSWORDS_STATE,
passwords_ui_controller_->GetState());
}
void BubbleObserver::AcceptUpdatePrompt() const { void BubbleObserver::AcceptUpdatePrompt() const {
ASSERT_TRUE(IsUpdatePromptAvailable()); ASSERT_TRUE(IsUpdatePromptAvailable());
passwords_ui_controller_->SavePassword( passwords_ui_controller_->SavePassword(
...@@ -387,6 +408,13 @@ bool BubbleObserver::WaitForFallbackForSaving( ...@@ -387,6 +408,13 @@ bool BubbleObserver::WaitForFallbackForSaving(
return controller->WaitForFallbackForSaving(timeout); return controller->WaitForFallbackForSaving(timeout);
} }
void BubbleObserver::WaitForSaveUnsyncedCredentialsPrompt() const {
CustomManagePasswordsUIController* controller =
static_cast<CustomManagePasswordsUIController*>(passwords_ui_controller_);
controller->WaitForState(
password_manager::ui::WILL_DELETE_UNSYNCED_ACCOUNT_PASSWORDS_STATE);
}
PasswordStoreResultsObserver::PasswordStoreResultsObserver() = default; PasswordStoreResultsObserver::PasswordStoreResultsObserver() = default;
PasswordStoreResultsObserver::~PasswordStoreResultsObserver() = default; PasswordStoreResultsObserver::~PasswordStoreResultsObserver() = default;
......
...@@ -96,6 +96,10 @@ class BubbleObserver { ...@@ -96,6 +96,10 @@ class BubbleObserver {
// checks that the prompt is no longer visible afterwards. // checks that the prompt is no longer visible afterwards.
void AcceptUpdatePrompt() const; void AcceptUpdatePrompt() const;
// Expecting that the prompt is available, saves the unsynced credentials.
// At the end, checks that the prompt is no longer visible afterwards.
void AcceptSaveUnsyncedCredentialsPrompt() const;
// Returns once the account chooser pops up or it's already shown. // Returns once the account chooser pops up or it's already shown.
// |web_contents| must be the custom one returned by // |web_contents| must be the custom one returned by
// PasswordManagerBrowserTestBase. // PasswordManagerBrowserTestBase.
...@@ -129,6 +133,9 @@ class BubbleObserver { ...@@ -129,6 +133,9 @@ class BubbleObserver {
bool WaitForFallbackForSaving( bool WaitForFallbackForSaving(
const base::TimeDelta timeout = base::TimeDelta::Max()) const; const base::TimeDelta timeout = base::TimeDelta::Max()) const;
// Returns once the prompt for saving unsynced credentials pops up.
void WaitForSaveUnsyncedCredentialsPrompt() const;
private: private:
ManagePasswordsUIController* const passwords_ui_controller_; ManagePasswordsUIController* const passwords_ui_controller_;
......
...@@ -23,11 +23,13 @@ ...@@ -23,11 +23,13 @@
#include "components/password_manager/core/browser/password_manager_features_util.h" #include "components/password_manager/core/browser/password_manager_features_util.h"
#include "components/password_manager/core/browser/password_manager_test_utils.h" #include "components/password_manager/core/browser/password_manager_test_utils.h"
#include "components/password_manager/core/common/password_manager_features.h" #include "components/password_manager/core/common/password_manager_features.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/sync/driver/profile_sync_service.h" #include "components/sync/driver/profile_sync_service.h"
#include "components/sync/driver/sync_driver_switches.h" #include "components/sync/driver/sync_driver_switches.h"
#include "components/sync/test/fake_server/fake_server_nigori_helper.h" #include "components/sync/test/fake_server/fake_server_nigori_helper.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/http/http_status_code.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"
...@@ -96,9 +98,12 @@ class PasswordManagerSyncTest : public SyncTest { ...@@ -96,9 +98,12 @@ class PasswordManagerSyncTest : public SyncTest {
SyncTest::TearDownOnMainThread(); SyncTest::TearDownOnMainThread();
} }
// Also stores the AccountInfo for the signed-in account in
// |signed_in_account_| as a side effect.
void SetupSyncTransportWithPasswordAccountStorage() { void SetupSyncTransportWithPasswordAccountStorage() {
ASSERT_TRUE(signed_in_account_.IsEmpty());
// Setup Sync for a secondary account (i.e. in transport mode). // Setup Sync for a secondary account (i.e. in transport mode).
secondary_account_helper::SignInSecondaryAccount( signed_in_account_ = secondary_account_helper::SignInSecondaryAccount(
GetProfile(0), &test_url_loader_factory_, "user@email.com"); GetProfile(0), &test_url_loader_factory_, "user@email.com");
ASSERT_TRUE(GetClient(0)->AwaitSyncTransportActive()); ASSERT_TRUE(GetClient(0)->AwaitSyncTransportActive());
ASSERT_FALSE(GetSyncService(0)->IsSyncFeatureEnabled()); ASSERT_FALSE(GetSyncService(0)->IsSyncFeatureEnabled());
...@@ -111,6 +116,15 @@ class PasswordManagerSyncTest : public SyncTest { ...@@ -111,6 +116,15 @@ class PasswordManagerSyncTest : public SyncTest {
ASSERT_TRUE(GetSyncService(0)->GetActiveDataTypes().Has(syncer::PASSWORDS)); ASSERT_TRUE(GetSyncService(0)->GetActiveDataTypes().Has(syncer::PASSWORDS));
} }
// Should only be called after SetupSyncTransportWithPasswordAccountStorage().
void SignOut() {
ASSERT_FALSE(signed_in_account_.IsEmpty());
secondary_account_helper::SignOutSecondaryAccount(
GetProfile(0), &test_url_loader_factory_,
signed_in_account_.account_id);
signed_in_account_ = AccountInfo();
}
GURL GetWWWOrigin() { GURL GetWWWOrigin() {
return embedded_test_server()->GetURL("www.example.com", "/"); return embedded_test_server()->GetURL("www.example.com", "/");
} }
...@@ -223,6 +237,7 @@ class PasswordManagerSyncTest : public SyncTest { ...@@ -223,6 +237,7 @@ class PasswordManagerSyncTest : public SyncTest {
private: private:
base::test::ScopedFeatureList feature_list_; base::test::ScopedFeatureList feature_list_;
AccountInfo signed_in_account_;
secondary_account_helper::ScopedSigninClientFactory secondary_account_helper::ScopedSigninClientFactory
test_signin_client_factory_; test_signin_client_factory_;
...@@ -572,6 +587,42 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerSyncTest, ...@@ -572,6 +587,42 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerSyncTest,
MatchesLoginAndRealm("user", "pass", GetWWWOrigin()), MatchesLoginAndRealm("user", "pass", GetWWWOrigin()),
MatchesLoginAndRealm("user", "pass", GetPSLOrigin()))); MatchesLoginAndRealm("user", "pass", GetPSLOrigin())));
} }
IN_PROC_BROWSER_TEST_F(
PasswordManagerSyncTest,
SaveInProfileStoreIfSaveButtonClickedInUnsyncedPasswordsBubble) {
ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
content::WebContents* web_contents = nullptr;
GetNewTab(GetBrowser(0), &web_contents);
SetupSyncTransportWithPasswordAccountStorage();
// Force credentials saved to the account to be unsynced.
GetFakeServer()->SetHttpError(net::HTTP_BAD_REQUEST);
NavigateToFile(web_contents, "/password/password_form.html");
FillAndSubmitPasswordForm(web_contents, "accountuser", "accountpass");
// Save the password in the account store.
BubbleObserver bubble_observer(web_contents);
bubble_observer.AcceptSavePrompt();
std::vector<std::unique_ptr<autofill::PasswordForm>> account_credentials =
GetAllLoginsFromAccountPasswordStore();
ASSERT_THAT(account_credentials,
ElementsAre(MatchesLogin("accountuser", "accountpass")));
SignOut();
// Fake user clicking the Save button in the UI.
bubble_observer.WaitForSaveUnsyncedCredentialsPrompt();
bubble_observer.AcceptSaveUnsyncedCredentialsPrompt();
std::vector<std::unique_ptr<autofill::PasswordForm>> profile_credentials =
GetAllLoginsFromProfilePasswordStore();
EXPECT_THAT(profile_credentials,
ElementsAre(MatchesLogin("accountuser", "accountpass")));
}
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
} // namespace } // namespace
...@@ -95,7 +95,7 @@ class ManagePasswordsUIController ...@@ -95,7 +95,7 @@ class ManagePasswordsUIController
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_move) std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_move)
override; override;
void NotifyUnsyncedCredentialsWillBeDeleted( virtual void NotifyUnsyncedCredentialsWillBeDeleted(
const std::vector<autofill::PasswordForm>& unsynced_credentials); const std::vector<autofill::PasswordForm>& unsynced_credentials);
// PasswordStore::Observer: // PasswordStore::Observer:
......
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