dummy_segmentation_platform_service_unittest.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/segmentation_platform/internal/dummy_segmentation_platform_service.h"
  5. #include <string>
  6. #include "base/bind.h"
  7. #include "base/run_loop.h"
  8. #include "base/test/task_environment.h"
  9. #include "components/segmentation_platform/internal/constants.h"
  10. #include "components/segmentation_platform/public/segment_selection_result.h"
  11. #include "testing/gtest/include/gtest/gtest.h"
  12. namespace segmentation_platform {
  13. class DummySegmentationPlatformServiceTest : public testing::Test {
  14. public:
  15. DummySegmentationPlatformServiceTest() = default;
  16. ~DummySegmentationPlatformServiceTest() override = default;
  17. void SetUp() override {
  18. segmentation_platform_service_ =
  19. std::make_unique<DummySegmentationPlatformService>();
  20. }
  21. void OnGetSelectedSegment(base::RepeatingClosure closure,
  22. const SegmentSelectionResult& expected,
  23. const SegmentSelectionResult& actual) {
  24. ASSERT_EQ(expected, actual);
  25. std::move(closure).Run();
  26. }
  27. protected:
  28. base::test::TaskEnvironment task_environment_;
  29. std::unique_ptr<DummySegmentationPlatformService>
  30. segmentation_platform_service_;
  31. };
  32. TEST_F(DummySegmentationPlatformServiceTest, GetSelectedSegment) {
  33. SegmentSelectionResult expected;
  34. base::RunLoop loop;
  35. segmentation_platform_service_->GetSelectedSegment(
  36. "test_key",
  37. base::BindOnce(
  38. &DummySegmentationPlatformServiceTest::OnGetSelectedSegment,
  39. base::Unretained(this), loop.QuitClosure(), expected));
  40. loop.Run();
  41. ASSERT_EQ(expected,
  42. segmentation_platform_service_->GetCachedSegmentResult("test_key"));
  43. }
  44. } // namespace segmentation_platform