#include "chrome/browser/autofill/automated_tests/cache_replayer.h"
#include <algorithm>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
#include "base/base64.h"
#include "base/base64url.h"
#include "base/cancelable_callback.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "net/base/url_util.h"
#include "services/network/public/cpp/data_element.h"
#include "services/network/public/cpp/resource_request.h"
#include "third_party/protobuf/src/google/protobuf/repeated_field.h"
#include "third_party/zlib/google/compression_utils.h"
namespace autofill::test {
JSONParserOptions;
JSONReader;
namespace {
constexpr char kHTTPBodySep[] = …;
constexpr char kApiServerDomain[] = …;
constexpr char kApiServerUrlGetPrefix[] = …;
constexpr char kApiServerQueryPath[] = …;
ErrorOr;
struct QueryNode { … };
std::string GetHexString(const std::string& input) { … }
std::string MakeHTTPTextFromSplit(const std::string& header,
const std::string& body) { … }
bool FailOnError(int options) { … }
bool FailOnEmpty(int options) { … }
bool SplitRequestsByForm(int options) { … }
bool CheckNodeType(const base::Value* node,
const std::string& name,
base::Value::Type type) { … }
template <class T>
ErrorOr<T> ParseProtoContents(const std::string& http_text) { … }
ErrorOr<std::string> GetQueryParameter(const GURL& url) { … }
RequestType GetRequestTypeFromURL(const GURL& url) { … }
ErrorOr<AutofillPageQueryRequest> GetAutofillQueryFromGETQueryURL(
const GURL& url) { … }
std::string GetStringFromDataElements(
const std::vector<network::DataElement>* data_elements) { … }
ErrorOr<std::string> PeelAutofillPageResourceQueryRequestWrapper(
const std::string& text) { … }
ErrorOr<AutofillPageQueryRequest> GetAutofillQueryFromPOSTQuery(
const network::ResourceRequest& resource_request) { … }
bool IsSingleFormRequest(const AutofillPageQueryRequest& query) { … }
bool RetrieveValueFromRequestNode(const base::Value::Dict& request_node,
const std::string node_name,
std::string* decoded_value) { … }
ErrorOr<AutofillPageQueryRequest> GetAutofillQueryFromRequestNode(
const base::Value::Dict& request_node) { … }
ErrorOr<AutofillQueryResponse> GetAutofillResponseFromRequestNode(
const base::Value::Dict& request_node,
std::string* response_header_text) { … }
bool FillFormSplitCache(const AutofillPageQueryRequest& query_request,
const std::string& response_header_text,
const AutofillQueryResponse& query_response,
ServerCache* cache_to_fill) { … }
ServerCacheReplayer::Status PopulateCacheFromQueryNode(
const QueryNode& query_node,
int options,
ServerCache* cache_to_fill) { … }
std::vector<QueryNode> FindQueryNodesInDomainDict(
const base::Value::Dict& domain,
const std::string& url_prefix) { … }
ServerCacheReplayer::Status PopulateCacheFromJSONFile(
const base::FilePath& json_file_path,
int options,
ServerCache* cache_to_fill) { … }
}
bool RetrieveAndDecompressStoredHTTP(const ServerCache& cache,
const std::string& key,
std::string* decompressed_http) { … }
AutofillServerBehaviorType ParseAutofillServerBehaviorType() { … }
std::pair<std::string, std::string> SplitHTTP(const std::string& http_text) { … }
std::ostream& operator<<(std::ostream& out,
const autofill::AutofillPageQueryRequest& query) { … }
std::ostream& operator<<(std::ostream& out,
const autofill::AutofillQueryResponse& response) { … }
std::string GetKeyFromQuery(const AutofillPageQueryRequest& query_request) { … }
ServerCacheReplayer::~ServerCacheReplayer() = default;
ServerCacheReplayer::ServerCacheReplayer(const base::FilePath& json_file_path,
int options)
: … { … }
ServerCacheReplayer::ServerCacheReplayer(ServerCache server_cache,
bool split_requests_by_form)
: … { … }
const ::google::protobuf::RepeatedPtrField<AutofillPageQueryRequest_Form>&
GetFormsRef(const AutofillPageQueryRequest& query) { … }
void CreateEmptyResponseForFormQuery(const AutofillPageQueryRequest_Form& form,
AutofillQueryResponse* response) { … }
void AppendSingleFormResponse(const AutofillQueryResponse& single_form_response,
AutofillQueryResponse* response) { … }
bool GetResponseForQuery(const ServerCacheReplayer& cache_replayer,
const AutofillPageQueryRequest& query,
std::string* http_text) { … }
bool ServerCacheReplayer::GetApiServerResponseForQuery(
const AutofillPageQueryRequest& query,
std::string* http_text) const { … }
ServerUrlLoader::ServerUrlLoader(
std::unique_ptr<ServerCacheReplayer> cache_replayer)
: … { … }
ServerUrlLoader::~ServerUrlLoader() { … }
bool WriteNotFoundResponse(
content::URLLoaderInterceptor::RequestParams* params) { … }
void SendBadRequest(network::mojom::URLLoaderClient* client) { … }
bool InterceptAutofillRequestHelper(
const ServerCacheReplayer& cache_replayer,
content::URLLoaderInterceptor::RequestParams* params) { … }
bool ServerUrlLoader::InterceptAutofillRequest(
content::URLLoaderInterceptor::RequestParams* params) { … }
}