Allow forcing tab-mute to a specific value
Based on the David Leavenworth's <dleavenworth3@gmail.com> work. Tests were written with the help of Claude Sonnet 4.5. Fix tests: use fake_web_tab fixture and parametrization
This commit is contained in:
parent
f2547f8a09
commit
8412e1c79e
|
|
@ -322,16 +322,23 @@ def debug_webaction(tab: apitypes.Tab, action: str, count: int = 1) -> None:
|
||||||
|
|
||||||
@cmdutils.register()
|
@cmdutils.register()
|
||||||
@cmdutils.argument('tab', value=cmdutils.Value.count_tab)
|
@cmdutils.argument('tab', value=cmdutils.Value.count_tab)
|
||||||
def tab_mute(tab: Optional[apitypes.Tab]) -> None:
|
@cmdutils.argument('mute', choices=['true', 'false'])
|
||||||
|
def tab_mute(tab: Optional[apitypes.Tab], mute: str = None) -> None:
|
||||||
"""Mute/Unmute the current/[count]th tab.
|
"""Mute/Unmute the current/[count]th tab.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
count: The tab index to mute or unmute, or None
|
count: The tab index to mute or unmute, or None
|
||||||
|
mute: The mute setting to force : 'true' to mute, 'false' to unmute, omit to toggle.
|
||||||
"""
|
"""
|
||||||
if tab is None:
|
if tab is None:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
tab.audio.set_muted(not tab.audio.is_muted(), override=True)
|
if mute == 'true':
|
||||||
|
tab.audio.set_muted(True, override=True)
|
||||||
|
elif mute == 'false':
|
||||||
|
tab.audio.set_muted(False, override=True)
|
||||||
|
else:
|
||||||
|
tab.audio.set_muted(not tab.audio.is_muted(), override=True)
|
||||||
except apitypes.WebTabError as e:
|
except apitypes.WebTabError as e:
|
||||||
raise cmdutils.CommandError(e)
|
raise cmdutils.CommandError(e)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -225,8 +225,16 @@ class FakeWebTabHistory(browsertab.AbstractHistory):
|
||||||
|
|
||||||
class FakeWebTabAudio(browsertab.AbstractAudio):
|
class FakeWebTabAudio(browsertab.AbstractAudio):
|
||||||
|
|
||||||
|
def __init__(self, tab):
|
||||||
|
super().__init__(tab)
|
||||||
|
self._is_muted = False
|
||||||
|
|
||||||
def is_muted(self):
|
def is_muted(self):
|
||||||
return False
|
return self._is_muted
|
||||||
|
|
||||||
|
def set_muted(self, muted: bool, override: bool = False) -> None:
|
||||||
|
"""Set muted state."""
|
||||||
|
self._is_muted = muted
|
||||||
|
|
||||||
def is_recently_audible(self):
|
def is_recently_audible(self):
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -77,3 +77,19 @@ def test_debug_trace_no_hunter(monkeypatch):
|
||||||
with pytest.raises(cmdutils.CommandError, match="You need to install "
|
with pytest.raises(cmdutils.CommandError, match="You need to install "
|
||||||
"'hunter' to use this command!"):
|
"'hunter' to use this command!"):
|
||||||
misccommands.debug_trace()
|
misccommands.debug_trace()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("initial_muted,mute_arg,expected_muted", [
|
||||||
|
(False, None, True), # Toggle: Unmuted → muted
|
||||||
|
(True, None, False), # Toggle: Muted → unmuted
|
||||||
|
(False, 'true', True), # Force mute
|
||||||
|
(True, 'true', True), # Force mute (idempotent)
|
||||||
|
(False, 'false', False), # Force unmute (idempotent)
|
||||||
|
(True, 'false', False), # Force unmute
|
||||||
|
])
|
||||||
|
def test_tab_mute(fake_web_tab, initial_muted, mute_arg, expected_muted):
|
||||||
|
"""Test tab_mute with different states and parameters."""
|
||||||
|
tab = fake_web_tab()
|
||||||
|
tab.audio.set_muted(initial_muted)
|
||||||
|
misccommands.tab_mute(tab, mute=mute_arg)
|
||||||
|
assert tab.audio.is_muted() == expected_muted
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue