Bug 1233679 - UpdateTestcase should remove any partially downloaded update. r?maja_zf
MozReview-Commit-ID: FpKDcElYF7L
--- a/testing/firefox-ui/harness/firefox_ui_harness/testcases.py
+++ b/testing/firefox-ui/harness/firefox_ui_harness/testcases.py
@@ -1,15 +1,17 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import pprint
from datetime import datetime
+import mozfile
+
from marionette import MarionetteTestCase
from marionette_driver import Wait
from firefox_puppeteer.api.prefs import Preferences
from firefox_puppeteer.api.software_update import SoftwareUpdate
from firefox_puppeteer.testcases import BaseFirefoxTestCase
from firefox_puppeteer.ui.update_wizard import UpdateWizardDialog
@@ -52,17 +54,18 @@ class UpdateTestCase(FirefoxTestCase):
super(UpdateTestCase, self).setUp()
self.software_update = SoftwareUpdate(lambda: self.marionette)
self.download_duration = None
# Bug 604364 - Preparation to test multiple update steps
self.current_update_index = 0
- self.staging_directory = self.software_update.staging_directory
+ # Ensure that there exists no already partially downloaded update
+ self.remove_downloaded_update()
# If requested modify the default update channel. It will be active
# after the next restart of the application
# Bug 1142805 - Modify file via Python directly
if self.update_channel:
# Backup the original content and the path of the channel-prefs.js file
self.default_update_channel = {
'content': self.software_update.update_channel.file_contents,
@@ -113,16 +116,19 @@ class UpdateTestCase(FirefoxTestCase):
# Print results for now until we have treeherder integration
output = pprint.pformat(self.updates)
self.logger.info('Update test results: \n{}'.format(output))
finally:
super(UpdateTestCase, self).tearDown()
+ # Ensure that no trace of an partially downloaded update remain
+ self.remove_downloaded_update()
+
self.restore_config_files()
@property
def patch_info(self):
""" Returns information about the active update in the queue.
:returns: A dictionary with information about the active patch
"""
@@ -357,16 +363,22 @@ class UpdateTestCase(FirefoxTestCase):
dialog.close()
finally:
self.updates[self.current_update_index]['patch'] = self.patch_info
# Restart Firefox to apply the update
self.restart()
+ def remove_downloaded_update(self):
+ """Remove an already downloaded update from the update staging directory."""
+ self.logger.info('Clean-up update staging directory: {}'.format(
+ self.software_update.staging_directory))
+ mozfile.remove(self.software_update.staging_directory)
+
def restore_config_files(self):
# Reset channel-prefs.js file if modified
try:
if self.default_update_channel:
path = self.default_update_channel['path']
self.logger.info('Restoring channel defaults for: {}'.format(path))
with open(path, 'w') as f:
f.write(self.default_update_channel['content'])