22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- import * as Common from '../../core/common/common.js' ;
65import * as Platform from '../../core/platform/platform.js' ;
76import * as SDK from '../../core/sdk/sdk.js' ;
87import type * as Protocol from '../../generated/protocol.js' ;
98import { getCleanTextContentFromElements , renderElementIntoDOM } from '../../testing/DOMHelpers.js' ;
109import { createTarget , stubNoopSettings } from '../../testing/EnvironmentHelpers.js' ;
1110import { describeWithMockConnection } from '../../testing/MockConnection.js' ;
11+ import { createViewFunctionStub , type ViewFunctionStub } from '../../testing/ViewFunctionHelpers.js' ;
1212import * as UI from '../../ui/legacy/legacy.js' ;
1313
1414import * as Application from './application.js' ;
@@ -21,18 +21,15 @@ describeWithMockConnection('AppManifestView', () => {
2121 const FIXTURES_640X320_URL = `${ new URL ( './fixtures/640x320.png' , import . meta. url ) } ` ;
2222
2323 let target : SDK . Target . Target ;
24- let emptyView : UI . EmptyWidget . EmptyWidget ;
25- let reportView : UI . ReportView . ReportView ;
26- let throttler : Common . Throttler . Throttler ;
2724 let view : Application . AppManifestView . AppManifestView ;
25+ let viewFunction : ViewFunctionStub < typeof Application . AppManifestView . AppManifestView > ;
26+
2827 beforeEach ( ( ) => {
2928 stubNoopSettings ( ) ;
3029 const tabTarget = createTarget ( { type : SDK . Target . Type . TAB } ) ;
3130 createTarget ( { parentTarget : tabTarget , subtype : 'prerender' } ) ;
3231 target = createTarget ( { parentTarget : tabTarget } ) ;
33- emptyView = new UI . EmptyWidget . EmptyWidget ( '' , '' ) ;
34- reportView = new UI . ReportView . ReportView ( '' ) ;
35- throttler = new Common . Throttler . Throttler ( 0 ) ;
32+ viewFunction = createViewFunctionStub ( Application . AppManifestView . AppManifestView ) ;
3633 } ) ;
3734
3835 afterEach ( ( ) => {
@@ -51,28 +48,22 @@ describeWithMockConnection('AppManifestView', () => {
5148 sinon . stub ( resourceTreeModel , 'getInstallabilityErrors' ) . resolves ( [ ] ) ;
5249 sinon . stub ( resourceTreeModel , 'getAppId' ) . resolves ( { } as Protocol . Page . GetAppIdResponse ) ;
5350
54- view = new Application . AppManifestView . AppManifestView ( emptyView , reportView , throttler ) ;
51+ view = new Application . AppManifestView . AppManifestView ( viewFunction ) ;
5552 renderElementIntoDOM ( view ) ;
5653
57- await new Promise ( resolve => {
58- view . addEventListener ( Application . AppManifestView . Events . MANIFEST_DETECTED , resolve , { once : true } ) ;
59- } ) ;
60- assert . isTrue ( emptyView . isShowing ( ) ) ;
61- assert . isFalse ( reportView . isShowing ( ) ) ;
54+ await viewFunction . nextInput ;
55+ assert . isTrue ( viewFunction . input . emptyView . isShowing ( ) ) ;
56+ assert . isFalse ( viewFunction . input . reportView . isShowing ( ) ) ;
6257
6358 resourceTreeModel . dispatchEventToListeners ( SDK . ResourceTreeModel . Events . DOMContentLoaded , 42 ) ;
64- await new Promise ( resolve => {
65- view . addEventListener ( Application . AppManifestView . Events . MANIFEST_DETECTED , resolve , { once : true } ) ;
66- } ) ;
67- assert . isTrue ( emptyView . isShowing ( ) ) ;
68- assert . isFalse ( reportView . isShowing ( ) ) ;
59+ await viewFunction . nextInput ;
60+ assert . isTrue ( viewFunction . input . emptyView . isShowing ( ) ) ;
61+ assert . isFalse ( viewFunction . input . reportView . isShowing ( ) ) ;
6962
7063 resourceTreeModel . dispatchEventToListeners ( SDK . ResourceTreeModel . Events . DOMContentLoaded , 42 ) ;
71- await new Promise ( resolve => {
72- view . addEventListener ( Application . AppManifestView . Events . MANIFEST_DETECTED , resolve , { once : true } ) ;
73- } ) ;
74- assert . isFalse ( emptyView . isShowing ( ) ) ;
75- assert . isTrue ( reportView . isShowing ( ) ) ;
64+ await viewFunction . nextInput ;
65+ assert . isFalse ( viewFunction . input . emptyView . isShowing ( ) ) ;
66+ assert . isTrue ( viewFunction . input . reportView . isShowing ( ) ) ;
7667 } ) ;
7768
7869 it ( 'shows pwa wco if available' , async ( ) => {
@@ -86,21 +77,17 @@ describeWithMockConnection('AppManifestView', () => {
8677 sinon . stub ( resourceTreeModel , 'getInstallabilityErrors' ) . resolves ( [ ] ) ;
8778 sinon . stub ( resourceTreeModel , 'getAppId' ) . resolves ( { } as Protocol . Page . GetAppIdResponse ) ;
8879
89- view = new Application . AppManifestView . AppManifestView ( emptyView , reportView , throttler ) ;
80+ view = new Application . AppManifestView . AppManifestView ( viewFunction ) ;
9081 renderElementIntoDOM ( view ) ;
9182
9283 resourceTreeModel . dispatchEventToListeners ( SDK . ResourceTreeModel . Events . DOMContentLoaded , 42 ) ;
93- await new Promise ( resolve => {
94- view . addEventListener ( Application . AppManifestView . Events . MANIFEST_RENDERED , resolve , { once : true } ) ;
95- } ) ;
84+ const { windowControlsData} = await viewFunction . nextInput ;
9685
97- const manifestSections = view . getStaticSections ( ) ;
98- const values = getCleanTextContentFromElements ( manifestSections [ 4 ] . getFieldElement ( ) , '.wco' ) ;
99- assert . deepEqual ( values , [ 'window-controls-overlay' ] ) ;
86+ assert . isTrue ( windowControlsData ?. hasWco ) ;
10087 } ) ;
10188
10289 it ( 'can parse ‘sizes’-field' , async ( ) => {
103- view = new Application . AppManifestView . AppManifestView ( emptyView , reportView , throttler ) ;
90+ view = new Application . AppManifestView . AppManifestView ( viewFunction ) ;
10491 const parsed =
10592 view . parseSizes ( '512x512' , 'Icon' as Platform . UIString . LocalizedString , 'https://web.dev/image.html' , [ ] ) ;
10693 const expected = [ {
@@ -112,7 +99,7 @@ describeWithMockConnection('AppManifestView', () => {
11299 } ) ;
113100
114101 it ( 'can handle missing ‘sizes’-field' , async ( ) => {
115- view = new Application . AppManifestView . AppManifestView ( emptyView , reportView , throttler ) ;
102+ view = new Application . AppManifestView . AppManifestView ( viewFunction ) ;
116103 const parsed = view . parseSizes (
117104 undefined as unknown as string , 'Icon' as Platform . UIString . LocalizedString , 'https://web.dev/image.html' , [ ] ) ;
118105 assert . deepEqual ( parsed , [ ] ) ;
@@ -141,18 +128,12 @@ describeWithMockConnection('AppManifestView', () => {
141128 }
142129 } ) ;
143130
144- view = new Application . AppManifestView . AppManifestView ( emptyView , reportView , throttler ) ;
131+ view = new Application . AppManifestView . AppManifestView ( viewFunction ) ;
145132 renderElementIntoDOM ( view ) ;
146133
147- await new Promise ( resolve => {
148- view . addEventListener ( Application . AppManifestView . Events . MANIFEST_RENDERED , resolve , { once : true } ) ;
149- } ) ;
134+ const { warnings, errors, imageErrors} = await viewFunction . nextInput ;
150135
151- const warningSection = reportView . element . shadowRoot ?. querySelector ( '.report-section' ) ;
152- assert . exists ( warningSection ) ;
153- const warnings = warningSection . querySelectorAll < HTMLDivElement > ( '.report-row' ) ;
154- assert . exists ( warnings ) ;
155- return Array . from ( warnings ) . map ( warning => warning . textContent || '' ) ;
136+ return [ ...warnings ?? [ ] , ...errors ?. map ( error => error . message ) ?? [ ] , ...imageErrors ?? [ ] ] ;
156137 }
157138
158139 it ( 'displays warnings for too many shortcuts and not enough screenshots' , async ( ) => {
@@ -307,21 +288,38 @@ describeWithMockConnection('AppManifestView', () => {
307288 } ) ;
308289
309290 it ( 'displays "form-factor", "platform" and "label" properties for screenshots' , async ( ) => {
310- await renderWithWarnings ( `{
311- "screenshots": [
312- {
313- "src": "${ FIXTURES_320X320_URL } ",
314- "type": "image/png",
315- "sizes": "320x320",
316- "form_factor": "wide",
317- "label": "Dummy Screenshot",
318- "platform": "windows"
291+ const emptyView = new UI . EmptyWidget . EmptyWidget ( '' , '' ) ;
292+ const reportView = new UI . ReportView . ReportView ( '' ) ;
293+ const viewInput = {
294+ reportView,
295+ emptyView,
296+ screenshotsSections : [ ] ,
297+ screenshotsData : {
298+ screenshots : [ {
299+ screenshot : {
300+ src : FIXTURES_320X320_URL ,
301+ type : 'image/png' ,
302+ sizes : '320x320' ,
303+ form_factor : 'wide' ,
304+ label : 'Dummy Screenshot' ,
305+ platform : 'windows'
306+ } ,
307+ processedImage : {
308+ imageResourceErrors : [ ] ,
309+ squareSizedIconAvailable : true ,
310+ naturalWidth : 320 ,
311+ naturalHeight : 320 ,
312+ title : '320×320px\nimage/png' ,
313+ imageSrc : '' ,
314+ imageUrl : FIXTURES_320X320_URL ,
319315 }
320- ]
321- }` ) ;
322-
323- const screenshotSection =
324- reportView . element . shadowRoot ?. querySelectorAll < HTMLDivElement > ( '.report-section' ) [ 7 ] || null ;
316+ } ] ,
317+ imageResourceErrors : [ ] ,
318+ warnings : [ ] ,
319+ }
320+ } ;
321+ Application . AppManifestView . DEFAULT_VIEW ( viewInput , undefined , viewInput . reportView . element ) ;
322+ const screenshotSection = reportView . element . shadowRoot ?. querySelector < HTMLDivElement > ( '.report-section' ) || null ;
325323 assert . instanceOf ( screenshotSection , HTMLDivElement ) ;
326324 assert . deepEqual (
327325 getCleanTextContentFromElements ( screenshotSection , '.report-field-name' ) . slice ( 0 , 3 ) ,
0 commit comments