This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26026 from jmcanterafonseca/logout_facebook_20
Bug 1084224 - [Midori 2.0][Contacts][Facebook]keep logging out interface...
- Loading branch information
Showing
3 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
apps/communications/contacts/test/unit/fb_utils_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
'use strict'; | ||
|
||
/* global MockasyncStorage, fb */ | ||
|
||
require('/shared/js/contacts/import/facebook/fb_contact_utils.js'); | ||
require('/shared/js/contacts/import/facebook/fb_utils.js'); | ||
require('/shared/js/fb/fb_request.js'); | ||
requireApp('communications/contacts/test/unit/mock_asyncstorage.js'); | ||
|
||
suite('Fb Utils Tests', function() { | ||
var subject; | ||
var messageCallback; | ||
var pendingSchedule = false, timesToExecute = 0; | ||
var realAsyncStorage; | ||
|
||
// We need this as sinon.useFaketimers does not support partial stub of | ||
// setInterval and we need setTimeout to work as usual | ||
function tick(times) { | ||
pendingSchedule = true; | ||
timesToExecute = times; | ||
} | ||
|
||
function resolveLogout(callback) { | ||
if (typeof callback !== 'function') { | ||
return; | ||
} | ||
|
||
window.setTimeout(callback, 0, { | ||
origin: location.origin, | ||
data: 'closed', | ||
stopImmediatePropagation: function() {} | ||
}); | ||
} | ||
|
||
suiteSetup(function() { | ||
subject = fb.utils; | ||
|
||
sinon.stub(window, 'open', function() { | ||
resolveLogout(messageCallback); | ||
|
||
return { | ||
closed: false | ||
}; | ||
}); | ||
|
||
sinon.stub(window, 'addEventListener', function(event, cb) { | ||
if (event === 'message') { | ||
messageCallback = cb; | ||
} | ||
}); | ||
|
||
sinon.stub(window, 'setInterval', function(cb, interval) { | ||
if (pendingSchedule === true) { | ||
for (var j = 0; j < timesToExecute; j++) { | ||
window.setTimeout(cb); | ||
} | ||
} | ||
pendingSchedule = false; timesToExecute = 0; | ||
return 1; | ||
}); | ||
|
||
realAsyncStorage = window.asyncStorage; | ||
window.asyncStorage = MockasyncStorage; | ||
}); | ||
|
||
suiteTeardown(function() { | ||
window.open.restore(); | ||
window.addEventListener.restore(); | ||
window.setInterval.restore(); | ||
|
||
window.asyncStorage = realAsyncStorage; | ||
}); | ||
|
||
|
||
setup(function() { | ||
MockasyncStorage.keys = { | ||
'tokenData': { | ||
access_token: '1234' | ||
} | ||
}; | ||
}); | ||
|
||
|
||
test('Logout, everything goes well', function(done) { | ||
var req = subject.logout(); | ||
|
||
req.onsuccess = function(e) { | ||
done(function() { | ||
assert.ok('everything went well'); | ||
}); | ||
}; | ||
|
||
req.onerror = done.bind(null, req.error); | ||
|
||
tick(1); | ||
}); | ||
|
||
|
||
test('Logout, timeout happens. Error raised', function(done) { | ||
window.open.restore(); | ||
sinon.stub(window, 'open', function() { | ||
return { | ||
closed: false | ||
}; | ||
}); | ||
|
||
var req = subject.logout(); | ||
|
||
req.onsuccess = done; | ||
|
||
req.onerror = function() { | ||
done(function() { | ||
assert.equal(req.error, 'Timeout'); | ||
}); | ||
}; | ||
|
||
tick(10); | ||
}); | ||
|
||
|
||
test('Logout, window is closed. Error raised', function(done) { | ||
window.open.restore(); | ||
sinon.stub(window, 'open', function() { | ||
return { | ||
closed: true | ||
}; | ||
}); | ||
|
||
var req = subject.logout(); | ||
|
||
// If onsuccess is called done is called with params and the test fails | ||
req.onsuccess = done; | ||
|
||
req.onerror = function() { | ||
done(function() { | ||
assert.equal(req.error, 'UserCancelled'); | ||
}); | ||
}; | ||
|
||
tick(1); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters