From 9d8af43617ed1dcdf3efc7121c3a916713805304 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sun, 29 May 2016 13:43:26 +0530 Subject: [PATCH] add spec --- spec/api-protocol-spec.js | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/spec/api-protocol-spec.js b/spec/api-protocol-spec.js index 2a1d158..1b46d58 100644 --- a/spec/api-protocol-spec.js +++ b/spec/api-protocol-spec.js @@ -3,8 +3,7 @@ const http = require('http') const path = require('path') const qs = require('querystring') const remote = require('electron').remote -const BrowserWindow = remote.require('electron').BrowserWindow -const protocol = remote.require('electron').protocol +const {BrowserWindow, protocol, webContents} = remote describe('protocol module', function () { var protocolName = 'sp' @@ -511,6 +510,42 @@ describe('protocol module', function () { }) }) }) + + it('loads resource for webContents', function (done) { + var contents = null + var server = http.createServer(function (req, res) { + if (req.url == '/serverRedirect') { + res.statusCode = 301 + res.setHeader('Location', 'http://' + req.rawHeaders[1]) + res.end() + } else { + res.end(text) + } + }) + server.listen(0, '127.0.0.1', function () { + var port = server.address().port + var url = `${protocolName}://fake-host` + var redirectURL = `http://127.0.0.1:${port}/serverRedirect` + var handler = function (request, callback) { + callback({ + url: redirectURL + }) + } + protocol.registerHttpProtocol(protocolName, handler, function (error) { + if (error) { + return done(error) + } + contents = webContents.create({}) + contents.on('did-finish-load', function () { + assert.equal(contents.getURL(), url) + server.close() + contents.destroy() + done() + }) + contents.loadURL(url) + }) + }) + }) }) describe('protocol.isProtocolHandled', function () { -- 2.7.4