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