add basic webview zoom specs
This commit is contained in:
parent
c71b44048c
commit
403e7681c1
4 changed files with 66 additions and 19 deletions
|
@ -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'
|
||||
]
|
||||
|
|
23
spec/fixtures/pages/webview-custom-zoom-level.html
vendored
Normal file
23
spec/fixtures/pages/webview-custom-zoom-level.html
vendored
Normal 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>
|
2
spec/fixtures/pages/zoom-factor.html
vendored
2
spec/fixtures/pages/zoom-factor.html
vendored
|
@ -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>
|
||||
|
|
|
@ -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`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue