Skip to content

Commit 51381b7

Browse files
committed
finished
1 parent 8034aeb commit 51381b7

9 files changed

+220
-92
lines changed
Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from typing import List
2+
3+
from selenium.webdriver.remote.webelement import WebElement
4+
15
from modules.browser_object_navigation import Navigation
26
from modules.page_base import BasePage
37

@@ -8,25 +12,51 @@ class TrackerPanel(BasePage):
812
"""
913

1014
URL_TEMPLATE = ""
11-
NAV = None
1215

13-
def wait_for_blocked_tracking_icon(self, nav: Navigation, page: BasePage):
16+
def wait_for_blocked_tracking_icon(
17+
self, nav: Navigation, page: BasePage
18+
) -> BasePage:
1419
"""
1520
Waits for the shield icon to indicate that cookies/trackers are being blocked by continuously refresing the page
16-
"""
17-
self.driver.set_context(self.driver.CONTEXT_CHROME)
1821
19-
while 1:
20-
nav.get_element("refresh-button").click()
22+
Remember to open the passed in page beforehand, this waits for the page to load.
2123
24+
Example Usage:
25+
first_tracker_website.open()
26+
tracker_panel.wait_for_blocked_tracking_icon(nav, first_tracker_website)
27+
"""
28+
self.driver.set_context(self.driver.CONTEXT_CHROME)
29+
try:
30+
while 1:
31+
nav.get_element("refresh-button").click()
32+
33+
self.driver.set_context(self.driver.CONTEXT_CONTENT)
34+
page.wait_for_page_to_load()
35+
36+
self.driver.set_context(self.driver.CONTEXT_CHROME)
37+
shield_icon = nav.get_element("shield-icon")
38+
39+
if (
40+
shield_icon.get_attribute("data-l10n-id")
41+
== "tracking-protection-icon-active-container"
42+
):
43+
return
44+
finally:
2245
self.driver.set_context(self.driver.CONTEXT_CONTENT)
23-
page.wait_for_page_to_load()
46+
return self
2447

25-
self.driver.set_context(self.driver.CONTEXT_CHROME)
48+
def verify_tracker_shield_indicator(self, nav: Navigation) -> BasePage:
49+
with self.driver.context(self.driver.CONTEXT_CHROME):
2650
shield_icon = nav.get_element("shield-icon")
27-
28-
if (
51+
assert (
2952
shield_icon.get_attribute("data-l10n-id")
3053
== "tracking-protection-icon-active-container"
31-
):
32-
return
54+
), "The label detected did not correspond to the expected one: tracking-protection-icon-no-trackers-detected-container"
55+
56+
def open_and_return_cross_site_trackers(self) -> List[WebElement]:
57+
self.get_element("tracker-cross-site-tracking").click()
58+
return self.get_elements("tracking-cross-site-tracking-item")
59+
60+
def open_and_return_allowed_trackers(self) -> List[WebElement]:
61+
self.get_element("tracker-tracking-content").click()
62+
return self.get_elements("tracking-allowed-content-item")

modules/data/generic_page.components.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,23 @@
2121
"selectorData": "mw-mmv-image",
2222
"strategy": "class",
2323
"groups": []
24+
},
25+
26+
"simulated-tracker-block-status": {
27+
"selectorData": "blacklisted-blocked",
28+
"strategy": "id",
29+
"groups": []
30+
},
31+
32+
"simulated-tracker-load-status": {
33+
"selectorData": "whitelisted-loaded",
34+
"strategy": "id",
35+
"groups": []
36+
},
37+
38+
"simulated-tracker-dnt-status": {
39+
"selectorData": "dnt-on",
40+
"strategy": "id",
41+
"groups": []
2442
}
2543
}

modules/data/navigation.components.json

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -224,48 +224,6 @@
224224
"groups": []
225225
},
226226

