Commit c6ff06af authored by Vasilii Sukhanov's avatar Vasilii Sukhanov Committed by Commit Bot

Enforce TestPasswordStore usage in the password manager browser tests.

Bug: 1116886
Change-Id: Icd7cbba98f0879959d0a3ea7a195c218a7621a63
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2360082
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799213}
parent 9c4ce76b
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/ui/tab_dialogs.h" #include "chrome/browser/ui/tab_dialogs.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_manager_test_utils.h"
#include "components/password_manager/core/browser/test_password_store.h" #include "components/password_manager/core/browser/test_password_store.h"
#include "components/password_manager/core/common/password_manager_features.h" #include "components/password_manager/core/common/password_manager_features.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
...@@ -157,9 +158,22 @@ class CapturedSitesPasswordManagerBrowserTest ...@@ -157,9 +158,22 @@ class CapturedSitesPasswordManagerBrowserTest
~CapturedSitesPasswordManagerBrowserTest() override = default; ~CapturedSitesPasswordManagerBrowserTest() override = default;
// InProcessBrowserTest: // InProcessBrowserTest:
void SetUpInProcessBrowserTestFixture() override {
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
create_services_subscription_ =
BrowserContextDependencyManager::GetInstance()
->RegisterCreateServicesCallbackForTesting(
base::BindRepeating([](content::BrowserContext* context) {
PasswordStoreFactory::GetInstance()->SetTestingFactory(
context, base::BindRepeating(
&password_manager::BuildPasswordStore<
content::BrowserContext,
password_manager::TestPasswordStore>));
}));
}
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
PasswordManagerBrowserTestBase::SetUpOnMainThreadAndGetNewTab( PasswordManagerBrowserTestBase::GetNewTab(browser(), &web_contents_);
browser(), &web_contents_);
recipe_replayer_ = recipe_replayer_ =
std::make_unique<captured_sites_test_utils::TestRecipeReplayer>( std::make_unique<captured_sites_test_utils::TestRecipeReplayer>(
browser(), this); browser(), this);
...@@ -212,6 +226,10 @@ class CapturedSitesPasswordManagerBrowserTest ...@@ -212,6 +226,10 @@ class CapturedSitesPasswordManagerBrowserTest
content::WebContents* web_contents_ = nullptr; content::WebContents* web_contents_ = nullptr;
std::unique_ptr<ServerUrlLoader> server_url_loader_; std::unique_ptr<ServerUrlLoader> server_url_loader_;
std::unique_ptr<
BrowserContextDependencyManager::CreateServicesCallbackList::Subscription>
create_services_subscription_;
DISALLOW_COPY_AND_ASSIGN(CapturedSitesPasswordManagerBrowserTest); DISALLOW_COPY_AND_ASSIGN(CapturedSitesPasswordManagerBrowserTest);
}; };
......
...@@ -444,31 +444,13 @@ void PasswordManagerBrowserTestBase::SetUpOnMainThread() { ...@@ -444,31 +444,13 @@ void PasswordManagerBrowserTestBase::SetUpOnMainThread() {
verify_result.verified_cert = cert; verify_result.verified_cert = cert;
mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK); mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK);
SetUpOnMainThreadAndGetNewTab(browser(), &web_contents_); GetNewTab(browser(), &web_contents_);
} }
void PasswordManagerBrowserTestBase::TearDownOnMainThread() { void PasswordManagerBrowserTestBase::TearDownOnMainThread() {
ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
} }
// static
void PasswordManagerBrowserTestBase::SetUpOnMainThreadAndGetNewTab(
Browser* browser,
content::WebContents** web_contents) {
// Use TestPasswordStore to remove a possible race. Normally the
// PasswordStore does its database manipulation on a background thread, which
// creates a possible race during navigation. Specifically the
// PasswordManager will ignore any forms in a page if the load from the
// PasswordStore has not completed.
PasswordStoreFactory::GetInstance()->SetTestingFactory(
browser->profile(),
base::BindRepeating(
&password_manager::BuildPasswordStore<
content::BrowserContext, password_manager::TestPasswordStore>));
GetNewTab(browser, web_contents);
}
// static // static
void PasswordManagerBrowserTestBase::GetNewTab( void PasswordManagerBrowserTestBase::GetNewTab(
Browser* browser, Browser* browser,
...@@ -681,17 +663,18 @@ void PasswordManagerBrowserTestBase::SetUpInProcessBrowserTestFixture() { ...@@ -681,17 +663,18 @@ void PasswordManagerBrowserTestBase::SetUpInProcessBrowserTestFixture() {
create_services_subscription_ = create_services_subscription_ =
BrowserContextDependencyManager::GetInstance() BrowserContextDependencyManager::GetInstance()
->RegisterCreateServicesCallbackForTesting( ->RegisterCreateServicesCallbackForTesting(
base::BindRepeating(&PasswordManagerBrowserTestBase:: base::BindRepeating([](content::BrowserContext* context) {
OnWillCreateBrowserContextServices)); // Set up a TestSyncService which will happily return
} // "everything is active" so that password generation is
// considered enabled.
// static
void PasswordManagerBrowserTestBase::OnWillCreateBrowserContextServices(
content::BrowserContext* context) {
// Set up a TestSyncService which will happily return "everything is active"
// so that password generation is considered enabled.
ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
context, base::BindRepeating(&BuildTestSyncService)); context, base::BindRepeating(&BuildTestSyncService));
PasswordStoreFactory::GetInstance()->SetTestingFactory(
context,
base::BindRepeating(&password_manager::BuildPasswordStore<
content::BrowserContext,
password_manager::TestPasswordStore>));
}));
} }
void PasswordManagerBrowserTestBase::AddHSTSHost(const std::string& host) { void PasswordManagerBrowserTestBase::AddHSTSHost(const std::string& host) {
......
...@@ -169,15 +169,6 @@ class PasswordManagerBrowserTestBase : public CertVerifierBrowserTest { ...@@ -169,15 +169,6 @@ class PasswordManagerBrowserTestBase : public CertVerifierBrowserTest {
void SetUpOnMainThread() override; void SetUpOnMainThread() override;
void TearDownOnMainThread() override; void TearDownOnMainThread() override;
// Bring up a new Chrome tab set up with password manager test hooks.
// @param[in] browser the browser running the password manager test, upon
// which this function will perform the setup steps.
// @param[out] a new tab on the browser set up with password manager test
// hooks.
static void SetUpOnMainThreadAndGetNewTab(
Browser* browser,
content::WebContents** web_contents);
// Creates a new tab with all the password manager test hooks and returns it // Creates a new tab with all the password manager test hooks and returns it
// in |web_contents|. // in |web_contents|.
static void GetNewTab(Browser* browser, content::WebContents** web_contents); static void GetNewTab(Browser* browser, content::WebContents** web_contents);
...@@ -248,9 +239,6 @@ class PasswordManagerBrowserTestBase : public CertVerifierBrowserTest { ...@@ -248,9 +239,6 @@ class PasswordManagerBrowserTestBase : public CertVerifierBrowserTest {
net::EmbeddedTestServer& https_test_server() { return https_test_server_; } net::EmbeddedTestServer& https_test_server() { return https_test_server_; }
private: private:
static void OnWillCreateBrowserContextServices(
content::BrowserContext* context);
net::EmbeddedTestServer https_test_server_; net::EmbeddedTestServer https_test_server_;
// A tab with some hooks injected. // A tab with some hooks injected.
content::WebContents* web_contents_; content::WebContents* web_contents_;
......
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