mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Test closing window
This commit is contained in:
parent
786ff5d5bf
commit
cef0d7711b
@ -147,6 +147,20 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
# After connecting to Tor, check for updates
|
# After connecting to Tor, check for updates
|
||||||
self.check_for_updates()
|
self.check_for_updates()
|
||||||
|
|
||||||
|
# Create the close warning dialog -- the dialog widget needs to be in the constructor
|
||||||
|
# in order to test it
|
||||||
|
self.close_dialog = QtWidgets.QMessageBox()
|
||||||
|
self.close_dialog.setWindowTitle(strings._("gui_quit_warning_title"))
|
||||||
|
self.close_dialog.setText(strings._("gui_quit_warning_description"))
|
||||||
|
self.close_dialog.setIcon(QtWidgets.QMessageBox.Critical)
|
||||||
|
self.close_dialog.accept_button = self.close_dialog.addButton(
|
||||||
|
strings._("gui_quit_warning_quit"), QtWidgets.QMessageBox.AcceptRole
|
||||||
|
)
|
||||||
|
self.close_dialog.reject_button = self.close_dialog.addButton(
|
||||||
|
strings._("gui_quit_warning_cancel"), QtWidgets.QMessageBox.NoRole
|
||||||
|
)
|
||||||
|
self.close_dialog.setDefaultButton(self.close_dialog.reject_button)
|
||||||
|
|
||||||
def tor_connection_canceled(self):
|
def tor_connection_canceled(self):
|
||||||
"""
|
"""
|
||||||
If the user cancels before Tor finishes connecting, ask if they want to
|
If the user cancels before Tor finishes connecting, ask if they want to
|
||||||
@ -272,21 +286,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
if self.tabs.are_tabs_active():
|
if self.tabs.are_tabs_active():
|
||||||
# Open the warning dialog
|
# Open the warning dialog
|
||||||
dialog = QtWidgets.QMessageBox()
|
self.common.log("MainWindow", "closeEvent, opening warning dialog")
|
||||||
dialog.setWindowTitle(strings._("gui_quit_warning_title"))
|
self.close_dialog.exec_()
|
||||||
dialog.setText(strings._("gui_quit_warning_description"))
|
|
||||||
dialog.setIcon(QtWidgets.QMessageBox.Critical)
|
|
||||||
dialog.addButton(
|
|
||||||
strings._("gui_quit_warning_quit"), QtWidgets.QMessageBox.YesRole
|
|
||||||
)
|
|
||||||
cancel_button = dialog.addButton(
|
|
||||||
strings._("gui_quit_warning_cancel"), QtWidgets.QMessageBox.NoRole
|
|
||||||
)
|
|
||||||
dialog.setDefaultButton(cancel_button)
|
|
||||||
reply = dialog.exec_()
|
|
||||||
|
|
||||||
# Close
|
# Close
|
||||||
if reply == 0:
|
if self.close_dialog.clickedButton() == self.close_dialog.accept_button:
|
||||||
self.system_tray.hide()
|
self.system_tray.hide()
|
||||||
e.accept()
|
e.accept()
|
||||||
# Cancel
|
# Cancel
|
||||||
|
@ -337,6 +337,38 @@ class TestTabs(unittest.TestCase):
|
|||||||
tab = self.new_website_tab()
|
tab = self.new_website_tab()
|
||||||
self.close_persistent_tab(tab)
|
self.close_persistent_tab(tab)
|
||||||
|
|
||||||
|
@pytest.mark.gui
|
||||||
|
def test_016_quit_with_server_started_should_warn(self):
|
||||||
|
"""Quitting OnionShare with any active servers should show a warning"""
|
||||||
|
tab = self.new_share_tab()
|
||||||
|
|
||||||
|
# Start the server
|
||||||
|
self.assertEqual(
|
||||||
|
tab.get_mode().server_status.status,
|
||||||
|
tab.get_mode().server_status.STATUS_STOPPED,
|
||||||
|
)
|
||||||
|
QtTest.QTest.mouseClick(
|
||||||
|
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
tab.get_mode().server_status.status,
|
||||||
|
tab.get_mode().server_status.STATUS_WORKING,
|
||||||
|
)
|
||||||
|
QtTest.QTest.qWait(1000)
|
||||||
|
self.assertEqual(
|
||||||
|
tab.get_mode().server_status.status,
|
||||||
|
tab.get_mode().server_status.STATUS_STARTED,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Prepare to reject the dialog
|
||||||
|
QtCore.QTimer.singleShot(1000, self.gui.close_dialog.reject_button.click)
|
||||||
|
|
||||||
|
# Close the window
|
||||||
|
self.gui.close()
|
||||||
|
|
||||||
|
# The window should still be open
|
||||||
|
self.assertTrue(self.gui.isVisible())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user