model_type_sync_bridge_unittest.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/sync/model/model_type_sync_bridge.h"
  5. #include <utility>
  6. #include "base/bind.h"
  7. #include "base/callback_helpers.h"
  8. #include "components/sync/model/conflict_resolution.h"
  9. #include "components/sync/model/metadata_batch.h"
  10. #include "components/sync/protocol/model_type_state.pb.h"
  11. #include "components/sync/test/mock_model_type_change_processor.h"
  12. #include "components/sync/test/stub_model_type_sync_bridge.h"
  13. #include "testing/gmock/include/gmock/gmock.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. namespace syncer {
  16. namespace {
  17. using testing::_;
  18. using testing::Return;
  19. class ModelTypeSyncBridgeTest : public ::testing::Test {
  20. public:
  21. ModelTypeSyncBridgeTest()
  22. : bridge_(mock_processor_.CreateForwardingProcessor()) {}
  23. ~ModelTypeSyncBridgeTest() override = default;
  24. StubModelTypeSyncBridge* bridge() { return &bridge_; }
  25. MockModelTypeChangeProcessor* processor() { return &mock_processor_; }
  26. private:
  27. testing::NiceMock<MockModelTypeChangeProcessor> mock_processor_;
  28. StubModelTypeSyncBridge bridge_;
  29. };
  30. // ResolveConflicts should return kUseRemote unless the remote data is deleted.
  31. TEST_F(ModelTypeSyncBridgeTest, DefaultConflictResolution) {
  32. EntityData local_data;
  33. EntityData remote_data;
  34. // There is no deleted/deleted case because that's not a conflict.
  35. local_data.specifics.mutable_preference()->set_value("value");
  36. EXPECT_FALSE(local_data.is_deleted());
  37. EXPECT_TRUE(remote_data.is_deleted());
  38. EXPECT_EQ(
  39. ConflictResolution::kUseLocal,
  40. bridge()->ResolveConflict(/*storage_key=*/std::string(), remote_data));
  41. remote_data.specifics.mutable_preference()->set_value("value");
  42. EXPECT_FALSE(local_data.is_deleted());
  43. EXPECT_FALSE(remote_data.is_deleted());
  44. EXPECT_EQ(
  45. ConflictResolution::kUseRemote,
  46. bridge()->ResolveConflict(/*storage_key=*/std::string(), remote_data));
  47. local_data.specifics.clear_preference();
  48. EXPECT_TRUE(local_data.is_deleted());
  49. EXPECT_FALSE(remote_data.is_deleted());
  50. EXPECT_EQ(
  51. ConflictResolution::kUseRemote,
  52. bridge()->ResolveConflict(/*storage_key=*/std::string(), remote_data));
  53. }
  54. } // namespace
  55. } // namespace syncer