#include "components/gcm_driver/gcm_driver_desktop.h"
#include <stdint.h>
#include <memory>
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/task/current_thread.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "components/gcm_driver/crypto/gcm_encryption_provider.h"
#include "components/gcm_driver/fake_gcm_app_handler.h"
#include "components/gcm_driver/fake_gcm_client.h"
#include "components/gcm_driver/fake_gcm_client_factory.h"
#include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_connection_observer.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gcm {
namespace {
const char kTestAppID1[] = …;
const char kTestAppID2[] = …;
const char kUserID1[] = …;
const char kScope[] = …;
const char kInstanceID1[] = …;
const char kInstanceID2[] = …;
class FakeGCMConnectionObserver : public GCMConnectionObserver { … };
FakeGCMConnectionObserver::FakeGCMConnectionObserver() : … { … }
FakeGCMConnectionObserver::~FakeGCMConnectionObserver() { … }
void FakeGCMConnectionObserver::OnConnected(
const net::IPEndPoint& ip_endpoint) { … }
void FakeGCMConnectionObserver::OnDisconnected() { … }
void PumpCurrentLoop() { … }
void PumpUILoop() { … }
std::vector<std::string> ToSenderList(const std::string& sender_ids) { … }
}
class GCMDriverTest : public testing::Test { … };
GCMDriverTest::GCMDriverTest()
: … { … }
GCMDriverTest::~GCMDriverTest() { … }
void GCMDriverTest::SetUp() { … }
void GCMDriverTest::TearDown() { … }
void GCMDriverTest::PumpIOLoop() { … }
void GCMDriverTest::ClearResults() { … }
bool GCMDriverTest::HasAppHandlers() const { … }
FakeGCMClient* GCMDriverTest::GetGCMClient() { … }
void GCMDriverTest::CreateDriver() { … }
void GCMDriverTest::ShutdownDriver() { … }
void GCMDriverTest::AddAppHandlers() { … }
void GCMDriverTest::RemoveAppHandlers() { … }
void GCMDriverTest::Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
WaitToFinish wait_to_finish) { … }
void GCMDriverTest::Send(const std::string& app_id,
const std::string& receiver_id,
const OutgoingMessage& message,
WaitToFinish wait_to_finish) { … }
void GCMDriverTest::GetEncryptionInfo(const std::string& app_id,
WaitToFinish wait_to_finish) { … }
void GCMDriverTest::Unregister(const std::string& app_id,
WaitToFinish wait_to_finish) { … }
void GCMDriverTest::WaitForAsyncOperation() { … }
void GCMDriverTest::RegisterCompleted(const std::string& registration_id,
GCMClient::Result result) { … }
void GCMDriverTest::SendCompleted(const std::string& message_id,
GCMClient::Result result) { … }
void GCMDriverTest::GetEncryptionInfoCompleted(std::string p256dh,
std::string auth_secret) { … }
void GCMDriverTest::UnregisterCompleted(GCMClient::Result result) { … }
TEST_F(GCMDriverTest, Create) { … }
TEST_F(GCMDriverTest, Shutdown) { … }
TEST_F(GCMDriverTest, StartOrStopGCMOnDemand) { … }
TEST_F(GCMDriverTest, RegisterFailed) { … }
TEST_F(GCMDriverTest, UnregisterFailed) { … }
TEST_F(GCMDriverTest, SendFailed) { … }
TEST_F(GCMDriverTest, GCMClientNotReadyBeforeRegistration) { … }
TEST_F(GCMDriverTest, GCMClientNotReadyBeforeSending) { … }
class GCMDriverFunctionalTest : public GCMDriverTest { … };
GCMDriverFunctionalTest::GCMDriverFunctionalTest() { … }
GCMDriverFunctionalTest::~GCMDriverFunctionalTest() { … }
void GCMDriverFunctionalTest::SetUp() { … }
TEST_F(GCMDriverFunctionalTest, Register) { … }
TEST_F(GCMDriverFunctionalTest, RegisterError) { … }
TEST_F(GCMDriverFunctionalTest, RegisterAgainWithSameSenderIDs) { … }
TEST_F(GCMDriverFunctionalTest, RegisterAgainWithDifferentSenderIDs) { … }
TEST_F(GCMDriverFunctionalTest, UnregisterExplicitly) { … }
#if defined(ADDRESS_SANITIZER)
TEST_F(GCMDriverFunctionalTest, DISABLED_UnregisterRemovesEncryptionInfo) {
#else
TEST_F(GCMDriverFunctionalTest, UnregisterRemovesEncryptionInfo) { … }
TEST_F(GCMDriverFunctionalTest, UnregisterWhenAsyncOperationPending) { … }
TEST_F(GCMDriverFunctionalTest, RegisterWhenAsyncOperationPending) { … }
TEST_F(GCMDriverFunctionalTest, RegisterAfterUnfinishedUnregister) { … }
TEST_F(GCMDriverFunctionalTest, Send) { … }
TEST_F(GCMDriverFunctionalTest, SendError) { … }
TEST_F(GCMDriverFunctionalTest, MessageReceived) { … }
TEST_F(GCMDriverFunctionalTest, MessageWithCollapseKeyReceived) { … }
TEST_F(GCMDriverFunctionalTest, EncryptedMessageReceivedError) { … }
TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { … }
TEST_F(GCMDriverFunctionalTest, LastTokenFetchTime) { … }
class GCMDriverInstanceIDTest : public GCMDriverTest { … };
GCMDriverInstanceIDTest::GCMDriverInstanceIDTest() { … }
GCMDriverInstanceIDTest::~GCMDriverInstanceIDTest() { … }
void GCMDriverInstanceIDTest::GetReady() { … }
void GCMDriverInstanceIDTest::GetInstanceID(const std::string& app_id,
WaitToFinish wait_to_finish) { … }
void GCMDriverInstanceIDTest::GetInstanceIDDataCompleted(
const std::string& instance_id, const std::string& extra_data) { … }
void GCMDriverInstanceIDTest::GetToken(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
WaitToFinish wait_to_finish) { … }
void GCMDriverInstanceIDTest::DeleteToken(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
WaitToFinish wait_to_finish) { … }
void GCMDriverInstanceIDTest::AddInstanceIDData(const std::string& app_id,
const std::string& instance_id,
const std::string& extra_data) { … }
void GCMDriverInstanceIDTest::RemoveInstanceIDData(const std::string& app_id) { … }
TEST_F(GCMDriverInstanceIDTest, InstanceIDData) { … }
TEST_F(GCMDriverInstanceIDTest, GCMClientNotReadyBeforeInstanceIDData) { … }
TEST_F(GCMDriverInstanceIDTest, GetToken) { … }
TEST_F(GCMDriverInstanceIDTest, GetTokenError) { … }
TEST_F(GCMDriverInstanceIDTest, GCMClientNotReadyBeforeGetToken) { … }
TEST_F(GCMDriverInstanceIDTest, DeleteToken) { … }
TEST_F(GCMDriverInstanceIDTest, GCMClientNotReadyBeforeDeleteToken) { … }
}