No need to actually create a page for cookie test

This commit is contained in:
Cheng Zhao 2015-07-14 09:14:22 -07:00
parent 020ccd8018
commit 346fb745f2

View file

@ -2,6 +2,7 @@ assert = require 'assert'
remote = require 'remote' remote = require 'remote'
http = require 'http' http = require 'http'
path = require 'path' path = require 'path'
app = remote.require 'app'
BrowserWindow = remote.require 'browser-window' BrowserWindow = remote.require 'browser-window'
describe 'session module', -> describe 'session module', ->
@ -15,7 +16,7 @@ describe 'session module', ->
it 'should get cookies', (done) -> it 'should get cookies', (done) ->
server = http.createServer (req, res) -> server = http.createServer (req, res) ->
res.setHeader('Set-Cookie', ['type=dummy']) res.setHeader('Set-Cookie', ['0=0'])
res.end('finished') res.end('finished')
server.close() server.close()
@ -24,46 +25,35 @@ describe 'session module', ->
{port} = server.address() {port} = server.address()
w.loadUrl "#{url}:#{port}" w.loadUrl "#{url}:#{port}"
w.webContents.on 'did-finish-load', -> w.webContents.on 'did-finish-load', ->
w.webContents.session.cookies.get {url: url}, (error, cookies) -> w.webContents.session.cookies.get {url: url}, (error, list) ->
return done(error) if error return done(error) if error
assert.equal 'type', cookies[0].name for cookie in list when cookie.name is '0'
assert.equal 'dummy', cookies[0].value if cookie.value is '0'
done() return done()
else
return done("cookie value is #{cookie.value} while expecting 0")
done('Can not find cookie')
it 'should over-write the existent cookie', (done) -> it 'should over-write the existent cookie', (done) ->
w.loadUrl 'file://' + path.join(fixtures, 'page', 'a.html') app.defaultSession.cookies.set {url: url, name: '1', value: '1'}, (error) ->
w.webContents.on 'did-finish-load', ->
w.webContents.session.cookies.set {url: url, name: 'type', value: 'dummy2'}, (error) ->
return done(error) if error return done(error) if error
w.webContents.session.cookies.get {url: url}, (error, cookies_list) -> app.defaultSession.cookies.get {url: url}, (error, list) ->
return done(error) if error return done(error) if error
assert.equal 'type', cookies_list[0].name for cookie in list when cookie.name is '1'
assert.equal 'dummy2', cookies_list[0].value if cookie.value is '1'
done()
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) ->
return done(error) if error
w.webContents.session.cookies.get {url: url}, (error, cookies_list) ->
return done(error) if error
for cookie in cookies_list
if cookie.name is 'key'
assert.equal 'dummy2', cookie.value
return done() return done()
else
return done("cookie value is #{cookie.value} while expecting 1")
done('Can not find cookie') done('Can not find cookie')
it 'should remove cookies', (done) -> it 'should remove cookies', (done) ->
w.loadUrl 'file://' + path.join(fixtures, 'page', 'a.html') app.defaultSession.cookies.set {url: url, name: '2', value: '2'}, (error) ->
w.webContents.on 'did-finish-load', ->
w.webContents.session.cookies.set {url: url, name: 'key', value: 'dummy2'}, (error) ->
return done(error) if error return done(error) if error
w.webContents.session.cookies.remove {url: url, name: 'key'}, (error) -> app.defaultSession.cookies.remove {url: url, name: '2'}, (error) ->
return done(error) if error return done(error) if error
w.webContents.session.cookies.get {url: url}, (error, list) -> app.defaultSession.cookies.get {url: url}, (error, list) ->
return done(error) if error return done(error) if error
for cookie in list when cookie.name is 'key' for cookie in list when cookie.name is '2'
return done('Cookie not deleted') return done('Cookie not deleted')
done() done()