interested_data_types_manager_unittest.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2020 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/invalidations/interested_data_types_manager.h"
  5. #include "base/callback_helpers.h"
  6. #include "components/sync/invalidations/interested_data_types_handler.h"
  7. #include "testing/gmock/include/gmock/gmock.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. using testing::_;
  10. namespace syncer {
  11. namespace {
  12. class MockDataTypesHandler : public InterestedDataTypesHandler {
  13. public:
  14. MOCK_METHOD(void, OnInterestedDataTypesChanged, (), (override));
  15. MOCK_METHOD(void,
  16. SetCommittedAdditionalInterestedDataTypesCallback,
  17. (base::RepeatingCallback<void(const ModelTypeSet&)> callback),
  18. (override));
  19. };
  20. class InterestedDataTypesManagerTest : public testing::Test {
  21. public:
  22. InterestedDataTypesManagerTest() {
  23. manager_.SetInterestedDataTypesHandler(&handler_);
  24. }
  25. ~InterestedDataTypesManagerTest() override {
  26. manager_.SetInterestedDataTypesHandler(nullptr);
  27. }
  28. protected:
  29. testing::NiceMock<MockDataTypesHandler> handler_;
  30. InterestedDataTypesManager manager_;
  31. };
  32. TEST_F(InterestedDataTypesManagerTest, ShouldReturnGivenDataTypes) {
  33. manager_.SetInterestedDataTypes(ModelTypeSet(BOOKMARKS, PREFERENCES));
  34. EXPECT_EQ(ModelTypeSet(BOOKMARKS, PREFERENCES),
  35. manager_.GetInterestedDataTypes());
  36. manager_.SetInterestedDataTypes(ModelTypeSet(PREFERENCES, PASSWORDS));
  37. EXPECT_EQ(ModelTypeSet(PREFERENCES, PASSWORDS),
  38. manager_.GetInterestedDataTypes());
  39. }
  40. TEST_F(InterestedDataTypesManagerTest, ShouldNotifyOnChange) {
  41. EXPECT_CALL(handler_, OnInterestedDataTypesChanged);
  42. manager_.SetInterestedDataTypes(ModelTypeSet(PASSWORDS, AUTOFILL));
  43. }
  44. TEST_F(InterestedDataTypesManagerTest,
  45. ShouldInitializeOnFirstSetInterestedDataTypes) {
  46. EXPECT_FALSE(manager_.GetInterestedDataTypes().has_value());
  47. manager_.SetInterestedDataTypes(ModelTypeSet(BOOKMARKS, PREFERENCES));
  48. EXPECT_TRUE(manager_.GetInterestedDataTypes().has_value());
  49. manager_.SetInterestedDataTypes(ModelTypeSet(BOOKMARKS, PREFERENCES, NIGORI));
  50. EXPECT_TRUE(manager_.GetInterestedDataTypes().has_value());
  51. }
  52. } // namespace
  53. } // namespace syncer