Commit 30cea792 authored by Josh Simmons's avatar Josh Simmons Committed by Commit Bot

Focus the UrlBar before setting its text in setSearchQuery.

Previously, calling setSearchQuery when the UrlBar didn't yet have focus would result in autocomplete results being shown but no visible search query.

This wasn't an issue previously, as all existing callsites explicitly focused the UrlBar. With https://chromium-review.googlesource.com/c/chromium/src/+/2496031 this will no longer be the case.

Bug: 1144966
Change-Id: I6efd40b25d93704fb35665d69d07541190dd024f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518081
Commit-Queue: Josh Simmons <jds@google.com>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825044}
parent 5e990053
...@@ -547,9 +547,11 @@ public class LocationBarLayout ...@@ -547,9 +547,11 @@ public class LocationBarLayout
return; return;
} }
// Ensure the UrlBar has focus before entering text. If the UrlBar is not focused,
// autocomplete text will be updated but the visible text will not.
setUrlBarFocus(true, null, OmniboxFocusReason.SEARCH_QUERY);
setUrlBarText(UrlBarData.forNonUrlText(query), UrlBar.ScrollType.NO_SCROLL, setUrlBarText(UrlBarData.forNonUrlText(query), UrlBar.ScrollType.NO_SCROLL,
SelectionState.SELECT_ALL); SelectionState.SELECT_ALL);
setUrlBarFocus(true, null, OmniboxFocusReason.SEARCH_QUERY);
mAutocompleteCoordinator.startAutocompleteForQuery(query); mAutocompleteCoordinator.startAutocompleteForQuery(query);
post(new Runnable() { post(new Runnable() {
@Override @Override
......
...@@ -247,6 +247,18 @@ public class LocationBarLayoutTest { ...@@ -247,6 +247,18 @@ public class LocationBarLayoutTest {
}); });
} }
@Test
@SmallTest
public void testSetSearchQueryFocuses() {
final LocationBarLayout locationBar = getLocationBar();
final String query = "testing query";
TestThreadUtils.runOnUiThreadBlocking(() -> {
locationBar.setSearchQuery(query);
Assert.assertEquals(query, locationBar.mUrlCoordinator.getTextWithoutAutocomplete());
});
}
/* /*
* Search engine logo tests. * Search engine logo tests.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment