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 "chrome/common/metrics/variations/variations_util.h" | |
6 | |
7 #include <set> | 5 #include <set> |
8 #include <string> | 6 #include <string> |
9 | 7 |
10 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
11 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
12 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/common/metrics/variations/variations_util.h" | |
Alexei Svitkine (slow)
2013/09/03 15:46:35
This should go to the top of the file. There were
gab
2013/11/05 22:20:38
Done.
| |
13 #include "chrome/common/metrics/variations/variations_util_win.h" | |
14 #include "components/variations/metrics_util.h" | 14 #include "components/variations/metrics_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace chrome_variations { | 17 namespace chrome_variations { |
18 | 18 |
19 namespace { | |
20 | |
21 const VariationID TEST_VALUE_A = 3300200; | |
22 const VariationID TEST_VALUE_B = 3300201; | |
23 const VariationID TEST_VALUE_C = 3300202; | |
24 const VariationID TEST_VALUE_D = 3300203; | |
25 | |
26 // Tests whether a field trial is active (i.e. group() has been called on it). | |
27 bool IsFieldTrialActive(const std::string& trial_name) { | |
28 base::FieldTrial::ActiveGroups active_groups; | |
29 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups); | |
30 for (size_t i = 0; i < active_groups.size(); ++i) { | |
31 if (active_groups[i].trial_name == trial_name) | |
32 return true; | |
33 } | |
34 return false; | |
35 } | |
36 | |
37 // Call FieldTrialList::FactoryGetFieldTrial() with a future expiry date. | |
38 scoped_refptr<base::FieldTrial> CreateFieldTrial( | |
39 const std::string& trial_name, | |
40 int total_probability, | |
41 const std::string& default_group_name, | |
42 int* default_group_number) { | |
43 return base::FieldTrialList::FactoryGetFieldTrial( | |
44 trial_name, total_probability, default_group_name, | |
45 base::FieldTrialList::kNoExpirationYear, 1, 1, | |
46 base::FieldTrial::SESSION_RANDOMIZED, default_group_number); | |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 class VariationsUtilTest : public ::testing::Test { | 19 class VariationsUtilTest : public ::testing::Test { |
52 public: | 20 public: |
53 VariationsUtilTest() : field_trial_list_(NULL) { | 21 VariationsUtilTest() : field_trial_list_(NULL) { |
54 } | 22 } |
55 | 23 |
56 virtual ~VariationsUtilTest() { | 24 virtual ~VariationsUtilTest() { |
57 // Ensure that the maps are cleared between tests, since they are stored as | 25 // Ensure that the maps are cleared between tests, since they are stored as |
58 // process singletons. | 26 // process singletons. |
59 testing::ClearAllVariationIDs(); | 27 testing::ClearAllVariationIDs(); |
60 } | 28 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 experiments.push_back(UTF8ToUTF16(kExperimentStrings[j])); | 119 experiments.push_back(UTF8ToUTF16(kExperimentStrings[j])); |
152 | 120 |
153 std::vector<string16> chunks; | 121 std::vector<string16> chunks; |
154 GenerateVariationChunks(experiments, &chunks); | 122 GenerateVariationChunks(experiments, &chunks); |
155 ASSERT_EQ(cases[i].expected_chunks_length, chunks.size()); | 123 ASSERT_EQ(cases[i].expected_chunks_length, chunks.size()); |
156 for (size_t j = 0; j < chunks.size(); ++j) | 124 for (size_t j = 0; j < chunks.size(); ++j) |
157 EXPECT_EQ(UTF8ToUTF16(cases[i].expected_chunks[j]), chunks[j]); | 125 EXPECT_EQ(UTF8ToUTF16(cases[i].expected_chunks[j]), chunks[j]); |
158 } | 126 } |
159 } | 127 } |
160 | 128 |
129 #if defined(OS_WIN) | |
130 | |
161 TEST_F(VariationsUtilTest, BuildGoogleUpdateExperimentLabel) { | 131 TEST_F(VariationsUtilTest, BuildGoogleUpdateExperimentLabel) { |
132 const VariationID TEST_VALUE_A = 3300200; | |
133 const VariationID TEST_VALUE_B = 3300201; | |
134 const VariationID TEST_VALUE_C = 3300202; | |
135 const VariationID TEST_VALUE_D = 3300203; | |
136 | |
162 struct { | 137 struct { |
163 const char* active_group_pairs; | 138 const char* active_group_pairs; |
164 const char* expected_ids; | 139 const char* expected_ids; |
165 } test_cases[] = { | 140 } test_cases[] = { |
166 // Empty group. | 141 // Empty group. |
167 {"", ""}, | 142 {"", ""}, |
168 // Group of 1. | 143 // Group of 1. |
169 {"FieldTrialA#Default", "3300200"}, | 144 {"FieldTrialA#Default", "3300200"}, |
170 // Group of 1, doesn't have an associated ID. | 145 // Group of 1, doesn't have an associated ID. |
171 {"FieldTrialA#DoesNotExist", ""}, | 146 {"FieldTrialA#DoesNotExist", ""}, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 {";;;;", ""}, | 293 {";;;;", ""}, |
319 }; | 294 }; |
320 | 295 |
321 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 296 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
322 std::string non_variation_labels = UTF16ToUTF8( | 297 std::string non_variation_labels = UTF16ToUTF8( |
323 ExtractNonVariationLabels(ASCIIToUTF16(test_cases[i].input_label))); | 298 ExtractNonVariationLabels(ASCIIToUTF16(test_cases[i].input_label))); |
324 EXPECT_EQ(test_cases[i].expected_output, non_variation_labels); | 299 EXPECT_EQ(test_cases[i].expected_output, non_variation_labels); |
325 } | 300 } |
326 } | 301 } |
327 | 302 |
303 #endif // defined(OS_WIN) | |
304 | |
328 } // namespace chrome_variations | 305 } // namespace chrome_variations |
OLD | NEW |