Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1131)

Side by Side Diff: chrome/common/metrics/entropy_provider_unittest.cc

Issue 11783033: Fix problem where field trials using kExpirationYearInFuture could get disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/variations/variations_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cmath> 5 #include <cmath>
6 #include <limits> 6 #include <limits>
7 #include <numeric> 7 #include <numeric>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 TEST_F(EntropyProviderTest, UseOneTimeRandomizationSHA1) { 185 TEST_F(EntropyProviderTest, UseOneTimeRandomizationSHA1) {
186 // Simply asserts that two trials using one-time randomization 186 // Simply asserts that two trials using one-time randomization
187 // that have different names, normally generate different results. 187 // that have different names, normally generate different results.
188 // 188 //
189 // Note that depending on the one-time random initialization, they 189 // Note that depending on the one-time random initialization, they
190 // _might_ actually give the same result, but we know that given 190 // _might_ actually give the same result, but we know that given
191 // the particular client_id we use for unit tests they won't. 191 // the particular client_id we use for unit tests they won't.
192 base::FieldTrialList field_trial_list(new SHA1EntropyProvider("client_id")); 192 base::FieldTrialList field_trial_list(new SHA1EntropyProvider("client_id"));
193 scoped_refptr<base::FieldTrial> trials[] = { 193 scoped_refptr<base::FieldTrial> trials[] = {
194 base::FieldTrialList::FactoryGetFieldTrial("one", 100, "default", 194 base::FieldTrialList::FactoryGetFieldTrial("one", 100, "default",
195 base::FieldTrialList::kExpirationYearInFuture, 1, 1, NULL), 195 base::FieldTrialList::kNoExpirationYear, 1, 1, NULL),
196 base::FieldTrialList::FactoryGetFieldTrial("two", 100, "default", 196 base::FieldTrialList::FactoryGetFieldTrial("two", 100, "default",
197 base::FieldTrialList::kExpirationYearInFuture, 1, 1, NULL) }; 197 base::FieldTrialList::kNoExpirationYear, 1, 1, NULL) };
198 198
199 for (size_t i = 0; i < arraysize(trials); ++i) { 199 for (size_t i = 0; i < arraysize(trials); ++i) {
200 trials[i]->UseOneTimeRandomization(); 200 trials[i]->UseOneTimeRandomization();
201 201
202 for (int j = 0; j < 100; ++j) 202 for (int j = 0; j < 100; ++j)
203 trials[i]->AppendGroup("", 1); 203 trials[i]->AppendGroup("", 1);
204 } 204 }
205 205
206 // The trials are most likely to give different results since they have 206 // The trials are most likely to give different results since they have
207 // different names. 207 // different names.
208 EXPECT_NE(trials[0]->group(), trials[1]->group()); 208 EXPECT_NE(trials[0]->group(), trials[1]->group());
209 EXPECT_NE(trials[0]->group_name(), trials[1]->group_name()); 209 EXPECT_NE(trials[0]->group_name(), trials[1]->group_name());
210 } 210 }
211 211
212 TEST_F(EntropyProviderTest, UseOneTimeRandomizationPermuted) { 212 TEST_F(EntropyProviderTest, UseOneTimeRandomizationPermuted) {
213 // Simply asserts that two trials using one-time randomization 213 // Simply asserts that two trials using one-time randomization
214 // that have different names, normally generate different results. 214 // that have different names, normally generate different results.
215 // 215 //
216 // Note that depending on the one-time random initialization, they 216 // Note that depending on the one-time random initialization, they
217 // _might_ actually give the same result, but we know that given 217 // _might_ actually give the same result, but we know that given
218 // the particular client_id we use for unit tests they won't. 218 // the particular client_id we use for unit tests they won't.
219 base::FieldTrialList field_trial_list( 219 base::FieldTrialList field_trial_list(
220 new PermutedEntropyProvider(1234, kMaxLowEntropySize)); 220 new PermutedEntropyProvider(1234, kMaxLowEntropySize));
221 scoped_refptr<base::FieldTrial> trials[] = { 221 scoped_refptr<base::FieldTrial> trials[] = {
222 base::FieldTrialList::FactoryGetFieldTrial("one", 100, "default", 222 base::FieldTrialList::FactoryGetFieldTrial("one", 100, "default",
223 base::FieldTrialList::kExpirationYearInFuture, 1, 1, NULL), 223 base::FieldTrialList::kNoExpirationYear, 1, 1, NULL),
224 base::FieldTrialList::FactoryGetFieldTrial("two", 100, "default", 224 base::FieldTrialList::FactoryGetFieldTrial("two", 100, "default",
225 base::FieldTrialList::kExpirationYearInFuture, 1, 1, NULL) }; 225 base::FieldTrialList::kNoExpirationYear, 1, 1, NULL) };
226 226
227 for (size_t i = 0; i < arraysize(trials); ++i) { 227 for (size_t i = 0; i < arraysize(trials); ++i) {
228 trials[i]->UseOneTimeRandomization(); 228 trials[i]->UseOneTimeRandomization();
229 229
230 for (int j = 0; j < 100; ++j) 230 for (int j = 0; j < 100; ++j)
231 trials[i]->AppendGroup("", 1); 231 trials[i]->AppendGroup("", 1);
232 } 232 }
233 233
234 // The trials are most likely to give different results since they have 234 // The trials are most likely to give different results since they have
235 // different names. 235 // different names.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 ++count; 329 ++count;
330 } 330 }
331 331
332 ASSERT_LT(count, kMaxAttempts) << "Expected average was " << 332 ASSERT_LT(count, kMaxAttempts) << "Expected average was " <<
333 kExpectedAverage << ", average ended at " << cumulative_average << 333 kExpectedAverage << ", average ended at " << cumulative_average <<
334 ", for trial " << kTestTrialNames[i]; 334 ", for trial " << kTestTrialNames[i];
335 } 335 }
336 } 336 }
337 337
338 } // namespace metrics 338 } // namespace metrics
OLDNEW
« no previous file with comments | « chrome/browser/metrics/variations/variations_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698