chromium/components/autofill/content/renderer/autofill_agent_form_interaction_browsertest.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>

#include "base/feature_list.h"
#include "base/test/scoped_feature_list.h"
#include "components/autofill/content/renderer/autofill_agent.h"
#include "components/autofill/content/renderer/autofill_renderer_test.h"
#include "components/autofill/content/renderer/form_autofill_util.h"
#include "components/autofill/core/common/aliases.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/form_field_data.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_input_element.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/public/web/web_view.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/rect.h"

namespace autofill {

namespace {

_;
AllOf;
ElementsAre;
Field;
InSequence;
MockFunction;
Not;
Property;

// Returns a matcher that matches a `FormFieldData::form_control_type`.
auto HasType(FormControlType type) {}

auto IsContentEditable() {}

template <typename... Args>
auto FieldsAre(Args&&... matchers) {}

// TODO(crbug.com/40286775): Clean up these functions once
// `kAutofillAndroidDisableSuggestionsOnJSFocus` is launched and Android and
// Desktop behave identically.

// Returns the expected number of calls to AskForValuesToFill when left
// clicking or tapping a previously unfocused field.
int NumCallsToAskForValuesToFillOnInitialLeftClick() {}

// Returns the expected number of calls to AskForValuesToFill when focusing a
// text field without left clicking or tapping it.
int NumCallsToAskForValuesToFillOnTextfieldFocusWithoutLeftClick() {}

// Returns the expected number of calls to HidePopup when unfocusing a field.
int NumCallsToHidePopupOnFocusLoss() {}

}  // namespace

class AutofillAgentFormInteractionTest : public test::AutofillRendererTest {};

// Tests that (repeatedly) clicking a text input field calls AskForValuesToFill
// each time, but clicking a button does not.
TEST_F(AutofillAgentFormInteractionTest, TextInputLeftClick) {}

// Tests that a right click does not trigger AskForValuesToFill on Desktop, but
// does on Android.
TEST_F(AutofillAgentFormInteractionTest, TextInputRightClick) {}

// Tests that focusing the text field without a click does not call
// AskForValuesToFill on Desktop, but does on Android. A later click interaction
// triggers it on both.
TEST_F(AutofillAgentFormInteractionTest, TextInputFocusAndLeftClick) {}

// Tests that (repeated) left clicks on a textarea trigger AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, TextAreaLeftClick) {}

// Tests that focusing a textarea without a click calls AskForValuesToFill with
// trigger source `kTextareaFocusedWithoutClick` on Desktop.
TEST_F(AutofillAgentFormInteractionTest, TextareaFocusAndLeftClick) {}

// Tests that left clicking a scaled text area triggers AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, ScaledTextareaLeftClick) {}

// Tests that tapping a scaled text area triggers AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, ScaledTextareaTapped) {}

// Tests that left clicking a disabled input field does not trigger
// AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, DisabledInputLeftClick) {}

// Tests that focusing a disabled input field does not trigger
// AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, DisabledInputFocusWithoutClick) {}

// Tests that left clicking a disabled textarea does not trigger
// AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, DisabledTextareaLeftClick) {}

// Tests that focusing a disabled textarea without click does not trigger
// AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, DisabledTextareaFocusWithoutClick) {}

// Tests that left clicking a readonly input field does not trigger
// AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, ReadonlyInputLeftClick) {}

// Tests that focusing a readonly input field does not trigger
// AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, ReadonlyInputFocusWithoutClick) {}

// Tests that left clicking a readonly textarea does not trigger
// AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, ReadonlyTextareaLeftClick) {}

// Tests that focusing a readonly textarea without click does not trigger
// AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, ReadonlyTextareaFocusWithoutClick) {}

// Tests that a tap near the edge of an input field trigger AskForValuesToFill.
TEST_F(AutofillAgentFormInteractionTest, TapNearEdge) {}

AutofillAgentContentEditableInteractionTest;

// Tests that left clicking on an contenteditable triggers AskForValuesToFill.
TEST_F(AutofillAgentContentEditableInteractionTest, LeftClick) {}

// Tests that unfocusing a contenteditable triggers a call to
// `AutofillDriver::HidePopup()`.
TEST_F(AutofillAgentContentEditableInteractionTest,
       LossOfFocusOfContentEditableTriggersHideAutofillSuggestions) {}

// Scrolling doesn't hide the popup on Android.
#if !BUILDFLAG(IS_ANDROID)
// Tests that scrolling triggers a call to `AutofillDriver::HidePopup()`.
TEST_F(AutofillAgentContentEditableInteractionTest,
       ScrollingHidesAutofillPopup) {}
#endif  // !BUILDFLAG(IS_ANDROID)

// Tests that clicking on a contenteditable form is ignored.
TEST_F(AutofillAgentContentEditableInteractionTest,
       ClickOnContentEditableFormIsIgnored) {}

// Tests that clicking on a contenteditable form element triggers
// AskForValuesToFill for the form element and not the contenteditable.
TEST_F(AutofillAgentContentEditableInteractionTest,
       ClickOnContentEditableFormControlIsTreatedAsFormControl) {}

}  // namespace autofill