diff --git a/runtime/main/extend/systemplugin/ohos/appAccount.js b/runtime/main/extend/systemplugin/ohos/appAccount.js index fd907958..c82a7f78 100644 --- a/runtime/main/extend/systemplugin/ohos/appAccount.js +++ b/runtime/main/extend/systemplugin/ohos/appAccount.js @@ -20,6 +20,16 @@ export function mockAppAccount() { owner: "[PC Preview] unknown owner", name: "[PC Preview] unknown name" }; + const OAuthTokenInfoMock = { + authType: "[PC preview] unknown authType", + token: "[PC preview] unknown token" + }; + const AuthenticatorInfoMock = { + owner: "[PC preview] unknown owner", + iconId: "[PC preview] unknown iconId", + labelId: "[PC preview] unknown labelId", + }; + const appAccountManagerMock = { addAccount: function (...args) { console.warn("AppAccountManager.addAccount interface mocked in the Previewer. " + @@ -33,6 +43,14 @@ export function mockAppAccount() { }) } }, + addAccountImplicitly: function (...args) { + console.warn("AppAccountManager.addAccountImplicitly interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } + }, deleteAccount: function (...args) { console.warn("AppAccountManager.deleteAccount interface mocked in the Previewer. " + "How this interface works on the Previewer may be different from that on a real device.") @@ -220,14 +238,201 @@ export function mockAppAccount() { resolve(appAccountInfoArrayMock); }) } + }, + authenticate: function (...args) { + console.warn("AppAccountManager.authenticate interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } + }, + getOAuthToken: function (...args) { + console.warn("AppAccountManager.getOAuthToken interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock) + }) + } + }, + setOAuthToken: function (...args) { + console.warn("AppAccountManager.setOAuthToken interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve() + }) + } + }, + deleteOAuthToken: function (...args) { + console.warn("AppAccountManager.deleteOAuthToken interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve() + }) + } + }, + setOAuthTokenVisibility: function (...args) { + console.warn("AppAccountManager.setOAuthTokenVisibility interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve() + }) + } + }, + checkOAuthTokenVisibility: function (...args) { + console.warn("AppAccountManager.checkOAuthTokenVisibility interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve() + }) + } + }, + getAllOAuthTokens: function (...args) { + console.warn("AppAccountManager.getAllOAuthTokens interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new Array(OAuthTokenInfoMock)); + } else { + return new Promise((resolve, reject) => { + resolve(new Array(OAuthTokenInfoMock)) + }) + } + }, + getOAuthList: function (...args) { + console.warn("AppAccountManager.getOAuthList interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new Array(paramMock.paramStringMock)); + } else { + return new Promise((resolve, reject) => { + resolve(new Array(paramMock.paramStringMock)) + }) + } + }, + getAuthenticatorCallback: function (...args) { + console.warn("AppAccountManager.getAuthenticatorCallback interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } else { + return new Promise((resolve, reject) => { + resolve(AuthenticatorCallbackMock) + }) + } + }, + getAuthenticatorInfo: function (...args) { + console.warn("AppAccountManager.getAuthenticatorInfo interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorInfoMock); + } else { + return new Promise((resolve, reject) => { + resolve(AuthenticatorInfoMock) + }) + } } - } + }; + const AuthenticatorCallbackMock = { + onResult: function (...args) { + console.warn("AuthenticatorCallback.onResult interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + }, + onRequestRedirected: function (...args) { + console.warn("AuthenticatorCallback.onRequestRedirected interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + } + }; + const AuthenticatorClass = class Authenticator { + constructor() { + console.warn("appAccount.Authenticator constructor interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + this.addAccountImplicitly = function (...args) { + console.warn("Authenticator.addAccountImplicitly interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } + }; + this.authenticate = function (...args) { + console.warn("Authenticator.authenticate interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } + }; + } + }; + const ConstantsMock = { + ACTION_ADD_ACCOUNT_IMPLICITLY: '[PC preview] unknow string', + ACTION_AUTHENTICATE: '[PC preview] unknow string', + KEY_NAME: '[PC preview] unknow string', + KEY_OWNER: '[PC preview] unknow string', + KEY_TOKEN: '[PC preview] unknow string', + KEY_ACTION: '[PC preview] unknow string', + KEY_AUTH_TYPE: '[PC preview] unknow string', + KEY_SESSION_ID: '[PC preview] unknow string', + KEY_CALLER_PID: '[PC preview] unknow string', + KEY_CALLER_UID: '[PC preview] unknow string', + KEY_CALLER_BUNDLE_NAME: '[PC preview] unknow string' + }; + const ResultCodeMock = { + SUCCESS: '[PC preview] unknow resultCode', + ERROR_ACCOUNT_NOT_EXIST: '[PC preview] unknow resultCode', + ERROR_APP_ACCOUNT_SERVICE_EXCEPTION: '[PC preview] unknow resultCode', + ERROR_INVALID_PASSWORD: '[PC preview] unknow resultCode', + ERROR_INVALID_REQUEST: '[PC preview] unknow resultCode', + ERROR_INVALID_RESPONSE: '[PC preview] unknow resultCode', + ERROR_NETWORK_EXCEPTION: '[PC preview] unknow resultCode', + ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST: '[PC preview] unknow resultCode', + ERROR_OAUTH_CANCELED: '[PC preview] unknow resultCode', + ERROR_OAUTH_LIST_TOO_LARGE: '[PC preview] unknow resultCode', + ERROR_OAUTH_SERVICE_BUSY: '[PC preview] unknow resultCode', + ERROR_OAUTH_SERVICE_EXCEPTION: '[PC preview] unknow resultCode', + ERROR_OAUTH_SESSION_NOT_EXIST: '[PC preview] unknow resultCode', + ERROR_OAUTH_TIMEOUT: '[PC preview] unknow resultCode', + ERROR_OAUTH_TOKEN_NOT_EXIST: '[PC preview] unknow resultCode', + ERROR_OAUTH_TOKEN_TOO_MANY: '[PC preview] unknow resultCode', + ERROR_OAUTH_UNSUPPORT_ACTION: '[PC preview] unknow resultCode', + ERROR_OAUTH_UNSUPPORT_AUTH_TYPE: '[PC preview] unknow resultCode', + ERROR_PERMISSION_DENIED: '[PC preview] unknow resultCode' + }; + global.ohosplugin.account = global.ohosplugin.account || {}; global.ohosplugin.account.appAccount = { createAppAccountManager: function (...args) { console.warn("appAccount.createAppAccountManager interface mocked in the Previewer. " + "How this interface works on the Previewer may be different from that on a real device.") return appAccountManagerMock; - } + }, + AuthenticatorCallback:AuthenticatorCallbackMock, + Authenticator:AuthenticatorClass, + Constants:ConstantsMock, + ResultCode:ResultCodeMock, } } \ No newline at end of file