@@ -76,14 +76,34 @@ test.describe('Web Share API', () => {
76
76
} ) ;
77
77
78
78
test . describe ( 'navigator.canShare()' , ( ) => {
79
- test ( 'should not let you share files' , async ( { page } ) => {
79
+ test ( 'should allow empty files arrays ' , async ( { page } ) => {
80
80
await navigate ( page ) ;
81
- const refuseFileShare = await page . evaluate ( ( ) => {
81
+ const allowEmptyFiles = await page . evaluate ( ( ) => {
82
82
return navigator . canShare ( { text : 'xxx' , files : [ ] } ) ;
83
83
} ) ;
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
+ } ) ;
84
94
expect ( refuseFileShare ) . toEqual ( false ) ;
85
95
} ) ;
86
96
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
+
87
107
test ( 'should not let you share non-http urls' , async ( { page } ) => {
88
108
await navigate ( page ) ;
89
109
const refuseShare = await page . evaluate ( ( ) => {
@@ -218,10 +238,21 @@ test.describe('Web Share API', () => {
218
238
expect ( result ) . toBeUndefined ( ) ;
219
239
} ) ;
220
240
221
- test ( 'should throw when sharing files' , async ( { page } ) => {
241
+ test ( 'should allow sharing with empty files array ' , async ( { page } ) => {
222
242
await navigate ( page ) ;
223
243
await beforeEach ( page ) ;
224
244
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
+ } ) ;
225
256
expect ( message ) . toBeNull ( ) ;
226
257
expect ( result . threw . message ) . toContain ( 'TypeError: Invalid share data' ) ;
227
258
} ) ;
0 commit comments