| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 kNoSentinels, kEnableFeatures, | 260 kNoSentinels, kEnableFeatures, |
| 261 kDisableFeatures); | 261 kDisableFeatures); |
| 262 | 262 |
| 263 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); | 263 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); |
| 264 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); | 264 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); |
| 265 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); | 265 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) { | 268 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) { |
| 269 const FeatureEntry& entry = kEntries[7]; | 269 const FeatureEntry& entry = kEntries[7]; |
| 270 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 271 |
| 270 // Select the "Default" variation. | 272 // Select the "Default" variation. |
| 271 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0), | 273 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0), |
| 272 true); | 274 true); |
| 273 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); | 275 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, |
| 276 feature_list.get()); |
| 274 // No value should be associated. | 277 // No value should be associated. |
| 275 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam)); | 278 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 276 // The trial should not be created. | 279 // The trial should not be created. |
| 277 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial); | 280 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial); |
| 278 EXPECT_EQ(nullptr, trial); | 281 EXPECT_EQ(nullptr, trial); |
| 279 | 282 |
| 280 // Select the default "Enabled" variation. | 283 // Select the default "Enabled" variation. |
| 281 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1), | 284 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1), |
| 282 true); | 285 true); |
| 283 | 286 |
| 284 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); | 287 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, |
| 288 feature_list.get()); |
| 285 // No value should be associated as this is the default option. | 289 // No value should be associated as this is the default option. |
| 286 EXPECT_EQ("", | 290 EXPECT_EQ("", |
| 287 variations::GetVariationParamValue(kTestTrial, kTestParam)); | 291 variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 288 | 292 |
| 289 // The trial should be created. | 293 // The trial should be created. |
| 290 trial = base::FieldTrialList::Find(kTestTrial); | 294 trial = base::FieldTrialList::Find(kTestTrial); |
| 291 EXPECT_NE(nullptr, trial); | 295 EXPECT_NE(nullptr, trial); |
| 292 // The about:flags group should be selected for the trial. | 296 // The about:flags group should be selected for the trial. |
| 293 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name()); | 297 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name()); |
| 294 | 298 |
| 295 // Select the only one variation. | 299 // Select the only one variation. |
| 296 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), | 300 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), |
| 297 true); | 301 true); |
| 298 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); | 302 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, |
| 303 feature_list.get()); |
| 299 // Associating for the second time should not change the value. | 304 // Associating for the second time should not change the value. |
| 300 EXPECT_EQ("", | 305 EXPECT_EQ("", |
| 301 variations::GetVariationParamValue(kTestTrial, kTestParam)); | 306 variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 302 } | 307 } |
| 303 | 308 |
| 304 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParametersNonDefault) { | 309 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParametersNonDefault) { |
| 305 const FeatureEntry& entry = kEntries[7]; | 310 const FeatureEntry& entry = kEntries[7]; |
| 311 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 312 |
| 306 // Select the only one variation. | 313 // Select the only one variation. |
| 307 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), | 314 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), |
| 308 true); | 315 true); |
| 309 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); | 316 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, |
| 317 feature_list.get()); |
| 318 |
| 319 // Set the feature_list as the main instance so that |
| 320 // variations::GetVariationParamValueByFeature below works. |
| 321 base::FeatureList::ClearInstanceForTesting(); |
| 322 base::FeatureList::SetInstance(std::move(feature_list)); |
| 323 |
| 310 // The param should have the value predefined in this variation. | 324 // The param should have the value predefined in this variation. |
| 311 EXPECT_EQ(kTestParamValue, | 325 EXPECT_EQ(kTestParamValue, |
| 312 variations::GetVariationParamValue(kTestTrial, kTestParam)); | 326 variations::GetVariationParamValue(kTestTrial, kTestParam)); |
| 327 |
| 328 // The value should be associated also via the name of the feature. |
| 329 EXPECT_EQ(kTestParamValue, variations::GetVariationParamValueByFeature( |
| 330 kTestFeature2, kTestParam)); |
| 313 } | 331 } |
| 314 | 332 |
| 315 base::CommandLine::StringType CreateSwitch(const std::string& value) { | 333 base::CommandLine::StringType CreateSwitch(const std::string& value) { |
| 316 #if defined(OS_WIN) | 334 #if defined(OS_WIN) |
| 317 return base::ASCIIToUTF16(value); | 335 return base::ASCIIToUTF16(value); |
| 318 #else | 336 #else |
| 319 return value; | 337 return value; |
| 320 #endif | 338 #endif |
| 321 } | 339 } |
| 322 | 340 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 &supported_entries, &unsupported_entries, | 780 &supported_entries, &unsupported_entries, |
| 763 base::Bind(&SkipFeatureEntry)); | 781 base::Bind(&SkipFeatureEntry)); |
| 764 // All |kEntries| except for |kFlags3| should be supported. | 782 // All |kEntries| except for |kFlags3| should be supported. |
| 765 EXPECT_EQ(7u, supported_entries.GetSize()); | 783 EXPECT_EQ(7u, supported_entries.GetSize()); |
| 766 EXPECT_EQ(1u, unsupported_entries.GetSize()); | 784 EXPECT_EQ(1u, unsupported_entries.GetSize()); |
| 767 EXPECT_EQ(arraysize(kEntries), | 785 EXPECT_EQ(arraysize(kEntries), |
| 768 supported_entries.GetSize() + unsupported_entries.GetSize()); | 786 supported_entries.GetSize() + unsupported_entries.GetSize()); |
| 769 } | 787 } |
| 770 | 788 |
| 771 } // namespace flags_ui | 789 } // namespace flags_ui |
| OLD | NEW |