#include "chrome/browser/autofill/captured_sites_test_utils.h"
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/base_switches.h"
#include "base/check_deref.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/autofill/autofill_uitest_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/javascript_dialogs/app_modal_dialog_controller.h"
#include "components/javascript_dialogs/app_modal_dialog_view.h"
#include "components/permissions/permission_request_manager.h"
#include "components/variations/variations_switches.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/browsing_data_remover_test_util.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "ipc/ipc_channel_factory.h"
#include "ipc/ipc_logging.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_sync_message.h"
#include "third_party/zlib/google/compression_utils.h"
#include "ui/events/keycodes/dom/dom_key.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
#include "ui/events/keycodes/keyboard_codes.h"
JSONParserOptions;
JSONReader;
namespace {
const char kCommandFileFlag[] = …;
const char kWebPageReplayVerboseFlag[] = …;
const base::TimeDelta kAutofillActionWaitForVisualUpdateTimeout = …;
const int kAutofillActionNumRetries = …;
const char kWebPageReplayCertSPKI[] = …;
const char kClockNotSetMessage[] = …;
bool IsVerboseWprLoggingEnabled() { … }
void PrintDebugInstructions(const base::FilePath& command_file_path) { … }
std::optional<autofill::FieldType> StringToFieldType(std::string_view str) { … }
enum class ExecutionCommandType { … };
struct ExecutionCommand { … };
std::vector<ExecutionCommand> ReadExecutionCommands(
const base::FilePath& command_file_path) { … }
struct ExecutionState { … };
ExecutionState ProcessCommands(ExecutionState execution_state,
const base::Value::List* action_list,
const base::FilePath& command_file_path) { … }
struct AllowNull { … };
std::optional<std::string> FindPopulateString(
const base::Value::Dict& container,
std::string_view key_name,
absl::variant<std::string_view, AllowNull> key_descriptor) { … }
std::optional<std::vector<std::string>> FindPopulateStringVector(
const base::Value::Dict& container,
std::string_view key_name,
absl::variant<std::string_view, AllowNull> key_descriptor) { … }
}
namespace captured_sites_test_utils {
CapturedSiteParams::CapturedSiteParams() = default;
CapturedSiteParams::~CapturedSiteParams() = default;
CapturedSiteParams::CapturedSiteParams(const CapturedSiteParams& other) =
default;
std::ostream& operator<<(std::ostream& os, const CapturedSiteParams& param) { … }
std::vector<CapturedSiteParams> GetCapturedSites(
const base::FilePath& replay_files_dir_path) { … }
std::string FilePathToUTF8(const base::FilePath::StringType& str) { … }
std::optional<base::FilePath> GetCommandFilePath() { … }
void PrintInstructions(const char* test_file_name) { … }
IFrameWaiter::IFrameWaiter(content::WebContents* web_contents)
: … { … }
IFrameWaiter::~IFrameWaiter() { … }
content::RenderFrameHost* IFrameWaiter::WaitForFrameMatchingName(
const std::string& name,
const base::TimeDelta timeout) { … }
content::RenderFrameHost* IFrameWaiter::WaitForFrameMatchingOrigin(
const GURL origin,
const base::TimeDelta timeout) { … }
content::RenderFrameHost* IFrameWaiter::WaitForFrameMatchingUrl(
const GURL url,
const base::TimeDelta timeout) { … }
void IFrameWaiter::RenderFrameCreated(
content::RenderFrameHost* render_frame_host) { … }
void IFrameWaiter::DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) { … }
void IFrameWaiter::FrameNameChanged(content::RenderFrameHost* render_frame_host,
const std::string& name) { … }
bool IFrameWaiter::FrameHasOrigin(const GURL& origin,
content::RenderFrameHost* frame) { … }
WebPageReplayServerWrapper::WebPageReplayServerWrapper(
const bool start_as_replay,
int host_http_port,
int host_https_port)
: … { … }
WebPageReplayServerWrapper::~WebPageReplayServerWrapper() = default;
bool WebPageReplayServerWrapper::Start(
const base::FilePath& capture_file_path) { … }
bool WebPageReplayServerWrapper::Stop() { … }
bool WebPageReplayServerWrapper::RunWebPageReplayCmdAndWaitForExit(
const std::vector<std::string>& args,
const base::TimeDelta& timeout) { … }
bool WebPageReplayServerWrapper::RunWebPageReplayCmd(
const std::vector<std::string>& args) { … }
ProfileDataController::ProfileDataController()
: … { … }
ProfileDataController::~ProfileDataController() = default;
bool ProfileDataController::AddAutofillProfileInfo(
const std::string& field_type,
const std::string& field_value) { … }
TestRecipeReplayer::TestRecipeReplayer(
Browser* browser,
TestRecipeReplayChromeFeatureActionExecutor* feature_action_executor)
: … { … }
TestRecipeReplayer::~TestRecipeReplayer() { … }
bool TestRecipeReplayer::ReplayTest(
const base::FilePath& capture_file_path,
const base::FilePath& recipe_file_path,
const std::optional<base::FilePath>& command_file_path) { … }
const std::vector<testing::AssertionResult>
TestRecipeReplayer::GetValidationFailures() const { … }
bool TestRecipeReplayer::OverrideAutofillClock(
const base::FilePath capture_file_path) { … }
void TestRecipeReplayer::SetUpHostResolverRules(
base::CommandLine* command_line) { … }
void TestRecipeReplayer::SetUpCommandLine(base::CommandLine* command_line) { … }
TestRecipeReplayChromeFeatureActionExecutor*
TestRecipeReplayer::feature_action_executor() { … }
Browser* TestRecipeReplayer::browser() { … }
WebPageReplayServerWrapper*
TestRecipeReplayer::web_page_replay_server_wrapper() { … }
content::WebContents* TestRecipeReplayer::GetWebContents() { … }
void TestRecipeReplayer::WaitTillPageIsIdle(
base::TimeDelta continuous_paint_timeout) { … }
bool TestRecipeReplayer::WaitForVisualUpdate(base::TimeDelta timeout) { … }
void TestRecipeReplayer::CleanupSiteData() { … }
bool TestRecipeReplayer::ReplayRecordedActions(
const base::FilePath& recipe_file_path,
const std::optional<base::FilePath>& command_file_path) { … }
bool TestRecipeReplayer::InitializeBrowserToExecuteRecipe(
base::Value::Dict& recipe) { … }
bool TestRecipeReplayer::ExecuteAutofillAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteClickAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteClickIfNotSeenAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteCloseTabAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteCoolOffAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteHoverAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteForceLoadPage(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecutePressEnterAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecutePressEscapeAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecutePressSpaceAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteRunCommandAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteSavePasswordAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteSelectDropdownAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteTypeAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteTypePasswordAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteUpdatePasswordAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteValidateFieldValueAction(
base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteValidateNoSavePasswordPromptAction(
base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteValidatePasswordGenerationPromptAction(
base::Value::Dict action) { … }
void TestRecipeReplayer::ValidatePasswordGenerationPromptState(
const content::ToRenderFrameHost& frame,
const std::string& element_xpath,
bool expect_to_be_shown) { … }
bool TestRecipeReplayer::ExecuteValidateSaveFallbackAction(
base::Value::Dict action) { … }
bool TestRecipeReplayer::ExecuteWaitForStateAction(base::Value::Dict action) { … }
bool TestRecipeReplayer::GetTargetHTMLElementXpathFromAction(
const base::Value::Dict& action,
std::string* xpath) { … }
bool TestRecipeReplayer::GetTargetHTMLElementVisibilityEnumFromAction(
const base::Value::Dict& action,
int* visibility_enum_val) { … }
bool TestRecipeReplayer::GetTargetFrameFromAction(
const base::Value::Dict& action,
content::RenderFrameHost** frame) { … }
bool TestRecipeReplayer::ExtractFrameAndVerifyElement(
const base::Value::Dict& action,
std::string* xpath,
content::RenderFrameHost** frame,
bool set_focus,
bool relaxed_visibility,
bool ignore_failure) { … }
bool TestRecipeReplayer::GetIFramePathFromAction(
const base::Value::Dict& action,
std::vector<std::string>* iframe_path) { … }
bool TestRecipeReplayer::GetIFrameOffsetFromIFramePath(
const std::vector<std::string>& iframe_path,
content::RenderFrameHost* frame,
gfx::Vector2d* offset) { … }
bool TestRecipeReplayer::WaitForElementToBeReady(
const std::string& xpath,
const int visibility_enum_val,
content::RenderFrameHost* frame,
bool ignore_failure) { … }
bool TestRecipeReplayer::WaitForStateChange(
content::RenderFrameHost* frame,
const std::vector<std::string>& state_assertions,
const base::TimeDelta& timeout,
bool ignore_failure) { … }
bool TestRecipeReplayer::AllAssertionsPassed(
const content::ToRenderFrameHost& frame,
const std::vector<std::string>& assertions) { … }
bool TestRecipeReplayer::ExecuteJavaScriptOnElementByXpath(
const content::ToRenderFrameHost& frame,
const std::string& element_xpath,
const std::string& execute_function_body,
const base::TimeDelta& time_to_wait_for_element) { … }
bool TestRecipeReplayer::GetElementProperty(
const content::ToRenderFrameHost& frame,
const std::string& element_xpath,
const std::string& get_property_function_body,
std::string* property) { … }
bool TestRecipeReplayer::ExpectElementPropertyEqualsAnyOf(
const content::ToRenderFrameHost& frame,
const std::string& element_xpath,
const std::string& get_property_function_body,
const std::vector<std::string>& expected_values,
const std::string& validation_field,
IgnoreCase ignore_case) { … }
bool TestRecipeReplayer::ScrollElementIntoView(
const std::string& element_xpath,
content::RenderFrameHost* frame) { … }
bool TestRecipeReplayer::PlaceFocusOnElement(
const std::string& element_xpath,
const std::vector<std::string> iframe_path,
content::RenderFrameHost* frame) { … }
bool TestRecipeReplayer::GetBoundingRectOfTargetElement(
const std::string& target_element_xpath,
content::RenderFrameHost* frame,
gfx::Rect* output_rect) { … }
bool TestRecipeReplayer::GetBoundingRectOfTargetElement(
const std::string& target_element_xpath,
const std::vector<std::string> iframe_path,
content::RenderFrameHost* frame,
gfx::Rect* output_rect) { … }
bool TestRecipeReplayer::SimulateLeftMouseClickAt(
const gfx::Point& point,
content::RenderFrameHost* render_frame_host) { … }
bool TestRecipeReplayer::SimulateMouseHoverAt(
content::RenderFrameHost* render_frame_host,
const gfx::Point& point) { … }
void TestRecipeReplayer::SimulateKeyPressWrapper(
content::WebContents* web_contents,
ui::DomKey key) { … }
bool TestRecipeReplayer::HasChromeStoredCredential(
const base::Value::Dict& action,
bool* stored_cred) { … }
bool TestRecipeReplayer::SetupSavedAutofillProfile(
base::Value::List saved_autofill_profile_container) { … }
bool TestRecipeReplayer::SetupSavedPasswords(
base::Value::List saved_password_list_container) { … }
TestRecipeReplayChromeFeatureActionExecutor::
TestRecipeReplayChromeFeatureActionExecutor() { … }
TestRecipeReplayChromeFeatureActionExecutor::
~TestRecipeReplayChromeFeatureActionExecutor() { … }
bool TestRecipeReplayChromeFeatureActionExecutor::AutofillForm(
const std::string& focus_element_css_selector,
const std::vector<std::string>& iframe_path,
const int attempts,
content::RenderFrameHost* frame,
std::optional<autofill::FieldType> triggered_field_type) { … }
bool TestRecipeReplayChromeFeatureActionExecutor::AddAutofillProfileInfo(
const std::string& field_type,
const std::string& field_value) { … }
bool TestRecipeReplayChromeFeatureActionExecutor::SetupAutofillProfile() { … }
bool TestRecipeReplayChromeFeatureActionExecutor::AddCredential(
const std::string& origin,
const std::string& username,
const std::string& password) { … }
bool TestRecipeReplayChromeFeatureActionExecutor::SavePassword() { … }
bool TestRecipeReplayChromeFeatureActionExecutor::UpdatePassword() { … }
bool TestRecipeReplayChromeFeatureActionExecutor::WaitForSaveFallback() { … }
bool TestRecipeReplayChromeFeatureActionExecutor::
IsChromeShowingPasswordGenerationPrompt() { … }
bool TestRecipeReplayChromeFeatureActionExecutor::
HasChromeShownSavePasswordPrompt() { … }
bool TestRecipeReplayChromeFeatureActionExecutor::HasChromeStoredCredential(
const std::string& origin,
const std::string& username,
const std::string& password) { … }
}