| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/safe_browsing/chrome_cleaner/srt_field_trial_win.h" | 5 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/metrics/field_trial.h" | |
| 11 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| 12 #include "components/variations/variations_associated_data.h" | 11 #include "components/variations/variations_params_manager.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| 15 namespace safe_browsing { | 14 namespace safe_browsing { |
| 16 | 15 |
| 17 class SRTDownloadURLTest : public ::testing::Test { | 16 class SRTDownloadURLTest : public ::testing::Test { |
| 18 protected: | 17 protected: |
| 19 void SetUp() override { | 18 void CreatePromptTrial(const std::string& experiment_name) { |
| 20 field_trial_list_ = std::make_unique<base::FieldTrialList>(nullptr); | 19 // Assigned trials will go out of scope when variations_ goes out of scope. |
| 21 } | |
| 22 | |
| 23 void CreatePromptTrial(const std::string& experiment_name, | |
| 24 const std::string& download_group) { | |
| 25 std::map<std::string, std::string> params; | |
| 26 if (!download_group.empty()) | |
| 27 params["download_group"] = download_group; | |
| 28 | |
| 29 // Assigned trials will go out of scope when field_trial_list_ goes out | |
| 30 // of scope. | |
| 31 constexpr char kTrialName[] = "SRTPromptFieldTrial"; | 20 constexpr char kTrialName[] = "SRTPromptFieldTrial"; |
| 32 variations::AssociateVariationParams(kTrialName, experiment_name, params); | |
| 33 base::FieldTrialList::CreateFieldTrial(kTrialName, experiment_name); | 21 base::FieldTrialList::CreateFieldTrial(kTrialName, experiment_name); |
| 34 } | 22 } |
| 35 | 23 |
| 24 void CreateDownloadFeature(const std::string& download_group_name) { |
| 25 constexpr char kFeatureName[] = "DownloadCleanupToolByBitness"; |
| 26 std::map<std::string, std::string> params; |
| 27 params["download_group"] = download_group_name; |
| 28 variations_.SetVariationParamsWithFeatureAssociations( |
| 29 "A trial name", params, {kFeatureName}); |
| 30 } |
| 31 |
| 36 private: | 32 private: |
| 37 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 33 variations::testing::VariationParamsManager variations_; |
| 38 }; | 34 }; |
| 39 | 35 |
| 40 TEST_F(SRTDownloadURLTest, Stable) { | 36 TEST_F(SRTDownloadURLTest, Stable) { |
| 41 CreatePromptTrial("On", ""); | 37 CreatePromptTrial("On"); |
| 42 EXPECT_EQ("/dl/softwareremovaltool/win/chrome_cleanup_tool.exe", | 38 EXPECT_EQ("/dl/softwareremovaltool/win/chrome_cleanup_tool.exe", |
| 43 GetSRTDownloadURL().path()); | 39 GetSRTDownloadURL().path()); |
| 44 } | 40 } |
| 45 | 41 |
| 46 TEST_F(SRTDownloadURLTest, Canary) { | 42 TEST_F(SRTDownloadURLTest, Canary) { |
| 47 CreatePromptTrial("SRTCanary", ""); | 43 CreatePromptTrial("SRTCanary"); |
| 48 EXPECT_EQ("/dl/softwareremovaltool/win/c/chrome_cleanup_tool.exe", | 44 EXPECT_EQ("/dl/softwareremovaltool/win/c/chrome_cleanup_tool.exe", |
| 49 GetSRTDownloadURL().path()); | 45 GetSRTDownloadURL().path()); |
| 50 } | 46 } |
| 51 | 47 |
| 52 TEST_F(SRTDownloadURLTest, Experiment) { | 48 TEST_F(SRTDownloadURLTest, Experiment) { |
| 53 CreatePromptTrial("Experiment", "experiment"); | 49 CreateDownloadFeature("experiment"); |
| 54 std::string expected_path; | 50 std::string expected_path; |
| 55 if (base::win::OSInfo::GetInstance()->architecture() == | 51 if (base::win::OSInfo::GetInstance()->architecture() == |
| 56 base::win::OSInfo::X86_ARCHITECTURE) { | 52 base::win::OSInfo::X86_ARCHITECTURE) { |
| 57 expected_path = | 53 expected_path = |
| 58 "/dl/softwareremovaltool/win/x86/experiment/chrome_cleanup_tool.exe"; | 54 "/dl/softwareremovaltool/win/x86/experiment/chrome_cleanup_tool.exe"; |
| 59 } else { | 55 } else { |
| 60 expected_path = | 56 expected_path = |
| 61 "/dl/softwareremovaltool/win/x64/experiment/chrome_cleanup_tool.exe"; | 57 "/dl/softwareremovaltool/win/x64/experiment/chrome_cleanup_tool.exe"; |
| 62 } | 58 } |
| 63 EXPECT_EQ(expected_path, GetSRTDownloadURL().path()); | 59 EXPECT_EQ(expected_path, GetSRTDownloadURL().path()); |
| 64 } | 60 } |
| 65 | 61 |
| 66 TEST_F(SRTDownloadURLTest, DefaultsToStable) { | 62 TEST_F(SRTDownloadURLTest, DefaultsToStable) { |
| 67 EXPECT_EQ("/dl/softwareremovaltool/win/chrome_cleanup_tool.exe", | 63 EXPECT_EQ("/dl/softwareremovaltool/win/chrome_cleanup_tool.exe", |
| 68 GetSRTDownloadURL().path()); | 64 GetSRTDownloadURL().path()); |
| 69 } | 65 } |
| 70 | 66 |
| 71 } // namespace safe_browsing | 67 } // namespace safe_browsing |
| OLD | NEW |