11import pytest
22
3- from webdriver .bidi .error import InvalidArgumentException , NoSuchFrameException
3+ from webdriver .bidi .error import InvalidArgumentException
44
55from ... import create_console_api_message
66
@@ -89,79 +89,6 @@ async def test_unsubscribe_from_one_event_and_then_from_module(
8989 await bidi_session .session .unsubscribe (events = ["browsingContext.load" ])
9090
9191
92- @pytest .mark .asyncio
93- @pytest .mark .parametrize ("value" , [True , "foo" , 42 , {}])
94- async def test_params_contexts_invalid_type (bidi_session , value ):
95- with pytest .raises (InvalidArgumentException ):
96- await bidi_session .session .unsubscribe (events = ["browsingContext.load" ], contexts = value )
97-
98-
99- @pytest .mark .asyncio
100- async def test_params_contexts_empty (bidi_session ):
101- with pytest .raises (InvalidArgumentException ):
102- await bidi_session .session .unsubscribe (events = ["browsingContext.load" ], contexts = [])
103-
104-
105- @pytest .mark .asyncio
106- @pytest .mark .parametrize ("value" , [None , True , 42 , [], {}])
107- async def test_params_contexts_value_invalid_type (bidi_session , value ):
108- with pytest .raises (InvalidArgumentException ):
109- await bidi_session .session .unsubscribe (events = ["browsingContext.load" ], contexts = [value ])
110-
111-
112- @pytest .mark .asyncio
113- async def test_params_contexts_value_invalid_value (bidi_session ):
114- with pytest .raises (NoSuchFrameException ):
115- await bidi_session .session .unsubscribe (events = ["browsingContext.load" ], contexts = ["foo" ])
116-
117-
118- @pytest .mark .asyncio
119- async def test_params_contexts_value_valid_and_invalid_value (
120- bidi_session , subscribe_events , wait_for_event , wait_for_future_safe , top_context
121- ):
122- # Subscribe to a valid context
123- await subscribe_events (events = ["log.entryAdded" ], contexts = [top_context ["context" ]])
124-
125- # Try to unsubscribe from the valid and an invalid context
126- with pytest .raises (NoSuchFrameException ):
127- await bidi_session .session .unsubscribe (events = ["log.entryAdded" ], contexts = [top_context ["context" ], "foo" ])
128-
129- # Make sure that we didn't unsubscribe from the valid context because of the error
130- # and events are still coming
131-
132- # Track all received log.entryAdded events in the events array
133- events = []
134-
135- async def on_event (method , data ):
136- events .append (data )
137-
138- remove_listener = bidi_session .add_event_listener (
139- "log.entryAdded" , on_event )
140-
141- on_entry_added = wait_for_event ("log.entryAdded" )
142- await create_console_api_message (bidi_session , top_context , "text1" )
143- await wait_for_future_safe (on_entry_added )
144-
145- assert len (events ) == 1
146-
147- remove_listener ()
148-
149-
150- @pytest .mark .asyncio
151- async def test_unsubscribe_from_closed_tab (
152- bidi_session , subscribe_events
153- ):
154- new_tab = await bidi_session .browsing_context .create (type_hint = "tab" )
155- # Subscribe to a new context
156- await subscribe_events (events = ["log.entryAdded" ], contexts = [new_tab ["context" ]])
157-
158- await bidi_session .browsing_context .close (context = new_tab ["context" ])
159-
160- # Try to unsubscribe from the closed context
161- with pytest .raises (NoSuchFrameException ):
162- await bidi_session .session .unsubscribe (events = ["log.entryAdded" ], contexts = [new_tab ["context" ]])
163-
164-
16592@pytest .mark .asyncio
16693async def test_params_unsubscribe_globally_without_subscription (bidi_session ):
16794 with pytest .raises (InvalidArgumentException ):
@@ -180,26 +107,6 @@ async def test_params_unsubscribe_globally_with_individual_subscription(
180107 await bidi_session .session .unsubscribe (events = ["log.entryAdded" ])
181108
182109
183- @pytest .mark .asyncio
184- async def test_params_unsubscribe_from_one_context_without_subscription (
185- bidi_session , top_context
186- ):
187- with pytest .raises (InvalidArgumentException ):
188- await bidi_session .session .unsubscribe (events = ["log.entryAdded" ], contexts = [top_context ["context" ]])
189-
190-
191- @pytest .mark .asyncio
192- async def test_params_unsubscribe_from_one_context_with_global_subscription (
193- subscribe_events , bidi_session , top_context
194- ):
195- # Subscribe to all contexts
196- await subscribe_events (events = ["log.entryAdded" ])
197-
198- # Try to unsubscribe from one context
199- with pytest .raises (InvalidArgumentException ):
200- await bidi_session .session .unsubscribe (events = ["log.entryAdded" ], contexts = [top_context ["context" ]])
201-
202-
203110@pytest .mark .asyncio
204111@pytest .mark .parametrize ("subscriptions" , [None , True , 42 , {}, "foo" ])
205112async def test_params_subscriptions_invalid_type (bidi_session , subscriptions ):
0 commit comments