Example #1
0
    def testDownloadPercentage(self):
        """Verify that during downloading, % values increases,
       and once download is over, % value is 100"""
        file_path = self._MakeFile(2**24)
        # Ensure there's sufficient space remaining to download file.
        free_space = test_utils.GetFreeSpace(
            self.GetDownloadDirectory().value())
        assert free_space >= 2**24, \
            'Not enough disk space to download. Got %d free' % free_space
        file_url = self.GetFileURLForPath(file_path)
        downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
                                      os.path.basename(file_path))
        os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
        self.DownloadAndWaitForStart(file_url)
        downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
                                      os.path.basename(file_path))
        downloads = self.GetDownloadsInfo().Downloads()
        old_percentage = downloads[0]['PercentComplete']

        def _PercentInc():
            percent = self.GetDownloadsInfo().Downloads()[0]['PercentComplete']
            return old_percentage == 100 or percent > old_percentage,

        self.assertTrue(self.WaitUntil(_PercentInc),
                        msg='Download percentage value is not increasing')
        # Once download is completed, percentage is 100.
        self.WaitForAllDownloadsToComplete()
        downloads = self.GetDownloadsInfo().Downloads()
        self.assertEqual(
            downloads[0]['PercentComplete'], 100,
            'Download percentage should be 100 after download completed')
        os.path.exists(file_path) and os.remove(file_path)
        os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
Example #2
0
    def testCancelDownload(self):
        """Verify that we can cancel a download."""
        # Create a big file (250 MB) on the fly, so that the download won't finish
        # before being cancelled.
        file_path = self._MakeFile(2**28)
        # Ensure there's sufficient space remaining to download file.
        free_space = test_utils.GetFreeSpace(
            self.GetDownloadDirectory().value())
        assert free_space >= 2**28, \
            'Not enough disk space to download. Got %d free' % free_space
        file_url = self.GetFileURLForPath(file_path)
        downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
                                      os.path.basename(file_path))
        self._ClearLocalDownloadState(downloaded_pkg)
        self.DownloadAndWaitForStart(file_url)
        self.PerformActionOnDownload(self._GetDownloadId(), 'cancel')
        self._DeleteAfterShutdown(file_path)

        state = self.GetDownloadsInfo().Downloads()[0]['state']
        if state == 'COMPLETE':
            logging.info('The download completed before cancel. Test stopped.')
            return

        # Verify the download has been cancelled.
        self.assertEqual('CANCELLED',
                         self.GetDownloadsInfo().Downloads()[0]['state'])
        self.assertFalse(os.path.exists(downloaded_pkg))
Example #3
0
    def testBigZip(self):
        """Verify that we can download a 1GB file.

    This test needs 2 GB of free space, 1 GB for the original zip file and
    another for the downloaded one.

    Note: This test increases automation timeout to 4 min.  Things might seem
          to hang.
    """
        # Create a 1 GB file on the fly
        file_path = self._MakeFile(2**30)
        # Ensure there's sufficient space remaining to download file.
        free_space = test_utils.GetFreeSpace(
            self.GetDownloadDirectory().value())
        assert free_space >= 2**30, \
            'Not enough disk space to download. Got %d free' % free_space
        file_url = self.GetFileURLForPath(file_path)
        downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
                                      os.path.basename(file_path))
        self._ClearLocalDownloadState(downloaded_pkg)
        self.DownloadAndWaitForStart(file_url)
        self._DeleteAfterShutdown(downloaded_pkg)
        self.WaitForAllDownloadsToComplete(
            timeout=self.large_test_timeout_ms())
        # Verify that the file was correctly downloaded
        self.assertTrue(os.path.exists(downloaded_pkg),
                        'Downloaded file %s missing.' % downloaded_pkg)
        self.assertTrue(
            self._EqualFileContents(file_path, downloaded_pkg),
            'Downloaded file %s does not match original' % downloaded_pkg)
Example #4
0
    def testPauseAndResume(self):
        """Verify that pause and resume work while downloading a file.

    Note: This test increases automation timeout to 2 min.  Things might seem
          to hang.
    """
        # Create a 250 MB file on the fly
        file_path = self._MakeFile(2**28)
        # Ensure there's sufficient space remaining to download file.
        free_space = test_utils.GetFreeSpace(
            self.GetDownloadDirectory().value())
        assert free_space >= 2**28, \
            'Not enough disk space to download. Got %d free' % free_space

        file_url = self.GetFileURLForPath(file_path)
        downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
                                      os.path.basename(file_path))
        self._ClearLocalDownloadState(downloaded_pkg)
        self.DownloadAndWaitForStart(file_url)

        self._DeleteAfterShutdown(downloaded_pkg)
        self._DeleteAfterShutdown(file_path)

        # Pause the download and assert that it is paused.
        pause_dict = self.PerformActionOnDownload(self._GetDownloadId(),
                                                  'toggle_pause')
        if pause_dict['state'] == 'COMPLETE':
            logging.info('The download completed before pause. Stopping test.')
            return

        self.assertTrue(pause_dict['is_paused'])
        self.assertTrue(pause_dict['state'] == 'IN_PROGRESS')

        # Resume the download and assert it is not paused.
        resume_dict = self.PerformActionOnDownload(self._GetDownloadId(),
                                                   'toggle_pause')
        self.assertFalse(resume_dict['is_paused'])
        self.WaitForAllDownloadsToComplete(
            timeout=self.large_test_timeout_ms())

        # Verify that the file was correctly downloaded after pause and resume.
        self.assertTrue(os.path.exists(downloaded_pkg),
                        'Downloaded file %s missing.' % downloaded_pkg)
        self.assertTrue(
            self._EqualFileContents(file_path, downloaded_pkg),
            'Downloaded file %s does not match original' % downloaded_pkg)