Index: chrome/test/chromedriver/client/run_py_tests.py |
diff --git a/chrome/test/chromedriver/test/run_py_tests.py b/chrome/test/chromedriver/client/run_py_tests.py |
similarity index 94% |
copy from chrome/test/chromedriver/test/run_py_tests.py |
copy to chrome/test/chromedriver/client/run_py_tests.py |
index 2b106a6783a372544520a9fcae0f182b673be9e2..dbed62ace8d4c9ea942f73b83593ef812c18e549 100755 |
--- a/chrome/test/chromedriver/test/run_py_tests.py |
+++ b/chrome/test/chromedriver/client/run_py_tests.py |
@@ -152,7 +152,7 @@ class ChromeDriverBaseTest(unittest.TestCase): |
except: |
pass |
- def CreateDriver(self, server_url=None, **kwargs): |
+ def CreateDriver(self, server_url=None, download_dir=None, **kwargs): |
if server_url is None: |
server_url = _CHROMEDRIVER_SERVER_URL |
@@ -165,7 +165,7 @@ class ChromeDriverBaseTest(unittest.TestCase): |
android_activity = constants.PACKAGE_INFO[_ANDROID_PACKAGE_KEY].activity |
android_process = '%s:main' % android_package |
- driver = chromedriver.ChromeDriver(server_url, |
+ driver = chromedriver.ChromeDriver(server_url, download_dir, |
chrome_binary=_CHROME_BINARY, |
android_package=android_package, |
android_activity=android_activity, |
@@ -203,11 +203,43 @@ class ChromeDriverTest(ChromeDriverBaseTest): |
return ChromeDriverTest._http_server.GetUrl() + file_path |
def setUp(self): |
- self._driver = self.CreateDriver() |
+ if self._testMethodName == 'testFileDownLoad': |
+ self.download_dir = tempfile.mkdtemp(dir='/tmp') |
samuong
2014/10/15 22:08:18
By default, tempfile.mkdtemp() will use dir='/tmp'
|
+ else: |
+ self.download_dir = None |
+ self._driver = self.CreateDriver(download_dir=self.download_dir) |
+ |
+ def tearDown(self): |
+ try: |
+ if self.download_dir: |
+ os.removedirs(self.download_dir) |
+ self.download_dir = None |
+ except: |
+ pass |
samuong
2014/10/15 22:08:17
If and when this fails, let's print out a proper e
|
+ ChromeDriverBaseTest.tearDown(self) |
def testStartStop(self): |
pass |
+ def testFileDownLoad(self): |
+ # check download file to make sure it does not exist |
+ download_name = self.download_dir + "/a_red_dot.png"; |
samuong
2014/10/15 22:08:18
Windows uses "\" as the directory separator, so yo
|
+ self.assertFalse(os.path.isfile(download_name), |
samuong
2014/10/15 22:08:18
If there's a directory called "a_red_dot.png" then
|
+ "Test prefer download directory failed! - download file already exist") |
+ # |
+ self._driver.Load(self.GetHttpUrlForFile('/chromedriver/download.html')) |
+ self._driver.FindElement('id', 'red-dot').Click() |
+ # wait until download completed |
+ timeout = time.time() + 60*1 # 1 minutes from now |
samuong
2014/10/15 22:08:18
How about we call this variable "deadline" instead
|
+ while True: |
+ time.sleep(0.1) |
+ if os.path.isfile(download_name) or time.time() > timeout: |
+ break |
+ # |
+ self.assertTrue(os.path.isfile(download_name), |
+ "Test user prefer download directory failed!") |
+ os.remove(download_name) |
+ |
def testLoadUrl(self): |
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html')) |
@@ -750,6 +782,34 @@ class ChromeDriverAndroidTest(ChromeDriverBaseTest): |
self._drivers[0].Quit() |
self._drivers[0] = self.CreateDriver() |
+class ChromeDownloadDirTest(ChromeDriverBaseTest): |
+ |
+ # test existing prefence profile - check setting if it is correct |
+ def testDownloadDirectoryOverridesExistingPreferences(self): |
+ userDataDir='/usr/local/google/home/andrewcheng/zz' |
samuong
2014/10/15 22:08:17
Please don't hardcode your home directory into tes
|
+ defPrefFile = userDataDir+'/Default/Preferences' |
samuong
2014/10/15 22:08:17
For both defPrefFile and userDataDir, use names wi
|
+ # |
samuong
2014/10/15 22:08:18
Also for consistency with the existing style in th
|
+ data = {} |
+ test_dir = {} |
+ test_dir['directory_upgrade'] = 'true' |
+ test_dir['default_directory'] = '/old/download/directory' |
+ data['test'] = 'this should not be changed' |
+ data['download'] = test_dir |
samuong
2014/10/15 22:08:18
How about we change these lines above so that data
|
+ # |
+ with open(defPrefFile, 'w') as outfile: |
+ json.dump(data, outfile) |
+ |
+ driver = self.CreateDriver(chrome_switches= |
+ ['user-data-dir='+userDataDir], |
+ download_dir="/usr/local/google/home/andrewcheng/zz") |
samuong
2014/10/15 22:08:17
You're setting the user data directory to the same
|
+ |
+ with open(defPrefFile) as inFile: data = json.load(inFile) |
samuong
2014/10/15 22:08:18
Please break the above line up into two lines:
wi
|
+ self.assertEqual(data['test'], 'this should not be changed', |
samuong
2014/10/15 22:08:17
Before doing this assert, please also check that t
|
+ "test data has changed") |
samuong
2014/10/15 22:08:18
"test data has changed" doesn't really tell anyone
|
+ download = data['download'] |
+ self.assertEqual(download['default_directory'], |
+ '/usr/local/google/home/andrewcheng/zz', |
+ "default_directory is not set") |
class ChromeSwitchesCapabilityTest(ChromeDriverBaseTest): |
"""Tests that chromedriver properly processes chromeOptions.args capabilities. |