tests: Wait until page is loaded by default

When doing quteproc.open_path, by default the test didn't wait until the page
was loaded. This caused unintentional race conditions which e.g. caused
dirbrowser tests to fail on OS X:

https://travis-ci.org/The-Compiler/qutebrowser/jobs/133730001

Now instead we wait by default, unless wait=False is passed to open_path() or
open_url().
This commit is contained in:
Florian Bruhin 2016-05-29 16:14:33 +02:00
parent 9bb425d598
commit d3fe2babd3
8 changed files with 22 additions and 23 deletions

View File

@ -55,7 +55,6 @@ def open_path_given(quteproc, path):
It always opens a new tab, unlike "When I open ..." It always opens a new tab, unlike "When I open ..."
""" """
quteproc.open_path(path, new_tab=True) quteproc.open_path(path, new_tab=True)
quteproc.wait_for_load_finished(path)
@bdd.given(bdd.parsers.parse("I run {command}")) @bdd.given(bdd.parsers.parse("I run {command}"))
@ -86,7 +85,7 @@ def open_path(quteproc, path):
""" """
new_tab = False new_tab = False
new_window = False new_window = False
wait_for_load_finished = True wait = True
new_tab_suffix = ' in a new tab' new_tab_suffix = ' in a new tab'
new_window_suffix = ' in a new window' new_window_suffix = ' in a new window'
@ -101,12 +100,9 @@ def open_path(quteproc, path):
if path.endswith(do_not_wait_suffix): if path.endswith(do_not_wait_suffix):
path = path[:-len(do_not_wait_suffix)] path = path[:-len(do_not_wait_suffix)]
wait_for_load_finished = False wait = False
quteproc.open_path(path, new_tab=new_tab, new_window=new_window) quteproc.open_path(path, new_tab=new_tab, new_window=new_window, wait=wait)
if wait_for_load_finished:
quteproc.wait_for_load_finished(path)
@bdd.when(bdd.parsers.parse("I set {sect} -> {opt} to {value}")) @bdd.when(bdd.parsers.parse("I set {sect} -> {opt} to {value}"))

View File

@ -23,8 +23,8 @@ bdd.scenarios('prompts.feature')
@bdd.when("I load a SSL page") @bdd.when("I load a SSL page")
def load_ssl_page(quteproc, ssl_server): def load_ssl_page(quteproc, ssl_server):
quteproc.open_path('/', port=ssl_server.port, https=True) # We don't wait here as we can get an SSL question.
# We don't call wait_for_load_finished here as we can get an SSL question. quteproc.open_path('/', port=ssl_server.port, https=True, wait=False)
@bdd.when("I wait until the SSL page finished loading") @bdd.when("I wait until the SSL page finished loading")

View File

@ -365,12 +365,12 @@ class QuteProc(testprocess.Process):
self.set_setting(sect, opt, old_value) self.set_setting(sect, opt, old_value)
def open_path(self, path, *, new_tab=False, new_window=False, port=None, def open_path(self, path, *, new_tab=False, new_window=False, port=None,
https=False): https=False, wait=True):
"""Open the given path on the local webserver in qutebrowser.""" """Open the given path on the local webserver in qutebrowser."""
url = self.path_to_url(path, port=port, https=https) url = self.path_to_url(path, port=port, https=https)
self.open_url(url, new_tab=new_tab, new_window=new_window) self.open_url(url, new_tab=new_tab, new_window=new_window, wait=wait)
def open_url(self, url, *, new_tab=False, new_window=False): def open_url(self, url, *, new_tab=False, new_window=False, wait=True):
"""Open the given url in qutebrowser.""" """Open the given url in qutebrowser."""
if new_tab and new_window: if new_tab and new_window:
raise ValueError("new_tab and new_window given!") raise ValueError("new_tab and new_window given!")
@ -382,15 +382,18 @@ class QuteProc(testprocess.Process):
else: else:
self.send_cmd(':open ' + url) self.send_cmd(':open ' + url)
if wait:
self._wait_for_load_finished_url(url)
def mark_expected(self, category=None, loglevel=None, message=None): def mark_expected(self, category=None, loglevel=None, message=None):
"""Mark a given logging message as expected.""" """Mark a given logging message as expected."""
line = self.wait_for(category=category, loglevel=loglevel, line = self.wait_for(category=category, loglevel=loglevel,
message=message) message=message)
line.expected = True line.expected = True
def wait_for_load_finished(self, path, *, port=None, https=False, def _wait_for_load_finished_url(self, url, *, timeout=None,
timeout=None, load_status='success'): load_status='success'):
"""Wait until any tab has finished loading.""" """Wait until a URL has finished loading."""
__tracebackhide__ = True __tracebackhide__ = True
if timeout is None: if timeout is None:
@ -399,7 +402,6 @@ class QuteProc(testprocess.Process):
else: else:
timeout = 5000 timeout = 5000
url = self.path_to_url(path, port=port, https=https)
# We really need the same representation that the webview uses in its # We really need the same representation that the webview uses in its
# __repr__ # __repr__
url = utils.elide(QUrl(url).toDisplayString(QUrl.EncodeUnicode), 100) url = utils.elide(QUrl(url).toDisplayString(QUrl.EncodeUnicode), 100)
@ -415,6 +417,14 @@ class QuteProc(testprocess.Process):
raise testprocess.WaitForTimeout("Timed out while waiting for {} " raise testprocess.WaitForTimeout("Timed out while waiting for {} "
"to be loaded".format(url)) "to be loaded".format(url))
def wait_for_load_finished(self, path, *, port=None, https=False,
timeout=None, load_status='success'):
"""Wait until a path has finished loading."""
__tracebackhide__ = True
url = self.path_to_url(path, port=port, https=https)
self._wait_for_load_finished_url(url, timeout=timeout,
load_status=load_status)
def get_session(self): def get_session(self):
"""Save the session and get the parsed session data.""" """Save the session and get the parsed session data."""
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:

