Add specs for content type on POST forms

This commit is contained in:
Kevin Sawicki 2016-11-11 10:13:06 -08:00
parent 50019f39e9
commit 134f8afbe6

View file

@ -8,16 +8,11 @@ const qs = require('querystring')
const http = require('http') const http = require('http')
const {closeWindow} = require('./window-helpers') const {closeWindow} = require('./window-helpers')
const remote = require('electron').remote const {ipcRenderer, remote, screen} = require('electron')
const screen = require('electron').screen const {app, ipcMain, BrowserWindow} = remote.require('electron')
const {protocol, session} = remote
const app = remote.require('electron').app
const ipcMain = remote.require('electron').ipcMain
const ipcRenderer = require('electron').ipcRenderer
const BrowserWindow = remote.require('electron').BrowserWindow
const isCI = remote.getGlobal('isCi') const isCI = remote.getGlobal('isCi')
const {protocol} = remote
describe('browser-window module', function () { describe('browser-window module', function () {
var fixtures = path.resolve(__dirname, 'fixtures') var fixtures = path.resolve(__dirname, 'fixtures')
@ -225,9 +220,52 @@ describe('browser-window module', function () {
w.loadURL('http://127.0.0.1:11111') w.loadURL('http://127.0.0.1:11111')
}) })
it('can initiate POST navigation', function (done) { describe('POST navigations', function () {
w.webContents.on('did-finish-load', () => done()) afterEach(() => {
w.loadURL(server.url, {postData: postData}) 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)
})
}) })
}) })