Don't crash if JS tab is closed twice.

Fixes #906.
This commit is contained in:
Florian Bruhin 2016-01-20 21:24:51 +01:00
parent 6bd092a948
commit 3c625790cc
4 changed files with 65 additions and 3 deletions

View File

@ -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):

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<body>
<button onclick="openWin()">Open "myWindow"</button>
<button onclick="closeWin()">Close "myWindow"</button>
<script>
var myWindow;
function openWin() {
myWindow = window.open("", "myWindow", "width=200, height=100");
}
function closeWin() {
myWindow.close();
myWindow.close();
}
</script>
</body>
</html>

View File

@ -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

View File

@ -0,0 +1,21 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# 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 <http://www.gnu.org/licenses/>.
import pytest_bdd as bdd
bdd.scenarios('javascript.feature')