def test_multiple_items(self, hist_tester): items = [ Item(url=QUrl('http://www.qutebrowser.org/'), title='test 1'), Item(url=QUrl('http://www.example.com/'), title='test 2', active=True), Item(url=QUrl('http://www.example.org/'), title='test 3'), ] expected = [ { 'url': 'http://www.qutebrowser.org/', 'title': 'test 1', }, { 'url': 'http://www.example.com/', 'title': 'test 2', 'active': True, 'scroll-pos': { 'x': 0, 'y': 0 }, 'zoom': 1.0 }, { 'url': 'http://www.example.org/', 'title': 'test 3', }, ] hist = hist_tester.get(items) assert hist == expected
def test_two_active_items(): """Check tabhistory.serialize with two active items.""" items = [ Item(QUrl(), '', active=True), Item(QUrl(), ''), Item(QUrl(), '', active=True) ] with pytest.raises(ValueError): tabhistory.serialize(items)
def test_zoom(self, hist_tester, factor): """Test zoom.""" items = [ Item(url=QUrl('http://www.example.com/'), title='Test title', active=True), Item(url=QUrl('http://www.example.com/'), title='Test title', user_data={'zoom': factor}), ] hist_tester.webview.setZoomFactor(factor) hist = hist_tester.get(items) assert hist[0]['zoom'] == factor assert hist[1]['zoom'] == factor
def test_scroll_current(self, hist_tester, pos_x, pos_y): """Test scroll position on the current URL.""" items = [ Item(url=QUrl('http://www.example.com/'), title='Test title', active=True), Item(url=QUrl('http://www.example.com/'), title='Test title', user_data={'scroll-pos': QPoint(pos_x, pos_y)}), ] frame = hist_tester.webview.page().mainFrame() text = '{}\n'.format('x' * 100) * 100 frame.setHtml('<html><body>{}</body></html>'.format(text)) frame.setScrollPosition(QPoint(pos_x, pos_y)) hist = hist_tester.get(items) assert hist[0]['scroll-pos'] == {'x': pos_x, 'y': pos_y} assert hist[1]['scroll-pos'] == {'x': pos_x, 'y': pos_y}
def test_utf_8_valid(self, tmpdir, sess_man, fake_history): """Make sure data containing valid UTF8 gets saved correctly.""" session_path = tmpdir / 'foo.yml' fake_history([ Item(QUrl('http://www.qutebrowser.org/'), 'foo☃bar', active=True) ]) sess_man.save(str(session_path)) data = session_path.read_text('utf-8') assert 'title: foo☃bar' in data
def test_original_url(self, hist_tester): """Test with an original-url which differs from the URL.""" item = Item(url=QUrl('http://www.example.com/'), original_url=QUrl('http://www.example.org/'), title='Test title', active=True) hist = hist_tester.get_single(item) assert hist['url'] == 'http://www.example.com/' assert hist['original-url'] == 'http://www.example.org/'
def test_utf_8_invalid(self, tmpdir, sess_man, fake_history): """Make sure data containing invalid UTF8 raises SessionError.""" session_path = tmpdir / 'foo.yml' fake_history( [Item(QUrl('http://www.qutebrowser.org/'), '\ud800', active=True)]) try: sess_man.save(str(session_path)) except sessions.SessionError: # This seems to happen on some systems only?! pass else: data = session_path.read_text('utf-8') assert r'title: "\uD800"' in data
def test_single_item(self, hist_tester): item = Item(url=QUrl('http://www.qutebrowser.org/'), title='Test title', active=True) expected = { 'url': 'http://www.qutebrowser.org/', 'title': 'Test title', 'active': True, 'scroll-pos': { 'x': 0, 'y': 0 }, 'zoom': 1.0 } hist = hist_tester.get_single(item) assert hist == expected
def test_no_active_item(): """Check tabhistory.serialize with no active item.""" items = [Item(QUrl(), '')] with pytest.raises(ValueError): tabhistory.serialize(items)
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. """Tests for webelement.tabhistory.""" import collections from PyQt5.QtCore import QUrl, QPoint import pytest from qutebrowser.browser.webkit import tabhistory from qutebrowser.browser.webkit.tabhistory import TabHistoryItem as Item from qutebrowser.utils import qtutils pytestmark = pytest.mark.qt_log_ignore('QIODevice::read.*: device not open') ITEMS = [ Item(QUrl('https://www.heise.de/'), 'heise'), Item(QUrl('http://example.com/%E2%80%A6'), 'percent', active=True), Item(QUrl('http://example.com/?foo=bar'), 'arg', original_url=QUrl('http://original.url.example.com/'), user_data={ 'foo': 23, 'bar': 42 }), # From https://github.com/OtterBrowser/otter-browser/issues/709#issuecomment-74749471 Item(QUrl('http://github.com/OtterBrowser/24/134/2344/otter-browser/' 'issues/709/'), 'Page not found | github', user_data={ 'zoom': 149, 'scroll-pos': QPoint(0, 0)
def test_long_output(self, fake_windows, tmpdir, sess_man): session_path = tmpdir / 'foo.yml' items1 = [ Item(QUrl('http://www.qutebrowser.org/'), 'test title 1'), Item(QUrl('http://www.example.org/'), 'test title 2', original_url=QUrl('http://www.example.com/'), active=True), ] items2 = [ Item(QUrl('http://www.example.com/?q=foo+bar'), 'test title 3'), Item(QUrl('http://www.example.com/?q=test%20foo'), 'test title 4', active=True), ] items3 = [] items4 = [ Item(QUrl('http://www.github.com/The-Compiler/qutebrowser'), 'test title 5', active=True), ] self._set_data(fake_windows[0], 0, items1) self._set_data(fake_windows[0], 1, items2) self._set_data(fake_windows[1], 0, items3) self._set_data(fake_windows[1], 1, items4) expected = """ windows: - active: true geometry: !!binary | ZmFrZS1nZW9tZXRyeS0w tabs: - history: - title: test title 1 url: http://www.qutebrowser.org/ - active: true original-url: http://www.example.com/ scroll-pos: x: 0 y: 0 title: test title 2 url: http://www.example.org/ zoom: 1.0 - active: true history: - title: test title 3 url: http://www.example.com/?q=foo+bar - active: true scroll-pos: x: 0 y: 0 title: test title 4 url: http://www.example.com/?q=test%20foo zoom: 1.0 - geometry: !!binary | ZmFrZS1nZW9tZXRyeS0x tabs: - history: [] - active: true history: - active: true scroll-pos: x: 0 y: 0 title: test title 5 url: http://www.github.com/The-Compiler/qutebrowser zoom: 1.0 """ sess_man.save(str(session_path)) data = session_path.read_text('utf-8') assert data == textwrap.dedent(expected.strip('\n'))