#include <string.h>
#include <memory>
#include <string>
#include <string_view>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h"
#include "chrome/renderer/autofill/fake_mojo_password_manager_driver.h"
#include "chrome/renderer/autofill/fake_password_generation_driver.h"
#include "chrome/renderer/autofill/password_generation_test_utils.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "components/autofill/content/renderer/autofill_agent.h"
#include "components/autofill/content/renderer/form_autofill_util.h"
#include "components/autofill/content/renderer/password_generation_agent.h"
#include "components/autofill/content/renderer/test_password_autofill_agent.h"
#include "components/autofill/core/common/autofill_switches.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/password_generation_util.h"
#include "components/autofill/core/common/unique_ids.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "content/public/renderer/render_frame.h"
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_element.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "ui/events/keycodes/keyboard_codes.h"
FocusedFieldType;
ASCIIToUTF16;
WebDocument;
WebElement;
WebInputElement;
WebNode;
WebString;
_;
AnyNumber;
AtLeast;
AtMost;
Eq;
namespace autofill {
namespace {
const FormFieldData* FindFieldById(const FormData& form, std::string_view id) { … }
class FakeContentAutofillDriver : public mojom::AutofillDriver { … };
}
constexpr char kSigninFormHTML[] = …;
constexpr char kAccountCreationFormHTML[] = …;
constexpr char kAccountCreationNoForm[] = …;
#if !BUILDFLAG(IS_ANDROID)
constexpr char kAccountCreationNoIds[] = …;
#endif
constexpr char kDisabledElementAccountCreationFormHTML[] = …;
constexpr char kHiddenPasswordAccountCreationFormHTML[] = …;
constexpr char kMultipleAccountCreationFormHTML[] = …;
constexpr char kPasswordChangeFormHTML[] = …;
constexpr char kPasswordFormAndSpanHTML[] = …;
class PasswordGenerationAgentTest : public ChromeRenderViewTest { … };
void PasswordGenerationAgentTest::RegisterMainFrameRemoteInterfaces() { … }
void PasswordGenerationAgentTest::SetUp() { … }
void PasswordGenerationAgentTest::TearDown() { … }
void PasswordGenerationAgentTest::LoadHTMLWithUserGesture(const char* html) { … }
WebElement PasswordGenerationAgentTest::GetElementById(
std::string_view element_id) { … }
void PasswordGenerationAgentTest::FocusField(const char* element_id) { … }
void PasswordGenerationAgentTest::ExpectAutomaticGenerationAvailable(
const char* element_id,
AutomaticGenerationStatus status) { … }
void PasswordGenerationAgentTest::ExpectGenerationElementLostFocus(
const char* new_element_id) { … }
void PasswordGenerationAgentTest::ExpectFormClassifierVoteReceived(
bool received,
const std::u16string& expected_generation_element) { … }
void PasswordGenerationAgentTest::SelectGenerationFallbackAndExpect(
bool available) { … }
void PasswordGenerationAgentTest::ExpectAttribute(
const WebElement& element,
std::string_view attribute,
std::string_view expected_value) { … }
void PasswordGenerationAgentTest::CheckPreviewedValue(
const WebInputElement& element,
const std::u16string& value) { … }
void PasswordGenerationAgentTest::BindAutofillDriver(
mojo::ScopedInterfaceEndpointHandle handle) { … }
void PasswordGenerationAgentTest::BindPasswordManagerDriver(
mojo::ScopedInterfaceEndpointHandle handle) { … }
void PasswordGenerationAgentTest::BindPasswordManagerClient(
mojo::ScopedInterfaceEndpointHandle handle) { … }
class PasswordGenerationAgentTestForHtmlAnnotation
: public PasswordGenerationAgentTest { … };
void PasswordGenerationAgentTestForHtmlAnnotation::TestAnnotateForm(
bool has_form_tag) { … }
TEST_F(PasswordGenerationAgentTest, HiddenSecondPasswordDetectionTest) { … }
TEST_F(PasswordGenerationAgentTest, DetectionTestNoForm) { … }
TEST_F(PasswordGenerationAgentTest, FillTest) { … }
TEST_F(PasswordGenerationAgentTest, EditingTest) { … }
TEST_F(PasswordGenerationAgentTest, EditingEventsTest) { … }
TEST_F(PasswordGenerationAgentTest, UnblocklistedMultipleTest) { … }
TEST_F(PasswordGenerationAgentTest, AccountCreationFormsDetectedTest) { … }
TEST_F(PasswordGenerationAgentTest, MaximumCharsForGenerationOffer) { … }
TEST_F(PasswordGenerationAgentTest, MinimumLengthForEditedPassword) { … }
TEST_F(PasswordGenerationAgentTest, DynamicFormTest) { … }
TEST_F(PasswordGenerationAgentTest, BlurTest) { … }
TEST_F(PasswordGenerationAgentTest, ChangePasswordFormDetectionTest) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(PasswordGenerationAgentTest, DesktopContextMenuGenerationInFormTest) { … }
TEST_F(PasswordGenerationAgentTest, DesktopContextMenuGenerationNoFormTest) { … }
TEST_F(PasswordGenerationAgentTest,
DesktopContextMenuGenerationDoesntSuppressAutomatic) { … }
TEST_F(PasswordGenerationAgentTest, DesktopContextMenuGenerationNoIds) { … }
TEST_F(PasswordGenerationAgentTest,
DesktopContextMenuGeneration_NoFocusedElement) { … }
TEST_F(PasswordGenerationAgentTest,
DesktopContextMenuManualGenerationOnReadonly) { … }
#endif
TEST_F(PasswordGenerationAgentTest, PresavingGeneratedPassword) { … }
TEST_F(PasswordGenerationAgentTest, FallbackForSaving) { … }
TEST_F(PasswordGenerationAgentTest, AcceptAfterNavigation) { … }
TEST_F(PasswordGenerationAgentTest, FormClassifierDisabled) { … }
TEST_F(PasswordGenerationAgentTest, RevealPassword) { … }
TEST_F(PasswordGenerationAgentTest,
DoesNotResetGenerationWhenJavascriptClearedTheField) { … }
TEST_F(PasswordGenerationAgentTest,
ResetsGenerationWhenUserFocusesFieldClearedByJavascript) { … }
TEST_F(PasswordGenerationAgentTest, JavascriptClearedThePassword_TypeUsername) { … }
TEST_F(PasswordGenerationAgentTest, GenerationFallback_NoFocusedElement) { … }
TEST_F(PasswordGenerationAgentTest, AutofillToGenerationField) { … }
TEST_F(PasswordGenerationAgentTestForHtmlAnnotation, AnnotateForm) { … }
TEST_F(PasswordGenerationAgentTestForHtmlAnnotation, AnnotateNoForm) { … }
TEST_F(PasswordGenerationAgentTest, PasswordUnmaskedUntilCompleteDeletion) { … }
TEST_F(PasswordGenerationAgentTest, ShortPasswordMaskedAfterChangingFocus) { … }
TEST_F(PasswordGenerationAgentTest, GenerationAvailableByRendererIds) { … }
TEST_F(PasswordGenerationAgentTest, SuggestionPreviewedAndClearedTest) { … }
TEST_F(PasswordGenerationAgentTest, SuggestionPreviewedAndFilledTest) { … }
TEST_F(PasswordGenerationAgentTest, AdvancesFocusToNextFieldAfterPasswords) { … }
TEST_F(PasswordGenerationAgentTest,
MasksPasswordAfterReplacingTextBySelectingAll) { … }
}