227-
"tracker-title": {
228-
"selectorData": "protections-popup-mainView-panel-header-span",
229-
"strategy": "id",
230-
"groups": []
231-
},
232-
233-
"tracker-cross-site-tracking": {
234-
"selectorData": "protections-popup-category-cookies",
235-
"strategy": "id",
236-
"groups": []
237-
},
238-
239-
"tracker-tracking-content": {
240-
"selectorData": "protections-popup-category-trackers",
241-
"strategy": "id",
242-
"groups": []
243-
},
244-
245-
"tracking-social-media": {
246-
"selectorData": "protections-popup-category-socialblock",
247-
"strategy": "id",
248-
"groups": []
249-
},
250-
251-
"tracking-finger-prints": {
252-
"selectorData": "protections-popup-category-fingerprinters",
253-
"strategy": "id",
254-
"groups": []
255-
},
256-
257-
"tracking-crypto-miners": {
258-
"selectorData": "protections-popup-category-cryptominers",
259-
"strategy": "id",
260-
"groups": []
261-
},
262-
263-
"tracking-cross-site-tracking-items": {
264-
"selectorData": "protections-popup-cookiesView-list-section",
265-
"strategy": "class",
266-
"groups": []
267-
},
268-
269227
"refresh-button": {
270228
"selectorData": "reload-button",
271229
"strategy": "id",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
11
{
2+
"context": "chrome",
3+
"tracker-title": {
4+
"selectorData": "protections-popup-mainView-panel-header-span",
5+
"strategy": "id",
6+
"groups": []
7+
},
28

9+
"tracker-cross-site-tracking": {
10+
"selectorData": "protections-popup-category-cookies",
11+
"strategy": "id",
12+
"groups": []
13+
},
14+
15+
"tracker-tracking-content": {
16+
"selectorData": "protections-popup-category-trackers",
17+
"strategy": "id",
18+
"groups": []
19+
},
20+
21+
"tracking-social-media": {
22+
"selectorData": "protections-popup-category-socialblock",
23+
"strategy": "id",
24+
"groups": []
25+
},
26+
27+
"tracking-finger-prints": {
28+
"selectorData": "protections-popup-category-fingerprinters",
29+
"strategy": "id",
30+
"groups": []
31+
},
32+
33+
"tracking-crypto-miners": {
34+
"selectorData": "protections-popup-category-cryptominers",
35+
"strategy": "id",
36+
"groups": []
37+
},
38+
39+
"tracking-cross-site-tracking-items": {
40+
"selectorData": "vbox[class='protections-popup-cookiesView-list-section']",
41+
"strategy": "css",
42+
"groups": []
43+
},
44+
45+
"tracking-cross-site-tracking-item": {
46+
"selectorData": "protections-popup-list-host-label",
47+
"strategy": "class",
48+
"groups": []
49+
},
50+
51+
"tracking-allowed-content-item": {
52+
"selectorData": "protections-popup-list-host-label",
53+
"strategy": "class",
54+
"groups": []
55+
}
356
}

modules/page_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ def get_all_children(
536536
Gets all the children of a webelement
537537
"""
538538
children = None
539+
print(self.context_id)
539540
with self.driver.context(self.context_id):
540541
element = self.fetch(reference, labels)
541542
children = element.find_elements(By.XPATH, "./*")

modules/page_object_autofill_login.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from selenium.webdriver import Firefox
2-
31
from modules.page_object_autofill import Autofill
42

53

tests/security_and_privacy/test_open_link_in_private_window.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import logging
2-
3-
import pytest
41
from selenium.webdriver import Firefox
52

63
from modules.browser_object import ContextMenu, Navigation
7-
from modules.page_object import ExamplePage, GenericPage
4+
from modules.page_object import ExamplePage
85

96

107
def test_open_link_in_private_window(driver: Firefox):
Lines changed: 105 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,127 @@
1-
import logging
2-
from time import sleep
3-
4-
import pytest
51
from selenium.webdriver import Firefox
62

7-
from modules.browser_object import Navigation, PanelUi, TabBar, TrackerPanel
3+
from modules.browser_object import Navigation, PanelUi, TrackerPanel
84
from modules.page_object import GenericPage
95

10-
# @pytest.fixture()
11-
# def add_prefs():
12-
# return [("browser.contentblocking.category", "standard")]
6+
ALLOWED_TRACKING_URLS = set(
7+
[
8+
"https://content-track-digest256.dummytracker.org",
9+
"https://ads-track-digest256.dummytracker.org",
10+
"https://social-track-digest256.dummytracker.org",
11+
"https://analytics-track-digest256.dummytracker.org",
12+
]
13+
)
14+
BLOCKED_TRACKER_URL = "https://content-track-digest256.dummytracker.org"
15+
16+
FIRST_TRACKER_WEBSITE = "https://senglehardt.com/test/trackingprotection/test_pages/tracking_protection.html"
17+
SECOND_TRACKER_WEBSITE = "https://www.itisatrap.org/firefox/its-a-tracker.html"
1318

1419

15-
def test_third_party_content_blocked_private_browsing(driver: Firefox):
20+
def test_third_party_content_blocked_private_browsing_cross_site(driver: Firefox):
1621
"""
17-
C446323: Ensure that third party content is blocked correctly
22+
C446323.1: Ensure that third party content is blocked correctly
1823
"""
24+
# instantiate objects
1925
panel_ui = PanelUi(driver).open()
2026
nav = Navigation(driver)
2127
tracker_panel = TrackerPanel(driver)
22-
first_tracker_website = GenericPage(
23-
driver,
24-
url="https://senglehardt.com/test/trackingprotection/test_pages/tracking_protection.html",
25-
)
26-
second_tracker_website = GenericPage(
27-
driver, url="https://itisatrap.org/firefox/its-a-tracker.html"
28-
)
28+
tracker_website = GenericPage(driver, url=FIRST_TRACKER_WEBSITE)
2929

30+
# open the new window
3031
panel_ui.open_private_window()
3132
nav.switch_to_new_window()
3233

33-
first_tracker_website.open()
34-
35-
tracker_panel.wait_for_blocked_tracking_icon(nav, first_tracker_website)
34+
# open the website, ensure the blocking is taking place by continuously refreshing website until indicated
35+
tracker_website.open()
36+
tracker_panel.wait_for_blocked_tracking_icon(nav, tracker_website)
3637

37-
# first_tracker_website.open()
38+
# verify the indicator
3839
driver.set_context(driver.CONTEXT_CHROME)
40+
tracker_panel.verify_tracker_shield_indicator(nav)
41+
nav.open_tracker_panel()
3942

40-
shield_icon = nav.get_element("shield-icon")
41-
42-
# # this could be labelled differently in different versions
43+
# verify the panel title
44+
tracker_panel_title = tracker_panel.get_element("tracker-title")
4345
assert (
44-
shield_icon.get_attribute("data-l10n-id")
45-
== "tracking-protection-icon-active-container"
46-
), "The label detected did not correspond to the expected one: tracking-protection-icon-no-trackers-detected-container"
46+
tracker_panel_title.get_attribute("innerHTML")
47+
== "Protections for senglehardt.com"
48+
)
49+
50+
# fetch the items in the cross site trackers
51+
cross_site_trackers = tracker_panel.open_and_return_cross_site_trackers()
52+
53+
# ensure that the correct blocked site is listed
54+
found_tracker = False
55+
for item in cross_site_trackers:
56+
if item.get_attribute("value") == BLOCKED_TRACKER_URL:
57+
found_tracker = True
58+
assert found_tracker
59+
60+
61+
def test_third_party_content_blocked_private_browsing_allowed_tracking(driver: Firefox):
62+
"""
63+
C446323.2: Ensure that some third party content is allowed
64+
"""
65+
# instantiate objects
66+
panel_ui = PanelUi(driver).open()
67+
nav = Navigation(driver)
68+
tracker_panel = TrackerPanel(driver)
69+
tracker_website = GenericPage(driver, url=FIRST_TRACKER_WEBSITE)
70+
71+
# open a private window
72+
panel_ui.open_private_window()
73+
nav.switch_to_new_window()
74+
75+
# open the website, ensure the blocking is taking place by continuously refreshing website until indicated
76+
tracker_website.open()
77+
tracker_panel.wait_for_blocked_tracking_icon(nav, tracker_website)
78+
79+
# verify the indicator
80+
driver.set_context(driver.CONTEXT_CHROME)
81+
tracker_panel.verify_tracker_shield_indicator(nav)
82+
83+
# open the panel and verify the title
4784
nav.open_tracker_panel()
85+
tracker_panel_title = tracker_panel.get_element("tracker-title")
86+
assert (
87+
tracker_panel_title.get_attribute("innerHTML")
88+
== "Protections for senglehardt.com"
89+
)
90+
91+
# fetch allowed trackers
92+
allowed_trackers = tracker_panel.open_and_return_allowed_trackers()
93+
94+
# verify the correct ones are allowed
95+
for item in allowed_trackers:
96+
assert item.get_attribute("value") in ALLOWED_TRACKING_URLS
97+
98+
99+
def test_third_party_content_private_browsing_tracking_statuses(driver: Firefox):
100+
"""
101+
C446323.3: Ensure that the statuses of some third party content is loaded properly
102+
"""
103+
# instantiate objects
104+
panel_ui = PanelUi(driver).open()
105+
nav = Navigation(driver)
106+
tracker_panel = TrackerPanel(driver)
107+
tracker_website = GenericPage(driver, url=SECOND_TRACKER_WEBSITE)
108+
109+
# open a private window
110+
panel_ui.open_private_window()
111+
nav.switch_to_new_window()
112+
113+
# open the tracker website
114+
tracker_website.open()
115+
tracker_panel.wait_for_blocked_tracking_icon(nav, tracker_website)
116+
117+
# verify the indicator
118+
tracker_panel.verify_tracker_shield_indicator(nav)
48119

49-
tracker_panel_title = nav.get_element("tracker-title")
50-
logging.info(tracker_panel_title.get_attribute("innerHTML"))
120+
# assert all of the various statuses, ensure that the correct one is displayed
121+
block_status = tracker_website.get_element("simulated-tracker-block-status")
122+
load_status = tracker_website.get_element("simulated-tracker-load-status")
123+
dnt_status = tracker_website.get_element("simulated-tracker-dnt-status")
51124

52-
nav.get_element("tracker-cross-site-tracking").click()
125+
assert "hidden" not in block_status.get_attribute("class")
126+
assert "hidden" not in load_status.get_attribute("class")
127+
assert "hidden" not in dnt_status.get_attribute("class")

tests/tabs/test_pin_tab.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import logging
2-
31
from selenium.webdriver import Firefox
42

53
from modules.browser_object import TabBar, TabContextMenu

0 commit comments

Comments
 (0)