Commit c7645040 authored by samuong's avatar samuong Committed by Commit bot

[chromedriver] Quit Chrome before cleaning up temporary directories

BUG=
NOTRY=true
TBR=stgao@chromium.org

Review URL: https://codereview.chromium.org/671433005

Cr-Commit-Position: refs/heads/master@{#300695}
parent 7f1ee85f
...@@ -105,6 +105,7 @@ _ANDROID_NEGATIVE_FILTER['chrome'] = ( ...@@ -105,6 +105,7 @@ _ANDROID_NEGATIVE_FILTER['chrome'] = (
'ChromeSwitchesCapabilityTest.*', 'ChromeSwitchesCapabilityTest.*',
'ChromeExtensionsCapabilityTest.*', 'ChromeExtensionsCapabilityTest.*',
'MobileEmulationCapabilityTest.*', 'MobileEmulationCapabilityTest.*',
'ChromeDownloadDirTest.*',
# https://crbug.com/274650 # https://crbug.com/274650
'ChromeDriverTest.testCloseWindow', 'ChromeDriverTest.testCloseWindow',
# https://code.google.com/p/chromedriver/issues/detail?id=270 # https://code.google.com/p/chromedriver/issues/detail?id=270
...@@ -771,30 +772,40 @@ class ChromeDriverAndroidTest(ChromeDriverBaseTest): ...@@ -771,30 +772,40 @@ class ChromeDriverAndroidTest(ChromeDriverBaseTest):
class ChromeDownloadDirTest(ChromeDriverBaseTest): class ChromeDownloadDirTest(ChromeDriverBaseTest):
def testFileDownLoad(self): def __init__(self, *args, **kwargs):
try: super(ChromeDownloadDirTest, self).__init__(*args, **kwargs)
self.download_dir = tempfile.mkdtemp() self._temp_dirs = []
download_name = os.path.join(self.download_dir, 'a_red_dot.png')
driver = self.CreateDriver(download_dir=self.download_dir) def CreateTempDir(self):
temp_dir = tempfile.mkdtemp()
self._temp_dirs.append(temp_dir)
return temp_dir
def tearDown(self):
# Call the superclass tearDown() method before deleting temp dirs, so that
# Chrome has a chance to exit before its user data dir is blown away from
# underneath it.
super(ChromeDownloadDirTest, self).tearDown()
for temp_dir in self._temp_dirs:
shutil.rmtree(temp_dir)
def testFileDownload(self):
download_dir = self.CreateTempDir()
download_name = os.path.join(download_dir, 'a_red_dot.png')
driver = self.CreateDriver(download_dir=download_dir)
driver.Load(ChromeDriverTest.GetHttpUrlForFile( driver.Load(ChromeDriverTest.GetHttpUrlForFile(
'/chromedriver/download.html')) '/chromedriver/download.html'))
driver.FindElement('id', 'red-dot').Click() driver.FindElement('id', 'red-dot').Click()
deadline = time.time() + 60 deadline = time.time() + 60
while True: while True:
time.sleep(0.1) time.sleep(0.1)
if os.path.isfile(download_name) or time.time() > deadline: if os.path.isfile(download_name) or time.time() > deadline:
break break
self.assertTrue(os.path.isfile(download_name), "Failed to download file!") self.assertTrue(os.path.isfile(download_name), "Failed to download file!")
finally:
shutil.rmtree(self.download_dir)
def testDownloadDirectoryOverridesExistingPreferences(self): def testDownloadDirectoryOverridesExistingPreferences(self):
""" test existing prefence profile - check setting if it is correct """ user_data_dir = self.CreateTempDir()
download_dir = self.CreateTempDir()
try:
user_data_dir = tempfile.mkdtemp()
tmp_download_dir = tempfile.mkdtemp()
sub_dir = os.path.join(user_data_dir, 'Default') sub_dir = os.path.join(user_data_dir, 'Default')
os.mkdir(sub_dir) os.mkdir(sub_dir)
prefs_file_path = os.path.join(sub_dir, 'Preferences') prefs_file_path = os.path.join(sub_dir, 'Preferences')
...@@ -811,19 +822,14 @@ class ChromeDownloadDirTest(ChromeDriverBaseTest): ...@@ -811,19 +822,14 @@ class ChromeDownloadDirTest(ChromeDriverBaseTest):
driver = self.CreateDriver( driver = self.CreateDriver(
chrome_switches=['user-data-dir=' + user_data_dir], chrome_switches=['user-data-dir=' + user_data_dir],
download_dir = tmp_download_dir) download_dir=download_dir)
with open(prefs_file_path) as f: with open(prefs_file_path) as f:
prefs = json.load(f) prefs = json.load(f)
self.assertEqual('this should not be changed', prefs['test'], self.assertEqual('this should not be changed', prefs['test'])
"Existing preference was unexpectedly overridden")
download = prefs['download'] download = prefs['download']
self.assertEqual(download['default_directory'], tmp_download_dir, self.assertEqual(download['default_directory'], download_dir)
'Download directory preference was not updated to match capabilities')
finally:
shutil.rmtree(user_data_dir)
shutil.rmtree(tmp_download_dir)
class ChromeSwitchesCapabilityTest(ChromeDriverBaseTest): class ChromeSwitchesCapabilityTest(ChromeDriverBaseTest):
"""Tests that chromedriver properly processes chromeOptions.args capabilities. """Tests that chromedriver properly processes chromeOptions.args capabilities.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment