@@ -76,6 +76,19 @@ describe('<webview> tag', function () {
7676 await emittedOnce ( ipcMain , 'pong' )
7777 } )
7878
79+ it ( 'works with sandbox' , async ( ) => {
80+ const w = await openTheWindow ( {
81+ show : false ,
82+ webPreferences : {
83+ webviewTag : true ,
84+ nodeIntegration : true ,
85+ sandbox : true
86+ }
87+ } )
88+ w . loadFile ( path . join ( fixtures , 'pages' , 'webview-isolated.html' ) )
89+ await emittedOnce ( ipcMain , 'pong' )
90+ } )
91+
7992 it ( 'works with contextIsolation' , async ( ) => {
8093 const w = await openTheWindow ( {
8194 show : false ,
@@ -89,6 +102,20 @@ describe('<webview> tag', function () {
89102 await emittedOnce ( ipcMain , 'pong' )
90103 } )
91104
105+ it ( 'works with contextIsolation + sandbox' , async ( ) => {
106+ const w = await openTheWindow ( {
107+ show : false ,
108+ webPreferences : {
109+ webviewTag : true ,
110+ nodeIntegration : true ,
111+ contextIsolation : true ,
112+ sandbox : true
113+ }
114+ } )
115+ w . loadFile ( path . join ( fixtures , 'pages' , 'webview-isolated.html' ) )
116+ await emittedOnce ( ipcMain , 'pong' )
117+ } )
118+
92119 it ( 'is disabled by default' , async ( ) => {
93120 const w = await openTheWindow ( {
94121 show : false ,
@@ -1349,47 +1376,56 @@ describe('<webview> tag', function () {
13491376 if ( div != null ) div . remove ( )
13501377 } )
13511378
1352- it ( 'emits resize events' , async ( ) => {
1353- const firstResizeSignal = waitForEvent ( webview , 'resize' )
1354- const domReadySignal = waitForEvent ( webview , 'dom-ready' )
1379+ const generateSpecs = ( description , sandbox ) => {
1380+ describe ( description , ( ) => {
1381+ it ( 'emits resize events' , async ( ) => {
1382+ const firstResizeSignal = waitForEvent ( webview , 'resize' )
1383+ const domReadySignal = waitForEvent ( webview , 'dom-ready' )
13551384
1356- webview . src = `file://${ fixtures } /pages/a.html`
1357- div . appendChild ( webview )
1358- document . body . appendChild ( div )
1385+ webview . src = `file://${ fixtures } /pages/a.html`
1386+ webview . webpreferences = `sandbox=${ sandbox ? 'yes' : 'no' } `
1387+ div . appendChild ( webview )
1388+ document . body . appendChild ( div )
13591389
1360- const firstResizeEvent = await firstResizeSignal
1361- expect ( firstResizeEvent . target ) . to . equal ( webview )
1362- expect ( firstResizeEvent . newWidth ) . to . equal ( 100 )
1363- expect ( firstResizeEvent . newHeight ) . to . equal ( 10 )
1390+ const firstResizeEvent = await firstResizeSignal
1391+ expect ( firstResizeEvent . target ) . to . equal ( webview )
1392+ expect ( firstResizeEvent . newWidth ) . to . equal ( 100 )
1393+ expect ( firstResizeEvent . newHeight ) . to . equal ( 10 )
13641394
1365- await domReadySignal
1395+ await domReadySignal
13661396
1367- const secondResizeSignal = waitForEvent ( webview , 'resize' )
1397+ const secondResizeSignal = waitForEvent ( webview , 'resize' )
13681398
1369- const newWidth = 1234
1370- const newHeight = 789
1371- div . style . width = `${ newWidth } px`
1372- div . style . height = `${ newHeight } px`
1399+ const newWidth = 1234
1400+ const newHeight = 789
1401+ div . style . width = `${ newWidth } px`
1402+ div . style . height = `${ newHeight } px`
13731403
1374- const secondResizeEvent = await secondResizeSignal
1375- expect ( secondResizeEvent . target ) . to . equal ( webview )
1376- expect ( secondResizeEvent . newWidth ) . to . equal ( newWidth )
1377- expect ( secondResizeEvent . newHeight ) . to . equal ( newHeight )
1378- } )
1404+ const secondResizeEvent = await secondResizeSignal
1405+ expect ( secondResizeEvent . target ) . to . equal ( webview )
1406+ expect ( secondResizeEvent . newWidth ) . to . equal ( newWidth )
1407+ expect ( secondResizeEvent . newHeight ) . to . equal ( newHeight )
1408+ } )
13791409
1380- it ( 'emits focus event' , async ( ) => {
1381- const domReadySignal = waitForEvent ( webview , 'dom-ready' )
1382- webview . src = `file://${ fixtures } /pages/a.html`
1383- document . body . appendChild ( webview )
1410+ it ( 'emits focus event' , async ( ) => {
1411+ const domReadySignal = waitForEvent ( webview , 'dom-ready' )
1412+ webview . src = `file://${ fixtures } /pages/a.html`
1413+ webview . webpreferences = `sandbox=${ sandbox ? 'yes' : 'no' } `
1414+ document . body . appendChild ( webview )
13841415
1385- await domReadySignal
1416+ await domReadySignal
13861417
1387- // If this test fails, check if webview.focus() still works.
1388- const focusSignal = waitForEvent ( webview , 'focus' )
1389- webview . focus ( )
1418+ // If this test fails, check if webview.focus() still works.
1419+ const focusSignal = waitForEvent ( webview , 'focus' )
1420+ webview . focus ( )
13901421
1391- await focusSignal
1392- } )
1422+ await focusSignal
1423+ } )
1424+ } )
1425+ }
1426+
1427+ generateSpecs ( 'without sandbox' , false )
1428+ generateSpecs ( 'with sandbox' , true )
13931429 } )
13941430
13951431 describe ( 'zoom behavior' , ( ) => {
0 commit comments