@@ -22,43 +22,65 @@ def test_case():
2222
2323def colors_match (a : str , b : str , tolerance : float = 0.14 ) -> bool :
2424 """
25- Determine if two CSS colors are close enough to be considered matches.
25+ Compare two CSS color strings and determine if they are close enough to be considered equal.
26+
27+ Args:
28+ a (str): First CSS color string in 'rgb(r,g,b)' or 'rgba(r,g,b,a)' format.
29+ b (str): Second CSS color string in 'rgb(r,g,b)' or 'rgba(r,g,b,a)' format.
30+ tolerance (float, optional): Allowed relative difference between each color channel.
31+ Defaults to 0.14. A higher value means colors can differ more and still match.
32+
33+ Returns:
34+ bool: True if the two colors are considered a match within the given tolerance.
35+ False if the color strings are invalid.
2636 """
2737 try :
2838 a_vals = a .split ("(" )[1 ][:- 1 ]
2939 b_vals = b .split ("(" )[1 ][:- 1 ]
3040 a_nums = [float (n .strip ()) for n in a_vals .split ("," )]
3141 b_nums = [float (n .strip ()) for n in b_vals .split ("," )]
32- for i in range (min (len (a_nums ), len (b_nums ))):
33- base = b_nums [i ] if b_nums [i ] != 0 else 1.0 # avoid div by zero
34- diff = abs ((a_nums [i ] / base ) - 1.0 )
35- if diff > tolerance :
36- return False
37- return True
38- except Exception :
42+ except (IndexError , ValueError ) as e :
43+ # Raised if string doesn't contain expected format or non-numeric parts
3944 return False
4045
46+ # Compare up to the shortest length (rgb vs rgba)
47+ for i in range (min (len (a_nums ), len (b_nums ))):
48+ base = b_nums [i ] if b_nums [i ] != 0 else 1.0
49+ diff = abs ((a_nums [i ] / base ) - 1.0 )
50+ if diff > tolerance :
51+ return False
52+
53+ return True
54+
4155
4256@pytest .mark .ci
4357def test_redirect_to_addons (driver : Firefox ) -> None :
4458 """
45- C118173: ensure the user is redirected to about:addons through the UI panel.
59+ C118173: Ensure the user is redirected to about:addons via the UI panel.
4660 """
4761 panel_ui = PanelUi (driver )
4862 panel_ui .open ()
4963 panel_ui .open_panel_menu ()
5064 panel_ui .navigate_to_about_addons ()
51- windows = driver .window_handles
52- driver .switch_to .window (windows [2 ])
65+
66+ # remember original window, then switch to newly opened one
67+ orig = driver .window_handles [0 ]
68+ new = driver .window_handles [- 1 ]
69+ driver .switch_to .window (new )
5370 assert driver .current_url == "about:addons"
5471
72+ # cleanup: close the tab we opened and restore focus
73+ driver .close ()
74+ driver .switch_to .window (orig )
75+
5576
5677@pytest .mark .parametrize ("theme_name" , list (THEMES .keys ()))
57- def test_open_addons (driver : Firefox , theme_name : str ) -> None :
78+ def test_activate_theme_background_matches_expected (driver : Firefox , theme_name : str ) -> None :
5879 """
59- C118173: continuation ensures that all the themes are set correctly .
60- Handles Developer Edition vs standard Firefox defaults as in the original .
80+ C118173: Ensure that activating each theme in about:addons applies the expected background color .
81+ Handles Developer Edition vs standard Firefox defaults.
6182 """
83+
6284 nav = Navigation (driver )
6385 abt_addons = AboutAddons (driver ).open ()
6486 abt_addons .choose_sidebar_option ("theme" )
@@ -79,9 +101,10 @@ def test_open_addons(driver: Firefox, theme_name: str) -> None:
79101
80102def test_alpenglow_theme (driver : Firefox ) -> None :
81103 """
82- C118173: Alpenglow theme can render two values depending on light/ dark mode.
83- Accept either using the tolerance- based comparison.
104+ C118173: Alpenglow theme can render two values depending on light / dark mode.
105+ Accept either using the tolerance - based comparison.
84106 """
107+
85108 nav = Navigation (driver )
86109 abt_addons = AboutAddons (driver ).open ()
87110 abt_addons .choose_sidebar_option ("theme" )
0 commit comments