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 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 self.assertEquals(latency, network['latency']); | 876 self.assertEquals(latency, network['latency']); |
877 self.assertEquals(throughput, network['download_throughput']); | 877 self.assertEquals(throughput, network['download_throughput']); |
878 self.assertEquals(throughput, network['upload_throughput']); | 878 self.assertEquals(throughput, network['upload_throughput']); |
879 self.assertEquals(False, network['offline']); | 879 self.assertEquals(False, network['offline']); |
880 | 880 |
881 # Network Conditions again cannot be retrieved after they've been deleted. | 881 # Network Conditions again cannot be retrieved after they've been deleted. |
882 self._driver.DeleteNetworkConditions() | 882 self._driver.DeleteNetworkConditions() |
883 self.assertRaises(chromedriver.UnknownError, | 883 self.assertRaises(chromedriver.UnknownError, |
884 self._driver.GetNetworkConditions) | 884 self._driver.GetNetworkConditions) |
885 | 885 |
| 886 def testEmulateNetworkConnection(self): |
| 887 # Network conditions must be set before it can be retrieved. |
| 888 self.assertRaises(chromedriver.UnknownError, |
| 889 self._driver.GetNetworkConditions) |
| 890 |
| 891 # Test 4G connection. |
| 892 connection_type = 0x8 |
| 893 self._driver.SetNetworkConnection(connection_type) |
| 894 network = self._driver.GetNetworkConditions() |
| 895 self.assertEquals(network['latency'], 20) |
| 896 self.assertEquals(network['upload_throughput'], 4096 * 1024) |
| 897 self.assertEquals(network['upload_throughput'], 4096 * 1024) |
| 898 self.assertEquals(network['offline'], False) |
| 899 |
| 900 # Test 3G connection. |
| 901 connection_type = 0x10 |
| 902 self._driver.SetNetworkConnection(connection_type) |
| 903 network = self._driver.GetNetworkConditions() |
| 904 self.assertEquals(network['latency'], 100) |
| 905 self.assertEquals(network['upload_throughput'], 750 * 1024) |
| 906 self.assertEquals(network['upload_throughput'], 750 * 1024) |
| 907 self.assertEquals(network['offline'], False) |
| 908 |
| 909 # Test 2G connection. |
| 910 connection_type = 0x20 |
| 911 self._driver.SetNetworkConnection(connection_type) |
| 912 network = self._driver.GetNetworkConditions() |
| 913 self.assertEquals(network['latency'], 300) |
| 914 self.assertEquals(network['upload_throughput'], 250 * 1024) |
| 915 self.assertEquals(network['upload_throughput'], 250 * 1024) |
| 916 self.assertEquals(network['offline'], False) |
| 917 |
| 918 # Connection with 4G, 3G, and 2G bits on. |
| 919 # Tests that 4G takes precedence. |
| 920 connection_type = 0x38 |
| 921 self._driver.SetNetworkConnection(connection_type) |
| 922 network = self._driver.GetNetworkConditions() |
| 923 self.assertEquals(network['latency'], 20) |
| 924 self.assertEquals(network['upload_throughput'], 4096 * 1024) |
| 925 self.assertEquals(network['upload_throughput'], 4096 * 1024) |
| 926 self.assertEquals(network['offline'], False) |
| 927 |
| 928 # Network Conditions again cannot be retrieved after they've been deleted. |
| 929 self._driver.DeleteNetworkConditions() |
| 930 self.assertRaises(chromedriver.UnknownError, |
| 931 self._driver.GetNetworkConditions) |
| 932 |
| 933 def testWifiEmulation(self): |
| 934 connection_type = 0x2 |
| 935 self._driver.SetNetworkConnection(connection_type) |
| 936 network = self._driver.GetNetworkConditions() |
| 937 self.assertEquals(network['latency'], 2) |
| 938 self.assertEquals(network['upload_throughput'], 30720 * 1024) |
| 939 self.assertEquals(network['download_throughput'], 30720 * 1024) |
| 940 self.assertEquals(network['offline'], False) |
| 941 |
| 942 def testAirplaneModeEmulation(self): |
| 943 connection_type = 0x1 |
| 944 self._driver.SetNetworkConnection(connection_type) |
| 945 network = self._driver.GetNetworkConditions() |
| 946 self.assertEquals(network['latency'], 0) |
| 947 self.assertEquals(network['upload_throughput'], 0) |
| 948 self.assertEquals(network['download_throughput'], 0) |
| 949 self.assertEquals(network['offline'], True) |
| 950 |
| 951 def testWifiAndAirplaneModeEmulation(self): |
| 952 # Connection with both Wifi and Airplane Mode on. |
| 953 # Tests that Wifi takes precedence over Airplane Mode. |
| 954 connection_type = 0x3 |
| 955 self._driver.SetNetworkConnection(connection_type) |
| 956 network = self._driver.GetNetworkConditions() |
| 957 self.assertEquals(network['latency'], 2) |
| 958 self.assertEquals(network['upload_throughput'], 30720 * 1024) |
| 959 self.assertEquals(network['download_throughput'], 30720 * 1024) |
| 960 self.assertEquals(network['offline'], False) |
| 961 |
| 962 def testNetworkConnectionAcrossTabs(self): |
| 963 # Set network to online |
| 964 connection_type = 0x10 |
| 965 self._driver.SetNetworkConnection(connection_type) |
| 966 network = self._driver.GetNetworkConditions() |
| 967 self.assertEquals(network['latency'], 100) |
| 968 self.assertEquals(network['upload_throughput'], 750 * 1024) |
| 969 self.assertEquals(network['offline'], False) |
| 970 |
| 971 # Open a window with two divs counting successful + unsuccessful |
| 972 # attempts to complete XML task |
| 973 self._driver.Load( |
| 974 self.GetHttpUrlForFile('/chromedriver/xmlrequest_test.html')) |
| 975 |
| 976 def respondWithString(request): |
| 977 return {}, """ |
| 978 <html> |
| 979 <body>%s</body> |
| 980 </html>""" % "hello world!" |
| 981 |
| 982 self._http_server.SetCallbackForPath( |
| 983 '/helloworld', respondWithString) |
| 984 |
| 985 self.assertEquals( |
| 986 1, self._driver.ExecuteScript('window.name = "oldWindow"; return 1;')) |
| 987 window1_handle = self._driver.GetCurrentWindowHandle() |
| 988 old_handles = self._driver.GetWindowHandles() |
| 989 self._driver.FindElement('id', 'requestButton').Click() |
| 990 |
| 991 self._driver.FindElement('id', 'link').Click() |
| 992 new_window_handle = self.WaitForNewWindow(self._driver, old_handles) |
| 993 self.assertNotEqual(None, new_window_handle) |
| 994 self._driver.SwitchToWindow(new_window_handle) |
| 995 self.assertEquals(new_window_handle, self._driver.GetCurrentWindowHandle()) |
| 996 |
| 997 # Set network to offline to determine whether the XML task continues to |
| 998 # run in the background, indicating that the conditions are only applied |
| 999 # to the current WebView |
| 1000 connection_type = 0x1 |
| 1001 self._driver.SetNetworkConnection(connection_type) |
| 1002 network = self._driver.GetNetworkConditions() |
| 1003 self.assertEquals(network['latency'], 0) |
| 1004 self.assertEquals(network['offline'], True) |
| 1005 |
| 1006 self._driver.SwitchToWindow(window1_handle) |
| 1007 connection_type = 0x1 |
| 1008 self._driver.SetNetworkConnection(connection_type) |
| 1009 self.assertEquals(network['latency'], 0) |
| 1010 self.assertEquals(network['offline'], True) |
| 1011 |
| 1012 def testNetworkConditionsDifferentWebViews(self): |
| 1013 |
| 1014 self.assertRaises(chromedriver.UnknownError, |
| 1015 self._driver.GetNetworkConditions) |
| 1016 |
| 1017 self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html')) |
| 1018 self.assertEquals( |
| 1019 1, self._driver.ExecuteScript('window.name = "oldWindow"; return 1;')) |
| 1020 window1_handle = self._driver.GetCurrentWindowHandle() |
| 1021 old_handles = self._driver.GetWindowHandles() |
| 1022 |
| 1023 # Test connection is offline. |
| 1024 connection_type = 0x1; |
| 1025 self._driver.SetNetworkConnection(connection_type) |
| 1026 network = self._driver.GetNetworkConditions() |
| 1027 self.assertEquals(network['latency'], 0) |
| 1028 self.assertEquals(network['offline'], True) |
| 1029 |
| 1030 # Navigate to another window. |
| 1031 self._driver.FindElement('id', 'link').Click() |
| 1032 new_window_handle = self.WaitForNewWindow(self._driver, old_handles) |
| 1033 self.assertNotEqual(None, new_window_handle) |
| 1034 self._driver.SwitchToWindow(new_window_handle) |
| 1035 self.assertEquals(new_window_handle, self._driver.GetCurrentWindowHandle()) |
| 1036 self.assertRaises( |
| 1037 chromedriver.NoSuchElement, self._driver.FindElement, 'id', 'link') |
| 1038 |
| 1039 # Set connection to 3G in second window. |
| 1040 connection_type = 0x10; |
| 1041 self._driver.SetNetworkConnection(connection_type) |
| 1042 network = self._driver.GetNetworkConditions() |
| 1043 self.assertEquals(network['latency'], 100) |
| 1044 self.assertEquals(network['upload_throughput'], 750 * 1024) |
| 1045 self.assertEquals(network['offline'], False) |
| 1046 |
| 1047 self._driver.SwitchToWindow('oldWindow') |
| 1048 self.assertEquals(window1_handle, self._driver.GetCurrentWindowHandle()) |
| 1049 |
| 1050 # Test whether first window has old or new network conditions. |
| 1051 network = self._driver.GetNetworkConditions() |
| 1052 self.assertEquals(network['latency'], 100) |
| 1053 |
886 def testEmulateNetworkConditionsName(self): | 1054 def testEmulateNetworkConditionsName(self): |
887 # DSL: 2Mbps throughput, 5ms RTT | 1055 # DSL: 2Mbps throughput, 5ms RTT |
888 #latency = 5 | 1056 #latency = 5 |
889 #throughput = 2048 * 1024 | 1057 #throughput = 2048 * 1024 |
890 self._driver.SetNetworkConditionsName('DSL') | 1058 self._driver.SetNetworkConditionsName('DSL') |
891 | 1059 |
892 network = self._driver.GetNetworkConditions() | 1060 network = self._driver.GetNetworkConditions() |
893 self.assertEquals(5, network['latency']); | 1061 self.assertEquals(5, network['latency']); |
894 self.assertEquals(2048*1024, network['download_throughput']); | 1062 self.assertEquals(2048*1024, network['download_throughput']); |
895 self.assertEquals(2048*1024, network['upload_throughput']); | 1063 self.assertEquals(2048*1024, network['upload_throughput']); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 """ | 1714 """ |
1547 | 1715 |
1548 @staticmethod | 1716 @staticmethod |
1549 def GlobalSetUp(): | 1717 def GlobalSetUp(): |
1550 def respondWithUserAgentString(request): | 1718 def respondWithUserAgentString(request): |
1551 return {}, """ | 1719 return {}, """ |
1552 <html> | 1720 <html> |
1553 <body>%s</body> | 1721 <body>%s</body> |
1554 </html>""" % request.GetHeader('User-Agent') | 1722 </html>""" % request.GetHeader('User-Agent') |
1555 | 1723 |
| 1724 #def respondWithHello(request): |
| 1725 # return {}, """ |
| 1726 # <html> |
| 1727 # <body>%s</body> |
| 1728 # </html>""" % hello |
| 1729 |
1556 def respondWithUserAgentStringUseDeviceWidth(request): | 1730 def respondWithUserAgentStringUseDeviceWidth(request): |
1557 return {}, """ | 1731 return {}, """ |
1558 <html> | 1732 <html> |
1559 <head> | 1733 <head> |
1560 <meta name="viewport" content="width=device-width,minimum-scale=1.0"> | 1734 <meta name="viewport" content="width=device-width,minimum-scale=1.0"> |
1561 </head> | 1735 </head> |
1562 <body>%s</body> | 1736 <body>%s</body> |
1563 </html>""" % request.GetHeader('User-Agent') | 1737 </html>""" % request.GetHeader('User-Agent') |
1564 | 1738 |
1565 MobileEmulationCapabilityTest._http_server = webserver.WebServer( | 1739 MobileEmulationCapabilityTest._http_server = webserver.WebServer( |
1566 chrome_paths.GetTestData()) | 1740 chrome_paths.GetTestData()) |
1567 MobileEmulationCapabilityTest._http_server.SetCallbackForPath( | 1741 MobileEmulationCapabilityTest._http_server.SetCallbackForPath( |
1568 '/userAgent', respondWithUserAgentString) | 1742 '/userAgent', respondWithUserAgentString) |
1569 MobileEmulationCapabilityTest._http_server.SetCallbackForPath( | 1743 MobileEmulationCapabilityTest._http_server.SetCallbackForPath( |
1570 '/userAgentUseDeviceWidth', respondWithUserAgentStringUseDeviceWidth) | 1744 '/userAgentUseDeviceWidth', respondWithUserAgentStringUseDeviceWidth) |
| 1745 #testNetworkConnectionAcrossTabs._http_server.SetCallbackForPath( |
| 1746 # '/hello', respondWithHello) |
1571 | 1747 |
1572 @staticmethod | 1748 @staticmethod |
1573 def GlobalTearDown(): | 1749 def GlobalTearDown(): |
1574 MobileEmulationCapabilityTest._http_server.Shutdown() | 1750 MobileEmulationCapabilityTest._http_server.Shutdown() |
1575 | 1751 |
1576 def testDeviceMetricsWithStandardWidth(self): | 1752 def testDeviceMetricsWithStandardWidth(self): |
1577 driver = self.CreateDriver( | 1753 driver = self.CreateDriver( |
1578 mobile_emulation = { | 1754 mobile_emulation = { |
1579 'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}, | 1755 'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}, |
1580 'userAgent': 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Bui' | 1756 'userAgent': 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Bui' |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 | 2108 |
1933 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 2109 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
1934 sys.modules[__name__]) | 2110 sys.modules[__name__]) |
1935 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) | 2111 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) |
1936 ChromeDriverTest.GlobalSetUp() | 2112 ChromeDriverTest.GlobalSetUp() |
1937 MobileEmulationCapabilityTest.GlobalSetUp() | 2113 MobileEmulationCapabilityTest.GlobalSetUp() |
1938 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) | 2114 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) |
1939 ChromeDriverTest.GlobalTearDown() | 2115 ChromeDriverTest.GlobalTearDown() |
1940 MobileEmulationCapabilityTest.GlobalTearDown() | 2116 MobileEmulationCapabilityTest.GlobalTearDown() |
1941 sys.exit(len(result.failures) + len(result.errors)) | 2117 sys.exit(len(result.failures) + len(result.errors)) |
OLD | NEW |