#include "net/reporting/reporting_uploader.h"
#include <memory>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "net/base/features.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/schemeful_site.h"
#include "net/cookies/cookie_access_result.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_store_test_callbacks.h"
#include "net/http/http_status_code.h"
#include "net/socket/socket_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/test_with_task_environment.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace net {
namespace {
class ReportingUploaderTest : public TestWithTaskEnvironment { … };
const char kUploadBody[] = …;
void CheckUpload(const test_server::HttpRequest& request) { … }
std::unique_ptr<test_server::HttpResponse> AllowPreflight(
const test_server::HttpRequest& request) { … }
std::unique_ptr<test_server::HttpResponse> ReturnResponse(
HttpStatusCode code,
const test_server::HttpRequest& request) { … }
std::unique_ptr<test_server::HttpResponse> ReturnInvalidResponse(
const test_server::HttpRequest& request) { … }
class TestUploadCallback { … };
TEST_F(ReportingUploaderTest, Upload) { … }
TEST_F(ReportingUploaderTest, Success) { … }
TEST_F(ReportingUploaderTest, NetworkError1) { … }
TEST_F(ReportingUploaderTest, NetworkError2) { … }
TEST_F(ReportingUploaderTest, ServerError) { … }
std::unique_ptr<test_server::HttpResponse> VerifyPreflight(
bool* preflight_received_out,
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, VerifyPreflight) { … }
TEST_F(ReportingUploaderTest, SkipPreflightForSameOrigin) { … }
std::unique_ptr<test_server::HttpResponse> ReturnPreflightError(
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, FailedCorsPreflight) { … }
std::unique_ptr<test_server::HttpResponse> ReturnPreflightWithoutOrigin(
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, CorsPreflightWithoutOrigin) { … }
std::unique_ptr<test_server::HttpResponse> ReturnPreflightWithoutMethods(
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, CorsPreflightWithoutMethods) { … }
std::unique_ptr<test_server::HttpResponse> ReturnPreflightWithWildcardMethods(
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, CorsPreflightWildcardMethods) { … }
std::unique_ptr<test_server::HttpResponse> ReturnPreflightWithoutHeaders(
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, CorsPreflightWithoutHeaders) { … }
std::unique_ptr<test_server::HttpResponse> ReturnPreflightWithWildcardHeaders(
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, CorsPreflightWildcardHeaders) { … }
TEST_F(ReportingUploaderTest, RemoveEndpoint) { … }
const char kRedirectPath[] = …;
std::unique_ptr<test_server::HttpResponse> ReturnRedirect(
const std::string& location,
const test_server::HttpRequest& request) { … }
std::unique_ptr<test_server::HttpResponse> CheckRedirect(
bool* redirect_followed_out,
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, FollowHttpsRedirect) { … }
TEST_F(ReportingUploaderTest, DontFollowHttpRedirect) { … }
void CheckNoCookie(const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, DontSendCookies) { … }
std::unique_ptr<test_server::HttpResponse> SendCookie(
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, DontSaveCookies) { … }
std::unique_ptr<test_server::HttpResponse> ReturnCacheableResponse(
int* request_count_out,
const test_server::HttpRequest& request) { … }
TEST_F(ReportingUploaderTest, DontCacheResponse) { … }
TEST_F(ReportingUploaderTest, RespectsNetworkAnonymizationKey) { … }
}
}