Commit 9e185fb2 authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[OsSettingsSearch] Do not initially focus internet detail Disconnect btn

* URL search param synced to search input text field.
* Adds a 'search' param to routes navigated to via the search box with
  the search query encoded.
* If the internet detail subpage is navigated to via the search box,
  do not focus the internet detail disconnect button. Instead, defer to
  default subpage behavior of focusing the back button.
* Modifies OsSettingsSearchBoxTest to account for a 'search-result'
  URL param if navigated via settings search box.

Bug: 1071284
Change-Id: I045257914bd12933b3e8a7d28a4770db522b7972
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212803
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772022}
parent 34afacd8
......@@ -387,8 +387,10 @@ Polymer({
this.parentNode.pageTitle = networkName;
Polymer.dom.flush();
if (!this.didSetFocus_) {
// Focus a button once the initial state is set.
if (!this.didSetFocus_ &&
!settings.Router.getInstance().getQueryParameters().has('search')) {
// Unless the page was navigated to via search, focus a button once the
// initial state is set.
this.didSetFocus_ = true;
const button = this.$$('#titleDiv .action-button:not([hidden])');
if (button) {
......
......@@ -334,10 +334,10 @@ cr.define('settings', function() {
settings.Router.getInstance().getRouteForPath(
'/' + pathAndOptParams[0]),
'Supplied path does not map to an existing route.');
const params = pathAndOptParams.length == 2 ?
new URLSearchParams(pathAndOptParams[1]) :
undefined;
const paramsString = `search=${encodeURIComponent(this.searchQuery)}` +
(pathAndOptParams.length == 2 ? `&${pathAndOptParams[1]}` : ``);
const params = new URLSearchParams(paramsString);
settings.Router.getInstance().navigateTo(route, params);
this.fire('navigated-to-result-route');
},
......
......@@ -108,6 +108,15 @@ Polymer({
searchInput.addEventListener(
'focus', this.onSearchInputFocused_.bind(this));
// If the search was initiated by directly entering a search URL, need to
// sync the URL parameter to the textbox.
const urlSearchQuery =
settings.Router.getInstance().getQueryParameters().get('search') || '';
// Setting the search box value without triggering a 'search-changed'
// event, to prevent an unnecessary duplicate entry in |window.history|.
toolbarSearchField.setValue(urlSearchQuery, /*noEvent=*/true);
// Initialize the announcer once.
Polymer.IronA11yAnnouncer.requestAvailability();
},
......
......@@ -211,7 +211,7 @@ suite('OSSettingsSearchBox', () => {
test('Keydown Enter on search box can cause route change', async () => {
settingsSearchHandler.setFakeResults(
[fakeResult('WiFi Settings', 'networks?type=WiFi')]);
await simulateSearch('query');
await simulateSearch('fake query');
await waitForListUpdate();
const enterEvent = new KeyboardEvent(
......@@ -223,6 +223,7 @@ suite('OSSettingsSearchBox', () => {
Polymer.dom.flush();
assertFalse(dropDown.opened);
const router = settings.Router.getInstance();
assertEquals(router.getQueryParameters().get('search'), 'fake query');
assertEquals(router.getCurrentRoute().path, '/networks');
assertEquals(router.getQueryParameters().get('type'), 'WiFi');
});
......@@ -230,7 +231,7 @@ suite('OSSettingsSearchBox', () => {
test('Keypress Enter on row causes route change', async () => {
settingsSearchHandler.setFakeResults(
[fakeResult('WiFi Settings', 'networks?type=WiFi')]);
await simulateSearch('query');
await simulateSearch('fake query');
await waitForListUpdate();
const selectedOsRow = searchBox.getSelectedOsSearchResultRow_();
......@@ -243,6 +244,7 @@ suite('OSSettingsSearchBox', () => {
selectedOsRow.$.searchResultContainer.dispatchEvent(enterEvent);
assertFalse(dropDown.opened);
const router = settings.Router.getInstance();
assertEquals(router.getQueryParameters().get('search'), 'fake query');
assertEquals(router.getCurrentRoute().path, '/networks');
assertEquals(router.getQueryParameters().get('type'), 'WiFi');
});
......@@ -250,7 +252,7 @@ suite('OSSettingsSearchBox', () => {
test('Route change when result row is clicked', async () => {
settingsSearchHandler.setFakeResults(
[fakeResult('WiFi Settings', 'networks?type=WiFi')]);
await simulateSearch('query');
await simulateSearch('fake query');
await waitForListUpdate();
const searchResultRow = searchBox.getSelectedOsSearchResultRow_();
......@@ -261,6 +263,7 @@ suite('OSSettingsSearchBox', () => {
assertFalse(dropDown.opened);
const router = settings.Router.getInstance();
assertEquals(router.getQueryParameters().get('search'), 'fake query');
assertEquals(router.getCurrentRoute().path, '/networks');
assertEquals(router.getQueryParameters().get('type'), 'WiFi');
});
......
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