#include "chrome/browser/ui/autofill/autofill_context_menu_manager.h"
#include <array>
#include <memory>
#include <optional>
#include <string>
#include "ash/constants/ash_switches.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/notreached.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/run_until.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autofill/autofill_uitest_util.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/password_manager/account_password_store_factory.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/password_manager/password_manager_uitest_util.h"
#include "chrome/browser/password_manager/passwords_navigation_observer.h"
#include "chrome/browser/password_manager/profile_password_store_factory.h"
#include "chrome/browser/plus_addresses/plus_address_service_factory.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/signin/signin_browser_test_base.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/autofill/address_bubbles_controller.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/autofill/content/browser/test_autofill_client_injector.h"
#include "components/autofill/content/browser/test_autofill_driver_injector.h"
#include "components/autofill/content/browser/test_content_autofill_client.h"
#include "components/autofill/core/browser/address_data_manager.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/browser_autofill_manager.h"
#include "components/autofill/core/browser/metrics/address_save_metrics.h"
#include "components/autofill/core/browser/metrics/manual_fallback_metrics.h"
#include "components/autofill/core/browser/payments_data_manager.h"
#include "components/autofill/core/browser/payments_data_manager_test_api.h"
#include "components/autofill/core/browser/personal_data_manager_test_utils.h"
#include "components/autofill/core/browser/test_autofill_manager_waiter.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_data_test_api.h"
#include "components/autofill/core/common/password_generation_util.h"
#include "components/autofill_prediction_improvements/core/browser/autofill_prediction_improvements_features.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/password_manager/content/browser/content_password_manager_driver.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/password_manager/core/browser/manage_passwords_referrer.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_store/password_store_interface.h"
#include "components/password_manager/core/common/password_manager_pref_names.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_service.h"
#include "components/plus_addresses/plus_address_test_utils.h"
#include "components/plus_addresses/plus_address_types.h"
#include "components/signin/public/base/consent_level.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync/base/features.h"
#include "components/sync/test/test_sync_service.h"
#include "components/sync/test/test_sync_user_settings.h"
#include "components/user_manager/user_names.h"
#include "components/variations/service/variations_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/menu_model.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace autofill {
namespace {
ElementsAre;
IsEmpty;
Not;
Property;
ACTION_P(QuitMessageLoop, loop) { … }
MATCHER(ContainsAnyAddressPaymentsOrPlusAddressFallbackEntries, "") { … }
MATCHER(ContainsAnyPlusAddressFallbackEntries, "") { … }
MATCHER(OnlyAddressFallbackAdded, "") { … }
MATCHER(ContainsPredictionImprovementsEntry, "") { … }
MATCHER(PlusAddressFallbackAdded, "") { … }
MATCHER(AddressAndPaymentsFallbacksAdded, "") { … }
MATCHER_P2(OnlyPasswordsFallbackAdded,
has_passwords_saved,
is_password_generation_enabled_for_current_field,
"") { … }
content::ContextMenuParams CreateContextMenuParams(
std::optional<autofill::FormRendererId> form_renderer_id = std::nullopt,
autofill::FieldRendererId field_render_id = autofill::FieldRendererId(0),
blink::mojom::FormControlType form_control_type =
blink::mojom::FormControlType::kInputText) { … }
class MockAutofillDriver : public ContentAutofillDriver { … };
}
class BaseAutofillContextMenuManagerTest : public InProcessBrowserTest { … };
class AutocompleteUnrecognizedFieldsTest
: public BaseAutofillContextMenuManagerTest { … };
IN_PROC_BROWSER_TEST_F(AutocompleteUnrecognizedFieldsTest,
UnclassifiedFormShown_FallbackOptionsNotPresent) { … }
IN_PROC_BROWSER_TEST_F(
AutocompleteUnrecognizedFieldsTest,
AutocompleteUnrecognizedFormShown_NoAutofillProfiles_FallbackOptionsNotPresent) { … }
IN_PROC_BROWSER_TEST_F(
AutocompleteUnrecognizedFieldsTest,
AutocompleteUnrecognizedFormShown_NoSuitableData_FallbackOptionsNotPresent) { … }
IN_PROC_BROWSER_TEST_F(
AutocompleteUnrecognizedFieldsTest,
AutocompleteUnrecognizedFormShown_AutofillDisabled_FallbackOptionsNotPresent) { … }
IN_PROC_BROWSER_TEST_F(AutocompleteUnrecognizedFieldsTest,
ClassifiedFormShown_FallbackOptionsNotPresent) { … }
IN_PROC_BROWSER_TEST_F(
AutocompleteUnrecognizedFieldsTest,
AutocompleteUnrecognizedFormShown_FallbackOptionsPresent) { … }
IN_PROC_BROWSER_TEST_F(AutocompleteUnrecognizedFieldsTest,
AutocompleteUnrecognizedFallback_TriggerSuggestions) { … }
class UnclassifiedFieldsTest : public BaseAutofillContextMenuManagerTest { … };
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
NoUserData_AddressManualFallbackPresent) { … }
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
HasAddressData_AddressManualFallbackAdded) { … }
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
AutofillDisabled_FallbackOptionsNotPresent) { … }
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
NoUserData_IncognitoMode_FallbackOptionsNotPresent) { … }
IN_PROC_BROWSER_TEST_F(
UnclassifiedFieldsTest,
HasAddressData_IncognitoMode_AddressManualFallbackAdded) { … }
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
HasCreditCardData_PaymentsManualFallbackAdded) { … }
class PredictionImprovementsDisabledTest
: public BaseAutofillContextMenuManagerTest { … };
IN_PROC_BROWSER_TEST_F(PredictionImprovementsDisabledTest,
PredictionImprovementsEntryNotAdded) { … }
class PredictionImprovementsEnabledTest
: public BaseAutofillContextMenuManagerTest { … };
IN_PROC_BROWSER_TEST_F(PredictionImprovementsEnabledTest,
PredictionImprovementsEntryAdded) { … }
IN_PROC_BROWSER_TEST_F(PredictionImprovementsEnabledTest,
ActionTriggersSuggestions) { … }
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
PaymentsDisabled_PaymentsManualFallbackNotAdded) { … }
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
UnclassifiedFormShown_ManualFallbacksPresent) { … }
IN_PROC_BROWSER_TEST_F(
UnclassifiedFieldsTest,
AutocompleteUnrecognizedFieldShown_ManualFallbacksPresent) { … }
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
ClassifiedFormShown_ManualFallbacksPresent) { … }
IN_PROC_BROWSER_TEST_F(
UnclassifiedFieldsTest,
UnclassifiedFormShown_AddressFallbackTriggersSuggestion) { … }
class AddNewAddressBubbleTest : public UnclassifiedFieldsTest { … };
IN_PROC_BROWSER_TEST_F(
AddNewAddressBubbleTest,
UnclassifiedFormShown_AddressFallbackTriggersAddNewAddressBubble) { … }
IN_PROC_BROWSER_TEST_F(AddNewAddressBubbleTest,
UnclassifiedFormShown_AddAddressSave) { … }
IN_PROC_BROWSER_TEST_F(AddNewAddressBubbleTest,
UnclassifiedFormShown_AddAddressMetricsAreSentOnCancel) { … }
IN_PROC_BROWSER_TEST_F(UnclassifiedFieldsTest,
UnclassifiedFormShown_PaymentsFallbackTriggersFallback) { … }
class PasswordsFallbackTest : public BaseAutofillContextMenuManagerTest { … };
IN_PROC_BROWSER_TEST_F(
PasswordsFallbackTest,
PasswordGenerationEnabled_NoPasswordsSaved_ManualFallbackAddedWithGeneratePasswordOptionAndImportPasswordsOption) { … }
IN_PROC_BROWSER_TEST_F(
PasswordsFallbackTest,
PasswordGenerationDisabled_NoPasswordsSaved_ManualFallbackAddedWithImportPasswordsOption) { … }
IN_PROC_BROWSER_TEST_F(
PasswordsFallbackTest,
PasswordGenerationEnabled_NonPasswordField_NoPasswordsSaved_ManualFallbackAddedWithImportPasswordsOptionAndWithoutGeneratePasswordOption) { … }
IN_PROC_BROWSER_TEST_F(PasswordsFallbackTest,
SelectPasswordTriggersSuggestions) { … }
IN_PROC_BROWSER_TEST_F(
PasswordsFallbackTest,
ImportPasswordsTriggersOpeningPaswordManagerTabAndRecordsMetrics) { … }
class PasswordsFallbackWithUIInteractionsTest
: public BaseAutofillContextMenuManagerTest { … };
IN_PROC_BROWSER_TEST_F(
PasswordsFallbackWithUIInteractionsTest,
SuggestPasswordTriggersPasswordGenerationAndRecordsMetrics) { … }
enum class PasswordDatabaseEntryType { … };
class PasswordsFallbackWithPasswordDatabaseEntriesTest
: public PasswordsFallbackTest,
public testing::WithParamInterface<
std::tuple<bool, PasswordDatabaseEntryType>> { … };
IN_PROC_BROWSER_TEST_P(
PasswordsFallbackWithPasswordDatabaseEntriesTest,
PasswordGenerationEnabled_HasPasswordDatabaseEntries_ManualFallbackAddedWithGeneratePasswordOption) { … }
IN_PROC_BROWSER_TEST_P(
PasswordsFallbackWithPasswordDatabaseEntriesTest,
PasswordGenerationDisabled_HasPasswordDatabaseEntries_ManualFallbackAddedWithoutGeneratePasswordOption) { … }
IN_PROC_BROWSER_TEST_P(
PasswordsFallbackWithPasswordDatabaseEntriesTest,
PasswordGenerationEnabled_NonPasswordField_HasPasswordDatabaseEntries_ManualFallbackAddedWithoutGeneratePasswordOption) { … }
INSTANTIATE_TEST_SUITE_P(…);
class PasswordsFallbackWithGuestProfileTest : public PasswordsFallbackTest { … };
IN_PROC_BROWSER_TEST_F(PasswordsFallbackWithGuestProfileTest,
NoManualFallback) { … }
struct ManualFallbackMetricsTestParams { … };
class ManualFallbackMetricsTest
: public BaseAutofillContextMenuManagerTest,
public ::testing::WithParamInterface<ManualFallbackMetricsTestParams> { … };
IN_PROC_BROWSER_TEST_P(ManualFallbackMetricsTest,
EmitExplicitlyTriggeredMetric) { … }
INSTANTIATE_TEST_SUITE_P(…);
class PlusAddressContextMenuManagerTest
: public SigninBrowserTestBaseT<BaseAutofillContextMenuManagerTest> { … };
IN_PROC_BROWSER_TEST_F(PlusAddressContextMenuManagerTest, UnclassifiedForm) { … }
IN_PROC_BROWSER_TEST_F(PlusAddressContextMenuManagerTest, ClassifiedForm) { … }
IN_PROC_BROWSER_TEST_F(PlusAddressContextMenuManagerTest, PasswordForm) { … }
IN_PROC_BROWSER_TEST_F(PlusAddressContextMenuManagerTest,
IncognitoModeWithoutPlusAddress) { … }
IN_PROC_BROWSER_TEST_F(PlusAddressContextMenuManagerTest,
IncognitoModeWithPlusAddress) { … }
IN_PROC_BROWSER_TEST_F(PlusAddressContextMenuManagerTest, ExcludedDomain) { … }
IN_PROC_BROWSER_TEST_F(PlusAddressContextMenuManagerTest, NonExcludedDomain) { … }
IN_PROC_BROWSER_TEST_F(PlusAddressContextMenuManagerTest,
ActionTriggersSuggestions) { … }
}