OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/variations/variations_associated_data.h" | 5 #include "components/variations/variations_associated_data.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace chrome_variations { | 10 namespace variations { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 const VariationID TEST_VALUE_A = 3300200; | 14 const VariationID TEST_VALUE_A = 3300200; |
15 const VariationID TEST_VALUE_B = 3300201; | 15 const VariationID TEST_VALUE_B = 3300201; |
16 | 16 |
17 // Convenience helper to retrieve the chrome_variations::VariationID for a | 17 // Convenience helper to retrieve the variations::VariationID for a FieldTrial. |
18 // FieldTrial. Note that this will do the group assignment in |trial| if not | 18 // Note that this will do the group assignment in |trial| if not already done. |
19 // already done. | |
20 VariationID GetIDForTrial(IDCollectionKey key, base::FieldTrial* trial) { | 19 VariationID GetIDForTrial(IDCollectionKey key, base::FieldTrial* trial) { |
21 return GetGoogleVariationID(key, trial->trial_name(), trial->group_name()); | 20 return GetGoogleVariationID(key, trial->trial_name(), trial->group_name()); |
22 } | 21 } |
23 | 22 |
24 // Tests whether a field trial is active (i.e. group() has been called on it). | 23 // Tests whether a field trial is active (i.e. group() has been called on it). |
25 bool IsFieldTrialActive(const std::string& trial_name) { | 24 bool IsFieldTrialActive(const std::string& trial_name) { |
26 base::FieldTrial::ActiveGroups active_groups; | 25 base::FieldTrial::ActiveGroups active_groups; |
27 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups); | 26 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups); |
28 for (size_t i = 0; i < active_groups.size(); ++i) { | 27 for (size_t i = 0; i < active_groups.size(); ++i) { |
29 if (active_groups[i].trial_name == trial_name) | 28 if (active_groups[i].trial_name == trial_name) |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 ASSERT_FALSE(IsFieldTrialActive(kTrialName)); | 321 ASSERT_FALSE(IsFieldTrialActive(kTrialName)); |
323 scoped_refptr<base::FieldTrial> trial( | 322 scoped_refptr<base::FieldTrial> trial( |
324 CreateFieldTrial(kTrialName, 100, "A", NULL)); | 323 CreateFieldTrial(kTrialName, 100, "A", NULL)); |
325 ASSERT_FALSE(IsFieldTrialActive(kTrialName)); | 324 ASSERT_FALSE(IsFieldTrialActive(kTrialName)); |
326 | 325 |
327 std::map<std::string, std::string> params; | 326 std::map<std::string, std::string> params; |
328 EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "x")); | 327 EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "x")); |
329 ASSERT_TRUE(IsFieldTrialActive(kTrialName)); | 328 ASSERT_TRUE(IsFieldTrialActive(kTrialName)); |
330 } | 329 } |
331 | 330 |
332 } // namespace chrome_variations | 331 } // namespace variations |
OLD | NEW |