In nsAutocompleteController::HandleKeyNavigation, we might trigger a search operation (or open the popup)
However, when we find there is already a search result received previously, and the search string is the same
as the current one, we won't trigger a new search[1] because the result should be the same.
This might be true for most of the cases, but not true when clients that perform the search is differnt.
As far as I know, there are at least 3 different autocomplete clients: form history, CC/Address autocomplete, and login manager.
For example, the same search string might return a different result when it is searched by the login manager
and by the form history component.
Here is how the intermittent occurs:
- The page is loaded
- Password field is detected so the login manager fetches the login data from the parent asynchronously
- The testcase continues to run. The username field is focused
- Autocomplete search for the focus field is triggered. Since the login manager has not yet told FormFillController this is a field we care, we search the form history and get an empty result.
- Login data is sent from parent to child, _fillForm is called. The LoginManagerChild calls MarkAsLoginManagerField
- Key event occurs on the field. Autocomplete search is triggered again. However, the search is not executed because [1]
- Popup is not shown. Testcase timeout.
When #5 occurs before #3, the autocomplete search in #4 will be processed by the login manager, and we will get the result
and open the popup in this case
In the current architecture, I don't see an easy way that we can distinguish whether the autocomplete client is different
in nsAutocompleteController. So instead of doing it in nsAutocompleteController, this patch fixes this issue in FormFillController.
In FormFillController, when we call MarkAsLoginManagerField on a focus field, we call ResetInternalState() to
tell nsAutocompleteController to clear previous search result.