ares-ide
Version:
A browser-based code editor and UI designer for Enyo 2 projects
84 lines (74 loc) • 3.49 kB
text/coffeescript
describe 'Dropbox.Drivers.Chrome', ->
beforeEach ->
= chrome? and (chrome.extension or chrome.app?.runtime)
= new Dropbox.Client testKeys
describe '#url', ->
beforeEach ->
return unless
= 'test/html/redirect_driver_test.html'
= new Dropbox.Drivers.Chrome 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'
suffix = + '?_dropboxjs_scope=default&dboauth_token=oauth%20token'
expect(url.substring(url.length - suffix.length)).to.equal suffix
describe '#loadCredentials', ->
beforeEach ->
return unless
= new Dropbox.Client testKeys
= new Dropbox.Drivers.Chrome scope: 'some_scope'
it 'produces the credentials passed to storeCredentials', (done) ->
return done() unless
goldCredentials = .credentials()
.storeCredentials goldCredentials, =>
= new Dropbox.Drivers.Chrome 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.Drivers.Chrome 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.Drivers.Chrome scope: 'other_scope'
.loadCredentials (credentials) ->
expect(credentials).to.equal null
done()
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.Drivers.Chrome(
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.authState).to.equal Dropbox.Client.DONE
# Verify that we can do API calls.
client.getUserInfo (error, userInfo) ->
expect(error).to.equal null
expect(userInfo).to.be.instanceOf Dropbox.UserInfo
# Follow-up authenticate() should use stored credentials.
client.reset()
client.authenticate interactive: false, (error, client) ->
expect(error).to.equal null
expect(client.authState).to.equal Dropbox.Client.DONE
expect(client.isAuthenticated()).to.equal true
# Verify that we can do API calls.
client.getUserInfo (error, userInfo) ->
expect(error).to.equal null
expect(userInfo).to.be.instanceOf Dropbox.UserInfo
done()