Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11149)

Unified Diff: chrome/test/chromedriver/test/run_py_tests.py

Issue 2065733002: Add a method to override the network conditions of the ChromeDriver session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test XHR with setting network emulation and refactored netowrk setter method Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ada88f570ab206634cfea7d45438a9bcf09be35f 100755
--- a/chrome/test/chromedriver/test/run_py_tests.py
+++ b/chrome/test/chromedriver/test/run_py_tests.py
@@ -883,6 +883,136 @@ 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 offline connection.
+ connection_type = 0x1;
+ self._driver.SetNetworkConnection(connection_type)
+ network = self._driver.GetNetworkConditions()
+ self.assertEquals(network['latency'], 0)
+ self.assertEquals(network['offline'], True)
+
+ # 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['offline'], False)
+
+
+ # Network Conditions again cannot be retrieved after they've been deleted.
+ self._driver.DeleteNetworkConditions()
+ self.assertRaises(chromedriver.UnknownError,
+ self._driver.GetNetworkConditions)
+
+
+ def testNetworkConnectionAcrossTabs(self):
+
+ # 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)
+ self.assertEquals(network['offline'], False)
+
+ # Open a window with two divs couting successful + unsuccessful
+ # attempts to complete XML task
+ self._driver.Load(self.GetHttpUrlForFile('/chromedriver/xmlrequest_test.html'))
+
+ def respondWithString(request):
+ return {}, """
+ <html>
+ <body>%s</body>
+ </html>""" % "hello world!"
+
+ self._http_server.SetCallbackForPath(
+ '/helloworld', respondWithString)
+
+ self.assertEquals(
+ 1, self._driver.ExecuteScript('window.name = "oldWindow"; return 1;'))
+ window1_handle = self._driver.GetCurrentWindowHandle()
+ old_handles = self._driver.GetWindowHandles()
+ self._driver.FindElement('id', 'requestButton').Click()
+ time.sleep(2)
+
+ # Open 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())
+
+ # Set network connection to offline (airplane)
+ connection_type = 0x1;
+ self._driver.SetNetworkConnection(connection_type)
+ network = self._driver.GetNetworkConditions()
+ self.assertEquals(network['latency'], 0)
+ self.assertEquals(network['offline'], True)
+
+ time.sleep(3)
+
+ self._driver.SwitchToWindow(window1_handle)
+ connection_type = 0x1;
+ self._driver.SetNetworkConnection(connection_type)
+ self.assertEquals(network['latency'], 0)
+ self.assertEquals(network['offline'], True)
+
+ time.sleep(3)
+
+
+ def testNetworkConditionsDifferentWebViews(self):
+
+ self.assertRaises(chromedriver.UnknownError,
+ self._driver.GetNetworkConditions)
+
+
+ # Set up first window.
+ self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
+ self.assertEquals(
+ 1, self._driver.ExecuteScript('window.name = "oldWindow"; return 1;'))
+ 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
@@ -1553,6 +1683,12 @@ class MobileEmulationCapabilityTest(ChromeDriverBaseTest):
<body>%s</body>
</html>""" % request.GetHeader('User-Agent')
+ #def respondWithHello(request):
+ # return {}, """
+ # <html>
+ # <body>%s</body>
+ # </html>""" % hello
+
def respondWithUserAgentStringUseDeviceWidth(request):
return {}, """
<html>
@@ -1568,6 +1704,8 @@ class MobileEmulationCapabilityTest(ChromeDriverBaseTest):
'/userAgent', respondWithUserAgentString)
MobileEmulationCapabilityTest._http_server.SetCallbackForPath(
'/userAgentUseDeviceWidth', respondWithUserAgentStringUseDeviceWidth)
+ #testNetworkConnectionAcrossTabs._http_server.SetCallbackForPath(
+ # '/hello', respondWithHello)
@staticmethod
def GlobalTearDown():

Powered by Google App Engine
This is Rietveld 408576698