@@ -10,6 +10,7 @@ import * as Host from '../../core/host/host.js';
1010import * as i18n from '../../core/i18n/i18n.js' ;
1111import * as Platform from '../../core/platform/platform.js' ;
1212import * as Root from '../../core/root/root.js' ;
13+ import type * as Foundation from '../../foundation/foundation.js' ;
1314import * as IconButton from '../components/icon_button/icon_button.js' ;
1415import * as VisualLogging from '../visual_logging/visual_logging.js' ;
1516
@@ -52,10 +53,12 @@ export const defaultOptionsForTabs = {
5253
5354export class PreRegisteredView implements View {
5455 private readonly viewRegistration : ViewRegistration ;
56+ private readonly universe ?: Foundation . Universe . Universe ;
5557 private widgetPromise : Promise < Widget > | null ;
5658
57- constructor ( viewRegistration : ViewRegistration ) {
59+ constructor ( viewRegistration : ViewRegistration , universe ?: Foundation . Universe . Universe ) {
5860 this . viewRegistration = viewRegistration ;
61+ this . universe = universe ;
5962 this . widgetPromise = null ;
6063 }
6164
@@ -124,7 +127,10 @@ export class PreRegisteredView implements View {
124127
125128 widget ( ) : Promise < Widget > {
126129 if ( this . widgetPromise === null ) {
127- this . widgetPromise = this . viewRegistration . loadView ( ) ;
130+ if ( ! this . universe ) {
131+ throw new Error ( 'Creating views via ViewManager requires a Foundation.Universe' ) ;
132+ }
133+ this . widgetPromise = this . viewRegistration . loadView ( this . universe ) ;
128134 }
129135 return this . widgetPromise ;
130136 }
@@ -170,7 +176,9 @@ export class ViewManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
170176
171177 private readonly preRegisteredViews : PreRegisteredView [ ] = [ ] ;
172178
173- private constructor ( ) {
179+ // TODO(crbug.com/458180550): Pass the universe unconditionally once tests no longer rely
180+ // on `instance()` to create ViewManagers lazily in after/afterEach blocks.
181+ private constructor ( universe ?: Foundation . Universe . Universe ) {
174182 super ( ) ;
175183
176184 // Read override setting for location
@@ -184,7 +192,7 @@ export class ViewManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
184192 for ( const view of getRegisteredViewExtensions ( ) ) {
185193 const location = view . location || 'none' ;
186194 const views = viewsByLocation . get ( location ) || [ ] ;
187- views . push ( new PreRegisteredView ( view ) ) ;
195+ views . push ( new PreRegisteredView ( view , universe ) ) ;
188196 viewsByLocation . set ( location , views ) ;
189197 }
190198
@@ -220,10 +228,11 @@ export class ViewManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
220228
221229 static instance ( opts : {
222230 forceNew : boolean | null ,
231+ universe ?: Foundation . Universe . Universe ,
223232 } = { forceNew : null } ) : ViewManager {
224- const { forceNew} = opts ;
233+ const { forceNew, universe } = opts ;
225234 if ( ! viewManagerInstance || forceNew ) {
226- viewManagerInstance = new ViewManager ( ) ;
235+ viewManagerInstance = new ViewManager ( universe ) ;
227236 }
228237
229238 return viewManagerInstance ;
0 commit comments