| 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..0b44f4ffac8d54b368ee6c6338de88c1688da406 100755
|
| --- a/chrome/test/chromedriver/test/run_py_tests.py
|
| +++ b/chrome/test/chromedriver/test/run_py_tests.py
|
| @@ -809,6 +809,52 @@ class ChromeLogPathCapabilityTest(ChromeDriverBaseTest):
|
| self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read())
|
|
|
|
|
| +class MobileEmulationCapabilityTest(ChromeDriverBaseTest):
|
| + """Tests that ChromeDriver processes chromeOptions.mobileEmulation capabilities.
|
| +
|
| + Makes sure the device metrics are overridden in DevTools and user agent is
|
| + overridden in Chrome.
|
| + """
|
| +
|
| + @staticmethod
|
| + def GlobalSetUp():
|
| + MobileEmulationCapabilityTest._http_server = webserver.WebServer(
|
| + chrome_paths.GetTestData())
|
| + MobileEmulationCapabilityTest._http_server.SetCallbackForPath(
|
| + '/userAgent', MobileEmulationCapabilityTest.respondWithUserAgentString)
|
| +
|
| + @staticmethod
|
| + def GlobalTearDown():
|
| + MobileEmulationCapabilityTest._http_server.Shutdown()
|
| +
|
| + @staticmethod
|
| + def respondWithUserAgentString(request):
|
| + return request.GetHeader('User-Agent')
|
| +
|
| + def testDeviceMetrics(self):
|
| + driver = self.CreateDriver(
|
| + mobile_emulation = {
|
| + 'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}})
|
| + 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):
|
| + 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) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'", body_tag.GetText())
|
| +
|
| +
|
| class ChromeDriverLogTest(unittest.TestCase):
|
| """Tests that chromedriver produces the expected log file."""
|
|
|
| @@ -1002,6 +1048,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))
|
|
|