Add specs for content type on POST forms
This commit is contained in:
parent
50019f39e9
commit
134f8afbe6
1 changed files with 49 additions and 11 deletions
|
@ -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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue