Skip to content

Commit c59ac38

Browse files
Bug 1989325 [wpt PR 54868] - [wdspec] remove unsubscribe by contexts, a=testonly
Automatic update from web-platform-tests [wdspec] remove unsubscribe by contexts (#54868) Co-authored-by: Maksim Sadym <[email protected]> -- wpt-commits: 41b243cce1a6aa2b93571707dc0ebd1e45cc5527 wpt-pr: 54868
1 parent cc0874d commit c59ac38

6 files changed

Lines changed: 11 additions & 317 deletions

File tree

testing/web-platform/tests/tools/webdriver/webdriver/bidi/modules/session.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ def subscribe(self,
4444
@command
4545
def unsubscribe(self,
4646
events: Optional[List[str]] = None,
47-
contexts: Optional[List[str]] = None,
4847
subscriptions: Optional[List[str]] = None) -> Mapping[str, Any]:
4948
params: MutableMapping[str, Any] = {}
50-
if contexts is not None:
51-
params["contexts"] = contexts
5249
if events is not None:
5350
params["events"] = events
5451
if subscriptions is not None:

testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
DisplayFeaturesProtocolPart,
5151
merge_dicts)
5252

53-
from typing import Any, List, Dict, Optional, Tuple
53+
from typing import Any, List, Dict, Optional
5454
from webdriver.client import Session
5555
from webdriver import error as webdriver_error
5656
from webdriver.bidi import error as webdriver_bidi_error
@@ -273,7 +273,7 @@ async def handle_user_prompt(self,
273273

274274

275275
class WebDriverBidiEventsProtocolPart(BidiEventsProtocolPart):
276-
_subscriptions: List[Tuple[List[str], Optional[List[str]]]] = []
276+
_subscriptions: List[str] = []
277277

278278
def __init__(self, parent):
279279
super().__init__(parent)
@@ -312,15 +312,10 @@ async def _get_top_context(self, context: str) -> Optional[str]:
312312

313313
async def subscribe(self, events, contexts):
314314
self.logger.info("Subscribing to events %s in %s" % (events, contexts))
315-
# The BiDi subscriptions are done for top context even if the sub-context is provided. We need to get the
316-
# top-level contexts list to handle the scenario when subscription is done for a sub-context which is closed
317-
# afterwards. However, the subscription itself is done for the provided contexts in order to throw in case of
318-
# the sub-context is removed.
319-
top_contexts = await self._contexts_to_top_contexts(contexts)
320315
result = await self.webdriver.bidi_session.session.subscribe(events=events, contexts=contexts)
321316
# The `subscribe` method either raises an exception or adds subscription. The command is atomic, meaning in case
322317
# of exception no subscription is added.
323-
self._subscriptions.append((events, top_contexts))
318+
self._subscriptions.append(result["subscription"])
324319
return result
325320

326321
async def unsubscribe(self, subscriptions):
@@ -331,10 +326,10 @@ async def unsubscribe(self, subscriptions):
331326
async def unsubscribe_all(self):
332327
self.logger.info("Unsubscribing from all the events")
333328
while self._subscriptions:
334-
events, contexts = self._subscriptions.pop()
335-
self.logger.debug("Unsubscribing from events %s in %s" % (events, contexts))
329+
subscription = self._subscriptions.pop()
330+
self.logger.debug("Unsubscribing from event %s" % subscription)
336331
try:
337-
await self.webdriver.bidi_session.session.unsubscribe(events=events, contexts=contexts)
332+
await self.webdriver.bidi_session.session.unsubscribe(subscriptions=[subscription])
338333
except webdriver_bidi_error.NoSuchFrameException:
339334
# The browsing context is already removed. Nothing to do.
340335
pass
@@ -345,7 +340,7 @@ async def unsubscribe_all(self):
345340
else:
346341
raise e
347342
except Exception as e:
348-
self.logger.error("Failed to unsubscribe from events %s in %s: %s" % (events, contexts, e))
343+
self.logger.error("Failed to unsubscribe from event %s: %s" % (subscription, e))
349344
# Re-raise the exception to identify regressions.
350345
# TODO: consider to continue the loop in case of the exception.
351346
raise e

testing/web-platform/tests/webdriver/tests/bidi/session/unsubscribe/contexts.py

Lines changed: 0 additions & 165 deletions
This file was deleted.

testing/web-platform/tests/webdriver/tests/bidi/session/unsubscribe/invalid.py

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from webdriver.bidi.error import InvalidArgumentException, NoSuchFrameException
2+
3+
from webdriver.bidi.error import InvalidArgumentException
34

45
from ... import create_console_api_message
56

@@ -88,79 +89,6 @@ async def test_unsubscribe_from_one_event_and_then_from_module(
8889
await bidi_session.session.unsubscribe(events=["browsingContext.load"])
8990

9091

91-
@pytest.mark.asyncio
92-
@pytest.mark.parametrize("value", [True, "foo", 42, {}])
93-
async def test_params_contexts_invalid_type(bidi_session, value):
94-
with pytest.raises(InvalidArgumentException):
95-
await bidi_session.session.unsubscribe(events=["browsingContext.load"], contexts=value)
96-
97-
98-
@pytest.mark.asyncio
99-
async def test_params_contexts_empty(bidi_session):
100-
with pytest.raises(InvalidArgumentException):
101-
await bidi_session.session.unsubscribe(events=["browsingContext.load"], contexts=[])
102-
103-
104-
@pytest.mark.asyncio
105-
@pytest.mark.parametrize("value", [None, True, 42, [], {}])
106-
async def test_params_contexts_value_invalid_type(bidi_session, value):
107-
with pytest.raises(InvalidArgumentException):
108-
await bidi_session.session.unsubscribe(events=["browsingContext.load"], contexts=[value])
109-
110-
111-
@pytest.mark.asyncio
112-
async def test_params_contexts_value_invalid_value(bidi_session):
113-
with pytest.raises(NoSuchFrameException):
114-
await bidi_session.session.unsubscribe(events=["browsingContext.load"], contexts=["foo"])
115-
116-
117-
@pytest.mark.asyncio
118-
async def test_params_contexts_value_valid_and_invalid_value(
119-
bidi_session, subscribe_events, wait_for_event, wait_for_future_safe, top_context
120-
):
121-
# Subscribe to a valid context
122-
await subscribe_events(events=["log.entryAdded"], contexts=[top_context["context"]])
123-
124-
# Try to unsubscribe from the valid and an invalid context
125-
with pytest.raises(NoSuchFrameException):
126-
await bidi_session.session.unsubscribe(events=["log.entryAdded"], contexts=[top_context["context"], "foo"])
127-
128-
# Make sure that we didn't unsubscribe from the valid context because of the error
129-
# and events are still coming
130-
131-
# Track all received log.entryAdded events in the events array
132-
events = []
133-
134-
async def on_event(method, data):
135-
events.append(data)
136-
137-
remove_listener = bidi_session.add_event_listener(
138-
"log.entryAdded", on_event)
139-
140-
on_entry_added = wait_for_event("log.entryAdded")
141-
await create_console_api_message(bidi_session, top_context, "text1")
142-
await wait_for_future_safe(on_entry_added)
143-
144-
assert len(events) == 1
145-
146-
remove_listener()
147-
148-
149-
@pytest.mark.asyncio
150-
async def test_unsubscribe_from_closed_tab(
151-
bidi_session, subscribe_events
152-
):
153-
new_tab = await bidi_session.browsing_context.create(type_hint="tab")
154-
# Subscribe to a new context
155-
await subscribe_events(events=["log.entryAdded"], contexts=[new_tab["context"]])
156-
157-
await bidi_session.browsing_context.close(context=new_tab["context"])
158-
159-
# Try to unsubscribe from the closed context
160-
with pytest.raises(NoSuchFrameException):
161-
await bidi_session.session.unsubscribe(events=["log.entryAdded"], contexts=[new_tab["context"]])
162-
163-
16492
@pytest.mark.asyncio
16593
async def test_params_unsubscribe_globally_without_subscription(bidi_session):
16694
with pytest.raises(InvalidArgumentException):
@@ -179,26 +107,6 @@ async def test_params_unsubscribe_globally_with_individual_subscription(
179107
await bidi_session.session.unsubscribe(events=["log.entryAdded"])
180108

181109

182-
@pytest.mark.asyncio
183-
async def test_params_unsubscribe_from_one_context_without_subscription(
184-
bidi_session, top_context
185-
):
186-
with pytest.raises(InvalidArgumentException):
187-
await bidi_session.session.unsubscribe(events=["log.entryAdded"], contexts=[top_context["context"]])
188-
189-
190-
@pytest.mark.asyncio
191-
async def test_params_unsubscribe_from_one_context_with_global_subscription(
192-
subscribe_events, bidi_session, top_context
193-
):
194-
# Subscribe to all contexts
195-
await subscribe_events(events=["log.entryAdded"])
196-
197-
# Try to unsubscribe from one context
198-
with pytest.raises(InvalidArgumentException):
199-
await bidi_session.session.unsubscribe(events=["log.entryAdded"], contexts=[top_context["context"]])
200-
201-
202110
@pytest.mark.asyncio
203111
@pytest.mark.parametrize("subscriptions", [None, True, 42, {}, "foo"])
204112
async def test_params_subscriptions_invalid_type(bidi_session, subscriptions):

testing/web-platform/tests/webdriver/tests/bidi/session/unsubscribe/subscriptions.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -215,47 +215,6 @@ async def on_load_event(method, data):
215215
remove_listener_2()
216216

217217

218-
async def test_unsubscribe_partially_from_one_context(
219-
bidi_session, top_context, new_tab, wait_for_events
220-
):
221-
# Subscribe for log events to multiple contexts at once
222-
result = await bidi_session.session.subscribe(
223-
events=["log.entryAdded"], contexts=[top_context["context"], new_tab["context"]]
224-
)
225-
# Unsubscribe from log events in one of the contexts
226-
await bidi_session.session.unsubscribe(
227-
events=["log.entryAdded"], contexts=[top_context["context"]]
228-
)
229-
230-
with wait_for_events(["log.entryAdded"]) as waiter:
231-
# Trigger console event in the unsubscribed context
232-
await create_console_api_message(bidi_session, top_context, "text1")
233-
events = await waiter.get_events(lambda events: len(events) >= 0)
234-
assert len(events) == 0
235-
236-
# Trigger another console event in the still observed context
237-
expected_text = await create_console_api_message(bidi_session, new_tab, "text2")
238-
events = await waiter.get_events(lambda events: len(events) >= 1)
239-
240-
assert len(events) == 1
241-
recursive_compare(
242-
{
243-
"text": expected_text,
244-
},
245-
events[0][1],
246-
)
247-
248-
# Unsubscribe from subscription.
249-
await bidi_session.session.unsubscribe(subscriptions=[result["subscription"]])
250-
251-
# Trigger another console event
252-
await create_console_api_message(bidi_session, new_tab, "text2")
253-
254-
# Make sure that there're no new events
255-
events = await waiter.get_events(lambda events: len(events) >= 1)
256-
assert len(events) == 1
257-
258-
259218
async def test_unsubscribe_with_event_and_subscriptions(bidi_session, new_tab, inline):
260219
result = await bidi_session.session.subscribe(events=["browsingContext"])
261220

0 commit comments

Comments
 (0)