From: deepak1556 Date: Sun, 29 May 2016 08:13:26 +0000 (+0530) Subject: add spec X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d8af43617ed1dcdf3efc7121c3a916713805304;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git add spec --- 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 () {