chromium/components/gcm_driver/gcm_client_impl_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/gcm_driver/gcm_client_impl.h"

#include <stdint.h>

#include <initializer_list>
#include <memory>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "components/gcm_driver/features.h"
#include "google_apis/gcm/base/fake_encryptor.h"
#include "google_apis/gcm/base/mcs_message.h"
#include "google_apis/gcm/base/mcs_util.h"
#include "google_apis/gcm/engine/checkin_request.h"
#include "google_apis/gcm/engine/fake_connection_factory.h"
#include "google_apis/gcm/engine/fake_connection_handler.h"
#include "google_apis/gcm/engine/gservices_settings.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
#include "google_apis/gcm/protocol/android_checkin.pb.h"
#include "google_apis/gcm/protocol/checkin.pb.h"
#include "google_apis/gcm/protocol/mcs.pb.h"
#include "net/test/gtest_util.h"
#include "net/test/scoped_disable_exit_on_dfatal.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_network_connection_tracker.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/leveldatabase/leveldb_chrome.h"

namespace gcm {
namespace {

enum LastEvent {};

const char kChromeVersion[] =;
const uint64_t kDeviceAndroidId =;
const uint64_t kDeviceSecurityToken =;
const uint64_t kDeviceAndroidId2 =;
const uint64_t kDeviceSecurityToken2 =;
const int64_t kSettingsCheckinInterval =;
const char kProductCategoryForSubtypes[] =;
const char kExtensionAppId[] =;
const char kRegistrationId[] =;
const char kSubtypeAppId[] =;
const char kSender[] =;
const char kSender2[] =;
const char kRegistrationResponsePrefix[] =;
const char kUnregistrationResponsePrefix[] =;
const char kRawData[] =;

const char kInstanceID[] =;
const char kScope[] =;
const char kDeleteTokenResponse[] =;
const int kTestTokenInvalidationPeriod =;
const char kMessageId[] =;

const char kRegisterUrl[] =;

// Helper for building arbitrary data messages.
MCSMessage BuildDownstreamMessage(
    const std::string& project_id,
    const std::string& category,
    const std::string& subtype,
    const std::map<std::string, std::string>& data,
    const std::string& raw_data) {}

GCMClient::AccountTokenInfo MakeAccountToken(const std::string& email,
                                             const std::string& token) {}

std::map<std::string, std::string> MakeEmailToTokenMap(
    const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {}

class FakeMCSClient : public MCSClient {};

FakeMCSClient::FakeMCSClient(
    base::Clock* clock,
    ConnectionFactory* connection_factory,
    GCMStore* gcm_store,
    scoped_refptr<base::SequencedTaskRunner> io_task_runner,
    GCMStatsRecorder* recorder)
    :{}

FakeMCSClient::~FakeMCSClient() {}

void FakeMCSClient::Login(uint64_t android_id, uint64_t security_token) {}

void FakeMCSClient::SendMessage(const MCSMessage& message) {}

class AutoAdvancingTestClock : public base::Clock {};

AutoAdvancingTestClock::AutoAdvancingTestClock(
    base::TimeDelta auto_increment_time_delta)
    :{}

AutoAdvancingTestClock::~AutoAdvancingTestClock() {}

base::Time AutoAdvancingTestClock::Now() const {}

void AutoAdvancingTestClock::Advance(base::TimeDelta delta) {}

class FakeGCMInternalsBuilder : public GCMInternalsBuilder {};

FakeGCMInternalsBuilder::FakeGCMInternalsBuilder(base::TimeDelta clock_step)
    :{}

FakeGCMInternalsBuilder::~FakeGCMInternalsBuilder() {}

base::Clock* FakeGCMInternalsBuilder::GetClock() {}

std::unique_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient(
    const std::string& version,
    base::Clock* clock,
    ConnectionFactory* connection_factory,
    GCMStore* gcm_store,
    scoped_refptr<base::SequencedTaskRunner> io_task_runner,
    GCMStatsRecorder* recorder) {}

std::unique_ptr<ConnectionFactory>
FakeGCMInternalsBuilder::BuildConnectionFactory(
    const std::vector<GURL>& endpoints,
    const net::BackoffEntry::Policy& backoff_policy,
    base::RepeatingCallback<void(
        mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
        get_socket_factory_callback,
    scoped_refptr<base::SequencedTaskRunner> io_task_runner,
    GCMStatsRecorder* recorder,
    network::NetworkConnectionTracker* network_connection_tracker) {}

}  // namespace

class GCMClientImplTest : public testing::Test,
                          public GCMClient::Delegate {};

GCMClientImplTest::GCMClientImplTest()
    :{}

GCMClientImplTest::~GCMClientImplTest() {}

void GCMClientImplTest::SetUp() {}

void GCMClientImplTest::TearDown() {}

void GCMClientImplTest::SetFeatureParams(const base::Feature& feature,
                                         const base::FieldTrialParams& params) {}

void GCMClientImplTest::InitializeInvalidationFieldTrial() {}

void GCMClientImplTest::PumpLoopUntilIdle() {}

bool GCMClientImplTest::CreateUniqueTempDir() {}

void GCMClientImplTest::BuildGCMClient(base::TimeDelta clock_step) {}

void GCMClientImplTest::FailCheckin(net::HttpStatusCode response_code) {}

void GCMClientImplTest::CompleteCheckin(
    uint64_t android_id,
    uint64_t security_token,
    const std::string& digest,
    const std::map<std::string, std::string>& settings) {}

void GCMClientImplTest::CompleteCheckinImpl(
    uint64_t android_id,
    uint64_t security_token,
    const std::string& digest,
    const std::map<std::string, std::string>& settings,
    net::HttpStatusCode response_code) {}

void GCMClientImplTest::CompleteRegistration(
    const std::string& registration_id) {}

void GCMClientImplTest::CompleteUnregistration(
    const std::string& app_id) {}

bool GCMClientImplTest::ExistsRegistration(const std::string& app_id) const {}

void GCMClientImplTest::AddRegistration(
    const std::string& app_id,
    const std::vector<std::string>& sender_ids,
    const std::string& registration_id) {}

void GCMClientImplTest::InitializeGCMClient() {}

void GCMClientImplTest::StartGCMClient() {}

void GCMClientImplTest::Register(const std::string& app_id,
                                 const std::vector<std::string>& senders) {}

void GCMClientImplTest::Unregister(const std::string& app_id) {}

void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) {}

void GCMClientImplTest::ReceiveOnMessageSentToMCS(
      const std::string& app_id,
      const std::string& message_id,
      const MCSClient::MessageSendStatus status) {}

void GCMClientImplTest::OnGCMReady(
    const std::vector<AccountMapping>& account_mappings,
    const base::Time& last_token_fetch_time) {}

void GCMClientImplTest::OnMessageReceived(const std::string& registration_id,
                                          const IncomingMessage& message) {}

void GCMClientImplTest::OnRegisterFinished(
    scoped_refptr<RegistrationInfo> registration_info,
    const std::string& registration_id,
    GCMClient::Result result) {}

void GCMClientImplTest::OnUnregisterFinished(
    scoped_refptr<RegistrationInfo> registration_info,
    GCMClient::Result result) {}

void GCMClientImplTest::OnMessagesDeleted(const std::string& app_id) {}

void GCMClientImplTest::OnMessageSendError(
    const std::string& app_id,
    const gcm::GCMClient::SendErrorDetails& send_error_details) {}

void GCMClientImplTest::OnSendAcknowledged(const std::string& app_id,
                                           const std::string& message_id) {}

int64_t GCMClientImplTest::CurrentTime() {}

TEST_F(GCMClientImplTest, LoadingCompleted) {}

TEST_F(GCMClientImplTest, LoadingBusted) {}

TEST_F(GCMClientImplTest, LoadingWithEmptyDirectory) {}

TEST_F(GCMClientImplTest, DestroyStoreWhenNotNeeded) {}

TEST_F(GCMClientImplTest, SerializeAndDeserialize) {}

TEST_F(GCMClientImplTest, RegisterApp) {}

TEST_F(GCMClientImplTest, RegisterAppFromCache) {}

TEST_F(GCMClientImplTest, RegisterPreviousSenderAgain) {}

TEST_F(GCMClientImplTest, RegisterAgainWhenTokenIsFresh) {}

TEST_F(GCMClientImplTest, RegisterAgainWhenTokenIsStale) {}

TEST_F(GCMClientImplTest, UnregisterApp) {}

// Tests that stopping the GCMClient also deletes pending registration requests.
// This is tested by checking that url fetcher contained in the request was
// deleted.
TEST_F(GCMClientImplTest, DeletePendingRequestsWhenStopping) {}

TEST_F(GCMClientImplTest, DispatchDownstreamMessage) {}

TEST_F(GCMClientImplTest, DispatchDownstreamMessageRawData) {}

TEST_F(GCMClientImplTest, DispatchDownstreamMessageSendError) {}

TEST_F(GCMClientImplTest, DispatchDownstreamMessgaesDeleted) {}

TEST_F(GCMClientImplTest, SendMessage) {}

TEST_F(GCMClientImplTest, SendMessageAcknowledged) {}

class GCMClientImplCheckinTest : public GCMClientImplTest {};

GCMClientImplCheckinTest::GCMClientImplCheckinTest() {}

GCMClientImplCheckinTest::~GCMClientImplCheckinTest() {}

void GCMClientImplCheckinTest::SetUp() {}

TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) {}

// This test only checks that periodic checkin happens.
TEST_F(GCMClientImplCheckinTest, PeriodicCheckin) {}

TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {}

// This test only checks that periodic checkin happens.
TEST_F(GCMClientImplCheckinTest, CheckinWithAccountsEmpty) {}

// This test only checks that periodic checkin happens.
TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemoved) {}

