| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 // Different cases to test, e.g. default vs. non default group being chosen. | 956 // Different cases to test, e.g. default vs. non default group being chosen. |
| 957 struct { | 957 struct { |
| 958 double entropy_value; | 958 double entropy_value; |
| 959 const char* expected_group; | 959 const char* expected_group; |
| 960 } test_cases[] = { | 960 } test_cases[] = { |
| 961 { 0.4, "A" }, | 961 { 0.4, "A" }, |
| 962 { 0.85, "B" }, | 962 { 0.85, "B" }, |
| 963 { 0.95, kDefaultGroupName }, | 963 { 0.95, kDefaultGroupName }, |
| 964 }; | 964 }; |
| 965 | 965 |
| 966 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 966 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 967 TestFieldTrialObserver observer; | 967 TestFieldTrialObserver observer; |
| 968 scoped_refptr<FieldTrial> trial( | 968 scoped_refptr<FieldTrial> trial( |
| 969 FieldTrial::CreateSimulatedFieldTrial(kTrialName, 100, kDefaultGroupName, | 969 FieldTrial::CreateSimulatedFieldTrial(kTrialName, 100, kDefaultGroupName, |
| 970 test_cases[i].entropy_value)); | 970 test_cases[i].entropy_value)); |
| 971 trial->AppendGroup("A", 80); | 971 trial->AppendGroup("A", 80); |
| 972 trial->AppendGroup("B", 10); | 972 trial->AppendGroup("B", 10); |
| 973 EXPECT_EQ(test_cases[i].expected_group, trial->group_name()); | 973 EXPECT_EQ(test_cases[i].expected_group, trial->group_name()); |
| 974 | 974 |
| 975 // Field trial shouldn't have been registered with the list. | 975 // Field trial shouldn't have been registered with the list. |
| 976 EXPECT_FALSE(FieldTrialList::TrialExists(kTrialName)); | 976 EXPECT_FALSE(FieldTrialList::TrialExists(kTrialName)); |
| 977 EXPECT_EQ(0u, FieldTrialList::GetFieldTrialCount()); | 977 EXPECT_EQ(0u, FieldTrialList::GetFieldTrialCount()); |
| 978 | 978 |
| 979 // Observer shouldn't have been notified. | 979 // Observer shouldn't have been notified. |
| 980 RunLoop().RunUntilIdle(); | 980 RunLoop().RunUntilIdle(); |
| 981 EXPECT_TRUE(observer.trial_name().empty()); | 981 EXPECT_TRUE(observer.trial_name().empty()); |
| 982 | 982 |
| 983 // The trial shouldn't be in the active set of trials. | 983 // The trial shouldn't be in the active set of trials. |
| 984 FieldTrial::ActiveGroups active_groups; | 984 FieldTrial::ActiveGroups active_groups; |
| 985 FieldTrialList::GetActiveFieldTrialGroups(&active_groups); | 985 FieldTrialList::GetActiveFieldTrialGroups(&active_groups); |
| 986 EXPECT_TRUE(active_groups.empty()); | 986 EXPECT_TRUE(active_groups.empty()); |
| 987 | 987 |
| 988 // The trial shouldn't be listed in the |StatesToString()| result. | 988 // The trial shouldn't be listed in the |StatesToString()| result. |
| 989 std::string states; | 989 std::string states; |
| 990 FieldTrialList::StatesToString(&states); | 990 FieldTrialList::StatesToString(&states); |
| 991 EXPECT_TRUE(states.empty()); | 991 EXPECT_TRUE(states.empty()); |
| 992 } | 992 } |
| 993 } | 993 } |
| 994 | 994 |
| 995 } // namespace base | 995 } // namespace base |
| OLD | NEW |