#include "components/plus_addresses/plus_address_service.h"
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "base/functional/callback_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "components/affiliations/core/browser/affiliation_utils.h"
#include "components/affiliations/core/browser/mock_affiliation_service.h"
#include "components/autofill/core/browser/ui/suggestion.h"
#include "components/autofill/core/browser/ui/suggestion_test_helpers.h"
#include "components/autofill/core/common/aliases.h"
#include "components/autofill/core/common/autofill_test_utils.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/plus_addresses/blocked_facets.pb.h"
#include "components/plus_addresses/features.h"
#include "components/plus_addresses/plus_address_blocklist_data.h"
#include "components/plus_addresses/plus_address_http_client_impl.h"
#include "components/plus_addresses/plus_address_preallocator.h"
#include "components/plus_addresses/plus_address_prefs.h"
#include "components/plus_addresses/plus_address_test_environment.h"
#include "components/plus_addresses/plus_address_test_utils.h"
#include "components/plus_addresses/plus_address_types.h"
#include "components/plus_addresses/settings/fake_plus_address_setting_service.h"
#include "components/plus_addresses/webdata/plus_address_sync_util.h"
#include "components/plus_addresses/webdata/plus_address_table.h"
#include "components/plus_addresses/webdata/plus_address_webdata_service.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/strings/grit/components_strings.h"
#include "components/webdata/common/web_database.h"
#include "components/webdata/common/web_database_backend.h"
#include "components/webdata/common/web_database_service.h"
#include "net/http/http_status_code.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace plus_addresses {
namespace {
PasswordFormClassification;
SuggestionEvent;
FacetURI;
AutofillSuggestionTriggerSource;
EqualsSuggestion;
FormFieldData;
Suggestion;
SuggestionType;
RunOnceCallback;
CreatePreallocatedPlusAddress;
AllOf;
ElementsAre;
Field;
IsEmpty;
NiceMock;
UnorderedElementsAre;
constexpr char kPlusAddress[] = …;
auto IsSingleCreatePlusAddressSuggestion() { … }
auto EqualsFillPlusAddressSuggestion(std::string_view address) { … }
auto IsSingleFillPlusAddressSuggestion(std::string_view address) { … }
MATCHER_P(IsPreallocatedPlusAddress, address, "") { … }
url::Origin OriginFromFacet(const affiliations::FacetURI& facet) { … }
}
class MockPlusAddressServiceObserver : public PlusAddressService::Observer { … };
class PlusAddressServiceTest : public ::testing::Test { … };
TEST_F(PlusAddressServiceTest, BasicTest) { … }
TEST_F(PlusAddressServiceTest, GetPlusProfileByFacet) { … }
TEST_F(PlusAddressServiceTest, DefaultShouldShowManualFallbackState) { … }
TEST_F(PlusAddressServiceTest, ShouldShowManualFallbackNoServer) { … }
TEST_F(PlusAddressServiceTest, NoAccountPlusAddressCreation) { … }
TEST_F(PlusAddressServiceTest, AbortPlusAddressCreation) { … }
TEST_F(PlusAddressServiceTest, GetPlusProfiles) { … }
class PlusAddressServiceRequestsTest : public PlusAddressServiceTest { … };
TEST_F(PlusAddressServiceRequestsTest, ReservePlusAddress_ReturnsUnconfirmed) { … }
TEST_F(PlusAddressServiceRequestsTest, ReservePlusAddress_ReturnsConfirmed) { … }
TEST_F(PlusAddressServiceRequestsTest, ReservePlusAddress_Fails) { … }
TEST_F(PlusAddressServiceRequestsTest, ConfirmPlusAddress_Successful) { … }
TEST_F(PlusAddressServiceRequestsTest, ConfirmPlusAddress_Fails) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(PlusAddressServiceRequestsTest,
PrimaryAccountCleared_TogglesPlusAddressCreationOff) { … }
#endif
TEST_F(PlusAddressServiceRequestsTest,
PrimaryRefreshTokenError_ResetsHttpRequests) { … }
TEST_F(PlusAddressServiceRequestsTest,
PrimaryRefreshTokenError_TogglesPlusAddressCreationOff) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(PlusAddressServiceRequestsTest, OngoingRequestsCancelledOnSignout) { … }
#endif
class PlusAddressServicePreAllocationTest
: public PlusAddressServiceRequestsTest { … };
TEST_F(PlusAddressServicePreAllocationTest,
ConfirmationRemovesAllocatedPlusAddress) { … }
class PlusAddressHttpForbiddenResponseTest
: public PlusAddressServiceRequestsTest { … };
TEST_F(PlusAddressHttpForbiddenResponseTest, RepeatedHttpForbiddenFromConfirm) { … }
TEST_F(PlusAddressHttpForbiddenResponseTest,
RepeatedHttpForbiddenFromConfirmWithDisabledParam) { … }
TEST_F(PlusAddressHttpForbiddenResponseTest, OtherErrorsHaveNoEffect) { … }
TEST_F(PlusAddressHttpForbiddenResponseTest, NoDisablingAfterSuccess) { … }
class PlusAddressServiceWebDataTest : public ::testing::Test { … };
TEST_F(PlusAddressServiceWebDataTest, OnWebDataChangedBySync) { … }
class PlusAddressServiceDisabledTest : public PlusAddressServiceTest { … };
TEST_F(PlusAddressServiceDisabledTest, FeatureExplicitlyDisabled) { … }
class PlusAddressServiceEnabledTest : public PlusAddressServiceTest { … };
TEST_F(PlusAddressServiceEnabledTest, NoSignedInUser) { … }
TEST_F(PlusAddressServiceEnabledTest, FullySupported) { … }
TEST_F(PlusAddressServiceEnabledTest, ExcludedSitesAreNotSupported) { … }
TEST_F(PlusAddressServiceEnabledTest, BlocklistMechanism) { … }
TEST_F(PlusAddressServiceEnabledTest, NonHTTPSchemesAreNotSupported) { … }
TEST_F(PlusAddressServiceEnabledTest, OpaqueOriginIsNotSupported) { … }
TEST_F(PlusAddressServiceEnabledTest, OTRWithNoExistingAddress) { … }
TEST_F(PlusAddressServiceEnabledTest, OTRWithExistingAddress) { … }
TEST_F(PlusAddressServiceEnabledTest, GlobalSettingsToggleOff) { … }
TEST_F(PlusAddressServiceEnabledTest,
GlobalSettingsToggleOffButTheUserHasPlusAddress) { … }
TEST_F(PlusAddressServiceEnabledTest, SignedOutGetEmail) { … }
TEST_F(PlusAddressServiceEnabledTest, SignedInGetEmail) { … }
class PlusAddressServiceSignoutTest : public PlusAddressServiceTest { … };
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(PlusAddressServiceSignoutTest, PrimaryAccountCleared_TogglesIsEnabled) { … }
#endif
TEST_F(PlusAddressServiceSignoutTest,
PrimaryRefreshTokenError_TogglesIsEnabled) { … }
class PlusAddressSuggestionsTest : public PlusAddressServiceTest { … };
TEST_F(PlusAddressSuggestionsTest, SuggestionsForExistingPlusAddress) { … }
TEST_F(PlusAddressSuggestionsTest,
SuggestionsForExistingPlusAddressWithManualFallback) { … }
TEST_F(PlusAddressSuggestionsTest, SuggestionsForCreateNewPlusAddress) { … }
TEST_F(PlusAddressSuggestionsTest,
SuggestionsForCreateNewPlusAddressWithManualFallback) { … }
TEST_F(PlusAddressSuggestionsTest, NoSuggestionsWhenDisabled) { … }
TEST_F(PlusAddressSuggestionsTest, SuggestionsOnPasswordFormsUsernameField) { … }
TEST_F(PlusAddressSuggestionsTest, SuggestionsOnPasswordFormsNonUsernameField) { … }
TEST_F(PlusAddressSuggestionsTest,
SuggestionsOnPasswordFormWithSingleUsernameCreationEnabled) { … }
TEST_F(PlusAddressSuggestionsTest,
SuggestionsOnPasswordFormsWithManualFallbacks) { … }
TEST_F(PlusAddressSuggestionsTest, GetManagePlusAddressSuggestion) { … }
TEST_F(PlusAddressSuggestionsTest, OnClickedRefreshInlineSuggestion) { … }
class PlusAddressAffiliationsTest : public PlusAddressServiceTest { … };
TEST_F(PlusAddressAffiliationsTest, GetAffiliatedPSLSuggestions) { … }
TEST_F(PlusAddressAffiliationsTest, GetAffiliatedGroupSuggestions) { … }
TEST_F(PlusAddressAffiliationsTest,
GetSuggestionsIsAffiliationAwareWhenOffTheRecord) { … }
TEST_F(PlusAddressAffiliationsTest,
GetSuggestionsDoesNotOfferCreationWhenOffTheRecord) { … }
TEST_F(PlusAddressAffiliationsTest,
GetSuggestionsDoesNotOfferCreationWhenToggleIsOff) { … }
TEST_F(PlusAddressAffiliationsTest,
FillingSuggestionsAreOfferedWhenGlobalToggleIsOff) { … }
TEST_F(PlusAddressAffiliationsTest, GetEmptyAffiliatedSuggestionMatches) { … }
TEST_F(PlusAddressAffiliationsTest, GetAffiliatedPSLProfiles) { … }
TEST_F(PlusAddressAffiliationsTest,
AffiliatedProfilesForDomainWithNoPlusAddresses) { … }
}