Add tests for fix described in #10793
This commit is contained in:
parent
05035eb1e3
commit
44f91e12e1
5 changed files with 87 additions and 7 deletions
|
@ -991,19 +991,47 @@ describe('chromium feature', function () {
|
|||
protocol: 'file',
|
||||
slashes: true
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
function createBrowserWindow ({plugins}) {
|
||||
function createBrowserWindow ({plugins,preload}) {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
preload: path.join(fixtures, 'module', 'preload-pdf-loaded.js'),
|
||||
preload: path.join(fixtures, 'module', preload),
|
||||
plugins: plugins
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function testPDFIsLoadedInSubFrame(page,preloadFile,done) {
|
||||
const pagePath = url.format({
|
||||
pathname: path.join(fixtures, 'pages',page ).replace(/\\/g, '/'),
|
||||
protocol: 'file',
|
||||
slashes: true
|
||||
})
|
||||
|
||||
createBrowserWindow({plugins: true,preload:preloadFile})
|
||||
ipcMain.once('pdf-loaded', function (event, state) {
|
||||
assert.equal(state, 'success')
|
||||
done()
|
||||
})
|
||||
w.webContents.on('page-title-updated', function () {
|
||||
const parsedURL = url.parse(w.webContents.getURL(), true)
|
||||
assert.equal(parsedURL.protocol, 'chrome:')
|
||||
assert.equal(parsedURL.hostname, 'pdf-viewer')
|
||||
assert.equal(parsedURL.query.src, pagePath)
|
||||
assert.equal(w.webContents.getTitle(), 'cat.pdf')
|
||||
})
|
||||
w.webContents.loadURL(pagePath)
|
||||
}
|
||||
|
||||
|
||||
it('opens when loading a pdf resource as top level navigation', function (done) {
|
||||
createBrowserWindow({plugins: true})
|
||||
createBrowserWindow({plugins: true,preload:'preload-pdf-loaded.js'})
|
||||
ipcMain.once('pdf-loaded', function (event, state) {
|
||||
assert.equal(state, 'success')
|
||||
done()
|
||||
|
@ -1019,7 +1047,7 @@ describe('chromium feature', function () {
|
|||
})
|
||||
|
||||
it('opens a pdf link given params, the query string should be escaped', function (done) {
|
||||
createBrowserWindow({plugins: true})
|
||||
createBrowserWindow({plugins: true,preload:'preload-pdf-loaded.js'})
|
||||
ipcMain.once('pdf-loaded', function (event, state) {
|
||||
assert.equal(state, 'success')
|
||||
done()
|
||||
|
@ -1037,7 +1065,7 @@ describe('chromium feature', function () {
|
|||
})
|
||||
|
||||
it('should download a pdf when plugins are disabled', function (done) {
|
||||
createBrowserWindow({plugins: false})
|
||||
createBrowserWindow({plugins: false,preload:'preload-pdf-loaded.js'})
|
||||
ipcRenderer.sendSync('set-download-option', false, false)
|
||||
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
||||
assert.equal(state, 'completed')
|
||||
|
@ -1050,7 +1078,7 @@ describe('chromium feature', function () {
|
|||
})
|
||||
|
||||
it('should not open when pdf is requested as sub resource', function (done) {
|
||||
createBrowserWindow({plugins: true})
|
||||
createBrowserWindow({plugins: true,preload:'preload-pdf-loaded.js'})
|
||||
webFrame.registerURLSchemeAsPrivileged('file', {
|
||||
secure: false,
|
||||
bypassCSP: false,
|
||||
|
@ -1065,6 +1093,16 @@ describe('chromium feature', function () {
|
|||
done(e)
|
||||
})
|
||||
})
|
||||
|
||||
it('opens when loading a pdf resource in a iframe', function (done) {
|
||||
testPDFIsLoadedInSubFrame('pdf-in-iframe.html','preload-pdf-loaded-in-subframe.js',done)
|
||||
})
|
||||
|
||||
it('opens when loading a pdf resource in a nested iframe', function (done) {
|
||||
testPDFIsLoadedInSubFrame('pdf-in-nested-iframe.html','preload-pdf-loaded-in-nested-subframe.js',done)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
describe('window.alert(message, title)', function () {
|
||||
|
|
16
spec/fixtures/module/preload-pdf-loaded-in-nested-subframe.js
vendored
Normal file
16
spec/fixtures/module/preload-pdf-loaded-in-nested-subframe.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
const {ipcRenderer} = require('electron')
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
var outerFrame = document.getElementById('outer-frame');
|
||||
if (outerFrame) {
|
||||
outerFrame.onload = function() {
|
||||
var pdframe = outerFrame.contentWindow.document.getElementById('pdf-frame');
|
||||
if (pdframe) {
|
||||
pdframe.contentWindow.addEventListener('pdf-loaded', function (event) {
|
||||
ipcRenderer.send('pdf-loaded', event.detail)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
11
spec/fixtures/module/preload-pdf-loaded-in-subframe.js
vendored
Normal file
11
spec/fixtures/module/preload-pdf-loaded-in-subframe.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
const {ipcRenderer} = require('electron')
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
var subframe = document.getElementById('pdf-frame');
|
||||
if (subframe) {
|
||||
subframe.contentWindow.addEventListener('pdf-loaded', function (event) {
|
||||
ipcRenderer.send('pdf-loaded', event.detail)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
8
spec/fixtures/pages/pdf-in-iframe.html
vendored
Normal file
8
spec/fixtures/pages/pdf-in-iframe.html
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<body>
|
||||
<iframe id="pdf-frame" src="../assets/cat.pdf"/>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
7
spec/fixtures/pages/pdf-in-nested-iframe.html
vendored
Normal file
7
spec/fixtures/pages/pdf-in-nested-iframe.html
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<html>
|
||||
<body>
|
||||
<iframe id='outer-frame' src="./pdf-in-iframe.html"/>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
Loading…
Reference in a new issue