[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / metrics / persistent_synthetic_trial_observer_unittest.cc
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/metrics/persistent_synthetic_trial_observer.h"
6
7 #include "base/test/task_environment.h"
8 #include "components/metrics/persistent_system_profile.h"
9 #include "components/variations/hashing.h"
10 #include "components/variations/synthetic_trials.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace metrics {
14
15 class PersistentSyntheticTrialObserverTest : public testing::Test {
16  public:
17   constexpr static int32_t kAllocatorMemorySize = 1 << 20;  // 1 MiB
18
19   PersistentSyntheticTrialObserverTest() = default;
20   ~PersistentSyntheticTrialObserverTest() override = default;
21
22   void SetUp() override {
23     Test::SetUp();
24
25     memory_allocator_ = std::make_unique<base::LocalPersistentMemoryAllocator>(
26         kAllocatorMemorySize, 0, "");
27     GlobalPersistentSystemProfile::GetInstance()->RegisterPersistentAllocator(
28         memory_allocator_.get());
29     SystemProfileProto profile;
30     profile.set_client_uuid("id");
31     GlobalPersistentSystemProfile::GetInstance()->SetSystemProfile(profile,
32                                                                    false);
33   }
34
35   void TearDown() override {
36     GlobalPersistentSystemProfile::GetInstance()->DeregisterPersistentAllocator(
37         memory_allocator_.get());
38     Test::TearDown();
39   }
40
41   SystemProfileProto GetSystemProfile() {
42     SystemProfileProto profile;
43     GlobalPersistentSystemProfile::GetInstance()->GetSystemProfile(
44         *memory_allocator_, &profile);
45     return profile;
46   }
47
48  protected:
49   base::test::TaskEnvironment task_env_;
50   std::unique_ptr<base::PersistentMemoryAllocator> memory_allocator_;
51 };
52
53 TEST_F(PersistentSyntheticTrialObserverTest, AddRemoveTrials) {
54   PersistentSyntheticTrialObserver observer;
55   const variations::SyntheticTrialGroup kGroup1(
56       "Trial1", "Group1",
57       variations::SyntheticTrialAnnotationMode::kCurrentLog);
58   const variations::SyntheticTrialGroup kGroup2(
59       "Trial2", "Group2", variations::SyntheticTrialAnnotationMode::kNextLog);
60   const variations::SyntheticTrialGroup kGroup3(
61       "Trial2", "Group3",
62       variations::SyntheticTrialAnnotationMode::kCurrentLog);
63
64   observer.OnSyntheticTrialsChanged({kGroup1, kGroup2}, {}, {kGroup1, kGroup2});
65   SystemProfileProto profile = GetSystemProfile();
66   ASSERT_EQ(1, profile.field_trial_size());
67   EXPECT_EQ(variations::HashName("Trial1"), profile.field_trial(0).name_id());
68   EXPECT_EQ(variations::HashName("Group1"), profile.field_trial(0).group_id());
69
70   observer.OnSyntheticTrialsChanged({kGroup3}, {kGroup1}, {kGroup3});
71   profile = GetSystemProfile();
72   ASSERT_EQ(1, profile.field_trial_size());
73   EXPECT_EQ(variations::HashName("Trial2"), profile.field_trial(0).name_id());
74   EXPECT_EQ(variations::HashName("Group3"), profile.field_trial(0).group_id());
75 }
76
77 }  // namespace metrics