diff --git a/lib/renderer/web-view/web-view.js b/lib/renderer/web-view/web-view.js index c98b02d2744a..5e5a10cb004f 100644 --- a/lib/renderer/web-view/web-view.js +++ b/lib/renderer/web-view/web-view.js @@ -374,7 +374,11 @@ var registerWebViewElement = function () { 'print', 'printToPDF', 'showDefinitionForSelection', - 'capturePage' + 'capturePage', + 'setZoomFactor', + 'setZoomLevel', + 'getZoomLevel', + 'getZoomFactor' ] const nonblockMethods = [ 'insertCSS', @@ -383,8 +387,6 @@ var registerWebViewElement = function () { 'sendInputEvent', 'setLayoutZoomLevelLimits', 'setVisualZoomLevelLimits', - 'setZoomFactor', - 'setZoomLevel', // TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings 'setZoomLevelLimits' ] diff --git a/spec/fixtures/pages/webview-custom-zoom-level.html b/spec/fixtures/pages/webview-custom-zoom-level.html new file mode 100644 index 000000000000..0598623a664f --- /dev/null +++ b/spec/fixtures/pages/webview-custom-zoom-level.html @@ -0,0 +1,23 @@ + + + + + + diff --git a/spec/fixtures/pages/zoom-factor.html b/spec/fixtures/pages/zoom-factor.html index b9f8f988caea..4c04e38f3a66 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 c6b69310a8ba..40e6a8bffd39 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -1067,21 +1067,6 @@ describe(' tag', function () { }) }) - it('inherits the zoomFactor of the parent window', function (done) { - w = new BrowserWindow({ - show: false, - webPreferences: { - zoomFactor: 1.2 - } - }) - ipcMain.once('pong', function (event, zoomFactor, zoomLevel) { - assert.equal(zoomFactor, 1.2) - assert.equal(zoomLevel, 1) - done() - }) - w.loadURL('file://' + fixtures + '/pages/webview-zoom-factor.html') - }) - it('inherits the parent window visibility state and receives visibilitychange events', function (done) { w = new BrowserWindow({ show: false @@ -1540,4 +1525,41 @@ describe(' tag', function () { }) }) }) + + describe('zoom behavior', () => { + it('inherits the zoomFactor of the parent window', (done) => { + w = new BrowserWindow({ + show: false, + webPreferences: { + zoomFactor: 1.2 + } + }) + ipcMain.once('webview-zoom-level', (event, zoomFactor, zoomLevel) => { + assert.equal(zoomFactor, 1.2) + assert.equal(zoomLevel, 1) + done() + }) + w.loadURL(`file://${fixtures}/pages/webview-zoom-factor.html`) + }) + + it('inherits the zoomLevel of parent window on navigation', (done) => { + w = new BrowserWindow({ + show: false, + webPreferences: { + zoomFactor: 1.2 + } + }) + ipcMain.on('webview-zoom-level', (event, zoomLevel, zoomFactor, final) => { + if (!final) { + assert.equal(zoomFactor, 1.44) + assert.equal(zoomLevel, 2.0) + } else { + assert.equal(zoomFactor, 1.2) + assert.equal(zoomLevel, 1) + done() + } + }) + w.loadURL(`file://${fixtures}/pages/webview-custom-zoom-level.html`) + }) + }) })