Commit 04546240 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Add Skeleton for BulkLeakCheckServiceAdapter

This change adds a skeleton for a BulkLeakCheckServiceAdapter, which is
supposed to be used by the settings page to interact with the bulk leak
check service.

Bug: 1047726
Change-Id: I587a4f0511e8b9b197d4a79bac81ca90a6979215
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2054155
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741389}
parent 8ce966f6
...@@ -216,6 +216,8 @@ jumbo_static_library("browser") { ...@@ -216,6 +216,8 @@ jumbo_static_library("browser") {
"sync/password_syncable_service.h", "sync/password_syncable_service.h",
"sync_credentials_filter.cc", "sync_credentials_filter.cc",
"sync_credentials_filter.h", "sync_credentials_filter.h",
"ui/bulk_leak_check_service_adapter.cc",
"ui/bulk_leak_check_service_adapter.h",
"ui/compromised_credentials_provider.cc", "ui/compromised_credentials_provider.cc",
"ui/compromised_credentials_provider.h", "ui/compromised_credentials_provider.h",
"ui/credential_provider_interface.h", "ui/credential_provider_interface.h",
...@@ -573,6 +575,7 @@ source_set("unit_tests") { ...@@ -573,6 +575,7 @@ source_set("unit_tests") {
"sync_credentials_filter_unittest.cc", "sync_credentials_filter_unittest.cc",
"sync_username_test_base.cc", "sync_username_test_base.cc",
"sync_username_test_base.h", "sync_username_test_base.h",
"ui/bulk_leak_check_service_adapter_unittest.cc",
"ui/compromised_credentials_provider_unittest.cc", "ui/compromised_credentials_provider_unittest.cc",
"vote_uploads_test_matchers.h", "vote_uploads_test_matchers.h",
"votes_uploader_unittest.cc", "votes_uploader_unittest.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/password_manager/core/browser/ui/bulk_leak_check_service_adapter.h"
#include "base/logging.h"
namespace password_manager {
BulkLeakCheckServiceAdapter::BulkLeakCheckServiceAdapter(
SavedPasswordsPresenter* presenter,
BulkLeakCheckService* service)
: presenter_(presenter), service_(service) {
DCHECK(presenter_);
DCHECK(service_);
presenter_->AddObserver(this);
}
BulkLeakCheckServiceAdapter::~BulkLeakCheckServiceAdapter() {
presenter_->RemoveObserver(this);
}
void BulkLeakCheckServiceAdapter::StartBulkLeakCheck() {
// TODO(crbug.com/1047726): Implement.
NOTIMPLEMENTED();
}
void BulkLeakCheckServiceAdapter::StopBulkLeakCheck() {
// TODO(crbug.com/1047726): Implement.
NOTIMPLEMENTED();
}
BulkLeakCheckService::State BulkLeakCheckServiceAdapter::GetBulkLeakCheckState()
const {
return service_->state();
}
size_t BulkLeakCheckServiceAdapter::GetPendingChecksCount() const {
return service_->GetPendingChecksCount();
}
void BulkLeakCheckServiceAdapter::OnEdited(const autofill::PasswordForm& form) {
// TODO(crbug.com/1047726): Implement.
NOTIMPLEMENTED();
}
} // namespace password_manager
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_UI_BULK_LEAK_CHECK_SERVICE_ADAPTER_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_UI_BULK_LEAK_CHECK_SERVICE_ADAPTER_H_
#include "components/password_manager/core/browser/bulk_leak_check_service.h"
#include "components/password_manager/core/browser/ui/saved_passwords_presenter.h"
namespace password_manager {
// This class serves as an apdater for the BulkLeakCheckService and exposes an
// API that is intended to be consumed from the settings page.
class BulkLeakCheckServiceAdapter : public SavedPasswordsPresenter::Observer {
public:
BulkLeakCheckServiceAdapter(SavedPasswordsPresenter* presenter,
BulkLeakCheckService* service);
~BulkLeakCheckServiceAdapter() override;
// Instructs the adapter to start a check. This will obtain the list of saved
// passwords from |presenter_|, perform de-duplication of username and
// password pairs and then feed it to the |service_| for checking.
void StartBulkLeakCheck();
// This asks |service_| to stop an ongoing check.
void StopBulkLeakCheck();
// Obtains the state of the bulk leak check.
BulkLeakCheckService::State GetBulkLeakCheckState() const;
// Gets the list of pending checks.
size_t GetPendingChecksCount() const;
private:
// SavedPasswordsPresenter::Observer:
void OnEdited(const autofill::PasswordForm& form) override;
// Weak handles to a presenter and service, respectively. These must be not
// null and must outlive the adapter.
SavedPasswordsPresenter* presenter_ = nullptr;
BulkLeakCheckService* service_ = nullptr;
};
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_UI_BULK_LEAK_CHECK_SERVICE_ADAPTER_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/password_manager/core/browser/ui/bulk_leak_check_service_adapter.h"
#include "base/strings/string_piece_forward.h"
#include "base/test/task_environment.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/bulk_leak_check_service.h"
#include "components/password_manager/core/browser/leak_detection/mock_leak_detection_check_factory.h"
#include "components/password_manager/core/browser/ui/saved_passwords_presenter.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace password_manager {
namespace {
struct MockSavedPasswordsPresenter : SavedPasswordsPresenter {
MOCK_METHOD(void,
EditPassword,
(const autofill::PasswordForm&, base::StringPiece16),
(override));
MOCK_METHOD(std::vector<autofill::PasswordForm>,
GetSavedPasswords,
(),
(override));
};
class BulkLeakCheckServiceAdapterTest : public ::testing::Test {
public:
BulkLeakCheckServiceAdapterTest()
: service_(identity_test_env_.identity_manager(),
base::MakeRefCounted<network::TestSharedURLLoaderFactory>()) {
service_.set_leak_factory(
std::make_unique<MockLeakDetectionCheckFactory>());
}
BulkLeakCheckServiceAdapter& adapter() { return adapter_; }
private:
base::test::TaskEnvironment task_env_;
signin::IdentityTestEnvironment identity_test_env_;
::testing::StrictMock<MockSavedPasswordsPresenter> presenter_;
BulkLeakCheckService service_;
BulkLeakCheckServiceAdapter adapter_{&presenter_, &service_};
};
} // namespace
TEST_F(BulkLeakCheckServiceAdapterTest, OnCreation) {
EXPECT_EQ(0u, adapter().GetPendingChecksCount());
EXPECT_EQ(BulkLeakCheckService::State::kIdle,
adapter().GetBulkLeakCheckState());
}
} // namespace password_manager
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