Skip to content

Commit

Permalink
CrOS Settings: Convert search handlers to TS
Browse files Browse the repository at this point in the history
Additionally moves the updated files out of the top-level directory
and into the search/ subfolder.

Bug: chromium:1315757
Test: browser_tests --gtest_filter='OSSettingsOsSettingsSearchBox*'
Test: Searching for settings and personalization settings
Change-Id: I19d4b3b83ce0e2fb81ee08b5224deaa4b35074a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4018076
Commit-Queue: Wes Okuhara <wesokuhara@google.com>
Reviewed-by: Jeffrey Young <cowmoo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1070594}
  • Loading branch information
Wes Okuhara authored and Chromium LUCI CQ committed Nov 12, 2022
1 parent b7ece23 commit 2e95c97
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 104 deletions.
23 changes: 0 additions & 23 deletions chrome/browser/resources/settings/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ js_type_check("closure_compile_local_module") {
closure_flags = os_settings_closure_flags

deps = [
":combined_search_handler",
":deep_linking_behavior",
":find_shortcut_behavior",
":global_scroll_target_behavior",
Expand All @@ -356,12 +355,10 @@ js_type_check("closure_compile_local_module") {
":os_settings",
":os_settings_icons_css",
":os_settings_routes",
":personalization_search_handler",
":pref_to_setting_metric_converter",
":prefs_behavior",
":route_observer_behavior",
":route_origin_behavior",
":settings_search_handler",
]
}

Expand Down Expand Up @@ -469,25 +466,5 @@ js_library("route_origin_behavior") {
]
}

js_library("combined_search_handler") {
deps = [
":personalization_search_handler",
":settings_search_handler",
"//ash/webui/personalization_app/search:mojo_bindings_webui_js",
"//mojo/public/mojom/base:base_webui_js",
]
}

js_library("icon") {
}

js_library("personalization_search_handler") {
deps = [ "//ash/webui/personalization_app/search:mojo_bindings_webui_js" ]
}

