OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """End to end tests for ChromeDriver.""" | 6 """End to end tests for ChromeDriver.""" |
7 | 7 |
8 import base64 | 8 import base64 |
9 import json | 9 import json |
10 import math | 10 import math |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 | 802 |
803 Verifies that a log message is written into the specified log file. | 803 Verifies that a log message is written into the specified log file. |
804 """ | 804 """ |
805 tmp_log_path = tempfile.NamedTemporaryFile() | 805 tmp_log_path = tempfile.NamedTemporaryFile() |
806 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) | 806 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) |
807 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) | 807 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) |
808 driver.Quit() | 808 driver.Quit() |
809 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) | 809 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) |
810 | 810 |
811 | 811 |
| 812 class MobileEmulationCapabilityTest(ChromeDriverBaseTest): |
| 813 """Tests that ChromeDriver processes chromeOptions.mobileEmulation capabilitie
s. |
| 814 |
| 815 Makes sure the device metrics are overridden in DevTools and user agent is |
| 816 overridden in Chrome. |
| 817 """ |
| 818 |
| 819 @staticmethod |
| 820 def GlobalSetUp(): |
| 821 MobileEmulationCapabilityTest._http_server = webserver.WebServer( |
| 822 chrome_paths.GetTestData()) |
| 823 MobileEmulationCapabilityTest._http_server.SetCallbackForPath( |
| 824 '/userAgent', MobileEmulationCapabilityTest.respondWithUserAgentString) |
| 825 |
| 826 @staticmethod |
| 827 def GlobalTearDown(): |
| 828 MobileEmulationCapabilityTest._http_server.Shutdown() |
| 829 |
| 830 @staticmethod |
| 831 def respondWithUserAgentString(request): |
| 832 return request.GetHeader('User-Agent') |
| 833 |
| 834 def testDeviceMetrics(self): |
| 835 driver = self.CreateDriver( |
| 836 mobile_emulation = { |
| 837 'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}}) |
| 838 self.assertEqual(360, driver.ExecuteScript('return window.innerWidth')) |
| 839 self.assertEqual(640, driver.ExecuteScript('return window.innerHeight')) |
| 840 |
| 841 def testUserAgent(self): |
| 842 driver = self.CreateDriver( |
| 843 mobile_emulation = {'userAgent': 'Agent Smith'}) |
| 844 driver.Load(self._http_server.GetUrl() + '/userAgent') |
| 845 body_tag = driver.FindElement('tag name', 'body') |
| 846 self.assertEqual("'Agent Smith'", body_tag.GetText()) |
| 847 |
| 848 def testDeviceName(self): |
| 849 driver = self.CreateDriver( |
| 850 mobile_emulation = {'deviceName': 'Google Nexus 5'}) |
| 851 driver.Load(self._http_server.GetUrl() + '/userAgent') |
| 852 self.assertEqual(360, driver.ExecuteScript('return window.innerWidth')) |
| 853 self.assertEqual(640, driver.ExecuteScript('return window.innerHeight')) |
| 854 body_tag = driver.FindElement('tag name', 'body') |
| 855 self.assertEqual("'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/J
OP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari
/535.19'", body_tag.GetText()) |
| 856 |
| 857 |
812 class ChromeDriverLogTest(unittest.TestCase): | 858 class ChromeDriverLogTest(unittest.TestCase): |
813 """Tests that chromedriver produces the expected log file.""" | 859 """Tests that chromedriver produces the expected log file.""" |
814 | 860 |
815 UNEXPECTED_CHROMEOPTION_CAP = 'unexpected_chromeoption_capability' | 861 UNEXPECTED_CHROMEOPTION_CAP = 'unexpected_chromeoption_capability' |
816 LOG_MESSAGE = 'unrecognized chrome option: %s' % UNEXPECTED_CHROMEOPTION_CAP | 862 LOG_MESSAGE = 'unrecognized chrome option: %s' % UNEXPECTED_CHROMEOPTION_CAP |
817 | 863 |
818 def testChromeDriverLog(self): | 864 def testChromeDriverLog(self): |
819 _, tmp_log_path = tempfile.mkstemp(prefix='chromedriver_log_') | 865 _, tmp_log_path = tempfile.mkstemp(prefix='chromedriver_log_') |
820 chromedriver_server = server.Server( | 866 chromedriver_server = server.Server( |
821 _CHROMEDRIVER_BINARY, log_path=tmp_log_path) | 867 _CHROMEDRIVER_BINARY, log_path=tmp_log_path) |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 if _ANDROID_PACKAGE_KEY: | 1041 if _ANDROID_PACKAGE_KEY: |
996 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE_KEY] | 1042 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE_KEY] |
997 else: | 1043 else: |
998 negative_filter = _GetDesktopNegativeFilter(options.chrome_version) | 1044 negative_filter = _GetDesktopNegativeFilter(options.chrome_version) |
999 options.filter = '*-' + ':__main__.'.join([''] + negative_filter) | 1045 options.filter = '*-' + ':__main__.'.join([''] + negative_filter) |
1000 | 1046 |
1001 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 1047 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
1002 sys.modules[__name__]) | 1048 sys.modules[__name__]) |
1003 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) | 1049 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) |
1004 ChromeDriverTest.GlobalSetUp() | 1050 ChromeDriverTest.GlobalSetUp() |
| 1051 MobileEmulationCapabilityTest.GlobalSetUp() |
1005 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) | 1052 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) |
1006 ChromeDriverTest.GlobalTearDown() | 1053 ChromeDriverTest.GlobalTearDown() |
| 1054 MobileEmulationCapabilityTest.GlobalTearDown() |
1007 sys.exit(len(result.failures) + len(result.errors)) | 1055 sys.exit(len(result.failures) + len(result.errors)) |
OLD | NEW |