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

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

Issue 2036193002: Allow overriding variation parameter via chrome://flags. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build deps #2 Created 4 years, 6 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') | components/flags_ui/resources/flags.html » ('j') | 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>
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/stl_util.h" 19 #include "base/stl_util.h"
19 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "build/build_config.h" 23 #include "build/build_config.h"
23 #include "components/flags_ui/feature_entry.h" 24 #include "components/flags_ui/feature_entry.h"
24 #include "components/flags_ui/flags_ui_pref_names.h" 25 #include "components/flags_ui/flags_ui_pref_names.h"
25 #include "components/flags_ui/flags_ui_switches.h" 26 #include "components/flags_ui/flags_ui_switches.h"
26 #include "components/flags_ui/pref_service_flags_storage.h" 27 #include "components/flags_ui/pref_service_flags_storage.h"
27 #include "components/prefs/pref_registry_simple.h" 28 #include "components/prefs/pref_registry_simple.h"
28 #include "components/prefs/testing_pref_service.h" 29 #include "components/prefs/testing_pref_service.h"
30 #include "components/variations/variations_associated_data.h"
29 #include "grit/components_strings.h" 31 #include "grit/components_strings.h"
30 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
31 33
32 namespace flags_ui { 34 namespace flags_ui {
33 35
34 namespace { 36 namespace {
35 37
36 const char kFlags1[] = "flag1"; 38 const char kFlags1[] = "flag1";
37 const char kFlags2[] = "flag2"; 39 const char kFlags2[] = "flag2";
38 const char kFlags3[] = "flag3"; 40 const char kFlags3[] = "flag3";
39 const char kFlags4[] = "flag4"; 41 const char kFlags4[] = "flag4";
40 const char kFlags5[] = "flag5"; 42 const char kFlags5[] = "flag5";
41 const char kFlags6[] = "flag6"; 43 const char kFlags6[] = "flag6";
42 const char kFlags7[] = "flag7"; 44 const char kFlags7[] = "flag7";
45 const char kFlags8[] = "flag8";
43 46
44 const char kSwitch1[] = "switch"; 47 const char kSwitch1[] = "switch";
45 const char kSwitch2[] = "switch2"; 48 const char kSwitch2[] = "switch2";
46 const char kSwitch3[] = "switch3"; 49 const char kSwitch3[] = "switch3";
47 const char kSwitch6[] = "switch6"; 50 const char kSwitch6[] = "switch6";
48 const char kValueForSwitch2[] = "value_for_switch2"; 51 const char kValueForSwitch2[] = "value_for_switch2";
49 52
50 const char kMultiSwitch1[] = "multi_switch1"; 53 const char kMultiSwitch1[] = "multi_switch1";
51 const char kMultiSwitch2[] = "multi_switch2"; 54 const char kMultiSwitch2[] = "multi_switch2";
52 const char kValueForMultiSwitch2[] = "value_for_multi_switch2"; 55 const char kValueForMultiSwitch2[] = "value_for_multi_switch2";
53 56
54 const char kEnableDisableValue1[] = "value1"; 57 const char kEnableDisableValue1[] = "value1";
55 const char kEnableDisableValue2[] = "value2"; 58 const char kEnableDisableValue2[] = "value2";
56 59
57 const char kEnableFeatures[] = "dummy-enable-features"; 60 const char kEnableFeatures[] = "dummy-enable-features";
58 const char kDisableFeatures[] = "dummy-disable-features"; 61 const char kDisableFeatures[] = "dummy-disable-features";
59 62
63 const char kTestTrial[] = "TestTrial";
64 const char kTestParam[] = "param";
65 const char kTestParamValue1[] = "value1";
66 const char kTestParamValue2[] = "value2";
67
68 const base::Feature kTestFeature1{"FeatureName1",
69 base::FEATURE_ENABLED_BY_DEFAULT};
70 const base::Feature kTestFeature2{"FeatureName2",
71 base::FEATURE_ENABLED_BY_DEFAULT};
72
73 const FeatureEntry::FeatureParam kTestVariationDefault[] = {
74 {kTestParam, kTestParamValue1}};
75
76 const FeatureEntry::FeatureParam kTestVariationOther[] = {
77 {kTestParam, kTestParamValue2}};
78
79 const FeatureEntry::FeatureVariation kTestVariations[] = {
80 {"", kTestVariationDefault, 1},
81 {"dummy description", kTestVariationOther, 1}};
82
60 // Those have to be valid ids for the translation system but the value are 83 // Those have to be valid ids for the translation system but the value are
61 // never used, so pick one at random from the current component. 84 // never used, so pick one at random from the current component.
62 const int kDummyNameId = IDS_FLAGS_UI_WARNING_HEADER; 85 const int kDummyNameId = IDS_FLAGS_UI_WARNING_HEADER;
63 const int kDummyDescriptionId = IDS_FLAGS_UI_WARNING_TEXT; 86 const int kDummyDescriptionId = IDS_FLAGS_UI_WARNING_TEXT;
64 87
65 bool SkipFeatureEntry(const FeatureEntry& feature_entry) { 88 bool SkipFeatureEntry(const FeatureEntry& feature_entry) {
66 return false; 89 return false;
67 } 90 }
68 91
69 } // namespace 92 } // namespace
70 93
71 const FeatureEntry::Choice kMultiChoices[] = { 94 const FeatureEntry::Choice kMultiChoices[] = {
72 {kDummyDescriptionId, "", ""}, 95 {kDummyDescriptionId, "", ""},
73 {kDummyDescriptionId, kMultiSwitch1, ""}, 96 {kDummyDescriptionId, kMultiSwitch1, ""},
74 {kDummyDescriptionId, kMultiSwitch2, kValueForMultiSwitch2}, 97 {kDummyDescriptionId, kMultiSwitch2, kValueForMultiSwitch2},
75 }; 98 };
76 99
77 const base::Feature kTestFeature{"FeatureName",
78 base::FEATURE_ENABLED_BY_DEFAULT};
79
80 // The entries that are set for these tests. The 3rd entry is not supported on 100 // The entries that are set for these tests. The 3rd entry is not supported on
81 // the current platform, all others are. 101 // the current platform, all others are.
82 static FeatureEntry kEntries[] = { 102 static FeatureEntry kEntries[] = {
83 {kFlags1, kDummyNameId, kDummyDescriptionId, 103 {kFlags1, kDummyNameId, kDummyDescriptionId,
84 0, // Ends up being mapped to the current platform. 104 0, // Ends up being mapped to the current platform.
85 FeatureEntry::SINGLE_VALUE, kSwitch1, "", nullptr, nullptr, nullptr, 105 FeatureEntry::SINGLE_VALUE, kSwitch1, "", nullptr, nullptr, nullptr, 0,
86 nullptr, 0}, 106 nullptr, nullptr, nullptr},
87 {kFlags2, kDummyNameId, kDummyDescriptionId, 107 {kFlags2, kDummyNameId, kDummyDescriptionId,
88 0, // Ends up being mapped to the current platform. 108 0, // Ends up being mapped to the current platform.
89 FeatureEntry::SINGLE_VALUE, kSwitch2, kValueForSwitch2, nullptr, nullptr, 109 FeatureEntry::SINGLE_VALUE, kSwitch2, kValueForSwitch2, nullptr, nullptr,
90 nullptr, nullptr, 0}, 110 nullptr, 0, nullptr, nullptr, nullptr},
91 {kFlags3, kDummyNameId, kDummyDescriptionId, 111 {kFlags3, kDummyNameId, kDummyDescriptionId,
92 0, // This ends up enabling for an OS other than the current. 112 0, // This ends up enabling for an OS other than the current.
93 FeatureEntry::SINGLE_VALUE, kSwitch3, "", nullptr, nullptr, nullptr, 113 FeatureEntry::SINGLE_VALUE, kSwitch3, "", nullptr, nullptr, nullptr, 0,
94 nullptr, 0}, 114 nullptr, nullptr, nullptr},
95 {kFlags4, kDummyNameId, kDummyDescriptionId, 115 {kFlags4, kDummyNameId, kDummyDescriptionId,
96 0, // Ends up being mapped to the current platform. 116 0, // Ends up being mapped to the current platform.
97 FeatureEntry::MULTI_VALUE, "", "", "", "", nullptr, kMultiChoices, 117 FeatureEntry::MULTI_VALUE, "", "", "", "", nullptr,
98 arraysize(kMultiChoices)}, 118 arraysize(kMultiChoices), kMultiChoices, nullptr, nullptr},
99 {kFlags5, kDummyNameId, kDummyDescriptionId, 119 {kFlags5, kDummyNameId, kDummyDescriptionId,
100 0, // Ends up being mapped to the current platform. 120 0, // Ends up being mapped to the current platform.
101 FeatureEntry::ENABLE_DISABLE_VALUE, kSwitch1, kEnableDisableValue1, 121 FeatureEntry::ENABLE_DISABLE_VALUE, kSwitch1, kEnableDisableValue1,
102 kSwitch2, kEnableDisableValue2, nullptr, nullptr, 3}, 122 kSwitch2, kEnableDisableValue2, nullptr, 3, nullptr, nullptr, nullptr},
103 {kFlags6, kDummyNameId, kDummyDescriptionId, 0, 123 {kFlags6, kDummyNameId, kDummyDescriptionId, 0,
104 FeatureEntry::SINGLE_DISABLE_VALUE, kSwitch6, "", nullptr, nullptr, 124 FeatureEntry::SINGLE_DISABLE_VALUE, kSwitch6, "", nullptr, nullptr,
105 nullptr, nullptr, 0}, 125 nullptr, 0, nullptr, nullptr, nullptr},
106 {kFlags7, kDummyNameId, kDummyDescriptionId, 126 {kFlags7, kDummyNameId, kDummyDescriptionId,
107 0, // Ends up being mapped to the current platform. 127 0, // Ends up being mapped to the current platform.
108 FeatureEntry::FEATURE_VALUE, nullptr, nullptr, nullptr, nullptr, 128 FeatureEntry::FEATURE_VALUE, nullptr, nullptr, nullptr, nullptr,
109 &kTestFeature, nullptr, 3}, 129 &kTestFeature1, 3, nullptr, nullptr, nullptr},
130 {kFlags8, kDummyNameId, kDummyDescriptionId,
131 0, // Ends up being mapped to the current platform.
132 FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE, nullptr, nullptr, nullptr,
133 nullptr, &kTestFeature2, 4, nullptr, kTestVariations, kTestTrial},
110 }; 134 };
111 135
112 class FlagsStateTest : public ::testing::Test { 136 class FlagsStateTest : public ::testing::Test {
113 protected: 137 protected:
114 FlagsStateTest() : flags_storage_(&prefs_) { 138 FlagsStateTest() : flags_storage_(&prefs_), trial_list_(nullptr) {
115 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments); 139 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments);
116 140
117 for (size_t i = 0; i < arraysize(kEntries); ++i) 141 for (size_t i = 0; i < arraysize(kEntries); ++i)
118 kEntries[i].supported_platforms = FlagsState::GetCurrentPlatform(); 142 kEntries[i].supported_platforms = FlagsState::GetCurrentPlatform();
119 143
120 int os_other_than_current = 1; 144 int os_other_than_current = 1;
121 while (os_other_than_current == FlagsState::GetCurrentPlatform()) 145 while (os_other_than_current == FlagsState::GetCurrentPlatform())
122 os_other_than_current <<= 1; 146 os_other_than_current <<= 1;
123 kEntries[2].supported_platforms = os_other_than_current; 147 kEntries[2].supported_platforms = os_other_than_current;
124 flags_state_.reset(new FlagsState(kEntries, arraysize(kEntries))); 148 flags_state_.reset(new FlagsState(kEntries, arraysize(kEntries)));
125 } 149 }
126 150
127 TestingPrefServiceSimple prefs_; 151 TestingPrefServiceSimple prefs_;
128 PrefServiceFlagsStorage flags_storage_; 152 PrefServiceFlagsStorage flags_storage_;
129 std::unique_ptr<FlagsState> flags_state_; 153 std::unique_ptr<FlagsState> flags_state_;
154 base::FieldTrialList trial_list_;
130 }; 155 };
131 156
132 TEST_F(FlagsStateTest, NoChangeNoRestart) { 157 TEST_F(FlagsStateTest, NoChangeNoRestart) {
133 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges()); 158 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges());
134 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, false); 159 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, false);
135 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges()); 160 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges());
136 161
137 // kFlags6 is enabled by default, so enabling should not require a restart. 162 // kFlags6 is enabled by default, so enabling should not require a restart.
138 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags6, true); 163 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags6, true);
139 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges()); 164 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges());
(...skipping 10 matching lines...) Expand all
150 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges()); 175 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges());
151 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags6, false); 176 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags6, false);
152 EXPECT_TRUE(flags_state_->IsRestartNeededToCommitChanges()); 177 EXPECT_TRUE(flags_state_->IsRestartNeededToCommitChanges());
153 } 178 }
154 179
155 TEST_F(FlagsStateTest, MultiFlagChangeNeedsRestart) { 180 TEST_F(FlagsStateTest, MultiFlagChangeNeedsRestart) {
156 const FeatureEntry& entry = kEntries[3]; 181 const FeatureEntry& entry = kEntries[3];
157 ASSERT_EQ(kFlags4, entry.internal_name); 182 ASSERT_EQ(kFlags4, entry.internal_name);
158 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges()); 183 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges());
159 // Enable the 2nd choice of the multi-value. 184 // Enable the 2nd choice of the multi-value.
160 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForChoice(2), 185 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2),
161 true); 186 true);
162 EXPECT_TRUE(flags_state_->IsRestartNeededToCommitChanges()); 187 EXPECT_TRUE(flags_state_->IsRestartNeededToCommitChanges());
163 flags_state_->Reset(); 188 flags_state_->Reset();
164 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges()); 189 EXPECT_FALSE(flags_state_->IsRestartNeededToCommitChanges());
165 // Enable the default choice now. 190 // Enable the default choice now.
166 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForChoice(0), 191 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0),
167 true); 192 true);
168 EXPECT_TRUE(flags_state_->IsRestartNeededToCommitChanges()); 193 EXPECT_TRUE(flags_state_->IsRestartNeededToCommitChanges());
169 } 194 }
170 195
171 TEST_F(FlagsStateTest, AddTwoFlagsRemoveOne) { 196 TEST_F(FlagsStateTest, AddTwoFlagsRemoveOne) {
172 // Add two entries, check they're there. 197 // Add two entries, check they're there.
173 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true); 198 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true);
174 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags2, true); 199 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags2, true);
175 200
176 const base::ListValue* entries_list = 201 const base::ListValue* entries_list =
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 259
235 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line2, 260 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line2,
236 kNoSentinels, kEnableFeatures, 261 kNoSentinels, kEnableFeatures,
237 kDisableFeatures); 262 kDisableFeatures);
238 263
239 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); 264 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1));
240 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); 265 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin));
241 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); 266 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd));
242 } 267 }
243 268
269 TEST_F(FlagsStateTest, RegisterAllFeatureVariationParameters) {
270 const FeatureEntry& entry = kEntries[7];
271 // Select the "Disabled" variation.
272 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0),
273 true);
274 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_);
275 // No value should be associated.
276 EXPECT_EQ("", variations::GetVariationParamValue(kTestTrial, kTestParam));
277 // The trial should not be created.
278 base::FieldTrial* trial = base::FieldTrialList::Find(kTestTrial);
279 EXPECT_EQ(nullptr, trial);
280
281 // Select the first "Enabled" variation.
282 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1),
283 true);
284
285 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_);
286 // The value should be associated.
287 EXPECT_EQ(kTestParamValue1,
288 variations::GetVariationParamValue(kTestTrial, kTestParam));
289
290 // The trial should be created.
291 trial = base::FieldTrialList::Find(kTestTrial);
292 EXPECT_NE(nullptr, trial);
293 // The about:flags group should be selected for the trial.
294 EXPECT_EQ(internal::kTrialGroupAboutFlags, trial->group_name());
295
296 // Select the second "Enabled" variation.
297 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2),
298 true);
299 flags_state_->RegisterAllFeatureVariationParameters(&flags_storage_);
300 // Associating for the second time should not change the value.
301 EXPECT_EQ(kTestParamValue1,
302 variations::GetVariationParamValue(kTestTrial, kTestParam));
303 }
304
244 base::CommandLine::StringType CreateSwitch(const std::string& value) { 305 base::CommandLine::StringType CreateSwitch(const std::string& value) {
245 #if defined(OS_WIN) 306 #if defined(OS_WIN)
246 return base::ASCIIToUTF16(value); 307 return base::ASCIIToUTF16(value);
247 #else 308 #else
248 return value; 309 return value;
249 #endif 310 #endif
250 } 311 }
251 312
252 TEST_F(FlagsStateTest, CompareSwitchesToCurrentCommandLine) { 313 TEST_F(FlagsStateTest, CompareSwitchesToCurrentCommandLine) {
253 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true); 314 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 int enabled_choice; // 0: default, 1: enabled, 2: disabled. 403 int enabled_choice; // 0: default, 1: enabled, 2: disabled.
343 const char* existing_enable_features; 404 const char* existing_enable_features;
344 const char* existing_disable_features; 405 const char* existing_disable_features;
345 const char* expected_enable_features; 406 const char* expected_enable_features;
346 const char* expected_disable_features; 407 const char* expected_disable_features;
347 } cases[] = { 408 } cases[] = {
348 // Default value: Should not affect existing flags. 409 // Default value: Should not affect existing flags.
349 {0, nullptr, nullptr, nullptr, nullptr}, 410 {0, nullptr, nullptr, nullptr, nullptr},
350 {0, "A,B", "C", "A,B", "C"}, 411 {0, "A,B", "C", "A,B", "C"},
351 // "Enable" option: should only affect enabled list. 412 // "Enable" option: should only affect enabled list.
352 {1, nullptr, nullptr, "FeatureName", nullptr}, 413 {1, nullptr, nullptr, "FeatureName1", nullptr},
353 {1, "A,B", "C", "A,B,FeatureName", "C"}, 414 {1, "A,B", "C", "A,B,FeatureName1", "C"},
354 // "Disable" option: should only affect disabled list. 415 // "Disable" option: should only affect disabled list.
355 {2, nullptr, nullptr, nullptr, "FeatureName"}, 416 {2, nullptr, nullptr, nullptr, "FeatureName1"},
356 {2, "A,B", "C", "A,B", "C,FeatureName"}, 417 {2, "A,B", "C", "A,B", "C,FeatureName1"},
357 }; 418 };
358 419
359 for (size_t i = 0; i < arraysize(cases); ++i) { 420 for (size_t i = 0; i < arraysize(cases); ++i) {
360 SCOPED_TRACE(base::StringPrintf( 421 SCOPED_TRACE(base::StringPrintf(
361 "Test[%" PRIuS "]: %d [%s] [%s]", i, cases[i].enabled_choice, 422 "Test[%" PRIuS "]: %d [%s] [%s]", i, cases[i].enabled_choice,
362 cases[i].existing_enable_features ? cases[i].existing_enable_features 423 cases[i].existing_enable_features ? cases[i].existing_enable_features
363 : "null", 424 : "null",
364 cases[i].existing_disable_features ? cases[i].existing_disable_features 425 cases[i].existing_disable_features ? cases[i].existing_disable_features
365 : "null")); 426 : "null"));
366 427
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 { 569 {
509 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 570 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
510 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 571 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
511 kAddSentinels, kEnableFeatures, 572 kAddSentinels, kEnableFeatures,
512 kDisableFeatures); 573 kDisableFeatures);
513 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); 574 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
514 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); 575 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
515 } 576 }
516 577
517 // Enable the 2nd choice of the multi-value. 578 // Enable the 2nd choice of the multi-value.
518 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForChoice(2), 579 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2),
519 true); 580 true);
520 { 581 {
521 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 582 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
522 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 583 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
523 kAddSentinels, kEnableFeatures, 584 kAddSentinels, kEnableFeatures,
524 kDisableFeatures); 585 kDisableFeatures);
525 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); 586 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
526 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2)); 587 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2));
527 EXPECT_EQ(std::string(kValueForMultiSwitch2), 588 EXPECT_EQ(std::string(kValueForMultiSwitch2),
528 command_line.GetSwitchValueASCII(kMultiSwitch2)); 589 command_line.GetSwitchValueASCII(kMultiSwitch2));
529 } 590 }
530 591
531 // Disable the multi-value entry. 592 // Disable the multi-value entry.
532 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForChoice(0), 593 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0),
533 true); 594 true);
534 { 595 {
535 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 596 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
536 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 597 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
537 kAddSentinels, kEnableFeatures, 598 kAddSentinels, kEnableFeatures,
538 kDisableFeatures); 599 kDisableFeatures);
539 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); 600 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
540 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); 601 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
541 } 602 }
542 } 603 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 { 642 {
582 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 643 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
583 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 644 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
584 kAddSentinels, kEnableFeatures, 645 kAddSentinels, kEnableFeatures,
585 kDisableFeatures); 646 kDisableFeatures);
586 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); 647 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
587 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); 648 EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
588 } 649 }
589 650
590 // "Enable" option selected. 651 // "Enable" option selected.
591 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForChoice(1), 652 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(1),
592 true); 653 true);
593 { 654 {
594 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 655 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
595 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 656 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
596 kAddSentinels, kEnableFeatures, 657 kAddSentinels, kEnableFeatures,
597 kDisableFeatures); 658 kDisableFeatures);
598 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); 659 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
599 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); 660 EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
600 EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1)); 661 EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1));
601 } 662 }
602 663
603 // "Disable" option selected. 664 // "Disable" option selected.
604 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForChoice(2), 665 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(2),
605 true); 666 true);
606 { 667 {
607 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 668 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
608 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 669 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
609 kAddSentinels, kEnableFeatures, 670 kAddSentinels, kEnableFeatures,
610 kDisableFeatures); 671 kDisableFeatures);
611 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); 672 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
612 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); 673 EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
613 EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2)); 674 EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2));
614 } 675 }
615 676
616 // "Default" option selected, same as nothing selected. 677 // "Default" option selected, same as nothing selected.
617 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForChoice(0), 678 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry.NameForOption(0),
618 true); 679 true);
619 { 680 {
620 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 681 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
621 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 682 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
622 kAddSentinels, kEnableFeatures, 683 kAddSentinels, kEnableFeatures,
623 kDisableFeatures); 684 kDisableFeatures);
624 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); 685 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
625 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); 686 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
626 } 687 }
627 } 688 }
628 689
629 TEST_F(FlagsStateTest, FeatureValues) { 690 TEST_F(FlagsStateTest, FeatureValues) {
630 const FeatureEntry& entry = kEntries[6]; 691 const FeatureEntry& entry = kEntries[6];
631 ASSERT_EQ(kFlags7, entry.internal_name); 692 ASSERT_EQ(kFlags7, entry.internal_name);
632 693
633 struct { 694 struct {
634 int enabled_choice; 695 int enabled_choice;
635 const char* existing_enable_features; 696 const char* existing_enable_features;
636 const char* existing_disable_features; 697 const char* existing_disable_features;
637 const char* expected_enable_features; 698 const char* expected_enable_features;
638 const char* expected_disable_features; 699 const char* expected_disable_features;
639 } cases[] = { 700 } cases[] = {
640 // Nothing selected. 701 // Nothing selected.
641 {-1, nullptr, nullptr, "", ""}, 702 {-1, nullptr, nullptr, "", ""},
642 // "Default" option selected, same as nothing selected. 703 // "Default" option selected, same as nothing selected.
643 {0, nullptr, nullptr, "", ""}, 704 {0, nullptr, nullptr, "", ""},
644 // "Enable" option selected. 705 // "Enable" option selected.
645 {1, nullptr, nullptr, "FeatureName", ""}, 706 {1, nullptr, nullptr, "FeatureName1", ""},
646 // "Disable" option selected. 707 // "Disable" option selected.
647 {2, nullptr, nullptr, "", "FeatureName"}, 708 {2, nullptr, nullptr, "", "FeatureName1"},
648 // "Enable" option should get added to the existing list. 709 // "Enable" option should get added to the existing list.
649 {1, "Foo,Bar", nullptr, "Foo,Bar,FeatureName", ""}, 710 {1, "Foo,Bar", nullptr, "Foo,Bar,FeatureName1", ""},
650 // "Disable" option should get added to the existing list. 711 // "Disable" option should get added to the existing list.
651 {2, nullptr, "Foo,Bar", "", "Foo,Bar,FeatureName"}, 712 {2, nullptr, "Foo,Bar", "", "Foo,Bar,FeatureName1"},
652 }; 713 };
653 714
654 for (size_t i = 0; i < arraysize(cases); ++i) { 715 for (size_t i = 0; i < arraysize(cases); ++i) {
655 SCOPED_TRACE(base::StringPrintf( 716 SCOPED_TRACE(base::StringPrintf(
656 "Test[%" PRIuS "]: %d [%s] [%s]", i, cases[i].enabled_choice, 717 "Test[%" PRIuS "]: %d [%s] [%s]", i, cases[i].enabled_choice,
657 cases[i].existing_enable_features ? cases[i].existing_enable_features 718 cases[i].existing_enable_features ? cases[i].existing_enable_features
658 : "null", 719 : "null",
659 cases[i].existing_disable_features ? cases[i].existing_disable_features 720 cases[i].existing_disable_features ? cases[i].existing_disable_features
660 : "null")); 721 : "null"));
661 722
662 if (cases[i].enabled_choice != -1) { 723 if (cases[i].enabled_choice != -1) {
663 flags_state_->SetFeatureEntryEnabled( 724 flags_state_->SetFeatureEntryEnabled(
664 &flags_storage_, entry.NameForChoice(cases[i].enabled_choice), true); 725 &flags_storage_, entry.NameForOption(cases[i].enabled_choice), true);
665 } 726 }
666 727
667 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 728 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
668 if (cases[i].existing_enable_features) { 729 if (cases[i].existing_enable_features) {
669 command_line.AppendSwitchASCII(kEnableFeatures, 730 command_line.AppendSwitchASCII(kEnableFeatures,
670 cases[i].existing_enable_features); 731 cases[i].existing_enable_features);
671 } 732 }
672 if (cases[i].existing_disable_features) { 733 if (cases[i].existing_disable_features) {
673 command_line.AppendSwitchASCII(kDisableFeatures, 734 command_line.AppendSwitchASCII(kDisableFeatures,
674 cases[i].existing_disable_features); 735 cases[i].existing_disable_features);
675 } 736 }
676 737
677 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 738 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
678 kAddSentinels, kEnableFeatures, 739 kAddSentinels, kEnableFeatures,
679 kDisableFeatures); 740 kDisableFeatures);
680 EXPECT_EQ(cases[i].expected_enable_features, 741 EXPECT_EQ(cases[i].expected_enable_features,
681 command_line.GetSwitchValueASCII(kEnableFeatures)); 742 command_line.GetSwitchValueASCII(kEnableFeatures));
682 EXPECT_EQ(cases[i].expected_disable_features, 743 EXPECT_EQ(cases[i].expected_disable_features,
683 command_line.GetSwitchValueASCII(kDisableFeatures)); 744 command_line.GetSwitchValueASCII(kDisableFeatures));
684 } 745 }
685 } 746 }
686 747
687 TEST_F(FlagsStateTest, GetFlagFeatureEntries) { 748 TEST_F(FlagsStateTest, GetFlagFeatureEntries) {
688 base::ListValue supported_entries; 749 base::ListValue supported_entries;
689 base::ListValue unsupported_entries; 750 base::ListValue unsupported_entries;
690 flags_state_->GetFlagFeatureEntries(&flags_storage_, kGeneralAccessFlagsOnly, 751 flags_state_->GetFlagFeatureEntries(&flags_storage_, kGeneralAccessFlagsOnly,
691 &supported_entries, &unsupported_entries, 752 &supported_entries, &unsupported_entries,
692 base::Bind(&SkipFeatureEntry)); 753 base::Bind(&SkipFeatureEntry));
693 // All |kEntries| except for |kFlags3| should be supported. 754 // All |kEntries| except for |kFlags3| should be supported.
694 EXPECT_EQ(6u, supported_entries.GetSize()); 755 EXPECT_EQ(7u, supported_entries.GetSize());
695 EXPECT_EQ(1u, unsupported_entries.GetSize()); 756 EXPECT_EQ(1u, unsupported_entries.GetSize());
696 EXPECT_EQ(arraysize(kEntries), 757 EXPECT_EQ(arraysize(kEntries),
697 supported_entries.GetSize() + unsupported_entries.GetSize()); 758 supported_entries.GetSize() + unsupported_entries.GetSize());
698 } 759 }
699 760
700 } // namespace flags_ui 761 } // namespace flags_ui
OLDNEW
« no previous file with comments | « components/flags_ui/flags_state.cc ('k') | components/flags_ui/resources/flags.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698