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 "chrome/test/chromedriver/logging.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 TEST(Switches, Empty) { | 13 TEST(Switches, Empty) { |
13 Switches switches; | 14 Switches switches; |
14 CommandLine cmd(CommandLine::NO_PROGRAM); | 15 CommandLine cmd(CommandLine::NO_PROGRAM); |
15 switches.AppendToCommandLine(&cmd); | 16 switches.AppendToCommandLine(&cmd); |
16 ASSERT_EQ(0u, cmd.GetSwitches().size()); | 17 ASSERT_EQ(0u, cmd.GetSwitches().size()); |
17 ASSERT_EQ("", switches.ToString()); | 18 ASSERT_EQ("", switches.ToString()); |
18 } | 19 } |
19 | 20 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 330 } |
330 | 331 |
331 TEST(ParseCapabilities, LoggingPrefsNotDict) { | 332 TEST(ParseCapabilities, LoggingPrefsNotDict) { |
332 Capabilities capabilities; | 333 Capabilities capabilities; |
333 base::DictionaryValue caps; | 334 base::DictionaryValue caps; |
334 caps.SetString("loggingPrefs", "INFO"); | 335 caps.SetString("loggingPrefs", "INFO"); |
335 Status status = capabilities.Parse(caps); | 336 Status status = capabilities.Parse(caps); |
336 ASSERT_FALSE(status.IsOk()); | 337 ASSERT_FALSE(status.IsOk()); |
337 } | 338 } |
338 | 339 |
| 340 TEST(ParseCapabilities, PerfLoggingPrefsInspectorDomainStatus) { |
| 341 Capabilities capabilities; |
| 342 // Perf log must be enabled if performance log preferences are specified. |
| 343 base::DictionaryValue logging_prefs; |
| 344 logging_prefs.SetString(WebDriverLog::kPerformanceType, "INFO"); |
| 345 base::DictionaryValue desired_caps; |
| 346 desired_caps.Set("loggingPrefs", logging_prefs.DeepCopy()); |
| 347 ASSERT_EQ(PerfLoggingPrefs::InspectorDomainStatus::kDefaultEnabled, |
| 348 capabilities.perf_logging_prefs.network); |
| 349 ASSERT_EQ(PerfLoggingPrefs::InspectorDomainStatus::kDefaultEnabled, |
| 350 capabilities.perf_logging_prefs.page); |
| 351 ASSERT_EQ(PerfLoggingPrefs::InspectorDomainStatus::kDefaultEnabled, |
| 352 capabilities.perf_logging_prefs.timeline); |
| 353 base::DictionaryValue perf_logging_prefs; |
| 354 perf_logging_prefs.SetBoolean("enableNetwork", true); |
| 355 perf_logging_prefs.SetBoolean("enablePage", false); |
| 356 desired_caps.Set("chromeOptions.perfLoggingPrefs", |
| 357 perf_logging_prefs.DeepCopy()); |
| 358 Status status = capabilities.Parse(desired_caps); |
| 359 ASSERT_TRUE(status.IsOk()); |
| 360 ASSERT_EQ(PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyEnabled, |
| 361 capabilities.perf_logging_prefs.network); |
| 362 ASSERT_EQ(PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyDisabled, |
| 363 capabilities.perf_logging_prefs.page); |
| 364 ASSERT_EQ(PerfLoggingPrefs::InspectorDomainStatus::kDefaultEnabled, |
| 365 capabilities.perf_logging_prefs.timeline); |
| 366 } |
| 367 |
| 368 TEST(ParseCapabilities, PerfLoggingPrefsTraceCategories) { |
| 369 Capabilities capabilities; |
| 370 // Perf log must be enabled if performance log preferences are specified. |
| 371 base::DictionaryValue logging_prefs; |
| 372 logging_prefs.SetString(WebDriverLog::kPerformanceType, "INFO"); |
| 373 base::DictionaryValue desired_caps; |
| 374 desired_caps.Set("loggingPrefs", logging_prefs.DeepCopy()); |
| 375 ASSERT_EQ("", capabilities.perf_logging_prefs.trace_categories); |
| 376 base::DictionaryValue perf_logging_prefs; |
| 377 perf_logging_prefs.SetString("traceCategories", "benchmark,webkit.console"); |
| 378 desired_caps.Set("chromeOptions.perfLoggingPrefs", |
| 379 perf_logging_prefs.DeepCopy()); |
| 380 Status status = capabilities.Parse(desired_caps); |
| 381 ASSERT_TRUE(status.IsOk()); |
| 382 ASSERT_EQ("benchmark,webkit.console", |
| 383 capabilities.perf_logging_prefs.trace_categories); |
| 384 } |
| 385 |
| 386 TEST(ParseCapabilities, PerfLoggingPrefsNotDict) { |
| 387 Capabilities capabilities; |
| 388 // Perf log must be enabled if performance log preferences are specified. |
| 389 base::DictionaryValue logging_prefs; |
| 390 logging_prefs.SetString(WebDriverLog::kPerformanceType, "INFO"); |
| 391 base::DictionaryValue desired_caps; |
| 392 desired_caps.Set("loggingPrefs", logging_prefs.DeepCopy()); |
| 393 desired_caps.SetString("chromeOptions.perfLoggingPrefs", "traceCategories"); |
| 394 Status status = capabilities.Parse(desired_caps); |
| 395 ASSERT_FALSE(status.IsOk()); |
| 396 } |
| 397 |
| 398 TEST(ParseCapabilities, PerfLoggingPrefsNoPerfLogLevel) { |
| 399 Capabilities capabilities; |
| 400 base::DictionaryValue desired_caps; |
| 401 base::DictionaryValue perf_logging_prefs; |
| 402 perf_logging_prefs.SetBoolean("enableNetwork", true); |
| 403 desired_caps.Set("chromeOptions.perfLoggingPrefs", |
| 404 perf_logging_prefs.DeepCopy()); |
| 405 // Should fail because perf log must be enabled if perf log prefs specified. |
| 406 Status status = capabilities.Parse(desired_caps); |
| 407 ASSERT_FALSE(status.IsOk()); |
| 408 } |
| 409 |
| 410 TEST(ParseCapabilities, PerfLoggingPrefsPerfLogOff) { |
| 411 Capabilities capabilities; |
| 412 base::DictionaryValue logging_prefs; |
| 413 // Disable performance log by setting logging level to OFF. |
| 414 logging_prefs.SetString(WebDriverLog::kPerformanceType, "OFF"); |
| 415 base::DictionaryValue desired_caps; |
| 416 desired_caps.Set("loggingPrefs", logging_prefs.DeepCopy()); |
| 417 base::DictionaryValue perf_logging_prefs; |
| 418 perf_logging_prefs.SetBoolean("enableNetwork", true); |
| 419 desired_caps.Set("chromeOptions.perfLoggingPrefs", |
| 420 perf_logging_prefs.DeepCopy()); |
| 421 // Should fail because perf log must be enabled if perf log prefs specified. |
| 422 Status status = capabilities.Parse(desired_caps); |
| 423 ASSERT_FALSE(status.IsOk()); |
| 424 } |
| 425 |
339 TEST(ParseCapabilities, ExcludeSwitches) { | 426 TEST(ParseCapabilities, ExcludeSwitches) { |
340 Capabilities capabilities; | 427 Capabilities capabilities; |
341 base::ListValue exclude_switches; | 428 base::ListValue exclude_switches; |
342 exclude_switches.AppendString("switch1"); | 429 exclude_switches.AppendString("switch1"); |
343 exclude_switches.AppendString("switch2"); | 430 exclude_switches.AppendString("switch2"); |
344 base::DictionaryValue caps; | 431 base::DictionaryValue caps; |
345 caps.Set("chromeOptions.excludeSwitches", exclude_switches.DeepCopy()); | 432 caps.Set("chromeOptions.excludeSwitches", exclude_switches.DeepCopy()); |
346 Status status = capabilities.Parse(caps); | 433 Status status = capabilities.Parse(caps); |
347 ASSERT_TRUE(status.IsOk()); | 434 ASSERT_TRUE(status.IsOk()); |
348 ASSERT_EQ(2u, capabilities.exclude_switches.size()); | 435 ASSERT_EQ(2u, capabilities.exclude_switches.size()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 base::DictionaryValue mobile_emulation; | 536 base::DictionaryValue mobile_emulation; |
450 mobile_emulation.SetString("deviceName", "Google Nexus 5"); | 537 mobile_emulation.SetString("deviceName", "Google Nexus 5"); |
451 mobile_emulation.SetInteger("deviceMetrics.width", 360); | 538 mobile_emulation.SetInteger("deviceMetrics.width", 360); |
452 mobile_emulation.SetInteger("deviceMetrics.height", 640); | 539 mobile_emulation.SetInteger("deviceMetrics.height", 640); |
453 mobile_emulation.SetDouble("deviceMetrics.pixelRatio", 3.0); | 540 mobile_emulation.SetDouble("deviceMetrics.pixelRatio", 3.0); |
454 base::DictionaryValue caps; | 541 base::DictionaryValue caps; |
455 caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy()); | 542 caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy()); |
456 Status status = capabilities.Parse(caps); | 543 Status status = capabilities.Parse(caps); |
457 ASSERT_FALSE(status.IsOk()); | 544 ASSERT_FALSE(status.IsOk()); |
458 } | 545 } |
OLD | NEW |