mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1160371 - fix intermittent test_oauth_tokens.js by correctly mocking storage. r=zaach
This commit is contained in:
parent
dce1ebe877
commit
2f084c91ca
@ -8,6 +8,7 @@ Cu.import("resource://gre/modules/FxAccountsClient.jsm");
|
||||
Cu.import("resource://gre/modules/FxAccountsCommon.js");
|
||||
Cu.import("resource://gre/modules/FxAccountsOAuthGrantClient.jsm");
|
||||
Cu.import("resource://services-common/utils.js");
|
||||
let {AccountState} = Cu.import("resource://gre/modules/FxAccounts.jsm", {});
|
||||
|
||||
function promiseNotification(topic) {
|
||||
return new Promise(resolve => {
|
||||
@ -20,24 +21,40 @@ function promiseNotification(topic) {
|
||||
}
|
||||
|
||||
// Just enough mocks so we can avoid hawk and storage.
|
||||
let MockStorage = function() {
|
||||
this.data = null;
|
||||
};
|
||||
MockStorage.prototype = Object.freeze({
|
||||
set: function (contents) {
|
||||
this.data = contents;
|
||||
return Promise.resolve(null);
|
||||
function MockStorageManager() {
|
||||
}
|
||||
|
||||
MockStorageManager.prototype = {
|
||||
promiseInitialized: Promise.resolve(),
|
||||
|
||||
initialize(accountData) {
|
||||
this.accountData = accountData;
|
||||
},
|
||||
get: function () {
|
||||
return Promise.resolve(this.data);
|
||||
},
|
||||
getOAuthTokens() {
|
||||
return Promise.resolve(null);
|
||||
},
|
||||
setOAuthTokens(contents) {
|
||||
|
||||
finalize() {
|
||||
return Promise.resolve();
|
||||
},
|
||||
});
|
||||
|
||||
getAccountData() {
|
||||
return Promise.resolve(this.accountData);
|
||||
},
|
||||
|
||||
updateAccountData(updatedFields) {
|
||||
for (let [name, value] of Iterator(updatedFields)) {
|
||||
if (value == null) {
|
||||
delete this.accountData[name];
|
||||
} else {
|
||||
this.accountData[name] = value;
|
||||
}
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
deleteAccountData() {
|
||||
this.accountData = null;
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
function MockFxAccountsClient() {
|
||||
this._email = "nobody@example.com";
|
||||
@ -62,7 +79,12 @@ function MockFxAccounts(mockGrantClient) {
|
||||
return new FxAccounts({
|
||||
fxAccountsClient: new MockFxAccountsClient(),
|
||||
getAssertion: () => Promise.resolve("assertion"),
|
||||
signedInUserStorage: new MockStorage(),
|
||||
newAccountState(credentials) {
|
||||
// we use a real accountState but mocked storage.
|
||||
let storage = new MockStorageManager();
|
||||
storage.initialize(credentials);
|
||||
return new AccountState(storage);
|
||||
},
|
||||
_destroyOAuthToken: function(tokenData) {
|
||||
// somewhat sad duplication of _destroyOAuthToken, but hard to avoid.
|
||||
return mockGrantClient.destroyToken(tokenData.token).then( () => {
|
||||
|
Loading…
Reference in New Issue
Block a user