#include <optional>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_entropy_provider.h"
#include "base/test/run_until.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/autofill/autofill_flow_test_util.h"
#include "chrome/browser/autofill/autofill_uitest.h"
#include "chrome/browser/autofill/autofill_uitest_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/translate/translate_service.h"
#include "chrome/browser/translate/translate_test_utils.h"
#include "chrome/browser/ui/autofill/autofill_suggestion_controller.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/translate/translate_bubble_model.h"
#include "chrome/browser/ui/translate/translate_bubble_test_utils.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/test_autofill_manager_injector.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/browser_autofill_manager.h"
#include "components/autofill/core/browser/browser_autofill_manager_test_api.h"
#include "components/autofill/core/browser/browser_autofill_manager_test_delegate.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/mock_autofill_manager_observer.h"
#include "components/autofill/core/browser/test_autofill_manager_waiter.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/translate/core/browser/translate_manager.h"
#include "components/translate/core/common/translate_switches.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/scoped_accessibility_mode_override.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "net/base/net_errors.h"
#include "net/cert/mock_cert_verifier.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/switches.h"
#include "third_party/re2/src/re2/re2.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/dom_us_layout_data.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
#include "ui/events/keycodes/keyboard_codes.h"
#if BUILDFLAG(IS_CHROMEOS_ASH) && BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/ash/accessibility/accessibility_manager.h"
#include "chrome/browser/ash/accessibility/speech_monitor.h"
#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "extensions/browser/browsertest_util.h"
#include "ui/base/test/ui_controls.h"
#endif
ASCIIToUTF16;
URLLoaderInterceptor;
_;
AllOf;
AssertionFailure;
AssertionResult;
AssertionSuccess;
ElementsAre;
Eq;
Field;
Property;
StartsWith;
UnorderedElementsAreArray;
namespace autofill {
namespace {
constexpr char kTestShippingFormString[] = …;
ACTION_P(InvokeClosure, closure) { … }
std::string GenerateTestShippingFormWithSelectList() { … }
content::RenderFrameHost* RenderFrameHostForName(
content::WebContents* web_contents,
const std::string& name) { … }
autofill::ElementExpr GetElementById(const std::string& id) { … }
struct FieldValue { … };
std::ostream& operator<<(std::ostream& os, const FieldValue& field) { … }
std::vector<FieldValue> GetFieldValues(
const ElementExpr& control_elements,
content::ToRenderFrameHost execution_target) { … }
[[nodiscard]] AssertionResult EnterTextIntoField(
const autofill::ElementExpr& e,
std::string_view value,
AutofillUiTest* test,
content::ToRenderFrameHost execution_target) { … }
const std::vector<FieldValue> kEmptyAddress{ … };
const struct { … } kDefaultAddressValues;
const std::vector<FieldValue> kDefaultAddress{ … };
[[nodiscard]] std::vector<FieldValue> MergeValue(std::vector<FieldValue> fields,
const FieldValue& update) { … }
template <typename Arg, typename Fun>
[[nodiscard]] auto Map(const std::vector<Arg>& args, Fun fun) { … }
[[nodiscard]] auto ValuesAre(const std::vector<FieldValue>& expected) { … }
[[nodiscard]] auto FieldsAre(auto matcher) {
return Property(&FormData::fields, ElementsAreArray(matcher));
}
class ValueWaiter { … };
[[nodiscard]] ValueWaiter ListenForValueChange(
const std::string& id,
const std::optional<std::string>& unblock_variable,
content::ToRenderFrameHost execution_target) { … }
}
class AutofillInteractiveTestBase : public AutofillUiTest { … };
const char AutofillInteractiveTestBase::kTestUrlPath[] = …;
class AutofillInteractiveTest : public AutofillInteractiveTestBase { … };
class AutofillInteractiveTestWithHistogramTester
: public AutofillInteractiveTest { … };
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, BasicFormFill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, FillHiddenSelect) { … }
class AutofillInteractiveTest_PrefillFormAndFill
: public AutofillInteractiveTest { … };
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, BasicUndoAutofill) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_ModifyTextFieldAndFill …
#else
#define MAYBE_ModifyTextFieldAndFill …
#endif
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
MAYBE_ModifyTextFieldAndFill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ModifyTextNotifiesObserver) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
ModifyTextAreaNotifiesObserver) { … }
void DoModifySelectFieldAndFill(AutofillInteractiveTest* test,
bool should_test_selectlist) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ModifySelectFieldAndFill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ModifySelectListFieldAndFill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest_PrefillFormAndFill,
PrefillFormAndFill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillViaDownArrow) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillSelectViaTab) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillViaClick) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, Click) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DontAutofillForOutsideClick) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
DontAutofillShowPopupWhenNoEnoughHeightInContentArea) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnDeleteValueAfterAutofill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnSelectOptionFromDatalist) { … }
IN_PROC_BROWSER_TEST_F(
AutofillInteractiveTest,
OnSelectOptionFromDatalistTurningToPasswordFieldAndBack) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnInputAfterAutofill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnChangeAfterAutofill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, InputFiresBeforeChange) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
AutofillFormsDistinguishedById) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillFormWithRepeatedField) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
AutofillFormWithAutocompleteOffField) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DynamicFormFill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillAfterReload) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillEvents) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillAfterTranslate) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ComparePhoneNumbers) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, NoAutofillForCompanyName) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
NoAutofillSuggestionForCompanyName) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, NoAutofillForReadOnlyFields) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, FormFillableOnReset) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
DistinguishMiddleInitialWithinName) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
MultipleEmailFilledByOneUserGesture) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
DISABLED_FormFillLatencyAfterSubmit) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
DisableAutocompleteWhileFilling) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
FillFormAndFieldWithNoNameOrId) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
Dynamic_MultipleNoNameForms_BadNames_FourthForm) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
Dynamic_MultipleNoNameForms_BadNames_ThirdForm) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
Dynamic_MultipleNoNameForms_BadNames_SecondForm) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
Dynamic_MultipleNoNameForms_BadNames_FirstForm) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, FieldsChangeName) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestBase, FillLocalCreditCard) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestBase, NoAutocomplete) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestBase, SomeAutocomplete) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestBase, AllAutocomplete) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
NoEventFiredWhenExitingSelectListPreview) { … }
class AutofillInteractiveIsolationTest : public AutofillInteractiveTestBase { … };
enum class FrameType { … };
class AutofillInteractiveFencedFrameTest
: public AutofillInteractiveIsolationTest,
public ::testing::WithParamInterface<FrameType> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(AutofillInteractiveFencedFrameTest,
SimpleCrossSiteFill) { … }
IN_PROC_BROWSER_TEST_P(AutofillInteractiveFencedFrameTest,
CrossSitePaymentForms) { … }
IN_PROC_BROWSER_TEST_P(AutofillInteractiveFencedFrameTest,
DeletingFrameClosesPopup) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ChangingTabClosesPopup) { … }
class AutofillInteractiveTestDynamicForm : public AutofillInteractiveTest { … };
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
TwoDynamicChangingFormsFill) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_SecondChange) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_AfterDelay) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_AddsNewFieldTypeGroups) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicFormFill_SelectToText) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicFormFill_VisibilitySwitch) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicFormFill_FirstElementDisappears) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicFormFill_FirstElementDisappearsNoNameForm) { … }
IN_PROC_BROWSER_TEST_F(
AutofillInteractiveTestDynamicForm,
DynamicFormFill_FirstElementDisappearsMultipleBadNameForms) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicFormFill_FirstElementDisappearsBadnameUnowned) { … }
IN_PROC_BROWSER_TEST_F(
AutofillInteractiveTestDynamicForm,
DynamicFormFill_FirstElementDisappearsMultipleNoNameForms) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicFormFill_FirstElementDisappearsUnowned) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_AlsoForCreditCard) { … }
void DoDynamicChangingFormFill_SelectUpdated(
AutofillInteractiveTestDynamicForm* test,
net::EmbeddedTestServer* test_server,
bool should_test_selectlist,
bool should_test_async_update) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_SelectUpdated) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_SelectListUpdated) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_SelectUpdatedAsync) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_SelectListUpdatedAsync) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_DoubleSelectUpdated) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_FormWithoutName) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_SelectUpdated_FormWithoutName) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_SyntheticForm) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
DynamicChangingFormFill_SelectUpdated_SyntheticForm) { … }
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestDynamicForm,
FillCardOnReformattingForm) { … }
class AutofillInteractiveTestShadowDom
: public AutofillInteractiveTest,
public ::testing::WithParamInterface<size_t> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(AutofillInteractiveTestShadowDom,
LabelInHostingDomOfField) { … }
IN_PROC_BROWSER_TEST_P(AutofillInteractiveTestShadowDom,
LabelInSameShadowDomAsField) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH) && BUILDFLAG(ENABLE_EXTENSIONS)
class AutofillInteractiveTestChromeVox : public AutofillInteractiveTestBase {
public:
AutofillInteractiveTestChromeVox() = default;
~AutofillInteractiveTestChromeVox() override = default;
void TearDownOnMainThread() override {
ash::AccessibilityManager::Get()->EnableSpokenFeedback(false);
AutomationManagerAura::GetInstance()->Disable();
AutofillInteractiveTestBase::TearDownOnMainThread();
}
void EnableChromeVox() {
ASSERT_FALSE(ash::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
ash::AccessibilityManager::Get()->EnableSpokenFeedback(true);
sm_.ExpectSpeechPattern("*");
sm_.Call([this]() { DisableEarcons(); });
}
void DisableEarcons() {
extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait(
browser()->profile(), extension_misc::kChromeVoxExtensionId,
"ChromeVox.earcons.playEarcon = function() {};");
}
ash::test::SpeechMonitor sm_;
};
#if BUILDFLAG(IS_CHROMEOS)
#define MAYBE_TestNotificationOfAutofillDropdown …
#else
#define MAYBE_TestNotificationOfAutofillDropdown …
#endif
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTestChromeVox,
MAYBE_TestNotificationOfAutofillDropdown) {
CreateTestProfile();
SetTestUrlResponse(kTestShippingFormString);
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), GetTestUrl()));
EnableChromeVox();
content::ScopedAccessibilityModeOverride scoped_accessibility_mode(
web_contents(), ui::kAXModeComplete);
sm_.ExpectSpeechPattern("Web Content");
sm_.Call([this]() {
content::WaitForAccessibilityTreeToContainNodeWithName(web_contents(),
"First name:");
web_contents()->Focus();
test_delegate()->SetExpectations({ObservedUiEvents::kSuggestionsShown});
ASSERT_TRUE(FocusField(GetElementById("firstname"), GetWebContents()));
});
sm_.ExpectSpeechPattern("First name:");
sm_.ExpectSpeechPattern("Edit text");
sm_.ExpectSpeechPattern("Region");
sm_.Call([this]() { ASSERT_TRUE(test_delegate()->Wait()); });
sm_.Call([this]() {
test_delegate()->SetExpectations({ObservedUiEvents::kPreviewFormData});
ASSERT_TRUE(
ui_controls::SendKeyPress(browser()->window()->GetNativeWindow(),
ui::VKEY_DOWN, false, false, false, false));
});
sm_.ExpectSpeechPattern("Autofill menu opened");
sm_.ExpectSpeechPattern("Milton 4120 Freidrich Lane");
sm_.ExpectSpeechPattern("List item");
sm_.ExpectSpeechPattern("1 of 2");
sm_.Call([this]() { ASSERT_TRUE(test_delegate()->Wait()); });
sm_.Replay();
}
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_AutofillInteractiveFormSubmissionTest …
#else
#define MAYBE_AutofillInteractiveFormSubmissionTest …
#endif
class MAYBE_AutofillInteractiveFormSubmissionTest
: public AutofillInteractiveTestBase { … };
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormSubmissionTest,
Submission) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormSubmissionTest,
ProbableSubmission) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormSubmissionTest,
SameDocumentNavigation) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormSubmissionTest,
XhrSucceededAndHideForm) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormSubmissionTest,
XhrSucceededAndDeleteForm) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormSubmissionTest,
DomMutationAfterXhr) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormSubmissionTest,
RememberUserInput) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormSubmissionTest,
TreatAutofillAsUserInput) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_AutofillInteractiveFormlessFormSubmissionTest …
#else
#define MAYBE_AutofillInteractiveFormlessFormSubmissionTest …
#endif
class MAYBE_AutofillInteractiveFormlessFormSubmissionTest
: public MAYBE_AutofillInteractiveFormSubmissionTest { … };
IN_PROC_BROWSER_TEST_F(MAYBE_AutofillInteractiveFormlessFormSubmissionTest,
NavigationAfterXhr) { … }
}