From 71ab69314cc41706ce5ef880891df9157ec6207f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 23 Jun 2016 13:11:19 +0900 Subject: [PATCH] spec: Put protocol registration in beforeEach --- spec/api-session-spec.js | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/spec/api-session-spec.js b/spec/api-session-spec.js index 25a09ba..874726d 100644 --- a/spec/api-session-spec.js +++ b/spec/api-session-spec.js @@ -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,18 +270,25 @@ 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'}) + } + + 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) { @@ -293,24 +296,14 @@ describe('session module', function () { }) 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") + 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") }) }) }) -- 2.7.4