| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/flags_ui/flags_state.h" | 5 #include "components/flags_ui/flags_state.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/feature_list.h" | 15 #include "base/feature_list.h" |
| 16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/test/scoped_feature_list.h" |
| 22 #include "base/values.h" | 23 #include "base/values.h" |
| 23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 24 #include "components/flags_ui/feature_entry.h" | 25 #include "components/flags_ui/feature_entry.h" |
| 25 #include "components/flags_ui/flags_ui_pref_names.h" | 26 #include "components/flags_ui/flags_ui_pref_names.h" |
| 26 #include "components/flags_ui/flags_ui_switches.h" | 27 #include "components/flags_ui/flags_ui_switches.h" |
| 27 #include "components/flags_ui/pref_service_flags_storage.h" | 28 #include "components/flags_ui/pref_service_flags_storage.h" |
| 28 #include "components/prefs/pref_registry_simple.h" | 29 #include "components/prefs/pref_registry_simple.h" |
| 29 #include "components/prefs/testing_pref_service.h" | 30 #include "components/prefs/testing_pref_service.h" |
| 30 #include "components/variations/variations_associated_data.h" | 31 #include "components/variations/variations_associated_data.h" |
| 31 #include "grit/components_strings.h" | 32 #include "grit/components_strings.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 312 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 312 | 313 |
| 313 // Select the only one variation. | 314 // Select the only one variation. |
| 314 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), | 315 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), |
| 315 true); | 316 true); |
| 316 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, | 317 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, |
| 317 feature_list.get()); | 318 feature_list.get()); |
| 318 | 319 |
| 319 // Set the feature_list as the main instance so that | 320 // Set the feature_list as the main instance so that |
| 320 // variations::GetVariationParamValueByFeature below works. | 321 // variations::GetVariationParamValueByFeature below works. |
| 321 base::FeatureList::ClearInstanceForTesting(); | 322 base::test::ScopedFeatureList scoped_feature_list; |
| 322 base::FeatureList::SetInstance(std::move(feature_list)); | 323 scoped_feature_list.InitWithFeatureList(std::move(feature_list)); |
| 323 | 324 |
| 324 // The param should have the value predefined in this variation. | 325 // The param should have the value predefined in this variation. |
| 325 EXPECT_EQ(kTestParamValue, | 326 EXPECT_EQ(kTestParamValue, |
| 326 variations::GetVariationParamValue(kTestTrial, kTestParam)); | 327 variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 327 | 328 |
| 328 // The value should be associated also via the name of the feature. | 329 // The value should be associated also via the name of the feature. |
| 329 EXPECT_EQ(kTestParamValue, variations::GetVariationParamValueByFeature( | 330 EXPECT_EQ(kTestParamValue, variations::GetVariationParamValueByFeature( |
| 330 kTestFeature2, kTestParam)); | 331 kTestFeature2, kTestParam)); |
| 331 } | 332 } |
| 332 | 333 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 &supported_entries, &unsupported_entries, | 781 &supported_entries, &unsupported_entries, |
| 781 base::Bind(&SkipFeatureEntry)); | 782 base::Bind(&SkipFeatureEntry)); |
| 782 // All |kEntries| except for |kFlags3| should be supported. | 783 // All |kEntries| except for |kFlags3| should be supported. |
| 783 EXPECT_EQ(7u, supported_entries.GetSize()); | 784 EXPECT_EQ(7u, supported_entries.GetSize()); |
| 784 EXPECT_EQ(1u, unsupported_entries.GetSize()); | 785 EXPECT_EQ(1u, unsupported_entries.GetSize()); |
| 785 EXPECT_EQ(arraysize(kEntries), | 786 EXPECT_EQ(arraysize(kEntries), |
| 786 supported_entries.GetSize() + unsupported_entries.GetSize()); | 787 supported_entries.GetSize() + unsupported_entries.GetSize()); |
| 787 } | 788 } |
| 788 | 789 |
| 789 } // namespace flags_ui | 790 } // namespace flags_ui |
| OLD | NEW |