OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/capabilities.h" | 5 #include "chrome/test/chromedriver/capabilities.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/test/chromedriver/chrome/log.h" | 8 #include "chrome/test/chromedriver/chrome/log.h" |
9 #include "chrome/test/chromedriver/chrome/status.h" | 9 #include "chrome/test/chromedriver/chrome/status.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
| 12 TEST(Switches, Empty) { |
| 13 Switches switches; |
| 14 CommandLine cmd(CommandLine::NO_PROGRAM); |
| 15 switches.AppendToCommandLine(&cmd); |
| 16 ASSERT_EQ(0u, cmd.GetSwitches().size()); |
| 17 ASSERT_EQ("", switches.ToString()); |
| 18 } |
| 19 |
| 20 TEST(Switches, NoValue) { |
| 21 Switches switches; |
| 22 switches.SetSwitch("hello"); |
| 23 |
| 24 CommandLine cmd(CommandLine::NO_PROGRAM); |
| 25 switches.AppendToCommandLine(&cmd); |
| 26 ASSERT_TRUE(cmd.HasSwitch("hello")); |
| 27 ASSERT_EQ(FILE_PATH_LITERAL(""), cmd.GetSwitchValueNative("hello")); |
| 28 ASSERT_EQ("--hello", switches.ToString()); |
| 29 } |
| 30 |
| 31 TEST(Switches, Value) { |
| 32 Switches switches; |
| 33 switches.SetSwitch("hello", "there"); |
| 34 |
| 35 CommandLine cmd(CommandLine::NO_PROGRAM); |
| 36 switches.AppendToCommandLine(&cmd); |
| 37 ASSERT_TRUE(cmd.HasSwitch("hello")); |
| 38 ASSERT_EQ(FILE_PATH_LITERAL("there"), cmd.GetSwitchValueNative("hello")); |
| 39 ASSERT_EQ("--hello=there", switches.ToString()); |
| 40 } |
| 41 |
| 42 TEST(Switches, Quoting) { |
| 43 Switches switches; |
| 44 switches.SetSwitch("hello", "a b"); |
| 45 switches.SetSwitch("hello2", " '\" "); |
| 46 |
| 47 ASSERT_EQ("--hello=\"a b\" --hello2=\" '\\\" \"", switches.ToString()); |
| 48 } |
| 49 |
| 50 TEST(Switches, Multiple) { |
| 51 Switches switches; |
| 52 switches.SetSwitch("switch"); |
| 53 switches.SetSwitch("hello", "there"); |
| 54 |
| 55 CommandLine cmd(CommandLine::NO_PROGRAM); |
| 56 switches.AppendToCommandLine(&cmd); |
| 57 ASSERT_TRUE(cmd.HasSwitch("switch")); |
| 58 ASSERT_TRUE(cmd.HasSwitch("hello")); |
| 59 ASSERT_EQ(FILE_PATH_LITERAL("there"), cmd.GetSwitchValueNative("hello")); |
| 60 ASSERT_EQ("--hello=there --switch", switches.ToString()); |
| 61 } |
| 62 |
| 63 TEST(Switches, Unparsed) { |
| 64 Switches switches; |
| 65 switches.SetUnparsedSwitch("a"); |
| 66 switches.SetUnparsedSwitch("--b"); |
| 67 switches.SetUnparsedSwitch("--c=1"); |
| 68 switches.SetUnparsedSwitch("d=1"); |
| 69 switches.SetUnparsedSwitch("-e=--1=1"); |
| 70 |
| 71 ASSERT_EQ("---e=--1=1 --a --b --c=1 --d=1", switches.ToString()); |
| 72 } |
| 73 |
12 TEST(ParseCapabilities, WithAndroidPackage) { | 74 TEST(ParseCapabilities, WithAndroidPackage) { |
13 Capabilities capabilities; | 75 Capabilities capabilities; |
14 base::DictionaryValue caps; | 76 base::DictionaryValue caps; |
15 caps.SetString("chromeOptions.androidPackage", "abc"); | 77 caps.SetString("chromeOptions.androidPackage", "abc"); |
16 Logger log(Log::kError); | 78 Logger log(Log::kError); |
17 Status status = capabilities.Parse(caps, &log); | 79 Status status = capabilities.Parse(caps, &log); |
18 ASSERT_TRUE(status.IsOk()); | 80 ASSERT_TRUE(status.IsOk()); |
19 ASSERT_TRUE(capabilities.IsAndroid()); | 81 ASSERT_TRUE(capabilities.IsAndroid()); |
20 ASSERT_EQ("abc", capabilities.android_package); | 82 ASSERT_EQ("abc", capabilities.android_package); |
21 } | 83 } |
(...skipping 19 matching lines...) Expand all Loading... |
41 TEST(ParseCapabilities, LogPath) { | 103 TEST(ParseCapabilities, LogPath) { |
42 Capabilities capabilities; | 104 Capabilities capabilities; |
43 base::DictionaryValue caps; | 105 base::DictionaryValue caps; |
44 caps.SetString("chromeOptions.logPath", "path/to/logfile"); | 106 caps.SetString("chromeOptions.logPath", "path/to/logfile"); |
45 Logger log(Log::kError); | 107 Logger log(Log::kError); |
46 Status status = capabilities.Parse(caps, &log); | 108 Status status = capabilities.Parse(caps, &log); |
47 ASSERT_TRUE(status.IsOk()); | 109 ASSERT_TRUE(status.IsOk()); |
48 ASSERT_STREQ("path/to/logfile", capabilities.log_path.c_str()); | 110 ASSERT_STREQ("path/to/logfile", capabilities.log_path.c_str()); |
49 } | 111 } |
50 | 112 |
51 TEST(ParseCapabilities, NoArgs) { | |
52 Capabilities capabilities; | |
53 base::ListValue args; | |
54 ASSERT_TRUE(args.empty()); | |
55 base::DictionaryValue caps; | |
56 caps.Set("chromeOptions.args", args.DeepCopy()); | |
57 Logger log(Log::kError); | |
58 Status status = capabilities.Parse(caps, &log); | |
59 ASSERT_TRUE(status.IsOk()); | |
60 ASSERT_TRUE(capabilities.command.GetSwitches().empty()); | |
61 } | |
62 | |
63 TEST(ParseCapabilities, SingleArgWithoutValue) { | |
64 Capabilities capabilities; | |
65 base::ListValue args; | |
66 args.AppendString("enable-nacl"); | |
67 ASSERT_EQ(1u, args.GetSize()); | |
68 base::DictionaryValue caps; | |
69 caps.Set("chromeOptions.args", args.DeepCopy()); | |
70 Logger log(Log::kError); | |
71 Status status = capabilities.Parse(caps, &log); | |
72 ASSERT_TRUE(status.IsOk()); | |
73 ASSERT_EQ(1u, capabilities.command.GetSwitches().size()); | |
74 ASSERT_TRUE(capabilities.command.HasSwitch("enable-nacl")); | |
75 } | |
76 | |
77 TEST(ParseCapabilities, SingleArgWithValue) { | |
78 Capabilities capabilities; | |
79 base::ListValue args; | |
80 args.AppendString("load-extension=/test/extension"); | |
81 ASSERT_EQ(1u, args.GetSize()); | |
82 base::DictionaryValue caps; | |
83 caps.Set("chromeOptions.args", args.DeepCopy()); | |
84 Logger log(Log::kError); | |
85 Status status = capabilities.Parse(caps, &log); | |
86 ASSERT_TRUE(status.IsOk()); | |
87 ASSERT_EQ(1u, capabilities.command.GetSwitches().size()); | |
88 ASSERT_TRUE(capabilities.command.HasSwitch("load-extension")); | |
89 ASSERT_STREQ( | |
90 "/test/extension", | |
91 capabilities.command.GetSwitchValueASCII("load-extension").c_str()); | |
92 } | |
93 | |
94 TEST(ParseCapabilities, MultipleArgs) { | |
95 Capabilities capabilities; | |
96 base::ListValue args; | |
97 args.AppendString("arg1"); | |
98 args.AppendString("arg2=val"); | |
99 args.AppendString("arg3='a space'"); | |
100 ASSERT_EQ(3u, args.GetSize()); | |
101 base::DictionaryValue caps; | |
102 caps.Set("chromeOptions.args", args.DeepCopy()); | |
103 Logger log(Log::kError); | |
104 Status status = capabilities.Parse(caps, &log); | |
105 ASSERT_TRUE(status.IsOk()); | |
106 ASSERT_EQ(3u, capabilities.command.GetSwitches().size()); | |
107 ASSERT_TRUE(capabilities.command.HasSwitch("arg1")); | |
108 ASSERT_TRUE(capabilities.command.HasSwitch("arg2")); | |
109 ASSERT_STREQ("val", capabilities.command.GetSwitchValueASCII("arg2").c_str()); | |
110 ASSERT_TRUE(capabilities.command.HasSwitch("arg3")); | |
111 ASSERT_STREQ("'a space'", | |
112 capabilities.command.GetSwitchValueASCII("arg3").c_str()); | |
113 } | |
114 | |
115 TEST(ParseCapabilities, Prefs) { | 113 TEST(ParseCapabilities, Prefs) { |
116 Capabilities capabilities; | 114 Capabilities capabilities; |
117 base::DictionaryValue prefs; | 115 base::DictionaryValue prefs; |
118 prefs.SetString("key1", "value1"); | 116 prefs.SetString("key1", "value1"); |
119 prefs.SetString("key2.k", "value2"); | 117 prefs.SetString("key2.k", "value2"); |
120 base::DictionaryValue caps; | 118 base::DictionaryValue caps; |
121 caps.Set("chromeOptions.prefs", prefs.DeepCopy()); | 119 caps.Set("chromeOptions.prefs", prefs.DeepCopy()); |
122 Logger log(Log::kError); | 120 Logger log(Log::kError); |
123 Status status = capabilities.Parse(caps, &log); | 121 Status status = capabilities.Parse(caps, &log); |
124 ASSERT_TRUE(status.IsOk()); | 122 ASSERT_TRUE(status.IsOk()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 175 |
178 TEST(ParseCapabilities, DirectProxy) { | 176 TEST(ParseCapabilities, DirectProxy) { |
179 Capabilities capabilities; | 177 Capabilities capabilities; |
180 base::DictionaryValue proxy; | 178 base::DictionaryValue proxy; |
181 proxy.SetString("proxyType", "DIRECT"); | 179 proxy.SetString("proxyType", "DIRECT"); |
182 base::DictionaryValue caps; | 180 base::DictionaryValue caps; |
183 caps.Set("proxy", proxy.DeepCopy()); | 181 caps.Set("proxy", proxy.DeepCopy()); |
184 Logger log(Log::kError); | 182 Logger log(Log::kError); |
185 Status status = capabilities.Parse(caps, &log); | 183 Status status = capabilities.Parse(caps, &log); |
186 ASSERT_TRUE(status.IsOk()); | 184 ASSERT_TRUE(status.IsOk()); |
187 ASSERT_EQ(1u, capabilities.command.GetSwitches().size()); | 185 ASSERT_EQ(1u, capabilities.switches.GetSize()); |
188 ASSERT_TRUE(capabilities.command.HasSwitch("no-proxy-server")); | 186 ASSERT_TRUE(capabilities.switches.HasSwitch("no-proxy-server")); |
189 } | 187 } |
190 | 188 |
191 TEST(ParseCapabilities, SystemProxy) { | 189 TEST(ParseCapabilities, SystemProxy) { |
192 Capabilities capabilities; | 190 Capabilities capabilities; |
193 base::DictionaryValue proxy; | 191 base::DictionaryValue proxy; |
194 proxy.SetString("proxyType", "system"); | 192 proxy.SetString("proxyType", "system"); |
195 base::DictionaryValue caps; | 193 base::DictionaryValue caps; |
196 caps.Set("proxy", proxy.DeepCopy()); | 194 caps.Set("proxy", proxy.DeepCopy()); |
197 Logger log(Log::kError); | 195 Logger log(Log::kError); |
198 Status status = capabilities.Parse(caps, &log); | 196 Status status = capabilities.Parse(caps, &log); |
199 ASSERT_TRUE(status.IsOk()); | 197 ASSERT_TRUE(status.IsOk()); |
200 ASSERT_TRUE(capabilities.command.GetSwitches().empty()); | 198 ASSERT_EQ(0u, capabilities.switches.GetSize()); |
201 } | 199 } |
202 | 200 |
203 TEST(ParseCapabilities, PacProxy) { | 201 TEST(ParseCapabilities, PacProxy) { |
204 Capabilities capabilities; | 202 Capabilities capabilities; |
205 base::DictionaryValue proxy; | 203 base::DictionaryValue proxy; |
206 proxy.SetString("proxyType", "PAC"); | 204 proxy.SetString("proxyType", "PAC"); |
207 proxy.SetString("proxyAutoconfigUrl", "test.wpad"); | 205 proxy.SetString("proxyAutoconfigUrl", "test.wpad"); |
208 base::DictionaryValue caps; | 206 base::DictionaryValue caps; |
209 caps.Set("proxy", proxy.DeepCopy()); | 207 caps.Set("proxy", proxy.DeepCopy()); |
210 Logger log(Log::kError); | 208 Logger log(Log::kError); |
211 Status status = capabilities.Parse(caps, &log); | 209 Status status = capabilities.Parse(caps, &log); |
212 ASSERT_TRUE(status.IsOk()); | 210 ASSERT_TRUE(status.IsOk()); |
213 ASSERT_EQ(1u, capabilities.command.GetSwitches().size()); | 211 ASSERT_EQ(1u, capabilities.switches.GetSize()); |
214 ASSERT_STREQ( | 212 ASSERT_EQ("test.wpad", capabilities.switches.GetSwitchValue("proxy-pac-url")); |
215 "test.wpad", | |
216 capabilities.command.GetSwitchValueASCII("proxy-pac-url").c_str()); | |
217 } | 213 } |
218 | 214 |
219 TEST(ParseCapabilities, MissingProxyAutoconfigUrl) { | 215 TEST(ParseCapabilities, MissingProxyAutoconfigUrl) { |
220 Capabilities capabilities; | 216 Capabilities capabilities; |
221 base::DictionaryValue proxy; | 217 base::DictionaryValue proxy; |
222 proxy.SetString("proxyType", "PAC"); | 218 proxy.SetString("proxyType", "PAC"); |
223 proxy.SetString("httpProxy", "http://localhost:8001"); | 219 proxy.SetString("httpProxy", "http://localhost:8001"); |
224 base::DictionaryValue caps; | 220 base::DictionaryValue caps; |
225 caps.Set("proxy", proxy.DeepCopy()); | 221 caps.Set("proxy", proxy.DeepCopy()); |
226 Logger log(Log::kError); | 222 Logger log(Log::kError); |
227 Status status = capabilities.Parse(caps, &log); | 223 Status status = capabilities.Parse(caps, &log); |
228 ASSERT_FALSE(status.IsOk()); | 224 ASSERT_FALSE(status.IsOk()); |
229 } | 225 } |
230 | 226 |
231 TEST(ParseCapabilities, AutodetectProxy) { | 227 TEST(ParseCapabilities, AutodetectProxy) { |
232 Capabilities capabilities; | 228 Capabilities capabilities; |
233 base::DictionaryValue proxy; | 229 base::DictionaryValue proxy; |
234 proxy.SetString("proxyType", "autodetect"); | 230 proxy.SetString("proxyType", "autodetect"); |
235 base::DictionaryValue caps; | 231 base::DictionaryValue caps; |
236 caps.Set("proxy", proxy.DeepCopy()); | 232 caps.Set("proxy", proxy.DeepCopy()); |
237 Logger log(Log::kError); | 233 Logger log(Log::kError); |
238 Status status = capabilities.Parse(caps, &log); | 234 Status status = capabilities.Parse(caps, &log); |
239 ASSERT_TRUE(status.IsOk()); | 235 ASSERT_TRUE(status.IsOk()); |
240 ASSERT_EQ(1u, capabilities.command.GetSwitches().size()); | 236 ASSERT_EQ(1u, capabilities.switches.GetSize()); |
241 ASSERT_TRUE(capabilities.command.HasSwitch("proxy-auto-detect")); | 237 ASSERT_TRUE(capabilities.switches.HasSwitch("proxy-auto-detect")); |
242 } | 238 } |
243 | 239 |
244 TEST(ParseCapabilities, ManualProxy) { | 240 TEST(ParseCapabilities, ManualProxy) { |
245 Capabilities capabilities; | 241 Capabilities capabilities; |
246 base::DictionaryValue proxy; | 242 base::DictionaryValue proxy; |
247 proxy.SetString("proxyType", "manual"); | 243 proxy.SetString("proxyType", "manual"); |
248 proxy.SetString("ftpProxy", "localhost:9001"); | 244 proxy.SetString("ftpProxy", "localhost:9001"); |
249 proxy.SetString("httpProxy", "localhost:8001"); | 245 proxy.SetString("httpProxy", "localhost:8001"); |
250 proxy.SetString("sslProxy", "localhost:10001"); | 246 proxy.SetString("sslProxy", "localhost:10001"); |
251 proxy.SetString("noProxy", "google.com, youtube.com"); | 247 proxy.SetString("noProxy", "google.com, youtube.com"); |
252 base::DictionaryValue caps; | 248 base::DictionaryValue caps; |
253 caps.Set("proxy", proxy.DeepCopy()); | 249 caps.Set("proxy", proxy.DeepCopy()); |
254 Logger log(Log::kError); | 250 Logger log(Log::kError); |
255 Status status = capabilities.Parse(caps, &log); | 251 Status status = capabilities.Parse(caps, &log); |
256 ASSERT_TRUE(status.IsOk()); | 252 ASSERT_TRUE(status.IsOk()); |
257 ASSERT_EQ(2u, capabilities.command.GetSwitches().size()); | 253 ASSERT_EQ(2u, capabilities.switches.GetSize()); |
258 ASSERT_STREQ( | 254 ASSERT_EQ( |
259 "ftp=localhost:9001;http=localhost:8001;https=localhost:10001", | 255 "ftp=localhost:9001;http=localhost:8001;https=localhost:10001", |
260 capabilities.command.GetSwitchValueASCII("proxy-server").c_str()); | 256 capabilities.switches.GetSwitchValue("proxy-server")); |
261 ASSERT_STREQ( | 257 ASSERT_EQ( |
262 "google.com, youtube.com", | 258 "google.com, youtube.com", |
263 capabilities.command.GetSwitchValueASCII("proxy-bypass-list").c_str()); | 259 capabilities.switches.GetSwitchValue("proxy-bypass-list")); |
264 } | 260 } |
265 | 261 |
266 TEST(ParseCapabilities, MissingSettingForManualProxy) { | 262 TEST(ParseCapabilities, MissingSettingForManualProxy) { |
267 Capabilities capabilities; | 263 Capabilities capabilities; |
268 base::DictionaryValue proxy; | 264 base::DictionaryValue proxy; |
269 proxy.SetString("proxyType", "manual"); | 265 proxy.SetString("proxyType", "manual"); |
270 base::DictionaryValue caps; | 266 base::DictionaryValue caps; |
271 caps.Set("proxy", proxy.DeepCopy()); | 267 caps.Set("proxy", proxy.DeepCopy()); |
272 Logger log(Log::kError); | 268 Logger log(Log::kError); |
273 Status status = capabilities.Parse(caps, &log); | 269 Status status = capabilities.Parse(caps, &log); |
274 ASSERT_FALSE(status.IsOk()); | 270 ASSERT_FALSE(status.IsOk()); |
275 } | 271 } |
276 | 272 |
277 TEST(ParseCapabilities, IgnoreNullValueForManualProxy) { | 273 TEST(ParseCapabilities, IgnoreNullValueForManualProxy) { |
278 Capabilities capabilities; | 274 Capabilities capabilities; |
279 base::DictionaryValue proxy; | 275 base::DictionaryValue proxy; |
280 proxy.SetString("proxyType", "manual"); | 276 proxy.SetString("proxyType", "manual"); |
281 proxy.SetString("ftpProxy", "localhost:9001"); | 277 proxy.SetString("ftpProxy", "localhost:9001"); |
282 proxy.Set("sslProxy", base::Value::CreateNullValue()); | 278 proxy.Set("sslProxy", base::Value::CreateNullValue()); |
283 proxy.Set("noProxy", base::Value::CreateNullValue()); | 279 proxy.Set("noProxy", base::Value::CreateNullValue()); |
284 base::DictionaryValue caps; | 280 base::DictionaryValue caps; |
285 caps.Set("proxy", proxy.DeepCopy()); | 281 caps.Set("proxy", proxy.DeepCopy()); |
286 Logger log(Log::kError); | 282 Logger log(Log::kError); |
287 Status status = capabilities.Parse(caps, &log); | 283 Status status = capabilities.Parse(caps, &log); |
288 ASSERT_TRUE(status.IsOk()); | 284 ASSERT_TRUE(status.IsOk()); |
289 ASSERT_EQ(1u, capabilities.command.GetSwitches().size()); | 285 ASSERT_EQ(1u, capabilities.switches.GetSize()); |
290 ASSERT_TRUE(capabilities.command.HasSwitch("proxy-server")); | 286 ASSERT_TRUE(capabilities.switches.HasSwitch("proxy-server")); |
291 ASSERT_STREQ( | 287 ASSERT_EQ( |
292 "ftp=localhost:9001", | 288 "ftp=localhost:9001", |
293 capabilities.command.GetSwitchValueASCII("proxy-server").c_str()); | 289 capabilities.switches.GetSwitchValue("proxy-server")); |
294 } | 290 } |
295 | 291 |
296 TEST(ParseCapabilities, LoggingPrefsOk) { | 292 TEST(ParseCapabilities, LoggingPrefsOk) { |
297 Capabilities capabilities; | 293 Capabilities capabilities; |
298 base::DictionaryValue logging_prefs; | 294 base::DictionaryValue logging_prefs; |
299 logging_prefs.SetString("Network", "INFO"); | 295 logging_prefs.SetString("Network", "INFO"); |
300 base::DictionaryValue caps; | 296 base::DictionaryValue caps; |
301 caps.Set("loggingPrefs", logging_prefs.DeepCopy()); | 297 caps.Set("loggingPrefs", logging_prefs.DeepCopy()); |
302 Logger log(Log::kError); | 298 Logger log(Log::kError); |
303 Status status = capabilities.Parse(caps, &log); | 299 Status status = capabilities.Parse(caps, &log); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 TEST(ParseCapabilities, UseExistingBrowser) { | 333 TEST(ParseCapabilities, UseExistingBrowser) { |
338 Capabilities capabilities; | 334 Capabilities capabilities; |
339 base::DictionaryValue caps; | 335 base::DictionaryValue caps; |
340 caps.SetString("chromeOptions.useExistingBrowser", "abc:123"); | 336 caps.SetString("chromeOptions.useExistingBrowser", "abc:123"); |
341 Logger log(Log::kError); | 337 Logger log(Log::kError); |
342 Status status = capabilities.Parse(caps, &log); | 338 Status status = capabilities.Parse(caps, &log); |
343 ASSERT_TRUE(status.IsOk()); | 339 ASSERT_TRUE(status.IsOk()); |
344 ASSERT_TRUE(capabilities.IsExistingBrowser()); | 340 ASSERT_TRUE(capabilities.IsExistingBrowser()); |
345 ASSERT_EQ(123, capabilities.existing_browser_port); | 341 ASSERT_EQ(123, capabilities.existing_browser_port); |
346 } | 342 } |
OLD | NEW |