#include "components/gcm_driver/gcm_account_tracker.h"
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "base/memory/raw_ptr.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/chromeos_buildflags.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/base/ip_endpoint.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gcm {
namespace {
const char kEmail1[] = …;
const char kEmail2[] = …;
std::string MakeAccessToken(const CoreAccountId& account_id) { … }
GCMClient::AccountTokenInfo MakeAccountToken(const CoreAccountInfo& account) { … }
void VerifyAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& expected_tokens,
const std::vector<GCMClient::AccountTokenInfo>& actual_tokens) { … }
class CustomFakeGCMDriver : public FakeGCMDriver { … };
CustomFakeGCMDriver::CustomFakeGCMDriver()
: … { … }
CustomFakeGCMDriver::~CustomFakeGCMDriver() { … }
void CustomFakeGCMDriver::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& accounts) { … }
void CustomFakeGCMDriver::AddConnectionObserver(
GCMConnectionObserver* observer) { … }
void CustomFakeGCMDriver::RemoveConnectionObserver(
GCMConnectionObserver* observer) { … }
void CustomFakeGCMDriver::SetConnected(bool connected) { … }
void CustomFakeGCMDriver::ResetResults() { … }
base::Time CustomFakeGCMDriver::GetLastTokenFetchTime() { … }
void CustomFakeGCMDriver::SetLastTokenFetchTime(const base::Time& time) { … }
}
class GCMAccountTrackerTest : public testing::Test { … };
GCMAccountTrackerTest::GCMAccountTrackerTest() { … }
GCMAccountTrackerTest::~GCMAccountTrackerTest() { … }
CoreAccountInfo GCMAccountTrackerTest::AddAccount(const std::string& email) { … }
CoreAccountInfo GCMAccountTrackerTest::SetPrimaryAccount(
const std::string& email) { … }
void GCMAccountTrackerTest::ClearPrimaryAccount() { … }
void GCMAccountTrackerTest::RemoveAccount(const CoreAccountId& account_id) { … }
void GCMAccountTrackerTest::IssueAccessToken(const CoreAccountId& account_id) { … }
void GCMAccountTrackerTest::IssueExpiredAccessToken(
const CoreAccountId& account_id) { … }
void GCMAccountTrackerTest::IssueError(const CoreAccountId& account_id) { … }
bool GCMAccountTrackerTest::IsFetchingRequired() const { … }
bool GCMAccountTrackerTest::IsTokenReportingRequired() const { … }
base::TimeDelta GCMAccountTrackerTest::GetTimeToNextTokenReporting() const { … }
TEST_F(GCMAccountTrackerTest, NoAccounts) { … }
TEST_F(GCMAccountTrackerTest, SingleAccount) { … }
TEST_F(GCMAccountTrackerTest, MultipleAccounts) { … }
TEST_F(GCMAccountTrackerTest, AccountAdded) { … }
TEST_F(GCMAccountTrackerTest, AccountRemoved) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(GCMAccountTrackerTest, AccountRemovedWithoutSyncConsentNoCrash) { … }
#endif
TEST_F(GCMAccountTrackerTest, GetTokenFailed) { … }
TEST_F(GCMAccountTrackerTest, GetTokenFailedAccountRemoved) { … }
TEST_F(GCMAccountTrackerTest, AccountRemovedWhileRequestsPending) { … }
TEST_F(GCMAccountTrackerTest, TrackerObservesConnection) { … }
TEST_F(GCMAccountTrackerTest, PostponeTokenFetchingUntilConnected) { … }
TEST_F(GCMAccountTrackerTest, InvalidateExpiredTokens) { … }
TEST_F(GCMAccountTrackerTest, IsTokenFetchingRequired) { … }
TEST_F(GCMAccountTrackerTest, GetTimeToNextTokenReporting) { … }
TEST_F(GCMAccountTrackerTest, IsTokenReportingRequired) { … }
}