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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 self._driver.ExecuteScript('debugger;') | 767 self._driver.ExecuteScript('debugger;') |
768 | 768 |
769 def testMobileEmulationDisabledByDefault(self): | 769 def testMobileEmulationDisabledByDefault(self): |
770 self.assertFalse(self._driver.capabilities['mobileEmulationEnabled']) | 770 self.assertFalse(self._driver.capabilities['mobileEmulationEnabled']) |
771 | 771 |
772 def testChromeDriverSendLargeData(self): | 772 def testChromeDriverSendLargeData(self): |
773 script = 's = ""; for (i = 0; i < 10e6; i++) s += "0"; return s;' | 773 script = 's = ""; for (i = 0; i < 10e6; i++) s += "0"; return s;' |
774 lots_of_data = self._driver.ExecuteScript(script) | 774 lots_of_data = self._driver.ExecuteScript(script) |
775 self.assertEquals('0'.zfill(int(10e6)), lots_of_data) | 775 self.assertEquals('0'.zfill(int(10e6)), lots_of_data) |
776 | 776 |
777 def testEmulateNetworkConditions(self): | |
778 # DSL: 2Mbps throughput, 5ms RTT | |
779 latency = 5 | |
780 throughput = 2048 * 1024 | |
781 self._driver.SetNetworkConditions(latency, throughput, throughput) | |
782 | |
783 network = self._driver.GetNetworkConditions() | |
784 self.assertEquals(latency, network['latency']); | |
785 self.assertEquals(throughput, network['download_throughput']); | |
786 self.assertEquals(throughput, network['upload_throughput']); | |
787 | |
788 def testEmulateNetworkConditionsSpeed(self): | |
789 # Warm up the browser. | |
790 self._http_server.SetDataForPath( | |
791 '/', "<html><body>blank</body></html>") | |
792 self._driver.Load(self._http_server.GetUrl() + '/') | |
793 | |
794 # DSL: 2Mbps throughput, 5ms RTT | |
795 latency = 5 | |
796 throughput_kbps = 2000 | |
797 throughput = throughput_kbps * 1024 | |
798 self._driver.SetNetworkConditions(latency, throughput, throughput) | |
799 | |
800 _32_bytes = " 0 1 2 3 4 5 6 7 8 9 A B C D E F" | |
801 self._http_server.SetDataForPath( | |
802 '/1MB', | |
803 "<html><body>%s</body></html>" % (_32_bytes * 32768)) | |
804 start = time.time() | |
805 self._driver.Load(self._http_server.GetUrl() + '/1MB') | |
806 finish = time.time() | |
807 duration = finish-start | |
808 actual_throughput_kbps = 1024 / duration | |
809 self.assertLessEqual(actual_throughput_kbps, throughput_kbps * 1.333) | |
810 self.assertGreaterEqual(actual_throughput_kbps, throughput_kbps / 1.333) | |
samuong
2015/02/11 23:22:14
I'm a bit concerned about flakiness for these test
srawlins
2015/02/25 22:40:57
I can presumably add a latency check as well that
| |
811 | |
777 def testShadowDomFindElementWithSlashDeep(self): | 812 def testShadowDomFindElementWithSlashDeep(self): |
778 """Checks that chromedriver can find elements in a shadow DOM using /deep/ | 813 """Checks that chromedriver can find elements in a shadow DOM using /deep/ |
779 css selectors.""" | 814 css selectors.""" |
780 self._driver.Load(self.GetHttpUrlForFile( | 815 self._driver.Load(self.GetHttpUrlForFile( |
781 '/chromedriver/shadow_dom_test.html')) | 816 '/chromedriver/shadow_dom_test.html')) |
782 self.assertTrue(self._driver.FindElement("css", "* /deep/ #olderTextBox")) | 817 self.assertTrue(self._driver.FindElement("css", "* /deep/ #olderTextBox")) |
783 | 818 |
784 def testShadowDomFindChildElement(self): | 819 def testShadowDomFindChildElement(self): |
785 """Checks that chromedriver can find child elements from a shadow DOM | 820 """Checks that chromedriver can find child elements from a shadow DOM |
786 element.""" | 821 element.""" |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1435 | 1470 |
1436 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 1471 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
1437 sys.modules[__name__]) | 1472 sys.modules[__name__]) |
1438 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) | 1473 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) |
1439 ChromeDriverTest.GlobalSetUp() | 1474 ChromeDriverTest.GlobalSetUp() |
1440 MobileEmulationCapabilityTest.GlobalSetUp() | 1475 MobileEmulationCapabilityTest.GlobalSetUp() |
1441 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) | 1476 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) |
1442 ChromeDriverTest.GlobalTearDown() | 1477 ChromeDriverTest.GlobalTearDown() |
1443 MobileEmulationCapabilityTest.GlobalTearDown() | 1478 MobileEmulationCapabilityTest.GlobalTearDown() |
1444 sys.exit(len(result.failures) + len(result.errors)) | 1479 sys.exit(len(result.failures) + len(result.errors)) |
OLD | NEW |