#include "components/autofill/content/renderer/autofill_agent.h"
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/feature_list.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "components/autofill/content/common/mojom/autofill_driver.mojom.h"
#include "components/autofill/content/renderer/autofill_agent_test_api.h"
#include "components/autofill/content/renderer/autofill_renderer_test.h"
#include "components/autofill/content/renderer/form_autofill_util.h"
#include "components/autofill/content/renderer/form_tracker.h"
#include "components/autofill/content/renderer/test_utils.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/field_data_manager.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_data_test_api.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom-shared.h"
#include "components/autofill/core/common/unique_ids.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/features_generated.h"
#include "third_party/blink/public/common/metrics/document_update_reason.h"
#include "third_party/blink/public/web/web_autofill_state.h"
#include "third_party/blink/public/web/web_form_control_element.h"
#include "third_party/blink/public/web/web_frame_widget.h"
namespace autofill {
namespace {
_;
AllOf;
AtMost;
DoAll;
ElementsAre;
ElementsAreArray;
Eq;
Field;
IsEmpty;
IsNull;
Matcher;
NiceMock;
Optional;
Property;
SaveArg;
SizeIs;
constexpr CallTimerState kCallTimerStateDummy = …;
class MockAutofillAgent : public AutofillAgent { … };
class MockFormTracker : public FormTracker { … };
template <typename... Args>
auto FieldsAre(Args&&... matchers) { … }
template <typename... Args>
auto HasFieldsWithIdAttributes(Args&&... id_attributes) { … }
auto HasFormId(FormRendererId expectation) { … }
auto HasFormIdAttribute(std::u16string id_attribute) { … }
auto HasFieldIdAttribute(std::u16string id_attribute) { … }
auto HasSelectedText(std::u16string selected_text) { … }
auto HasValue(std::u16string value) { … }
auto HasNumFields(size_t num) { … }
auto HasNumChildFrames(size_t num) { … }
auto HasSingleElementWhich(auto... element_matchers) {
return AllOf(SizeIs(1), ElementsAre(AllOf(element_matchers...)));
}
auto HasType(FormControlType type) { … }
class AutofillAgentTest : public test::AutofillRendererTest { … };
class AutofillAgentTestWithFeatures : public AutofillAgentTest { … };
TEST_F(AutofillAgentTestWithFeatures, FormsSeen_Empty) { … }
TEST_F(AutofillAgentTestWithFeatures, FormsSeen_NoEmpty) { … }
TEST_F(AutofillAgentTestWithFeatures, FormsSeen_NewFormUnowned) { … }
TEST_F(AutofillAgentTestWithFeatures, FormsSeen_NewForm) { … }
TEST_F(AutofillAgentTestWithFeatures, FormsSeen_NewIframe) { … }
TEST_F(AutofillAgentTestWithFeatures, FormsSeen_UpdatedForm) { … }
TEST_F(AutofillAgentTestWithFeatures, FormsSeen_RemovedInput) { … }
TEST_F(AutofillAgentTestWithFeatures, TriggerFormExtractionWithResponse) { … }
AutofillAgentShadowDomTest;
TEST_F(AutofillAgentShadowDomTest, UnownedUnassociatedElements) { … }
TEST_F(AutofillAgentShadowDomTest, UnassociatedElementsOwnedByNonShadowForm) { … }
TEST_F(AutofillAgentShadowDomTest, FormControlInsideSlotWithinFormInShadowDom) { … }
TEST_F(AutofillAgentShadowDomTest, ElementsOwnedByFormInShadowTree) { … }
TEST_F(AutofillAgentShadowDomTest, NestedForms) { … }
TEST_F(AutofillAgentShadowDomTest, NestedFormsWithAssociation) { … }
TEST_F(AutofillAgentShadowDomTest, MultipleNestedForms) { … }
TEST_F(AutofillAgentShadowDomTest, DeepNestedForms) { … }
class AutofillAgentTestExtractForms : public AutofillAgentTestWithFeatures { … };
TEST_F(AutofillAgentTestExtractForms, CallbackIsCalledIfFormIsNotFound) { … }
TEST_F(AutofillAgentTestExtractForms, CallbackIsCalledForForm) { … }
TEST_F(AutofillAgentTestExtractForms, CallbackIsCalledForFormlessFields) { … }
TEST_F(AutofillAgentTestExtractForms, CallbackIsCalledForContentEditable) { … }
TEST_F(AutofillAgentTestWithFeatures,
TriggerFormExtractionWithResponse_CalledTwice) { … }
TEST_F(AutofillAgentTestWithFeatures, TriggerSuggestions) { … }
TEST_F(AutofillAgentTestWithFeatures,
TriggerSuggestionsForElementWithDatalist) { … }
TEST_F(AutofillAgentTestWithFeatures, TriggerSuggestionsForContenteditable) { … }
TEST_F(AutofillAgentTest, PreviewThenClear) { … }
TEST_F(AutofillAgentTest, JavaScriptChangedValue_AutofillState) { … }
class AutofillAgentSubmissionTest : public AutofillAgentTest,
public testing::WithParamInterface<int> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(AutofillAgentSubmissionTest,
JavaScriptChangedValueUpdatesLastInteractedSavedState) { … }
TEST_P(AutofillAgentSubmissionTest,
FormlessApplyFormActionUpdatesLastInteractedSavedState) { … }
TEST_P(AutofillAgentSubmissionTest,
FormApplyFormActionUpdatesLastInteractedSavedState) { … }
TEST_P(AutofillAgentSubmissionTest,
HideElementTriggersFormTracker_DisplayNone) { … }
TEST_P(AutofillAgentSubmissionTest,
HideElementTriggersFormTracker_VisibilityHidden) { … }
TEST_P(AutofillAgentSubmissionTest, HideElementTriggersFormTracker_TypeHidden) { … }
TEST_P(AutofillAgentSubmissionTest, HideElementTriggersFormTracker_HiddenTrue) { … }
TEST_P(AutofillAgentSubmissionTest, HideElementTriggersFormTracker_ShadowDom) { … }
TEST_P(AutofillAgentSubmissionTest,
FormlessOnInferredFormSubmissionAfterXhrAndAllInputsRemoved) { … }
TEST_P(AutofillAgentSubmissionTest,
FormlessOnInferredFormSubmissionAfterXhrAndSomeInputsRemoved) { … }
TEST_P(AutofillAgentSubmissionTest,
FormlessOnNavigationAfterSomeInputsRemoved) { … }
TEST_P(AutofillAgentSubmissionTest,
OnInferredFormSubmissionAfterAutofillRemovesLastQueriedElement) { … }
class AutofillAgentTestNavigationReset : public AutofillAgentTest { … };
TEST_F(AutofillAgentTestNavigationReset, NavigationResetsIsDomContentLoaded) { … }
class AutofillAgentTestFocus : public AutofillAgentTest { … };
TEST_F(AutofillAgentTestFocus, FireFocusEventsWhenCyclingThroughFields) { … }
TEST_F(AutofillAgentTestFocus,
FireFocusEventsWhenSwitchingBetweenFieldAndNonField) { … }
TEST_F(AutofillAgentTestFocus, FireFocusEventsForNullElement) { … }
class AutofillAgentTestCaret
: public AutofillAgentTest,
public ::testing::WithParamInterface<FormControlType> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(AutofillAgentTestCaret, AskForValuesToFillContainsCaret) { … }
TEST_P(AutofillAgentTestCaret, MovingCaretSlowlyFiresEvent) { … }
TEST_P(AutofillAgentTestCaret, MovingCaretFastThrottlesEvent) { … }
TEST_P(AutofillAgentTestCaret, SelectionFiresEvent) { … }
class AutofillAgentTestClick
: public AutofillAgentTest,
public ::testing::WithParamInterface<const char*> { … };
INSTANTIATE_TEST_SUITE_P(…);
#if !BUILDFLAG(IS_ANDROID)
#define MAYBE_AskForValuesToFillOnClick …
#else
#define MAYBE_AskForValuesToFillOnClick …
#endif
TEST_P(AutofillAgentTestClick, MAYBE_AskForValuesToFillOnClick) { … }
TEST_F(AutofillAgentTest, DOMContentLoadedEmitsMetric) { … }
}
}