move protocol to session properties for working with partitions

This commit is contained in:
deepak1556 2016-06-08 20:01:27 +05:30
parent 0e0235407b
commit aa853dd3be
6 changed files with 74 additions and 13 deletions

View file

@ -16,8 +16,15 @@ describe('session module', function () {
var fixtures = path.resolve(__dirname, 'fixtures')
var w = null
var url = 'http://127.0.0.1'
var partitionName = 'temp'
var protocolName = 'sp'
const tempProtocol = session.fromPartition(partitionName).protocol
const protocol = session.defaultSession.protocol
beforeEach(function () {
if (w != null) {
w.destroy()
}
w = new BrowserWindow({
show: false,
width: 400,
@ -26,7 +33,10 @@ describe('session module', function () {
})
afterEach(function () {
w.destroy()
if (w != null) {
w.destroy()
}
w = null
})
describe('session.cookies', function () {
@ -262,4 +272,50 @@ describe('session module', function () {
})
})
})
describe('session.protocol', function () {
beforeEach(function () {
if (w != null) {
w.destroy()
}
w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
partition: partitionName
}
})
})
afterEach(function () {
if (w != null) {
w.destroy()
}
w = null
})
it('handles requests from a partition', function (done) {
var handler = function (error, callback) {
callback({
data: 'test'
})
}
tempProtocol.registerStringProtocol(protocolName, handler, function (error) {
if (error) {
return done(error)
}
protocol.isProtocolHandled(protocolName, function (result) {
assert.equal(result, false)
tempProtocol.isProtocolHandled(protocolName, function (result) {
assert.equal(result, true)
w.webContents.on('did-finish-load', function () {
done()
})
w.loadURL(protocolName + "://fake-host")
})
})
})
})
})
})