chromium/components/sync/service/sync_service_impl_startup_unittest.cc

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

#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "build/chromeos_buildflags.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/sync/base/pref_names.h"
#include "components/sync/engine/sync_protocol_error.h"
#include "components/sync/service/sync_service_impl.h"
#include "components/sync/test/fake_data_type_controller.h"
#include "components/sync/test/fake_sync_engine.h"
#include "components/sync/test/fake_sync_engine_factory.h"
#include "components/sync/test/sync_client_mock.h"
#include "components/sync/test/sync_service_impl_bundle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
ByMove;
Return;

namespace syncer {

namespace {

const char kEmail[] =;
const char kTimeDeferredHistogram[] =;

class MockSyncServiceObserver : public SyncServiceObserver {};

}  // namespace

class SyncServiceImplStartupTest : public testing::Test {};

// ChromeOS does not support sign-in after startup
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplStartupTest, StartFirstTime) {}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

TEST_F(SyncServiceImplStartupTest, StartNoCredentials) {}

TEST_F(SyncServiceImplStartupTest, WebSignoutBeforeInitialization) {}

TEST_F(SyncServiceImplStartupTest, WebSignoutDuringDeferredStartup) {}

TEST_F(SyncServiceImplStartupTest, WebSignoutAfterInitialization) {}

TEST_F(SyncServiceImplStartupTest, StartInvalidCredentials) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplStartupTest, StartAshNoCredentials) {
  // We've never completed startup.
  ASSERT_FALSE(
      engine_factory()->HasTransportDataIncludingFirstSync(gaia_id_hash()));

  // On ChromeOS, the user is always immediately signed in, but a refresh token
  // isn't necessarily available yet.
  SimulateRefreshTokensNotLoadedYet();
  SignInWithSyncConsentWithoutRefreshToken();

  CreateSyncService();

  // Calling Initialize should cause the service to immediately create and
  // initialize the engine, and configure the DataTypeManager.
  base::RunLoop().RunUntilIdle();

  // Sync should be considered active, even though there is no refresh token.
  EXPECT_EQ(SyncService::TransportState::ACTIVE,
            sync_service()->GetTransportState());
  // FirstSetupComplete gets set automatically on Ash.
  EXPECT_TRUE(
      sync_service()->GetUserSettings()->IsInitialSyncFeatureSetupComplete());
}

TEST_F(SyncServiceImplStartupTest, StartAshFirstTime) {
  // We've never completed Sync startup.
  ASSERT_FALSE(
      engine_factory()->HasTransportDataIncludingFirstSync(gaia_id_hash()));

  // There is already a signed-in user.
  SignInWithSyncConsent();

  // Sync should become active, even though IsInitialSyncFeatureSetupComplete
  // wasn't set yet.
  CreateSyncService();
  base::RunLoop().RunUntilIdle();
  EXPECT_EQ(SyncService::TransportState::ACTIVE,
            sync_service()->GetTransportState());
}
#endif

TEST_F(SyncServiceImplStartupTest, ResetSyncViaDashboard) {}

// ChromeOS does not support sign-in after startup.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
// Verify that enabling sync honors existing values of data type preferences.
TEST_F(SyncServiceImplStartupTest, HonorsExistingDatatypePrefs) {}
#endif

TEST_F(SyncServiceImplStartupTest, ManagedStartup) {}

TEST_F(SyncServiceImplStartupTest, SwitchManaged) {}

TEST_F(SyncServiceImplStartupTest, StartDownloadFailed) {}

// ChromeOS does not support sign-in after startup.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplStartupTest, FullStartupSequenceFirstTime) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)

TEST_F(SyncServiceImplStartupTest, FullStartupSequenceNthTime) {}

TEST_F(SyncServiceImplStartupTest, DeferredStartInterruptedByDataType) {}

// ChromeOS does not support sign-in after startup.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplStartupTest, UserTriggeredStartIsNotDeferredStart) {}
#endif

TEST_F(SyncServiceImplStartupTest,
       ShouldClearMetadataForAlreadyDisabledTypesBeforeConfigurationDone) {}

TEST_F(SyncServiceImplStartupTest,
       ShouldClearMetadataForTypesDisabledBeforeInitCompletion) {}

TEST_F(SyncServiceImplStartupTest,
       ShouldClearMetadataForTypesDisabledWhileInit) {}

}  // namespace syncer