fix test related to view-source

remove pygment title
remove view-source from history
This commit is contained in:
Marc Jauvin 2018-01-25 15:17:03 -05:00
parent eb888cc8d7
commit bb8bc7ea3c
4 changed files with 12 additions and 9 deletions

View File

@ -172,7 +172,7 @@ class WebHistory(sql.SqlTable):
@pyqtSlot(QUrl, QUrl, str) @pyqtSlot(QUrl, QUrl, str)
def add_from_tab(self, url, requested_url, title): def add_from_tab(self, url, requested_url, title):
"""Add a new history entry as slot, called from a BrowserTab.""" """Add a new history entry as slot, called from a BrowserTab."""
if any(url.scheme() == 'data' or if any(url.scheme() in ('data', 'view-source') or
(url.scheme(), url.host()) == ('qute', 'back') (url.scheme(), url.host()) == ('qute', 'back')
for url in (url, requested_url)): for url in (url, requested_url)):
return return

View File

@ -104,11 +104,13 @@ class WebEngineAction(browsertab.AbstractAction):
self._widget.triggerPageAction(QWebEnginePage.ViewSource) self._widget.triggerPageAction(QWebEnginePage.ViewSource)
except AttributeError: except AttributeError:
# Qt < 5.8 # Qt < 5.8
url_str = self._tab.url().toString(QUrl.RemoveUserInfo)
new_url = QUrl('view-source:' + url_str)
tb = objreg.get('tabbed-browser', scope='window', tb = objreg.get('tabbed-browser', scope='window',
window=self._win_id) window=self._win_id)
tb.tabopen(new_url, background=False, related=True) url_str = self._tab.url().toString(QUrl.RemoveUserInfo)
# The original URL becomes the path of a view-source: URL
# (without a host), but query/fragment should stay.
url = QUrl('view-source:' + url_str)
tb.tabopen(url, background=False, related=True)
class WebEnginePrinting(browsertab.AbstractPrinting): class WebEnginePrinting(browsertab.AbstractPrinting):

View File

@ -62,16 +62,17 @@ class WebKitAction(browsertab.AbstractAction):
# pylint: disable=no-member # pylint: disable=no-member
lexer = pygments.lexers.HtmlLexer() lexer = pygments.lexers.HtmlLexer()
formatter = pygments.formatters.HtmlFormatter( formatter = pygments.formatters.HtmlFormatter(
full=True, linenos='table', full=True, linenos='table')
title='Source for {}'.format(url_str))
# pylint: enable=no-member # pylint: enable=no-member
highlighted = pygments.highlight(source, lexer, formatter) highlighted = pygments.highlight(source, lexer, formatter)
base_url = QUrl('view-source:' + url_str)
tb = objreg.get('tabbed-browser', scope='window', tb = objreg.get('tabbed-browser', scope='window',
window=self._win_id) window=self._win_id)
new_tab = tb.tabopen(background=False, related=True) new_tab = tb.tabopen(background=False, related=True)
new_tab.set_html(highlighted, base_url) # The original URL becomes the path of a view-source: URL
# (without a host), but query/fragment should stay.
url = QUrl('view-source:' + url_str)
new_tab.set_html(highlighted, url)
url_str = self._tab.url().toString(QUrl.RemoveUserInfo) url_str = self._tab.url().toString(QUrl.RemoveUserInfo)
self._tab.dump_async(show_source_cb) self._tab.dump_async(show_source_cb)

View File

@ -69,7 +69,7 @@ Feature: Page history
Scenario: History with view-source URL Scenario: History with view-source URL
When I open data/title.html When I open data/title.html
And I run :view-source And I run :view-source
And I wait for regex "Changing title for idx \d+ to '(Source for |view-source:)(http://)?localhost:\d+/data/title.html'" in the log And I wait for regex "Changing title for idx \d+ to 'view-source:(http://)?localhost:\d+/data/title.html'" in the log
Then the history should contain: Then the history should contain:
http://localhost:(port)/data/title.html Test title http://localhost:(port)/data/title.html Test title