Commit 0cc77b09 authored by Viktor Semeniuk's avatar Viktor Semeniuk Committed by Commit Bot

[Passwords] Use of HashAffiliationFetcher

This change replaces usage of AffiliationFetcher to
HashAffiliationFetcher depending on the feature state.

Bug: 1108279
Change-Id: I2398fc91ce14af80ef28a1e48dad61c60690366a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529109
Commit-Queue: Viktor Semeniuk <vsemeniuk@google.com>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826878}
parent 5fb9a6ed
......@@ -658,6 +658,7 @@ source_set("unit_tests") {
"password_ui_utils_unittest.cc",
"possible_username_data_unittest.cc",
"psl_matching_helper_unittest.cc",
"site_affiliation/affiliation_fetcher_factory_impl_unittest.cc",
"site_affiliation/affiliation_service_impl_unittest.cc",
"site_affiliation/asset_link_data_unittest.cc",
"site_affiliation/hash_affiliation_fetcher_unittest.cc",
......
......@@ -13,6 +13,7 @@
#include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h"
#include "components/password_manager/core/browser/android_affiliation/android_affiliation_service.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_user_settings.h"
......@@ -111,6 +112,10 @@ base::FilePath GetLoginDatabaseForAccountStoragePathForTesting(
}
bool ShouldAffiliationBasedMatchingBeActive(syncer::SyncService* sync_service) {
if (base::FeatureList::IsEnabled(
password_manager::features::kUseOfHashAffiliationFetcher)) {
return true;
}
return sync_service && sync_service->IsSyncFeatureActive() &&
sync_service->GetUserSettings()->GetSelectedTypes().Has(
syncer::UserSelectableType::kPasswords) &&
......
......@@ -5,6 +5,8 @@
#include "components/password_manager/core/browser/site_affiliation/affiliation_fetcher_factory_impl.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher.h"
#include "components/password_manager/core/browser/site_affiliation/hash_affiliation_fetcher.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace password_manager {
......@@ -16,6 +18,11 @@ std::unique_ptr<AffiliationFetcherInterface>
AffiliationFetcherFactoryImpl::CreateInstance(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
AffiliationFetcherDelegate* delegate) {
if (base::FeatureList::IsEnabled(
password_manager::features::kUseOfHashAffiliationFetcher)) {
return std::make_unique<HashAffiliationFetcher>(
std::move(url_loader_factory), delegate);
}
return std::make_unique<AffiliationFetcher>(std::move(url_loader_factory),
delegate);
}
......
// 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/site_affiliation/affiliation_fetcher_factory_impl.h"
#include "base/test/bind.h"
#include "base/test/gmock_move_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher_interface.h"
#include "components/password_manager/core/browser/android_affiliation/mock_affiliation_fetcher_delegate.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace password_manager {
class AffiliationFetcherFactoryImplTest : public testing::Test {
public:
AffiliationFetcherFactoryImplTest() {
test_url_loader_factory_.SetInterceptor(base::BindLambdaForTesting(
[&](const network::ResourceRequest& request) { url_ = request.url; }));
}
void CreateAndStartFetcher() {
MockAffiliationFetcherDelegate mock_delegate;
std::unique_ptr<AffiliationFetcherInterface> fetcher =
fetcher_factory_.CreateInstance(test_shared_loader_factory_,
&mock_delegate);
fetcher->StartRequest({}, {});
}
const GURL& url() const { return url_; }
void EnableHashAffiliationService() {
feature_list_.InitAndEnableFeature(
password_manager::features::kUseOfHashAffiliationFetcher);
}
void DisableHashAffiliationService() {
feature_list_.InitAndDisableFeature(
password_manager::features::kUseOfHashAffiliationFetcher);
}
private:
base::test::ScopedFeatureList feature_list_;
base::test::TaskEnvironment task_env_;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_ =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_);
AffiliationFetcherFactoryImpl fetcher_factory_;
GURL url_;
};
TEST_F(AffiliationFetcherFactoryImplTest, NormalAffiliationFetcher) {
DisableHashAffiliationService();
CreateAndStartFetcher();
EXPECT_TRUE(base::EndsWith(url().path_piece(), "lookup"));
}
TEST_F(AffiliationFetcherFactoryImplTest, HashAffiliationFetcher) {
EnableHashAffiliationService();
CreateAndStartFetcher();
EXPECT_TRUE(base::EndsWith(url().path_piece(), "lookupByHashPrefix"));
}
} // 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