Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(630)

Side by Side Diff: components/flags_ui/flags_state_unittest.cc

Issue 2129543002: Registering field trial for a feature overridden in chrome://flags. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After code review #1 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 kNoSentinels, kEnableFeatures, 261 kNoSentinels, kEnableFeatures,
262 kDisableFeatures); 262 kDisableFeatures);
263 263
264 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); 264 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1));
265 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); 265 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin));
266 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); 266 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd));
267 } 267 }
268 268
269 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) { 269 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) {
270 const FeatureEntry& entry = kEntries[7]; 270 const FeatureEntry& entry = kEntries[7];
271 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
272
271 // Select the "Disabled" variation. 273 // Select the "Disabled" variation.
272 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0), 274 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0),
273 true); 275 true);
274 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); 276 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_,
277 feature_list.get());
275 // No value should be associated. 278 // No value should be associated.
276 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam)); 279 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam));
277 // The trial should not be created. 280 // The trial should not be created.
278 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial); 281 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial);
279 EXPECT_EQ(nullptr, trial); 282 EXPECT_EQ(nullptr, trial);
280 283
281 // Select the first "Enabled" variation. 284 // Select the first "Enabled" variation.
282 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1), 285 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1),
283 true); 286 true);
284 287
285 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); 288 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_,
289 feature_list.get());
290 // Set the feature_list as the main instance so that
291 // variations::GetVariationParamValueByFeature below works.
292 base::FeatureList::ClearInstanceForTesting();
293 base::FeatureList::SetInstance(std::move(feature_list));
294
286 // The value should be associated. 295 // The value should be associated.
287 EXPECT_EQ(kTestParamValue1, 296 EXPECT_EQ(kTestParamValue1,
288 variations::GetVariationParamValue(kTestTrial, kTestParam)); 297 variations::GetVariationParamValue(kTestTrial, kTestParam));
298 // The value should be associated also via the name of the feature.
299 EXPECT_EQ(kTestParamValue1, variations::GetVariationParamValueByFeature(
300 kTestFeature2, kTestParam));
289 301
290 // The trial should be created. 302 // The trial should be created.
291 trial = base::FieldTrialList::Find(kTestTrial); 303 trial = base::FieldTrialList::Find(kTestTrial);
292 EXPECT_NE(nullptr, trial); 304 EXPECT_NE(nullptr, trial);
293 // The about:flags group should be selected for the trial. 305 // The about:flags group should be selected for the trial.
294 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name()); 306 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name());
295 307
296 // Select the second "Enabled" variation. 308 // Select the second "Enabled" variation.
297 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), 309 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2),
298 true); 310 true);
299 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_); 311 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_,
312 feature_list.get());
300 // Associating for the second time should not change the value. 313 // Associating for the second time should not change the value.
301 EXPECT_EQ(kTestParamValue1, 314 EXPECT_EQ(kTestParamValue1,
302 variations::GetVariationParamValue(kTestTrial, kTestParam)); 315 variations::GetVariationParamValue(kTestTrial, kTestParam));
303 } 316 }
304 317
305 base::CommandLine::StringType CreateSwitch(const std::string& value) { 318 base::CommandLine::StringType CreateSwitch(const std::string& value) {
306 #if defined(OS_WIN) 319 #if defined(OS_WIN)
307 return base::ASCIIToUTF16(value); 320 return base::ASCIIToUTF16(value);
308 #else 321 #else
309 return value; 322 return value;
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 &supported_entries, &unsupported_entries, 765 &supported_entries, &unsupported_entries,
753 base::Bind(&SkipFeatureEntry)); 766 base::Bind(&SkipFeatureEntry));
754 // All |kEntries| except for |kFlags3| should be supported. 767 // All |kEntries| except for |kFlags3| should be supported.
755 EXPECT_EQ(7u, supported_entries.GetSize()); 768 EXPECT_EQ(7u, supported_entries.GetSize());
756 EXPECT_EQ(1u, unsupported_entries.GetSize()); 769 EXPECT_EQ(1u, unsupported_entries.GetSize());
757 EXPECT_EQ(arraysize(kEntries), 770 EXPECT_EQ(arraysize(kEntries),
758 supported_entries.GetSize() + unsupported_entries.GetSize()); 771 supported_entries.GetSize() + unsupported_entries.GetSize());
759 } 772 }
760 773
761 } // namespace flags_ui 774 } // namespace flags_ui
OLDNEW
« components/flags_ui/flags_state.h ('K') | « components/flags_ui/flags_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698