Skip to content

Commit

Permalink
bdd: Fix scrolling tests with QtWebEngine
Browse files Browse the repository at this point in the history
Scrolling happens async with QtWebEngine, so we add a new log output
when the page was scrolled, and wait for that in various places.
  • Loading branch information
The-Compiler committed Sep 6, 2016
1 parent f6392d7 commit 85b3d08
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 5 deletions.
6 changes: 6 additions & 0 deletions qutebrowser/browser/browsertab.py
Expand Up @@ -325,6 +325,12 @@ def __init__(self, tab, parent=None):
super().__init__(parent)
self._tab = tab
self._widget = None
self.perc_changed.connect(self._log_scroll_pos_change)

@pyqtSlot()
def _log_scroll_pos_change(self):
log.webview.vdebug("Scroll position changed to {}".format(
self.pos_px()))

def _init_widget(self, widget):
self._widget = widget
Expand Down
1 change: 1 addition & 0 deletions tests/end2end/features/conftest.py
Expand Up @@ -526,6 +526,7 @@ def _get_scroll_values(quteproc):
@bdd.then(bdd.parsers.re(r"the page should be scrolled "
r"(?P<direction>horizontally|vertically)"))
def check_scrolled(request, quteproc, direction):
quteproc.wait_for(message='Scroll position changed to *')
x, y = _get_scroll_values(quteproc)
if direction == 'horizontally':
assert x != 0
Expand Down
27 changes: 27 additions & 0 deletions tests/end2end/features/marks.feature
Expand Up @@ -8,40 +8,55 @@ Feature: Setting positional marks

Scenario: Setting and jumping to a local mark
When I run :scroll-px 5 10
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 10)" in the log
And I run :set-mark a
And I run :scroll-px 0 20
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 30)" in the log
And I run :jump-mark a
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 10)" in the log
Then the page should be scrolled to 5 10

Scenario: Jumping back after jumping to a particular percentage
When I run :scroll-px 10 20
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(10, 20)" in the log
And I run :scroll-perc 100
And I wait for "Scroll position changed to *" in the log
And I run :jump-mark "'"
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(10, 20)" in the log
Then the page should be scrolled to 10 20

Scenario: Setting the same local mark on another page
When I run :scroll-px 5 10
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 10)" in the log
And I run :set-mark a
And I open data/marks.html
And I run :scroll-px 0 20
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(0, 20)" in the log
And I run :set-mark a
And I run :jump-mark a
Then the page should be scrolled to 0 20

Scenario: Jumping to a local mark after returning to a page
When I run :scroll-px 5 10
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 10)" in the log
And I run :set-mark a
And I run :scroll-px 0 20
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 30)" in the log
And I open data/numbers/1.txt
And I run :set-mark a
And I open data/marks.html
And I run :jump-mark a
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 10)" in the log
Then the page should be scrolled to 5 10

Scenario: Setting and jumping to a global mark
When I run :scroll-px 5 20
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 20)" in the log
And I run :set-mark A
And I open data/numbers/1.txt
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
And I run :jump-mark A
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(5, 20)" in the log
Then data/marks.html should be loaded
And the page should be scrolled to 5 20

Expand All @@ -59,34 +74,46 @@ Feature: Setting positional marks
Scenario: Jumping to a local mark after changing fragments
When I open data/marks.html#top
And I run :scroll 'top'
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
And I run :scroll-px 10 10
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(10, 10)" in the log
And I run :set-mark a
When I open data/marks.html#bottom
And I run :jump-mark a
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(10, 10)" in the log
Then the page should be scrolled to 10 10

@qtwebengine_todo: Does not emit loaded signal for fragments?
Scenario: Jumping back after following a link
When I hint with args "links normal" and follow s
And I wait until data/marks.html#bottom is loaded
And I run :jump-mark "'"
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should be scrolled to 0 0

Scenario: Jumping back after searching
When I run :scroll-px 20 15
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(20, 15)" in the log
And I run :search Waldo
And I wait for "Scroll position changed to *" in the log
And I run :jump-mark "'"
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(20, 15)" in the log
Then the page should be scrolled to 20 15

