From 57fbfbd606c2ea31a2106a1e9b919044ce46d3e5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 11 Jun 2017 17:45:18 +0200 Subject: [PATCH] Set an initial window size for background tabs When we open a background tab, it gets a hardcoded size (800x600 or so) because it doesn't get resized by the layout yet. By resizing it to the size it'll actually have later, we make sure scrolling to an anchor in an background tab works, and JS also gets the correct size for background tabs. Fixes #1190 Fixes #2495 See #1417 --- CHANGELOG.asciidoc | 2 ++ qutebrowser/mainwindow/tabbedbrowser.py | 10 +++++++- tests/end2end/data/javascript/windowsize.html | 24 +++++++++++++++++++ tests/end2end/data/scroll/simple.html | 16 ++++++++++++- tests/end2end/features/javascript.feature | 16 +++++++++++++ tests/end2end/features/scroll.feature | 9 +++++++ tests/end2end/features/test_javascript_bdd.py | 10 ++++++++ tests/end2end/fixtures/quteprocess.py | 3 ++- 8 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 tests/end2end/data/javascript/windowsize.html diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 5d31e60da..dffdff139 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -134,6 +134,8 @@ Fixed - Various other rare crashes should now be fixed. - The settings documentation was truncated with v0.10.1 which should now be fixed. +- Scrolling to an anchor in a background tab now works correctly, and javascript + gets the correct window size for background tabs. v0.10.1 ------- diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 3e471f399..22ad7dd6b 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -23,7 +23,7 @@ import functools import collections from PyQt5.QtWidgets import QSizePolicy -from PyQt5.QtCore import pyqtSignal, pyqtSlot, QTimer, QUrl +from PyQt5.QtCore import pyqtSignal, pyqtSlot, QTimer, QUrl, QSize from PyQt5.QtGui import QIcon from qutebrowser.config import config @@ -426,12 +426,20 @@ class TabbedBrowser(tabwidget.TabWidget): if url is not None: tab.openurl(url) + if background is None: background = config.get('tabs', 'background-tabs') if background: + # Make sure the background tab has the correct initial size. + # With a foreground tab, it's going to be resized correctly by the + # layout anyways. + tab_size = QSize(self.width(), + self.height() - self.tabBar().height()) + tab.resize(tab_size) self.tab_index_changed.emit(self.currentIndex(), self.count()) else: self.setCurrentWidget(tab) + tab.show() self.new_tab.emit(tab, idx) return tab diff --git a/tests/end2end/data/javascript/windowsize.html b/tests/end2end/data/javascript/windowsize.html new file mode 100644 index 000000000..d2c077369 --- /dev/null +++ b/tests/end2end/data/javascript/windowsize.html @@ -0,0 +1,24 @@ + + + + + window sizes + + + + +

visible: unknown

+

hidden: unknown

+ + diff --git a/tests/end2end/data/scroll/simple.html b/tests/end2end/data/scroll/simple.html index 7da9df101..7f1bba4d5 100644 --- a/tests/end2end/data/scroll/simple.html +++ b/tests/end2end/data/scroll/simple.html @@ -3,10 +3,24 @@ Scrolling + Just a link +

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus

 0
 1
@@ -78,7 +92,7 @@
 67
 68
 69
-70
+70
 71
 72
 73
diff --git a/tests/end2end/features/javascript.feature b/tests/end2end/features/javascript.feature
index 7ea712d15..efdd692ac 100644
--- a/tests/end2end/features/javascript.feature
+++ b/tests/end2end/features/javascript.feature
@@ -72,6 +72,7 @@ Feature: Javascript stuff
     Scenario: Executing jseval when javascript is disabled
         When I set content -> allow-javascript to false
         And I run :jseval console.log('jseval executed')
+        And I set content -> allow-javascript to true
         Then the javascript message "jseval executed" should be logged
 
     ## webelement issues (mostly with QtWebEngine)
@@ -100,3 +101,18 @@ Feature: Javascript stuff
         And I run :click-element id listitem
         And I wait for "Sending fake click to *" in the log
         Then no crash should happen
+
+    # We load the tab in the background, and the HTML sets the window size for
+    # when it's hidden.
+    # Then, "the window sizes should be the same" uses :jseval to set the size
+    # when it's shown, and compares the two.
+    # https://github.com/qutebrowser/qutebrowser/issues/1190
+    # https://github.com/qutebrowser/qutebrowser/issues/2495
+
+    Scenario: Checking visible/invisible window size
+        When I run :tab-only
+        And I set general -> log-javascript-console to info
+        And I open data/javascript/windowsize.html in a new background tab
+        And I wait for "[*/data/javascript/windowsize.html:*] loaded" in the log
+        And I run :tab-next
+        Then the window sizes should be the same
diff --git a/tests/end2end/features/scroll.feature b/tests/end2end/features/scroll.feature
index 4e2643b6d..a69b6ffae 100644
--- a/tests/end2end/features/scroll.feature
+++ b/tests/end2end/features/scroll.feature
@@ -314,3 +314,12 @@ Feature: Scrolling
         And I wait until the scroll position changed
         And I run :scroll-page --bottom-navigate next 0 1
         Then data/hello2.txt should be loaded
+
+    Scenario: Scrolling to anchor in background tab
+        When I set general -> log-javascript-console to info
+        And I open about:blank
+        And I run :tab-only
+        And I open data/scroll/simple.html#anchor in a new background tab
+        And I run :tab-next
+        And I run :jseval --world main checkAnchor()
+        Then "[*] [PASS] Positions equal: *" should be logged
diff --git a/tests/end2end/features/test_javascript_bdd.py b/tests/end2end/features/test_javascript_bdd.py
index ca65a9d1d..9f6c021ce 100644
--- a/tests/end2end/features/test_javascript_bdd.py
+++ b/tests/end2end/features/test_javascript_bdd.py
@@ -19,3 +19,13 @@
 
 import pytest_bdd as bdd
 bdd.scenarios('javascript.feature')
+
+
+@bdd.then("the window sizes should be the same")
+def check_window_sizes(quteproc):
+    hidden = quteproc.wait_for_js('hidden window size: *')
+    quteproc.send_cmd(':jseval --world main updateText("visible")')
+    visible = quteproc.wait_for_js('visible window size: *')
+    hidden_size = hidden.message.split()[-1]
+    visible_size = visible.message.split()[-1]
+    assert hidden_size == visible_size
diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py
index 7971a657f..9c4f0fea8 100644
--- a/tests/end2end/fixtures/quteprocess.py
+++ b/tests/end2end/fixtures/quteprocess.py
@@ -430,7 +430,8 @@ class QuteProc(testprocess.Process):
             pattern="load status for <* tab_id=* url='*duckduckgo*'>: *",
             value=msg.message)
 
-        is_log_error = msg.loglevel > logging.INFO
+        is_log_error = (msg.loglevel > logging.INFO and
+                        not msg.message.startswith("Ignoring world ID"))
         return is_log_error or is_js_error or is_ddg_load
 
     def _maybe_skip(self):