Skip to content

Commit 783e207

Browse files
committed
Merge main
2 parents ecd51cd + 3aad3bf commit 783e207

File tree

2 files changed

+95
-44
lines changed

2 files changed

+95
-44
lines changed

tests/theme_and_toolbar/test_customize_themes_and_redirect.py

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,82 +10,122 @@ def test_case():
1010
return "118173"
1111

1212

13-
themes = {
14-
"firefox-compact-dark_mozilla_org-heading": "rgb(43, 42, 51)",
15-
"firefox-compact-light_mozilla_org-heading": "rgb(249, 249, 251)",
13+
THEMES: dict[str, list[str]] = {
14+
"firefox-compact-dark_mozilla_org-heading": [
15+
"rgb(43, 42, 51)", # classic darker tone
16+
"rgb(143, 143, 148)", # focused dark
17+
"rgb(120, 119, 126)", # dark without focus
18+
],
19+
# Compact Light
20+
"firefox-compact-light_mozilla_org-heading": [
21+
"rgb(249, 249, 251)",
22+
],
1623
}
1724

18-
alpenglow_map = {"light": "rgba(255, 255, 255, 0.76)", "dark": "rgba(40, 29, 78, 0.96)"}
25+
ALPENGLOW_MAP: dict[str, str] = {
26+
"light": "rgba(255, 255, 255, 0.76)",
27+
"dark": "rgba(40, 29, 78, 0.96)",
28+
}
29+
30+
31+
def colors_match(a: str, b: str, tolerance: float = 0.14) -> bool:
32+
"""
33+
Compare two CSS color strings and determine if they are close enough to be considered equal.
1934
35+
Args:
36+
a (str): First CSS color string in 'rgb(r,g,b)' or 'rgba(r,g,b,a)' format.
37+
b (str): Second CSS color string in 'rgb(r,g,b)' or 'rgba(r,g,b,a)' format.
38+
tolerance (float, optional): Allowed relative difference between each color channel.
39+
Defaults to 0.14. A higher value means colors can differ more and still match.
2040
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)
41+
Returns:
42+
bool: True if the two colors are considered a match within the given tolerance.
43+
False if the color strings are invalid.
44+
"""
45+
try:
46+
a_vals = a.split("(")[1][:-1]
47+
b_vals = b.split("(")[1][:-1]
48+
a_nums = [float(n.strip()) for n in a_vals.split(",")]
49+
b_nums = [float(n.strip()) for n in b_vals.split(",")]
50+
except (IndexError, ValueError):
51+
# Raised if string doesn't contain expected format or non-numeric parts
52+
return False
53+
54+
# Compare up to the shortest length (rgb vs rgba)
55+
for i in range(min(len(a_nums), len(b_nums))):
56+
base = b_nums[i] if b_nums[i] != 0 else 1.0
57+
diff = abs((a_nums[i] / base) - 1.0)
3058
if diff > tolerance:
3159
return False
60+
3261
return True
3362

3463

3564
@pytest.mark.ci
36-
def test_redirect_to_addons(driver: Firefox):
65+
def test_redirect_to_addons(driver: Firefox) -> None:
3766
"""
38-
C118173, ensures that the user is redirected to about:addons through the ui panel
67+
C118173: Ensure the user is redirected to about:addons via the UI panel.
3968
"""
4069
panel_ui = PanelUi(driver)
4170
panel_ui.open()
4271
panel_ui.open_panel_menu()
4372
panel_ui.navigate_to_about_addons()
44-
windows = driver.window_handles
45-
driver.switch_to.window(windows[2])
73+
74+
# remember original window, then switch to newly opened one
75+
orig = driver.window_handles[0]
76+
new = driver.window_handles[-1]
77+
driver.switch_to.window(new)
4678
assert driver.current_url == "about:addons"
4779

80+
# cleanup: close the tab we opened and restore focus
81+
driver.close()
82+
driver.switch_to.window(orig)
4883

49-
@pytest.mark.parametrize("theme_name", list(themes.keys()))
50-
def test_open_addons(driver: Firefox, theme_name: str):
84+
85+
@pytest.mark.parametrize("theme_name", list(THEMES.keys()))
86+
def test_activate_theme_background_matches_expected(
87+
driver: Firefox, theme_name: str
88+
) -> None:
5189
"""
52-
C118173, continuation ensures that all the themes are set correctly
90+
C118173: Ensure that activating each theme in about:addons applies the expected background color.
91+
Handles Developer Edition vs standard Firefox defaults.
5392
"""
93+
5494
nav = Navigation(driver)
5595
abt_addons = AboutAddons(driver).open()
5696
abt_addons.choose_sidebar_option("theme")
5797

5898
# Dynamically detect if running Developer Edition
5999
if abt_addons.is_devedition():
60-
# Adjust expectations for Developer Edition
61100
if theme_name == "firefox-compact-dark_mozilla_org-heading":
62-
# Already default on Developer Edition; skip activation/assertion
63101
pytest.skip("Compact Dark is default on DevEdition, skipping.")
64102
else:
65-
# Adjust expectations for standard Firefox
66103
if theme_name == "firefox-compact-light_mozilla_org-heading":
67-
# Already default on Firefox standard; skip activation/assertion
68104
pytest.skip("Compact Light is default on Firefox, skipping.")
69105

70-
current_bg = abt_addons.activate_theme(
71-
nav, theme_name, themes[theme_name], perform_assert=False
106+
current_bg = abt_addons.activate_theme(nav, theme_name, "", perform_assert=False)
107+
108+
expected_list = THEMES[theme_name]
109+
assert any(colors_match(current_bg, exp) for exp in expected_list), (
110+
f"Got {current_bg} for {theme_name}; expected one of {expected_list}"
72111
)
73-
assert colors_match(current_bg, themes[theme_name])
74112

75113

76-
def test_alpenglow_theme(driver: Firefox):
114+
def test_alpenglow_theme(driver: Firefox) -> None:
77115
"""
78-
C118173, specifically for alpenglow theme because color can be two values for dark or light mode
116+
C118173: Alpenglow theme can render two values depending on light / dark mode.
117+
Accept either using the tolerance-based comparison.
79118
"""
80119

81120
nav = Navigation(driver)
82-
abt_addons = AboutAddons(driver).open()
121+
abt_addons = AboutAddons(driver)
122+
abt_addons.open()
83123
abt_addons.choose_sidebar_option("theme")
124+
84125
current_bg = abt_addons.activate_theme(
85126
nav, "firefox-alpenglow_mozilla_org-heading", "", perform_assert=False
86127
)
87128

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"]
129+
assert colors_match(current_bg, ALPENGLOW_MAP["light"]) or colors_match(
130+
current_bg, ALPENGLOW_MAP["dark"]
91131
)

tests/theme_and_toolbar/test_installed_theme_enabled.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,50 @@ 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(
16+
"darwin"
17+
)
18+
19+
AMO_HOST: str = "addons.mozilla.org"
20+
AMO_THEMES_PATH: str = "firefox/themes"
1621

1722

1823
@pytest.mark.skipif(MAC_GHA, reason="Test unstable in MacOS Github Actions")
19-
def test_find_more_themes(driver: Firefox):
24+
def test_find_more_themes(driver: Firefox) -> None:
2025
"""
21-
C118174, first part
26+
C118174 (part 1): From about:addons > Themes, 'Find more themes' opens AMO in a new tab.
27+
Verify AMO host and themes path are present in the URL.
2228
"""
2329
about_addons = AboutAddons(driver).open()
2430
about_addons.choose_sidebar_option("theme")
2531
about_addons.get_element("find-more-themes-button").click()
32+
2633
driver.switch_to.window(driver.window_handles[-1])
2734

28-
# Continuing to call the object "about_addons" is confusing
2935
base = about_addons
30-
base.url_contains("addons.mozilla.org")
31-
base.url_contains("firefox/themes")
36+
base.url_contains(AMO_HOST)
37+
base.url_contains(AMO_THEMES_PATH)
3238

3339

3440
@pytest.mark.skipif(MAC_GHA, reason="Test unstable in MacOS Github Actions")
35-
def test_installed_theme_enabled(driver: Firefox):
41+
def test_installed_theme_enabled(driver: Firefox) -> None:
3642
"""
37-
C118174: install a theme and make sure it is set to enabled immediately
43+
C118174 (part 2): Install a recommended theme from AMO and ensure it becomes enabled immediately.
3844
"""
3945
about_addons = AboutAddons(driver).open()
4046
about_addons.choose_sidebar_option("theme")
47+
48+
# Capture currently enabled theme title
4149
starting_theme = about_addons.get_element("enabled-theme-title").get_attribute(
4250
"innerText"
4351
)
44-
amo = AmoThemes(driver).open()
45-
amo.install_recommended_theme()
52+
53+
# Go to AMO and install a recommended theme (POM encapsulates waits and flows)
54+
AmoThemes(driver).open().install_recommended_theme()
55+
56+
# Return to about:addons > Themes and verify the enabled theme changed
4657
about_addons = AboutAddons(driver).open()
4758
about_addons.choose_sidebar_option("theme")
4859

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

0 commit comments

Comments
 (0)