js_library("settings_search_handler") {
deps = [
"//chrome/browser/ui/webui/settings/ash/search:mojo_bindings_js_library_for_compile",
"//ui/webui/resources/js:cr.m",
]
}
6 changes: 3 additions & 3 deletions chrome/browser/resources/settings/chromeos/os_settings.gni
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ foreach(f, css_files) {

non_web_component_files = [
"chromeos/assert_extras.ts",
"chromeos/combined_search_handler.js",
"chromeos/crostini_page/crostini_browser_proxy.ts",
"chromeos/crostini_page/crostini_shared_usb_devices.ts",
"chromeos/date_time_page/date_time_types.ts",
Expand Down Expand Up @@ -279,12 +278,13 @@ non_web_component_files = [
"chromeos/os_settings_routes.js",
"chromeos/parental_controls_page/parental_controls_browser_proxy.ts",
"chromeos/personalization_page/personalization_hub_browser_proxy.ts",
"chromeos/personalization_search_handler.js",
"chromeos/pref_to_setting_metric_converter.js",
"chromeos/prefs_behavior.js",
"chromeos/route_observer_behavior.js",
"chromeos/route_origin_behavior.js",
"chromeos/settings_search_handler.js",
"chromeos/search/combined_search_handler.ts",
"chromeos/search/personalization_search_handler.ts",
"chromeos/search/settings_search_handler.ts",

# Files below are from Browser Settings and shared with ChromeOS Settings
"appearance_page/fonts_browser_proxy.ts",
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/resources/settings/chromeos/os_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export {routes} from './os_route.js';
export {SearchEngine, SearchEnginesBrowserProxy, SearchEnginesBrowserProxyImpl, SearchEnginesInfo} from './os_search_page/search_engines_browser_proxy.js';
export {ParentalControlsBrowserProxy, ParentalControlsBrowserProxyImpl} from './parental_controls_page/parental_controls_browser_proxy.js';
export {PersonalizationHubBrowserProxy, PersonalizationHubBrowserProxyImpl} from './personalization_page/personalization_hub_browser_proxy.js';
export {getPersonalizationSearchHandler, setPersonalizationSearchHandlerForTesting} from './personalization_search_handler.js';
export {getSettingsSearchHandler, setSettingsSearchHandlerForTesting} from './settings_search_handler.js';
export {getPersonalizationSearchHandler, setPersonalizationSearchHandlerForTesting} from './search/personalization_search_handler.js';
export {getSettingsSearchHandler, setSettingsSearchHandlerForTesting} from './search/settings_search_handler.js';
export {
appNotificationHandlerMojomWebui,
crosAudioConfigMojomWebui,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import '../os_icons.js';
import '../../settings_shared.css.js';

import {getInstance as getAnnouncerInstance} from 'chrome://resources/cr_elements/cr_a11y_announcer/cr_a11y_announcer.js';
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js';
import {assert, assertNotReached} from 'chrome://resources/js/assert_ts.js';
import {FocusRowMixin} from 'chrome://resources/js/focus_row_mixin.js';
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

Expand All @@ -21,7 +21,7 @@ import {SearchResult as SettingsSearchResult, SearchResultIdentifier, SearchResu
import {SearchResultIcon} from '../../mojom-webui/search/search_result_icon.mojom-webui.js';
import {OpenWindowProxyImpl} from '../../open_window_proxy.js';
import {Router} from '../../router.js';
import {SearchResult} from '../combined_search_handler.js';
import {SearchResult} from '../search/combined_search_handler.js';

import {getTemplate} from './os_search_result_row.html.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import {SearchResultsObserverInterface as PersonalizationSearchResultsObserverIn
import {ParentResultBehavior, SearchResultsObserverInterface, SearchResultsObserverReceiver} from '../../mojom-webui/search/search.mojom-webui.js';
import {Router} from '../../router.js';
import {castExists} from '../assert_extras.js';
import {combinedSearch, SearchResult} from '../combined_search_handler.js';
import {recordSearch} from '../metrics_recorder.js';
import {routes} from '../os_route.js';
import {getPersonalizationSearchHandler} from '../personalization_search_handler.js';
import {getSettingsSearchHandler} from '../settings_search_handler.js';
import {combinedSearch, getPersonalizationSearchHandler, getSettingsSearchHandler, SearchResult} from '../search/combined_search_handler.js';

import {OsSearchResultRowElement} from './os_search_result_row.js';
import {getTemplate} from './os_settings_search_box.html.js';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {String16} from 'chrome://resources/mojo/mojo/public/mojom/base/string16.mojom-webui.js';

import {SearchResult as PersonalizationSearchResult} from '../mojom-webui/personalization/search.mojom-webui.js';
import {ParentResultBehavior, SearchResult as SettingsSearchResult} from '../mojom-webui/search/search.mojom-webui.js';
import {SearchResult as PersonalizationSearchResult} from '../../mojom-webui/personalization/search.mojom-webui.js';
import {ParentResultBehavior, SearchResult as SettingsSearchResult} from '../../mojom-webui/search/search.mojom-webui.js';

import {getPersonalizationSearchHandler} from './personalization_search_handler.js';
import {getSettingsSearchHandler} from './settings_search_handler.js';

/**
* @typedef {SettingsSearchResult|PersonalizationSearchResult}
*/
export let SearchResult;
export type SearchResult = SettingsSearchResult|PersonalizationSearchResult;

/**
* Return array of the top |maxNumResults| search results.
* @param {!Array<!SearchResult>} a
* @param {!Array<!SearchResult>} b
* @param {number} maxNumResults
* @return {!Array<!SearchResult>}
*/
function mergeResults(a, b, maxNumResults) {
function mergeResults(
a: SearchResult[], b: SearchResult[],
maxNumResults: number): SearchResult[] {
// Simple concat and sort is faster than 2-pointer algorithm for small arrays.
return a.concat(b)
.sort((x, y) => y.relevanceScore - x.relevanceScore)
Expand All @@ -32,13 +26,11 @@ function mergeResults(a, b, maxNumResults) {

/**
* Search both settings and personalization and merge the results.
* @param {!String16} query
* @param {!number} maxNumResults
* @param {!ParentResultBehavior} parentResultBehavior
* @return {!Promise<{results: !Array<!SearchResult>}>}
*/
export async function combinedSearch(
query, maxNumResults, parentResultBehavior) {
query: String16, maxNumResults: number,
parentResultBehavior: ParentResultBehavior):
Promise<{results: SearchResult[]}> {
const [settingsResponse, personalizationResponse] = await Promise.all([
getSettingsSearchHandler().search(
query, maxNumResults, parentResultBehavior),
Expand All @@ -50,3 +42,8 @@ export async function combinedSearch(
maxNumResults),
};
}

export {
getPersonalizationSearchHandler,
getSettingsSearchHandler,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
* @fileoverview
* Provides functions used for personalization search, results of which link to
* Personalization App.
* Also provides a way to inject a test implementation for verifying
* personalization search.
*/

import {SearchHandler, SearchHandlerInterface} from '../../mojom-webui/personalization/search.mojom-webui.js';

let personalizationSearchHandler: SearchHandlerInterface|null = null;

export function setPersonalizationSearchHandlerForTesting(
testSearchHandler: SearchHandlerInterface): void {
personalizationSearchHandler = testSearchHandler;
}

export function getPersonalizationSearchHandler(): SearchHandlerInterface {
if (!personalizationSearchHandler) {
personalizationSearchHandler = SearchHandler.getRemote();
}

return personalizationSearchHandler;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {SearchHandler, SearchHandlerInterface} from '../mojom-webui/search/search.mojom-webui.js';

/**
* @fileoverview
* Provides functions used for OS settings search.
* Also provides a way to inject a test implementation for verifying
* OS settings search.
*/
/** @type {?SearchHandlerInterface} */
let settingsSearchHandler = null;

/**
* @param {!SearchHandlerInterface}
* testSearchHandler A test search handler.
*/
export function setSettingsSearchHandlerForTesting(testSearchHandler) {
import {SearchHandler, SearchHandlerInterface} from '../../mojom-webui/search/search.mojom-webui.js';

let settingsSearchHandler: SearchHandlerInterface|null = null;

export function setSettingsSearchHandlerForTesting(
testSearchHandler: SearchHandlerInterface): void {
settingsSearchHandler = testSearchHandler;
}

/**
* @return {!SearchHandlerInterface} Search handler.
*/
export function getSettingsSearchHandler() {
export function getSettingsSearchHandler(): SearchHandlerInterface {
if (settingsSearchHandler) {
return settingsSearchHandler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
// found in the LICENSE file.

import {OpenWindowProxyImpl, personalizationSearchMojomWebui, Router, routes, routesMojomWebui, searchMojomWebui, searchResultIconMojomWebui, setPersonalizationSearchHandlerForTesting, setSettingsSearchHandlerForTesting, settingMojomWebui, setUserActionRecorderForTesting, userActionRecorderMojomWebui} from 'chrome://os-settings/chromeos/os_settings.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {eventToPromise} from 'chrome://webui-test/test_util.js';

import {assertDeepEquals, assertEquals, assertFalse, assertNotEquals, assertTrue} from 'chrome://webui-test/chai_assert.js';
import {TestBrowserProxy} from 'chrome://webui-test/test_browser_proxy.js';
import {eventToPromise} from 'chrome://webui-test/test_util.js';

import {FakePersonalizationSearchHandler} from './fake_personalization_search_handler.js';
import {FakeSettingsSearchHandler} from './fake_settings_search_handler.js';
Expand Down

0 comments on commit 2e95c97

Please sign in to comment.