From 1e9942c1bf440ad83f13401070c4423c2159cf55 Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Ali Date: Fri, 20 Oct 2017 08:46:41 +0200 Subject: [PATCH] Fix js coding style errors --- spec/chromium-spec.js | 76 +++++++++---------- .../preload-pdf-loaded-in-nested-subframe.js | 23 +++--- .../module/preload-pdf-loaded-in-subframe.js | 11 ++- 3 files changed, 50 insertions(+), 60 deletions(-) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index bb4027853c3f..b8184d79e407 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -991,11 +991,8 @@ describe('chromium feature', function () { protocol: 'file', slashes: true }) - - - - function createBrowserWindow ({plugins,preload}) { + function createBrowserWindow ({plugins, preload}) { w = new BrowserWindow({ show: false, webPreferences: { @@ -1004,34 +1001,31 @@ describe('chromium feature', function () { } }) } - - - - 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) - } - - + + 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,preload:'preload-pdf-loaded.js'}) + createBrowserWindow({plugins: true, preload: 'preload-pdf-loaded.js'}) ipcMain.once('pdf-loaded', function (event, state) { assert.equal(state, 'success') done() @@ -1047,7 +1041,7 @@ describe('chromium feature', function () { }) 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) { assert.equal(state, 'success') done() @@ -1065,7 +1059,7 @@ describe('chromium feature', function () { }) 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.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) { 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) { - createBrowserWindow({plugins: true,preload:'preload-pdf-loaded.js'}) + createBrowserWindow({plugins: true, preload: 'preload-pdf-loaded.js'}) webFrame.registerURLSchemeAsPrivileged('file', { secure: false, bypassCSP: false, @@ -1093,16 +1087,14 @@ 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 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) + + 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 () { diff --git a/spec/fixtures/module/preload-pdf-loaded-in-nested-subframe.js b/spec/fixtures/module/preload-pdf-loaded-in-nested-subframe.js index cba1d012aeac..e38b3658429f 100644 --- a/spec/fixtures/module/preload-pdf-loaded-in-nested-subframe.js +++ b/spec/fixtures/module/preload-pdf-loaded-in-nested-subframe.js @@ -1,16 +1,15 @@ const {ipcRenderer} = require('electron') -document.addEventListener("DOMContentLoaded", function(event) { - var outerFrame = document.getElementById('outer-frame'); +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) - }); - } - } + 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) + }) + } + } } -}); - +}) diff --git a/spec/fixtures/module/preload-pdf-loaded-in-subframe.js b/spec/fixtures/module/preload-pdf-loaded-in-subframe.js index aa027eaf66b7..c2b7de21c898 100644 --- a/spec/fixtures/module/preload-pdf-loaded-in-subframe.js +++ b/spec/fixtures/module/preload-pdf-loaded-in-subframe.js @@ -1,11 +1,10 @@ const {ipcRenderer} = require('electron') -document.addEventListener("DOMContentLoaded", function(event) { - var subframe = document.getElementById('pdf-frame'); +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) - }); + ipcRenderer.send('pdf-loaded', event.detail) + }) } -}); - +})