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

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

Issue 2707013002: [chrome://flags] Let features override params in the same trial (Closed)
Patch Set: Comments #2 Created 3 years, 9 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
« no previous file with comments | « components/flags_ui/flags_state.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 26 matching lines...) Expand all
37 namespace { 37 namespace {
38 38
39 const char kFlags1[] = "flag1"; 39 const char kFlags1[] = "flag1";
40 const char kFlags2[] = "flag2"; 40 const char kFlags2[] = "flag2";
41 const char kFlags3[] = "flag3"; 41 const char kFlags3[] = "flag3";
42 const char kFlags4[] = "flag4"; 42 const char kFlags4[] = "flag4";
43 const char kFlags5[] = "flag5"; 43 const char kFlags5[] = "flag5";
44 const char kFlags6[] = "flag6"; 44 const char kFlags6[] = "flag6";
45 const char kFlags7[] = "flag7"; 45 const char kFlags7[] = "flag7";
46 const char kFlags8[] = "flag8"; 46 const char kFlags8[] = "flag8";
47 const char kFlags9[] = "flag9";
48 const char kFlags10[] = "flag10";
47 49
48 const char kSwitch1[] = "switch"; 50 const char kSwitch1[] = "switch";
49 const char kSwitch2[] = "switch2"; 51 const char kSwitch2[] = "switch2";
50 const char kSwitch3[] = "switch3"; 52 const char kSwitch3[] = "switch3";
51 const char kSwitch6[] = "switch6"; 53 const char kSwitch6[] = "switch6";
52 const char kValueForSwitch2[] = "value_for_switch2"; 54 const char kValueForSwitch2[] = "value_for_switch2";
53 55
54 const char kMultiSwitch1[] = "multi_switch1"; 56 const char kMultiSwitch1[] = "multi_switch1";
55 const char kMultiSwitch2[] = "multi_switch2"; 57 const char kMultiSwitch2[] = "multi_switch2";
56 const char kValueForMultiSwitch2[] = "value_for_multi_switch2"; 58 const char kValueForMultiSwitch2[] = "value_for_multi_switch2";
57 59
58 const char kEnableDisableValue1[] = "value1"; 60 const char kEnableDisableValue1[] = "value1";
59 const char kEnableDisableValue2[] = "value2"; 61 const char kEnableDisableValue2[] = "value2";
60 62
61 const char kEnableFeatures[] = "dummy-enable-features"; 63 const char kEnableFeatures[] = "dummy-enable-features";
62 const char kDisableFeatures[] = "dummy-disable-features"; 64 const char kDisableFeatures[] = "dummy-disable-features";
63 65
64 const char kTestTrial[] = "TestTrial"; 66 const char kTestTrial[] = "TestTrial";
65 const char kTestParam[] = "param"; 67 const char kTestParam1[] = "param1";
68 const char kTestParam2[] = "param2";
66 const char kTestParamValue[] = "value"; 69 const char kTestParamValue[] = "value";
67 70
68 const base::Feature kTestFeature1{"FeatureName1", 71 const base::Feature kTestFeature1{"FeatureName1",
69 base::FEATURE_ENABLED_BY_DEFAULT}; 72 base::FEATURE_ENABLED_BY_DEFAULT};
70 const base::Feature kTestFeature2{"FeatureName2", 73 const base::Feature kTestFeature2{"FeatureName2",
71 base::FEATURE_ENABLED_BY_DEFAULT}; 74 base::FEATURE_ENABLED_BY_DEFAULT};
72 75
73 const FeatureEntry::FeatureParam kTestVariationOther[] = { 76 const FeatureEntry::FeatureParam kTestVariationOther1[] = {
74 {kTestParam, kTestParamValue}}; 77 {kTestParam1, kTestParamValue}};
78 const FeatureEntry::FeatureParam kTestVariationOther2[] = {
79 {kTestParam2, kTestParamValue}};
75 80
76 const FeatureEntry::FeatureVariation kTestVariations[] = { 81 const FeatureEntry::FeatureVariation kTestVariations1[] = {
77 {"dummy description", kTestVariationOther, 1, nullptr}}; 82 {"dummy description 1", kTestVariationOther1, 1, nullptr}};
83 const FeatureEntry::FeatureVariation kTestVariations2[] = {
84 {"dummy description 2", kTestVariationOther2, 1, nullptr}};
78 85
79 // Those have to be valid ids for the translation system but the value are 86 // Those have to be valid ids for the translation system but the value are
80 // never used, so pick one at random from the current component. 87 // never used, so pick one at random from the current component.
81 const int kDummyNameId = IDS_FLAGS_UI_WARNING_HEADER; 88 const int kDummyNameId = IDS_FLAGS_UI_WARNING_HEADER;
82 const int kDummyDescriptionId = IDS_FLAGS_UI_WARNING_TEXT; 89 const int kDummyDescriptionId = IDS_FLAGS_UI_WARNING_TEXT;
83 90
84 bool SkipFeatureEntry(const FeatureEntry& feature_entry) { 91 bool SkipFeatureEntry(const FeatureEntry& feature_entry) {
85 return false; 92 return false;
86 } 93 }
87 94
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 {kFlags6, kDummyNameId, kDummyDescriptionId, 0, 126 {kFlags6, kDummyNameId, kDummyDescriptionId, 0,
120 FeatureEntry::SINGLE_DISABLE_VALUE, kSwitch6, "", nullptr, nullptr, 127 FeatureEntry::SINGLE_DISABLE_VALUE, kSwitch6, "", nullptr, nullptr,
121 nullptr, 0, nullptr, nullptr, nullptr}, 128 nullptr, 0, nullptr, nullptr, nullptr},
122 {kFlags7, kDummyNameId, kDummyDescriptionId, 129 {kFlags7, kDummyNameId, kDummyDescriptionId,
123 0, // Ends up being mapped to the current platform. 130 0, // Ends up being mapped to the current platform.
124 FeatureEntry::FEATURE_VALUE, nullptr, nullptr, nullptr, nullptr, 131 FeatureEntry::FEATURE_VALUE, nullptr, nullptr, nullptr, nullptr,
125 &kTestFeature1, 3, nullptr, nullptr, nullptr}, 132 &kTestFeature1, 3, nullptr, nullptr, nullptr},
126 {kFlags8, kDummyNameId, kDummyDescriptionId, 133 {kFlags8, kDummyNameId, kDummyDescriptionId,
127 0, // Ends up being mapped to the current platform. 134 0, // Ends up being mapped to the current platform.
128 FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE, nullptr, nullptr, nullptr, 135 FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE, nullptr, nullptr, nullptr,
129 nullptr, &kTestFeature2, 4, nullptr, kTestVariations, kTestTrial}, 136 nullptr, &kTestFeature1, 4, nullptr, kTestVariations1, kTestTrial},
137 {kFlags9, kDummyNameId, kDummyDescriptionId,
138 0, // Ends up being mapped to the current platform.
139 FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE, nullptr, nullptr, nullptr,
140 nullptr, &kTestFeature1, 4, nullptr, kTestVariations1, kTestTrial},
141 {kFlags10, kDummyNameId, kDummyDescriptionId,
142 0, // Ends up being mapped to the current platform.
143 FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE, nullptr, nullptr, nullptr,
144 nullptr, &kTestFeature2, 4, nullptr, kTestVariations2, kTestTrial},
130 }; 145 };
131 146
132 class FlagsStateTest : public ::testing::Test { 147 class FlagsStateTest : public ::testing::Test {
133 protected: 148 protected:
134 FlagsStateTest() : flags_storage_(&prefs_), trial_list_(nullptr) { 149 FlagsStateTest() : flags_storage_(&prefs_), trial_list_(nullptr) {
135 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments); 150 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments);
136 151
137 for (size_t i = 0; i < arraysize(kEntries); ++i) 152 for (size_t i = 0; i < arraysize(kEntries); ++i)
138 kEntries[i].supported_platforms = FlagsState::GetCurrentPlatform(); 153 kEntries[i].supported_platforms = FlagsState::GetCurrentPlatform();
139 154
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) { 284 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) {
270 const FeatureEntry& entry = kEntries[7]; 285 const FeatureEntry& entry = kEntries[7];
271 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 286 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
272 287
273 // Select the "Default" variation. 288 // Select the "Default" variation.
274 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0), 289 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0),
275 true); 290 true);
276 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, 291 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_,
277 feature_list.get()); 292 feature_list.get());
278 // No value should be associated. 293 // No value should be associated.
279 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam)); 294 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam1));
280 // The trial should not be created. 295 // The trial should not be created.
281 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial); 296 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial);
282 EXPECT_EQ(nullptr, trial); 297 EXPECT_EQ(nullptr, trial);
283 298
284 // Select the default "Enabled" variation. 299 // Select the default "Enabled" variation.
285 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1), 300 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1),
286 true); 301 true);
287 302
288 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, 303 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_,
289 feature_list.get()); 304 feature_list.get());
290 // No value should be associated as this is the default option. 305 // No value should be associated as this is the default option.
291 EXPECT_EQ("", 306 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam1));
292 variations::GetVariationParamValue(kTestTrial, kTestParam));
293 307
294 // The trial should be created. 308 // The trial should be created.
295 trial = base::FieldTrialList::Find(kTestTrial); 309 trial = base::FieldTrialList::Find(kTestTrial);
296 EXPECT_NE(nullptr, trial); 310 EXPECT_NE(nullptr, trial);
297 // The about:flags group should be selected for the trial. 311 // The about:flags group should be selected for the trial.
298 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name()); 312 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name());
299 313
300 // Select the only one variation. 314 // Select the only one variation.
301 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), 315 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2),
302 true); 316 true);
303 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, 317 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_,
304 feature_list.get()); 318 feature_list.get());
305 // Associating for the second time should not change the value. 319 // Associating for the second time should not change the value.
306 EXPECT_EQ("", 320 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam1));
307 variations::GetVariationParamValue(kTestTrial, kTestParam));
308 } 321 }
309 322
310 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParametersNonDefault) { 323 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParametersNonDefault) {
311 const FeatureEntry& entry = kEntries[7]; 324 const FeatureEntry& entry = kEntries[7];
312 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 325 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
313 326
314 // Select the only one variation. 327 // Select the only one variation.
315 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2), 328 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2),
316 true); 329 true);
317 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_, 330 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_,
318 feature_list.get()); 331 feature_list.get());
319 332
320 // Set the feature_list as the main instance so that 333 // Set the feature_list as the main instance so that
321 // variations::GetVariationParamValueByFeature below works. 334 // variations::GetVariationParamValueByFeature below works.
322 base::test::ScopedFeatureList scoped_feature_list; 335 base::test::ScopedFeatureList scoped_feature_list;
323 scoped_feature_list.InitWithFeatureList(std::move(feature_list)); 336 scoped_feature_list.InitWithFeatureList(std::move(feature_list));
324 337
325 // The param should have the value predefined in this variation. 338 // The param should have the value predefined in this variation.
326 EXPECT_EQ(kTestParamValue, 339 EXPECT_EQ(kTestParamValue,
327 variations::GetVariationParamValue(kTestTrial, kTestParam)); 340 variations::GetVariationParamValue(kTestTrial, kTestParam1));
328 341
329 // The value should be associated also via the name of the feature. 342 // The value should be associated also via the name of the feature.
330 EXPECT_EQ(kTestParamValue, variations::GetVariationParamValueByFeature( 343 EXPECT_EQ(kTestParamValue, variations::GetVariationParamValueByFeature(
331 kTestFeature2, kTestParam)); 344 kTestFeature1, kTestParam1));
345 }
346
347 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParametersWithDefaultTrials) {
348 const FeatureEntry& entry1 = kEntries[8];
349 const FeatureEntry& entry2 = kEntries[9];
350 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
351
352 // Select the only one variation for each FeatureEntry.
353 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry1.NameForOption(2),
354 true);
355 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry2.NameForOption(2),
356 true);
357 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_,
358 feature_list.get());
359
360 // Set the feature_list as the main instance so that
361 // variations::GetVariationParamValueByFeature below works.
362 base::test::ScopedFeatureList scoped_feature_list;
363 scoped_feature_list.InitWithFeatureList(std::move(feature_list));
364
365 // The params should have the values predefined in these variations
366 // (accessible via the names of the features).
367 EXPECT_EQ(kTestParamValue, variations::GetVariationParamValueByFeature(
368 kTestFeature1, kTestParam1));
369 EXPECT_EQ(kTestParamValue, variations::GetVariationParamValueByFeature(
370 kTestFeature2, kTestParam2));
371 // The params are registered in the same trial.
372 EXPECT_EQ(kTestParamValue,
373 variations::GetVariationParamValue(kTestTrial, kTestParam1));
374 EXPECT_EQ(kTestParamValue,
375 variations::GetVariationParamValue(kTestTrial, kTestParam2));
332 } 376 }
333 377
334 base::CommandLine::StringType CreateSwitch(const std::string& value) { 378 base::CommandLine::StringType CreateSwitch(const std::string& value) {
335 #if defined(OS_WIN) 379 #if defined(OS_WIN)
336 return base::ASCIIToUTF16(value); 380 return base::ASCIIToUTF16(value);
337 #else 381 #else
338 return value; 382 return value;
339 #endif 383 #endif
340 } 384 }
341 385
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 } 818 }
775 } 819 }
776 820
777 TEST_F(FlagsStateTest, GetFlagFeatureEntries) { 821 TEST_F(FlagsStateTest, GetFlagFeatureEntries) {
778 base::ListValue supported_entries; 822 base::ListValue supported_entries;
779 base::ListValue unsupported_entries; 823 base::ListValue unsupported_entries;
780 flags_state_->GetFlagFeatureEntries(&flags_storage_, kGeneralAccessFlagsOnly, 824 flags_state_->GetFlagFeatureEntries(&flags_storage_, kGeneralAccessFlagsOnly,
781 &supported_entries, &unsupported_entries, 825 &supported_entries, &unsupported_entries,
782 base::Bind(&SkipFeatureEntry)); 826 base::Bind(&SkipFeatureEntry));
783 // All |kEntries| except for |kFlags3| should be supported. 827 // All |kEntries| except for |kFlags3| should be supported.
784 EXPECT_EQ(7u, supported_entries.GetSize()); 828 EXPECT_EQ(9u, supported_entries.GetSize());
785 EXPECT_EQ(1u, unsupported_entries.GetSize()); 829 EXPECT_EQ(1u, unsupported_entries.GetSize());
786 EXPECT_EQ(arraysize(kEntries), 830 EXPECT_EQ(arraysize(kEntries),
787 supported_entries.GetSize() + unsupported_entries.GetSize()); 831 supported_entries.GetSize() + unsupported_entries.GetSize());
788 } 832 }
789 833
790 } // namespace flags_ui 834 } // namespace flags_ui
OLDNEW
« no previous file with comments | « components/flags_ui/flags_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698