1 // Copyright 2014 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.
5 #include "components/variations/active_field_trials.h"
7 #include "components/variations/metrics_util.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace variations
{
12 TEST(ActiveFieldTrialsTest
, GetFieldTrialActiveGroups
) {
13 typedef std::set
<ActiveGroupId
, ActiveGroupIdCompare
> ActiveGroupIdSet
;
14 std::string
trial_one("trial one");
15 std::string
group_one("group one");
16 std::string
trial_two("trial two");
17 std::string
group_two("group two");
19 base::FieldTrial::ActiveGroups active_groups
;
20 base::FieldTrial::ActiveGroup active_group
;
21 active_group
.trial_name
= trial_one
;
22 active_group
.group_name
= group_one
;
23 active_groups
.push_back(active_group
);
25 active_group
.trial_name
= trial_two
;
26 active_group
.group_name
= group_two
;
27 active_groups
.push_back(active_group
);
29 // Create our expected groups of IDs.
30 ActiveGroupIdSet expected_groups
;
31 ActiveGroupId name_group_id
;
32 name_group_id
.name
= metrics::HashName(trial_one
);
33 name_group_id
.group
= metrics::HashName(group_one
);
34 expected_groups
.insert(name_group_id
);
35 name_group_id
.name
= metrics::HashName(trial_two
);
36 name_group_id
.group
= metrics::HashName(group_two
);
37 expected_groups
.insert(name_group_id
);
39 std::vector
<ActiveGroupId
> active_group_ids
;
40 testing::TestGetFieldTrialActiveGroupIds(active_groups
, &active_group_ids
);
41 EXPECT_EQ(2U, active_group_ids
.size());
42 for (size_t i
= 0; i
< active_group_ids
.size(); ++i
) {
43 ActiveGroupIdSet::iterator expected_group
=
44 expected_groups
.find(active_group_ids
[i
]);
45 EXPECT_FALSE(expected_group
== expected_groups
.end());
46 expected_groups
.erase(expected_group
);
48 EXPECT_EQ(0U, expected_groups
.size());
51 } // namespace variations