#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/devtools/device/adb/mock_adb_server.h"
#include <stddef.h>
#include <stdint.h>
#include <string_view>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/sequence_checker.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_source.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_server_socket.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
BrowserThread;
namespace {
const char kHostTransportPrefix[] = …;
const char kLocalAbstractPrefix[] = …;
const char kShellPrefix[] = …;
const char kOpenedUnixSocketsCommand[] = …;
const char kDeviceModelCommand[] = …;
const char kDumpsysCommand[] = …;
const char kListProcessesCommand[] = …;
const char kListUsersCommand[] = …;
const char kEchoCommandPrefix[] = …;
const char kSerialOnline[] = …;
const char kSerialOffline[] = …;
const char kDeviceModel[] = …;
const char kJsonVersionPath[] = …;
const char kJsonPath[] = …;
const char kJsonListPath[] = …;
const char kHttpRequestTerminator[] = …;
const char kHttpResponse[] = …;
const char kSampleOpenedUnixSockets[] = …;
const char kSampleListProcesses[] = …;
const char kSampleDumpsys[] = …;
const char kSampleListUsers[] = …;
char kSampleChromeVersion[] = …;
char kSampleChromeBetaVersion[] = …;
char kSampleWebViewVersion[] = …;
char kSampleNodeVersion[] = …;
char kSampleChromePages[] = …;
char kSampleChromeBetaPages[] = …;
char kSampleWebViewPages[] = …;
char kSampleNodePage[] = …;
static const int kBufferSize = …;
static const uint16_t kAdbPort = …;
static const int kAdbMessageHeaderSize = …;
class SimpleHttpServer { … };
SimpleHttpServer::SimpleHttpServer(const ParserFactory& factory,
net::IPEndPoint endpoint)
: … { … }
SimpleHttpServer::~SimpleHttpServer() { … }
SimpleHttpServer::Connection::Connection(net::StreamSocket* socket,
const ParserFactory& factory)
: … { … }
SimpleHttpServer::Connection::~Connection() { … }
void SimpleHttpServer::Connection::Send(const std::string& message) { … }
void SimpleHttpServer::Connection::ReadData() { … }
void SimpleHttpServer::Connection::OnDataRead(int count) { … }
void SimpleHttpServer::Connection::WriteData() { … }
void SimpleHttpServer::Connection::OnDataWritten(int count) { … }
void SimpleHttpServer::OnConnect() { … }
void SimpleHttpServer::OnAccepted(int result) { … }
class AdbParser : public SimpleHttpServer::Parser,
public MockAndroidConnection::Delegate { … };
static SimpleHttpServer* mock_adb_server_ = …;
void StartMockAdbServerOnIOThread(FlushMode flush_mode) { … }
void StopMockAdbServerOnIOThread() { … }
}
MockAndroidConnection::MockAndroidConnection(
Delegate* delegate,
const std::string& serial,
const std::string& command)
: … { … }
MockAndroidConnection::~MockAndroidConnection() { … }
void MockAndroidConnection::Receive(const std::string& data) { … }
void MockAndroidConnection::ProcessCommand(const std::string& command) { … }
void MockAndroidConnection::SendHTTPResponse(const std::string& body) { … }
void StartMockAdbServer(FlushMode flush_mode) { … }
void StopMockAdbServer() { … }