add basic webview zoom specs

This commit is contained in:
deepak1556 2017-02-17 21:18:30 +05:30
parent c71b44048c
commit 403e7681c1
4 changed files with 66 additions and 19 deletions

View file

@ -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'
]

View file

@ -0,0 +1,23 @@
<html>
<body>
<webview nodeintegration src="a.html" id="view"/>
</body>
<script>
const {ipcRenderer, webFrame} = require('electron')
const view = document.getElementById('view')
let finalNavigation = false
view.addEventListener('dom-ready', () => {
if (!finalNavigation)
view.setZoomLevel(2.0)
view.getZoomLevel((zoomLevel) => {
view.getZoomFactor((zoomFactor) => {
ipcRenderer.send('webview-zoom-level', zoomLevel, zoomFactor, finalNavigation)
if (!finalNavigation) {
finalNavigation = true
view.src = 'b.html'
}
})
})
})
</script>
</html>

View file

@ -2,7 +2,7 @@
<body>
<script type="text/javascript" charset="utf-8">
const {ipcRenderer, webFrame} = require('electron')
ipcRenderer.send('pong', webFrame.getZoomFactor(), webFrame.getZoomLevel())
ipcRenderer.send('webview-zoom-level', webFrame.getZoomFactor(), webFrame.getZoomLevel())
</script>
</body>
</html>

View file

@ -1067,21 +1067,6 @@ describe('<webview> 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('<webview> 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`)
})
})
})