Open Bug 1329939 Opened 3 years ago Updated 9 months ago

Popup notifications are not displayed if Firefox is not the foremost application

Categories

(Testing :: General, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: davehunt, Unassigned)

Details

(Whiteboard: gfx-noted)

Whilst working on some end-to-end automation for addons.mozilla.org I have observed that the popup notifications used for add-on installation are not displayed unless Firefox is the top window. To work around this, I am launching Firefox with the -foreground command line option. This means that when running tests locally as the focus shifts to the Firefox window, and must not lose focus during the test. It also means that these tests cannot run in parallel, causing test runs to take much longer than they would otherwise.

I'm using Selenium with GeckoDriver (Marionette) and Python. The following Python script replicates the issue, and requires the Selenium Python client [1] to be installed and GeckoDriver [2] to be in the system path:

> import time
> from selenium.webdriver import Firefox
> driver = Firefox()
> driver.get('https://addons.mozilla.org/en-US/firefox/addon/firebug/')
> def get_notification():
>     time.sleep(5)  # give us a chance to focus the window
>     driver.find_element_by_css_selector('#addon .install-button a').click()
>     time.sleep(5)  # make sure the notification would be displayed
>     with driver.context(driver.CONTEXT_CHROME):
>         n = driver.find_element_by_css_selector('#notification-popup popupnotification')
>         print(n.get_attribute('label'))

When Firefox is the foremost application the output is:
This site would like to install an add-on in Firefox:

When Firefox is not the foremost application the output is:
NoSuchElementException: Message: Unable to locate element: #notification-popup popupnotification

The exception indicates that the popup notification cannot be found, which confirms what is seen on the screen.

Is there a way we can convince Firefox to display these elements when it is not the foremost application?

[1] https://pypi.python.org/pypi/selenium
[2] https://github.com/mozilla/geckodriver
Flags: needinfo?(enndeakin)
I have to add that geckodriver sets the focusmanager.testmode preference to true:
https://github.com/mozilla/geckodriver/blob/master/src/prefs.rs#L150-L152

So does it mean that there is no integration for popup notifications yet? The same btw also applies for the autocomplete results of the locationbar.
> When Firefox is not the foremost application the output is:
> NoSuchElementException: Message: Unable to locate element:
> #notification-popup popupnotification

That isn't a Firefox error. It looks more like a python error. Those elements should always be there in the browser window whether the notification is open or not, so it is more likely that the test harness isn't finding the correct window.
Flags: needinfo?(enndeakin)
The exception is indeed a Python one, but was used as a demonstration that the notification is not displayed. The Python exception is confirming what I see visually; that the popup notification is not displayed when Firefox is not the foremost application.

It's also worth noting that when Firefox is not the foremost application and the interaction that would display the notification is complete (and the notification is not displayed), bringing Firefox to focus by clicking on the window will then cause the notification to be displayed.

Neil: It was suggested that you would be able to offer advice in this area (hence the needinfo). Please redirect this if you feel there is someone else that can assist.
Flags: needinfo?(enndeakin)
So I'm not sure what you want to me provide advice on. The behaviour in comment 3 is the way it should work as far as I can tell.

Your test code is giving an error because something in your test system is doing something wrong.

Is your goal to focus the Firefox window? Is your goal to test what happens when someone tries to install an addon while not focused? The notification won't appear until Firefox is focused. I don't know how that is done; it is specific to the notification type popups handled in PopupNotifications.jsm
Flags: needinfo?(enndeakin)
Neil, the basic question here is if we can get a similar behavior for Firefox in terms of running under automation similar as what we did for focusmanager.testing which fakes the focus for Firefox, even Firefox is not in the foreground. Thanks.
Flags: needinfo?(enndeakin)
Component: Graphics → Marionette
Product: Core → Testing
Whiteboard: gfx-noted
Version: unspecified → Trunk
I just want to add that this bug is not a Marionette specific issue. It's all related to automated testing in Firefox, and the current behavior is kinda limiting us.
Component: Marionette → General
I'm guessing that the code that handles this is at https://dxr.mozilla.org/mozilla-central/source/toolkit/modules/PopupNotifications.jsm#450

It looks like both 'isActiveBrowser' and 'isActiveWindow' must be true to show the notification. The latter should be true when the focus testing mode is enabled, assuming that you have attempted to focus the window properly. I'm not sure what the former does (perhaps checking for the selected tab?)
Flags: needinfo?(enndeakin)
I'm not an expert in the Firefox codebase, but it looks to me like we'd need a mode that skipped checking if the window with the notification is the currently active window. Perhaps this is possible now, though I can't find any mention of a test mode for this.
What I noticed lately is that the edit bookmark panel which pops-up when you click the star button or press Ctrl/Cmd+D is also shown when Firefox runs in the brackground. So I suspect that this problem here with popup notifications could be fixed without another preference. 

Marko, could you point us to the code which opens the edit bookmark dialog?
Flags: needinfo?(mak77)
http://searchfox.org/mozilla-central/rev/bf98cd4315b5efa1b28831001ad27d54df7bbb68/browser/base/content/browser-places.js#303
But it doesn't make any kind of check on the window focus, so I'm not sure it will be useful to figure out your problem with notifications.
Flags: needinfo?(mak77)
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.