def test_add_bookmark(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().add_or_remove_bookmark( instance.tabs.currentWidget().current_url) if "github.com" in instance.bookmark_list: assert True else: assert False
def test_set_start_page(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("google.com") instance.set_start_page() # Should have set the start page to the current url that's loaded in the selected tab if instance.start_page == "google.com": assert True else: assert False
def test_clear_history(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("google.com") instance.tabs.currentWidget().register_address("bing.com") instance.clear_history() if len(instance.history_list) == 0: assert True else: assert False
def test_add_history(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().register_address("google.com") if ("github.com" in instance.history_list) and ("google.com" in instance.history_list): assert True else: assert False
def test_prev_page(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().register_address("google.com") instance.tabs.currentWidget().prev_page() if instance.tabs.currentWidget().current_url == "github.com": assert True else: assert False
def test_prev_page_back_button_stack(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().register_address("google.com") instance.tabs.currentWidget().prev_page() # Back button stack should now be empty now that we naviaged back to 'github.com' with prev_page if len(instance.tabs.currentWidget().back_history_stack) == 0: assert True else: assert False
def test_amazon_time(): f = open("performanceMetrics.txt", "a+") start_time = time.time() app = QApplication(sys.argv) a_window = web_gui.BrowserWindow(None) a_window.add_tab() a_window.tabs.currentWidget().register_address('amazon.com') f.write("Time to load 'amazon.com' in seconds: " + str(time.time() - start_time) + "\n") assert True
def test_back_button_stack_no_last_url(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().register_address("google.com") instance.tabs.currentWidget().register_address("bing.com") # 'bing.com' is the current url so it shouldn't be part of the back button's stack yet (will get added when another website is loaded) if "bing.com" not in instance.tabs.currentWidget().back_history_stack: assert True else: assert False
def test_new_tab_opens_start_page(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") instance.set_start_page() # Set the start page to 'github.com' instance.add_tab() # The new tab should open 'github.com' since it is the selected start page if instance.tabs.currentWidget().current_url == "github.com": assert True else: assert False
def test_add_bookmarks_multi_tabs_2(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") # First time adds the bookmark instance.tabs.currentWidget().add_or_remove_bookmark( instance.tabs.currentWidget().current_url) instance.add_tab() # Adds a tab and sets it as current tab instance.tabs.currentWidget().register_address("github.com") if instance.tabs.currentWidget().current_url in instance.bookmark_list: assert True else: assert False
def test_history_multiple_tabs(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) # Load one website to add it to back history stack for the current tab instance.tabs.currentWidget().register_address("github.com") instance.add_tab() # create a second tab # Load url in the second tab instance.tabs.currentWidget().register_address("google.com") # urls loaded in both tabs should be added to history list if len(instance.history_list) == 2: assert True else: assert False
def test_remove_bookmark(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") # First time adds the bookmark instance.tabs.currentWidget().add_or_remove_bookmark( instance.tabs.currentWidget().current_url) # Second time it detects the bookmark is already there so it removes it instance.tabs.currentWidget().add_or_remove_bookmark( instance.tabs.currentWidget().current_url) if "github.com" not in instance.bookmark_list: assert True else: assert False
def test_clear_forward_stack(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().register_address("google.com") instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().prev_page() instance.tabs.currentWidget().prev_page() instance.tabs.currentWidget().register_address("https://atom.io") # Forward history stack should be emptied every time there's a new url that's loaded (except for the back button's calls to register_address) if len(instance.tabs.currentWidget().forward_history_stack) == 0: assert True else: assert False
def test_separate_back_button_stack_per_tab(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) # Load one website to add it to back history stack for the current tab instance.tabs.currentWidget().register_address("github.com") instance.add_tab() # create a second tab # Load url in the second tab instance.tabs.currentWidget().register_address("google.com") instance.tabs.setCurrentIndex(0) # switch back to the first tab # If the url loaded in the second tab shows up in the back button stack for the first tab, assert False if "google.com" not in instance.tabs.currentWidget().back_history_stack: assert True else: assert False
def test_forward_stack_contents(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().register_address("google.com") instance.tabs.currentWidget().register_address("github.com") instance.tabs.currentWidget().prev_page() instance.tabs.currentWidget().prev_page() if instance.tabs.currentWidget( ).forward_history_stack[0] == "github.com" and instance.tabs.currentWidget( ).forward_history_stack[1] == "google.com": assert True else: assert False
def test_back_button_stack(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("google.com") instance.tabs.currentWidget().register_address("bing.com") instance.tabs.currentWidget().register_address("github.com") # Tests whether the first element is the first website searched and the second element is the second website searched if instance.tabs.currentWidget( ).back_history_stack[0] == "google.com" and instance.tabs.currentWidget( ).back_history_stack[1] == "bing.com": assert True else: assert False
def test_zoom_out(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) instance.tabs.currentWidget().register_address("google.com") starting_font_size = instance.tabs.currentWidget().font_size starting_title_font_size = instance.tabs.currentWidget().title_font_size instance.tabs.currentWidget().zoom_out() # Text should be smaller than when it first started out if starting_font_size > instance.tabs.currentWidget( ).font_size and starting_title_font_size > instance.tabs.currentWidget( ).title_font_size: assert True else: assert False
def test_set_start_page_in_new_tab(): app = QApplication(sys.argv) instance = web_gui.BrowserWindow(None) # Load a website in the default tab instance.tabs.currentWidget().register_address("google.com") instance.add_tab() # add a new tab (should switch to it as default) # Load a different website in the new tab instance.tabs.currentWidget().register_address("bing.com") instance.set_start_page() # call set_start_page # Should set the start page to the new tab's url, not the first tab's url if instance.start_page == "bing.com": assert True else: assert False