diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 1214e0817492..84f2b92c627e 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -8,16 +8,11 @@ const qs = require('querystring') const http = require('http') const {closeWindow} = require('./window-helpers') -const remote = require('electron').remote -const screen = require('electron').screen - -const app = remote.require('electron').app -const ipcMain = remote.require('electron').ipcMain -const ipcRenderer = require('electron').ipcRenderer -const BrowserWindow = remote.require('electron').BrowserWindow +const {ipcRenderer, remote, screen} = require('electron') +const {app, ipcMain, BrowserWindow} = remote.require('electron') +const {protocol, session} = remote const isCI = remote.getGlobal('isCi') -const {protocol} = remote describe('browser-window module', function () { var fixtures = path.resolve(__dirname, 'fixtures') @@ -225,9 +220,52 @@ describe('browser-window module', function () { w.loadURL('http://127.0.0.1:11111') }) - it('can initiate POST navigation', function (done) { - w.webContents.on('did-finish-load', () => done()) - w.loadURL(server.url, {postData: postData}) + describe('POST navigations', function () { + afterEach(() => { + w.webContents.session.webRequest.onBeforeSendHeaders(null) + }) + + it('supports specifying POST data', function (done) { + w.webContents.on('did-finish-load', () => done()) + w.loadURL(server.url, {postData: postData}) + }) + + it('sets the content type header on URL encoded forms', function (done) { + w.webContents.on('did-finish-load', () => { + w.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => { + assert.equal(details.requestHeaders['content-type'], 'application/x-www-form-urlencoded') + done() + }) + w.webContents.executeJavaScript(` + form = document.createElement('form') + form.method = 'POST' + form.target = '_blank' + form.submit() + `) + }) + w.loadURL(server.url) + }) + + it('sets the content type header on multi part forms', function (done) { + w.webContents.on('did-finish-load', () => { + w.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => { + assert(details.requestHeaders['content-type'].startsWith('multipart/form-data; boundary=----WebKitFormBoundary')) + done() + }) + w.webContents.executeJavaScript(` + form = document.createElement('form') + form.method = 'POST' + form.target = '_blank' + form.enctype = 'multipart/form-data' + file = document.createElement('input') + file.type = 'file' + file.name = 'file' + form.appendChild(file) + form.submit() + `) + }) + w.loadURL(server.url) + }) }) })