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

Side by Side Diff: chrome/test/chromedriver/capabilities_unittest.cc

Issue 288193004: [Chromedriver] Add Device Metrics override support to ChromeDriver via Capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
OLDNEW
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"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 TEST(ParseCapabilities, UseExistingBrowser) { 354 TEST(ParseCapabilities, UseExistingBrowser) {
355 Capabilities capabilities; 355 Capabilities capabilities;
356 base::DictionaryValue caps; 356 base::DictionaryValue caps;
357 caps.SetString("chromeOptions.debuggerAddress", "abc:123"); 357 caps.SetString("chromeOptions.debuggerAddress", "abc:123");
358 Status status = capabilities.Parse(caps); 358 Status status = capabilities.Parse(caps);
359 ASSERT_TRUE(status.IsOk()); 359 ASSERT_TRUE(status.IsOk());
360 ASSERT_TRUE(capabilities.IsExistingBrowser()); 360 ASSERT_TRUE(capabilities.IsExistingBrowser());
361 ASSERT_EQ("abc", capabilities.debugger_address.host()); 361 ASSERT_EQ("abc", capabilities.debugger_address.host());
362 ASSERT_EQ(123, capabilities.debugger_address.port()); 362 ASSERT_EQ(123, capabilities.debugger_address.port());
363 } 363 }
364
365 TEST(ParseCapabilities, MobileEmulationUserAgent) {
366 Capabilities capabilities;
367 base::DictionaryValue mobile_emulation;
368 mobile_emulation.SetString("userAgent", "Agent Smith");
369 base::DictionaryValue caps;
370 caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
371 Status status = capabilities.Parse(caps);
372 ASSERT_TRUE(status.IsOk());
373
374 ASSERT_EQ(1u, capabilities.switches.GetSize());
375 ASSERT_TRUE(capabilities.switches.HasSwitch("user-agent"));
376 ASSERT_EQ("Agent Smith", capabilities.switches.GetSwitchValue("user-agent"));
377 }
378
379 TEST(ParseCapabilities, MobileEmulationDeviceMetrics) {
380 Capabilities capabilities;
381 base::DictionaryValue mobile_emulation;
382 mobile_emulation.SetInteger("deviceMetrics.width", 360);
383 mobile_emulation.SetInteger("deviceMetrics.height", 640);
384 mobile_emulation.SetDouble("deviceMetrics.pixelRatio", 3.0);
385 base::DictionaryValue caps;
386 caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
387 Status status = capabilities.Parse(caps);
388 ASSERT_TRUE(status.IsOk());
389
390 ASSERT_EQ(360, capabilities.device_metrics->width);
391 ASSERT_EQ(640, capabilities.device_metrics->height);
392 ASSERT_EQ(3.0, capabilities.device_metrics->device_scale_factor);
393 }
394
395 TEST(ParseCapabilities, MobileEmulationDeviceName) {
396 Capabilities capabilities;
397 base::DictionaryValue mobile_emulation;
398 mobile_emulation.SetString("deviceName", "Google Nexus 5");
399 base::DictionaryValue caps;
400 caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
401 Status status = capabilities.Parse(caps);
402 ASSERT_TRUE(status.IsOk());
403
404 ASSERT_EQ(1u, capabilities.switches.GetSize());
405 ASSERT_TRUE(capabilities.switches.HasSwitch("user-agent"));
406 ASSERT_EQ(
407 "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) "
408 "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 "
409 "Mobile Safari/535.19",
410 capabilities.switches.GetSwitchValue("user-agent"));
411
412 ASSERT_EQ(360, capabilities.device_metrics->width);
413 ASSERT_EQ(640, capabilities.device_metrics->height);
414 ASSERT_EQ(3.0, capabilities.device_metrics->device_scale_factor);
415 }
416
417 TEST(ParseCapabilities, MobileEmulationNotDict) {
418 Capabilities capabilities;
419 base::DictionaryValue caps;
420 caps.SetString("chromeOptions.mobileEmulation", "Google Nexus 5");
421 Status status = capabilities.Parse(caps);
422 ASSERT_FALSE(status.IsOk());
423 }
424
425 TEST(ParseCapabilities, MobileEmulationDeviceMetricsNotDict) {
426 Capabilities capabilities;
427 base::DictionaryValue mobile_emulation;
428 mobile_emulation.SetInteger("deviceMetrics", 360);
429 base::DictionaryValue caps;
430 caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
431 Status status = capabilities.Parse(caps);
432 ASSERT_FALSE(status.IsOk());
433 }
434
435 TEST(ParseCapabilities, MobileEmulationDeviceMetricsNotNumbers) {
436 Capabilities capabilities;
437 base::DictionaryValue mobile_emulation;
438 mobile_emulation.SetString("deviceMetrics.width", "360");
439 mobile_emulation.SetString("deviceMetrics.height", "640");
440 mobile_emulation.SetString("deviceMetrics.pixelRatio", "3.0");
441 base::DictionaryValue caps;
442 caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
443 Status status = capabilities.Parse(caps);
444 ASSERT_FALSE(status.IsOk());
445 }
446
447 TEST(ParseCapabilities, MobileEmulationBadDict) {
448 Capabilities capabilities;
449 base::DictionaryValue mobile_emulation;
450 mobile_emulation.SetString("deviceName", "Google Nexus 5");
451 mobile_emulation.SetInteger("deviceMetrics.width", 360);
452 mobile_emulation.SetInteger("deviceMetrics.height", 640);
453 mobile_emulation.SetDouble("deviceMetrics.pixelRatio", 3.0);
454 base::DictionaryValue caps;
455 caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
456 Status status = capabilities.Parse(caps);
457 ASSERT_FALSE(status.IsOk());
458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698