2015-05-12 17:05:01 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
|
|
# Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""Tests for position_caret.js."""
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
from PyQt5.QtWebKit import QWebSettings
|
|
|
|
from PyQt5.QtWebKitWidgets import QWebPage
|
|
|
|
|
|
|
|
|
2015-05-13 06:31:48 +02:00
|
|
|
@pytest.yield_fixture(autouse=True)
|
2015-08-19 21:40:13 +02:00
|
|
|
def enable_caret_browsing(qapp):
|
2015-05-12 17:05:01 +02:00
|
|
|
"""Fixture to enable caret browsing globally."""
|
2015-05-13 06:31:48 +02:00
|
|
|
settings = QWebSettings.globalSettings()
|
|
|
|
old_value = settings.testAttribute(QWebSettings.CaretBrowsingEnabled)
|
|
|
|
settings.setAttribute(QWebSettings.CaretBrowsingEnabled, True)
|
|
|
|
yield
|
|
|
|
settings.setAttribute(QWebSettings.CaretBrowsingEnabled, old_value)
|
2015-05-12 17:05:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CaretTester:
|
|
|
|
|
|
|
|
"""Helper class (for the caret_tester fixture) for asserts.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
js: The js_tester fixture.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, js_tester):
|
|
|
|
self.js = js_tester
|
|
|
|
|
|
|
|
def check(self):
|
|
|
|
"""Check whether the caret is before the MARKER text."""
|
|
|
|
self.js.run_file('position_caret.js')
|
|
|
|
self.js.webview.triggerPageAction(QWebPage.SelectNextWord)
|
2015-05-18 23:04:11 +02:00
|
|
|
assert self.js.webview.selectedText().rstrip() == "MARKER"
|
2015-05-12 17:05:01 +02:00
|
|
|
|
|
|
|
def check_scrolled(self):
|
|
|
|
"""Check if the page is scrolled down."""
|
|
|
|
frame = self.js.webview.page().mainFrame()
|
|
|
|
minimum = frame.scrollBarMinimum(Qt.Vertical)
|
|
|
|
value = frame.scrollBarValue(Qt.Vertical)
|
|
|
|
assert value > minimum
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def caret_tester(js_tester):
|
|
|
|
"""Helper fixture to test caret browsing positions."""
|
|
|
|
return CaretTester(js_tester)
|
|
|
|
|
|
|
|
|
2015-08-11 19:36:27 +02:00
|
|
|
@pytest.mark.integration
|
2015-05-12 17:05:01 +02:00
|
|
|
def test_simple(caret_tester):
|
|
|
|
"""Test with a simple (one-line) HTML text."""
|
|
|
|
caret_tester.js.load('position_caret/simple.html')
|
|
|
|
caret_tester.check()
|
|
|
|
|
|
|
|
|
2015-08-11 19:36:27 +02:00
|
|
|
@pytest.mark.integration
|
2015-05-12 17:05:01 +02:00
|
|
|
def test_scrolled_down(caret_tester):
|
|
|
|
"""Test with multiple text blocks with the viewport scrolled down."""
|
|
|
|
caret_tester.js.load('position_caret/scrolled_down.html')
|
|
|
|
caret_tester.js.scroll_anchor('anchor')
|
|
|
|
caret_tester.check_scrolled()
|
|
|
|
caret_tester.check()
|
2015-05-12 19:08:54 +02:00
|
|
|
|
|
|
|
|
2015-08-11 19:36:27 +02:00
|
|
|
@pytest.mark.integration
|
2015-05-12 19:08:54 +02:00
|
|
|
@pytest.mark.parametrize('style', ['visibility: hidden', 'display: none'])
|
|
|
|
def test_invisible(caret_tester, style):
|
|
|
|
"""Test with hidden text elements."""
|
|
|
|
caret_tester.js.load('position_caret/invisible.html', style=style)
|
|
|
|
caret_tester.check()
|
2015-05-12 19:15:16 +02:00
|
|
|
|
|
|
|
|
2015-08-11 19:36:27 +02:00
|
|
|
@pytest.mark.integration
|
2015-05-12 19:15:16 +02:00
|
|
|
def test_scrolled_down_img(caret_tester):
|
|
|
|
"""Test with an image at the top with the viewport scrolled down."""
|
|
|
|
caret_tester.js.load('position_caret/scrolled_down_img.html')
|
|
|
|
caret_tester.js.scroll_anchor('anchor')
|
|
|
|
caret_tester.check_scrolled()
|
|
|
|
caret_tester.check()
|