model_type_store_service_impl_unittest.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2021 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_store_service_impl.h"
  5. #include <memory>
  6. #include "base/run_loop.h"
  7. #include "base/test/bind.h"
  8. #include "base/test/task_environment.h"
  9. #include "base/test/test_file_util.h"
  10. #include "components/sync/base/model_type.h"
  11. #include "testing/gmock/include/gmock/gmock.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. namespace syncer {
  14. namespace {
  15. using testing::NotNull;
  16. // Regression test for http://crbug.com/1190187.
  17. TEST(ModelTypeStoreServiceImplTest, ShouldSupportFactoryOutlivingService) {
  18. base::test::TaskEnvironment task_environment;
  19. auto service = std::make_unique<ModelTypeStoreServiceImpl>(
  20. base::CreateUniqueTempDirectoryScopedToTest());
  21. const RepeatingModelTypeStoreFactory store_factory =
  22. service->GetStoreFactory();
  23. ASSERT_TRUE(store_factory);
  24. // Destroy the service and wait until all backend cleanup work is done.
  25. service.reset();
  26. task_environment.RunUntilIdle();
  27. // Verify that the factory continues to work, even if it outlives the service.
  28. base::RunLoop loop;
  29. store_factory.Run(
  30. syncer::PREFERENCES,
  31. base::BindLambdaForTesting([&](const absl::optional<ModelError>& error,
  32. std::unique_ptr<ModelTypeStore> store) {
  33. EXPECT_FALSE(error.has_value());
  34. EXPECT_THAT(store, NotNull());
  35. loop.Quit();
  36. }));
  37. loop.Run();
  38. }
  39. } // namespace
  40. } // namespace syncer