Scenario: Jumping back after search-next
When I run :search Grail
And I run :search-next
And I wait for "Scroll position changed to *" in the log
And I run :jump-mark "'"
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should be scrolled to 0 0

Scenario: Hovering a hint does not set the ' mark
When I run :scroll-px 30 20
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(30, 20)" in the log
And I run :scroll-perc 0
And I wait for "Scroll position changed to *" in the log
And I hint with args "links hover" and follow s
And I run :jump-mark "'"
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(30, 20)" in the log
Then the page should be scrolled to 30 20
5 changes: 5 additions & 0 deletions tests/end2end/features/misc.feature
Expand Up @@ -537,15 +537,20 @@ Feature: Various utility commands.
Given I open data/scroll/simple.html
And I run :tab-only
When I run :scroll down with count 3
And I wait for "Scroll position changed to *" in the log
And I run :scroll up
And I wait for "Scroll position changed to *" in the log
And I run :repeat-command with count 2
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: :repeat-command with not-normal command inbetween
Given I open data/scroll/simple.html
And I run :tab-only
When I run :scroll down with count 3
And I wait for "Scroll position changed to *" in the log
And I run :scroll up
And I wait for "Scroll position changed to *" in the log
And I run :prompt-accept
And I run :repeat-command with count 2
Then the page should not be scrolled
Expand Down
47 changes: 43 additions & 4 deletions tests/end2end/features/scroll.feature
Expand Up @@ -17,24 +17,32 @@ Feature: Scrolling

Scenario: Scrolling down and up
When I run :scroll-px 10 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(10, 0)" in the log
And I run :scroll-px -10 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling right and left
When I run :scroll-px 0 10
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(0, 10)" in the log
And I run :scroll-px 0 -10
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling down and up with count
When I run :scroll-px 0 10 with count 2
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(0, 20)" in the log
When I run :scroll-px 0 -10
When I run :scroll-px 0 -10
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling left and right with count
When I run :scroll-px 10 0 with count 2
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint(20, 0)" in the log
When I run :scroll-px -10 0
When I run :scroll-px -10 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: :scroll-px with a very big value
Expand All @@ -44,7 +52,7 @@ Feature: Scrolling
Scenario: :scroll-px on a page without scrolling
When I open data/hello.txt
And I run :scroll-px 10 10
Then no crash should happen
Then the page should not be scrolled

Scenario: :scroll-px with floats
# This used to be allowed, but doesn't make much sense.
Expand All @@ -60,7 +68,9 @@ Feature: Scrolling

Scenario: Scrolling down and up
When I run :scroll down
And I wait for "Scroll position changed to *" in the log
And I run :scroll up
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling right
Expand All @@ -69,7 +79,9 @@ Feature: Scrolling

Scenario: Scrolling right and left
When I run :scroll right
And I wait for "Scroll position changed to *" in the log
And I run :scroll left
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

# causes segfault with postEvent instead of sendEvent
Expand All @@ -83,7 +95,9 @@ Feature: Scrolling

Scenario: Scrolling with page down and page up
When I run :scroll page-down
And I wait for "Scroll position changed to *" in the log
And I run :scroll page-up
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling to bottom
Expand All @@ -92,7 +106,9 @@ Feature: Scrolling

Scenario: Scrolling to bottom and to top
When I run :scroll bottom
And I wait for "Scroll position changed to *" in the log
And I run :scroll top
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: :scroll with invalid argument
Expand All @@ -102,8 +118,10 @@ Feature: Scrolling

Scenario: Scrolling down and up with count
When I run :scroll down with count 2
And I wait for "Scroll position changed to *" in the log
And I run :scroll up
And I run :scroll up
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling right
Expand All @@ -112,13 +130,17 @@ Feature: Scrolling

Scenario: Scrolling right and left
When I run :scroll right
And I wait for "Scroll position changed to *" in the log
And I run :scroll left
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling right and left with count
When I run :scroll right with count 2
And I wait for "Scroll position changed to *" in the log
And I run :scroll left
And I run :scroll left
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

