From 0851999b8985998309f6129416d9648d31daa927 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 23 Oct 2015 14:01:22 +0200 Subject: [PATCH] Add unit/regression test --- tests/helpers/stubs.py | 15 +++++++- tests/unit/mainwindow/test_tabwidget.py | 50 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/unit/mainwindow/test_tabwidget.py diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index 58e88a81e..844de59a2 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -26,8 +26,9 @@ from unittest import mock from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache, QNetworkCacheMetaData) -from PyQt5.QtWidgets import QCommonStyle +from PyQt5.QtWidgets import QCommonStyle, QWidget +from qutebrowser.browser import webview from qutebrowser.config import configexc @@ -204,6 +205,18 @@ def fake_qprocess(): return m +class FakeWebView(QWidget): + + """Fake WebView which can be added to a tab.""" + + def __init__(self): + super().__init__() + self.progress = 0 + self.scroll_pos = (-1, -1) + self.load_status = webview.LoadStatus.none + self.tab_id = 0 + + class FakeSignal: """Fake pyqtSignal stub which does nothing. diff --git a/tests/unit/mainwindow/test_tabwidget.py b/tests/unit/mainwindow/test_tabwidget.py new file mode 100644 index 000000000..4cf817123 --- /dev/null +++ b/tests/unit/mainwindow/test_tabwidget.py @@ -0,0 +1,50 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015 Daniel Schadt +# +# 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 . + +"""Tests for the custom TabWidget/TabBar.""" + +import pytest +import functools + +from qutebrowser.mainwindow import tabwidget +from PyQt5.QtGui import QIcon, QPixmap + + +class TestTabWidget: + + """Tests for TabBar.""" + + @pytest.fixture + def widget(self, qtbot, default_config): + w = tabwidget.TabWidget(0) + qtbot.addWidget(w) + return w + + def test_small_icon_doesnt_crash(self, widget, qtbot, stubs): + """Test that setting a small icon doesn't produce a crash. + + Regression test for #1015. + """ + # Size taken from issue report + pixmap = QPixmap(72, 1) + icon = QIcon(pixmap) + page = stubs.FakeWebView() + widget.addTab(page, icon, 'foobar') + widget.show() + qtbot.waitForWindowShown(widget)