2019-11-03 02:47:51 -05:00
|
|
|
import pytest
|
|
|
|
import os
|
|
|
|
|
2020-10-14 01:28:21 -04:00
|
|
|
from PySide2 import QtCore, QtTest, QtWidgets
|
2019-11-03 02:47:51 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
from .gui_base_test import GuiBaseTest
|
2019-11-03 02:47:51 -05:00
|
|
|
|
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
class TestTabs(GuiBaseTest):
|
2019-11-08 02:31:02 -05:00
|
|
|
# Shared test methods
|
|
|
|
|
2019-11-07 00:34:24 -05:00
|
|
|
def close_tab_with_active_server(self, tab):
|
|
|
|
# Start the server
|
|
|
|
self.assertEqual(
|
|
|
|
tab.get_mode().server_status.status,
|
|
|
|
tab.get_mode().server_status.STATUS_STOPPED,
|
|
|
|
)
|
2019-11-08 04:25:30 -05:00
|
|
|
tab.get_mode().server_status.server_button.click()
|
2019-11-07 00:34:24 -05:00
|
|
|
self.assertEqual(
|
|
|
|
tab.get_mode().server_status.status,
|
|
|
|
tab.get_mode().server_status.STATUS_WORKING,
|
|
|
|
)
|
2020-08-27 17:59:00 -04:00
|
|
|
QtTest.QTest.qWait(1000)
|
2019-11-07 00:34:24 -05:00
|
|
|
self.assertEqual(
|
|
|
|
tab.get_mode().server_status.status,
|
|
|
|
tab.get_mode().server_status.STATUS_STARTED,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Prepare to reject the dialog
|
2019-11-08 04:27:17 -05:00
|
|
|
QtCore.QTimer.singleShot(0, tab.close_dialog.reject_button.click)
|
2019-11-07 00:34:24 -05:00
|
|
|
|
|
|
|
# Close tab
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
2019-11-07 00:34:24 -05:00
|
|
|
|
|
|
|
# The tab should still be open
|
|
|
|
self.assertFalse(tab.new_tab.isVisible())
|
|
|
|
self.assertTrue(tab.get_mode().isVisible())
|
|
|
|
|
|
|
|
# Prepare to accept the dialog
|
2019-11-08 04:27:17 -05:00
|
|
|
QtCore.QTimer.singleShot(0, tab.close_dialog.accept_button.click)
|
2019-11-07 00:34:24 -05:00
|
|
|
|
|
|
|
# Close tab
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
2019-11-07 00:34:24 -05:00
|
|
|
|
|
|
|
# The tab should be closed
|
|
|
|
self.assertTrue(self.gui.tabs.widget(0).new_tab.isVisible())
|
|
|
|
|
2019-11-08 02:31:02 -05:00
|
|
|
def close_persistent_tab(self, tab):
|
|
|
|
# There shouldn't be a persistent settings file
|
|
|
|
self.assertFalse(os.path.exists(tab.settings.filename))
|
|
|
|
|
|
|
|
# Click the persistent checkbox
|
|
|
|
tab.get_mode().server_status.mode_settings_widget.persistent_checkbox.click()
|
|
|
|
QtTest.QTest.qWait(100)
|
|
|
|
|
|
|
|
# There should be a persistent settings file now
|
|
|
|
self.assertTrue(os.path.exists(tab.settings.filename))
|
|
|
|
|
|
|
|
# Prepare to reject the dialog
|
2019-11-08 04:27:17 -05:00
|
|
|
QtCore.QTimer.singleShot(0, tab.close_dialog.reject_button.click)
|
2019-11-08 02:31:02 -05:00
|
|
|
|
|
|
|
# Close tab
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
2019-11-08 02:31:02 -05:00
|
|
|
|
|
|
|
# The tab should still be open
|
|
|
|
self.assertFalse(tab.new_tab.isVisible())
|
|
|
|
self.assertTrue(tab.get_mode().isVisible())
|
|
|
|
|
|
|
|
# There should be a persistent settings file still
|
|
|
|
self.assertTrue(os.path.exists(tab.settings.filename))
|
|
|
|
|
|
|
|
# Prepare to accept the dialog
|
2019-11-08 04:27:17 -05:00
|
|
|
QtCore.QTimer.singleShot(0, tab.close_dialog.accept_button.click)
|
2019-11-08 02:31:02 -05:00
|
|
|
|
|
|
|
# Close tab
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
2019-11-08 02:31:02 -05:00
|
|
|
|
|
|
|
# The tab should be closed
|
|
|
|
self.assertTrue(self.gui.tabs.widget(0).new_tab.isVisible())
|
|
|
|
|
|
|
|
# The persistent settings file should be deleted
|
|
|
|
self.assertFalse(os.path.exists(tab.settings.filename))
|
|
|
|
|
|
|
|
# Tests
|
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_01_common_tests(self):
|
|
|
|
"""Run all common tests"""
|
|
|
|
self.run_all_common_setup_tests()
|
2019-11-03 02:47:51 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_02_starts_with_one_new_tab(self):
|
2019-11-03 02:47:51 -05:00
|
|
|
"""There should be one "New Tab" tab open"""
|
|
|
|
self.assertEqual(self.gui.tabs.count(), 1)
|
|
|
|
self.assertTrue(self.gui.tabs.widget(0).new_tab.isVisible())
|
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_03_new_tab_button_opens_new_tabs(self):
|
2019-11-03 02:47:51 -05:00
|
|
|
"""Clicking the "+" button should open new tabs"""
|
|
|
|
self.assertEqual(self.gui.tabs.count(), 1)
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.new_tab_button.click()
|
|
|
|
self.gui.tabs.new_tab_button.click()
|
|
|
|
self.gui.tabs.new_tab_button.click()
|
2019-11-03 02:47:51 -05:00
|
|
|
self.assertEqual(self.gui.tabs.count(), 4)
|
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_04_close_tab_button_closes_tabs(self):
|
2019-11-03 02:47:51 -05:00
|
|
|
"""Clicking the "x" button should close tabs"""
|
|
|
|
self.assertEqual(self.gui.tabs.count(), 4)
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
2019-11-03 02:47:51 -05:00
|
|
|
self.assertEqual(self.gui.tabs.count(), 1)
|
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_05_closing_last_tab_opens_new_one(self):
|
2019-11-03 02:47:51 -05:00
|
|
|
"""Closing the last tab should open a new tab"""
|
|
|
|
self.assertEqual(self.gui.tabs.count(), 1)
|
|
|
|
|
|
|
|
# Click share button
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.widget(0).share_button.click()
|
2019-11-03 02:47:51 -05:00
|
|
|
self.assertFalse(self.gui.tabs.widget(0).new_tab.isVisible())
|
|
|
|
self.assertTrue(self.gui.tabs.widget(0).share_mode.isVisible())
|
|
|
|
|
|
|
|
# Close the tab
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
2019-11-03 02:47:51 -05:00
|
|
|
|
|
|
|
# A new tab should be opened
|
|
|
|
self.assertEqual(self.gui.tabs.count(), 1)
|
|
|
|
self.assertTrue(self.gui.tabs.widget(0).new_tab.isVisible())
|
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_06_new_tab_mode_buttons_show_correct_modes(self):
|
2019-11-03 02:47:51 -05:00
|
|
|
"""Clicking the mode buttons in a new tab should change the mode of the tab"""
|
|
|
|
|
|
|
|
# New tab, share files
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.new_tab_button.click()
|
|
|
|
self.gui.tabs.widget(1).share_button.click()
|
2019-11-03 02:47:51 -05:00
|
|
|
self.assertFalse(self.gui.tabs.widget(1).new_tab.isVisible())
|
|
|
|
self.assertTrue(self.gui.tabs.widget(1).share_mode.isVisible())
|
2020-08-27 17:59:00 -04:00
|
|
|
self.assertEqual(
|
|
|
|
self.gui.status_bar.server_status_label.text(), "Ready to share"
|
|
|
|
)
|
2019-11-03 02:47:51 -05:00
|
|
|
|
|
|
|
# New tab, receive files
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.new_tab_button.click()
|
|
|
|
self.gui.tabs.widget(2).receive_button.click()
|
2019-11-03 02:47:51 -05:00
|
|
|
self.assertFalse(self.gui.tabs.widget(2).new_tab.isVisible())
|
|
|
|
self.assertTrue(self.gui.tabs.widget(2).receive_mode.isVisible())
|
2020-08-27 17:59:00 -04:00
|
|
|
self.assertEqual(
|
|
|
|
self.gui.status_bar.server_status_label.text(), "Ready to receive"
|
|
|
|
)
|
2019-11-03 02:47:51 -05:00
|
|
|
|
|
|
|
# New tab, publish website
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.new_tab_button.click()
|
|
|
|
self.gui.tabs.widget(3).website_button.click()
|
2019-11-03 02:47:51 -05:00
|
|
|
self.assertFalse(self.gui.tabs.widget(3).new_tab.isVisible())
|
|
|
|
self.assertTrue(self.gui.tabs.widget(3).website_mode.isVisible())
|
2020-08-27 17:59:00 -04:00
|
|
|
self.assertEqual(
|
|
|
|
self.gui.status_bar.server_status_label.text(), "Ready to share"
|
|
|
|
)
|
2019-11-03 02:47:51 -05:00
|
|
|
|
|
|
|
# Close tabs
|
2019-11-08 04:25:30 -05:00
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
|
|
|
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
|
2019-11-03 02:47:51 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_07_close_share_tab_while_server_started_should_warn(self):
|
2019-11-03 02:47:51 -05:00
|
|
|
"""Closing a share mode tab when the server is running should throw a warning"""
|
2019-11-08 06:11:30 -05:00
|
|
|
tab = self.new_share_tab_with_files()
|
2019-11-07 00:34:24 -05:00
|
|
|
self.close_tab_with_active_server(tab)
|
2019-11-03 02:47:51 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_08_close_receive_tab_while_server_started_should_warn(self):
|
2019-11-07 00:34:24 -05:00
|
|
|
"""Closing a recieve mode tab when the server is running should throw a warning"""
|
2019-11-08 02:31:02 -05:00
|
|
|
tab = self.new_receive_tab()
|
2019-11-07 00:34:24 -05:00
|
|
|
self.close_tab_with_active_server(tab)
|
2019-11-07 00:25:47 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_09_close_website_tab_while_server_started_should_warn(self):
|
2019-11-07 00:34:24 -05:00
|
|
|
"""Closing a website mode tab when the server is running should throw a warning"""
|
2019-11-08 06:11:30 -05:00
|
|
|
tab = self.new_website_tab_with_files()
|
2019-11-08 02:31:02 -05:00
|
|
|
self.close_tab_with_active_server(tab)
|
2019-11-03 02:47:51 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_10_close_persistent_share_tab_shows_warning(self):
|
2019-11-08 02:31:02 -05:00
|
|
|
"""Closing a share mode tab that's persistent should show a warning"""
|
2019-11-08 06:11:30 -05:00
|
|
|
tab = self.new_share_tab_with_files()
|
2019-11-08 02:31:02 -05:00
|
|
|
self.close_persistent_tab(tab)
|
2019-11-07 00:34:24 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_11_close_persistent_receive_tab_shows_warning(self):
|
2019-11-08 02:31:02 -05:00
|
|
|
"""Closing a receive mode tab that's persistent should show a warning"""
|
|
|
|
tab = self.new_receive_tab()
|
|
|
|
self.close_persistent_tab(tab)
|
2019-11-07 00:34:24 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_12_close_persistent_website_tab_shows_warning(self):
|
2019-11-08 02:31:02 -05:00
|
|
|
"""Closing a website mode tab that's persistent should show a warning"""
|
2019-11-08 06:11:30 -05:00
|
|
|
tab = self.new_website_tab_with_files()
|
2019-11-08 02:31:02 -05:00
|
|
|
self.close_persistent_tab(tab)
|
2019-11-03 02:47:51 -05:00
|
|
|
|
2019-11-08 02:57:12 -05:00
|
|
|
def test_13_quit_with_server_started_should_warn(self):
|
2019-11-08 02:40:37 -05:00
|
|
|
"""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,
|
|
|
|
)
|
2019-11-08 04:25:30 -05:00
|
|
|
tab.get_mode().server_status.server_button.click()
|
2019-11-08 02:40:37 -05:00
|
|
|
self.assertEqual(
|
|
|
|
tab.get_mode().server_status.status,
|
|
|
|
tab.get_mode().server_status.STATUS_WORKING,
|
|
|
|
)
|
2019-11-08 04:08:21 -05:00
|
|
|
QtTest.QTest.qWait(500)
|
2019-11-08 02:40:37 -05:00
|
|
|
self.assertEqual(
|
|
|
|
tab.get_mode().server_status.status,
|
|
|
|
tab.get_mode().server_status.STATUS_STARTED,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Prepare to reject the dialog
|
2019-11-08 04:27:17 -05:00
|
|
|
QtCore.QTimer.singleShot(0, self.gui.close_dialog.reject_button.click)
|
2019-11-08 02:40:37 -05:00
|
|
|
|
|
|
|
# Close the window
|
|
|
|
self.gui.close()
|
|
|
|
|
|
|
|
# The window should still be open
|
|
|
|
self.assertTrue(self.gui.isVisible())
|
|
|
|
|
2019-11-08 03:20:38 -05:00
|
|
|
# Stop the server
|
2019-11-08 04:25:30 -05:00
|
|
|
tab.get_mode().server_status.server_button.click()
|