| 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> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 const char kValueForMultiSwitch2[] = "value_for_multi_switch2"; | 55 const char kValueForMultiSwitch2[] = "value_for_multi_switch2"; |
| 56 | 56 |
| 57 const char kEnableDisableValue1[] = "value1"; | 57 const char kEnableDisableValue1[] = "value1"; |
| 58 const char kEnableDisableValue2[] = "value2"; | 58 const char kEnableDisableValue2[] = "value2"; |
| 59 | 59 |
| 60 const char kEnableFeatures[] = "dummy-enable-features"; | 60 const char kEnableFeatures[] = "dummy-enable-features"; |
| 61 const char kDisableFeatures[] = "dummy-disable-features"; | 61 const char kDisableFeatures[] = "dummy-disable-features"; |
| 62 | 62 |
| 63 const char kTestTrial[] = "TestTrial"; | 63 const char kTestTrial[] = "TestTrial"; |
| 64 const char kTestParam[] = "param"; | 64 const char kTestParam[] = "param"; |
| 65 const char kTestParamValue1[] = "value1"; | 65 const char kTestParamValue[] = "value"; |
| 66 const char kTestParamValue2[] = "value2"; | |
| 67 | 66 |
| 68 const base::Feature kTestFeature1{"FeatureName1", | 67 const base::Feature kTestFeature1{"FeatureName1", |
| 69 base::FEATURE_ENABLED_BY_DEFAULT}; | 68 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 70 const base::Feature kTestFeature2{"FeatureName2", | 69 const base::Feature kTestFeature2{"FeatureName2", |
| 71 base::FEATURE_ENABLED_BY_DEFAULT}; | 70 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 72 | 71 |
| 73 const FeatureEntry::FeatureParam kTestVariationDefault[] = { | |
| 74 {kTestParam, kTestParamValue1}}; | |
| 75 | |
| 76 const FeatureEntry::FeatureParam kTestVariationOther[] = { | 72 const FeatureEntry::FeatureParam kTestVariationOther[] = { |
| 77 {kTestParam, kTestParamValue2}}; | 73 {kTestParam, kTestParamValue}}; |
| 78 | 74 |
| 79 const FeatureEntry::FeatureVariation kTestVariations[] = { | 75 const FeatureEntry::FeatureVariation kTestVariations[] = { |
| 80 {"", kTestVariationDefault, 1}, | |
| 81 {"dummy description", kTestVariationOther, 1}}; | 76 {"dummy description", kTestVariationOther, 1}}; |
| 82 | 77 |
| 83 // Those have to be valid ids for the translation system but the value are | 78 // Those have to be valid ids for the translation system but the value are |
| 84 // never used, so pick one at random from the current component. | 79 // never used, so pick one at random from the current component. |
| 85 const int kDummyNameId = IDS_FLAGS_UI_WARNING_HEADER; | 80 const int kDummyNameId = IDS_FLAGS_UI_WARNING_HEADER; |
| 86 const int kDummyDescriptionId = IDS_FLAGS_UI_WARNING_TEXT; | 81 const int kDummyDescriptionId = IDS_FLAGS_UI_WARNING_TEXT; |
| 87 | 82 |
| 88 bool SkipFeatureEntry(const FeatureEntry& feature_entry) { | 83 bool SkipFeatureEntry(const FeatureEntry& feature_entry) { |
| 89 return false; | 84 return false; |
| 90 } | 85 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 kNoSentinels, kEnableFeatures, | 256 kNoSentinels, kEnableFeatures, |
| 262 kDisableFeatures); | 257 kDisableFeatures); |
| 263 | 258 |
| 264 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); | 259 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); |
| 265 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); | 260 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); |
| 266 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); | 261 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); |
| 267 } | 262 } |
| 268 | 263 |
| 269 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) { | 264 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) { |
| 270 const FeatureEntry& entry = kEntries[7]; | 265 const FeatureEntry& entry = kEntries[7]; |
| 271 // Select the "Disabled" variation. | 266 // Select the "Default" variation. |
| 272 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0), | 267 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0), |
| 273 true); | 268 true); |
| 274 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); | 269 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); |
| 275 // No value should be associated. | 270 // No value should be associated. |
| 276 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam)); | 271 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 277 // The trial should not be created. | 272 // The trial should not be created. |
| 278 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial); | 273 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial); |
| 279 EXPECT_EQ(nullptr, trial); | 274 EXPECT_EQ(nullptr, trial); |
| 280 | 275 |
| 281 // Select the first "Enabled" variation. | 276 // Select the default "Enabled" variation. |
| 282 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1), | 277 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1), |
| 283 true); | 278 true); |
| 284 | 279 |
| 285 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); | 280 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); |
| 286 // The value should be associated. | 281 // No value should be associated as this is the default option. |
| 287 EXPECT_EQ(kTestParamValue1, | 282 EXPECT_EQ("", |
| 288 variations::GetVariationParamValue(kTestTrial, kTestParam)); | 283 variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 289 | 284 |
| 290 // The trial should be created. | 285 // The trial should be created. |
| 291 trial = base::FieldTrialList::Find(kTestTrial); | 286 trial = base::FieldTrialList::Find(kTestTrial); |
| 292 EXPECT_NE(nullptr, trial); | 287 EXPECT_NE(nullptr, trial); |
| 293 // The about:flags group should be selected for the trial. | 288 // The about:flags group should be selected for the trial. |
| 294 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name()); | 289 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name()); |
| 295 | 290 |
| 296 // Select the second "Enabled" variation. | 291 // Select the only one variation. |
| 297 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), | 292 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), |
| 298 true); | 293 true); |
| 299 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); | 294 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); |
| 300 // Associating for the second time should not change the value. | 295 // Associating for the second time should not change the value. |
| 301 EXPECT_EQ(kTestParamValue1, | 296 EXPECT_EQ("", |
| 302 variations::GetVariationParamValue(kTestTrial, kTestParam)); | 297 variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 303 } | 298 } |
| 304 | 299 |
| 300 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParametersNonDefault) { |
| 301 const FeatureEntry& entry = kEntries[7]; |
| 302 // Select the only one variation. |
| 303 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), |
| 304 true); |
| 305 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); |
| 306 // The param should have the value predefined in this variation. |
| 307 EXPECT_EQ(kTestParamValue, |
| 308 variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 309 } |
| 310 |
| 305 base::CommandLine::StringType CreateSwitch(const std::string& value) { | 311 base::CommandLine::StringType CreateSwitch(const std::string& value) { |
| 306 #if defined(OS_WIN) | 312 #if defined(OS_WIN) |
| 307 return base::ASCIIToUTF16(value); | 313 return base::ASCIIToUTF16(value); |
| 308 #else | 314 #else |
| 309 return value; | 315 return value; |
| 310 #endif | 316 #endif |
| 311 } | 317 } |
| 312 | 318 |
| 313 TEST_F(FlagsStateTest, CompareSwitchesToCurrentCommandLine) { | 319 TEST_F(FlagsStateTest, CompareSwitchesToCurrentCommandLine) { |
| 314 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true); | 320 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 &supported_entries, &unsupported_entries, | 758 &supported_entries, &unsupported_entries, |
| 753 base::Bind(&SkipFeatureEntry)); | 759 base::Bind(&SkipFeatureEntry)); |
| 754 // All |kEntries| except for |kFlags3| should be supported. | 760 // All |kEntries| except for |kFlags3| should be supported. |
| 755 EXPECT_EQ(7u, supported_entries.GetSize()); | 761 EXPECT_EQ(7u, supported_entries.GetSize()); |
| 756 EXPECT_EQ(1u, unsupported_entries.GetSize()); | 762 EXPECT_EQ(1u, unsupported_entries.GetSize()); |
| 757 EXPECT_EQ(arraysize(kEntries), | 763 EXPECT_EQ(arraysize(kEntries), |
| 758 supported_entries.GetSize() + unsupported_entries.GetSize()); | 764 supported_entries.GetSize() + unsupported_entries.GetSize()); |
| 759 } | 765 } |
| 760 | 766 |
| 761 } // namespace flags_ui | 767 } // namespace flags_ui |
| OLD | NEW |