// This test only checks that periodic checkin happens.
TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountReplaced) {}

TEST_F(GCMClientImplCheckinTest, ResetStoreWhenCheckinRejected) {}

class GCMClientImplStartAndStopTest : public GCMClientImplTest {};

GCMClientImplStartAndStopTest::GCMClientImplStartAndStopTest() {}

GCMClientImplStartAndStopTest::~GCMClientImplStartAndStopTest() {}

void GCMClientImplStartAndStopTest::SetUp() {}

void GCMClientImplStartAndStopTest::DefaultCompleteCheckin() {}

TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestart) {}

TEST_F(GCMClientImplStartAndStopTest, DelayedStartAndStopImmediately) {}

TEST_F(GCMClientImplStartAndStopTest, ImmediateStartAndStopImmediately) {}

TEST_F(GCMClientImplStartAndStopTest, DelayedStartStopAndRestart) {}

TEST_F(GCMClientImplStartAndStopTest, ImmediateStartStopAndRestart) {}

TEST_F(GCMClientImplStartAndStopTest, ImmediateStartAndThenImmediateStart) {}

TEST_F(GCMClientImplStartAndStopTest, ImmediateStartAndThenDelayStart) {}

TEST_F(GCMClientImplStartAndStopTest, DelayedStartRace) {}

