Fix js coding style errors

This commit is contained in:
Ahmed Mohamed Ali 2017-10-20 08:46:41 +02:00
parent 9f3cfa2dbd
commit 1e9942c1bf
3 changed files with 50 additions and 60 deletions

View file

@ -991,11 +991,8 @@ describe('chromium feature', function () {
protocol: 'file', protocol: 'file',
slashes: true slashes: true
}) })
function createBrowserWindow ({plugins,preload}) { function createBrowserWindow ({plugins, preload}) {
w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
@ -1004,34 +1001,31 @@ describe('chromium feature', function () {
} }
}) })
} }
function testPDFIsLoadedInSubFrame (page, preloadFile, done) {
const pagePath = url.format({
function testPDFIsLoadedInSubFrame(page,preloadFile,done) { pathname: path.join(fixtures, 'pages', page).replace(/\\/g, '/'),
const pagePath = url.format({ protocol: 'file',
pathname: path.join(fixtures, 'pages',page ).replace(/\\/g, '/'), slashes: true
protocol: 'file', })
slashes: true
}) createBrowserWindow({plugins: true, preload: preloadFile})
ipcMain.once('pdf-loaded', function (event, state) {
createBrowserWindow({plugins: true,preload:preloadFile}) assert.equal(state, 'success')
ipcMain.once('pdf-loaded', function (event, state) { done()
assert.equal(state, 'success') })
done() w.webContents.on('page-title-updated', function () {
}) const parsedURL = url.parse(w.webContents.getURL(), true)
w.webContents.on('page-title-updated', function () { assert.equal(parsedURL.protocol, 'chrome:')
const parsedURL = url.parse(w.webContents.getURL(), true) assert.equal(parsedURL.hostname, 'pdf-viewer')
assert.equal(parsedURL.protocol, 'chrome:') assert.equal(parsedURL.query.src, pagePath)
assert.equal(parsedURL.hostname, 'pdf-viewer') assert.equal(w.webContents.getTitle(), 'cat.pdf')
assert.equal(parsedURL.query.src, pagePath) })
assert.equal(w.webContents.getTitle(), 'cat.pdf') w.webContents.loadURL(pagePath)
}) }
w.webContents.loadURL(pagePath)
}
it('opens when loading a pdf resource as top level navigation', function (done) { it('opens when loading a pdf resource as top level navigation', function (done) {
createBrowserWindow({plugins: true,preload:'preload-pdf-loaded.js'}) createBrowserWindow({plugins: true, preload: 'preload-pdf-loaded.js'})
ipcMain.once('pdf-loaded', function (event, state) { ipcMain.once('pdf-loaded', function (event, state) {
assert.equal(state, 'success') assert.equal(state, 'success')
done() done()
@ -1047,7 +1041,7 @@ describe('chromium feature', function () {
}) })
it('opens a pdf link given params, the query string should be escaped', function (done) { it('opens a pdf link given params, the query string should be escaped', function (done) {
createBrowserWindow({plugins: true,preload:'preload-pdf-loaded.js'}) createBrowserWindow({plugins: true, preload: 'preload-pdf-loaded.js'})
ipcMain.once('pdf-loaded', function (event, state) { ipcMain.once('pdf-loaded', function (event, state) {
assert.equal(state, 'success') assert.equal(state, 'success')
done() done()
@ -1065,7 +1059,7 @@ describe('chromium feature', function () {
}) })
it('should download a pdf when plugins are disabled', function (done) { it('should download a pdf when plugins are disabled', function (done) {
createBrowserWindow({plugins: false,preload:'preload-pdf-loaded.js'}) createBrowserWindow({plugins: false, preload: 'preload-pdf-loaded.js'})
ipcRenderer.sendSync('set-download-option', false, false) ipcRenderer.sendSync('set-download-option', false, false)
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) { ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
assert.equal(state, 'completed') assert.equal(state, 'completed')
@ -1078,7 +1072,7 @@ describe('chromium feature', function () {
}) })
it('should not open when pdf is requested as sub resource', function (done) { it('should not open when pdf is requested as sub resource', function (done) {
createBrowserWindow({plugins: true,preload:'preload-pdf-loaded.js'}) createBrowserWindow({plugins: true, preload: 'preload-pdf-loaded.js'})
webFrame.registerURLSchemeAsPrivileged('file', { webFrame.registerURLSchemeAsPrivileged('file', {
secure: false, secure: false,
bypassCSP: false, bypassCSP: false,
@ -1093,16 +1087,14 @@ describe('chromium feature', function () {
done(e) done(e)
}) })
}) })
it('opens when loading a pdf resource in a iframe', function (done) { it('opens when loading a pdf resource in a iframe', function (done) {
testPDFIsLoadedInSubFrame('pdf-in-iframe.html','preload-pdf-loaded-in-subframe.js',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) { 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) testPDFIsLoadedInSubFrame('pdf-in-nested-iframe.html', 'preload-pdf-loaded-in-nested-subframe.js', done)
}) })
}) })
describe('window.alert(message, title)', function () { describe('window.alert(message, title)', function () {

View file

@ -1,16 +1,15 @@
const {ipcRenderer} = require('electron') const {ipcRenderer} = require('electron')
document.addEventListener("DOMContentLoaded", function(event) { document.addEventListener('DOMContentLoaded', function (event) {
var outerFrame = document.getElementById('outer-frame'); var outerFrame = document.getElementById('outer-frame')
if (outerFrame) { if (outerFrame) {
outerFrame.onload = function() { outerFrame.onload = function () {
var pdframe = outerFrame.contentWindow.document.getElementById('pdf-frame'); var pdframe = outerFrame.contentWindow.document.getElementById('pdf-frame')
if (pdframe) { if (pdframe) {
pdframe.contentWindow.addEventListener('pdf-loaded', function (event) { pdframe.contentWindow.addEventListener('pdf-loaded', function (event) {
ipcRenderer.send('pdf-loaded', event.detail) ipcRenderer.send('pdf-loaded', event.detail)
}); })
} }
} }
} }
}); })

View file

@ -1,11 +1,10 @@
const {ipcRenderer} = require('electron') const {ipcRenderer} = require('electron')
document.addEventListener("DOMContentLoaded", function(event) { document.addEventListener('DOMContentLoaded', function (event) {
var subframe = document.getElementById('pdf-frame'); var subframe = document.getElementById('pdf-frame')
if (subframe) { if (subframe) {
subframe.contentWindow.addEventListener('pdf-loaded', function (event) { subframe.contentWindow.addEventListener('pdf-loaded', function (event) {
ipcRenderer.send('pdf-loaded', event.detail) ipcRenderer.send('pdf-loaded', event.detail)
}); })
} }
}); })