Skip to content

Commit d5bb618

Browse files
committed
vs/refactor-themes
1 parent 6198202 commit d5bb618

File tree

2 files changed

+59
-46
lines changed

2 files changed

+59
-46
lines changed
Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22
from selenium.webdriver import Firefox
3-
43
from modules.browser_object import Navigation, PanelUi
54
from modules.page_object import AboutAddons
65

@@ -10,32 +9,42 @@ def test_case():
109
return "118173"
1110

1211

13-
themes = {
12+
# Exact values preserved from the original file
13+
THEMES: dict[str, str] = {
1414
"firefox-compact-dark_mozilla_org-heading": "rgb(43, 42, 51)",
1515
"firefox-compact-light_mozilla_org-heading": "rgb(249, 249, 251)",
1616
}
1717

18-
alpenglow_map = {"light": "rgba(255, 255, 255, 0.76)", "dark": "rgba(40, 29, 78, 0.96)"}
18+
ALPENGLOW_MAP: dict[str, str] = {
19+
"light": "rgba(255, 255, 255, 0.76)",
20+
"dark": "rgba(40, 29, 78, 0.96)",
21+
}
1922

2023

21-
def colors_match(a, b):
22-
"""Determine if two colors are close enough to be considered matches"""
23-
tolerance = 0.14
24-
a_colorstring = a.split("(")[1][:-1]
25-
b_colorstring = b.split("(")[1][:-1]
26-
a_colors = [float(n) for n in a_colorstring.split(",")]
27-
b_colors = [float(n) for n in b_colorstring.split(",")]
28-
for i in range(len(a_colors)):
29-
diff = abs((a_colors[i] / b_colors[i]) - 1.0)
30-
if diff > tolerance:
31-
return False
32-
return True
24+
def colors_match(a: str, b: str, tolerance: float = 0.14) -> bool:
25+
"""
26+
Determine if two CSS colors are close enough to be considered matches.
27+
Preserves the original multiplicative tolerance logic and supports rgb/rgba.
28+
"""
29+
try:
30+
a_vals = a.split("(")[1][:-1]
31+
b_vals = b.split("(")[1][:-1]
32+
a_nums = [float(n.strip()) for n in a_vals.split(",")]
33+
b_nums = [float(n.strip()) for n in b_vals.split(",")]
34+
for i in range(min(len(a_nums), len(b_nums))):
35+
base = b_nums[i] if b_nums[i] != 0 else 1.0 # avoid div by zero
36+
diff = abs((a_nums[i] / base) - 1.0)
37+
if diff > tolerance:
38+
return False
39+
return True
40+
except Exception:
41+
return False
3342

3443

3544
@pytest.mark.ci
36-
def test_redirect_to_addons(driver: Firefox):
45+
def test_redirect_to_addons(driver: Firefox) -> None:
3746
"""
38-
C118173, ensures that the user is redirected to about:addons through the ui panel
47+
C118173: ensure the user is redirected to about:addons through the UI panel.
3948
"""
4049
panel_ui = PanelUi(driver)
4150
panel_ui.open()
@@ -46,46 +55,43 @@ def test_redirect_to_addons(driver: Firefox):
4655
assert driver.current_url == "about:addons"
4756

4857

49-
@pytest.mark.parametrize("theme_name", list(themes.keys()))
50-
def test_open_addons(driver: Firefox, theme_name: str):
58+
@pytest.mark.parametrize("theme_name", list(THEMES.keys()))
59+
def test_open_addons(driver: Firefox, theme_name: str) -> None:
5160
"""
52-
C118173, continuation ensures that all the themes are set correctly
61+
C118173: continuation ensures that all the themes are set correctly.
62+
Handles Developer Edition vs standard Firefox defaults as in the original.
5363
"""
5464
nav = Navigation(driver)
5565
abt_addons = AboutAddons(driver).open()
5666
abt_addons.choose_sidebar_option("theme")
5767

5868
# Dynamically detect if running Developer Edition
5969
if abt_addons.is_devedition():
60-
# Adjust expectations for Developer Edition
6170
if theme_name == "firefox-compact-dark_mozilla_org-heading":
62-
# Already default on Developer Edition; skip activation/assertion
6371
pytest.skip("Compact Dark is default on DevEdition, skipping.")
6472
else:
65-
# Adjust expectations for standard Firefox
6673
if theme_name == "firefox-compact-light_mozilla_org-heading":
67-
# Already default on Firefox standard; skip activation/assertion
6874
pytest.skip("Compact Light is default on Firefox, skipping.")
6975

7076
current_bg = abt_addons.activate_theme(
71-
nav, theme_name, themes[theme_name], perform_assert=False
77+
nav, theme_name, THEMES[theme_name], perform_assert=False
7278
)
73-
assert colors_match(current_bg, themes[theme_name])
79+
assert colors_match(current_bg, THEMES[theme_name])
7480

7581

76-
def test_alpenglow_theme(driver: Firefox):
82+
def test_alpenglow_theme(driver: Firefox) -> None:
7783
"""
78-
C118173, specifically for alpenglow theme because color can be two values for dark or light mode
84+
C118173: Alpenglow theme can render two values depending on light/dark mode.
85+
Accept either using the tolerance-based comparison.
7986
"""
80-
8187
nav = Navigation(driver)
8288
abt_addons = AboutAddons(driver).open()
8389
abt_addons.choose_sidebar_option("theme")
90+
8491
current_bg = abt_addons.activate_theme(
8592
nav, "firefox-alpenglow_mozilla_org-heading", "", perform_assert=False
8693
)
8794

88-
# assert current_bg == alpenglow_map["light"] or current_bg == alpenglow_map["dark"]
89-
assert colors_match(current_bg, alpenglow_map["light"]) or colors_match(
90-
current_bg, alpenglow_map["dark"]
95+
assert colors_match(current_bg, ALPENGLOW_MAP["light"]) or colors_match(
96+
current_bg, ALPENGLOW_MAP["dark"]
9197
)

tests/theme_and_toolbar/test_installed_theme_enabled.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,46 @@ def test_case():
1212
return "118174"
1313

1414

15-
MAC_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("darwin")
15+
MAC_GHA: bool = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("darwin")
16+
17+
AMO_HOST: str = "addons.mozilla.org"
18+
AMO_THEMES_PATH: str = "firefox/themes"
1619

1720

1821
@pytest.mark.skipif(MAC_GHA, reason="Test unstable in MacOS Github Actions")
19-
def test_find_more_themes(driver: Firefox):
22+
def test_find_more_themes(driver: Firefox) -> None:
2023
"""
21-
C118174, first part
24+
C118174 (part 1): From about:addons > Themes, 'Find more themes' opens AMO in a new tab.
25+
Verify AMO host and themes path are present in the URL.
2226
"""
2327
about_addons = AboutAddons(driver).open()
2428
about_addons.choose_sidebar_option("theme")
2529
about_addons.get_element("find-more-themes-button").click()
30+
2631
driver.switch_to.window(driver.window_handles[-1])
2732

28-
# Continuing to call the object "about_addons" is confusing
2933
base = about_addons
30-
base.url_contains("addons.mozilla.org")
31-
base.url_contains("firefox/themes")
34+
base.url_contains(AMO_HOST)
35+
base.url_contains(AMO_THEMES_PATH)
3236

3337

3438
@pytest.mark.skipif(MAC_GHA, reason="Test unstable in MacOS Github Actions")
35-
def test_installed_theme_enabled(driver: Firefox):
39+
def test_installed_theme_enabled(driver: Firefox) -> None:
3640
"""
37-
C118174: install a theme and make sure it is set to enabled immediately
41+
C118174 (part 2): Install a recommended theme from AMO and ensure it becomes enabled immediately.
3842
"""
3943
about_addons = AboutAddons(driver).open()
4044
about_addons.choose_sidebar_option("theme")
41-
starting_theme = about_addons.get_element("enabled-theme-title").get_attribute(
42-
"innerText"
43-
)
44-
amo = AmoThemes(driver).open()
45-
amo.install_recommended_theme()
45+
46+
# Capture currently enabled theme title
47+
starting_theme = about_addons.get_element("enabled-theme-title").get_attribute("innerText")
48+
49+
# Go to AMO and install a recommended theme (POM encapsulates waits and flows)
50+
AmoThemes(driver).open().install_recommended_theme()
51+
52+
# Return to about:addons > Themes and verify the enabled theme changed
4653
about_addons = AboutAddons(driver).open()
4754
about_addons.choose_sidebar_option("theme")
4855

49-
# NOTE: AMO does not enforce that the listed theme name remains the same after installation
56+
# AMO may change display names; we only assert that the enabled theme is different
5057
about_addons.check_theme_has_changed(starting_theme)

0 commit comments

Comments
 (0)