@@ -76,14 +76,34 @@ test.describe('Web Share API', () => {
7676 } ) ;
7777
7878 test . describe ( 'navigator.canShare()' , ( ) => {
79- test ( 'should not let you share files' , async ( { page } ) => {
79+ test ( 'should allow empty files arrays ' , async ( { page } ) => {
8080 await navigate ( page ) ;
81- const refuseFileShare = await page . evaluate ( ( ) => {
81+ const allowEmptyFiles = await page . evaluate ( ( ) => {
8282 return navigator . canShare ( { text : 'xxx' , files : [ ] } ) ;
8383 } ) ;
84+ expect ( allowEmptyFiles ) . toEqual ( true ) ;
85+ } ) ;
86+
87+ test ( 'should not let you share non-empty files arrays' , async ( { page } ) => {
88+ await navigate ( page ) ;
89+ const refuseFileShare = await page . evaluate ( ( ) => {
90+ // Create a mock File object
91+ const mockFile = new File ( [ '' ] , 'test.txt' , { type : 'text/plain' } ) ;
92+ return navigator . canShare ( { text : 'xxx' , files : [ mockFile ] } ) ;
93+ } ) ;
8494 expect ( refuseFileShare ) . toEqual ( false ) ;
8595 } ) ;
8696
97+ test ( 'should reject non-array files values' , async ( { page } ) => {
98+ await navigate ( page ) ;
99+ const rejectNonArrayFiles = await page . evaluate ( ( ) => {
100+ // eslint-disable-next-line
101+ // @ts -ignore intentionally testing invalid files type
102+ return navigator . canShare ( { text : 'xxx' , files : 'not-an-array' } ) ;
103+ } ) ;
104+ expect ( rejectNonArrayFiles ) . toEqual ( false ) ;
105+ } ) ;
106+
87107 test ( 'should not let you share non-http urls' , async ( { page } ) => {
88108 await navigate ( page ) ;
89109 const refuseShare = await page . evaluate ( ( ) => {
@@ -218,10 +238,21 @@ test.describe('Web Share API', () => {
218238 expect ( result ) . toBeUndefined ( ) ;
219239 } ) ;
220240
221- test ( 'should throw when sharing files' , async ( { page } ) => {
241+ test ( 'should allow sharing with empty files array ' , async ( { page } ) => {
222242 await navigate ( page ) ;
223243 await beforeEach ( page ) ;
224244 const { result, message } = await checkShare ( page , { title : 'title' , files : [ ] } ) ;
245+ expect ( message ) . toMatchObject ( { featureName : 'webCompat' , method : 'webShare' , params : { title : 'title' , text : '' } } ) ;
246+ expect ( result ) . toBeUndefined ( ) ;
247+ } ) ;
248+
249+ test ( 'should throw when sharing non-empty files arrays' , async ( { page } ) => {
250+ await navigate ( page ) ;
251+ await beforeEach ( page ) ;
252+ const { result, message } = await checkShare ( page , {
253+ title : 'title' ,
254+ files : [ new File ( [ '' ] , 'test.txt' , { type : 'text/plain' } ) ] ,
255+ } ) ;
225256 expect ( message ) . toBeNull ( ) ;
226257 expect ( result . threw . message ) . toContain ( 'TypeError: Invalid share data' ) ;
227258 } ) ;
0 commit comments