Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/command_line.h" | |
| 6 #include "build/build_config.h" | |
| 7 #include "chrome/browser/browser_process.h" | |
| 8 #include "chrome/common/chrome_switches.h" | |
| 9 #include "chrome/common/pref_names.h" | |
| 10 #include "chrome/test/base/in_process_browser_test.h" | |
| 11 #include "chrome/test/base/testing_browser_process.h" | |
| 12 #include "components/prefs/scoped_user_pref_update.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 static const char kNewPublicKey[] = "new public key"; | |
| 18 | |
| 19 static const std::vector<std::string> kOneDisabledFeatureList = {"A"}; | |
| 20 static const std::vector<std::string> kTwoDisabledFeaturesList = {"A", "B"}; | |
| 21 static const std::vector<std::string> kThreeDisabledFeaturesList = {"A", "B", | |
| 22 "C"}; | |
| 23 static const std::vector<std::string> kSpacesInDisabledFeaturesList = {"A", | |
| 24 "B C"}; | |
| 25 static const char kOneDisabledFeatureSwitch[] = "A"; | |
| 26 static const char kTwoDisabledFeaturesSwitch[] = "A|B"; | |
| 27 static const char kThreeDisabledFeaturesSwitch[] = "A|B|C"; | |
| 28 static const char kSpacesInDisabledFeaturesSwitch[] = "A|B C"; | |
| 29 | |
| 30 static const std::vector<std::string> kOneDisabledTokenList = {"t1"}; | |
| 31 static const std::vector<std::string> kTwoDisabledTokensList = {"t1", "t2"}; | |
| 32 static const std::vector<std::string> kThreeDisabledTokensList = {"t1", "t2", | |
| 33 "t3"}; | |
| 34 static const char kOneDisabledTokenSwitch[] = "t1"; | |
| 35 static const char kTwoDisabledTokensSwitch[] = "t1|t2"; | |
| 36 static const char kThreeDisabledTokensSwitch[] = "t1|t2|t3"; | |
| 37 | |
| 38 class ChromeOriginTrialsTest : public InProcessBrowserTest { | |
| 39 protected: | |
| 40 ChromeOriginTrialsTest() {} | |
| 41 | |
| 42 void AddDisabledFeaturesToPrefs(const std::vector<std::string>& features) { | |
| 43 base::ListValue disabled_feature_list; | |
| 44 disabled_feature_list.AppendStrings(features); | |
| 45 ListPrefUpdate update(local_state(), prefs::kOriginTrialDisabledFeatures); | |
| 46 update->Swap(&disabled_feature_list); | |
| 47 } | |
| 48 | |
| 49 void AddDisabledTokensToPrefs(const std::vector<std::string>& tokens) { | |
| 50 base::ListValue disabled_token_list; | |
| 51 disabled_token_list.AppendStrings(tokens); | |
| 52 ListPrefUpdate update(local_state(), prefs::kOriginTrialDisabledTokens); | |
| 53 update->Swap(&disabled_token_list); | |
| 54 } | |
| 55 | |
| 56 PrefService* local_state() { return g_browser_process->local_state(); } | |
| 57 | |
| 58 private: | |
| 59 DISALLOW_COPY_AND_ASSIGN(ChromeOriginTrialsTest); | |
| 60 }; | |
| 61 | |
| 62 // Tests to verify that the public key is correctly read from prefs and | |
| 63 // added to the command line | |
| 64 | |
| 65 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, NoPublicKeySet) { | |
| 66 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 67 EXPECT_FALSE(command_line->HasSwitch(switches::kOriginTrialPublicKey)); | |
| 68 } | |
| 69 | |
| 70 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, PRE_PublicKeySetOnCommandLine) { | |
| 71 local_state()->Set(prefs::kOriginTrialPublicKey, base::Value(kNewPublicKey)); | |
| 72 ASSERT_EQ(kNewPublicKey, | |
| 73 local_state()->GetString(prefs::kOriginTrialPublicKey)); | |
| 74 } | |
| 75 | |
| 76 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, PublicKeySetOnCommandLine) { | |
| 77 ASSERT_EQ(kNewPublicKey, | |
| 78 local_state()->GetString(prefs::kOriginTrialPublicKey)); | |
| 79 | |
| 80 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 81 | |
| 82 EXPECT_TRUE(command_line->HasSwitch(switches::kOriginTrialPublicKey)); | |
| 83 | |
| 84 if (command_line->HasSwitch(switches::kOriginTrialPublicKey)) { | |
|
Marijn Kruisselbrink
2017/03/14 05:54:42
rather than having this if, would it make sense to
chasej
2017/03/14 20:00:08
I created a helper method GetCommandLineSwitch(),
| |
| 85 std::string actual_key = | |
| 86 command_line->GetSwitchValueASCII(switches::kOriginTrialPublicKey); | |
| 87 EXPECT_EQ(kNewPublicKey, actual_key); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 // Tests to verify that disabled features are correctly read from prefs and | |
| 92 // added to the command line | |
| 93 | |
| 94 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, NoDisabledFeatures) { | |
| 95 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 96 EXPECT_FALSE(command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)); | |
| 97 } | |
| 98 | |
| 99 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 100 PRE_OneDisabledFeatureSetOnCommandLine) { | |
| 101 AddDisabledFeaturesToPrefs(kOneDisabledFeatureList); | |
| 102 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledFeatures)); | |
| 103 } | |
| 104 | |
| 105 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 106 OneDisabledFeatureSetOnCommandLine) { | |
| 107 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledFeatures)); | |
| 108 | |
| 109 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 110 | |
| 111 EXPECT_TRUE(command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)); | |
| 112 | |
| 113 if (command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)) { | |
| 114 std::string switch_value = command_line->GetSwitchValueASCII( | |
| 115 switches::kOriginTrialDisabledFeatures); | |
| 116 EXPECT_EQ(kOneDisabledFeatureSwitch, switch_value); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
|
Marijn Kruisselbrink
2017/03/14 05:54:42
Rather than having all these essentially identical
chasej
2017/03/14 20:00:08
Done. Thanks for the suggestion. I had to add sepa
| |
| 121 PRE_TwoDisabledFeaturesSetOnCommandLine) { | |
| 122 AddDisabledFeaturesToPrefs(kTwoDisabledFeaturesList); | |
| 123 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledFeatures)); | |
| 124 } | |
| 125 | |
| 126 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 127 TwoDisabledFeaturesSetOnCommandLine) { | |
| 128 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledFeatures)); | |
| 129 | |
| 130 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 131 | |
| 132 EXPECT_TRUE(command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)); | |
| 133 | |
| 134 if (command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)) { | |
| 135 std::string switch_value = command_line->GetSwitchValueASCII( | |
| 136 switches::kOriginTrialDisabledFeatures); | |
| 137 EXPECT_EQ(kTwoDisabledFeaturesSwitch, switch_value); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 142 PRE_ThreeDisabledFeaturesSetOnCommandLine) { | |
| 143 AddDisabledFeaturesToPrefs(kThreeDisabledFeaturesList); | |
| 144 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledFeatures)); | |
| 145 } | |
| 146 | |
| 147 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 148 ThreeDisabledFeaturesSetOnCommandLine) { | |
| 149 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledFeatures)); | |
| 150 | |
| 151 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 152 | |
| 153 EXPECT_TRUE(command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)); | |
| 154 | |
| 155 if (command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)) { | |
| 156 std::string switch_value = command_line->GetSwitchValueASCII( | |
| 157 switches::kOriginTrialDisabledFeatures); | |
| 158 EXPECT_EQ(kThreeDisabledFeaturesSwitch, switch_value); | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 163 PRE_SpacesInDisabledFeaturesSetOnCommandLine) { | |
| 164 AddDisabledFeaturesToPrefs(kSpacesInDisabledFeaturesList); | |
| 165 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledFeatures)); | |
| 166 } | |
| 167 | |
| 168 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 169 SpacesInDisabledFeaturesSetOnCommandLine) { | |
| 170 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledFeatures)); | |
| 171 | |
| 172 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 173 | |
| 174 EXPECT_TRUE(command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)); | |
| 175 | |
| 176 if (command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)) { | |
| 177 std::string switch_value = command_line->GetSwitchValueASCII( | |
| 178 switches::kOriginTrialDisabledFeatures); | |
| 179 EXPECT_EQ(kSpacesInDisabledFeaturesSwitch, switch_value); | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 // Tests to verify that disabled tokens are correctly read from prefs and | |
| 184 // added to the command line | |
| 185 | |
| 186 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, NoDisabledTokens) { | |
| 187 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 188 EXPECT_FALSE(command_line->HasSwitch(switches::kOriginTrialDisabledTokens)); | |
| 189 } | |
| 190 | |
| 191 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 192 PRE_OneDisabledTokenSetOnCommandLine) { | |
| 193 AddDisabledTokensToPrefs(kOneDisabledTokenList); | |
| 194 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledTokens)); | |
| 195 } | |
| 196 | |
| 197 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 198 OneDisabledTokenSetOnCommandLine) { | |
| 199 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledTokens)); | |
| 200 | |
| 201 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 202 | |
| 203 EXPECT_TRUE(command_line->HasSwitch(switches::kOriginTrialDisabledTokens)); | |
| 204 | |
| 205 if (command_line->HasSwitch(switches::kOriginTrialDisabledTokens)) { | |
| 206 std::string switch_value = | |
| 207 command_line->GetSwitchValueASCII(switches::kOriginTrialDisabledTokens); | |
| 208 EXPECT_EQ(kOneDisabledTokenSwitch, switch_value); | |
| 209 } | |
| 210 } | |
| 211 | |
| 212 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 213 PRE_TwoDisabledTokensSetOnCommandLine) { | |
| 214 AddDisabledTokensToPrefs(kTwoDisabledTokensList); | |
| 215 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledTokens)); | |
| 216 } | |
| 217 | |
| 218 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 219 TwoDisabledTokensSetOnCommandLine) { | |
| 220 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledTokens)); | |
| 221 | |
| 222 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 223 | |
| 224 EXPECT_TRUE(command_line->HasSwitch(switches::kOriginTrialDisabledTokens)); | |
| 225 | |
| 226 if (command_line->HasSwitch(switches::kOriginTrialDisabledTokens)) { | |
| 227 std::string switch_value = | |
| 228 command_line->GetSwitchValueASCII(switches::kOriginTrialDisabledTokens); | |
| 229 EXPECT_EQ(kTwoDisabledTokensSwitch, switch_value); | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 234 PRE_ThreeDisabledTokensSetOnCommandLine) { | |
| 235 AddDisabledTokensToPrefs(kThreeDisabledTokensList); | |
| 236 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledTokens)); | |
| 237 } | |
| 238 | |
| 239 IN_PROC_BROWSER_TEST_F(ChromeOriginTrialsTest, | |
| 240 ThreeDisabledTokensSetOnCommandLine) { | |
| 241 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kOriginTrialDisabledTokens)); | |
| 242 | |
| 243 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 244 | |
| 245 EXPECT_TRUE(command_line->HasSwitch(switches::kOriginTrialDisabledTokens)); | |
| 246 | |
| 247 if (command_line->HasSwitch(switches::kOriginTrialDisabledTokens)) { | |
| 248 std::string switch_value = | |
| 249 command_line->GetSwitchValueASCII(switches::kOriginTrialDisabledTokens); | |
| 250 EXPECT_EQ(kThreeDisabledTokensSwitch, switch_value); | |
| 251 } | |
| 252 } | |
| 253 | |
| 254 } // namespace | |
| OLD | NEW |