Merge branch 'Kingdread-issue-1535'

This commit is contained in:
Florian Bruhin 2016-06-04 13:15:44 +02:00
commit 4054992583
4 changed files with 38 additions and 1 deletions

View File

@ -70,6 +70,7 @@ Fixed
- Fixed a crash when entering `:-- ` in the commandline
- Fixed `:debug-console` with PyQt 5.6
- Fixed qutebrowser not starting when `sys.stderr` is `None`
- Fixed crash when cancelling a download which belongs to a MHTML download
v0.6.2
------

View File

@ -345,7 +345,7 @@ class _Downloader:
self.pending_downloads.add((url, item))
item.finished.connect(functools.partial(self._finished, url, item))
item.error.connect(functools.partial(self._error, url, item))
item.cancelled.connect(functools.partial(self._error, url, item))
item.cancelled.connect(functools.partial(self._cancelled, url, item))
def _finished(self, url, item):
"""Callback when a single asset is downloaded.
@ -418,6 +418,20 @@ class _Downloader:
return
self._finish_file()
def _cancelled(self, url, item):
"""Callback when a download is cancelled by the user.
Args:
url: The original url of the asset as QUrl.
item: The DownloadItem given by the DownloadManager.
"""
# This callback is called before _finished, so there's no need to
# remove the item or close the fileobject.
log.downloads.debug("MHTML download cancelled by user: {}".format(url))
# Write an empty file instead
item.fileobj.seek(0)
item.fileobj.truncate()
def _finish_file(self):
"""Save the file to the filename given in __init__."""
if self._finished_file:

View File

@ -0,0 +1,14 @@
<html>
<head>
<title>test case for issue 1535</title>
</head>
<body>
<p>Cancelling a download that belongs to a mhtml download.</p>
<p>See also <a href="https://github.com/The-Compiler/qutebrowser/issues/1535">GitHub</a></p>
<!--
Use drip so we have a chance to cancel the download before
it finishes
-->
<img src="/drip?numbytes=128&duration=2">
</body>
</html>

View File

@ -126,6 +126,14 @@ Feature: Downloading things from a website.
Then "cancelled" should be logged
And "cancelled" should be logged
# https://github.com/The-Compiler/qutebrowser/issues/1535
Scenario: Cancelling a MHTML download (issue 1535)
When I open data/downloads/issue1535.html
And I run :download --mhtml
And I wait for "fetch: PyQt5.QtCore.QUrl('http://localhost:*/drip?numbytes=128&duration=2') -> drip" in the log
And I run :download-cancel
Then no crash should happen
## :download-delete
Scenario: Deleting a download