def download_via_update_wizard(dialog): """ Download the update via the old update wizard dialog. :param dialog: Instance of :class:`UpdateWizardDialog`. """ prefs = Preferences(lambda: self.marionette) prefs.set_pref(self.PREF_APP_UPDATE_ALTWINDOWTYPE, dialog.window_type) try: # If updates have already been found, proceed to download if dialog.wizard.selected_panel in [ dialog.wizard.updates_found_basic, dialog.wizard.updates_found_billboard, dialog.wizard.error_patching, ]: dialog.select_next_page() # If incompatible add-on are installed, skip over the wizard page # TODO: Remove once we no longer support version Firefox 45.0ESR if self.utils.compare_version(self.appinfo.version, '49.0a1') == -1: if dialog.wizard.selected_panel == dialog.wizard.incompatible_list: dialog.select_next_page() # Updates were stored in the cache, so no download is necessary if dialog.wizard.selected_panel in [ dialog.wizard.finished, dialog.wizard.finished_background, ]: pass # Download the update elif dialog.wizard.selected_panel == dialog.wizard.downloading: if wait_for_finish: start_time = datetime.now() self.wait_for_download_finished(dialog, timeout) self.download_duration = (datetime.now() - start_time).total_seconds() Wait(self.marionette).until( lambda _: (dialog.wizard.selected_panel in [ dialog.wizard.finished, dialog.wizard.finished_background, ]), message='Final wizard page has been selected.') else: raise Exception( 'Invalid wizard page for downloading an update: {}'. format(dialog.wizard.selected_panel)) finally: prefs.restore_pref(self.PREF_APP_UPDATE_ALTWINDOWTYPE)
def download_via_update_wizard(dialog): """ Download the update via the old update wizard dialog. :param dialog: Instance of :class:`UpdateWizardDialog`. """ prefs = Preferences(lambda: self.marionette) prefs.set_pref(self.PREF_APP_UPDATE_ALTWINDOWTYPE, dialog.window_type) try: # If updates have already been found, proceed to download if dialog.wizard.selected_panel in [dialog.wizard.updates_found_basic, dialog.wizard.updates_found_billboard, dialog.wizard.error_patching, ]: dialog.select_next_page() # If incompatible add-on are installed, skip over the wizard page # TODO: Remove once we no longer support version Firefox 45.0ESR if self.utils.compare_version(self.appinfo.version, '49.0a1') == -1: if dialog.wizard.selected_panel == dialog.wizard.incompatible_list: dialog.select_next_page() # Updates were stored in the cache, so no download is necessary if dialog.wizard.selected_panel in [dialog.wizard.finished, dialog.wizard.finished_background, ]: pass # Download the update elif dialog.wizard.selected_panel == dialog.wizard.downloading: if wait_for_finish: start_time = datetime.now() self.wait_for_download_finished(dialog, timeout) self.download_duration = (datetime.now() - start_time).total_seconds() Wait(self.marionette).until(lambda _: ( dialog.wizard.selected_panel in [dialog.wizard.finished, dialog.wizard.finished_background, ]), message='Final wizard page has been selected.') else: raise Exception('Invalid wizard page for downloading an update: {}'.format( dialog.wizard.selected_panel)) finally: prefs.restore_pref(self.PREF_APP_UPDATE_ALTWINDOWTYPE)
class UpdateWizardDialog(BaseWindow): """Representation of the old Software Update Wizard Dialog.""" window_type = 'Update:Wizard' dtds = [ 'chrome://branding/locale/brand.dtd', 'chrome://mozapps/locale/update/updates.dtd', ] properties = [ 'chrome://branding/locale/brand.properties', 'chrome://mozapps/locale/update/updates.properties', ] # For the old update wizard, the errors are displayed inside the dialog. For the # handling of updates in the about window the errors are displayed in new dialogs. # When the old wizard is open we have to set the preference, so the errors will be # shown as expected, otherwise we would have unhandled modal dialogs when errors are raised. # See: # http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/update/nsUpdateService.js?rev=a9240b1eb2fb#4813 # http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/update/nsUpdateService.js?rev=a9240b1eb2fb#4756 PREF_APP_UPDATE_ALTWINDOWTYPE = 'app.update.altwindowtype' TIMEOUT_UPDATE_DOWNLOAD = 360 def __init__(self, *args, **kwargs): BaseWindow.__init__(self, *args, **kwargs) self._prefs = Preferences(lambda: self.marionette) self._software_update = SoftwareUpdate(lambda: self.marionette) self._download_duration = None @property def wizard(self): """The :class:`Wizard` instance which represents the wizard. :returns: Reference to the wizard. """ # The deck is also the root element wizard = self.marionette.find_element(By.ID, 'updates') return Wizard(lambda: self.marionette, self, wizard) @property def patch_info(self): """ Returns information about the active update in the queue. :returns: A dictionary with information about the active patch """ patch = self._software_update.patch_info patch['download_duration'] = self._download_duration return patch def download(self, wait_for_finish=True, timeout=TIMEOUT_UPDATE_DOWNLOAD): """ Download the update. :param wait_for_finish: Optional, if True the function has to wait for the download to be finished, default to `True` :param timeout: Optional, How long to wait for the download to finish, default to 360 seconds """ self._prefs.set_pref(self.PREF_APP_UPDATE_ALTWINDOWTYPE, self.window_type) try: # If updates have already been found, proceed to download if self.wizard.selected_panel in (self.wizard.updates_found_basic, self.wizard.updates_found_billboard, self.wizard.error_patching, ): self.select_next_page() # If incompatible add-on are installed, skip over the wizard page if self.wizard.selected_panel == self.wizard.incompatible_list: self.select_next_page() # Updates were stored in the cache, so no download is necessary if self.wizard.selected_panel in (self.wizard.finished, self.wizard.finished_background, ): pass # Download the update elif self.wizard.selected_panel == self.wizard.downloading: if wait_for_finish: start_time = datetime.now() self.wait_for_download_finished(timeout) self._download_duration = (datetime.now() - start_time).total_seconds() Wait(self.marionette).until( lambda _: self.wizard.selected_panel in (self.wizard.finished, self.wizard.finished_background, ), message='Final wizard page has been selected.') else: raise Exception('Invalid wizard page for downloading an update: {}'.format( self.wizard.selected_panel)) finally: self._prefs.restore_pref(self.PREF_APP_UPDATE_ALTWINDOWTYPE) def select_next_page(self): """Clicks on "Next" button, and waits for the next page to show up.""" current_panel = self.wizard.selected_panel self.wizard.next_button.click() Wait(self.marionette).until(lambda _: self.wizard.selected_panel != current_panel) def wait_for_download_finished(self, timeout=TIMEOUT_UPDATE_DOWNLOAD): """Waits until download is completed. :param timeout: Optional, How long to wait for the download to finish, default to 360 seconds. """ Wait(self.marionette, timeout=timeout).until( lambda _: self.wizard.selected_panel != self.wizard.downloading, message='Download has been completed.') assert self.wizard.selected_panel not in (self.wizard.error, self.wizard.error_extra, ), \ 'Update has been successfully downloaded.'