nebulab-dropbox
Version:
Client library for the Dropbox API
148 lines (130 loc) • 6.14 kB
text/coffeescript
describe 'Dropbox.AuthDriver.ChromeBase', ->
beforeEach ->
= chrome?.runtime?.id
= new Dropbox.Client testKeys
describe '#loadCredentials', ->
beforeEach ->
return unless
= new Dropbox.Client testKeys
= new Dropbox.AuthDriver.ChromeBase scope: 'some_scope'
it 'produces the credentials passed to storeCredentials', (done) ->
return done() unless
goldCredentials = .credentials()
.storeCredentials goldCredentials, =>
= new Dropbox.AuthDriver.ChromeBase scope: 'some_scope'
.loadCredentials (credentials) ->
expect(credentials).to.deep.equal goldCredentials
done()
it 'produces null after forgetCredentials was called', (done) ->
return done() unless
.storeCredentials .credentials(), =>
.forgetCredentials =>
= new Dropbox.AuthDriver.ChromeBase scope: 'some_scope'
.loadCredentials (credentials) ->
expect(credentials).to.equal null
done()
it 'produces null if a different scope is provided', (done) ->
return done() unless
.storeCredentials .credentials(), =>
= new Dropbox.AuthDriver.ChromeBase scope: 'other_scope'
.loadCredentials (credentials) ->
expect(credentials).to.equal null
done()
describe 'Dropbox.AuthDriver.ChromeApp', ->
beforeEach ->
= chrome?.runtime?.id
= and chrome?.app?.window
= new Dropbox.Client testKeys
describe '#url', ->
beforeEach ->
return unless
= new Dropbox.AuthDriver.ChromeApp()
it 'produces a chromiumapp.org url', ->
return unless
expect(.url()).to.match(
/https:\/\/[a-z0-9]+\.chromiumapp\.org\/$/)
describe 'integration', ->
it 'should work', (done) ->
return done() unless
45 * 1000 # Time-consuming because the user must click.
client = new Dropbox.Client testKeys
client.reset()
authDriver = new Dropbox.AuthDriver.ChromeApp(
scope: 'chrome_integration')
client.authDriver authDriver
authDriver.forgetCredentials ->
client.authenticate (error, client) ->
expect(error).to.equal null
expect(client.authStep).to.equal Dropbox.Client.DONE
# Verify that we can do API calls.
client.getAccountInfo (error, accountInfo) ->
expect(error).to.equal null
expect(accountInfo).to.be.instanceOf Dropbox.AccountInfo
# Follow-up authenticate() should use stored credentials.
client.reset()
client.authenticate interactive: false, (error, client) ->
expect(error).to.equal null
expect(client.authStep).to.equal Dropbox.Client.DONE
expect(client.isAuthenticated()).to.equal true
# Verify that we can do API calls.
client.getAccountInfo (error, accountInfo) ->
expect(error).to.equal null
expect(accountInfo).to.be.instanceOf Dropbox.AccountInfo
done()
it 'should be the default driver in Chrome packaged apps', ->
return unless
client = new Dropbox.Client testKeys
Dropbox.AuthDriver.autoConfigure client
expect(client._driver).to.be.instanceOf Dropbox.AuthDriver.ChromeApp
describe 'Dropbox.AuthDriver.ChromeExtension', ->
beforeEach ->
= chrome?.runtime?.id
= and chrome?.tabs
= new Dropbox.Client testKeys
describe '#url', ->
beforeEach ->
return unless
= 'test/html/redirect_driver_test.html'
= new Dropbox.AuthDriver.ChromeExtension receiverPath:
it 'produces a chrome-extension:// url', ->
return unless
expect(.url('oauth token')).to.match(/^chrome-extension:\/\//)
it 'produces an URL with the correct suffix', ->
return unless
url = .url 'oauth token'
expect(url.substring(url.length - .length)).to.equal
describe 'integration', ->
it 'should work', (done) ->
return done() unless
45 * 1000 # Time-consuming because the user must click.
client = new Dropbox.Client testKeys
client.reset()
authDriver = new Dropbox.AuthDriver.ChromeExtension(
receiverPath: 'test/html/chrome_oauth_receiver.html',
scope: 'chrome_integration')
client.authDriver authDriver
authDriver.forgetCredentials ->
client.authenticate (error, client) ->
expect(error).to.equal null
expect(client.authStep).to.equal Dropbox.Client.DONE
# Verify that we can do API calls.
client.getAccountInfo (error, accountInfo) ->
expect(error).to.equal null
expect(accountInfo).to.be.instanceOf Dropbox.AccountInfo
# Follow-up authenticate() should use stored credentials.
client.reset()
client.authenticate interactive: false, (error, client) ->
expect(error).to.equal null
expect(client.authStep).to.equal Dropbox.Client.DONE
expect(client.isAuthenticated()).to.equal true
# Verify that we can do API calls.
client.getAccountInfo (error, accountInfo) ->
expect(error).to.equal null
expect(accountInfo).to.be.instanceOf Dropbox.AccountInfo
done()
it 'should be the default driver in Chrome extensions', ->
return unless
client = new Dropbox.Client testKeys
Dropbox.AuthDriver.autoConfigure client
expect(client._driver).to.be.instanceOf(
Dropbox.AuthDriver.ChromeExtension)