#include "components/policy/core/common/cloud/device_management_service.h"
#include <memory>
#include <optional>
#include <ostream>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/statistics_recorder.h"
#include "base/run_loop.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/cloud/dm_auth.h"
#include "components/policy/core/common/cloud/mock_device_management_service.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_server.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
_;
DoAll;
Invoke;
Mock;
em;
namespace policy {
const char kServiceUrl[] = …;
const char kResponseEmpty[] = …;
#define PROTO_STRING(name) …
const char kOAuthToken[] = …;
const char kDMToken[] = …;
const char kClientID[] = …;
const char kRobotAuthCode[] = …;
const char kEnrollmentToken[] = …;
const char kProfileID[] = …;
const char kIdToken[] = …;
#if BUILDFLAG(IS_IOS)
const char kOAuthAuthorizationHeaderPrefix[] = "OAuth ";
#endif
std::string GenerateResponseWithErrorDetail(
em::DeviceManagementErrorDetail error_detail) { … }
class DeviceManagementServiceTestBase : public testing::Test { … };
struct FailedRequestParams { … };
void PrintTo(const FailedRequestParams& params, std::ostream* os) { … }
class DeviceManagementServiceFailedRequestTest
: public DeviceManagementServiceTestBase,
public testing::WithParamInterface<FailedRequestParams> { … };
TEST_P(DeviceManagementServiceFailedRequestTest, RegisterRequest) { … }
TEST_P(DeviceManagementServiceFailedRequestTest, CertBasedRegisterRequest) { … }
TEST_P(DeviceManagementServiceFailedRequestTest, BrowserRegistrationRequest) { … }
TEST_P(DeviceManagementServiceFailedRequestTest,
PolicyAgentRegistrationRequest) { … }
TEST_P(DeviceManagementServiceFailedRequestTest, OidcEnrollmentRequest) { … }
TEST_P(DeviceManagementServiceFailedRequestTest, ApiAuthCodeFetchRequest) { … }
TEST_P(DeviceManagementServiceFailedRequestTest, PolicyRequest) { … }
TEST_P(DeviceManagementServiceFailedRequestTest, AutoEnrollmentRequest) { … }
INSTANTIATE_TEST_SUITE_P(…);
class QueryParams { … };
class DeviceManagementServiceTest : public DeviceManagementServiceTestBase { … };
TEST_F(DeviceManagementServiceTest, RegisterRequest) { … }
TEST_F(DeviceManagementServiceTest, CriticalRequest) { … }
TEST_F(DeviceManagementServiceTest, CertBasedRegisterRequest) { … }
TEST_F(DeviceManagementServiceTest, BrowserRegistrationRequest) { … }
TEST_F(DeviceManagementServiceTest, PolicyAgentRegistrationRequest) { … }
TEST_F(DeviceManagementServiceTest, OidcEnrollmentRequest) { … }
TEST_F(DeviceManagementServiceTest, ApiAuthCodeFetchRequest) { … }
TEST_F(DeviceManagementServiceTest, RequestWithProfileId) { … }
TEST_F(DeviceManagementServiceTest, CancelRegisterRequest) { … }
TEST_F(DeviceManagementServiceTest, CancelCertBasedRegisterRequest) { … }
TEST_F(DeviceManagementServiceTest, CancelBrowserRegistrationRequest) { … }
TEST_F(DeviceManagementServiceTest, CancelOidcEnrollmentRequest) { … }
TEST_F(DeviceManagementServiceTest, CancelApiAuthCodeFetch) { … }
TEST_F(DeviceManagementServiceTest, CancelPolicyRequest) { … }
TEST_F(DeviceManagementServiceTest, JobQueueing) { … }
TEST_F(DeviceManagementServiceTest, CancelRequestAfterShutdown) { … }
ACTION_P(ResetPointer, pointer) { … }
TEST_F(DeviceManagementServiceTest, CancelDuringCallback) { … }
TEST_F(DeviceManagementServiceTest, RetryOnProxyError) { … }
TEST_F(DeviceManagementServiceTest, RetryOnBadResponseFromProxy) { … }
TEST_F(DeviceManagementServiceTest, AcceptMimeTypeFromProxy) { … }
TEST_F(DeviceManagementServiceTest, RetryOnNetworkChanges) { … }
TEST_F(DeviceManagementServiceTest, PolicyFetchRetryImmediately) { … }
TEST_F(DeviceManagementServiceTest, RetryLimit) { … }
TEST_F(DeviceManagementServiceTest, CancelDuringRetry) { … }
class DeviceManagementRequestAuthTest : public DeviceManagementServiceTestBase { … };
TEST_F(DeviceManagementRequestAuthTest, OnlyOAuthToken) { … }
TEST_F(DeviceManagementRequestAuthTest, OnlyDMToken) { … }
TEST_F(DeviceManagementRequestAuthTest, OnlyEnrollmentToken) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(DeviceManagementRequestAuthTest, OAuthAndDMToken) { … }
TEST_F(DeviceManagementRequestAuthTest, OAuthAndEnrollmentToken) { … }
TEST_F(DeviceManagementRequestAuthTest, OidcAuthAndIdToken) { … }
#endif
#if defined(GTEST_HAS_DEATH_TEST)
TEST_F(DeviceManagementRequestAuthTest, CannotUseOAuthTokenAsAuthData) { … }
#endif
class DeviceManagementServiceTestWithTimeManipulation
: public DeviceManagementServiceTestBase { … };
TEST_F(DeviceManagementServiceTestWithTimeManipulation,
BrowserRegistrationRequestWithTimeout) { … }
TEST_F(DeviceManagementServiceTestWithTimeManipulation,
OidcEnrollmentRequestWithTimeout) { … }
}