| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/chromeos/hats/hats_finch_helper.h" | 5 #include "chrome/browser/chromeos/hats/hats_finch_helper.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> |
| 9 #include <string> |
| 8 | 10 |
| 9 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/test/scoped_feature_list.h" | 12 #include "base/test/scoped_feature_list.h" |
| 11 #include "chrome/common/chrome_features.h" | 13 #include "chrome/common/chrome_features.h" |
| 12 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 15 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
| 18 #include "components/variations/variations_params_manager.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 21 |
| 19 namespace chromeos { | 22 namespace chromeos { |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 const char kGroupTesting[] = "Testing"; | 26 const std::string kFeatureAndTrialName(features::kHappinessTrackingSystem.name); |
| 24 const std::string kTrialName(features::kHappinessTrackingSystem.name); | |
| 25 | 27 |
| 26 } // namespace | 28 } // namespace |
| 27 | 29 |
| 28 class HatsFinchHelperTest : public testing::Test { | 30 class HatsFinchHelperTest : public testing::Test { |
| 29 public: | 31 public: |
| 30 using ParamMap = std::map<std::string, std::string>; | 32 using ParamMap = std::map<std::string, std::string>; |
| 31 | 33 |
| 32 HatsFinchHelperTest() : params_manager_(kTrialName, {{}}) {} | 34 HatsFinchHelperTest() {} |
| 33 | |
| 34 void SetUp() override { | |
| 35 scoped_feature_list_.InitAndEnableFeature( | |
| 36 features::kHappinessTrackingSystem); | |
| 37 } | |
| 38 | 35 |
| 39 void SetFinchSeedParams(ParamMap params) { | 36 void SetFinchSeedParams(ParamMap params) { |
| 40 // Clear all the things. | 37 params_manager_.SetVariationParamsWithFeatureAssociations( |
| 41 variations::testing::ClearAllVariationParams(); | 38 kFeatureAndTrialName /* trial name */, params, |
| 42 variations::testing::ClearAllVariationIDs(); | 39 std::set<std::string>{kFeatureAndTrialName} /*features to switch on */); |
| 43 variations::AssociateVariationParams(kTrialName, kGroupTesting, params); | |
| 44 } | 40 } |
| 45 | 41 |
| 46 ParamMap CreateParamMap(std::string prob, | 42 ParamMap CreateParamMap(std::string prob, |
| 47 std::string cycle_length, | 43 std::string cycle_length, |
| 48 std::string start_date, | 44 std::string start_date, |
| 49 std::string reset_survey, | 45 std::string reset_survey, |
| 50 std::string reset) { | 46 std::string reset) { |
| 51 ParamMap params; | 47 ParamMap params; |
| 52 params[HatsFinchHelper::kProbabilityParam] = prob; | 48 params[HatsFinchHelper::kProbabilityParam] = prob; |
| 53 params[HatsFinchHelper::kSurveyCycleLengthParam] = cycle_length; | 49 params[HatsFinchHelper::kSurveyCycleLengthParam] = cycle_length; |
| 54 params[HatsFinchHelper::kSurveyStartDateMsParam] = start_date; | 50 params[HatsFinchHelper::kSurveyStartDateMsParam] = start_date; |
| 55 params[HatsFinchHelper::kResetSurveyCycleParam] = reset_survey; | 51 params[HatsFinchHelper::kResetSurveyCycleParam] = reset_survey; |
| 56 params[HatsFinchHelper::kResetAllParam] = reset; | 52 params[HatsFinchHelper::kResetAllParam] = reset; |
| 57 return params; | 53 return params; |
| 58 } | 54 } |
| 59 | 55 |
| 60 private: | 56 private: |
| 61 // Must outlive |profile_|. | 57 // Must outlive |profile_|. |
| 62 content::TestBrowserThreadBundle thread_bundle_; | 58 content::TestBrowserThreadBundle thread_bundle_; |
| 63 | 59 |
| 64 protected: | 60 protected: |
| 65 TestingProfile profile_; | 61 TestingProfile profile_; |
| 66 | 62 |
| 67 private: | 63 private: |
| 68 variations::testing::VariationParamsManager params_manager_; | 64 variations::testing::VariationParamsManager params_manager_; |
| 69 base::test::ScopedFeatureList scoped_feature_list_; | |
| 70 | 65 |
| 71 DISALLOW_COPY_AND_ASSIGN(HatsFinchHelperTest); | 66 DISALLOW_COPY_AND_ASSIGN(HatsFinchHelperTest); |
| 72 }; | 67 }; |
| 73 | 68 |
| 74 TEST_F(HatsFinchHelperTest, InitFinchSeed_ValidValues) { | 69 TEST_F(HatsFinchHelperTest, InitFinchSeed_ValidValues) { |
| 75 ParamMap params = | 70 ParamMap params = |
| 76 CreateParamMap("1.0", "7", "1475613895337", "false", "false"); | 71 CreateParamMap("1.0", "7", "1475613895337", "false", "false"); |
| 77 SetFinchSeedParams(params); | 72 SetFinchSeedParams(params); |
| 78 | 73 |
| 79 HatsFinchHelper hats_finch_helper(&profile_); | 74 HatsFinchHelper hats_finch_helper(&profile_); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 2 * current_time.ToJsTime()); | 167 2 * current_time.ToJsTime()); |
| 173 | 168 |
| 174 EXPECT_FALSE(pref_service->GetBoolean(prefs::kHatsDeviceIsSelected)); | 169 EXPECT_FALSE(pref_service->GetBoolean(prefs::kHatsDeviceIsSelected)); |
| 175 EXPECT_NE(pref_service->GetInt64(prefs::kHatsSurveyCycleEndTimestamp), | 170 EXPECT_NE(pref_service->GetInt64(prefs::kHatsSurveyCycleEndTimestamp), |
| 176 initial_timestamp); | 171 initial_timestamp); |
| 177 EXPECT_NE(pref_service->GetInt64(prefs::kHatsLastInteractionTimestamp), | 172 EXPECT_NE(pref_service->GetInt64(prefs::kHatsLastInteractionTimestamp), |
| 178 initial_timestamp); | 173 initial_timestamp); |
| 179 } | 174 } |
| 180 | 175 |
| 181 } // namespace chromeos | 176 } // namespace chromeos |
| OLD | NEW |