Open Bug 2035439 Opened 2 months ago Updated 2 months 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

(Not tracked)

People

(Reporter: julienw, Unassigned)

Details

(Whiteboard: [webdriver:m21])

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]
You need to log in before you can comment on or make changes to this bug.