From ad5f944185c749f74b2301f151af10583432e301 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 12 Oct 2016 22:56:53 +0530 Subject: [PATCH] add spec --- .../content_converter.cc | 3 +- spec/api-browser-window-spec.js | 46 ++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/atom/common/native_mate_converters/content_converter.cc b/atom/common/native_mate_converters/content_converter.cc index 8646ec99eb60..e70c65699c43 100644 --- a/atom/common/native_mate_converters/content_converter.cc +++ b/atom/common/native_mate_converters/content_converter.cc @@ -254,7 +254,8 @@ bool Converter>::FromV8( for (int i = 0; i < list->GetSize(); ++i) { base::DictionaryValue* dict = nullptr; std::string type; - list->GetDictionary(i, &dict); + if (!list->GetDictionary(i, &dict)) + return false; dict->GetString("type", &type); if (type == "data") { base::BinaryValue* bytes = nullptr; diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index b81ec2f790d6..f4bb529b605c 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -4,6 +4,7 @@ const assert = require('assert') const fs = require('fs') const path = require('path') const os = require('os') +const qs = require('querystring') const http = require('http') const {closeWindow} = require('./window-helpers') @@ -21,11 +22,47 @@ const {protocol} = remote describe('browser-window module', function () { var fixtures = path.resolve(__dirname, 'fixtures') var w = null - var server + var server, postData before(function (done) { + const filePath = path.join(fixtures, 'pages', 'a.html') + const fileStats = fs.statSync(filePath) + postData = [ + { + 'type': 'data', + 'bytes': new Buffer('username=test&file=') + }, + { + 'type': 'file', + 'filePath': filePath, + 'offset': 0, + 'length': fileStats.size, + 'modificationTime': fileStats.mtime.getTime() / 1000 + } + ] server = http.createServer(function (req, res) { - function respond () { res.end('') } + function respond () { + if (req.method === 'POST') { + let body = '' + req.on('data', (data) => { + if (data) { + body += data + } + }) + req.on('end', () => { + let parsedData = qs.parse(body) + fs.readFile(filePath, (err, data) => { + if (err) return + if (parsedData.username === 'test' && + parsedData.file === data.toString()) { + res.end() + } + }) + }) + } else { + res.end() + } + } setTimeout(respond, req.url.includes('slow') ? 200 : 0) }) server.listen(0, '127.0.0.1', function () { @@ -187,6 +224,11 @@ 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('BrowserWindow.show()', function () {