@qtwebengine_skip: Causes memory leak...
Expand All @@ -127,11 +149,12 @@ Feature: Scrolling
# Make sure it doesn't hang
And I run :message-info "Still alive!"
Then the message "Still alive!" should be shown
And "Scroll position changed to *" should be logged

Scenario: :scroll on a page without scrolling
When I open data/hello.txt
And I run :scroll down
Then no crash should happen
Then the page should not be scrolled

## :scroll-perc

Expand All @@ -141,7 +164,9 @@ Feature: Scrolling

Scenario: Scrolling to bottom and to top with :scroll-perc
When I run :scroll-perc 100
And I wait for "Scroll position changed to *" in the log
And I run :scroll-perc 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling to middle with :scroll-perc
Expand All @@ -154,7 +179,9 @@ Feature: Scrolling

Scenario: Scrolling to middle and to top with :scroll-perc
When I run :scroll-perc 50
And I wait for "Scroll position changed to *" in the log
And I run :scroll-perc 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling to right with :scroll-perc
Expand All @@ -163,7 +190,9 @@ Feature: Scrolling

Scenario: Scrolling to right and to left with :scroll-perc
When I run :scroll-perc --horizontal 100
And I wait for "Scroll position changed to *" in the log
And I run :scroll-perc --horizontal 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling to middle (horizontally) with :scroll-perc
Expand All @@ -172,7 +201,9 @@ Feature: Scrolling

Scenario: Scrolling to middle and to left with :scroll-perc
When I run :scroll-perc --horizontal 50
And I wait for "Scroll position changed to *" in the log
And I run :scroll-perc --horizontal 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: :scroll-perc without argument
Expand All @@ -195,7 +226,7 @@ Feature: Scrolling
Scenario: :scroll-perc on a page without scrolling
When I open data/hello.txt
And I run :scroll-perc 20
Then no crash should happen
Then the page should not be scrolled

Scenario: :scroll-perc with count and argument
When I run :scroll-perc 0 with count 50
Expand All @@ -219,7 +250,9 @@ Feature: Scrolling

Scenario: Scrolling down and up with :scroll-page
When I run :scroll-page 0 1
And I wait for "Scroll position changed to *" in the log
And I run :scroll-page 0 -1
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling right with :scroll-page
Expand All @@ -232,18 +265,24 @@ Feature: Scrolling

Scenario: Scrolling right and left with :scroll-page
When I run :scroll-page 1 0
And I wait for "Scroll position changed to *" in the log
And I run :scroll-page -1 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

Scenario: Scrolling right and left with :scroll-page and count
When I run :scroll-page 1 0 with count 2
And I wait for "Scroll position changed to *" in the log
And I run :scroll-page -1 0
And I wait for "Scroll position changed to *" in the log
And I run :scroll-page -1 0
And I wait for "Scroll position changed to PyQt5.QtCore.QPoint()" in the log
Then the page should not be scrolled

@qtwebengine_todo: at_bottom is not implemented yet
Scenario: :scroll-page with --bottom-navigate
When I run :scroll-perc 100
And I wait for "Scroll position changed to *" in the log
And I run :scroll-page --bottom-navigate next 0 1
Then data/hello2.txt should be loaded

Expand All @@ -259,4 +298,4 @@ Feature: Scrolling
Scenario: :scroll-page on a page without scrolling
When I open data/hello.txt
And I run :scroll-page 1 1
Then no crash should happen
Then the page should not be scrolled
3 changes: 2 additions & 1 deletion tests/end2end/fixtures/quteprocess.py
Expand Up @@ -262,7 +262,8 @@ def _executable_args(self):
def _default_args(self):
backend = 'webengine' if self.request.config.webengine else 'webkit'
return ['--debug', '--no-err-windows', '--temp-basedir',
'--json-logging', '--backend', backend, 'about:blank']
'--json-logging', '--loglevel', 'vdebug',
'--backend', backend, 'about:blank']

def path_to_url(self, path, *, port=None, https=False):
"""Get a URL based on a filename for the localhost webserver.
Expand Down

0 comments on commit 85b3d08

Please sign in to comment.