Chromium Code Reviews| 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..9b0692aa84434a50b18487bcdf7767ca543e0284 100755 |
| --- a/chrome/test/chromedriver/test/run_py_tests.py |
| +++ b/chrome/test/chromedriver/test/run_py_tests.py |
| @@ -809,6 +809,54 @@ 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(): |
| + 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): |
|
stgao
2014/05/14 05:10:14
This method could be moved into GlobalSetUp, as it
sam.rawlins
2014/05/16 21:09:38
Done.
|
| + 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'", |
|
stgao
2014/05/14 05:10:14
over 80 chars.
We use 'str' instead of "str".
It
sam.rawlins
2014/05/16 21:09:38
Done.
|
| + body_tag.GetText()) |
| + |
| + |
| class ChromeDriverLogTest(unittest.TestCase): |
| """Tests that chromedriver produces the expected log file.""" |
| @@ -1002,6 +1050,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)) |