diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index d7a894cce4fd..448d2556a1bb 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -496,7 +496,7 @@ describe('webContents module', function () { }) }) ipcMain.once('temporary-zoom-set', (e, zoomLevel) => { - w2.loadURL(`file://${fixtures}/pages/a.html`) + w2.loadURL(`file://${fixtures}/pages/c.html`) finalZoomLevel = zoomLevel }) w.loadURL(`file://${fixtures}/pages/webframe-zoom.html`) @@ -521,10 +521,10 @@ describe('webContents module', function () { }) ipcMain.once('zoom-level-set', (e, zoomLevel) => { assert.equal(zoomLevel, 0.6) - w.loadURL(`file://${fixtures}/pages/b.html`) + w.loadURL(`file://${fixtures}/pages/d.html`) initialNavigation = false }) - w.loadURL(`file://${fixtures}/pages/a.html`) + w.loadURL(`file://${fixtures}/pages/c.html`) }) }) }) diff --git a/spec/fixtures/pages/webview-custom-zoom-level.html b/spec/fixtures/pages/webview-custom-zoom-level.html index 0598623a664f..24f246fdd292 100644 --- a/spec/fixtures/pages/webview-custom-zoom-level.html +++ b/spec/fixtures/pages/webview-custom-zoom-level.html @@ -1,20 +1,23 @@ - + + diff --git a/spec/fixtures/pages/zoom-factor.html b/spec/fixtures/pages/zoom-factor.html index 4c04e38f3a66..c27b5ea495a4 100644 --- a/spec/fixtures/pages/zoom-factor.html +++ b/spec/fixtures/pages/zoom-factor.html @@ -2,7 +2,7 @@ diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 40e6a8bffd39..027a3a952006 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -1527,6 +1527,21 @@ describe(' tag', function () { }) describe('zoom behavior', () => { + const zoomScheme = remote.getGlobal('zoomScheme') + const webviewSession = session.fromPartition('webview-temp') + + before((done) => { + const protocol = webviewSession.protocol + protocol.registerStringProtocol(zoomScheme, (request, callback) => { + callback('hello') + }, (error) => done(error)) + }) + + after((done) => { + const protocol = webviewSession.protocol + protocol.unregisterProtocol(zoomScheme, (error) => done(error)) + }) + it('inherits the zoomFactor of the parent window', (done) => { w = new BrowserWindow({ show: false, @@ -1534,7 +1549,7 @@ describe(' tag', function () { zoomFactor: 1.2 } }) - ipcMain.once('webview-zoom-level', (event, zoomFactor, zoomLevel) => { + ipcMain.once('webview-parent-zoom-level', (event, zoomFactor, zoomLevel) => { assert.equal(zoomFactor, 1.2) assert.equal(zoomLevel, 1) done() @@ -1542,24 +1557,39 @@ describe(' tag', function () { w.loadURL(`file://${fixtures}/pages/webview-zoom-factor.html`) }) - it('inherits the zoomLevel of parent window on navigation', (done) => { + it('maintains zoom level on navigation', (done) => { w = new BrowserWindow({ show: false, webPreferences: { zoomFactor: 1.2 } }) - ipcMain.on('webview-zoom-level', (event, zoomLevel, zoomFactor, final) => { - if (!final) { + ipcMain.on('webview-zoom-level', (event, zoomLevel, zoomFactor, newHost, final) => { + if (!newHost) { assert.equal(zoomFactor, 1.44) assert.equal(zoomLevel, 2.0) } else { assert.equal(zoomFactor, 1.2) assert.equal(zoomLevel, 1) - done() } + if (final) done() }) w.loadURL(`file://${fixtures}/pages/webview-custom-zoom-level.html`) }) + + it('maintains zoom level when navigating within same page', (done) => { + w = new BrowserWindow({ + show: false, + webPreferences: { + zoomFactor: 1.2 + } + }) + ipcMain.on('webview-zoom-in-page', (event, zoomLevel, zoomFactor, final) => { + assert.equal(zoomFactor, 1.44) + assert.equal(zoomLevel, 2.0) + if (final) done() + }) + w.loadURL(`file://${fixtures}/pages/webview-in-page-navigate.html`) + }) }) })