Skip to content

Commit abadc46

Browse files
authored
Merge pull request #120 from mozilla/sl/undo-close-tab-private-browsing
Undo Tab Close Private Browsing
2 parents bacfeff + 7e9844b commit abadc46

8 files changed

+112
-7
lines changed

modules/browser_object_panel_ui.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,12 @@ def start_sync(self) -> BasePage:
132132
self.element_has_text("fxa-sync-label", "Sync now")
133133
self.get_element("fxa-sync-label").click()
134134
return self
135+
136+
def open_private_window(self) -> BasePage:
137+
"""
138+
Opens a new window in private browsing mode using the panel
139+
"""
140+
self.open_panel_menu()
141+
with self.driver.context(self.driver.CONTEXT_CHROME):
142+
self.get_element("panel-ui-new-private-window").click()
143+
return self

modules/browser_object_tabbar.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,29 @@ def new_window_by_keys(self, sys_platform: str) -> BasePage:
6565
).perform()
6666
return self
6767

68+
def reopen_closed_tab_by_keys(self, sys_platform: str) -> BasePage:
69+
"""Use keyboard shortcut to reopen a last closed tab"""
70+
if sys_platform == "Darwin":
71+
self.actions.key_down(Keys.COMMAND).key_down(Keys.SHIFT).send_keys(
72+
"t"
73+
).key_up(Keys.SHIFT).key_up(Keys.COMMAND).perform()
74+
else:
75+
self.actions.key_down(Keys.CONTROL).key_down(Keys.SHIFT).send_keys(
76+
"t"
77+
).key_up(Keys.SHIFT).key_up(Keys.CONTROL).perform()
78+
return self
79+
6880
def click_tab_by_title(self, title: str) -> BasePage:
6981
"""Given a full page title, click the corresponding tab"""
7082
with self.driver.context(self.driver.CONTEXT_CHROME):
7183
self.get_element("tab-by-title", labels=[title]).click()
7284
return self
7385

86+
def get_tab_by_title(self, title: str) -> BasePage:
87+
"""Given a full page title, return the corresponding tab"""
88+
with self.driver.context(self.driver.CONTEXT_CHROME):
89+
return self.get_element("tab-by-title", labels=[title])
90+
7491
def click_tab_by_index(self, index: int) -> BasePage:
7592
"""Given a tab index (int), click the corresponding tab"""
7693
with self.driver.context(self.driver.CONTEXT_CHROME):
@@ -247,3 +264,12 @@ def scroll_on_all_tabs_menu(self, down=True, pixels=200) -> BasePage:
247264
self.actions.move_by_offset(0, (sign * pixels))
248265
self.actions.release()
249266
self.actions.perform()
267+
268+
def close_tab(self, tab: WebElement) -> BasePage:
269+
"""
270+
Given the index of the tab, it closes that tab.
271+
"""
272+
# cur_tab = self.click_tab_by_index(index)
273+
with self.driver.context(self.driver.CONTEXT_CHROME):
274+
self.get_element("tab-x-icon", parent_element=tab).click()
275+
return self

modules/data/panel_ui.components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@
119119
"selectorData": "toolbarbutton[class='restoreallitem subviewbutton panel-subview-footer-button']",
120120
"strategy": "css",
121121
"groups": []
122+
},
123+
124+
"panel-ui-new-private-window": {
125+
"selectorData": "appMenu-new-private-window-button2",
126+
"strategy": "id",
127+
"groups": []
122128
}
123129

124130
}

modules/page_base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ def url_contains(self, url_part: str) -> Page:
391391
self.expect(EC.url_contains(url_part))
392392
return self
393393

