Merge pull request #6198 from electron/fix-session-protocol-test

Split the session.protocol test into multiple tests
This commit is contained in:
Cheng Zhao 2016-06-23 04:49:06 +00:00 committed by GitHub
commit d313639bbb

View file

@ -16,10 +16,6 @@ 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 partitionProtocol = session.fromPartition(partitionName).protocol
const protocol = session.defaultSession.protocol
beforeEach(function () {
if (w != null) {
@ -274,45 +270,46 @@ describe('session module', function () {
})
describe('session.protocol', function () {
beforeEach(function () {
if (w != null) {
w.destroy()
}
const partitionName = 'temp'
const protocolName = 'sp'
const partitionProtocol = session.fromPartition(partitionName).protocol
const protocol = session.defaultSession.protocol
const handler = function (error, callback) {
callback({data: 'test', mimeType: 'text/html'})
}
beforeEach(function (done) {
if (w != null) w.destroy()
w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
partition: partitionName
}
})
partitionProtocol.registerStringProtocol(protocolName, handler, function (error) {
done(error ? error : undefined)
})
})
afterEach(function (done) {
partitionProtocol.unregisterProtocol(protocolName, () => done())
})
it('handles requests from a partition', function (done) {
var handler = function (error, callback) {
callback({
data: 'test'
})
}
partitionProtocol.registerStringProtocol(protocolName, handler, function (error) {
if (error) {
return done(error)
}
protocol.isProtocolHandled(protocolName, function (result) {
assert.equal(result, false)
partitionProtocol.isProtocolHandled(protocolName, function (result) {
assert.equal(result, true)
w.webContents.on('did-finish-load', function () {
done()
})
w.loadURL(protocolName + "://fake-host")
})
it('does not affect defaultSession', function (done) {
protocol.isProtocolHandled(protocolName, function (result) {
assert.equal(result, false)
partitionProtocol.isProtocolHandled(protocolName, function (result) {
assert.equal(result, true)
done()
})
})
})
it('handles requests from partition', function (done) {
w.webContents.on('did-finish-load', function () {
done()
})
w.loadURL(`${protocolName}://fake-host`)
})
})
})