TEST_F(GCMClientImplStartAndStopTest, DelayedStart) {}

// Test for known account mappings and last token fetching time being passed
// to OnGCMReady.
TEST_F(GCMClientImplStartAndStopTest, OnGCMReadyAccountsAndTokenFetchingTime) {}


class GCMClientInstanceIDTest : public GCMClientImplTest {};

GCMClientInstanceIDTest::GCMClientInstanceIDTest() {}

GCMClientInstanceIDTest::~GCMClientInstanceIDTest() {}

void GCMClientInstanceIDTest::AddInstanceID(const std::string& app_id,
                                            const std::string& instance_id) {}

void GCMClientInstanceIDTest::RemoveInstanceID(const std::string& app_id) {}

void GCMClientInstanceIDTest::GetToken(const std::string& app_id,
                                       const std::string& authorized_entity,
                                       const std::string& scope) {}

void GCMClientInstanceIDTest::DeleteToken(const std::string& app_id,
                                          const std::string& authorized_entity,
                                          const std::string& scope) {}

void GCMClientInstanceIDTest::CompleteDeleteToken() {}

bool GCMClientInstanceIDTest::ExistsToken(const std::string& app_id,
                                          const std::string& authorized_entity,
                                          const std::string& scope) const {}

TEST_F(GCMClientInstanceIDTest, GetToken) {}

// Most tests in this file use kExtensionAppId which is special-cased by
// InstanceIDUsesSubtypeForAppId in gcm_client_impl.cc. This test uses
// kSubtypeAppId to cover the alternate case.
TEST_F(GCMClientInstanceIDTest, GetTokenWithSubtype) {}

TEST_F(GCMClientInstanceIDTest, DeleteInvalidToken) {}

TEST_F(GCMClientInstanceIDTest, DeleteSingleToken) {}

TEST_F(GCMClientInstanceIDTest, DeleteAllTokens) {}

TEST_F(GCMClientInstanceIDTest, DeleteAllTokensBeforeGetAnyToken) {}

TEST_F(GCMClientInstanceIDTest, DispatchDownstreamMessageWithoutSubtype) {}

TEST_F(GCMClientInstanceIDTest, DispatchDownstreamMessageWithSubtype) {}

TEST_F(GCMClientInstanceIDTest, DispatchDownstreamMessageWithFakeSubtype) {}

}  // namespace gcm