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

Unified Diff: chrome/test/chromedriver/test/run_py_tests.py

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/test/run_py_tests.py
diff --git a/chrome/test/chromedriver/test/run_py_tests.py b/chrome/test/chromedriver/test/run_py_tests.py
index d5ee27e9bee28bf61067e93050dd7f68d8ff7e27..e54f5b8000627fb9bdcea6d7ef104c795d9e9323 100755
--- a/chrome/test/chromedriver/test/run_py_tests.py
+++ b/chrome/test/chromedriver/test/run_py_tests.py
@@ -100,6 +100,7 @@ _ANDROID_NEGATIVE_FILTER['chrome'] = (
# Android doesn't support switches and extensions.
'ChromeSwitchesCapabilityTest.*',
'ChromeExtensionsCapabilityTest.*',
+ 'MobileEmulationCapabilityTest.*',
# https://crbug.com/274650
'ChromeDriverTest.testCloseWindow',
# https://code.google.com/p/chromedriver/issues/detail?id=270
@@ -708,6 +709,9 @@ class ChromeDriverTest(ChromeDriverBaseTest):
def testDoesntHangOnDebugger(self):
self._driver.ExecuteScript('debugger;')
+ def testMobileEmulationDisabledByDefault(self):
+ self.assertFalse(self._driver.capabilities['mobileEmulationEnabled'])
+
class ChromeDriverAndroidTest(ChromeDriverBaseTest):
"""End to end tests for Android-specific tests."""
@@ -809,6 +813,56 @@ class ChromeLogPathCapabilityTest(ChromeDriverBaseTest):
self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read())
+class MobileEmulationCapabilityTest(ChromeDriverBaseTest):
+ """Tests that ChromeDriver processes chromeOptions.mobileEmulation.
+
+ Makes sure the device metrics are overridden in DevTools and user agent is
+ overridden in Chrome.
+ """
+
+ @staticmethod
+ def GlobalSetUp():
+ def respondWithUserAgentString(request):
+ return request.GetHeader('User-Agent')
+
+ MobileEmulationCapabilityTest._http_server = webserver.WebServer(
+ chrome_paths.GetTestData())
+ MobileEmulationCapabilityTest._http_server.SetCallbackForPath(
+ '/userAgent', respondWithUserAgentString)
+
+ @staticmethod
+ def GlobalTearDown():
+ MobileEmulationCapabilityTest._http_server.Shutdown()
+
+ def testDeviceMetrics(self):
+ driver = self.CreateDriver(
+ mobile_emulation = {
+ 'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}})
+ self.assertTrue(driver.capabilities['mobileEmulationEnabled'])
+ self.assertEqual(360, driver.ExecuteScript('return window.innerWidth'))
+ self.assertEqual(640, driver.ExecuteScript('return window.innerHeight'))
+
+ def testUserAgent(self):
+ driver = self.CreateDriver(
+ mobile_emulation = {'userAgent': 'Agent Smith'})
+ driver.Load(self._http_server.GetUrl() + '/userAgent')
+ body_tag = driver.FindElement('tag name', 'body')
+ self.assertEqual("Agent Smith", body_tag.GetText())
+
+ def testDeviceName(self):
stgao 2014/05/22 05:02:22 It seems this testcase keeps failing on Chrome 33,
+ driver = self.CreateDriver(
+ mobile_emulation = {'deviceName': 'Google Nexus 5'})
+ driver.Load(self._http_server.GetUrl() + '/userAgent')
+ self.assertEqual(360, driver.ExecuteScript('return window.innerWidth'))
+ self.assertEqual(640, driver.ExecuteScript('return window.innerHeight'))
+ body_tag = driver.FindElement('tag name', 'body')
+ self.assertEqual(
+ 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleW'
+ 'ebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/53'
+ '5.19',
+ body_tag.GetText())
+
+
class ChromeDriverLogTest(unittest.TestCase):
"""Tests that chromedriver produces the expected log file."""
@@ -1002,6 +1056,8 @@ if __name__ == '__main__':
sys.modules[__name__])
tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter)
ChromeDriverTest.GlobalSetUp()
+ MobileEmulationCapabilityTest.GlobalSetUp()
result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests)
ChromeDriverTest.GlobalTearDown()
+ MobileEmulationCapabilityTest.GlobalTearDown()
sys.exit(len(result.failures) + len(result.errors))

Powered by Google App Engine
This is Rietveld 408576698