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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 | 46 |
47 _NEGATIVE_FILTER = [ | 47 _NEGATIVE_FILTER = [ |
48 # https://code.google.com/p/chromedriver/issues/detail?id=213 | 48 # https://code.google.com/p/chromedriver/issues/detail?id=213 |
49 'ChromeDriverTest.testClickElementInSubFrame', | 49 'ChromeDriverTest.testClickElementInSubFrame', |
50 # This test is flaky since it uses setTimeout. | 50 # This test is flaky since it uses setTimeout. |
51 # Re-enable once crbug.com/177511 is fixed and we can remove setTimeout. | 51 # Re-enable once crbug.com/177511 is fixed and we can remove setTimeout. |
52 'ChromeDriverTest.testAlert', | 52 'ChromeDriverTest.testAlert', |
53 # Enable per-browser when http://crbug.com/456324 is fixed. | 53 # Enable per-browser when http://crbug.com/456324 is fixed. |
54 'ChromeDriverTest.testEmulateNetworkConditionsOffline', | 54 'ChromeDriverTest.testEmulateNetworkConditionsOffline', |
| 55 # This test is too flaky on the bots, but seems to run perfectly fine |
| 56 # on developer workstations. |
| 57 'ChromeDriverTest.testEmulateNetworkConditionsSpeed', |
55 ] | 58 ] |
56 | 59 |
57 _VERSION_SPECIFIC_FILTER = {} | 60 _VERSION_SPECIFIC_FILTER = {} |
58 _VERSION_SPECIFIC_FILTER['HEAD'] = [ | 61 _VERSION_SPECIFIC_FILTER['HEAD'] = [ |
59 # https://code.google.com/p/chromedriver/issues/detail?id=992 | 62 # https://code.google.com/p/chromedriver/issues/detail?id=992 |
60 'ChromeDownloadDirTest.testDownloadDirectoryOverridesExistingPreferences', | 63 'ChromeDownloadDirTest.testDownloadDirectoryOverridesExistingPreferences', |
61 ] | 64 ] |
62 _VERSION_SPECIFIC_FILTER['37'] = [ | 65 _VERSION_SPECIFIC_FILTER['37'] = [ |
63 # https://code.google.com/p/chromedriver/issues/detail?id=954 | 66 # https://code.google.com/p/chromedriver/issues/detail?id=954 |
64 'MobileEmulationCapabilityTest.testClickElement', | 67 'MobileEmulationCapabilityTest.testClickElement', |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 ) | 155 ) |
153 _ANDROID_NEGATIVE_FILTER['chromedriver_webview_shell'] = ( | 156 _ANDROID_NEGATIVE_FILTER['chromedriver_webview_shell'] = ( |
154 _ANDROID_NEGATIVE_FILTER['chrome_shell'] + [ | 157 _ANDROID_NEGATIVE_FILTER['chrome_shell'] + [ |
155 # https://code.google.com/p/chromedriver/issues/detail?id=913 | 158 # https://code.google.com/p/chromedriver/issues/detail?id=913 |
156 'ChromeDriverTest.testChromeDriverSendLargeData', | 159 'ChromeDriverTest.testChromeDriverSendLargeData', |
157 'PerformanceLoggerTest.testPerformanceLogger', | 160 'PerformanceLoggerTest.testPerformanceLogger', |
158 'ChromeDriverTest.testShadowDom*', | 161 'ChromeDriverTest.testShadowDom*', |
159 # WebView doesn't support emulating network conditions. | 162 # WebView doesn't support emulating network conditions. |
160 'ChromeDriverTest.testEmulateNetworkConditions', | 163 'ChromeDriverTest.testEmulateNetworkConditions', |
161 'ChromeDriverTest.testEmulateNetworkConditionsOffline', | 164 'ChromeDriverTest.testEmulateNetworkConditionsOffline', |
| 165 'ChromeDriverTest.testEmulateNetworkConditionsSpeed', |
162 ] | 166 ] |
163 ) | 167 ) |
164 | 168 |
165 | 169 |
166 class ChromeDriverBaseTest(unittest.TestCase): | 170 class ChromeDriverBaseTest(unittest.TestCase): |
167 """Base class for testing chromedriver functionalities.""" | 171 """Base class for testing chromedriver functionalities.""" |
168 | 172 |
169 def __init__(self, *args, **kwargs): | 173 def __init__(self, *args, **kwargs): |
170 super(ChromeDriverBaseTest, self).__init__(*args, **kwargs) | 174 super(ChromeDriverBaseTest, self).__init__(*args, **kwargs) |
171 self._drivers = [] | 175 self._drivers = [] |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 # DSL: 2Mbps throughput, 5ms RTT | 800 # DSL: 2Mbps throughput, 5ms RTT |
797 latency = 5 | 801 latency = 5 |
798 throughput = 2048 * 1024 | 802 throughput = 2048 * 1024 |
799 self._driver.SetNetworkConditions(latency, throughput, throughput) | 803 self._driver.SetNetworkConditions(latency, throughput, throughput) |
800 | 804 |
801 network = self._driver.GetNetworkConditions() | 805 network = self._driver.GetNetworkConditions() |
802 self.assertEquals(latency, network['latency']); | 806 self.assertEquals(latency, network['latency']); |
803 self.assertEquals(throughput, network['download_throughput']); | 807 self.assertEquals(throughput, network['download_throughput']); |
804 self.assertEquals(throughput, network['upload_throughput']); | 808 self.assertEquals(throughput, network['upload_throughput']); |
805 | 809 |
| 810 def testEmulateNetworkConditionsSpeed(self): |
| 811 # Warm up the browser. |
| 812 self._http_server.SetDataForPath( |
| 813 '/', "<html><body>blank</body></html>") |
| 814 self._driver.Load(self._http_server.GetUrl() + '/') |
| 815 |
| 816 # DSL: 2Mbps throughput, 5ms RTT |
| 817 latency = 5 |
| 818 throughput_kbps = 2048 |
| 819 throughput = throughput_kbps * 1024 |
| 820 self._driver.SetNetworkConditions(latency, throughput, throughput) |
| 821 |
| 822 _32_bytes = " 0 1 2 3 4 5 6 7 8 9 A B C D E F" |
| 823 _1_megabyte = _32_bytes * 32768 |
| 824 self._http_server.SetDataForPath( |
| 825 '/1MB', |
| 826 "<html><body>%s</body></html>" % _1_megabyte) |
| 827 start = time.time() |
| 828 self._driver.Load(self._http_server.GetUrl() + '/1MB') |
| 829 finish = time.time() |
| 830 duration = finish - start |
| 831 actual_throughput_kbps = 1024 / duration |
| 832 self.assertLessEqual(actual_throughput_kbps, throughput_kbps * 1.5) |
| 833 self.assertGreaterEqual(actual_throughput_kbps, throughput_kbps / 1.5) |
| 834 |
806 def testEmulateNetworkConditionsOffline(self): | 835 def testEmulateNetworkConditionsOffline(self): |
807 self._driver.SetNetworkConditions(5, 2048, 2048, offline=True) | 836 self._driver.SetNetworkConditions(5, 2048, 2048, offline=True) |
808 self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html')) | 837 self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html')) |
809 self.assertIn('is not available', self._driver.GetTitle()) | 838 self.assertIn('is not available', self._driver.GetTitle()) |
810 | 839 |
811 def testShadowDomFindElementWithSlashDeep(self): | 840 def testShadowDomFindElementWithSlashDeep(self): |
812 """Checks that chromedriver can find elements in a shadow DOM using /deep/ | 841 """Checks that chromedriver can find elements in a shadow DOM using /deep/ |
813 css selectors.""" | 842 css selectors.""" |
814 self._driver.Load(self.GetHttpUrlForFile( | 843 self._driver.Load(self.GetHttpUrlForFile( |
815 '/chromedriver/shadow_dom_test.html')) | 844 '/chromedriver/shadow_dom_test.html')) |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 | 1497 |
1469 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 1498 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
1470 sys.modules[__name__]) | 1499 sys.modules[__name__]) |
1471 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) | 1500 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) |
1472 ChromeDriverTest.GlobalSetUp() | 1501 ChromeDriverTest.GlobalSetUp() |
1473 MobileEmulationCapabilityTest.GlobalSetUp() | 1502 MobileEmulationCapabilityTest.GlobalSetUp() |
1474 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) | 1503 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) |
1475 ChromeDriverTest.GlobalTearDown() | 1504 ChromeDriverTest.GlobalTearDown() |
1476 MobileEmulationCapabilityTest.GlobalTearDown() | 1505 MobileEmulationCapabilityTest.GlobalTearDown() |
1477 sys.exit(len(result.failures) + len(result.errors)) | 1506 sys.exit(len(result.failures) + len(result.errors)) |
OLD | NEW |