[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 5 | #include "base/prefs/pref_registry_simple.h" |
[email protected] | e5ba874f | 2013-02-14 17:20:19 | [diff] [blame] | 6 | #include "base/prefs/testing_pref_service.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 7 | #include "base/strings/string_number_conversions.h" |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 8 | #include "base/utf_string_conversions.h" |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 9 | #include "base/values.h" |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 10 | #include "chrome/browser/about_flags.h" |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 11 | #include "chrome/common/chrome_switches.h" |
| 12 | #include "chrome/common/pref_names.h" |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 13 | #include "grit/chromium_strings.h" |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 16 | const char kFlags1[] = "flag1"; |
| 17 | const char kFlags2[] = "flag2"; |
| 18 | const char kFlags3[] = "flag3"; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 19 | const char kFlags4[] = "flag4"; |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 20 | const char kFlags5[] = "flag5"; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 21 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 22 | const char kSwitch1[] = "switch"; |
| 23 | const char kSwitch2[] = "switch2"; |
| 24 | const char kSwitch3[] = "switch3"; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 25 | const char kValueForSwitch2[] = "value_for_switch2"; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 26 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 27 | const char kMultiSwitch1[] = "multi_switch1"; |
| 28 | const char kMultiSwitch2[] = "multi_switch2"; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 29 | const char kValueForMultiSwitch2[] = "value_for_multi_switch2"; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 30 | |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 31 | const char kEnableDisableValue1[] = "value1"; |
| 32 | const char kEnableDisableValue2[] = "value2"; |
| 33 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 34 | namespace about_flags { |
| 35 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 36 | const Experiment::Choice kMultiChoices[] = { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 37 | { IDS_PRODUCT_NAME, "", "" }, |
| 38 | { IDS_PRODUCT_NAME, kMultiSwitch1, "" }, |
| 39 | { IDS_PRODUCT_NAME, kMultiSwitch2, kValueForMultiSwitch2 }, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | // The experiments that are set for these tests. The 3rd experiment is not |
| 43 | // supported on the current platform, all others are. |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 44 | static Experiment kExperiments[] = { |
| 45 | { |
| 46 | kFlags1, |
| 47 | IDS_PRODUCT_NAME, |
| 48 | IDS_PRODUCT_NAME, |
| 49 | 0, // Ends up being mapped to the current platform. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 50 | Experiment::SINGLE_VALUE, |
| 51 | kSwitch1, |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 52 | "", |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 53 | NULL, |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 54 | NULL, |
| 55 | NULL, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 56 | 0 |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 57 | }, |
| 58 | { |
| 59 | kFlags2, |
| 60 | IDS_PRODUCT_NAME, |
| 61 | IDS_PRODUCT_NAME, |
| 62 | 0, // Ends up being mapped to the current platform. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 63 | Experiment::SINGLE_VALUE, |
| 64 | kSwitch2, |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 65 | kValueForSwitch2, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 66 | NULL, |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 67 | NULL, |
| 68 | NULL, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 69 | 0 |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 70 | }, |
| 71 | { |
| 72 | kFlags3, |
| 73 | IDS_PRODUCT_NAME, |
| 74 | IDS_PRODUCT_NAME, |
| 75 | 0, // This ends up enabling for an OS other than the current. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 76 | Experiment::SINGLE_VALUE, |
| 77 | kSwitch3, |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 78 | "", |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 79 | NULL, |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 80 | NULL, |
| 81 | NULL, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 82 | 0 |
| 83 | }, |
| 84 | { |
| 85 | kFlags4, |
| 86 | IDS_PRODUCT_NAME, |
| 87 | IDS_PRODUCT_NAME, |
| 88 | 0, // Ends up being mapped to the current platform. |
| 89 | Experiment::MULTI_VALUE, |
| 90 | "", |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 91 | "", |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 92 | "", |
| 93 | "", |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 94 | kMultiChoices, |
| 95 | arraysize(kMultiChoices) |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 96 | }, |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 97 | { |
| 98 | kFlags5, |
| 99 | IDS_PRODUCT_NAME, |
| 100 | IDS_PRODUCT_NAME, |
| 101 | 0, // Ends up being mapped to the current platform. |
| 102 | Experiment::ENABLE_DISABLE_VALUE, |
| 103 | kSwitch1, |
| 104 | kEnableDisableValue1, |
| 105 | kSwitch2, |
| 106 | kEnableDisableValue2, |
| 107 | NULL, |
| 108 | 3 |
| 109 | }, |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 112 | class AboutFlagsTest : public ::testing::Test { |
| 113 | protected: |
| 114 | AboutFlagsTest() { |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 115 | prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 116 | testing::ClearState(); |
| 117 | } |
| 118 | |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 119 | virtual void SetUp() OVERRIDE { |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 120 | for (size_t i = 0; i < arraysize(kExperiments); ++i) |
| 121 | kExperiments[i].supported_platforms = GetCurrentPlatform(); |
| 122 | |
| 123 | int os_other_than_current = 1; |
| 124 | while (os_other_than_current == GetCurrentPlatform()) |
| 125 | os_other_than_current <<= 1; |
| 126 | kExperiments[2].supported_platforms = os_other_than_current; |
| 127 | |
| 128 | testing::SetExperiments(kExperiments, arraysize(kExperiments)); |
| 129 | } |
| 130 | |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 131 | virtual void TearDown() OVERRIDE { |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 132 | testing::SetExperiments(NULL, 0); |
| 133 | } |
| 134 | |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 135 | TestingPrefServiceSimple prefs_; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | TEST_F(AboutFlagsTest, ChangeNeedsRestart) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 139 | EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
| 140 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 141 | EXPECT_TRUE(IsRestartNeededToCommitChanges()); |
| 142 | } |
| 143 | |
| 144 | TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 145 | // Add two experiments, check they're there. |
| 146 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 147 | SetExperimentEnabled(&prefs_, kFlags2, true); |
| 148 | |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 149 | const ListValue* experiments_list = prefs_.GetList( |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 150 | prefs::kEnabledLabsExperiments); |
| 151 | ASSERT_TRUE(experiments_list != NULL); |
| 152 | |
| 153 | ASSERT_EQ(2u, experiments_list->GetSize()); |
| 154 | |
| 155 | std::string s0; |
| 156 | ASSERT_TRUE(experiments_list->GetString(0, &s0)); |
| 157 | std::string s1; |
| 158 | ASSERT_TRUE(experiments_list->GetString(1, &s1)); |
| 159 | |
| 160 | EXPECT_TRUE(s0 == kFlags1 || s1 == kFlags1); |
| 161 | EXPECT_TRUE(s0 == kFlags2 || s1 == kFlags2); |
| 162 | |
| 163 | // Remove one experiment, check the other's still around. |
| 164 | SetExperimentEnabled(&prefs_, kFlags2, false); |
| 165 | |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 166 | experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 167 | ASSERT_TRUE(experiments_list != NULL); |
| 168 | ASSERT_EQ(1u, experiments_list->GetSize()); |
| 169 | ASSERT_TRUE(experiments_list->GetString(0, &s0)); |
| 170 | EXPECT_TRUE(s0 == kFlags1); |
| 171 | } |
| 172 | |
| 173 | TEST_F(AboutFlagsTest, AddTwoFlagsRemoveBoth) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 174 | // Add two experiments, check the pref exists. |
| 175 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 176 | SetExperimentEnabled(&prefs_, kFlags2, true); |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 177 | const ListValue* experiments_list = prefs_.GetList( |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 178 | prefs::kEnabledLabsExperiments); |
| 179 | ASSERT_TRUE(experiments_list != NULL); |
| 180 | |
| 181 | // Remove both, the pref should have been removed completely. |
| 182 | SetExperimentEnabled(&prefs_, kFlags1, false); |
| 183 | SetExperimentEnabled(&prefs_, kFlags2, false); |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 184 | experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 185 | EXPECT_TRUE(experiments_list == NULL || experiments_list->GetSize() == 0); |
| 186 | } |
| 187 | |
| 188 | TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 189 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 190 | |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 191 | CommandLine command_line(CommandLine::NO_PROGRAM); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 192 | command_line.AppendSwitch("foo"); |
| 193 | |
| 194 | EXPECT_TRUE(command_line.HasSwitch("foo")); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 195 | EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 196 | |
| 197 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 198 | |
| 199 | EXPECT_TRUE(command_line.HasSwitch("foo")); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame] | 200 | EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | TEST_F(AboutFlagsTest, RemoveFlagSwitches) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 204 | std::map<std::string, CommandLine::StringType> switch_list; |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 205 | switch_list[kSwitch1] = CommandLine::StringType(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 206 | switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); |
| 207 | switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); |
| 208 | switch_list["foo"] = CommandLine::StringType(); |
| 209 | |
| 210 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 211 | |
| 212 | // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called. |
| 213 | RemoveFlagsSwitches(&switch_list); |
| 214 | ASSERT_EQ(4u, switch_list.size()); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 215 | EXPECT_TRUE(switch_list.find(kSwitch1) != switch_list.end()); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 216 | EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesBegin) != |
| 217 | switch_list.end()); |
| 218 | EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesEnd) != |
| 219 | switch_list.end()); |
| 220 | EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); |
| 221 | |
| 222 | // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again. |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 223 | CommandLine command_line(CommandLine::NO_PROGRAM); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 224 | command_line.AppendSwitch("foo"); |
| 225 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 226 | RemoveFlagsSwitches(&switch_list); |
| 227 | |
| 228 | // Now the about:flags-related switch should have been removed. |
| 229 | ASSERT_EQ(1u, switch_list.size()); |
| 230 | EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); |
| 231 | } |
| 232 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 233 | // Tests enabling experiments that aren't supported on the current platform. |
| 234 | TEST_F(AboutFlagsTest, PersistAndPrune) { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 235 | // Enable experiments 1 and 3. |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 236 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 237 | SetExperimentEnabled(&prefs_, kFlags3, true); |
| 238 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 239 | EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 240 | EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
| 241 | |
| 242 | // Convert the flags to switches. Experiment 3 shouldn't be among the switches |
| 243 | // as it is not applicable to the current platform. |
| 244 | ConvertFlagsToSwitches(&prefs_, &command_line); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame] | 245 | EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 246 | EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
| 247 | |
| 248 | // Experiment 3 should show still be persisted in preferences though. |
| 249 | scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
| 250 | ASSERT_TRUE(switch_prefs.get()); |
[email protected] | cc3e205 | 2011-12-20 01:01:40 | [diff] [blame] | 251 | EXPECT_EQ(arraysize(kExperiments), switch_prefs->GetSize()); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 252 | } |
| 253 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 254 | // Tests that switches which should have values get them in the command |
| 255 | // line. |
| 256 | TEST_F(AboutFlagsTest, CheckValues) { |
| 257 | // Enable experiments 1 and 2. |
| 258 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 259 | SetExperimentEnabled(&prefs_, kFlags2, true); |
| 260 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 261 | EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 262 | EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 263 | |
| 264 | // Convert the flags to switches. |
| 265 | ConvertFlagsToSwitches(&prefs_, &command_line); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame] | 266 | EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 267 | EXPECT_EQ(std::string(""), command_line.GetSwitchValueASCII(kSwitch1)); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame] | 268 | EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); |
| 269 | EXPECT_EQ(std::string(kValueForSwitch2), |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 270 | command_line.GetSwitchValueASCII(kSwitch2)); |
| 271 | |
| 272 | // Confirm that there is no '=' in the command line for simple switches. |
| 273 | std::string switch1_with_equals = std::string("--") + |
| 274 | std::string(kSwitch1) + |
| 275 | std::string("="); |
| 276 | #if defined(OS_WIN) |
| 277 | EXPECT_EQ(std::wstring::npos, |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 278 | command_line.GetCommandLineString().find( |
[email protected] | 47e870b | 2013-02-24 21:14:53 | [diff] [blame] | 279 | ASCIIToWide(switch1_with_equals))); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 280 | #else |
| 281 | EXPECT_EQ(std::string::npos, |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 282 | command_line.GetCommandLineString().find(switch1_with_equals)); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 283 | #endif |
| 284 | |
| 285 | // And confirm there is a '=' for switches with values. |
| 286 | std::string switch2_with_equals = std::string("--") + |
| 287 | std::string(kSwitch2) + |
| 288 | std::string("="); |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 289 | #if defined(OS_WIN) |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame] | 290 | EXPECT_NE(std::wstring::npos, |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 291 | command_line.GetCommandLineString().find( |
[email protected] | 47e870b | 2013-02-24 21:14:53 | [diff] [blame] | 292 | ASCIIToWide(switch2_with_equals))); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 293 | #else |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame] | 294 | EXPECT_NE(std::string::npos, |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 295 | command_line.GetCommandLineString().find(switch2_with_equals)); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 296 | #endif |
| 297 | |
| 298 | // And it should persist |
| 299 | scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
| 300 | ASSERT_TRUE(switch_prefs.get()); |
[email protected] | cc3e205 | 2011-12-20 01:01:40 | [diff] [blame] | 301 | EXPECT_EQ(arraysize(kExperiments), switch_prefs->GetSize()); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 304 | // Tests multi-value type experiments. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 305 | TEST_F(AboutFlagsTest, MultiValues) { |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 306 | const Experiment& experiment = kExperiments[3]; |
| 307 | ASSERT_EQ(kFlags4, experiment.internal_name); |
| 308 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 309 | // Initially, the first "deactivated" option of the multi experiment should |
| 310 | // be set. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 311 | { |
| 312 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 313 | ConvertFlagsToSwitches(&prefs_, &command_line); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 314 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 315 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 316 | } |
| 317 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 318 | // Enable the 2nd choice of the multi-value. |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 319 | SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 320 | { |
| 321 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 322 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 323 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame] | 324 | EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2)); |
| 325 | EXPECT_EQ(std::string(kValueForMultiSwitch2), |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 326 | command_line.GetSwitchValueASCII(kMultiSwitch2)); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | // Disable the multi-value experiment. |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame^] | 330 | SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true); |
| 331 | { |
| 332 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 333 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 334 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 335 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | TEST_F(AboutFlagsTest, EnableDisableValues) { |
| 340 | const Experiment& experiment = kExperiments[4]; |
| 341 | ASSERT_EQ(kFlags5, experiment.internal_name); |
| 342 | |
| 343 | // Nothing selected. |
| 344 | { |
| 345 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 346 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 347 | EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 348 | EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 349 | } |
| 350 | |
| 351 | // "Enable" option selected. |
| 352 | SetExperimentEnabled(&prefs_, experiment.NameForChoice(1), true); |
| 353 | { |
| 354 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 355 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 356 | EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
| 357 | EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 358 | EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1)); |
| 359 | } |
| 360 | |
| 361 | // "Disable" option selected. |
| 362 | SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true); |
| 363 | { |
| 364 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 365 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 366 | EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 367 | EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); |
| 368 | EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2)); |
| 369 | } |
| 370 | |
| 371 | // "Default" option selected, same as nothing selected. |
| 372 | SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 373 | { |
| 374 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 375 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 376 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 377 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | // Makes sure there are no separators in any of the experiment names. |
| 382 | TEST_F(AboutFlagsTest, NoSeparators) { |
| 383 | testing::SetExperiments(NULL, 0); |
| 384 | size_t count; |
| 385 | const Experiment* experiments = testing::GetExperiments(&count); |
| 386 | for (size_t i = 0; i < count; ++i) { |
| 387 | std::string name = experiments->internal_name; |
| 388 | EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; |
| 389 | } |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 390 | } |
| 391 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 392 | } // namespace about_flags |