OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_seed_simulator.h" | 5 #include "components/variations/variations_seed_simulator.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "components/variations/processed_study.h" | 10 #include "components/variations/processed_study.h" |
11 #include "components/variations/proto/study.pb.h" | 11 #include "components/variations/proto/study.pb.h" |
12 #include "components/variations/variations_associated_data.h" | 12 #include "components/variations/variations_associated_data.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace chrome_variations { | 15 namespace variations { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // An implementation of EntropyProvider that always returns a specific entropy | 19 // An implementation of EntropyProvider that always returns a specific entropy |
20 // value, regardless of field trial. | 20 // value, regardless of field trial. |
21 class TestEntropyProvider : public base::FieldTrial::EntropyProvider { | 21 class TestEntropyProvider : public base::FieldTrial::EntropyProvider { |
22 public: | 22 public: |
23 explicit TestEntropyProvider(double entropy_value) | 23 explicit TestEntropyProvider(double entropy_value) |
24 : entropy_value_(entropy_value) {} | 24 : entropy_value_(entropy_value) {} |
25 virtual ~TestEntropyProvider() {} | 25 virtual ~TestEntropyProvider() {} |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 // Simulates the differences between |study| and the current field trial | 104 // Simulates the differences between |study| and the current field trial |
105 // state, returning a string like "1 2 3", where 1 is the number of regular | 105 // state, returning a string like "1 2 3", where 1 is the number of regular |
106 // group changes, 2 is the number of "kill best effort" group changes and 3 | 106 // group changes, 2 is the number of "kill best effort" group changes and 3 |
107 // is the number of "kill critical" group changes. | 107 // is the number of "kill critical" group changes. |
108 std::string SimulateStudyDifferences(const Study* study) { | 108 std::string SimulateStudyDifferences(const Study* study) { |
109 std::vector<ProcessedStudy> studies; | 109 std::vector<ProcessedStudy> studies; |
110 if (!ProcessedStudy::ValidateAndAppendStudy(study, false, &studies)) | 110 if (!ProcessedStudy::ValidateAndAppendStudy(study, false, &studies)) |
111 return "invalid study"; | 111 return "invalid study"; |
112 return ConvertSimulationResultToString(SimulateDifferences(studies)); | 112 return ConvertSimulationResultToString(SimulateDifferences(studies)); |
113 | |
114 } | 113 } |
115 | 114 |
116 // Simulates the differences between expired |study| and the current field | 115 // Simulates the differences between expired |study| and the current field |
117 // trial state, returning a string like "1 2 3", where 1 is the number of | 116 // trial state, returning a string like "1 2 3", where 1 is the number of |
118 // regular group changes, 2 is the number of "kill best effort" group changes | 117 // regular group changes, 2 is the number of "kill best effort" group changes |
119 // and 3 is the number of "kill critical" group changes. | 118 // and 3 is the number of "kill critical" group changes. |
120 std::string SimulateStudyDifferencesExpired(const Study* study) { | 119 std::string SimulateStudyDifferencesExpired(const Study* study) { |
121 std::vector<ProcessedStudy> studies; | 120 std::vector<ProcessedStudy> studies; |
122 if (!ProcessedStudy::ValidateAndAppendStudy(study, true, &studies)) | 121 if (!ProcessedStudy::ValidateAndAppendStudy(study, true, &studies)) |
123 return "invalid study"; | 122 return "invalid study"; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 experiment->set_type(Study_Experiment_Type_NORMAL); | 371 experiment->set_type(Study_Experiment_Type_NORMAL); |
373 EXPECT_EQ("1 0 0", SimulateStudyDifferences(&study)); | 372 EXPECT_EQ("1 0 0", SimulateStudyDifferences(&study)); |
374 experiment->set_type(Study_Experiment_Type_IGNORE_CHANGE); | 373 experiment->set_type(Study_Experiment_Type_IGNORE_CHANGE); |
375 EXPECT_EQ("0 0 0", SimulateStudyDifferences(&study)); | 374 EXPECT_EQ("0 0 0", SimulateStudyDifferences(&study)); |
376 experiment->set_type(Study_Experiment_Type_KILL_BEST_EFFORT); | 375 experiment->set_type(Study_Experiment_Type_KILL_BEST_EFFORT); |
377 EXPECT_EQ("0 1 0", SimulateStudyDifferences(&study)); | 376 EXPECT_EQ("0 1 0", SimulateStudyDifferences(&study)); |
378 experiment->set_type(Study_Experiment_Type_KILL_CRITICAL); | 377 experiment->set_type(Study_Experiment_Type_KILL_CRITICAL); |
379 EXPECT_EQ("0 0 1", SimulateStudyDifferences(&study)); | 378 EXPECT_EQ("0 0 1", SimulateStudyDifferences(&study)); |
380 } | 379 } |
381 | 380 |
382 } // namespace chrome_variations | 381 } // namespace variations |
OLD | NEW |