@@ -19,7 +19,6 @@ import {loadTimeData} from 'chrome://resources/js/load_time_data.js';
1919import { isMac } from 'chrome://resources/js/platform.js' ;
2020import { PromiseResolver } from 'chrome://resources/js/promise_resolver.js' ;
2121import { PageCallbackRouter as SearchboxPageCallbackRouter , PageHandlerRemote as SearchboxPageHandlerRemote } from 'chrome://resources/mojo/components/omnibox/browser/searchbox.mojom-webui.js' ;
22- import type { AutocompleteMatch , AutocompleteResult } from 'chrome://resources/mojo/components/omnibox/browser/searchbox.mojom-webui.js' ;
2322import { assertDeepEquals , assertEquals , assertFalse , assertNotEquals , assertTrue } from 'chrome://webui-test/chai_assert.js' ;
2423import type { MetricsTracker } from 'chrome://webui-test/metrics_test_support.js' ;
2524import { fakeMetricsPrivate } from 'chrome://webui-test/metrics_test_support.js' ;
@@ -119,65 +118,6 @@ suite('NewTabPageAppTest', () => {
119118 '#composeButton' ) ;
120119 }
121120
122- function createAutocompleteMatch ( ) : AutocompleteMatch {
123- return {
124- a11yLabel : '' ,
125- actions : [ ] ,
126- allowedToBeDefaultMatch : false ,
127- isSearchType : false ,
128- isEnterpriseSearchAggregatorPeopleType : false ,
129- swapContentsAndDescription : false ,
130- supportsDeletion : false ,
131- suggestionGroupId : - 1 , // Indicates a missing suggestion group Id.
132- contents : '' ,
133- contentsClass : [ { offset : 0 , style : 0 } ] ,
134- description : '' ,
135- descriptionClass : [ { offset : 0 , style : 0 } ] ,
136- destinationUrl : { url : '' } ,
137- inlineAutocompletion : '' ,
138- fillIntoEdit : '' ,
139- iconPath : '' ,
140- iconUrl : { url : '' } ,
141- imageDominantColor : '' ,
142- imageUrl : '' ,
143- isNoncannedAimSuggestion : false ,
144- removeButtonA11yLabel : '' ,
145- type : '' ,
146- isRichSuggestion : false ,
147- isWeatherAnswerSuggestion : null ,
148- answer : null ,
149- tailSuggestCommonPrefix : null ,
150- hasInstantKeyword : false ,
151- keywordChipHint : '' ,
152- keywordChipA11y : '' ,
153- } ;
154- }
155-
156- function createAutocompleteResult (
157- modifiers : Partial < AutocompleteResult > = { } ) : AutocompleteResult {
158- const base : AutocompleteResult = {
159- input : '' ,
160- matches : [ ] ,
161- suggestionGroupsMap : { } ,
162- smartComposeInlineHint : null ,
163- } ;
164-
165- return Object . assign ( base , modifiers ) ;
166- }
167-
168- function createSearchMatch ( modifiers : Partial < AutocompleteMatch > = { } ) :
169- AutocompleteMatch {
170- return Object . assign (
171- createAutocompleteMatch ( ) , {
172- isSearchType : true ,
173- contents : 'hello world' ,
174- destinationUrl : { url : 'https://www.google.com/search?q=hello+world' } ,
175- fillIntoEdit : 'hello world' ,
176- type : 'search-suggest' ,
177- } ,
178- modifiers ) ;
179- }
180-
181121 function getScrim ( ) : HTMLElement | null {
182122 return app . shadowRoot . querySelector < HTMLElement > ( '#scrim' ) ;
183123 }
@@ -1920,45 +1860,30 @@ suite('NewTabPageAppTest', () => {
19201860 } ) ;
19211861 } ) ;
19221862 test (
1923- 'A scrim is applied when the dropdown is shown in searchbox' ,
1924- async ( ) => {
1925- assertFalse ( ! ! getScrim ( ) ) ;
1863+ 'A scrim is applied when the focus is on searchbox input' , async ( ) => {
1864+ const scrim = getScrim ( ) ;
1865+ assertTrue ( ! ! scrim ) ;
1866+ assertTrue ( scrim . hidden ) ;
19261867 const realbox_input =
19271868 $$ < SearchboxElement > ( app , '#searchbox' ) ! . $ . input ;
1928- realbox_input . value = 'he' ;
1929- realbox_input . dispatchEvent ( new InputEvent ( 'input' ) ) ;
1869+ realbox_input . dispatchEvent ( new FocusEvent ( 'focus' ) ) ;
19301870 await microtasksFinished ( ) ;
1931- const matches = [ createSearchMatch ( ) ] ;
1932- SearchboxBrowserProxy . getInstance ( )
1933- . callbackRouter . $ . bindNewPipeAndPassRemote ( )
1934- . autocompleteResultChanged ( createAutocompleteResult ( {
1935- input : realbox_input . value . trimStart ( ) ,
1936- matches : matches ,
1937- } ) ) ;
1938- await microtasksFinished ( ) ;
1939- const scrim = getScrim ( ) ;
1940- assertTrue ( ! ! scrim ) ;
1871+ assertFalse ( scrim . hidden ) ;
19411872
1942- // The dropdown is closed when a keypress on Esc is made.
1943- const escapeEvent = new KeyboardEvent ( 'keydown' , {
1944- bubbles : true ,
1945- cancelable : true ,
1946- composed : true , // So it propagates across shadow DOM boundary.
1947- key : 'Escape' ,
1948- } ) ;
1949- realbox_input . dispatchEvent ( escapeEvent ) ;
1873+ $$ < SearchboxElement > ( app , '#searchbox' ) ! . $ . inputWrapper . dispatchEvent (
1874+ new FocusEvent ( 'focusout' , { relatedTarget : scrim } ) ) ;
19501875 await microtasksFinished ( ) ;
1951- assertFalse ( ! ! getScrim ( ) ) ;
1876+ assertTrue ( scrim . hidden ) ;
19521877 } ) ;
19531878 test (
1954- 'A scrim is applied when the dropdown is shown in composebox' ,
1879+ 'A scrim is applied when the focus is on the composebox input ' ,
19551880 async ( ) => {
19561881 loadTimeData . overrideValues ( {
1957- composeboxShowZps : true ,
1958- composeboxShowTypedSuggest : true ,
19591882 composeboxCloseByClickOutside : true ,
19601883 } ) ;
1961- assertFalse ( ! ! getScrim ( ) ) ;
1884+ const scrim = getScrim ( ) ;
1885+ assertTrue ( ! ! scrim ) ;
1886+ assertTrue ( scrim ?. hidden ) ;
19621887 const realbox = $$ ( app , '#searchbox' ) ;
19631888 assertTrue ( ! ! realbox ) ;
19641889 realbox . dispatchEvent ( new CustomEvent ( 'open-composebox' , {
@@ -1967,26 +1892,19 @@ suite('NewTabPageAppTest', () => {
19671892 await microtasksFinished ( ) ;
19681893 const ntpComposebox = app . shadowRoot . querySelector ( 'ntp-composebox' ) ;
19691894 assertTrue ( ! ! ntpComposebox ) ;
1970-
1971- // Open the dropbox by satisfying its opening condition
1972- ntpComposebox . $ . input . value = 'Test' ;
1973- ntpComposebox . $ . input . style . height = '48px' ;
1974- ntpComposebox . $ . input . dispatchEvent ( new Event ( 'input' ) ) ;
1975- await microtasksFinished ( ) ;
1976- const matches = [ createSearchMatch ( ) ] ;
1977- ComposeboxProxyImpl . getInstance ( )
1978- . searchboxCallbackRouter . $ . bindNewPipeAndPassRemote ( )
1979- . autocompleteResultChanged ( createAutocompleteResult ( {
1980- input : 'Test' . trimStart ( ) ,
1981- matches : matches ,
1982- } ) ) ;
1895+ ntpComposebox . $ . input . dispatchEvent ( new FocusEvent ( 'focus' ) ) ;
19831896 await microtasksFinished ( ) ;
1984- const scrim = getScrim ( ) ;
1985- assertTrue ( ! ! scrim ) ;
19861897
1987- scrim . click ( ) ; // closes the composebox and thus the dropdown
1898+ assertFalse ( scrim . hidden ) ;
1899+
1900+ ntpComposebox . $ . input . dispatchEvent (
1901+ new FocusEvent ( 'focusout' , { relatedTarget : scrim } ) ) ;
1902+ await microtasksFinished ( ) ;
1903+ scrim . click ( ) ;
19881904 await microtasksFinished ( ) ;
1989- assertFalse ( ! ! getScrim ( ) ) ;
1905+ assertTrue ( scrim ?. hidden ) ;
1906+ // Composebox should have been closed.
1907+ assertFalse ( ! ! app . shadowRoot . querySelector ( 'ntp-composebox' ) ) ;
19901908 } ) ;
19911909 test ( 'searchbox text carries over to composebox' , async ( ) => {
19921910 // Arrange.
0 commit comments