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 8c0acbdd2744c9cbe0d37f893c49390cdbfb18cc..e5130c1ed07260b556f28b4c95e6c5ccebdb4edd 100755 |
| --- a/chrome/test/chromedriver/test/run_py_tests.py |
| +++ b/chrome/test/chromedriver/test/run_py_tests.py |
| @@ -883,6 +883,176 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer): |
| self.assertRaises(chromedriver.UnknownError, |
| self._driver.GetNetworkConditions) |
| + def testEmulateNetworkConnection(self): |
| + # Network conditions must be set before it can be retrieved. |
| + self.assertRaises(chromedriver.UnknownError, |
| + self._driver.GetNetworkConditions) |
| + |
| + # Test 4G connection. |
| + connection_type = 0x8 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 20) |
| + self.assertEquals(network['upload_throughput'], 4096 * 1024) |
| + self.assertEquals(network['upload_throughput'], 4096 * 1024) |
| + self.assertEquals(network['offline'], False) |
|
samuong
2016/06/29 18:37:54
this looks ok for now but after eva submits her cl
|
| + |
| + # Test 3G connection. |
| + connection_type = 0x10 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 100) |
| + self.assertEquals(network['upload_throughput'], 750 * 1024) |
| + self.assertEquals(network['upload_throughput'], 750 * 1024) |
| + self.assertEquals(network['offline'], False) |
| + |
| + # Test 2G connection. |
| + connection_type = 0x20 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 300) |
| + self.assertEquals(network['upload_throughput'], 250 * 1024) |
| + self.assertEquals(network['upload_throughput'], 250 * 1024) |
| + self.assertEquals(network['offline'], False) |
| + |
| + # Connection with 4G, 3G, and 2G bits on. |
| + # Tests that 4G takes precedence. |
| + connection_type = 0x38 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 20) |
| + self.assertEquals(network['upload_throughput'], 4096 * 1024) |
| + self.assertEquals(network['upload_throughput'], 4096 * 1024) |
| + self.assertEquals(network['offline'], False) |
| + |
| + # Network Conditions again cannot be retrieved after they've been deleted. |
| + self._driver.DeleteNetworkConditions() |
| + self.assertRaises(chromedriver.UnknownError, |
| + self._driver.GetNetworkConditions) |
| + |
| + def testWifiEmulation(self): |
| + connection_type = 0x2 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 2) |
| + self.assertEquals(network['upload_throughput'], 30720 * 1024) |
| + self.assertEquals(network['download_throughput'], 30720 * 1024) |
| + self.assertEquals(network['offline'], False) |
| + |
| + def testAirplaneModeEmulation(self): |
| + connection_type = 0x1 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 0) |
| + self.assertEquals(network['upload_throughput'], 0) |
| + self.assertEquals(network['download_throughput'], 0) |
| + self.assertEquals(network['offline'], True) |
| + |
| + def testWifiAndAirplaneModeEmulation(self): |
| + # Connection with both Wifi and Airplane Mode on. |
| + # Tests that Wifi takes precedence over Airplane Mode. |
| + connection_type = 0x3 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 2) |
| + self.assertEquals(network['upload_throughput'], 30720 * 1024) |
| + self.assertEquals(network['download_throughput'], 30720 * 1024) |
| + self.assertEquals(network['offline'], False) |
| + |
| + def testNetworkConnectionAcrossTabs(self): |
|
samuong
2016/06/29 18:37:54
change name to: testNetworkConnectionTypeIsApplied
roisinmcl
2016/06/29 19:45:00
Done.
|
| + # Set network to online |
| + connection_type = 0x10 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 100) |
| + self.assertEquals(network['upload_throughput'], 750 * 1024) |
|
samuong
2016/06/29 18:37:54
i think it's unnecessary to check latency and thro
roisinmcl
2016/06/29 19:45:00
Done.
|
| + self.assertEquals(network['offline'], False) |
| + |
| + # Open a window with two divs counting successful + unsuccessful |
| + # attempts to complete XML task |
| + self._driver.Load( |
| + self.GetHttpUrlForFile('/chromedriver/xmlrequest_test.html')) |
| + |
| + time.sleep(10) |
|
samuong
2016/06/29 18:37:54
do we actually need to have this call to sleep?
g
roisinmcl
2016/06/29 19:45:00
I was using this to make sure the tests ran correc
|
| + |
| + def respondWithString(request): |
| + return {}, """ |
| + <html> |
| + <body>%s</body> |
| + </html>""" % "hello world!" |
| + |
| + self._http_server.SetCallbackForPath( |
| + '/helloworld', respondWithString) |
|
samuong
2016/06/29 18:37:54
the xmlrequest_test.html page makes requests to th
roisinmcl
2016/06/29 19:45:00
xmlrequest_test.html doesn't use this endpoint unt
samuong
2016/06/29 20:32:08
for consistency, can you move it to the top of the
|
| + |
| + self.assertEquals( |
| + 1, self._driver.ExecuteScript('window.name = "oldWindow"; return 1;')) |
|
samuong
2016/06/29 18:37:54
is it necessary to set window.name here? i don't s
roisinmcl
2016/06/29 19:45:00
I removed this line.
|
| + window1_handle = self._driver.GetCurrentWindowHandle() |
| + old_handles = self._driver.GetWindowHandles() |
| + self._driver.FindElement('id', 'requestButton').Click() |
| + |
| + self._driver.FindElement('id', 'link').Click() |
| + new_window_handle = self.WaitForNewWindow(self._driver, old_handles) |
| + self.assertNotEqual(None, new_window_handle) |
| + self._driver.SwitchToWindow(new_window_handle) |
| + self.assertEquals(new_window_handle, self._driver.GetCurrentWindowHandle()) |
| + |
| + # Set network to offline to determine whether the XML task continues to |
| + # run in the background, indicating that the conditions are only applied |
| + # to the current WebView |
| + connection_type = 0x1 |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 0) |
| + self.assertEquals(network['offline'], True) |
| + |
| + self._driver.SwitchToWindow(window1_handle) |
| + connection_type = 0x1 |
| + self._driver.SetNetworkConnection(connection_type) |
| + self.assertEquals(network['latency'], 0) |
| + self.assertEquals(network['offline'], True) |
| + |
| + def testNetworkConditionsDifferentWebViews(self): |
|
samuong
2016/06/29 18:37:54
change the name of this test to: testNetworkConnec
roisinmcl
2016/06/29 19:45:00
Done.
|
| + |
| + self.assertRaises(chromedriver.UnknownError, |
| + self._driver.GetNetworkConditions) |
| + |
| + self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html')) |
| + self.assertEquals( |
| + 1, self._driver.ExecuteScript('window.name = "oldWindow"; return 1;')) |
|
samuong
2016/06/29 18:37:54
is it necessary to set window.name here? it's used
roisinmcl
2016/06/29 19:45:00
Done.
|
| + window1_handle = self._driver.GetCurrentWindowHandle() |
| + old_handles = self._driver.GetWindowHandles() |
| + |
| + # Test connection is offline. |
| + connection_type = 0x1; |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 0) |
| + self.assertEquals(network['offline'], True) |
| + |
| + # Navigate to another window. |
| + self._driver.FindElement('id', 'link').Click() |
| + new_window_handle = self.WaitForNewWindow(self._driver, old_handles) |
| + self.assertNotEqual(None, new_window_handle) |
| + self._driver.SwitchToWindow(new_window_handle) |
| + self.assertEquals(new_window_handle, self._driver.GetCurrentWindowHandle()) |
| + self.assertRaises( |
| + chromedriver.NoSuchElement, self._driver.FindElement, 'id', 'link') |
| + |
| + # Set connection to 3G in second window. |
| + connection_type = 0x10; |
| + self._driver.SetNetworkConnection(connection_type) |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 100) |
| + self.assertEquals(network['upload_throughput'], 750 * 1024) |
| + self.assertEquals(network['offline'], False) |
| + |
| + self._driver.SwitchToWindow('oldWindow') |
| + self.assertEquals(window1_handle, self._driver.GetCurrentWindowHandle()) |
| + |
| + # Test whether first window has old or new network conditions. |
| + network = self._driver.GetNetworkConditions() |
| + self.assertEquals(network['latency'], 100) |
| + |
| def testEmulateNetworkConditionsName(self): |
| # DSL: 2Mbps throughput, 5ms RTT |
| #latency = 5 |