Commit 07c57907 authored by Nela Kaczmarek's avatar Nela Kaczmarek Committed by Commit Bot

Add Affiliation Fetcher interface and mock class.

Bug: 1108279
Change-Id: I0d50e041c78f871fa9167ff157aa301559c6ff91
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341646
Commit-Queue: Nela Kaczmarek <nelakaczmarek@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796441}
parent 6c2ddda1
...@@ -44,6 +44,7 @@ static_library("browser") { ...@@ -44,6 +44,7 @@ static_library("browser") {
"android_affiliation/affiliation_fetcher.cc", "android_affiliation/affiliation_fetcher.cc",
"android_affiliation/affiliation_fetcher.h", "android_affiliation/affiliation_fetcher.h",
"android_affiliation/affiliation_fetcher_delegate.h", "android_affiliation/affiliation_fetcher_delegate.h",
"android_affiliation/affiliation_fetcher_interface.h",
"android_affiliation/android_affiliation_service.cc", "android_affiliation/android_affiliation_service.cc",
"android_affiliation/android_affiliation_service.h", "android_affiliation/android_affiliation_service.h",
"android_affiliation/facet_manager.cc", "android_affiliation/facet_manager.cc",
...@@ -451,6 +452,8 @@ static_library("test_support") { ...@@ -451,6 +452,8 @@ static_library("test_support") {
"android_affiliation/mock_affiliated_match_helper.h", "android_affiliation/mock_affiliated_match_helper.h",
"android_affiliation/mock_affiliation_consumer.cc", "android_affiliation/mock_affiliation_consumer.cc",
"android_affiliation/mock_affiliation_consumer.h", "android_affiliation/mock_affiliation_consumer.h",
"android_affiliation/mock_affiliation_fetcher.cc",
"android_affiliation/mock_affiliation_fetcher.h",
"fake_form_fetcher.cc", "fake_form_fetcher.cc",
"fake_form_fetcher.h", "fake_form_fetcher.h",
"mock_bulk_leak_check_service.cc", "mock_bulk_leak_check_service.cc",
......
...@@ -256,9 +256,8 @@ bool AffiliationBackend::OnCanSendNetworkRequest() { ...@@ -256,9 +256,8 @@ bool AffiliationBackend::OnCanSendNetworkRequest() {
if (requested_facet_uris.empty()) if (requested_facet_uris.empty())
return false; return false;
fetcher_.reset(AffiliationFetcher::Create(url_loader_factory_, fetcher_.reset(AffiliationFetcher::Create(url_loader_factory_, this));
requested_facet_uris, this)); fetcher_->StartRequest(requested_facet_uris);
fetcher_->StartRequest();
ReportStatistics(requested_facet_uris.size()); ReportStatistics(requested_facet_uris.size());
return true; return true;
} }
......
...@@ -44,10 +44,8 @@ static TestAffiliationFetcherFactory* g_testing_factory = nullptr; ...@@ -44,10 +44,8 @@ static TestAffiliationFetcherFactory* g_testing_factory = nullptr;
AffiliationFetcher::AffiliationFetcher( AffiliationFetcher::AffiliationFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_uris,
AffiliationFetcherDelegate* delegate) AffiliationFetcherDelegate* delegate)
: url_loader_factory_(std::move(url_loader_factory)), : url_loader_factory_(std::move(url_loader_factory)),
requested_facet_uris_(facet_uris),
delegate_(delegate) { delegate_(delegate) {
for (const FacetURI& uri : requested_facet_uris_) { for (const FacetURI& uri : requested_facet_uris_) {
DCHECK(uri.is_valid()); DCHECK(uri.is_valid());
...@@ -59,14 +57,12 @@ AffiliationFetcher::~AffiliationFetcher() = default; ...@@ -59,14 +57,12 @@ AffiliationFetcher::~AffiliationFetcher() = default;
// static // static
AffiliationFetcher* AffiliationFetcher::Create( AffiliationFetcher* AffiliationFetcher::Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_uris,
AffiliationFetcherDelegate* delegate) { AffiliationFetcherDelegate* delegate) {
if (g_testing_factory) { if (g_testing_factory) {
return g_testing_factory->CreateInstance(std::move(url_loader_factory), return g_testing_factory->CreateInstance(std::move(url_loader_factory),
facet_uris, delegate); delegate);
} }
return new AffiliationFetcher(std::move(url_loader_factory), facet_uris, return new AffiliationFetcher(std::move(url_loader_factory), delegate);
delegate);
} }
// static // static
...@@ -75,8 +71,9 @@ void AffiliationFetcher::SetFactoryForTesting( ...@@ -75,8 +71,9 @@ void AffiliationFetcher::SetFactoryForTesting(
g_testing_factory = factory; g_testing_factory = factory;
} }
void AffiliationFetcher::StartRequest() { void AffiliationFetcher::StartRequest(const std::vector<FacetURI>& facet_uris) {
DCHECK(!simple_url_loader_); DCHECK(!simple_url_loader_);
requested_facet_uris_ = facet_uris;
net::NetworkTrafficAnnotationTag traffic_annotation = net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("affiliation_lookup", R"( net::DefineNetworkTrafficAnnotation("affiliation_lookup", R"(
...@@ -125,6 +122,14 @@ void AffiliationFetcher::StartRequest() { ...@@ -125,6 +122,14 @@ void AffiliationFetcher::StartRequest() {
base::Unretained(this))); base::Unretained(this)));
} }
const std::vector<FacetURI>& AffiliationFetcher::GetRequestedFacetURIs() const {
return requested_facet_uris_;
}
AffiliationFetcherDelegate* AffiliationFetcher::delegate() const {
return delegate_;
}
// static // static
GURL AffiliationFetcher::BuildQueryURL() { GURL AffiliationFetcher::BuildQueryURL() {
return net::AppendQueryParameter( return net::AppendQueryParameter(
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher_delegate.h" #include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher_interface.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h"
class GURL; class GURL;
...@@ -31,16 +30,15 @@ class TestAffiliationFetcherFactory; ...@@ -31,16 +30,15 @@ class TestAffiliationFetcherFactory;
// //
// An instance is good for exactly one fetch, and may be used from any thread // An instance is good for exactly one fetch, and may be used from any thread
// that runs a message loop (i.e. not a worker pool thread). // that runs a message loop (i.e. not a worker pool thread).
class AffiliationFetcher { class AffiliationFetcher : public AffiliationFetcherInterface {
public: public:
~AffiliationFetcher(); ~AffiliationFetcher() override;
// Constructs a fetcher to retrieve affiliations for each facet in |facet_ids| // Constructs a fetcher using the specified |url_loader_factory|, and will
// using the specified |url_loader_factory|, and will provide the results // provide the results to the |delegate| on the same thread that creates the
// to the |delegate| on the same thread that creates the instance. // instance.
static AffiliationFetcher* Create( static AffiliationFetcher* Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_uris,
AffiliationFetcherDelegate* delegate); AffiliationFetcherDelegate* delegate);
// Builds the URL for the Affiliation API's lookup method. // Builds the URL for the Affiliation API's lookup method.
...@@ -53,25 +51,22 @@ class AffiliationFetcher { ...@@ -53,25 +51,22 @@ class AffiliationFetcher {
// calls. The caller may pass in NULL to resume using the default factory. // calls. The caller may pass in NULL to resume using the default factory.
static void SetFactoryForTesting(TestAffiliationFetcherFactory* factory); static void SetFactoryForTesting(TestAffiliationFetcherFactory* factory);
// Actually starts the request, and will call the delegate with the results on // Actually starts the request to retrieve affiliations for each facet in
// the same thread when done. If |this| is destroyed before completion, the // |facet_uris|, and will call the delegate with the results on the same
// in-flight request is cancelled, and the delegate will not be called. // thread when done. If |this| is destroyed before completion, the in-flight
// Further details: // request is cancelled, and the delegate will not be called. Further details:
// * No cookies are sent/saved with the request. // * No cookies are sent/saved with the request.
// * In case of network/server errors, the request will not be retried. // * In case of network/server errors, the request will not be retried.
// * Results are guaranteed to be always fresh and will never be cached. // * Results are guaranteed to be always fresh and will never be cached.
void StartRequest(); void StartRequest(const std::vector<FacetURI>& facet_uris) override;
const std::vector<FacetURI>& requested_facet_uris() const { const std::vector<FacetURI>& GetRequestedFacetURIs() const override;
return requested_facet_uris_;
}
AffiliationFetcherDelegate* delegate() const { return delegate_; } AffiliationFetcherDelegate* delegate() const;
protected: protected:
AffiliationFetcher( AffiliationFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_uris,
AffiliationFetcherDelegate* delegate); AffiliationFetcherDelegate* delegate);
private: private:
...@@ -91,7 +86,7 @@ class AffiliationFetcher { ...@@ -91,7 +86,7 @@ class AffiliationFetcher {
void OnSimpleLoaderComplete(std::unique_ptr<std::string> response_body); void OnSimpleLoaderComplete(std::unique_ptr<std::string> response_body);
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
const std::vector<FacetURI> requested_facet_uris_; std::vector<FacetURI> requested_facet_uris_;
AffiliationFetcherDelegate* const delegate_; AffiliationFetcherDelegate* const delegate_;
std::unique_ptr<network::SimpleURLLoader> simple_url_loader_; std::unique_ptr<network::SimpleURLLoader> simple_url_loader_;
......
// 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_ANDROID_AFFILIATION_AFFILIATION_FETCHER_INTERFACE_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_ANDROID_AFFILIATION_AFFILIATION_FETCHER_INTERFACE_H_
#include <vector>
#include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher_delegate.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h"
namespace password_manager {
class AffiliationFetcherInterface {
public:
AffiliationFetcherInterface() = default;
virtual ~AffiliationFetcherInterface() = default;
// Not copyable or movable
AffiliationFetcherInterface(const AffiliationFetcherInterface&) = delete;
AffiliationFetcherInterface& operator=(const AffiliationFetcherInterface&) =
delete;
AffiliationFetcherInterface(AffiliationFetcherInterface&&) = delete;
AffiliationFetcherInterface& operator=(AffiliationFetcherInterface&&) =
delete;
// Starts the request to retrieve affiliations for each facet in
// |facet_uris|.
virtual void StartRequest(const std::vector<FacetURI>& facet_uris) = 0;
// Returns requested facet uris.
virtual const std::vector<FacetURI>& GetRequestedFacetURIs() const = 0;
};
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_ANDROID_AFFILIATION_AFFILIATION_FETCHER_INTERFACE_H_
...@@ -146,9 +146,9 @@ TEST_F(AffiliationFetcherTest, BasicReqestAndResponse) { ...@@ -146,9 +146,9 @@ TEST_F(AffiliationFetcherTest, BasicReqestAndResponse) {
SetupSuccessfulResponse(test_response.SerializeAsString()); SetupSuccessfulResponse(test_response.SerializeAsString());
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnFetchSucceededProxy()); EXPECT_CALL(mock_delegate, OnFetchSucceededProxy());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), requested_uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(requested_uris);
WaitForResponse(); WaitForResponse();
ASSERT_NO_FATAL_FAILURE(VerifyRequestPayload(requested_uris)); ASSERT_NO_FATAL_FAILURE(VerifyRequestPayload(requested_uris));
...@@ -185,9 +185,9 @@ TEST_F(AffiliationFetcherTest, AndroidBrandingInfoIsReturnedIfPresent) { ...@@ -185,9 +185,9 @@ TEST_F(AffiliationFetcherTest, AndroidBrandingInfoIsReturnedIfPresent) {
SetupSuccessfulResponse(test_response.SerializeAsString()); SetupSuccessfulResponse(test_response.SerializeAsString());
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnFetchSucceededProxy()); EXPECT_CALL(mock_delegate, OnFetchSucceededProxy());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), requested_uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(requested_uris);
WaitForResponse(); WaitForResponse();
ASSERT_NO_FATAL_FAILURE(VerifyRequestPayload(requested_uris)); ASSERT_NO_FATAL_FAILURE(VerifyRequestPayload(requested_uris));
...@@ -216,9 +216,9 @@ TEST_F(AffiliationFetcherTest, MissingEquivalenceClassesAreCreated) { ...@@ -216,9 +216,9 @@ TEST_F(AffiliationFetcherTest, MissingEquivalenceClassesAreCreated) {
SetupSuccessfulResponse(empty_test_response.SerializeAsString()); SetupSuccessfulResponse(empty_test_response.SerializeAsString());
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnFetchSucceededProxy()); EXPECT_CALL(mock_delegate, OnFetchSucceededProxy());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), requested_uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(requested_uris);
WaitForResponse(); WaitForResponse();
ASSERT_NO_FATAL_FAILURE(VerifyRequestPayload(requested_uris)); ASSERT_NO_FATAL_FAILURE(VerifyRequestPayload(requested_uris));
...@@ -247,9 +247,9 @@ TEST_F(AffiliationFetcherTest, DuplicateEquivalenceClassesAreIgnored) { ...@@ -247,9 +247,9 @@ TEST_F(AffiliationFetcherTest, DuplicateEquivalenceClassesAreIgnored) {
SetupSuccessfulResponse(test_response.SerializeAsString()); SetupSuccessfulResponse(test_response.SerializeAsString());
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnFetchSucceededProxy()); EXPECT_CALL(mock_delegate, OnFetchSucceededProxy());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), requested_uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(requested_uris);
WaitForResponse(); WaitForResponse();
ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&mock_delegate)); ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&mock_delegate));
...@@ -275,9 +275,9 @@ TEST_F(AffiliationFetcherTest, EmptyEquivalenceClassesAreIgnored) { ...@@ -275,9 +275,9 @@ TEST_F(AffiliationFetcherTest, EmptyEquivalenceClassesAreIgnored) {
SetupSuccessfulResponse(test_response.SerializeAsString()); SetupSuccessfulResponse(test_response.SerializeAsString());
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnFetchSucceededProxy()); EXPECT_CALL(mock_delegate, OnFetchSucceededProxy());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), requested_uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(requested_uris);
WaitForResponse(); WaitForResponse();
ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&mock_delegate)); ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&mock_delegate));
...@@ -307,9 +307,9 @@ TEST_F(AffiliationFetcherTest, UnrecognizedFacetURIsAreIgnored) { ...@@ -307,9 +307,9 @@ TEST_F(AffiliationFetcherTest, UnrecognizedFacetURIsAreIgnored) {
SetupSuccessfulResponse(test_response.SerializeAsString()); SetupSuccessfulResponse(test_response.SerializeAsString());
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnFetchSucceededProxy()); EXPECT_CALL(mock_delegate, OnFetchSucceededProxy());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), requested_uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(requested_uris);
WaitForResponse(); WaitForResponse();
ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&mock_delegate)); ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&mock_delegate));
...@@ -331,9 +331,9 @@ TEST_F(AffiliationFetcherTest, FailureBecauseResponseIsNotAProtobuf) { ...@@ -331,9 +331,9 @@ TEST_F(AffiliationFetcherTest, FailureBecauseResponseIsNotAProtobuf) {
SetupSuccessfulResponse(kMalformedResponse); SetupSuccessfulResponse(kMalformedResponse);
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnMalformedResponse()); EXPECT_CALL(mock_delegate, OnMalformedResponse());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(uris);
WaitForResponse(); WaitForResponse();
} }
...@@ -355,9 +355,9 @@ TEST_F(AffiliationFetcherTest, ...@@ -355,9 +355,9 @@ TEST_F(AffiliationFetcherTest,
SetupSuccessfulResponse(test_response.SerializeAsString()); SetupSuccessfulResponse(test_response.SerializeAsString());
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnMalformedResponse()); EXPECT_CALL(mock_delegate, OnMalformedResponse());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(uris);
WaitForResponse(); WaitForResponse();
} }
...@@ -368,9 +368,9 @@ TEST_F(AffiliationFetcherTest, FailOnServerError) { ...@@ -368,9 +368,9 @@ TEST_F(AffiliationFetcherTest, FailOnServerError) {
SetupServerErrorResponse(); SetupServerErrorResponse();
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnFetchFailed()); EXPECT_CALL(mock_delegate, OnFetchFailed());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(uris);
WaitForResponse(); WaitForResponse();
} }
...@@ -381,9 +381,9 @@ TEST_F(AffiliationFetcherTest, FailOnNetworkError) { ...@@ -381,9 +381,9 @@ TEST_F(AffiliationFetcherTest, FailOnNetworkError) {
SetupNetworkErrorResponse(); SetupNetworkErrorResponse();
MockAffiliationFetcherDelegate mock_delegate; MockAffiliationFetcherDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnFetchFailed()); EXPECT_CALL(mock_delegate, OnFetchFailed());
std::unique_ptr<AffiliationFetcher> fetcher(AffiliationFetcher::Create( std::unique_ptr<AffiliationFetcher> fetcher(
test_shared_loader_factory(), uris, &mock_delegate)); AffiliationFetcher::Create(test_shared_loader_factory(), &mock_delegate));
fetcher->StartRequest(); fetcher->StartRequest(uris);
WaitForResponse(); WaitForResponse();
} }
......
...@@ -33,7 +33,7 @@ bool ScopedFakeAffiliationAPI::HasPendingRequest() { ...@@ -33,7 +33,7 @@ bool ScopedFakeAffiliationAPI::HasPendingRequest() {
std::vector<FacetURI> ScopedFakeAffiliationAPI::GetNextRequestedFacets() { std::vector<FacetURI> ScopedFakeAffiliationAPI::GetNextRequestedFacets() {
if (fake_fetcher_factory_.has_pending_fetchers()) if (fake_fetcher_factory_.has_pending_fetchers())
return fake_fetcher_factory_.PeekNextFetcher()->requested_facet_uris(); return fake_fetcher_factory_.PeekNextFetcher()->GetRequestedFacetURIs();
return std::vector<FacetURI>(); return std::vector<FacetURI>();
} }
...@@ -46,7 +46,7 @@ void ScopedFakeAffiliationAPI::ServeNextRequest() { ...@@ -46,7 +46,7 @@ void ScopedFakeAffiliationAPI::ServeNextRequest() {
new AffiliationFetcherDelegate::Result); new AffiliationFetcherDelegate::Result);
for (const auto& preset_equivalence_class : preset_equivalence_relation_) { for (const auto& preset_equivalence_class : preset_equivalence_relation_) {
bool had_intersection_with_request = false; bool had_intersection_with_request = false;
for (const auto& requested_facet_uri : fetcher->requested_facet_uris()) { for (const auto& requested_facet_uri : fetcher->GetRequestedFacetURIs()) {
if (std::any_of(preset_equivalence_class.begin(), if (std::any_of(preset_equivalence_class.begin(),
preset_equivalence_class.end(), preset_equivalence_class.end(),
[&requested_facet_uri](const Facet& facet) { [&requested_facet_uri](const Facet& facet) {
......
...@@ -11,9 +11,8 @@ namespace password_manager { ...@@ -11,9 +11,8 @@ namespace password_manager {
password_manager::FakeAffiliationFetcher::FakeAffiliationFetcher( password_manager::FakeAffiliationFetcher::FakeAffiliationFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate) AffiliationFetcherDelegate* delegate)
: AffiliationFetcher(std::move(url_loader_factory), facet_ids, delegate) {} : AffiliationFetcher(std::move(url_loader_factory), delegate) {}
password_manager::FakeAffiliationFetcher::~FakeAffiliationFetcher() = default; password_manager::FakeAffiliationFetcher::~FakeAffiliationFetcher() = default;
...@@ -50,10 +49,9 @@ FakeAffiliationFetcher* ScopedFakeAffiliationFetcherFactory::PeekNextFetcher() { ...@@ -50,10 +49,9 @@ FakeAffiliationFetcher* ScopedFakeAffiliationFetcherFactory::PeekNextFetcher() {
AffiliationFetcher* ScopedFakeAffiliationFetcherFactory::CreateInstance( AffiliationFetcher* ScopedFakeAffiliationFetcherFactory::CreateInstance(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate) { AffiliationFetcherDelegate* delegate) {
FakeAffiliationFetcher* fetcher = new FakeAffiliationFetcher( FakeAffiliationFetcher* fetcher =
std::move(url_loader_factory), facet_ids, delegate); new FakeAffiliationFetcher(std::move(url_loader_factory), delegate);
pending_fetchers_.push(fetcher); pending_fetchers_.push(fetcher);
return fetcher; return fetcher;
} }
......
...@@ -21,9 +21,8 @@ class FakeAffiliationFetcher : public AffiliationFetcher { ...@@ -21,9 +21,8 @@ class FakeAffiliationFetcher : public AffiliationFetcher {
public: public:
FakeAffiliationFetcher( FakeAffiliationFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate); AffiliationFetcherDelegate* delegate);
~FakeAffiliationFetcher(); ~FakeAffiliationFetcher() override;
// Simulates successful completion of the request with |fake_result|. Note // Simulates successful completion of the request with |fake_result|. Note
// that the consumer may choose to destroy |this| from within this call. // that the consumer may choose to destroy |this| from within this call.
...@@ -66,7 +65,6 @@ class ScopedFakeAffiliationFetcherFactory ...@@ -66,7 +65,6 @@ class ScopedFakeAffiliationFetcherFactory
// AffiliationFetcherFactory: // AffiliationFetcherFactory:
AffiliationFetcher* CreateInstance( AffiliationFetcher* CreateInstance(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate) override; AffiliationFetcherDelegate* delegate) override;
private: private:
......
// 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/android_affiliation/mock_affiliation_fetcher.h"
namespace password_manager {
MockAffiliationFetcher::MockAffiliationFetcher() = default;
MockAffiliationFetcher::~MockAffiliationFetcher() = default;
} // 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_ANDROID_AFFILIATION_MOCK_AFFILIATION_FETCHER_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_ANDROID_AFFILIATION_MOCK_AFFILIATION_FETCHER_H_
#include <string>
#include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher_interface.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace password_manager {
class MockAffiliationFetcher : public AffiliationFetcherInterface {
public:
MockAffiliationFetcher();
~MockAffiliationFetcher() override;
MOCK_METHOD(void, StartRequest, (const std::vector<FacetURI>&), (override));
MOCK_METHOD(std::vector<FacetURI>&,
GetRequestedFacetURIs,
(),
(const, override));
};
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_ANDROID_AFFILIATION_MOCK_AFFILIATION_FETCHER_H_
...@@ -13,7 +13,6 @@ class SharedURLLoaderFactory; ...@@ -13,7 +13,6 @@ class SharedURLLoaderFactory;
namespace password_manager { namespace password_manager {
class FacetURI;
class AffiliationFetcherDelegate; class AffiliationFetcherDelegate;
// Interface for a factory to be used by AffiliationFetcher::Create() in tests // Interface for a factory to be used by AffiliationFetcher::Create() in tests
...@@ -27,7 +26,6 @@ class TestAffiliationFetcherFactory { ...@@ -27,7 +26,6 @@ class TestAffiliationFetcherFactory {
// to the |delegate| on the same thread that creates the instance. // to the |delegate| on the same thread that creates the instance.
virtual AffiliationFetcher* CreateInstance( virtual AffiliationFetcher* CreateInstance(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate) = 0; AffiliationFetcherDelegate* delegate) = 0;
protected: protected:
......
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