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

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: Changed hard coded network values to constants. Fixed style issues. 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..7190823e399bcc76e647d3b57030c8a67a3127cc 100755
--- a/chrome/test/chromedriver/test/run_py_tests.py
+++ b/chrome/test/chromedriver/test/run_py_tests.py
@@ -883,6 +883,126 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
self.assertRaises(chromedriver.UnknownError,
self._driver.GetNetworkConditions)
+ def testEmulateNetworkConnection(self):
+
prasadv 2016/06/20 20:29:09 Remove this blank line.
roisinmcl 2016/06/21 18:55:11 Done.
+ # Network conditions must be set before it can be retrieved.
prasadv 2016/06/20 20:29:09 Sam@ I'm not sure chromedriver unittesting guideli
samuong 2016/06/20 21:43:23 I think that makes sense - we could probably split
roisinmcl 2016/06/21 18:55:11 I added three tests dealing with the different typ
+ 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
prasadv 2016/06/20 20:29:09 s/couting/counting
roisinmcl 2016/06/21 18:55:11 Done.
+ # attempts to complete XML task
prasadv 2016/06/20 20:29:09 s/attemps/Attempts
roisinmcl 2016/06/21 18:55:11 This is meant to read as one sentence broken up fo
+ self._driver.Load(self.GetHttpUrlForFile(
prasadv 2016/06/20 20:29:09 Alternatively you can do this: self._driver.Load(
roisinmcl 2016/06/21 18:55:11 Done.
+ '/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()
+
+ # Open another window
prasadv 2016/06/20 20:29:10 As per the style guide, you don't want to write co
roisinmcl 2016/06/21 18:55:11 Done.
+ 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)
+
+ 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):
+
+ 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,
prasadv 2016/06/20 20:29:10 self.assertRaises( chromedriver.NoSuchElement,
roisinmcl 2016/06/21 18:55:11 Done.
+ 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 +1673,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 +1694,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