Skip to content

Commit 839deec

Browse files
authored
Anca/ Add test restored closed tabs removed from all history entries (#1050)
* Add test restored closed tabs removed from all history entries * Add test to key.manifest * Revert to an earlier line * Add hard sleep * Remove duplication
1 parent ddc92fc commit 839deec

File tree

6 files changed

+127
-8
lines changed

6 files changed

+127
-8
lines changed

manifests/key.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,10 @@ session_restore:
10181018
result: pass
10191019
splits:
10201020
- functional2
1021+
test_restored_closed_tabs_removed_from_all_history_entries:
1022+
result: pass
1023+
splits:
1024+
- functional2
10211025
sync_and_fxa:
10221026
test_existing_fxa:
10231027
result: unstable

modules/browser_object_panel_ui.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,12 @@ def redirect_to_about_logins_page(self) -> BasePage:
167167

168168
@BasePage.context_chrome
169169
def reopen_recently_closed_tabs(self) -> BasePage:
170-
"""Reopen all recently closed tabs"""
170+
"""Navigate to Hamburger > History > Recently Closed Tabs subview."""
171171
self.open_panel_menu()
172172
self.click_on("panel-ui-history")
173-
174173
self.click_on("panel-ui-history-recently-closed")
175-
if self.sys_platform() in ("Linux", "Darwin"):
176-
sleep(2)
177-
174+
sleep(2)
178175
self.click_on("panel-ui-history-recently-closed-reopen-tabs")
179-
180176
return self
181177

182178
# History
@@ -394,7 +390,29 @@ def unfocus_address_bar(self) -> None:
394390

395391
@BasePage.context_chrome
396392
def reopen_all_recently_closed_tabs(self) -> BasePage:
397-
"""Reopen all recently closed tabs"""
393+
"""Reopen all recently closed tabs via Hamburger > History > Recently Closed."""
398394
self.reopen_recently_closed_tabs()
395+
self.element_visible("reopen-all-closed-tabs-button")
399396
self.click_on("reopen-all-closed-tabs-button")
400397
return self
398+
399+
@BasePage.context_chrome
400+
def get_recently_closed_tab_urls(self):
401+
"""Get URLs/labels of recently closed tabs from the Hamburger menu."""
402+
self.reopen_recently_closed_tabs()
403+
items = self.get_elements("bookmark-item")
404+
urls = []
405+
for item in items:
406+
if item.is_displayed():
407+
label = item.get_attribute("label") or ""
408+
urls.append(label)
409+
return urls
410+
411+
@BasePage.context_chrome
412+
def verify_urls_not_in_recently_closed(self, urls: set[str]):
413+
"""Verify that the specified URLs are not in the recently closed tabs list."""
414+
recently_closed = set(self.get_recently_closed_tab_urls())
415+
found = urls.intersection(recently_closed)
416+
assert len(found) == 0, (
417+
f"Expected URLs to be removed from recently closed, but found: {found}"
418+
)

modules/browser_object_tabbar.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,3 +663,14 @@ def verify_removed_tab_displayed_after_group(self, tab_index: int):
663663
f"Tab position: {tab_position}, Group end: {group_end_position}"
664664
)
665665
return self
666+
667+
def get_all_window_urls(self) -> set[str]:
668+
"""Get URLs from all open windows/tabs.
669+
Iterates through all window handles and collects current URLs
670+
"""
671+
urls = set()
672+
with self.driver.context(self.driver.CONTEXT_CONTENT):
673+
for handle in self.driver.window_handles:
674+
self.driver.switch_to.window(handle)
675+
urls.add(self.driver.current_url)
676+
return urls

modules/data/panel_ui.components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
"groups": []
293293
},
294294
"reopen-all-closed-tabs-button": {
295-
"selectorData": "toolbarbutton[class='restoreallitem subviewbutton panel-subview-footer-button'][label='Reopen all tabs']",
295+
"selectorData": "toolbarbutton.restoreallitem[label='Reopen all tabs']",
296296
"strategy": "css",
297297
"groups": []
298298
}

