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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/capabilities_unittest.cc
diff --git a/chrome/test/chromedriver/capabilities_unittest.cc b/chrome/test/chromedriver/capabilities_unittest.cc
index f4b313ef00c2a6aa9e7d48d7b295f9b73f91cee1..ea1e87cde9301937e6ffeef27f5e389b08fb62ac 100644
--- a/chrome/test/chromedriver/capabilities_unittest.cc
+++ b/chrome/test/chromedriver/capabilities_unittest.cc
@@ -361,3 +361,98 @@ TEST(ParseCapabilities, UseExistingBrowser) {
ASSERT_EQ("abc", capabilities.debugger_address.host());
ASSERT_EQ(123, capabilities.debugger_address.port());
}
+
+TEST(ParseCapabilities, MobileEmulationUserAgent) {
+ Capabilities capabilities;
+ base::DictionaryValue mobile_emulation;
+ mobile_emulation.SetString("userAgent", "Agent Smith");
+ base::DictionaryValue caps;
+ caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
+ Status status = capabilities.Parse(caps);
+ ASSERT_TRUE(status.IsOk());
+
+ ASSERT_EQ(1u, capabilities.switches.GetSize());
+ ASSERT_TRUE(capabilities.switches.HasSwitch("user-agent"));
+ ASSERT_EQ("Agent Smith", capabilities.switches.GetSwitchValue("user-agent"));
+}
+
+TEST(ParseCapabilities, MobileEmulationDeviceMetrics) {
+ Capabilities capabilities;
+ base::DictionaryValue mobile_emulation;
+ mobile_emulation.SetInteger("deviceMetrics.width", 360);
+ mobile_emulation.SetInteger("deviceMetrics.height", 640);
+ mobile_emulation.SetDouble("deviceMetrics.pixelRatio", 3.0);
+ base::DictionaryValue caps;
+ caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
+ Status status = capabilities.Parse(caps);
+ ASSERT_TRUE(status.IsOk());
+
+ ASSERT_EQ(360, capabilities.device_metrics->width);
+ ASSERT_EQ(640, capabilities.device_metrics->height);
+ ASSERT_EQ(3.0, capabilities.device_metrics->device_scale_factor);
+}
+
+TEST(ParseCapabilities, MobileEmulationDeviceName) {
+ Capabilities capabilities;
+ base::DictionaryValue mobile_emulation;
+ mobile_emulation.SetString("deviceName", "Google Nexus 5");
+ base::DictionaryValue caps;
+ caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
+ Status status = capabilities.Parse(caps);
+ ASSERT_TRUE(status.IsOk());
+
+ ASSERT_EQ(1u, capabilities.switches.GetSize());
+ ASSERT_TRUE(capabilities.switches.HasSwitch("user-agent"));
+ ASSERT_EQ(
+ "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) "
+ "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 "
+ "Mobile Safari/535.19",
+ capabilities.switches.GetSwitchValue("user-agent"));
+
+ ASSERT_EQ(360, capabilities.device_metrics->width);
+ ASSERT_EQ(640, capabilities.device_metrics->height);
+ ASSERT_EQ(3.0, capabilities.device_metrics->device_scale_factor);
+}
+
+TEST(ParseCapabilities, MobileEmulationNotDict) {
+ Capabilities capabilities;
+ base::DictionaryValue caps;
+ caps.SetString("chromeOptions.mobileEmulation", "Google Nexus 5");
+ Status status = capabilities.Parse(caps);
+ ASSERT_FALSE(status.IsOk());
+}
+
+TEST(ParseCapabilities, MobileEmulationDeviceMetricsNotDict) {
+ Capabilities capabilities;
+ base::DictionaryValue mobile_emulation;
+ mobile_emulation.SetInteger("deviceMetrics", 360);
+ base::DictionaryValue caps;
+ caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
+ Status status = capabilities.Parse(caps);
+ ASSERT_FALSE(status.IsOk());
+}
+
+TEST(ParseCapabilities, MobileEmulationDeviceMetricsNotNumbers) {
+ Capabilities capabilities;
+ base::DictionaryValue mobile_emulation;
+ mobile_emulation.SetString("deviceMetrics.width", "360");
+ mobile_emulation.SetString("deviceMetrics.height", "640");
+ mobile_emulation.SetString("deviceMetrics.pixelRatio", "3.0");
+ base::DictionaryValue caps;
+ caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
+ Status status = capabilities.Parse(caps);
+ ASSERT_FALSE(status.IsOk());
+}
+
+TEST(ParseCapabilities, MobileEmulationBadDict) {
+ Capabilities capabilities;
+ base::DictionaryValue mobile_emulation;
+ mobile_emulation.SetString("deviceName", "Google Nexus 5");
+ mobile_emulation.SetInteger("deviceMetrics.width", 360);
+ mobile_emulation.SetInteger("deviceMetrics.height", 640);
+ mobile_emulation.SetDouble("deviceMetrics.pixelRatio", 3.0);
+ base::DictionaryValue caps;
+ caps.Set("chromeOptions.mobileEmulation", mobile_emulation.DeepCopy());
+ Status status = capabilities.Parse(caps);
+ ASSERT_FALSE(status.IsOk());
+}

Powered by Google App Engine
This is Rietveld 408576698