Simplify mhtml tests with QtWebEngine
The actual mhtml files are produced by QtWebEngine, so we don't actually care about how they look in detail. The output changes with almost every Qt/Chromium update, so let's only sanity-check the resulting file with QtWebEngine instead of playing catch-up all the time. See #5013
This commit is contained in:
parent
e080ea15be
commit
ccbaddf6e6
|
|
@ -1,27 +0,0 @@
|
|||
From: <Saved by Blink>
|
||||
Snapshot-Content-Location: http://localhost:(port)/data/downloads/mhtml/simple/simple.html
|
||||
Subject: Simple MHTML test
|
||||
Date: today
|
||||
MIME-Version: 1.0
|
||||
Content-Type: multipart/related;
|
||||
type="text/html";
|
||||
boundary="---=_qute-UUID"
|
||||
|
||||
-----=_qute-UUID
|
||||
Content-Type: text/html
|
||||
Content-ID: 42
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
Content-Location: http://localhost:(port)/data/downloads/mhtml/simple/simple.html
|
||||
|
||||
<!DOCTYPE html><html><head><meta http-equiv=3D"Content-Type" content=3D"tex=
|
||||
t/html; charset=3DUTF-8">
|
||||
=20
|
||||
<title>Simple MHTML test</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href=3D"http://localhost:(port)/">normal link to another page</a>
|
||||
=20
|
||||
|
||||
</body><style>
|
||||
html > ::-webkit-scrollbar { width: 0px; height: 0px; }</style></html>
|
||||
-----=_qute-UUID
|
||||
|
|
@ -26,8 +26,6 @@ import collections
|
|||
|
||||
import pytest
|
||||
|
||||
from qutebrowser.utils import qtutils
|
||||
|
||||
|
||||
def collect_tests():
|
||||
basedir = os.path.dirname(__file__)
|
||||
|
|
@ -38,15 +36,11 @@ def collect_tests():
|
|||
|
||||
def normalize_line(line):
|
||||
line = line.rstrip('\n')
|
||||
line = re.sub('boundary="-+(=_qute|MultipartBoundary)-[0-9a-zA-Z-]+"',
|
||||
line = re.sub('boundary="---=_qute-[0-9a-f-]+"',
|
||||
'boundary="---=_qute-UUID"', line)
|
||||
line = re.sub('^-+(=_qute|MultipartBoundary)-[0-9a-zA-Z-]+$',
|
||||
line = re.sub('^-----+=_qute-[0-9a-f-]+$',
|
||||
'-----=_qute-UUID', line)
|
||||
line = re.sub(r'localhost:\d{1,5}', 'localhost:(port)', line)
|
||||
if line.startswith('Date: '):
|
||||
line = 'Date: today'
|
||||
if line.startswith('Content-ID: '):
|
||||
line = 'Content-ID: 42'
|
||||
|
||||
# Depending on Python's mimetypes module/the system's mime files, .js
|
||||
# files could be either identified as x-javascript or just javascript
|
||||
|
|
@ -57,20 +51,9 @@ def normalize_line(line):
|
|||
# specified.
|
||||
line = line.replace('javascript; charset=utf-8', 'javascript')
|
||||
|
||||
# Added with Qt 5.11
|
||||
if (line.startswith('Snapshot-Content-Location: ') and
|
||||
not qtutils.version_check('5.11', compiled=False)):
|
||||
line = None
|
||||
|
||||
return line
|
||||
|
||||
|
||||
def normalize_whole(s, webengine):
|
||||
if qtutils.version_check('5.12', compiled=False) and webengine:
|
||||
s = s.replace('\n\n-----=_qute-UUID', '\n-----=_qute-UUID')
|
||||
return s
|
||||
|
||||
|
||||
class DownloadDir:
|
||||
|
||||
"""Abstraction over a download directory."""
|
||||
|
|
@ -97,9 +80,6 @@ class DownloadDir:
|
|||
if normalize_line(line) is not None)
|
||||
actual_data = '\n'.join(normalize_line(line)
|
||||
for line in self.read_file())
|
||||
actual_data = normalize_whole(actual_data,
|
||||
webengine=self._config.webengine)
|
||||
|
||||
assert actual_data == expected_data
|
||||
|
||||
|
||||
|
|
@ -150,13 +130,12 @@ def test_mhtml(request, test_name, download_dir, quteproc, server):
|
|||
quteproc.wait_for(category='downloads',
|
||||
message='File successfully written.')
|
||||
|
||||
suffix = '-webengine' if request.config.webengine else ''
|
||||
filename = '{}{}.mht'.format(test_name, suffix)
|
||||
expected_file = os.path.join(test_dir, filename)
|
||||
if os.path.exists(expected_file):
|
||||
download_dir.compare_mhtml(expected_file)
|
||||
else:
|
||||
if request.config.webengine:
|
||||
download_dir.sanity_check_mhtml()
|
||||
return
|
||||
|
||||
if not request.config.webengine:
|
||||
_test_mhtml_requests(test_dir, test_path, server)
|
||||
filename = test_name + '.mht'
|
||||
expected_file = os.path.join(test_dir, filename)
|
||||
|
||||
download_dir.compare_mhtml(expected_file)
|
||||
_test_mhtml_requests(test_dir, test_path, server)
|
||||
|
|
|
|||
Loading…
Reference in New Issue