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