#include "chrome/browser/autofill/automated_tests/cache_replayer.h"
#include <memory>
#include <optional>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
#include "base/base64.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_writer.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/proto/api_v1.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/zlib/google/compression_utils.h"
namespace autofill {
namespace test {
namespace {
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
JSONWriter;
Value;
RequestResponsePair;
constexpr char kTestHTTPResponseHeader[] = …;
constexpr char kHTTPBodySep[] = …;
constexpr char kHostname[] = …;
struct LightField { … };
struct LightForm { … };
std::string CreateQueryUrl(const std::string& base64_encoded_query) { … }
bool GetServerResponseForQuery(const ServerCacheReplayer& cache_replayer,
const AutofillPageQueryRequest& query,
std::string* http_text) { … }
RequestResponsePair MakeQueryRequestResponsePair(
const std::vector<LightForm>& forms) { … }
bool MakeQueryRequestURL(std::optional<AutofillPageQueryRequest> query,
std::string* request_url) { … }
inline std::string MakeRequestHeader(std::string_view url) { … }
bool MakeSerializedRequest(const AutofillPageQueryRequest& query,
RequestType type,
std::string* serialized_request,
std::string* request_url) { … }
std::string MakeSerializedResponse(
const AutofillQueryResponse& query_response) { … }
bool WriteJSONNode(const base::FilePath& file_path, const base::Value& node) { … }
bool WriteJSON(const base::FilePath& file_path,
const std::vector<RequestResponsePair>& request_response_pairs,
RequestType request_type = RequestType::kQueryProtoPOST) { … }
TEST(AutofillCacheReplayerDeathTest,
DISABLED_ServerCacheReplayerConstructor_CrashesWhenNoDomainNode) { … }
TEST(AutofillCacheReplayerDeathTest,
ServerCacheReplayerConstructor_CrashesWhenNoQueryNodesAndFailOnEmpty) { … }
class AutofillCacheReplayerGETQueryDeathTest
: public testing::TestWithParam<std::string> { … };
TEST_P(
AutofillCacheReplayerGETQueryDeathTest,
ApiServerCacheReplayerConstructor_CrashesWhenInvalidRequestURLForGETQuery) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST(AutofillCacheReplayerTest,
CanUseReplayerWhenNoCacheContentWithNotFailOnEmpty) { … }
template <typename U, typename V>
bool ProtobufsEqual(const U& u, const V& v) { … }
class AutofillCacheReplayerGetResponseForQueryTest
: public testing::TestWithParam<RequestType> { … };
TEST_P(AutofillCacheReplayerGetResponseForQueryTest,
FillsResponseWhenNoErrors) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST(AutofillCacheReplayerTest, GetResponseForQueryGivesFalseWhenNullptr) { … }
TEST(AutofillCacheReplayerTest, GetResponseForQueryGivesFalseWhenNoKeyMatch) { … }
TEST(AutofillCacheReplayerTest,
GetResponseForQueryGivesFalseWhenDecompressFailsBecauseInvalidHTTP) { … }
TEST(AutofillCacheReplayerTest,
GetResponseForQueryGivesTrueWhenDecompressSucceededBecauseEmptyBody) { … }
std::vector<bool> DoFormsMatch(const AutofillQueryResponse& response,
const std::vector<LightForm>& forms) { … }
std::vector<bool> CheckFormsInCache(const ServerCacheReplayer& cache_replayer,
const std::vector<LightForm>& forms) { … }
TEST(AutofillCacheReplayerTest, CrossEnvironmentIntegrationTest) { … }
#endif
}
}
}