modules/page_object_firefox_view.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ def wait_for_closed_tabs_with_urls(self, expected_urls: set[str]) -> BasePage:
6262
lambda _: expected_urls.issubset(set(self.get_closed_tab_urls()))
6363
)
6464
return self
65+
66+
def wait_for_no_closed_tabs(self) -> BasePage:
67+
"""Wait until the Recently Closed section has no tab entries."""
68+
self.wait.until(lambda _: len(self.get_closed_tab_urls()) == 0)
69+
return self
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import platform
2+
3+
import pytest
4+
from selenium.webdriver import Firefox
5+
6+
from modules.browser_object import TabBar
7+
from modules.browser_object_panel_ui import PanelUi
8+
from modules.page_object_firefox_view import FirefoxView
9+
10+
11+
@pytest.fixture()
12+
def test_case():
13+
return "2333482"
14+
15+
16+
URLS_TO_CLOSE = {
17+
"window1": ["about:mozilla", "about:robots"],
18+
"window2": ["about:logo", "about:license"],
19+
"window3": ["about:buildconfig", "about:credits"],
20+
}
21+
ALL_CLOSED_URLS = set(sum(URLS_TO_CLOSE.values(), []))
22+
23+
24+
def test_restored_closed_tabs_removed_from_all_history_entries(driver: Firefox):
25+
"""
26+
C2333482 - Verify that closed tabs from multiple windows can be restored via Hamburger Menu > History > Recently
27+
Closed Tabs > Reopen All Tabs, and that they are removed from Firefox View, hamburger menu, and History menu bar.
28+
"""
29+
# Initialize objects
30+
tabs = TabBar(driver)
31+
fx_view = FirefoxView(driver)
32+
panel = PanelUi(driver)
33+
main_window = driver.current_window_handle
34+
35+
# Helper method to open tabs in a new window and close them
36+
def close_tabs_in_new_window(urls: list[str]):
37+
"""Open a new window, create tabs for URLs, then close them."""
38+
driver.switch_to.window(main_window)
39+
tabs.open_and_switch_to_new_window("window")
40+
tabs.clear_cache()
41+
tabs.open_urls_in_tabs(urls)
42+
tabs.close_last_n_tabs(total_tabs=1 + len(urls), count=len(urls))
43+
44+
# Close tabs across multiple windows
45+
tabs.open_urls_in_tabs(["about:about"] + URLS_TO_CLOSE["window1"])
46+
tabs.close_last_n_tabs(total_tabs=4, count=2) # leave one tab opened
47+
48+
close_tabs_in_new_window(URLS_TO_CLOSE["window2"])
49+
close_tabs_in_new_window(URLS_TO_CLOSE["window3"])
50+
51+
# Verify closed tabs appear in Firefox View
52+
driver.switch_to.window(main_window)
53+
fx_view.open_recently_closed()
54+
fx_view.wait_for_closed_tabs_with_urls(ALL_CLOSED_URLS)
55+
56+
# Restore all closed tabs via Panel UI (must navigate away from Firefox View first)
57+
driver.get("about:blank")
58+
panel.clear_cache()
59+
panel.reopen_all_recently_closed_tabs()
60+
tabs.custom_wait(timeout=30).until(
61+
lambda _: ALL_CLOSED_URLS.issubset(tabs.get_all_window_urls())
62+
)
63+
64+
# Verify all recently closed lists are now empty
65+
# Verify Firefox View
66+
driver.switch_to.window(main_window)
67+
fx_view.clear_cache()
68+
fx_view.open_recently_closed()
69+
fx_view.wait_for_no_closed_tabs()
70+
71+
# Verify Panel UI
72+
panel.verify_urls_not_in_recently_closed(ALL_CLOSED_URLS)
73+
74+
# Verify Menu Bar (not on macOS)
75+
if platform.system() != "Darwin":
76+
from modules.browser_object_menu_bar import MenuBar
77+
78+
menu_bar = MenuBar(driver)
79+
assert len(menu_bar.get_recently_closed_urls()) == 0, (
80+
"Expected no recently closed tabs in menu bar"
81+
)

0 commit comments

Comments
 (0)