Skip to content

feat: add support for userContext in WebDriver BiDi events#56744

Open
jimevans wants to merge 17 commits into
web-platform-tests:masterfrom
jimevans:webdriver-bidi-user-context-in-events
Open

feat: add support for userContext in WebDriver BiDi events#56744
jimevans wants to merge 17 commits into
web-platform-tests:masterfrom
jimevans:webdriver-bidi-user-context-in-events

Conversation

@jimevans

Copy link
Copy Markdown
Contributor

Adds tests for WebDriver BiDi spec PR 1046.

@whimboo whimboo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimevans I'm sorry that I completely missed your PR. I just stumbled over it. Maybe next time please send a ping if you don't get a review within a week?

Due to the changes to make the userContext optional for some time first, this PR needs some updates. Would you still be happy to get it updated?

Comment thread webdriver/tests/bidi/browsing_context/create/reference_context.py Outdated
Comment thread webdriver/tests/bidi/browsing_context/__init__.py Outdated
Comment thread webdriver/tests/bidi/input/file_dialog_opened/__init__.py Outdated
@wpt-pr-bot wpt-pr-bot requested a review from lutien April 1, 2026 16:08
@jimevans

jimevans commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

@whimboo Please feel free to take another look now.

@whimboo

whimboo commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Thank you @jimevans. I'll take a look next week. It would be good for verification when I could quickly check with an implementation for it on our side.

@jimevans

Copy link
Copy Markdown
Contributor Author

@whimboo From a test authoring perspective, what's left for getting these merged?

@whimboo whimboo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply but I actually missed to submit my review comments :(

@juliandescottes might be able to help with these updates.

It would be good to see the failures fixed before we merge this PR.

Comment thread webdriver/tests/bidi/input/file_dialog_opened/file_dialog_opened.py Outdated
Comment thread webdriver/tests/bidi/log/entry_added/__init__.py Outdated
Comment thread webdriver/tests/bidi/log/entry_added/console.py Outdated
Comment thread webdriver/tests/bidi/browsing_context/load/load.py
@juliandescottes

juliandescottes commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

+1 to what was mentioned by @whimboo, let's at least fix the errors here.

I tried to validate this against my implementation for https://bugzilla.mozilla.org/show_bug.cgi?id=2018611, but since the new fields are all considered as optional, it's hard to know whether I'm really passing the userContext tests or simply falling back to the "optional" branch. This is unfortunate because that will expose us to regressions until we make the fields mandatory.

So I would suggest adding at least one smoke test per event / return value where we expect unconditionally the userContext field. Browsers which don't implement it yet will fail the additional test for now, but at least it would give us some indication that the feature is working.

Edit: in the interest of keeping things moving forward, I can add such tests in https://bugzilla.mozilla.org/show_bug.cgi?id=2018611. I need this PR to land and be synced before landing my changes.

@whimboo

whimboo commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

So I would suggest adding at least one smoke test per event / return value where we expect unconditionally the userContext field. Browsers which don't implement it yet will fail the additional test for now, but at least it would give us some indication that the feature is working.

Edit: in the interest of keeping things moving forward, I can add such tests in https://bugzilla.mozilla.org/show_bug.cgi?id=2018611. I need this PR to land and be synced before landing my changes.

That's a good idea. Lets only make sure that the changes on this PR actually allow both Firefox and Chrome to pass the tests, and add additional tests like a user_context.py file for each of the affected commands / events.

@jimevans

Copy link
Copy Markdown
Contributor Author

@whimboo, @juliandescottes, I think I've fixed the extant issues in the PR. Let me know what other issues there may be.

@juliandescottes

Copy link
Copy Markdown
Contributor

@whimboo, @juliandescottes, I think I've fixed the extant issues in the PR. Let me know what other issues there may be.

I'll pull and test again, thanks for the update!

@juliandescottes juliandescottes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one issue spotted, other than this the tests seem to run fine.

Comment thread webdriver/tests/bidi/log/entry_added/console.py Outdated
@juliandescottes

Copy link
Copy Markdown
Contributor

The other thing which might be worth adding in this changeset is a small validation on the browsingContext.create result:

https://github.com/web-platform-tests/wpt/blob/master/tools/webdriver/webdriver/bidi/modules/browsing_context.py#L101-L105

Ideally we would validate that if present, it's a string.

Co-authored-by: Julian Descottes <jdescottes@mozilla.com>
@jimevans

Copy link
Copy Markdown
Contributor Author

@juliandescottes I've added the conditional assertion of userContext as a string. I'm not quite sure if there's not another, more pythonic syntax for that (e.g., assert isinstance(...) if "userContext" in result else ...), but this will get the job done.

Comment thread tools/webdriver/webdriver/bidi/modules/browsing_context.py Outdated

@juliandescottes juliandescottes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last version looks good to me, thanks @jimevans !
I'm not sure what is happening with the CI failures though, might need to restart the jobs.

@whimboo do you want to re-review ?

assert_console_entry(event_data, method="log")


async def test_new_context_with_new_window(bidi_session, subscribe_events, top_context, wait_for_event, wait_for_future_safe):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this test still fails in both Firefox and Chrome and it looks like to be permanent. The failure message is message: KeyError: 'userContext'. The changes look valid to me so not sure which of the two assert_console_entry calls fails.

@juliandescottes can you reproduce it locally? If not we could ignore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whimboo I've pushed a change to attempt to resolve this issue. Let's see how we do.

Comment thread webdriver/tests/bidi/input/file_dialog_opened/file_dialog_opened.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants