Merge remote-tracking branch 'origin/pr/3582'

This commit is contained in:
Florian Bruhin 2018-02-11 09:37:49 +01:00
commit f28ab5285c
4 changed files with 38 additions and 11 deletions

View File

@ -253,7 +253,10 @@ class TabbedBrowser(tabwidget.TabWidget):
def shutdown(self):
"""Try to shut down all tabs cleanly."""
self.shutting_down = True
for tab in self.widgets():
# Reverse tabs so we don't have to recacluate tab titles over and over
# Removing first causes [2..-1] to be recomputed
# Removing the last causes nothing to be recomputed
for tab in reversed(self.widgets()):
self._remove_tab(tab)
def tab_close_prompt_if_pinned(

View File

@ -110,8 +110,6 @@ class TabWidget(QTabWidget):
tab.data.pinned = pinned
self._update_tab_title(idx)
bar.refresh()
def tab_indicator_color(self, idx):
"""Get the tab indicator color for the given index."""
return self.tabBar().tab_indicator_color(idx)
@ -150,8 +148,9 @@ class TabWidget(QTabWidget):
title = '' if fmt is None else fmt.format(**fields)
tabbar = self.tabBar()
tabbar.setTabText(idx, title)
tabbar.setTabToolTip(idx, title)
if tabbar.tabText(idx) != title:
tabbar.setTabText(idx, title)
tabbar.setTabToolTip(idx, title)
def get_tab_fields(self, idx):
"""Get the tab field data."""

View File

@ -261,6 +261,9 @@ class FakeWebTab(browsertab.AbstractTab):
def load_status(self):
return self._load_status
def shutdown(self):
pass
class FakeSignal:

View File

@ -23,7 +23,7 @@ import pytest
from PyQt5.QtGui import QIcon, QPixmap
from qutebrowser.mainwindow import tabwidget
from qutebrowser.mainwindow import tabwidget, tabbedbrowser
from qutebrowser.utils import usertypes
@ -39,6 +39,14 @@ class TestTabWidget:
usertypes.Backend.QtWebKit)
return w
@pytest.fixture
def browser(self, qtbot, monkeypatch, config_stub):
w = tabbedbrowser.TabbedBrowser(win_id=0, private=False)
qtbot.addWidget(w)
monkeypatch.setattr(tabwidget.objects, 'backend',
usertypes.Backend.QtWebKit)
return w
def test_small_icon_doesnt_crash(self, widget, qtbot, fake_web_tab):
"""Test that setting a small icon doesn't produce a crash.
@ -53,15 +61,29 @@ class TestTabWidget:
with qtbot.waitExposed(widget):
widget.show()
@pytest.mark.parametrize("num_tabs", [4, 10])
def test_update_tab_titles_benchmark(self, benchmark, widget,
qtbot, fake_web_tab):
qtbot, fake_web_tab, num_tabs):
"""Benchmark for update_tab_titles."""
widget.addTab(fake_web_tab(), 'foobar')
widget.addTab(fake_web_tab(), 'foobar2')
widget.addTab(fake_web_tab(), 'foobar3')
widget.addTab(fake_web_tab(), 'foobar4')
for i in range(num_tabs):
widget.addTab(fake_web_tab(), 'foobar' + str(i))
with qtbot.waitExposed(widget):
widget.show()
benchmark(widget._update_tab_titles)
@pytest.mark.parametrize("num_tabs", [4, 10])
def test_add_remove_tab_benchmark(self, benchmark, browser,
qtbot, fake_web_tab, num_tabs):
"""Benchmark for addTab and removeTab."""
def _run_bench():
for i in range(num_tabs):
browser.addTab(fake_web_tab(), 'foobar' + str(i))
with qtbot.waitExposed(browser):
browser.show()
browser.shutdown()
benchmark(_run_bench)