394+
def title_contains(self, url_part: str) -> Page:
395+
"""Expect helper: wait until driver URL contains given text or timeout"""
396+
self.expect(EC.title_contains(url_part))
397+
return self
398+
394399
def verify_opened_image_url(self, url_substr: str, pattern: str) -> Page:
395400
"""
396401
Given a part of a URL and a regex, wait for that substring to exist in
@@ -545,11 +550,13 @@ def switch_to_new_tab(self) -> Page:
545550

546551
def wait_for_num_windows(self, num: int) -> Page:
547552
"""Wait for the number of open tabs + windows to equal given int"""
548-
return self.wait_for_num_tabs(num)
553+
with self.driver.context(self.driver.CONTEXT_CONTENT):
554+
return self.wait_for_num_tabs(num)
549555

550556
def switch_to_new_window(self) -> Page:
551557
"""Switch to newest window"""
552-
return self.switch_to_new_tab()
558+
with self.driver.context(self.driver.CONTEXT_CONTENT):
559+
return self.switch_to_new_tab()
553560

554561
def hide_popup(self, context_menu: str, chrome=False) -> Page:
555562
"""

tests/security_and_privacy/test_tls_v1_2_protocol.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ def test_tls_v1_2_protocol(driver: Firefox):
4141
EC.presence_of_element_located((By.ID, "security-technical-shortform"))
4242
)
4343

44-
expected_technical_details = ("Connection Encrypted (TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, 256 bit keys, "
45-
"TLS 1.2)")
44+
expected_technical_details = (
45+
"Connection Encrypted (TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, 256 bit keys, "
46+
"TLS 1.2)"
47+
)
4648
assert (
4749
technical_details.get_attribute("value") == expected_technical_details
4850
), f"Expected '{expected_technical_details}' but found '{technical_details.get_attribute('value')}'"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import logging
2+
3+
import pytest
4+
from selenium.webdriver import Firefox
5+
6+
from modules.browser_object import Navigation, PanelUi, TabBar
7+
from modules.page_object import GenericPage
8+
9+
VISIT_URL = "about:about"
10+
11+
12+
@pytest.fixture()
13+
def add_prefs():
14+
return []
15+
16+
17+
def test_undo_close_tab_private_browsing(driver: Firefox, sys_platform: str):
18+
"""
19+
C120118: ensure that you can close a tab in private browsing window
20+
"""
21+
# instantiate objs
22+
panel_ui = PanelUi(driver).open()
23+
nav = Navigation(driver)
24+
tabs = TabBar(driver)
25+
generic_page = GenericPage(driver, url="about:about")
26+
27+
# open a new private window and open a new tab
28+
panel_ui.open_private_window()
29+
tabs.switch_to_new_window()
30+
31+
# open a new tab
32+
tabs.new_tab_by_button()
33+
tabs.switch_to_new_tab()
34+
35+
# navigate to the URL
36+
nav.search(VISIT_URL)
37+
38+
# ensure its loaded
39+
generic_page.url_contains("about:about")
40+
41+
# close the most recent window
42+
cur_tab = tabs.get_tab_by_title("About About")
43+
tabs.close_tab(cur_tab)
44+
45+
# ensuring that one of the tabs was closed properly
46+
tabs.wait_for_num_tabs(2)
47+
assert len(driver.window_handles) == 2
48+
49+
# ensure the last tab can be reopened
50+
with driver.context(driver.CONTEXT_CHROME):
51+
tabs.reopen_closed_tab_by_keys(sys_platform)
52+
tabs.wait_for_num_tabs(2)
53+
tabs.switch_to_new_tab()
54+
logging.info(f"The observed title in the chrome context is {driver.title}")
55+
tabs.title_contains("Private Browsing")
56+
57+
logging.info(f"The observed title in the content context is {driver.title}")
58+
generic_page.title_contains("About About")

tests/tabs/test_list_all_tabs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import logging
2-
from time import sleep
32

4-
import pytest
53
from selenium.webdriver import Firefox
64
from selenium.webdriver.common.keys import Keys
75

tests/tabs/test_navigation_multiple_tabs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22

3-
import pytest
43
from selenium.webdriver import Firefox
54

65
from modules.browser_object import TabBar

0 commit comments

Comments
 (0)