View File

@ -43,7 +43,6 @@ def test_hints(test_name, zoom_text_only, zoom_level, quteproc):
'data', 'hints', 'html', test_name) 'data', 'hints', 'html', test_name)
url_path = 'data/hints/html/{}'.format(test_name) url_path = 'data/hints/html/{}'.format(test_name)
quteproc.open_path(url_path) quteproc.open_path(url_path)
quteproc.wait_for_load_finished(url_path)
with open(file_path, 'r', encoding='utf-8') as html: with open(file_path, 'r', encoding='utf-8') as html:
soup = bs4.BeautifulSoup(html, 'html.parser') soup = bs4.BeautifulSoup(html, 'html.parser')
@ -91,7 +90,6 @@ def test_word_hints_issue1393(quteproc, tmpdir):
for hint, target in targets: for hint, target in targets:
quteproc.open_path('data/hints/issue1393.html') quteproc.open_path('data/hints/issue1393.html')
quteproc.wait_for_load_finished('data/hints/issue1393.html')
quteproc.send_cmd(':hint') quteproc.send_cmd(':hint')
quteproc.wait_for(message='hints: *', category='hints') quteproc.wait_for(message='hints: *', category='hints')
quteproc.send_cmd(':follow-hint {}'.format(hint)) quteproc.send_cmd(':follow-hint {}'.format(hint))

View File

@ -35,7 +35,6 @@ import pytest
def test_insert_mode(file_name, source, input_text, auto_insert, quteproc): def test_insert_mode(file_name, source, input_text, auto_insert, quteproc):
url_path = 'data/insert_mode_settings/html/{}'.format(file_name) url_path = 'data/insert_mode_settings/html/{}'.format(file_name)
quteproc.open_path(url_path) quteproc.open_path(url_path)
quteproc.wait_for_load_finished(url_path)
quteproc.set_setting('input', 'auto-insert-mode', auto_insert) quteproc.set_setting('input', 'auto-insert-mode', auto_insert)
quteproc.send_cmd(':hint all') quteproc.send_cmd(':hint all')
@ -66,7 +65,6 @@ def test_insert_mode(file_name, source, input_text, auto_insert, quteproc):
def test_auto_leave_insert_mode(quteproc): def test_auto_leave_insert_mode(quteproc):
url_path = 'data/insert_mode_settings/html/autofocus.html' url_path = 'data/insert_mode_settings/html/autofocus.html'
quteproc.open_path(url_path) quteproc.open_path(url_path)
quteproc.wait_for_load_finished(url_path)
quteproc.set_setting('input', 'auto-leave-insert-mode', 'true') quteproc.set_setting('input', 'auto-leave-insert-mode', 'true')

View File

@ -92,5 +92,4 @@ def test_no_loglines(quteproc_new):
quteproc_new.start(args=['--debug', '--no-err-windows', '--temp-basedir', quteproc_new.start(args=['--debug', '--no-err-windows', '--temp-basedir',
'--loglines=0', 'about:blank']) '--loglines=0', 'about:blank'])
quteproc_new.open_path('qute:log') quteproc_new.open_path('qute:log')
quteproc_new.wait_for_load_finished('qute:log')
assert quteproc_new.get_content() == 'Log output was disabled.' assert quteproc_new.get_content() == 'Log output was disabled.'

View File

@ -89,7 +89,6 @@ def test_mhtml(test_name, download_dir, quteproc, httpbin):
url_path = '{}/{}.html'.format(test_path, test_name) url_path = '{}/{}.html'.format(test_path, test_name)
quteproc.open_path(url_path) quteproc.open_path(url_path)
quteproc.wait_for_load_finished(url_path)
download_dest = os.path.join(download_dir.location, download_dest = os.path.join(download_dir.location,
'{}-downloaded.mht'.format(test_name)) '{}-downloaded.mht'.format(test_name))

View File

@ -173,7 +173,6 @@ class TestClickElement:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def open_page(self, quteproc): def open_page(self, quteproc):
quteproc.open_path('data/click_element.html') quteproc.open_path('data/click_element.html')
quteproc.wait_for_load_finished('data/click_element.html')
def test_click_element(self, quteproc): def test_click_element(self, quteproc):
quteproc.click_element('Test Element') quteproc.click_element('Test Element')