1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_NETWORK_TEST_MOCK_DEVTOOLS_OBSERVER_H_
#define SERVICES_NETWORK_TEST_MOCK_DEVTOOLS_OBSERVER_H_
#include <optional>
#include <string>
#include "base/run_loop.h"
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "net/url_request/url_request.h"
#include "services/network/public/mojom/client_security_state.mojom-forward.h"
#include "services/network/public/mojom/devtools_observer.mojom.h"
#include "services/network/public/mojom/http_raw_headers.mojom-forward.h"
#include "services/network/public/mojom/ip_address_space.mojom-forward.h"
#include "services/network/public/mojom/shared_dictionary_error.mojom.h"
#include "services/network/public/mojom/sri_message_signature.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace network {
class MockDevToolsObserver : public mojom::DevToolsObserver {
public:
MockDevToolsObserver();
~MockDevToolsObserver() override;
MockDevToolsObserver(const MockDevToolsObserver&) = delete;
MockDevToolsObserver& operator=(const MockDevToolsObserver&) = delete;
mojo::PendingRemote<mojom::DevToolsObserver> Bind();
// mojom::DevToolsObserver:
void OnRawRequest(
const std::string& devtools_request_id,
const net::CookieAccessResultList& cookies_with_access_result,
std::vector<network::mojom::HttpRawHeaderPairPtr> headers,
const base::TimeTicks timestamp,
network::mojom::ClientSecurityStatePtr client_security_state,
network::mojom::OtherPartitionInfoPtr site_has_cookie_in_other_partition,
const std::optional<base::UnguessableToken>&
applied_network_conditions_id) override;
void OnRawResponse(
const std::string& devtools_request_id,
const net::CookieAndLineAccessResultList& cookies_with_access_result,
std::vector<network::mojom::HttpRawHeaderPairPtr> headers,
const std::optional<std::string>& raw_response_headers,
network::mojom::IPAddressSpace resource_address_space,
int32_t http_status_code,
const std::optional<net::CookiePartitionKey>& cookie_partition_key)
override;
void OnEarlyHintsResponse(
const std::string& devtools_request_id,
std::vector<network::mojom::HttpRawHeaderPairPtr> headers) override;
void OnPrivateNetworkRequest(
const std::optional<std::string>& devtools_request_id,
const GURL& url,
bool is_warning,
network::mojom::IPAddressSpace resource_address_space,
network::mojom::ClientSecurityStatePtr client_security_state) override;
void OnCorsPreflightRequest(
const base::UnguessableToken& devtool_request_id,
const net::HttpRequestHeaders& request_headers,
network::mojom::URLRequestDevToolsInfoPtr request_info,
const GURL& initiator_url,
const std::string& initiator_devtool_request_id) override;
void OnCorsPreflightResponse(
const base::UnguessableToken& devtool_request_id,
const GURL& url,
network::mojom::URLResponseHeadDevToolsInfoPtr head) override;
void OnCorsPreflightRequestCompleted(
const base::UnguessableToken& devtool_request_id,
const network::URLLoaderCompletionStatus& status) override;
void OnTrustTokenOperationDone(
const std::string& devtool_request_id,
network::mojom::TrustTokenOperationResultPtr result) override;
MOCK_METHOD(void,
OnSharedDictionaryError,
(const std::string& devtool_request_id,
const GURL& url,
network::mojom::SharedDictionaryError error),
(override));
MOCK_METHOD(void,
OnSRIMessageSignatureIssue,
(const std::string& devtool_request_id,
const GURL& url,
std::vector<network::mojom::SRIMessageSignatureIssuePtr> issues),
(override));
MOCK_METHOD(void,
OnUnencodedDigestError,
(const std::string& devtool_request_id,
const GURL& url,
network::mojom::UnencodedDigestIssue issue),
(override));
void OnCorsError(const std::optional<std::string>& devtool_request_id,
const std::optional<::url::Origin>& initiator_origin,
mojom::ClientSecurityStatePtr client_security_state,
const GURL& url,
const network::CorsErrorStatus& status,
bool is_warning) override;
MOCK_METHOD(void,
OnOrbError,
(const std::optional<std::string>& devtools_request_id,
const GURL& url),
(override));
void Clone(mojo::PendingReceiver<DevToolsObserver> observer) override;
void WaitUntilRawResponse(size_t goal);
void WaitUntilRawRequest(size_t goal);
void WaitUntilPrivateNetworkRequest();
void WaitUntilCorsError();
void WaitUntilEarlyHints();
const net::CookieAndLineAccessResultList& raw_response_cookies() const {
return raw_response_cookies_;
}
const net::CookieAccessResultList& raw_request_cookies() const {
return raw_request_cookies_;
}
const std::string devtools_request_id() { return devtools_request_id_; }
const std::vector<network::mojom::HttpRawHeaderPairPtr>& response_headers()
const {
return response_headers_;
}
const std::optional<std::string> raw_response_headers() const {
return raw_response_headers_;
}
int32_t raw_response_http_status_code() const {
return raw_response_http_status_code_;
}
const network::mojom::ClientSecurityStatePtr& client_security_state() const {
return client_security_state_;
}
network::mojom::IPAddressSpace resource_address_space() const {
return resource_address_space_;
}
struct OnPrivateNetworkRequestParams {
OnPrivateNetworkRequestParams(
const std::optional<std::string>& devtools_request_id,
const GURL& url,
bool is_warning,
network::mojom::IPAddressSpace resource_address_space,
network::mojom::ClientSecurityStatePtr client_security_state);
OnPrivateNetworkRequestParams(OnPrivateNetworkRequestParams&&);
~OnPrivateNetworkRequestParams();
std::optional<std::string> devtools_request_id;
GURL url;
bool is_warning;
network::mojom::IPAddressSpace resource_address_space;
network::mojom::ClientSecurityStatePtr client_security_state;
};
const std::optional<OnPrivateNetworkRequestParams>&
private_network_request_params() const {
return params_of_private_network_request_;
}
struct OnCorsErrorParams {
OnCorsErrorParams();
OnCorsErrorParams(OnCorsErrorParams&&);
OnCorsErrorParams& operator=(OnCorsErrorParams&&);
~OnCorsErrorParams();
std::optional<std::string> devtools_request_id;
std::optional<::url::Origin> initiator_origin;
mojom::ClientSecurityStatePtr client_security_state;
GURL url;
std::optional<network::CorsErrorStatus> status;
bool is_warning = false;
};
const std::optional<OnCorsErrorParams>& cors_error_params() const {
return params_of_cors_error_;
}
const std::optional<net::CookiePartitionKey>& response_cookie_partition_key()
const {
return response_cookie_partition_key_;
}
const std::optional<network::URLLoaderCompletionStatus>& preflight_status()
const {
return preflight_status_;
}
const std::vector<network::mojom::HttpRawHeaderPairPtr>& early_hint_headers()
const {
return early_hints_headers_;
}
private:
net::CookieAndLineAccessResultList raw_response_cookies_;
base::OnceClosure wait_for_raw_response_;
size_t wait_for_raw_response_goal_ = 0u;
bool got_raw_response_ = false;
network::mojom::IPAddressSpace resource_address_space_;
std::string devtools_request_id_;
std::optional<std::string> raw_response_headers_;
std::vector<network::mojom::HttpRawHeaderPairPtr> response_headers_;
int32_t raw_response_http_status_code_ = -1;
std::optional<network::URLLoaderCompletionStatus> preflight_status_;
bool got_raw_request_ = false;
net::CookieAccessResultList raw_request_cookies_;
base::OnceClosure wait_for_raw_request_;
size_t wait_for_raw_request_goal_ = 0u;
network::mojom::ClientSecurityStatePtr client_security_state_;
base::RunLoop wait_for_private_network_request_;
std::optional<OnPrivateNetworkRequestParams>
params_of_private_network_request_;
base::RunLoop wait_for_cors_error_;
std::optional<OnCorsErrorParams> params_of_cors_error_;
mojo::ReceiverSet<mojom::DevToolsObserver> receivers_;
std::optional<net::CookiePartitionKey> response_cookie_partition_key_;
base::RunLoop wait_for_early_hints_;
std::vector<network::mojom::HttpRawHeaderPairPtr> early_hints_headers_;
};
} // namespace network
#endif // SERVICES_NETWORK_TEST_MOCK_DEVTOOLS_OBSERVER_H_
|