No need to actually create a page for cookie test
This commit is contained in:
parent
020ccd8018
commit
346fb745f2
1 changed files with 32 additions and 42 deletions
|
@ -1,7 +1,8 @@
|
||||||
assert = require 'assert'
|
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,48 +25,37 @@ 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
|
||||||
it 'should over-write the existent cookie', (done) ->
|
return done("cookie value is #{cookie.value} while expecting 0")
|
||||||
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) ->
|
|
||||||
return done(error) if error
|
|
||||||
w.webContents.session.cookies.get {url: url}, (error, cookies_list) ->
|
|
||||||
return done(error) if error
|
|
||||||
assert.equal 'type', cookies_list[0].name
|
|
||||||
assert.equal 'dummy2', cookies_list[0].value
|
|
||||||
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()
|
|
||||||
done('Can not find cookie')
|
done('Can not find cookie')
|
||||||
|
|
||||||
it 'should remove cookies', (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', ->
|
return done(error) if error
|
||||||
w.webContents.session.cookies.set {url: url, name: 'key', value: 'dummy2'}, (error) ->
|
app.defaultSession.cookies.get {url: url}, (error, list) ->
|
||||||
return done(error) if error
|
return done(error) if error
|
||||||
w.webContents.session.cookies.remove {url: url, name: 'key'}, (error) ->
|
for cookie in list when cookie.name is '1'
|
||||||
|
if cookie.value is '1'
|
||||||
|
return done()
|
||||||
|
else
|
||||||
|
return done("cookie value is #{cookie.value} while expecting 1")
|
||||||
|
done('Can not find cookie')
|
||||||
|
|
||||||
|
it 'should remove cookies', (done) ->
|
||||||
|
app.defaultSession.cookies.set {url: url, name: '2', value: '2'}, (error) ->
|
||||||
|
return done(error) if error
|
||||||
|
app.defaultSession.cookies.remove {url: url, name: '2'}, (error) ->
|
||||||
|
return done(error) if error
|
||||||
|
app.defaultSession.cookies.get {url: url}, (error, list) ->
|
||||||
return done(error) if error
|
return done(error) if error
|
||||||
w.webContents.session.cookies.get {url: url}, (error, list) ->
|
for cookie in list when cookie.name is '2'
|
||||||
return done(error) if error
|
return done('Cookie not deleted')
|
||||||
for cookie in list when cookie.name is 'key'
|
done()
|
||||||
return done('Cookie not deleted')
|
|
||||||
done()
|
|
||||||
|
|
||||||
describe 'session.clearStorageData(options)', ->
|
describe 'session.clearStorageData(options)', ->
|
||||||
fixtures = path.resolve __dirname, 'fixtures'
|
fixtures = path.resolve __dirname, 'fixtures'
|
||||||
|
|
Loading…
Reference in a new issue