Roll ANGLE cc54ab3..c5b2ba5
[chromium-blink-merge.git] / components / variations / caching_permuted_entropy_provider_unittest.cc
blob269feab0fe5dcad7b2ab8be535356806fbb01fc7
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/variations/caching_permuted_entropy_provider.h"
7 #include <string>
9 #include "base/basictypes.h"
10 #include "base/prefs/testing_pref_service.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace metrics {
15 // Size of the low entropy source to use for the permuted entropy provider
16 // in tests.
17 const size_t kMaxLowEntropySize = 8000;
19 // Field trial names used in unit tests.
20 const char* const kTestTrialNames[] = {"TestTrial", "AnotherTestTrial",
21 "NewTabButton"};
23 TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) {
24 TestingPrefServiceSimple prefs;
25 CachingPermutedEntropyProvider::RegisterPrefs(prefs.registry());
26 const int kEntropyValue = 1234;
28 // Check that the caching provider returns the same results as the non caching
29 // one. Loop over the trial names twice, to test that caching returns the
30 // expected results.
31 PermutedEntropyProvider provider(kEntropyValue, kMaxLowEntropySize);
32 for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) {
33 CachingPermutedEntropyProvider cached_provider(
34 &prefs, kEntropyValue, kMaxLowEntropySize);
35 const std::string trial_name =
36 kTestTrialNames[i % arraysize(kTestTrialNames)];
37 EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0),
38 cached_provider.GetEntropyForTrial(trial_name, 0));
41 // Now, do the same test re-using the same caching provider.
42 CachingPermutedEntropyProvider cached_provider(
43 &prefs, kEntropyValue, kMaxLowEntropySize);
44 for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) {
45 const std::string trial_name =
46 kTestTrialNames[i % arraysize(kTestTrialNames)];
47 EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0),
48 cached_provider.GetEntropyForTrial(trial_name, 0));
52 } // namespace metrics