Closed Bug 2035439 Opened 4 months ago Closed 1 month ago

The current browsing context's document loses focus when a download is triggered because the DownloadsPanel takes focus

Categories

(Remote Protocol :: Agent, defect, P2)

defect
Points:
3

Tracking

(firefox155 fixed)

RESOLVED FIXED
155 Branch
Tracking Status
firefox155 --- fixed

People

(Reporter: julienw, Assigned: Sasha)

References

Details

(Whiteboard: [webdriver:m21][wptsync upstream][webdriver:relnote])

Attachments

(3 files, 1 obsolete file)

STR:

  1. Clone https://github.com/julienw/bug-firefox-webdriver-focus-after-download
  2. Run npm i then npm test

=> Notice that all focus-related tests fail after initiating download.

From what I see after removing the headless arg, the problem is that the download manager is present. If I add some code to send the Escape to the chrome, with some timeouts before/after to account for races, then the tests are passing as expected.

I understand it's useful for a user, especially for accessibility, but it would be good to have a pref to avoid that, that we could use in tests.

Thanks

Julien, does it still happen with the latest Nightly build?

Flags: needinfo?(felash)

I tried on latest main it still happens.

We can modify one of our wdspec tests to check that:

diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browser/set_download_behavior/download_behavior_allowed.py b/testing/web-platform/tests/webdriver/tests/bidi/browser/set_download_behavior/download_behavior_allowed.py
index 1fa9a1a37803..7828c4f9393c 100644
--- a/testing/web-platform/tests/webdriver/tests/bidi/browser/set_download_behavior/download_behavior_allowed.py
+++ b/testing/web-platform/tests/webdriver/tests/bidi/browser/set_download_behavior/download_behavior_allowed.py
@@ -1,4 +1,6 @@
 import pytest
+import time
+from webdriver.bidi.modules.script import ContextTarget
 
 pytestmark = pytest.mark.asyncio
 
@@ -21,7 +23,29 @@ async def test_destination_folder(bidi_session, new_tab, temp_dir,
         "type": "allowed",
         "destinationFolder": temp_dir
     })
+
+    async def assert_has_focus():
+        hasFocus = await bidi_session.script.call_function(
+            arguments=[],
+            function_declaration="() => document.hasFocus()",
+            target=ContextTarget(new_tab["context"]),
+            await_promise=True,
+            user_activation=True,
+        )
+        assert hasFocus["value"]
+
+    # OK
+    await assert_has_focus()
+
+    # trigger the download, the download list will be displayed
     event = await trigger_download(new_tab)
+
+    # wait a bit, does not fail immediately
+    time.sleep(1)
+
+    # KO: fails because focus is kept by the download manager
+    await assert_has_focus()
+
     # Assert download is allowed.
     assert event["status"] == "complete"
     # Assert `destinationFolder` is respected.

yeah I was on latest nightly already :-)

Flags: needinfo?(felash)

Ok, so we are speaking about the downloader popup which stays open when a download is initiated and finished? If that's the case we should probably enforce that the popup doesn't get opened.

so we are speaking about the downloader popup which stays open when a download is initiated and finished?

Correct.

So the problem seems to be here:
https://searchfox.org/firefox-main/rev/410a52656dd13aa2360a3e96788e41bf48e80c0f/browser/components/downloads/content/downloads.js#349

We probably need a preference to control the panel, and that we can force it to not show up by default for WebDriver.

Summary: The page loses focus when triggering a download, because of the download manager → The current browsing context's document loses focus when a download is triggered because the DownloadsPanel takes focus

Could be an issue with async events, let's tackle this next milestone.

Severity: -- → S3
Points: --- → 3
Priority: -- → P2
Whiteboard: [webdriver:m21]
Assignee: nobody → aborovova
Status: NEW → ASSIGNED
Attachment #9617266 - Attachment description: Bug 2035439 - [remote] Disable "browser.download.focusPanelOnOpen" preference to prevent focus being stolen when starting a download. → Bug 2035439 - [remote] Disable "browser.download.alwaysOpenPanel" preference to not show the download panel when a download begins.
Attachment #9617265 - Attachment is obsolete: true
Attachment #9617268 - Attachment description: Bug 2035439 - [wdspec] Add test for focus positioning when starting a download. → Bug 2035439 - Add tests for focus positioning when starting a download.
Pushed by aborovova@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/d158559ee71c https://hg.mozilla.org/integration/autoland/rev/0a81792cc553 [remote] Disable "browser.download.alwaysOpenPanel" preference to not show the download panel when a download begins. r=jdescottes https://github.com/mozilla-firefox/firefox/commit/2a20464df091 https://hg.mozilla.org/integration/autoland/rev/1b5d8b766328 [wdspec] Make "get_document_focus" a fixture. r=jdescottes https://github.com/mozilla-firefox/firefox/commit/79ef81e002f3 https://hg.mozilla.org/integration/autoland/rev/4ca09fa6b1e8 Add tests for focus positioning when starting a download. r=jdescottes

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/61665 for changes under testing/web-platform/tests

Whiteboard: [webdriver:m21] → [webdriver:m21], [wptsync upstream]
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch

Upstream PR merged by moz-wptsync-bot

Regressions: 2059998
Whiteboard: [webdriver:m21], [wptsync upstream] → [webdriver:m21][wptsync upstream][webdriver:relnote]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: