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

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

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 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
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::kNoExpirationYear, 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::kNoExpirationYear, 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(std::string(), 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::kNoExpirationYear, 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::kNoExpirationYear, 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(std::string(), 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.
236 EXPECT_NE(trials[0]->group(), trials[1]->group()); 236 EXPECT_NE(trials[0]->group(), trials[1]->group());
237 EXPECT_NE(trials[0]->group_name(), trials[1]->group_name()); 237 EXPECT_NE(trials[0]->group_name(), trials[1]->group_name());
238 } 238 }
239 239
240 TEST_F(EntropyProviderTest, SHA1Entropy) { 240 TEST_F(EntropyProviderTest, SHA1Entropy) {
241 const double results[] = { GenerateSHA1Entropy("hi", "1"), 241 const double results[] = { GenerateSHA1Entropy("hi", "1"),
(...skipping 87 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/common/json_schema/json_schema_validator_unittest_base.cc ('k') | chrome/common/net/x509_certificate_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698