From fdaa6328193d20fb3ec873ed63ee999bea0927e1 Mon Sep 17 00:00:00 2001 From: Ben Chatterton Date: Wed, 17 Sep 2025 15:50:29 -0700 Subject: [PATCH 1/3] get color values for all bgs --- .../test_customize_themes_and_redirect.py | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/theme_and_toolbar/test_customize_themes_and_redirect.py b/tests/theme_and_toolbar/test_customize_themes_and_redirect.py index 0b4e38c16..7fef13b3b 100644 --- a/tests/theme_and_toolbar/test_customize_themes_and_redirect.py +++ b/tests/theme_and_toolbar/test_customize_themes_and_redirect.py @@ -1,4 +1,4 @@ -from platform import system +import logging import pytest from selenium.webdriver import Firefox @@ -20,6 +20,21 @@ def test_case(): alpenglow_map = {"light": "rgba(255, 255, 255, 0.76)", "dark": "rgba(40, 29, 78, 0.96)"} +def colors_match(a, b): + """Determine if two colors are close enough to be considered matches""" + tolerance = 0.14 + a_colorstring = a.split("(")[1][:-1] + b_colorstring = b.split("(")[1][:-1] + a_colors = [float(n) for n in a_colorstring.split(",")] + b_colors = [float(n) for n in b_colorstring.split(",")] + for i in range(len(a_colors)): + diff = abs((a_colors[i] / b_colors[i]) - 1.0) + logging.warning(f"a: {a_colors[i]}, b: {b_colors[i]}, diff: {diff}") + if diff > tolerance: + return False + return True + + @pytest.mark.ci def test_redirect_to_addons(driver: Firefox): """ @@ -34,7 +49,6 @@ def test_redirect_to_addons(driver: Firefox): assert driver.current_url == "about:addons" -@pytest.mark.skipif(system().lower().startswith("win"), reason="Bug 1974109") @pytest.mark.parametrize("theme_name", list(themes.keys())) def test_open_addons(driver: Firefox, theme_name: str): """ @@ -56,10 +70,12 @@ def test_open_addons(driver: Firefox, theme_name: str): # Already default on Firefox standard; skip activation/assertion pytest.skip("Compact Light is default on Firefox, skipping.") - abt_addons.activate_theme(nav, theme_name, themes[theme_name]) + current_bg = abt_addons.activate_theme( + nav, theme_name, themes[theme_name], perform_assert=False + ) + assert current_bg == themes[theme_name] -@pytest.mark.skipif(system().lower().startswith("win"), reason="Bug 1974109") def test_alpenglow_theme(driver: Firefox): """ C118173, specifically for alpenglow theme because color can be two values for dark or light mode @@ -72,4 +88,8 @@ def test_alpenglow_theme(driver: Firefox): nav, "firefox-alpenglow_mozilla_org-heading", "", perform_assert=False ) - assert current_bg == alpenglow_map["light"] or current_bg == alpenglow_map["dark"] + logging.warning(f"alpenglow: {current_bg}") + # assert current_bg == alpenglow_map["light"] or current_bg == alpenglow_map["dark"] + assert colors_match(current_bg, alpenglow_map["light"]) or colors_match( + current_bg, alpenglow_map["dark"] + ) From 34312bb5d255023763cbe6161fb886f116e7e3ad Mon Sep 17 00:00:00 2001 From: Ben Chatterton Date: Wed, 17 Sep 2025 16:39:28 -0700 Subject: [PATCH 2/3] get color values for all bgs --- tests/theme_and_toolbar/test_customize_themes_and_redirect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/theme_and_toolbar/test_customize_themes_and_redirect.py b/tests/theme_and_toolbar/test_customize_themes_and_redirect.py index 7fef13b3b..2f636436a 100644 --- a/tests/theme_and_toolbar/test_customize_themes_and_redirect.py +++ b/tests/theme_and_toolbar/test_customize_themes_and_redirect.py @@ -73,7 +73,7 @@ def test_open_addons(driver: Firefox, theme_name: str): current_bg = abt_addons.activate_theme( nav, theme_name, themes[theme_name], perform_assert=False ) - assert current_bg == themes[theme_name] + assert colors_match(current_bg, themes[theme_name]) def test_alpenglow_theme(driver: Firefox): From 2d39c8d7d8caf7311d2f7155fc4df365d9e9e3a1 Mon Sep 17 00:00:00 2001 From: Ben Chatterton Date: Thu, 18 Sep 2025 11:45:30 -0700 Subject: [PATCH 3/3] remove unnecessary logging --- tests/theme_and_toolbar/test_customize_themes_and_redirect.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/theme_and_toolbar/test_customize_themes_and_redirect.py b/tests/theme_and_toolbar/test_customize_themes_and_redirect.py index 2f636436a..67786a325 100644 --- a/tests/theme_and_toolbar/test_customize_themes_and_redirect.py +++ b/tests/theme_and_toolbar/test_customize_themes_and_redirect.py @@ -1,5 +1,3 @@ -import logging - import pytest from selenium.webdriver import Firefox @@ -29,7 +27,6 @@ def colors_match(a, b): b_colors = [float(n) for n in b_colorstring.split(",")] for i in range(len(a_colors)): diff = abs((a_colors[i] / b_colors[i]) - 1.0) - logging.warning(f"a: {a_colors[i]}, b: {b_colors[i]}, diff: {diff}") if diff > tolerance: return False return True @@ -88,7 +85,6 @@ def test_alpenglow_theme(driver: Firefox): nav, "firefox-alpenglow_mozilla_org-heading", "", perform_assert=False ) - logging.warning(f"alpenglow: {current_bg}") # assert current_bg == alpenglow_map["light"] or current_bg == alpenglow_map["dark"] assert colors_match(current_bg, alpenglow_map["light"]) or colors_match( current_bg, alpenglow_map["dark"]