#include "components/affiliations/core/browser/hash_affiliation_fetcher.h"
#include <memory>
#include <string>
#include "base/strings/string_number_conversions_win.h"
#include "base/test/bind.h"
#include "base/test/gmock_move_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "components/affiliations/core/browser/affiliation_service_impl.h"
#include "components/affiliations/core/browser/affiliation_utils.h"
#include "components/affiliations/core/browser/affiliation_api.pb.h"
#include "components/affiliations/core/browser/mock_affiliation_fetcher_delegate.h"
#include "components/variations/scoped_variations_ids_provider.h"
#include "crypto/sha2.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace affiliations {
namespace {
constexpr char kExampleAndroidFacetURI[] = …;
constexpr char kExampleAndroidPlayName[] = …;
constexpr char kExampleAndroidIconURL[] = …;
constexpr char kExampleWebFacet1URI[] = …;
constexpr char kExampleWebFacet2URI[] = …;
constexpr char kExampleWebFacet1ChangePasswordURI[] = …;
constexpr char kExampleWebFacet2ChangePasswordURI[] = …;
constexpr char k1ExampleURL[] = …;
constexpr uint64_t k1ExampleHash16LenPrefix = …;
constexpr char k2ExampleURL[] = …;
constexpr uint64_t k2ExampleHash16LenPrefix = …;
uint64_t ComputeHashPrefix(const FacetURI& uri) { … }
std::vector<uint64_t> ComputeHashes(const std::vector<FacetURI>& facet_uris) { … }
}
class HashAffiliationFetcherTest : public testing::Test { … };
void HashAffiliationFetcherTest::VerifyRequestPayload(
const std::vector<uint64_t>& expected_hash_prefixes,
HashAffiliationFetcher::RequestInfo request_info) { … }
TEST_F(HashAffiliationFetcherTest, BuildQueryURL) { … }
TEST_F(HashAffiliationFetcherTest, GetRequestedFacetURIs) { … }
TEST_F(HashAffiliationFetcherTest,
VerifyPayloadForMultipleHashesRequestWith16LengthPrefix) { … }
TEST_F(HashAffiliationFetcherTest, BasicRequestAndResponse) { … }
TEST_F(HashAffiliationFetcherTest, AndroidBrandingInfoIsReturnedIfPresent) { … }
TEST_F(HashAffiliationFetcherTest, ChangePasswordInfoIsReturnedIfPresent) { … }
TEST_F(HashAffiliationFetcherTest, MissingEquivalenceClassesAreCreated) { … }
TEST_F(HashAffiliationFetcherTest, DuplicateEquivalenceClassesAreIgnored) { … }
TEST_F(HashAffiliationFetcherTest, NonRequestedEquivalenceClassesAreIgnored) { … }
TEST_F(HashAffiliationFetcherTest, EmptyEquivalenceClassesAreIgnored) { … }
TEST_F(HashAffiliationFetcherTest, UnrecognizedFacetURIsAreIgnored) { … }
TEST_F(HashAffiliationFetcherTest, FailureBecauseResponseIsNotAProtobuf) { … }
TEST_F(HashAffiliationFetcherTest,
FailureBecausePartiallyOverlappingEquivalenceClasses) { … }
TEST_F(HashAffiliationFetcherTest, FailOnServerError) { … }
TEST_F(HashAffiliationFetcherTest, FailOnNetworkError) { … }
TEST_F(HashAffiliationFetcherTest, MetricsWhenSuccess) { … }
TEST_F(HashAffiliationFetcherTest, MetricsWhenFailed) { … }
TEST_F(HashAffiliationFetcherTest, GroupBrandingInfoIsReturnedIfPresent) { … }
}