From 3c625790cc7d4adb0c7b4c1822fa470a9934c02c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 20 Jan 2016 21:24:51 +0100 Subject: [PATCH] Don't crash if JS tab is closed twice. Fixes #906. --- qutebrowser/mainwindow/tabbedbrowser.py | 10 ++++++--- .../integration/data/javascript/issue906.html | 22 +++++++++++++++++++ tests/integration/features/javascript.feature | 15 +++++++++++++ tests/integration/features/test_javascript.py | 21 ++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 tests/integration/data/javascript/issue906.html create mode 100644 tests/integration/features/javascript.feature create mode 100644 tests/integration/features/test_javascript.py diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index dc6d3df46..bdf5f311b 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -272,8 +272,8 @@ class TabbedBrowser(tabwidget.TabWidget): """ idx = self.indexOf(tab) if idx == -1: - raise ValueError("tab {} is not contained in TabbedWidget!".format( - tab)) + raise TabDeletedError("tab {} is not contained in " + "TabbedWidget!".format(tab)) if tab is self._now_focused: self._now_focused = None if tab is objreg.get('last-focused-tab', None, scope='window', @@ -350,7 +350,11 @@ class TabbedBrowser(tabwidget.TabWidget): @pyqtSlot(webview.WebView) def on_window_close_requested(self, widget): """Close a tab with a widget given.""" - self.close_tab(widget) + try: + self.close_tab(widget) + except TabDeletedError: + log.webview.debug("Requested to close {!r} which does not " + "exist!".format(widget)) @pyqtSlot('QUrl', bool) def tabopen(self, url=None, background=None, explicit=False): diff --git a/tests/integration/data/javascript/issue906.html b/tests/integration/data/javascript/issue906.html new file mode 100644 index 000000000..14378971f --- /dev/null +++ b/tests/integration/data/javascript/issue906.html @@ -0,0 +1,22 @@ + + + + + + + + + + + diff --git a/tests/integration/features/javascript.feature b/tests/integration/features/javascript.feature new file mode 100644 index 000000000..1c3960f4b --- /dev/null +++ b/tests/integration/features/javascript.feature @@ -0,0 +1,15 @@ +Feature: Javascript stuff + + Integration with javascript. + + # https://github.com/The-Compiler/qutebrowser/issues/906 + + Scenario: Closing a JS window twice (issue 906) + When I open about:blank + And I open data/javascript/issue906.html in a new tab + And I run :hint + And I run :follow-hint a + And I run :tab-focus 2 + And I run :hint + And I run :follow-hint s + Then "Requested to close * which does not exist!" should be logged diff --git a/tests/integration/features/test_javascript.py b/tests/integration/features/test_javascript.py new file mode 100644 index 000000000..78d45ab5a --- /dev/null +++ b/tests/integration/features/test_javascript.py @@ -0,0 +1,21 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2016 Florian Bruhin (The Compiler) +# +# 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 . + +import pytest_bdd as bdd +bdd.scenarios('javascript.feature')