Update cookies spec.

This commit is contained in:
Haojian Wu 2015-06-20 10:42:18 +08:00
parent bafbee805c
commit db23d1165c

View file

@ -7,7 +7,7 @@ BrowserWindow = remote.require 'browser-window'
describe 'cookies module', ->
fixtures = path.resolve __dirname, 'fixtures'
w = null
url = "http://127.0.0.1:9999"
url = "http://127.0.0.1"
beforeEach -> w = new BrowserWindow(show: true)
afterEach -> w.destroy()
@ -17,12 +17,14 @@ describe 'cookies module', ->
console.log req
res.setHeader('Set-Cookie', ['type=dummy'])
res.end('finished')
server.close()
server.listen 9999, '127.0.0.1', ->
port = remote.process.port
server.listen port, '127.0.0.1', ->
{port} = server.address()
w.loadUrl url
w.loadUrl "#{url}:#{port}"
w.webContents.on 'did-finish-load', ()->
w.webContents.session.cookies.get {url:url}, (error, cookies) ->
w.webContents.session.cookies.get {url: url}, (error, cookies) ->
throw error if error
assert.equal 1, cookies.length
assert.equal 'type', cookies[0].name
@ -32,9 +34,9 @@ describe 'cookies module', ->
it 'should overwrite the existent cookie', (done) ->
w.loadUrl 'file://' + path.join(fixtures, 'page', 'a.html')
w.webContents.on 'did-finish-load', ()->
w.webContents.session.cookies.set {url:url, name:'type', value:'dummy2'}, (error) ->
w.webContents.session.cookies.set {url: url, name: 'type', value: 'dummy2'}, (error) ->
throw error if error
w.webContents.session.cookies.get {url:url}, (error, cookies_list) ->
w.webContents.session.cookies.get {url: url}, (error, cookies_list) ->
throw error if error
assert.equal 1, cookies_list.length
assert.equal 'type', cookies_list[0].name
@ -44,9 +46,9 @@ describe 'cookies module', ->
it 'should set new cookie', (done) ->
w.loadUrl 'file://' + path.join(fixtures, 'page', 'a.html')
w.webContents.on 'did-finish-load', ()->
w.webContents.session.cookies.set {url:url, name:'key', value:'dummy2'}, (error) ->
w.webContents.session.cookies.set {url: url, name: 'key', value: 'dummy2'}, (error) ->
throw error if error
w.webContents.session.cookies.get {url:url}, (error, cookies_list) ->
w.webContents.session.cookies.get {url: url}, (error, cookies_list) ->
throw error if error
assert.equal 2, cookies_list.length
for cookie in cookies_list
@ -57,14 +59,14 @@ describe 'cookies module', ->
it 'should remove cookies', (done) ->
w.loadUrl 'file://' + path.join(fixtures, 'page', 'a.html')
w.webContents.on 'did-finish-load', ()->
w.webContents.session.cookies.get {url:url}, (error, cookies_list) ->
w.webContents.session.cookies.get {url: url}, (error, cookies_list) ->
count = 0
for cookie in cookies_list
w.webContents.session.cookies.remove {url:url, name:cookie.name}, (error) ->
w.webContents.session.cookies.remove {url: url, name: cookie.name}, (error) ->
throw error if error
++count
if count == cookies_list.length
w.webContents.session.cookies.get {url:url}, (error, cookies_list) ->
w.webContents.session.cookies.get {url: url}, (error, cookies_list) ->
throw error if error
assert.equal 0, cookies_list.length
done()