chromium/chrome/browser/sync/test/integration/single_client_standalone_transport_sync_test.cc

// Copyright 2018 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/feature_list.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/test/integration/encryption_helper.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_service_impl_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/common/chrome_paths.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/service/glue/sync_transport_data_prefs.h"
#include "components/sync/service/sync_service_impl.h"
#include "components/sync/test/fake_server_nigori_helper.h"
#include "components/sync/test/nigori_test_utils.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_launcher.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_features.h"
#endif

namespace {

#if !BUILDFLAG(IS_ANDROID)
base::FilePath GetTestFilePathForCacheGuid() {}
#endif

#if BUILDFLAG(IS_CHROMEOS_ASH)
class SyncDisabledViaDashboardChecker : public SingleClientStatusChangeChecker {
 public:
  explicit SyncDisabledViaDashboardChecker(syncer::SyncServiceImpl* service)
      : SingleClientStatusChangeChecker(service) {}

  bool IsExitConditionSatisfied(std::ostream* os) override {
    *os << "Waiting for sync disabled by dashboard";
    return service()->GetUserSettings()->IsSyncFeatureDisabledViaDashboard();
  }
};
#else
class SyncConsentDisabledChecker : public SingleClientStatusChangeChecker {};
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

class SingleClientStandaloneTransportSyncTest : public SyncTest {};

// On Chrome OS sync auto-starts on sign-in.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(SingleClientStandaloneTransportSyncTest,
                       StartsSyncTransportOnSignin) {}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SingleClientStandaloneTransportSyncTest,
                       SwitchesBetweenTransportAndFeature) {}
#endif  // BUILDFLAG(IS_ANDROID)

// Tests the behavior of receiving a "Reset Sync" operation from the dashboard
// while Sync-the-feature is active: On non-ChromeOS, this signs the user out,
// so Sync will be fully disabled. On ChromeOS, there is no sign-out, so
// Sync-the-transport will start.
IN_PROC_BROWSER_TEST_F(SingleClientStandaloneTransportSyncTest,
                       HandlesResetFromDashboardWhenSyncActive) {}

// TODO(crbug.com/40200835): Android currently doesn't support PRE_ tests.
#if !BUILDFLAG(IS_ANDROID)
// Regression test for crbug.com/955989 that verifies the cache GUID is not
// reset upon restart of the browser, in standalone transport mode.
IN_PROC_BROWSER_TEST_F(SingleClientStandaloneTransportSyncTest,
                       PRE_ReusesSameCacheGuid) {}

IN_PROC_BROWSER_TEST_F(SingleClientStandaloneTransportSyncTest,
                       ReusesSameCacheGuid) {}
#endif  // BUILDFLAG(IS_ANDROID)

class SingleClientStandaloneTransportWithReplaceSyncWithSigninSyncTest
    : public SingleClientStandaloneTransportSyncTest {};

IN_PROC_BROWSER_TEST_F(
    SingleClientStandaloneTransportWithReplaceSyncWithSigninSyncTest,
    DataTypesEnabledInTransportMode) {}

// TODO(crbug.com/40200835): Android currently doesn't support PRE_ tests.
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(
    SingleClientStandaloneTransportWithReplaceSyncWithSigninSyncTest,
    PRE_DataTypesEnabledInTransportModeWithCustomPassphrase) {}

// Tests that a custom passphrase user's opt-in to kAutofill (which happened in
// the PRE_ test) survives a browser restart.
IN_PROC_BROWSER_TEST_F(
    SingleClientStandaloneTransportWithReplaceSyncWithSigninSyncTest,
    DataTypesEnabledInTransportModeWithCustomPassphrase) {}
#endif  // BUILDFLAG(IS_ANDROID)

class SingleClientStandaloneTransportWithoutReplaceSyncWithSigninSyncTest
    : public SingleClientStandaloneTransportSyncTest {};

IN_PROC_BROWSER_TEST_F(
    SingleClientStandaloneTransportWithoutReplaceSyncWithSigninSyncTest,
    DataTypesNotEnabledInTransportMode) {}

// TODO(crbug.com/40145099): Android currently doesn't support PRE_ tests and
// all of these are.
#if !BUILDFLAG(IS_ANDROID)
// A test fixture to cover migration behavior: In PRE_ tests, the
// kReplaceSyncPromosWithSignInPromos is *dis*abled, in non-PRE_ tests it is
// *en*abled.
class SingleClientStandaloneTransportReplaceSyncWithSigninMigrationSyncTest
    : public SingleClientStandaloneTransportSyncTest {};

IN_PROC_BROWSER_TEST_F(
    SingleClientStandaloneTransportReplaceSyncWithSigninMigrationSyncTest,
    PRE_MigratesSignedInUser) {}

IN_PROC_BROWSER_TEST_F(
    SingleClientStandaloneTransportReplaceSyncWithSigninMigrationSyncTest,
    MigratesSignedInUser) {}

IN_PROC_BROWSER_TEST_F(
    SingleClientStandaloneTransportReplaceSyncWithSigninMigrationSyncTest,
    PRE_MigratesSignedInCustomPassphraseUser) {}

IN_PROC_BROWSER_TEST_F(
    SingleClientStandaloneTransportReplaceSyncWithSigninMigrationSyncTest,
    MigratesSignedInCustomPassphraseUser) {}
#endif  // BUILDFLAG(IS_ANDROID)

}  // namespace