chromium/components/sync/service/data_type_controller_unittest.cc

// Copyright 2016 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/sync/service/data_type_controller.h"

#include <utility>

#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/test/gmock_move_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/model/data_type_activation_request.h"
#include "components/sync/model/forwarding_data_type_controller_delegate.h"
#include "components/sync/model/type_entities_count.h"
#include "components/sync/service/configure_context.h"
#include "components/sync/test/fake_data_type_processor.h"
#include "components/sync/test/mock_data_type_controller_delegate.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace syncer {

namespace {

_;
DoAll;
InSequence;
NiceMock;
NotNull;
SaveArg;

const DataType kTestDataType =;
const char kCacheGuid[] =;
const char kAccountId[] =;

const char kStartFailuresHistogram[] =;
const char kRunFailuresHistogram[] =;

MATCHER(ErrorIsSet, "") {}

// Class used to expose ReportModelError() publicly.
class TestDataTypeController : public DataTypeController {};

ConfigureContext MakeConfigureContext() {}

}  // namespace

class DataTypeControllerTest : public testing::Test {};

TEST_F(DataTypeControllerTest, InitialState) {}

TEST_F(DataTypeControllerTest, LoadModelsOnBackendThread) {}

TEST_F(DataTypeControllerTest, Connect) {}

TEST_F(DataTypeControllerTest, ConnectWithInitialSyncDone) {}

TEST_F(DataTypeControllerTest, ConnectWithError) {}

TEST_F(DataTypeControllerTest, Stop) {}

// Test emulates normal browser shutdown. Ensures that metadata was not cleared.
TEST_F(DataTypeControllerTest, StopWhenDatatypeEnabled) {}

// Test emulates scenario when user disables datatype. Metadata should be
// cleared.
TEST_F(DataTypeControllerTest, StopWhenDatatypeDisabled) {}

// When Stop() is called with SyncStopMetadataFate::CLEAR_METADATA, while
// the controller is still stopping, data is indeed cleared, regardless of the
// ShutdownReason of previous calls.
TEST_F(DataTypeControllerTest, StopWhileStopping) {}

// Test emulates disabling sync when datatype is not loaded yet.
TEST_F(DataTypeControllerTest, StopBeforeLoadModels) {}

// Test emulates disabling sync when datatype is in error state. Metadata should
// not be cleared as the delegate is potentially not ready to handle it.
TEST_F(DataTypeControllerTest, StopDuringFailedState) {}

// Test emulates disabling sync when datatype is loading. The controller should
// wait for completion of the delegate, before stopping it.
TEST_F(DataTypeControllerTest, StopWhileStarting) {}

// Test emulates disabling sync when datatype is loading. The controller should
// wait for completion of the delegate, before stopping it. In this test,
// loading produces an error, so the resulting state should be FAILED.
TEST_F(DataTypeControllerTest, StopWhileStartingWithError) {}

// Test emulates a controller talking to a delegate (processor) in a backend
// thread, which necessarily involves task posting (usually via
// ProxyDataTypeControllerDelegate), where the backend posts an error
// simultaneously to the UI stopping the datatype.
TEST_F(DataTypeControllerTest, StopWhileErrorInFlight) {}

// Test emulates a controller subclass issuing ReportModelError() (e.g. custom
// passphrase was enabled and the type should be disabled) while the delegate
// is starting.
TEST_F(DataTypeControllerTest, ReportErrorWhileStarting) {}

// Test emulates a controller subclass issuing ReportModelError() (e.g. custom
// passphrase was enabled and the type should be disabled) AND the controller
// being requested to stop, both of which are received while the delegate is
// starting.
TEST_F(DataTypeControllerTest, StopAndReportErrorWhileStarting) {}

// Tests that SyncMode is honored when the controller has been constructed
// with two delegates.
TEST(DataTypeControllerWithMultiDelegateTest, ToggleSyncMode) {}

TEST_F(DataTypeControllerTest, ReportErrorAfterLoaded) {}

TEST_F(DataTypeControllerTest, ReportErrorAfterRegisteredWithBackend) {}

TEST_F(DataTypeControllerTest, ClearMetadataWhenDatatypeNotRunning) {}

TEST_F(DataTypeControllerTest,
       ShouldNotClearMetadataWhenDatatypeInFailedState) {}

}  // namespace syncer