#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "google_apis/gcm/engine/connection_handler_impl.h"
#include <stdint.h>
#include <memory>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "google/protobuf/wire_format_lite.h"
#include "google_apis/gcm/base/mcs_util.h"
#include "google_apis/gcm/base/socket_stream.h"
#include "google_apis/gcm/protocol/mcs.pb.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/ip_address.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/test_completion_callback.h"
#include "net/log/net_log_source.h"
#include "net/socket/socket_test_util.h"
#include "net/socket/stream_socket.h"
#include "net/test/gtest_util.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.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 "services/network/network_context.h"
#include "services/network/network_service.h"
#include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h"
namespace gcm {
namespace {
ScopedMessage;
ReadList;
WriteList;
const uint64_t kAuthId = …;
const uint64_t kAuthToken = …;
const char kMCSVersion = …;
const int kMCSPort = …;
const char kDataMsgFrom[] = …;
const char kDataMsgCategory[] = …;
const char kDataMsgFrom2[] = …;
const char kDataMsgCategory2[] = …;
const char kDataMsgFromLong[] = …;
const char kDataMsgCategoryLong[] = …;
const char kDataMsgFromLong2[] = …;
const char kDataMsgCategoryLong2[] = …;
const uint8_t kInvalidTag = …;
std::string EncodePacket(uint8_t tag, const std::string& proto) { … }
std::string EncodeHandshakeRequest() { … }
std::string BuildLoginResponse() { … }
std::string EncodeHandshakeResponse() { … }
std::string BuildDataMessage(const std::string& from,
const std::string& category) { … }
std::string BuildCorruptDataMessage() { … }
class GCMConnectionHandlerImplTest : public testing::Test { … };
GCMConnectionHandlerImplTest::GCMConnectionHandlerImplTest()
: … { … }
GCMConnectionHandlerImplTest::~GCMConnectionHandlerImplTest() { … }
void GCMConnectionHandlerImplTest::BuildSocket(const ReadList& read_list,
const WriteList& write_list) { … }
void GCMConnectionHandlerImplTest::PumpLoop() { … }
void GCMConnectionHandlerImplTest::Connect(
ScopedMessage* dst_proto) { … }
void GCMConnectionHandlerImplTest::ReadContinuation(
ScopedMessage* dst_proto,
ScopedMessage new_proto) { … }
void GCMConnectionHandlerImplTest::WaitForMessage() { … }
void GCMConnectionHandlerImplTest::WriteContinuation() { … }
void GCMConnectionHandlerImplTest::ConnectionContinuation(int error) { … }
TEST_F(GCMConnectionHandlerImplTest, Init) { … }
TEST_F(GCMConnectionHandlerImplTest, InitFailedVersionCheck) { … }
TEST_F(GCMConnectionHandlerImplTest, InitTimeout) { … }
TEST_F(GCMConnectionHandlerImplTest, InitIncompleteTimeout) { … }
TEST_F(GCMConnectionHandlerImplTest, ReInit) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_RecvMsg …
#else
#define MAYBE_RecvMsg …
#endif
TEST_F(GCMConnectionHandlerImplTest, MAYBE_RecvMsg) { … }
TEST_F(GCMConnectionHandlerImplTest, Recv2Msgs) { … }
TEST_F(GCMConnectionHandlerImplTest, RecvLongMsg) { … }
TEST_F(GCMConnectionHandlerImplTest, RecvLongMsg2Parts) { … }
TEST_F(GCMConnectionHandlerImplTest, Recv2LongMsgs) { … }
TEST_F(GCMConnectionHandlerImplTest, ReadTimeout) { … }
TEST_F(GCMConnectionHandlerImplTest, RecvMsgNoData) { … }
TEST_F(GCMConnectionHandlerImplTest, SendMsg) { … }
TEST_F(GCMConnectionHandlerImplTest, SendMsgSocketDisconnected) { … }
TEST_F(GCMConnectionHandlerImplTest, ExtraLargeDataPacket) { … }
TEST_F(GCMConnectionHandlerImplTest, 2ExtraLargeDataPacketMsgs) { … }
TEST_F(GCMConnectionHandlerImplTest, InvalidTag) { … }
TEST_F(GCMConnectionHandlerImplTest, RecvMsgSplitSize) { … }
TEST_F(GCMConnectionHandlerImplTest, InvalidData) { … }
TEST_F(GCMConnectionHandlerImplTest, InvalidDataLong) { … }
}
}