diff --git a/.gitattributes b/.gitattributes index 51c63e29..8b137891 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,15 +1 @@ -*.tgz filter=lfs diff=lfs merge=lfs -text -*.trp filter=lfs diff=lfs merge=lfs -text -*.apk filter=lfs diff=lfs merge=lfs -text -*.jar filter=lfs diff=lfs merge=lfs -text -*.mp4 filter=lfs diff=lfs merge=lfs -text -*.zip filter=lfs diff=lfs merge=lfs -text -*.asm filter=lfs diff=lfs merge=lfs -text -*.8svn filter=lfs diff=lfs merge=lfs -text -*.9svn filter=lfs diff=lfs merge=lfs -text -*.dylib filter=lfs diff=lfs merge=lfs -text -*.exe filter=lfs diff=lfs merge=lfs -text -*.a filter=lfs diff=lfs merge=lfs -text -*.so filter=lfs diff=lfs merge=lfs -text -*.bin filter=lfs diff=lfs merge=lfs -text -*.dll filter=lfs diff=lfs merge=lfs -text + diff --git a/BUILD.gn b/BUILD.gn index a4123675..3c122f0a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -38,8 +38,15 @@ action("gen_snapshot") { if (is_standard_system) { node_modules = "//prebuilts/build-tools/common/js-framework/node_modules" - nodejs_path = - "//prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64" + if (use_mac) { + nodejs_path = + "//prebuilts/build-tools/common/nodejs/node-v12.18.4-darwin-x64" + is_mac = "true" + } else { + nodejs_path = + "//prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64" + is_mac = "false" + } } else { node_modules = "//prebuilts/ace-toolkit/js-framework/node_modules" if (use_mac) { diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 00000000..58822a64 --- /dev/null +++ b/OAT.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + diff --git a/package.json b/package.json index 3d59235c..152ff766 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "index.js", "scripts": { "test:lint": "eslint -c .eslintrc --fix test/**/*.ts", - "test:unit": "mocha -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts", + "test:unit": "mocha --timeout 5000 -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts", "build": "node build.js" }, "keywords": [ diff --git a/runtime/main/extend/i18n/I18n.ts b/runtime/main/extend/i18n/I18n.ts index 82e66b78..cf01411e 100644 --- a/runtime/main/extend/i18n/I18n.ts +++ b/runtime/main/extend/i18n/I18n.ts @@ -171,7 +171,7 @@ class I18n { return ''; }); } else if (Object.prototype.toString.call(params) === '[object Number]') { - value = value.replace(/\{count\}/g, params); + value = value.replace(/\{count\}/g, params.toLocaleString(this.locale.replace('_', '-'))); } else { return value; } diff --git a/runtime/main/extend/systemplugin/ability.js b/runtime/main/extend/systemplugin/ability.js index 9be9a72c..c35346c3 100644 --- a/runtime/main/extend/systemplugin/ability.js +++ b/runtime/main/extend/systemplugin/ability.js @@ -26,78 +26,78 @@ const ResultSetMock = { isClose: "[PC Preview] unknow isClose", getColumnIndex: function (...args) { console.warn("ResultSet.getColumnIndex interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramNumberMock; }, getColumnName: function (...args) { console.warn("ResultSet.getColumnName interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramStringMock; }, goTo: function (...args) { console.warn("ResultSet.goTo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramBooleanMock; }, goToRow: function (...args) { console.warn("ResultSet.goToRow interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramBooleanMock; }, goToLastRow: function (...args) { console.warn("ResultSet.goToLastRow interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramBooleanMock; }, goToFirstRow: function (...args) { console.warn("ResultSet.goToFirstRow interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramBooleanMock; }, goToNextRow: function (...args) { console.warn("ResultSet.goToNextRow interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramBooleanMock; }, goToPreviousRow: function (...args) { console.warn("ResultSet.goToPreviousRow interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramBooleanMock; }, getBlob: function (...args) { console.warn("ResultSet.getBlob interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramArrayMock; }, getString: function (...args) { console.warn("ResultSet.getString interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramStringMock; }, getLong: function (...args) { console.warn("ResultSet.getLong interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramNumberMock; }, getDouble: function (...args) { console.warn("ResultSet.getDouble interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramNumberMock; }, isColumnNull: function (...args) { console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramBooleanMock; }, close: function () { console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") } } const DataAbilityHelperMock = { openFile: function (...args) { console.warn("DataAbilityHelper.openFile interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -109,7 +109,7 @@ const DataAbilityHelperMock = { }, on: function (...args) { console.warn("DataAbilityHelper.on interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -117,7 +117,7 @@ const DataAbilityHelperMock = { }, off: function (...args) { console.warn("DataAbilityHelper.off interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -125,7 +125,7 @@ const DataAbilityHelperMock = { }, call: function (...args) { console.warn("DataAbilityHelper.call interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, PacMapTypeMock) @@ -137,7 +137,7 @@ const DataAbilityHelperMock = { }, getType: function (...args) { console.warn("DataAbilityHelper.getType interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -149,7 +149,7 @@ const DataAbilityHelperMock = { }, getFileTypes: function (...args) { console.warn("DataAbilityHelper.getFileTypes interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, getFileTypesArrayMock) @@ -161,7 +161,7 @@ const DataAbilityHelperMock = { }, normalizeUri: function (...args) { console.warn("DataAbilityHelper.normalizeUri interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -173,7 +173,7 @@ const DataAbilityHelperMock = { }, denormalizeUri: function (...args) { console.warn("DataAbilityHelper.denormalizeUri interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -185,7 +185,7 @@ const DataAbilityHelperMock = { }, notifyChange: function (...args) { console.warn("DataAbilityHelper.notifyChange interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -197,7 +197,7 @@ const DataAbilityHelperMock = { }, insert: function (...args) { console.warn("DataAbilityHelper.insert interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -209,7 +209,7 @@ const DataAbilityHelperMock = { }, batchInsert: function (...args) { console.warn("DataAbilityHelper.batchInsert interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -221,7 +221,7 @@ const DataAbilityHelperMock = { }, delete: function (...args) { console.warn("DataAbilityHelper.delete interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -233,7 +233,7 @@ const DataAbilityHelperMock = { }, update: function (...args) { console.warn("DataAbilityHelper.update interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -245,7 +245,7 @@ const DataAbilityHelperMock = { }, query: function (...args) { console.warn("DataAbilityHelper.query interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, ResultSetMock) @@ -257,7 +257,7 @@ const DataAbilityHelperMock = { }, executeBatch: function (...args) { console.warn("DataAbilityHelper.executeBatch interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, DataAbilityResultArrayMock) @@ -287,9 +287,9 @@ export function mockAbilityFeatureAbility() { want: WantMock } const ContinuationStateMock = { - LOCAL_RUNNING : '0', - REMOTE_RUNNING : '1', - REPLICA_RUNNING : '2' + LOCAL_RUNNING: '0', + REMOTE_RUNNING: '1', + REPLICA_RUNNING: '2' } const PermissionRequestResultMock = { requestCode: "[PC Preview] unknow requestCode", @@ -320,7 +320,7 @@ export function mockAbilityFeatureAbility() { permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], moduleInfo: [ModuleInfoMock], entryDir: "[PC Preview] unknow entryDir", - customizeData:new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]]) + customizeData: new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]]) } const AbilityInfoMock = { bundleName: "[PC Preview] unknow bundleName", @@ -391,7 +391,7 @@ export function mockAbilityFeatureAbility() { const ContextMock = { getCacheDir: function (...args) { console.warn("Context.getCacheDir interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -403,7 +403,7 @@ export function mockAbilityFeatureAbility() { }, getFilesDir: function (...args) { console.warn("Context.getFilesDir interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -415,7 +415,7 @@ export function mockAbilityFeatureAbility() { }, getExternalCacheDir: function (...args) { console.warn("Context.getExternalCacheDir interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -427,7 +427,7 @@ export function mockAbilityFeatureAbility() { }, getOrCreateLocalDir: function (...args) { console.warn("Context.getOrCreateLocalDir interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -439,7 +439,7 @@ export function mockAbilityFeatureAbility() { }, getOrCreateDistributedDir: function (...args) { console.warn("Context.getOrCreateDistributedDir interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -451,7 +451,7 @@ export function mockAbilityFeatureAbility() { }, verifyPermission: function (...args) { console.warn("Context.verifyPermission interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -463,7 +463,7 @@ export function mockAbilityFeatureAbility() { }, compelVerifyPermission: function (...args) { console.warn("Context.compelVerifyPermission interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -475,7 +475,7 @@ export function mockAbilityFeatureAbility() { }, authUriAccessPermission: function (...args) { console.warn("Context.authUriAccessPermission interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -487,7 +487,7 @@ export function mockAbilityFeatureAbility() { }, unauthUriAccessPermission: function (...args) { console.warn("Context.unauthUriAccessPermission interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -499,7 +499,7 @@ export function mockAbilityFeatureAbility() { }, requestPermissionsFromUser: function (...args) { console.warn("Context.requestPermissionsFromUser interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, PermissionRequestResultMock) @@ -511,7 +511,7 @@ export function mockAbilityFeatureAbility() { }, getApplicationInfo: function (...args) { console.warn("Context.getApplicationInfo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, ApplicationInfoMock) @@ -523,7 +523,7 @@ export function mockAbilityFeatureAbility() { }, getBundleName: function (...args) { console.warn("Context.getBundleName interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -535,7 +535,7 @@ export function mockAbilityFeatureAbility() { }, getDisplayOrientation: function (...args) { console.warn("Context.getDisplayOrientation interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -547,7 +547,7 @@ export function mockAbilityFeatureAbility() { }, setDisplayOrientation: function (...args) { console.warn("Context.setDisplayOrientation interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -559,7 +559,7 @@ export function mockAbilityFeatureAbility() { }, setShowOnLockScreen: function (...args) { console.warn("Context.setShowOnLockScreen interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -571,7 +571,7 @@ export function mockAbilityFeatureAbility() { }, setWakeUpScreen: function (...args) { console.warn("Context.setWakeUpScreen interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -583,7 +583,7 @@ export function mockAbilityFeatureAbility() { }, getProcessInfo: function (...args) { console.warn("Context.getProcessInfo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, ProcessInfoMock) @@ -595,7 +595,7 @@ export function mockAbilityFeatureAbility() { }, getAppType: function (...args) { console.warn("Context.getAppType interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -607,7 +607,7 @@ export function mockAbilityFeatureAbility() { }, getElementName: function (...args) { console.warn("Context.getElementName interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, ElementNameMock) @@ -619,7 +619,7 @@ export function mockAbilityFeatureAbility() { }, getHapModuleInfo: function (...args) { console.warn("Context.getHapModuleInfo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, HapModuleInfoMock) @@ -631,7 +631,7 @@ export function mockAbilityFeatureAbility() { }, getProcessName: function (...args) { console.warn("Context.getProcessName interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -643,7 +643,7 @@ export function mockAbilityFeatureAbility() { }, getCallingBundle: function (...args) { console.warn("Context.getCallingBundle interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -655,7 +655,7 @@ export function mockAbilityFeatureAbility() { }, printDrawnCompleted: function (...args) { console.warn("Context.printDrawnCompleted interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -667,7 +667,7 @@ export function mockAbilityFeatureAbility() { }, isUpdatingConfigurations: function (...args) { console.warn("Context.isUpdatingConfigurations interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) @@ -679,7 +679,7 @@ export function mockAbilityFeatureAbility() { }, getAppVersionInfo: function (...args) { console.warn("Context.getAppVersionInfo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, AppVersionInfoMock) @@ -691,7 +691,7 @@ export function mockAbilityFeatureAbility() { }, getAbilityInfo: function (...args) { console.warn("Context.getAbilityInfo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, AbilityInfoMock) @@ -703,7 +703,7 @@ export function mockAbilityFeatureAbility() { }, getApplicationContext: function () { console.warn("Context.getApplicationContext interface mocked in the Previewer. How this interface works on" + - " the Previewer may be different from that on a real device.") + " the Previewer may be different from that on a real device.") return ContextMock; } } @@ -734,12 +734,12 @@ export function mockAbilityFeatureAbility() { }, connectAbility: function (...args) { console.warn("ability.featureAbility.connectAbility interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") return paramMock.paramNumberMock; }, disconnectAbility: function (...args) { console.warn("ability.featureAbility.disconnectAbility interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -751,12 +751,12 @@ export function mockAbilityFeatureAbility() { }, getContext: function () { console.warn("ability.featureAbility.getContext interface mocked in the Previewer. How this interface works on" + - " the Previewer may be different from that on a real device.") + " the Previewer may be different from that on a real device.") return ContextMock; }, startAbilityForResult: function (...args) { console.warn("ability.featureAbility.startAbilityForResult interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, AbilityResultMock) @@ -768,7 +768,7 @@ export function mockAbilityFeatureAbility() { }, terminateSelfWithResult: function (...args) { console.warn("ability.featureAbility.terminateSelfWithResult interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -780,7 +780,7 @@ export function mockAbilityFeatureAbility() { }, terminateSelf: function (...args) { console.warn("ability.featureAbility.terminateSelf interface mocked in the Previewer. How this interface works on" + - " the Previewer may be different from that on a real device.") + " the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -792,12 +792,12 @@ export function mockAbilityFeatureAbility() { }, acquireDataAbilityHelper: function (...args) { console.warn("ability.featureAbility.acquireDataAbilityHelper mocked in the Previewer. How this interface works on the Previewer may be" + - " different from that on a real device.") + " different from that on a real device.") return DataAbilityHelperMock; }, hasWindowFocus: function (...args) { console.warn("ability.featureAbility.hasWindowFocus interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) @@ -809,7 +809,7 @@ export function mockAbilityFeatureAbility() { }, getAbilityMissionId: function (...args) { console.warn("ability.featureAbility.getAbilityMissionId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -821,7 +821,7 @@ export function mockAbilityFeatureAbility() { }, getWindow: function (...args) { console.warn("ability.featureAbility.getWindow interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, windowMock) @@ -833,7 +833,7 @@ export function mockAbilityFeatureAbility() { }, continueAbility: function (...args) { console.warn("ability.featureAbility.continueAbility interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -845,7 +845,7 @@ export function mockAbilityFeatureAbility() { }, getContinuationState: function (...args) { console.warn("ability.featureAbility.getContinuationState interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, ContinuationStateMock) @@ -857,7 +857,7 @@ export function mockAbilityFeatureAbility() { }, getOriginalDeviceId: function (...args) { console.warn("ability.featureAbility.getOriginalDeviceId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) @@ -869,7 +869,7 @@ export function mockAbilityFeatureAbility() { }, reverseContinueAbility: function (...args) { console.warn("ability.featureAbility.reverseContinueAbility interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -881,11 +881,11 @@ export function mockAbilityFeatureAbility() { }, finishTaskSyncAnimation: function (...args) { console.warn("ability.featureAbility.finishTaskSyncAnimation interface mocked in the Previewer. How this interface works on" + - " the Previewer may be different from that on a real device.") + " the Previewer may be different from that on a real device.") }, setTaskSyncAnimationParams: function (...args) { console.warn("ability.featureAbility.setTaskSyncAnimationParams interface mocked in the Previewer. How this interface works on" + - " the Previewer may be different from that on a real device.") + " the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -897,11 +897,11 @@ export function mockAbilityFeatureAbility() { }, startAssistAbility: function (...args) { console.warn("ability.featureAbility.startAssistAbility mocked in the Previewer. How this interface works on the Previewer may be" + - " different from that on a real device.") + " different from that on a real device.") }, stopAssistAbility: function (...args) { console.warn("ability.featureAbility.stopAssistAbility interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -913,7 +913,7 @@ export function mockAbilityFeatureAbility() { }, on: function (...args) { console.warn("ability.featureAbility.on interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { if (args[0] == 'assistConnect') { @@ -927,7 +927,7 @@ export function mockAbilityFeatureAbility() { }, off: function (...args) { console.warn("ability.featureAbility.off interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { if (args[0] == 'assistConnect') { @@ -945,7 +945,7 @@ export function mockAbilityParticleAbility() { global.systemplugin.ability.particleAbility = { startAbility: function (...args) { console.warn("ability.particleAbility.startAbility interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -956,13 +956,13 @@ export function mockAbilityParticleAbility() { } }, connectAbility: function (...args) { - console.warn("ability.featureAbility.connectAbility interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + console.warn("ability.particleAbility.connectAbility interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") return paramMock.paramNumberMock; }, disconnectAbility: function (...args) { - console.warn("ability.featureAbility.disconnectAbility interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + console.warn("ability.particleAbility.disconnectAbility 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 (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -974,7 +974,7 @@ export function mockAbilityParticleAbility() { }, terminateSelf: function (...args) { console.warn("ability.particleAbility.terminateSelf interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -986,12 +986,12 @@ export function mockAbilityParticleAbility() { }, acquireDataAbilityHelper: function (...args) { console.warn("ability.particleAbility.acquireDataAbilityHelper interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") return DataAbilityHelperMock; }, startBackgroundRunning: function (...args) { console.warn("ability.particleAbility.startBackgroundRunning interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1003,7 +1003,7 @@ export function mockAbilityParticleAbility() { }, cancelBackgroundRunning: function (...args) { console.warn("ability.particleAbility.cancelBackgroundRunning interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1049,9 +1049,9 @@ export function mockAbilityFormManager() { entities: "[PC Preview] unknow entities" } const FormStateMock = { - UNKNOWN : '-1', - DEFAULT : '0', - READY : '1' + UNKNOWN: '-1', + DEFAULT: '0', + READY: '1' } const FormInfoArrayMock = [ FormInfoMock @@ -1063,7 +1063,7 @@ export function mockAbilityFormManager() { global.systemplugin.ability.formManager = { requestForm: function (...args) { console.warn("ability.formManager.requestForm interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1075,7 +1075,7 @@ export function mockAbilityFormManager() { }, deleteForm: function (...args) { console.warn("ability.formManager.deleteForm interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1087,7 +1087,7 @@ export function mockAbilityFormManager() { }, releaseForm: function (...args) { console.warn("ability.formManager.releaseForm interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") + " be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -1099,7 +1099,7 @@ export function mockAbilityFormManager() { }, notifyVisibleForms: function (...args) { console.warn("ability.formManager.notifyVisibleForms interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1111,7 +1111,7 @@ export function mockAbilityFormManager() { }, notifyInvisibleForms: function (...args) { console.warn("ability.formManager.notifyInvisibleForms interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1123,7 +1123,7 @@ export function mockAbilityFormManager() { }, enableFormsUpdate: function (...args) { console.warn("ability.formManager.enableFormsUpdate interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1135,7 +1135,7 @@ export function mockAbilityFormManager() { }, disableFormsUpdate: function (...args) { console.warn("ability.formManager.disableFormsUpdate interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1147,7 +1147,7 @@ export function mockAbilityFormManager() { }, isSystemReady: function (...args) { console.warn("ability.formManager.isSystemReady interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) @@ -1159,7 +1159,7 @@ export function mockAbilityFormManager() { }, castTempForm: function (...args) { console.warn("ability.formManager.castTempForm interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1171,7 +1171,7 @@ export function mockAbilityFormManager() { }, deleteInvalidForms: function (...args) { console.warn("ability.formManager.deleteInvalidForms interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -1183,7 +1183,7 @@ export function mockAbilityFormManager() { }, acquireFormState: function (...args) { console.warn("ability.formManager.acquireFormState interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, AcquireFormStateMock) @@ -1195,7 +1195,7 @@ export function mockAbilityFormManager() { }, on: function (...args) { console.warn("ability.formManager.on interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.paramStringMock) @@ -1203,7 +1203,7 @@ export function mockAbilityFormManager() { }, off: function (...args) { console.warn("ability.formManager.off interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.paramStringMock) @@ -1211,7 +1211,7 @@ export function mockAbilityFormManager() { }, getAllFormsInfo: function (...args) { console.warn("ability.formManager.getAllFormsInfo interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, FormInfoArrayMock) @@ -1223,7 +1223,7 @@ export function mockAbilityFormManager() { }, getFormsInfo: function (...args) { console.warn("ability.formManager.getFormsInfo interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, FormInfoArrayMock) @@ -1235,7 +1235,7 @@ export function mockAbilityFormManager() { }, updateForm: function (...args) { console.warn("ability.formManager.updateForm interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1256,7 +1256,7 @@ export function mockAbilityContinuationRegisterManager() { global.systemplugin.ability.continuationRegisterManager = { on: function (...args) { console.warn("ability.ContinuationRegisterManager.on interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (args[0] === 'deviceConnect') { if (typeof args[len - 1] === 'function') { @@ -1270,7 +1270,7 @@ export function mockAbilityContinuationRegisterManager() { }, off: function (...args) { console.warn("ability.ContinuationRegisterManager.off interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (args[0] === 'deviceConnect') { if (typeof args[len - 1] === 'function') { @@ -1284,7 +1284,7 @@ export function mockAbilityContinuationRegisterManager() { }, register: function (...args) { console.warn("ability.ContinuationRegisterManager.register interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -1296,7 +1296,7 @@ export function mockAbilityContinuationRegisterManager() { }, unregister: function (...args) { console.warn("ability.ContinuationRegisterManager.unregister interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1308,7 +1308,7 @@ export function mockAbilityContinuationRegisterManager() { }, updateConnectStatus: function (...args) { console.warn("ability.ContinuationRegisterManager.updateConnectStatus interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -1320,7 +1320,7 @@ export function mockAbilityContinuationRegisterManager() { }, showDeviceList: function (...args) { console.warn("ability.ContinuationRegisterManager.showDeviceList interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -1332,7 +1332,7 @@ export function mockAbilityContinuationRegisterManager() { }, disconnect: function (...args) { console.warn("ability.ContinuationRegisterManager.disconnect interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1348,22 +1348,22 @@ export function mockAbilityDataUriUtils() { global.systemplugin.ability.dataUriUtils = { getId: function (...args) { console.warn("ability.dataUriUtils.getId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") return paramMock.paramNumberMock }, attachId: function (...args) { console.warn("ability.dataUriUtils.attachId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") return paramMock.paramStringMock }, deleteId: function (...args) { console.warn("ability.dataUriUtils.deleteId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") return paramMock.paramStringMock }, updateId: function (...args) { console.warn("ability.dataUriUtils.updateId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") return paramMock.paramStringMock } } @@ -1372,7 +1372,7 @@ export function mockAbilityAbilityAgent() { global.systemplugin.ability.abilityAgent = { on: function (...args) { console.warn("ability.abilityAgent.on interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { if (args[0] == 'message') { @@ -1384,7 +1384,7 @@ export function mockAbilityAbilityAgent() { }, off: function (...args) { console.warn("ability.abilityAgent.off interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { if (args[0] == 'message') { @@ -1396,7 +1396,7 @@ export function mockAbilityAbilityAgent() { }, postMessage: function (...args) { console.warn("ability.abilityAgent.postMessage interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -1415,7 +1415,7 @@ export function mockAbilityFormBindingData() { global.systemplugin.ability.formBindingData = { createFormBindingData: function (...args) { console.warn("ability.formBindingData.createFormBindingData interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") return FormBindingDataMock; } } diff --git a/runtime/main/extend/systemplugin/accessibility.js b/runtime/main/extend/systemplugin/accessibility.js index 5fa49283..9d478af2 100644 --- a/runtime/main/extend/systemplugin/accessibility.js +++ b/runtime/main/extend/systemplugin/accessibility.js @@ -1,244 +1,199 @@ -import { paramMock } from "./utils" +import {paramMock} from './utils'; export function mockAccessibility() { const AbilitySubTypeMock = { UNSPECIFIED: 0, - CA: 1, - } + CA: 1 + }; const DisplayOrientationMock = { UNSPECIFIED: 1, LANDSCAPE: 2, PORTRAIT: 3, - FOLLOWRECENT: 4, - } + FOLLOWRECENT: 4 + }; const LaunchModeMock = { SINGLETON: 0, - STANDARD: 1, - } + STANDARD: 1 + }; const ApplicationInfoMock = { - name: "[PC Preview] unknow name", - description: "[PC Preview] unknow description", - descriptionId: "[PC Preview] unknow descriptionId", - systemApp: "[PC Preview] unknow systemApp", - enabled: "[PC Preview] unknow enabled", - label: "[PC Preview] unknow label", - labelId: "[PC Preview] unknow labelId", - icon: "[PC Preview] unknow icon", - iconId: "[PC Preview] unknow iconId", - process: "[PC Preview] unknow process", - supportedModes: "[PC Preview] unknow supportedModes", - moduleSourceDirs: "[PC Preview] unknow moduleSourceDirs", - permissions: "[PC Preview] unknow permissions", - permissions: "[PC Preview] unknow permissions", - flags: "[PC Preview] unknow flags", - entryDir: "[PC Preview] unknow entryDir", - } + name: '[PC Preview] unknow name', + description: '[PC Preview] unknow description', + descriptionId: '[PC Preview] unknow descriptionId', + systemApp: '[PC Preview] unknow systemApp', + enabled: '[PC Preview] unknow enabled', + label: '[PC Preview] unknow label', + labelId: '[PC Preview] unknow labelId', + icon: '[PC Preview] unknow icon', + iconId: '[PC Preview] unknow iconId', + process: '[PC Preview] unknow process', + supportedModes: '[PC Preview] unknow supportedModes', + moduleSourceDirs: '[PC Preview] unknow moduleSourceDirs', + permissions: '[PC Preview] unknow permissions', + permissions: '[PC Preview] unknow permissions', + flags: '[PC Preview] unknow flags', + entryDir: '[PC Preview] unknow entryDir' + }; const AbilityInfoMock = { - bundleName: "[PC Preview] unknow bundleName", - name: "[PC Preview] unknow name", - label: "[PC Preview] unknow label", - description: "[PC Preview] unknow description", - icon: "[PC Preview] unknow icon", - labelId: "[PC Preview] unknow labelId", - descriptionId: "[PC Preview] unknow descriptionId", - moduleName: "[PC Preview] unknow moduleName", - iconId: "[PC Preview] unknow iconId", - process: "[PC Preview] unknow process", - targetAbility: "[PC Preview] unknow targetAbility", - backgroundModes: "[PC Preview] unknow backgroundModes", - isVisible: "[PC Preview] unknow isVisible", - formEnabled: "[PC Preview] unknow formEnabled", + bundleName: '[PC Preview] unknow bundleName', + name: '[PC Preview] unknow name', + label: '[PC Preview] unknow label', + description: '[PC Preview] unknow description', + icon: '[PC Preview] unknow icon', + labelId: '[PC Preview] unknow labelId', + descriptionId: '[PC Preview] unknow descriptionId', + moduleName: '[PC Preview] unknow moduleName', + iconId: '[PC Preview] unknow iconId', + process: '[PC Preview] unknow process', + targetAbility: '[PC Preview] unknow targetAbility', + backgroundModes: '[PC Preview] unknow backgroundModes', + isVisible: '[PC Preview] unknow isVisible', + formEnabled: '[PC Preview] unknow formEnabled', type: AbilityTypeMock, subType: AbilitySubTypeMock, orientation: DisplayOrientationMock, launchMode: LaunchModeMock, - permissions: "[PC Preview] unknow permissions", - deviceTypes: "[PC Preview] unknow deviceTypes", - deviceCapabilities: "[PC Preview] unknow deviceCapabilities", - readPermission: "[PC Preview] unknow readPermission", - writePermission: "[PC Preview] unknow writePermission", + permissions: '[PC Preview] unknow permissions', + deviceTypes: '[PC Preview] unknow deviceTypes', + deviceCapabilities: '[PC Preview] unknow deviceCapabilities', + readPermission: '[PC Preview] unknow readPermission', + writePermission: '[PC Preview] unknow writePermission', applicationInfo: ApplicationInfoMock, - formEntity: "[PC Preview] unknow formEntity", - minFormHeight: "[PC Preview] unknow minFormHeight", - defaultFormHeight: "[PC Preview] unknow defaultFormHeight", - minFormWidth: "[PC Preview] unknow minFormWidth", - defaultFormWidth: "[PC Preview] unknow defaultFormWidth", - uri: "[PC Preview] unknow uri", - } + formEntity: '[PC Preview] unknow formEntity', + minFormHeight: '[PC Preview] unknow minFormHeight', + defaultFormHeight: '[PC Preview] unknow defaultFormHeight', + minFormWidth: '[PC Preview] unknow minFormWidth', + defaultFormWidth: '[PC Preview] unknow defaultFormWidth', + uri: '[PC Preview] unknow uri' + }; const AbilityTypeMock = { audible: 'audible', generic: 'generic', haptic: 'haptic', spoken: 'spoken', - visual: 'visual', - } + visual: 'visual' + }; const CapabilityMock = { retrieve: 'retrieve', touchGuide: 'touchGuide', keyEventObserver: 'keyEventObserver', zoom: 'zoom', - gesture: 'gesture', - } + gesture: 'gesture' + }; - const EventTypeMock = { - accessibilityFocus: 'accessibilityFocus', - accessibilityFocusClear: 'accessibilityFocusClear', - click: 'click', - longClick: 'longClick', - focus: 'focus', - select: 'select', - hoverEnter: 'hoverEnter', - hoverExit: 'hoverExit', - textUpdate: 'textUpdate', - textSelectionUpdate: 'textSelectionUpdate', - scroll: 'scroll', - } + const EventTypeMock = '[PC Preview] unknow EventType'; const AccessibilityAbilityInfoMock = { - id: "[PC Preview] unknow id", - name: "[PC Preview] unknow name", - bundleName: "[PC Preview] unknow bundleName", + id: '[PC Preview] unknow id', + name: '[PC Preview] unknow name', + bundleName: '[PC Preview] unknow bundleName', abilityInfo: AbilityInfoMock, abilityTypes: [AbilityTypeMock], capabilities: [CapabilityMock], - description: "[PC Preview] unknow description", - eventTypes: [EventTypeMock], - } + description: '[PC Preview] unknow description', + eventTypes: [EventTypeMock] + }; - const WindowUpdateTypeMock = { - add: 'add', - remove: 'remove', - title: 'title', - bounds: 'bounds', - layer: 'layer', - active: 'active', - focus: 'focus', - accessibilityFocus: 'accessibilityFocus', - parent: 'parent', - children: 'children', - pip: 'pip', - } + const WindowUpdateTypeMock = '[PC Preview] unknow WindowUpdateType'; - const ActionMock = { - accessibilityFocus: 'accessibilityFocus', - clearAccessibilityFocus: 'clearAccessibilityFocus', - focus: 'focus', - clearFocus: 'clearFocus', - clearSelection: 'clearSelection', - click: 'click', - longClick: 'longClick', - cut: 'cut', - copy: 'copy', - paste: 'paste', - select: 'select', - setText: 'setText', - delete: 'delete', - scrollForward: 'scrollForward', - scrollBackward: 'scrollBackward', - setSelection: 'setSelection', - } + const ActionMock = '[PC Preview] unknow Action'; - const TextMoveUnitMock = { - char: 'char', - word: 'word', - line: 'line', - page: 'page', - paragraph: 'paragraph' - } - - const EventInfoMock = { - type: EventTypeMock, - windowUpdateType: WindowUpdateTypeMock, - bundleName: "[PC Preview] unknow bundleName", - componentType: "[PC Preview] unknow componentType", - pageId: "[PC Preview] unknow pageId", - description: "[PC Preview] unknow description", - triggerAction: ActionMock, - textMoveUnit: TextMoveUnitMock, - contents: "[PC Preview] unknow contents", - lastContent: "[PC Preview] unknow lastContent", - beginIndex: "[PC Preview] unknow beginIndex", - currentIndex: "[PC Preview] unknow currentIndex", - endIndex: "[PC Preview] unknow endIndex", - itemCount: "[PC Preview] unknow itemCount", - } + const TextMoveUnitMock = '[PC Preview] unknow TextMoveUnit'; + const EventInfoClass = class EventInfo { + constructor(jsonObject) { + console.warn('accessibility.EventInfoClass.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.type = EventTypeMock; + this.windowUpdateType = WindowUpdateTypeMock; + this.bundleName = '[PC Preview] unknow bundleName'; + this.componentType = '[PC Preview] unknow componentType'; + this.pageId = '[PC Preview] unknow pageId'; + this.description = '[PC Preview] unknow description'; + this.triggerAction = ActionMock; + this.textMoveUnit = TextMoveUnitMock; + this.contents = '[PC Preview] unknow contents'; + this.lastContent = '[PC Preview] unknow lastContent'; + this.beginIndex = '[PC Preview] unknow beginIndex'; + this.currentIndex = '[PC Preview] unknow currentIndex'; + this.endIndex = '[PC Preview] unknow endIndex'; + this.itemCount = '[PC Preview] unknow itemCount'; + } + }; + const StateEventMock = { + eventType: '[PC Preview] unknow eventType', + state: '[PC Preview] unknow state', + description: '[PC Preview] unknow description' + }; global.systemplugin.accessibility = { - isOpenAccessibility: function (...args) { - console.warn("accessibility.isOpenAccessibility 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 + EventInfo: EventInfoClass, + isOpenAccessibility: function(...args) { + console.warn('accessibility.isOpenAccessibility 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramBooleanMock); - }) + }); } }, - isOpenTouchGuide: function (...args) { - console.warn("accessibility.isOpenTouchGuide 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 + isOpenTouchGuide: function(...args) { + console.warn('accessibility.isOpenTouchGuide 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); } else { return new Promise((resolve) => { resolve(paramMock.paramBooleanMock); - }) + }); } }, - on: function (...args) { - console.warn("accessibility.on 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 - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + on: function(...args) { + console.warn('accessibility.on 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; + args[len - 1].call(this, paramMock.businessErrorMock, StateEventMock); }, - off: function (...args) { - console.warn("accessibility.off 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) { - return - } - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + off: function(...args) { + console.warn('accessibility.off 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, StateEventMock); } else { - return + return; } }, - getAbilityLists: function (...args) { - console.warn("accessibility.getAbilityLists 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 + getAbilityLists: function(...args) { + console.warn('accessibility.getAbilityLists 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [AccessibilityAbilityInfoMock]) + args[len - 1].call(this, paramMock.businessErrorMock, [AccessibilityAbilityInfoMock]); } else { return new Promise((resolve, reject) => { resolve([AccessibilityAbilityInfoMock]); - }) + }); } }, - sendEvent: function (...args) { - console.warn("accessibility.sendEvent 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 === 1 && args[0].className === 'EventInfo') { - return - } else if (len === 2 && args[0].className === 'EventInfo' && typeof args[1] === 'function') { - args[1].call(this, paramMock.businessErrorMock, EventInfoMock) - } else if (len === 2 && typeof args[0] === 'string' && typeof args[1] === 'function') { - args[1].call(this, paramMock.businessErrorMock) + sendEvent: function(...args) { + console.warn('accessibility.sendEvent 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); } else { return new Promise((resolve, reject) => { resolve(); - }) + }); } - }, - } + } + }; } diff --git a/runtime/main/extend/systemplugin/calendar.js b/runtime/main/extend/systemplugin/calendar.js index 25d508c9..cd84afd1 100644 --- a/runtime/main/extend/systemplugin/calendar.js +++ b/runtime/main/extend/systemplugin/calendar.js @@ -1,166 +1,379 @@ -import {paramMock} from "./utils" +import {paramMock} from './utils'; export function mockCalendar() { - const arr = ["accId", "availableStatus", "syncId", "description", "duration", - "endTimezone", "eventColour", "eventColourIndex", "eventEndTime", "eventPosition", "eventStartTime", "eventStatus", - "initialId", "recurDate", "recurRule", "startTimezone", "title", "hasAlarm", "hasAttendeeInfo", "isWholeDay"] - const infoMock = { - isDeleted: "[PC preview] unknown isDeleted", - isUpdated: "[PC preview] unknown isUpdated", - isInsert: "[PC preview] unknown isInsert", - number: "[PC preview] unknown number", + const CalendarEntityClass = class CalendarEntity { + constructor() { + console.warn('calendar.CalendarEntity.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.id = '[PC preview] unknown id'; } - const event1 = { - accId: "[PC preview] unknown accId", - availableStatus: "[PC preview] unknown availableStatus", - syncId: "[PC preview] unknown syncId", - description: "[PC preview] unknown description", - duration: "[PC preview] unknown duration", - endTimezone: "[PC preview] unknown endTimezone", - eventColour: "[PC preview] unknown eventColour", - eventColourIndex: "[PC preview] unknown eventColourIndex", - eventEndTime: "[PC preview] unknown eventEndTime", - eventPosition: "[PC preview] unknown eventPosition", - eventStartTime: "[PC preview] unknown eventStartTime", - eventStatus: "[PC preview] unknown eventStatus", - initialId: "[PC preview] unknown initialId", - recurDate: "[PC preview] unknown recurDate", - recurRule: "[PC preview] unknown recurRule", - startTimezone: "[PC preview] unknown startTimezone", - title: "[PC preview] unknown title", - hasAlarm: "[PC preview] unknown hasAlarm", - hasAttendeeInfo: "[PC preview] unknown hasAttendeeInfo", - isWholeDay: "[PC preview] unknown isWholeDay", + }; + CalendarEntityClass.ACC_TYPE_LOCAL = 'LOCAL'; + CalendarEntityClass.IS_SYNC_ADAPTER = 'caller_is_syncadapter'; + const AccountsClass = class Accounts extends CalendarEntityClass { + constructor() { + super(); + console.warn('calendar.Accounts.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.name = '[PC preview] unknown name'; + this.accName = '[PC preview] unknown accName'; + this.accType = '[PC preview] unknown accType'; + this.accColour = '[PC preview] unknown accColour'; + this.accDisplayName = '[PC preview] unknown accDisplayName'; + this.visible = '[PC preview] unknown visible'; + this.accTimezone = '[PC preview] unknown accTimezone'; + this.isSyncEvents = '[PC preview] unknown isSyncEvents'; + this.remindersType = '[PC preview] unknown remindersType'; + this.attendeeTypes = '[PC preview] unknown attendeeTypes'; } - - const helper = { - queryEntityName: "[PC preview] unknown queryEntityName", + }; + AccountsClass.NAME = 'name'; + const EventsClass = class Events extends CalendarEntityClass { + constructor() { + super(); + console.warn('calendar.Events.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.accId = '[PC preview] unknown accId'; + this.title = '[PC preview] unknown title'; + this.description = '[PC preview] unknown description'; + this.eventPosition = '[PC preview] unknown eventPosition'; + this.eventStatus = '[PC preview] unknown eventStatus'; + this.eventStartTime = '[PC preview] unknown eventStartTime'; + this.eventEndTime = '[PC preview] unknown eventEndTime'; + this.duration = '[PC preview] unknown duration'; + this.isWholeDay = '[PC preview] unknown isWholeDay'; + this.availableStatus = '[PC preview] unknown availableStatus'; + this.hasAlarm = '[PC preview] unknown hasAlarm'; + this.recurRule = '[PC preview] unknown recurRule'; + this.recurDate = '[PC preview] unknown recurDate'; + this.initialId = '[PC preview] unknown initialId'; + this.hasAttendeeInfo = '[PC preview] unknown hasAttendeeInfo'; } - - const CalendarCollectionMock = { - handler: "[PC preview] unknown handler", - count: function (...args) { - console.warn("calendar.CalendarCollection.count interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramNumberMock; - }, - next: function (...args) { - console.warn("calendar.CalendarCollection.next interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return infoMock.event1; - }, - close: function (...args) { - console.warn("calendar.CalendarCollection.close interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - hasNext: function (...args) { - console.warn("calendar.CalendarCollection.hasNext interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; + }; + const InstancesClass = class Instances extends CalendarEntityClass { + constructor() { + super(); + console.warn('calendar.Instances.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.instanceBegin = '[PC preview] unknown instanceBegin'; + this.instanceEnd = '[PC preview] unknown instanceEnd'; + this.eventId = '[PC preview] unknown eventId'; + this.instanceStartDay = '[PC preview] unknown instanceStartDay'; + this.instanceEndDay = '[PC preview] unknown instanceEndDay'; + this.instanceStartMinute = '[PC preview] unknown instanceStartMinute'; + this.instanceEndMinute = '[PC preview] unknown instanceEndMinute'; + } + }; + const ParticipantsClass = class Participants extends CalendarEntityClass { + constructor() { + super(); + console.warn('calendar.Participants.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.eventId = '[PC preview] unknown eventId'; + this.participantName = '[PC preview] unknown participantName'; + this.participantEmail = '[PC preview] unknown participantEmail'; + this.participantRoleType = '[PC preview] unknown participantRoleType'; + this.participantType = '[PC preview] unknown participantType'; + this.participantStatus = '[PC preview] unknown participantStatus'; + } + }; + const RemindersClass = class Reminders extends CalendarEntityClass { + constructor() { + super(); + console.warn('calendar.Reminders.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.eventId = '[PC preview] unknown eventId'; + this.remindMinutes = '[PC preview] unknown remindMinutes'; + this.remindType = '[PC preview] unknown remindType'; + this.syncId = '[PC preview] unknown syncId'; + } + }; + const AppletEntityClass = class AppletEntity { + constructor() { + console.warn('calendar.AppletEntity.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.title = '[PC preview] unknown title'; + this.startTime = '[PC preview] unknown startTime'; + this.allDay = '[PC preview] unknown allDay'; + this.description = '[PC preview] unknown description'; + this.location = '[PC preview] unknown location'; + this.endTime = '[PC preview] unknown endTime'; + this.alarm = '[PC preview] unknown alarm'; + this.alarmOffset = '[PC preview] unknown alarmOffset'; + this.repeatInterval = '[PC preview] unknown repeatInterval'; + this.repeatEndTime = '[PC preview] unknown repeatEndTime'; + } + }; + const AppletRepeatEntityClass = class AppletRepeatEntity extends AppletEntityClass { + constructor() { + super(); + console.warn('calendar.AppletRepeatEntity.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.repeatInterval = '[PC preview] unknown repeatInterval'; + this.repeatEndTime = '[PC preview] unknown repeatEndTime'; + } + }; + const CalendarCollectionClass = class CalendarCollection { + constructor() { + this.handler = '[PC preview] unknown handler'; + this.close = function (...args) { + console.warn('calendar.CalendarCollection.close interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + }; + this.count = function (...args) { + console.warn('calendar.CalendarCollection.count interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return paramMock.paramNumberMock; + }; + this.next = function (...args) { + console.warn('calendar.CalendarCollection.next interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new CalendarEntityClass(); + }; + this.hasNext = function (...args) { + console.warn('calendar.CalendarCollection.hasNext interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return paramMock.paramBooleanMock; + }; + } + }; + const CalendarDataHelperClass = class CalendarDataHelper { + constructor() { + this.name = '[PC preview] unknown queryEntityName'; + this.query = function (...args) { + console.warn('calendar.CalendarDataHelper.query 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new CalendarCollectionClass()); + } else { + return new Promise((resolve) => { + resolve(new CalendarCollectionClass()); + }); } - } - - global.systemplugin.calendar = { - addPhoneCalendar: function (...args) { - console.warn("calendar.addPhoneCalendar 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve() - }); - } - }, - addPhoneRepeatCalendar: function (...args) { - console.warn("calendar.addPhoneRepeatCalendar 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve() - }); - } - }, - CalendarDataHelper: { - name: '[PC preview] unknown queryEntityName', - creator: function (...args) { - console.warn("calendar.CalendarDataHelper.creator interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return global.systemplugin.calendar.CalendarDataHelper; - }, - query: function (...args) { - console.warn("calendar.CalendarDataHelper.query 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, CalendarCollectionMock) - } else { - return new Promise((resolve) => { - resolve(CalendarCollectionMock) - }); - } - }, - delete: function (...args) { - console.warn("calendar.CalendarDataHelper.delete 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 (!Array.prototype.subsetTo) { - Array.prototype.subsetTo = function (arr) { - return this.every(v => arr.includes(v)); - } - } - if (typeof args[len - 1] === 'function') { - if (typeof args[len - 2] === 'number') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else if (Object.getOwnPropertyNames(args[len - 2]).subsetTo(arr)) { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - args[len - 1].call(this, paramMock.businessErrorMock, infoMock.number); - } - } else { - if (typeof args(len - 1) === 'number') { - return new Promise((resolve) => { - resolve() - }); - } else if (Object.getOwnPropertyNames(args[len - 1]).subsetTo(arr)) { - return new Promise((resolve) => { - resolve() - }); - } else { - return new Promise((resolve) => { - resolve(infoMock.number) - }); - } - } - }, - update: function (...args) { - console.warn("calendar.CalendarDataHelper.update 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, infoMock.isUpdated) - } else { - return new Promise((resolve) => { - resolve(infoMock.isUpdated) - }); - } - }, - insert: function (...args) { - console.warn("calendar.CalendarDataHelper.insert 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, infoMock.isInsert) - } else { - return new Promise((resolve) => { - resolve(infoMock.isInsert) - }); - } - }, + }; + this.insert = function (...args) { + console.warn('calendar.CalendarDataHelper.insert 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }); } + }; + this.update = function (...args) { + console.warn('calendar.CalendarDataHelper.update 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }; + this.delete = function (...args) { + console.warn('calendar.CalendarDataHelper.delete 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 (typeof args[len - 1] === 'function') { + if (typeof args[0] === 'number') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] instanceof CalendarEntityClass) { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } + } else { + if (typeof args[0] === 'number') { + return new Promise((resolve) => { + resolve(); + }); + } else if (args[0] instanceof CalendarEntityClass) { + return new Promise((resolve) => { + resolve(); + }); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramNumberMock); + }); + } + } + }; } -} \ No newline at end of file + }; + CalendarDataHelperClass.creator = function (...args) { + console.warn('calendar.CalendarDataHelper.creator interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new CalendarDataHelperClass(); + }; + global.systemplugin.calendar = { + BaseColumns: { + COUNT: "_count", + ID: "_id" + }, + AccountColumns: { + ACC_COLOR: "calendar_color", + ACC_COLOR_INDEX: "calendar_color_index", + ACC_DISPLAY_NAME: "calendar_displayName", + VISIBLE: "visible", + ACC_TIME_ZONE: "calendar_timezone", + IS_SYNC_EVENTS: "sync_events", + REMINDERS_TYPE: "allowedReminders", + AVAILABILITY_STATUS: "allowedAvailability", + ATTENDEE_TYPES: "allowedAttendeeTypes", + IS_PRIMARY: "isPrimary" + }, + AccountSyncColumns: { + ACC_SYNC1: "cal_sync1", + ACC_SYNC2: "cal_sync2", + ACC_SYNC3: "cal_sync3", + ACC_SYNC4: "cal_sync4", + ACC_SYNC5: "cal_sync5", + ACC_SYNC6: "cal_sync6", + ACC_SYNC7: "cal_sync7", + ACC_SYNC8: "cal_sync8", + ACC_SYNC9: "cal_sync9", + ACC_SYNC10: "cal_sync10" + }, + EventsColumns: { + ACC_ID: "calendar_id", + TITLE: "title", + DESCRIPTION: "description", + EVENT_POSITION: "eventLocation", + EVENT_STATUS: "eventStatus", + EVENT_STATUS_TENTATIVE: 0, + EVENT_STATUS_CONFIRMED: 1, + EVENT_STATUS_CANCELED: 2, + OWNER_ATTENDEE_STATUS: "selfAttendeeStatus", + EXTEND_DATA1: "sync_data1", + EXTEND_DATA2: "sync_data2", + EXTEND_DATA3: "sync_data3", + EXTEND_DATA4: "sync_data4", + EXTEND_DATA5: "sync_data5", + EXTEND_DATA6: "sync_data6", + D_DATA7: "sync_data7", + EXTEND_DATA8: "sync_data8", + EXTEND_DATA9: "sync_data9", + EXTEND_DATA10: "sync_data10", + EVENT_START_TIME: "dtstart", + EVENT_END_TIME: "dtend", + DURATION: "duration", + START_TIMEZONE: "eventTimezone", + END_TIMEZONE: "eventEndTimezone", + IS_WHOLE_DAY: "allDay", + PERMISSION_LEVEL: "accessLevel", + PERMISSION_DEFAULT: 0, + PERMISSION_CONFIDENTIAL: 1, + PERMISSION_PRIVATE: 2, + PERMISSION_PUBLIC: 3, + AVAILABLE_STATUS: "availability", + STATUS_BUSY: 0, + STATUS_FREE: 1, + STATUS_TENTATIVE: 2, + HAS_ALARM: "hasAlarm", + HAS_EXTENDED_ATTRIBUTES: "hasExtendedProperties", + RECUR_RULE: "rrule", + RECUR_DATE: "rdate", + INITIAL_ID: "original_id", + INITIAL_SYNC_ID: "original_sync_id", + HAS_ATTENDEE_INFO: "hasAttendeeData", + ORGANIZER_EMAIL: "organizer" + }, + InstancesColumns: { + EVENT_ID: "event_id", + INSTANCE_START: "begin", + INSTANCE_END: "end", + INSTANCE_START_DAY: "startDay", + INSTANCE_END_DAY: "endDay", + INSTANCE_START_MINUTE: "startMinute", + INSTANCE_END_MINUTE: "endMinute" + }, + ParticipantsColumns: { + EVENT_ID: "event_id", + PARTICIPANT_NAME: "attendeeName", + PARTICIPANT_EMAIL: "attendeeEmail", + PARTICIPANT_ROLE_TYPE: "attendeeRelationship", + ROLE_NONE: 0, + ROLE_ATTENDEE: 1, + ROLE_ORGANIZER: 2, + ROLE_PERFORMER: 3, + ROLE_SPEAKER: 4, + PARTICIPANT_TYPE: "attendeeType", + TYPE_NONE: 0, + TYPE_REQUIRED: 1, + TYPE_OPTIONAL: 2, + TYPE_RESOURCE: 3, + PARTICIPANT_STATUS: "attendeeStatus", + PARTICIPANT_STATUS_NONE: 0, + PARTICIPANT_STATUS_ACCEPTED: 1, + PARTICIPANT_STATUS_DECLINED: 2, + PARTICIPANT_STATUS_INVITED: 3, + PARTICIPANT_STATUS_TENTATIVE: 4 + }, + RemindersColumns: { + EVENT_ID: "event_id", + REMIND_MINUTES: "minutes", + REMIND_MINUTES_DEFAULT: -1, + REMIND_TYPE: "method", + TYPE_DEFAULT: 0, + TYPE_ALERT: 1, + TYPE_EMAIL: 2, + TYPE_SMS: 3, + TYPE_ALARM: 4 + }, + SyncColumns: { + ACC_NAME: "account_name", + ACC_TYPE: "account_type", + SYNC_ID: "_sync_id", + DIRTY: "dirty", + CALLING_BUNDLE_NAME: "mutators", + DELETED: "deleted" + }, + queryEntityName: { + EVENTS: "EVENTS", + ACCOUNTS: "ACCOUNTS", + INSTANCES: "INSTANCES", + PARTICIPANTS: "PARTICIPANTS", + REMINDERS: "REMINDERS" + }, + CalendarEntity: CalendarEntityClass, + Accounts: AccountsClass, + Events: EventsClass, + Instances: InstancesClass, + Participants: ParticipantsClass, + Reminders: RemindersClass, + AppletEntity: AppletEntityClass, + AppletRepeatEntity: AppletRepeatEntityClass, + CalendarCollection: CalendarCollectionClass, + CalendarDataHelper: CalendarDataHelperClass, + addPhoneCalendar: function (...args) { + console.warn('calendar.addPhoneCalendar 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + addPhoneRepeatCalendar: function (...args) { + console.warn('calendar.addPhoneRepeatCalendar 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + } + }; +} diff --git a/runtime/main/extend/systemplugin/contact.js b/runtime/main/extend/systemplugin/contact.js index 603f63e5..ba6cef93 100644 --- a/runtime/main/extend/systemplugin/contact.js +++ b/runtime/main/extend/systemplugin/contact.js @@ -1,216 +1,440 @@ -import { paramMock } from "./utils" +import {paramMock} from "./utils" -export function mockContact () { - const contactMock = { - contactAttributes:"[PC Preview] unknow contactAttributes", - id:"[PC Preview] unknow id", - key:"[PC Preview] unknow key", - emails:"[PC Preview] unknow emails", - events:"[PC Preview] unknow events", - groups:"[PC Preview] unknow groups", - imAddresses:"[PC Preview] unknow imAddresses", - phoneNumbers:"[PC Preview] unknow phoneNumbers", - portrait:"[PC Preview] unknow portrait", - postalAddresses:"[PC Preview] unknow postalAddresses", - relations:"[PC Preview] unknow relations", - sipAddresses:"[PC Preview] unknow sipAddresses", - websites:"[PC Preview] unknow websites", - name:"[PC Preview] unknow name", - nickName:"[PC Preview] unknow nickName", - note:"[PC Preview] unknow note", - organization:"[PC Preview] unknow organization", +export function mockContact() { + const ContactClass = class Contact { + constructor() { + console.warn('contact.Contact.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.id = "[PC Preview] unknow id"; + this.key = "[PC Preview] unknow key"; + this.contactAttributes = "[PC Preview] unknow contactAttributes"; + this.emails = "[PC Preview] unknow emails"; + this.events = "[PC Preview] unknow events"; + this.groups = "[PC Preview] unknow groups"; + this.imAddresses = "[PC Preview] unknow imAddresses"; + this.phoneNumbers = "[PC Preview] unknow phoneNumbers"; + this.portrait = "[PC Preview] unknow portrait"; + this.postalAddresses = "[PC Preview] unknow postalAddresses"; + this.relations = "[PC Preview] unknow relations"; + this.sipAddresses = "[PC Preview] unknow sipAddresses"; + this.websites = "[PC Preview] unknow websites"; + this.name = "[PC Preview] unknow name"; + this.nickName = "[PC Preview] unknow nickName"; + this.note = "[PC Preview] unknow note"; + this.organization = "[PC Preview] unknow organization"; } - const holderMock = { - holderId:"[PC Preview] unknow holderId", - bundleName:"[PC Preview] unknow bundleName", - displayName:"[PC Preview] unknow displayName", + } + const ContactAttributesClass = class ContactAttributes { + constructor() { + console.warn('contact.ContactAttributes.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.attributes = ["[PC Preview] unknow Attribute"] } - const groupMock = { - groupId:"[PC Preview] unknow groupId", - title:"[PC Preview] unknow title" + } + const EmailClass = class Email { + constructor() { + console.warn('contact.Email.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.CUSTOM_LABEL = 0; + this.EMAIL_HOME = 1; + this.EMAIL_WORK = 2; + this.EMAIL_OTHER = 3; + this.INVALID_LABEL_ID = -1; + this.email = "[PC Preview] unknow email"; + this.labelName = "[PC Preview] unknow labelName"; + this.displayName = "[PC Preview] unknow displayName"; + this.labelId = "[PC Preview] unknow labelId"; } - global.systemplugin.contact = { - addContact: function (...args) { - console.warn("contact.addContact 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramNumberMock) - }); - } - }, - selectContact: function (...args) { - console.warn("contact.selectContact interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - var array = new Array(); - array.push(contactMock); - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, array) - } else { - return new Promise((resolve) => { - resolve(array) - }); - } - }, - deleteContact: function (...args) { - console.warn("contact.deleteContact 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve() - }); - } - }, - queryContact: function (...args) { - console.warn("contact.queryContact 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, contactMock) - } else { - return new Promise((resolve) => { - resolve(contactMock) - }); - } - }, - queryContacts: function (...args) { - console.warn("contact.queryContacts interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - var array = new Array(); - array.push(contactMock); - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, array) - } else { - return new Promise((resolve) => { - resolve(array) - }); - } - }, - queryContactsByEmail: function (...args) { - console.warn("contact.queryContactsByEmail interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - var array = new Array(); - array.push(contactMock); - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, array) - } else { - return new Promise((resolve) => { - resolve(array) - }); - } - }, - queryContactsByPhoneNumber: function (...args) { - console.warn("contact.queryContactsByPhoneNumber interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - var array = new Array(); - array.push(contactMock); - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, array) - } else { - return new Promise((resolve) => { - resolve(array) - }); - } - }, - queryGroups: function (...args) { - console.warn("contact.queryGroups interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - var array = new Array(); - array.push(groupMock); - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, array) - } else { - return new Promise((resolve) => { - resolve(array) - }); - } - }, - queryHolders: function (...args) { - console.warn("contact.queryHolders interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - var array = new Array(); - array.push(holderMock); - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, array) - } else { - return new Promise((resolve) => { - resolve(array) - }); - } - }, - queryKey: function (...args) { - console.warn("contact.queryKey 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramStringMock) - }); - } - }, - queryMyCard: function (...args) { - console.warn("contact.queryMyCard interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - var array = new Array(); - array.push(contactMock); - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, array) - } else { - return new Promise((resolve) => { - resolve(array) - }); - } - }, - updateContact: function (...args) { - console.warn("contact.updateContact 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve() - }); - } - }, - isLocalContact: function (...args) { - console.warn("contact.isLocalContact 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock) - }); - } - }, - isMyCard: function (...args) { - console.warn("contact.isMyCard 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock) - }); - } - } + } + const EventClass = class Event { + constructor() { + console.warn('contact.Event.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.CUSTOM_LABEL = 0; + this.EVENT_ANNIVERSARY = 1; + this.EVENT_OTHER = 2; + this.EVENT_BIRTHDAY = 3; + this.INVALID_LABEL_ID = -1; + this.eventDate = "[PC Preview] unknow eventDate"; + this.labelName = "[PC Preview] unknow labelName"; + this.labelId = "[PC Preview] unknow labelId"; } -} \ No newline at end of file + } + const GroupClass = class Group { + constructor() { + console.warn('contact.Group.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.groupId = "[PC Preview] unknow groupId"; + this.title = "[PC Preview] unknow title"; + } + } + const HolderClass = class Holder { + constructor() { + console.warn('contact.Holder.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.bundleName = "[PC Preview] unknow bundleName"; + this.displayName = "[PC Preview] unknow displayName"; + this.holderId = "[PC Preview] unknow holderId"; + } + } + const ImAddressClass = class ImAddress { + constructor() { + console.warn('contact.ImAddress.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.CUSTOM_LABEL = -1; + this.IM_AIM = 0; + this.IM_MSN = 1; + this.IM_YAHOO = 2; + this.IM_SKYPE = 3; + this.IM_QQ = 4; + this.IM_ICQ = 6; + this.IM_JABBER = 7; + this.INVALID_LABEL_ID = -2; + this.imAddress = "[PC Preview] unknow imAddress"; + this.labelName = "[PC Preview] unknow labelName"; + this.labelId = "[PC Preview] unknow labelId"; + } + } + const NameClass = class Name { + constructor() { + console.warn('contact.Name.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.familyName = "[PC Preview] unknow familyName"; + this.familyNamePhonetic = "[PC Preview] unknow familyNamePhonetic"; + this.fullName = "[PC Preview] unknow fullName"; + this.givenName = "[PC Preview] unknow givenName"; + this.givenNamePhonetic = "[PC Preview] unknow givenNamePhonetic"; + this.middleNamePhonetic = "[PC Preview] unknow middleNamePhonetic"; + this.namePrefix = "[PC Preview] unknow namePrefix"; + this.nameSuffix = "[PC Preview] unknow nameSuffix"; + } + } + const NickNameClass = class NickName { + constructor() { + console.warn('contact.NickName.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.nickName = "[PC Preview] unknow nickName"; + } + } + const NoteClass = class Note { + constructor() { + console.warn('contact.Note.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.noteContent = "[PC Preview] unknow noteContent"; + } + } + const OrganizationClass = class Organization { + constructor() { + console.warn('contact.Organization.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.name = "[PC Preview] unknow name"; + this.title = "[PC Preview] unknow title"; + } + } + const PhoneNumberClass = class PhoneNumber { + constructor() { + console.warn('contact.PhoneNumber.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.CUSTOM_LABEL = 0; + this.NUM_HOME = 1; + this.NUM_MOBILE = 2; + this.NUM_WORK = 3; + this.NUM_FAX_WORK = 4; + this.NUM_FAX_HOME = 5; + this.NUM_PAGER = 6; + this.NUM_OTHER = 7; + this.NUM_CALLBACK = 8; + this.NUM_CAR = 9; + this.NUM_COMPANY_MAIN = 10; + this.NUM_ISDN = 11; + this.NUM_MAIN = 12; + this.NUM_OTHER_FAX = 13; + this.NUM_RADIO = 14; + this.NUM_TELEX = 15; + this.NUM_TTY_TDD = 16; + this.NUM_WORK_MOBILE = 17; + this.NUM_WORK_PAGER = 18; + this.NUM_ASSISTANT = 19; + this.NUM_MMS = 20; + this.INVALID_LABEL_ID = -1; + this.phoneNumber = "[PC Preview] unknow phoneNumber"; + this.labelName = "[PC Preview] unknow labelName"; + this.labelId = "[PC Preview] unknow labelId"; + } + } + const PortraitClass = class Portrait { + constructor() { + console.warn('contact.Portrait.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.uri = "[PC Preview] unknow uri"; + } + } + const PostalAddressClass = class PostalAddress { + constructor() { + console.warn('contact.PostalAddress.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.CUSTOM_LABEL = 0; + this.ADDR_HOME = 1; + this.ADDR_WORK = 2; + this.ADDR_OTHER = 3; + this.INVALID_LABEL_ID = -1; + this.city = "[PC Preview] unknow city"; + this.country = "[PC Preview] unknow country"; + this.labelName = "[PC Preview] unknow labelName"; + this.neighborhood = "[PC Preview] unknow neighborhood"; + this.pobox = "[PC Preview] unknow pobox"; + this.postalAddress = "[PC Preview] unknow postalAddress"; + this.postcode = "[PC Preview] unknow postcode"; + this.region = "[PC Preview] unknow region"; + this.street = "[PC Preview] unknow street"; + this.labelId = "[PC Preview] unknow labelId"; + } + } + const RelationClass = class Relation { + constructor() { + console.warn('contact.Relation.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.CUSTOM_LABEL = 0; + this.RELATION_ASSISTANT = 1; + this.RELATION_BROTHER = 2; + this.RELATION_CHILD = 3; + this.RELATION_DOMESTIC_PARTNER = 4; + this.RELATION_FATHER = 5; + this.RELATION_FRIEND = 6; + this.RELATION_MANAGER = 7; + this.RELATION_MOTHER = 8; + this.RELATION_PARENT = 9; + this.RELATION_PARTNER = 10; + this.RELATION_REFERRED_BY = 11; + this.RELATION_RELATIVE = 12; + this.RELATION_SISTER = 13; + this.RELATION_SPOUSE = 14; + this.INVALID_LABEL_ID = -1; + this.relationName = "[PC Preview] unknow relationName"; + this.labelName = "[PC Preview] unknow labelName"; + this.labelId = "[PC Preview] unknow labelId"; + } + } + const SipAddressClass = class SipAddress { + constructor() { + console.warn('contact.SipAddress.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.CUSTOM_LABEL = 0; + this.SIP_HOME = 1; + this.SIP_WORK = 2; + this.SIP_OTHER = 3; + this.INVALID_LABEL_ID = -1; + this.sipAddress = "[PC Preview] unknow sipAddress"; + this.labelName = "[PC Preview] unknow labelName"; + this.labelId = "[PC Preview] unknow labelId"; + } + } + const WebsiteClass = class Website { + constructor() { + console.warn('contact.Website.constructor interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + this.website = "[PC Preview] unknow website"; + } + } + global.systemplugin.contact = { + Contact: ContactClass, + ContactAttributes: ContactAttributesClass, + Email: EmailClass, + Event: EventClass, + Group: GroupClass, + Holder: HolderClass, + ImAddress: ImAddressClass, + Name: NameClass, + NickName: NickNameClass, + Note: NoteClass, + Organization: OrganizationClass, + PhoneNumber: PhoneNumberClass, + Portrait: PortraitClass, + PostalAddress: PostalAddressClass, + Relation: RelationClass, + SipAddress: SipAddressClass, + Website: WebsiteClass, + addContact: function (...args) { + console.warn("contact.addContact 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramNumberMock) + }); + } + }, + selectContact: function (...args) { + console.warn("contact.selectContact interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(new ContactClass()); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + deleteContact: function (...args) { + console.warn("contact.deleteContact 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + queryContact: function (...args) { + console.warn("contact.queryContact 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new ContactClass()) + } else { + return new Promise((resolve) => { + resolve(new ContactClass()) + }); + } + }, + queryContacts: function (...args) { + console.warn("contact.queryContacts interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(new ContactClass()); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryContactsByEmail: function (...args) { + console.warn("contact.queryContactsByEmail interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(new ContactClass()); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryContactsByPhoneNumber: function (...args) { + console.warn("contact.queryContactsByPhoneNumber interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(new ContactClass()); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryGroups: function (...args) { + console.warn("contact.queryGroups interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(new GroupClass()); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryHolders: function (...args) { + console.warn("contact.queryHolders interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(new HolderClass()); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryKey: function (...args) { + console.warn("contact.queryKey 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramStringMock) + }); + } + }, + queryMyCard: function (...args) { + console.warn("contact.queryMyCard interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(new ContactClass()); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + updateContact: function (...args) { + console.warn("contact.updateContact 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + isLocalContact: function (...args) { + console.warn("contact.isLocalContact 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + isMyCard: function (...args) { + console.warn("contact.isMyCard 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + } + } +} diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index 6a965be6..1d72eb48 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -62,7 +62,7 @@ import { mockSystemPackage } from './systemPackage' import { mockUserauth } from './userIAM' import { mockVibrator } from './vibrator' -import { mockWebSocket, mockHttp, mockMdns, mockSocket, mockHotspot, mockStatistics } from './net' +import { mockWebSocket, mockHttp, mockMdns, mockSocket, mockHotspot, mockStatistics, mockConnection } from './net' import { mockWifi } from './ohos/wifi' import { mockWindow } from './window' import { mockWorkScheduler } from './ohos/workScheduler' @@ -139,6 +139,7 @@ export function mockSystemPlugin() { mockSocket() mockHotspot() mockStatistics() + mockConnection() mockDeviceInfo() mockWifi() mockResourceManager() diff --git a/runtime/main/extend/systemplugin/multimedia.js b/runtime/main/extend/systemplugin/multimedia.js index d0f6c409..ca870aaa 100644 --- a/runtime/main/extend/systemplugin/multimedia.js +++ b/runtime/main/extend/systemplugin/multimedia.js @@ -14,7 +14,7 @@ export const PixelMapMock = { isEditable: "[PC Preview]: unknow isEditable", readPixelsToBuffer: function (...args) { console.warn("PixelMap.readPixelsToBuffer interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -26,7 +26,7 @@ export const PixelMapMock = { }, readPixels: function (...args) { console.warn("PixelMap.readPixels interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -38,7 +38,7 @@ export const PixelMapMock = { }, writePixels: function (...args) { console.warn("PixelMap.writePixels interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -50,7 +50,7 @@ export const PixelMapMock = { }, writeBufferToPixels: function (...args) { console.warn("PixelMap.writeBufferToPixels interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -62,7 +62,7 @@ export const PixelMapMock = { }, getImageInfo: function (...args) { console.warn("PixelMap.getImageInfo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " 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, imageInfoMock); @@ -74,17 +74,17 @@ export const PixelMapMock = { }, getBytesNumberPerRow: function (...args) { console.warn("PixelMap.getBytesNumberPerRow interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramNumberMock }, getPixelBytesNumber: function (...args) { console.warn("PixelMap.getPixelBytesNumber interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") return paramMock.paramNumberMock }, release: function (...args) { console.warn("PixelMap.release interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " 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); @@ -444,6 +444,127 @@ export function mockMultimediaMedia() { } } } + const MimeTypeMock = '[PC Preview] unknow mimeType' + const CodecDescriptionMock = { + name: "[PC Preview] unknow name", + mimeTypes: new Array(MimeTypeMock), + isAudio: "[PC Preview] unknow isAudio", + isEncoder: "[PC Preview] unknow isEncoder", + isSoftware: "[PC Preview] unknow isSoftware", + } + const codecDescriptionHelperMock = { + findDecoder: function (...args) { + console.warn("CodecDescriptionHelper.findDecoder 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionMock); + } else { + return new Promise((resolve, reject) => { + resolve(CodecDescriptionMock); + }) + } + }, + findEncoder: function (...args) { + console.warn("CodecDescriptionHelper.findEncoder 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionMock); + } else { + return new Promise((resolve, reject) => { + resolve(CodecDescriptionMock); + }) + } + }, + getSupportedDecoders: function (...args) { + console.warn("CodecDescriptionHelper.getSupportedDecoders 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 + var CodecDescriptionArray = new Array(CodecDescriptionMock) + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionArray); + } else { + return new Promise((resolve, reject) => { + resolve(CodecDescriptionArray); + }) + } + }, + getSupportedEncoders: function (...args) { + console.warn("CodecDescriptionHelper.getSupportedEncoders 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 + var CodecDescriptionArray = new Array(CodecDescriptionMock) + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionArray); + } else { + return new Promise((resolve, reject) => { + resolve(CodecDescriptionArray); + }) + } + }, + getSupportedMimes: function (...args) { + console.warn("CodecDescriptionHelper.getSupportedMimes 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 + var MimeTypeArray = new Array(MimeTypeMock) + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, MimeTypeArray); + } else { + return new Promise((resolve, reject) => { + resolve(MimeTypeArray); + }) + } + }, + isDecoderSupportedByFormat: function (...args) { + console.warn("CodecDescriptionHelper.isDecoderSupportedByFormat 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isDecoderSupportedByMime: function (...args) { + console.warn("CodecDescriptionHelper.isDecoderSupportedByMime 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isEncoderSupportedByFormat: function (...args) { + console.warn("CodecDescriptionHelper.isEncoderSupportedByFormat 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isEncoderSupportedByMime: function (...args) { + console.warn("CodecDescriptionHelper.findDisEncoderSupportedByMime 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + } + } global.systemplugin.multimedia.media = { MediaType: { VIDEO: 0, @@ -468,29 +589,34 @@ export function mockMultimediaMedia() { console.warn("multimedia.media.createMediaDecoder interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") return mediaDecoderMock; + }, + getCodecDescriptionHelper: function () { + console.warn("multimedia.media.getCodecDescriptionHelper interface mocked in the Previewer. How this" + + " interface works on the Previewer may be different from that on a real device.") + return codecDescriptionHelperMock; } } } export function mockMultimediaMedialibrary() { const FileAssetMock = { - id: "[PC Preview] unknow id", - uri: "[PC Preview] unknow uri", - thumbnailUri: "[PC Preview] unknow thumbnailUri", - mimeType: "[PC Preview] unknow mimeType", - mediaType: "[PC Preview] unknow mediaType", - displayName: "[PC Preview] unknow displayName", - title: "[PC Preview] unknow title", - size: "[PC Preview] unknow size", - albumId: "[PC Preview] unknow albumId", - albumName: "[PC Preview] unknow albumName", - dateAdded: "[PC Preview] unknow dateAdded", - dateModified: "[PC Preview] unknow dateMidified", - dateTaken: "[PC Preview] unknow dateTaken", - orientation: "[PC Preview] unknow orientation", - width: "[PC Preview] unknow width", - height: "[PC Preview] unknow height", - extendedValues: "[PC Preview] unknow extendedValues", + id: "[PC Preview] unknow id", + uri: "[PC Preview] unknow uri", + thumbnailUri: "[PC Preview] unknow thumbnailUri", + mimeType: "[PC Preview] unknow mimeType", + mediaType: "[PC Preview] unknow mediaType", + displayName: "[PC Preview] unknow displayName", + title: "[PC Preview] unknow title", + size: "[PC Preview] unknow size", + albumId: "[PC Preview] unknow albumId", + albumName: "[PC Preview] unknow albumName", + dateAdded: "[PC Preview] unknow dateAdded", + dateModified: "[PC Preview] unknow dateMidified", + dateTaken: "[PC Preview] unknow dateTaken", + orientation: "[PC Preview] unknow orientation", + width: "[PC Preview] unknow width", + height: "[PC Preview] unknow height", + extendedValues: "[PC Preview] unknow extendedValues", } const MediaLibraryMock = { storeMediaAsset: function (...args) { @@ -535,7 +661,7 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FetchFileResultMock) - : new Promise((resolve, reject) => { + : new Promise((resolve, reject) => { resolve(FetchFileResultMock); }) }, @@ -546,7 +672,7 @@ export function mockMultimediaMedialibrary() { var albumsMock = new Array(AlbumMock) var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, albumsMock) - : new Promise((resolve, reject) => { + : new Promise((resolve, reject) => { resolve(albumsMock); }) }, @@ -583,7 +709,7 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock) - : new Promise((resolve, reject) => { + : new Promise((resolve, reject) => { resolve(FileAssetMock); }) }, @@ -593,7 +719,7 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock) - : new Promise((resolve, reject) => { + : new Promise((resolve, reject) => { resolve(FileAssetMock); }) }, @@ -603,7 +729,7 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock) - : new Promise((resolve, reject) => { + : new Promise((resolve, reject) => { resolve(FileAssetMock); }) }, @@ -613,7 +739,7 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock) - : new Promise((resolve, reject) => { + : new Promise((resolve, reject) => { resolve(FileAssetMock); }) }, @@ -624,7 +750,7 @@ export function mockMultimediaMedialibrary() { var fileAssets = new Array(FileAssetMock) var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, fileAssets) - : new Promise((resolve, reject) => { + : new Promise((resolve, reject) => { resolve(fileAssets); }) } @@ -640,9 +766,9 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FetchFileResultMock) - : new Promise((resolve, reject) => { - resolve(FetchFileResultMock); - }) + : new Promise((resolve, reject) => { + resolve(FetchFileResultMock); + }) } } const AVMetadataHelperMock = { @@ -652,9 +778,9 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock) - : new Promise((resolve, reject) => { - resolve(); - }) + : new Promise((resolve, reject) => { + resolve(); + }) }, fetchVideoPixelMapByTime: function (...args) { console.warn("AVMetadataHelper.fetchVideoPixelMapByTime interface mocked in the Previewer. How this interface" + @@ -662,9 +788,9 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock) - : new Promise((resolve, reject) => { - resolve(paramMock.paramObjectMock); - }) + : new Promise((resolve, reject) => { + resolve(paramMock.paramObjectMock); + }) }, resolveMetadata: function (...args) { console.warn("AVMetadataHelper.resolveMetadata interface mocked in the Previewer. How this interface" + @@ -672,9 +798,9 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) - : new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) + : new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) }, release: function (...args) { console.warn("AVMetadataHelper.release interface mocked in the Previewer. How this interface works on the" + @@ -682,9 +808,9 @@ export function mockMultimediaMedialibrary() { const len = args.length var isCallBack = typeof args[len - 1] === 'function' return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock) - : new Promise((resolve, reject) => { - resolve(); - }) + : new Promise((resolve, reject) => { + resolve(); + }) } } global.systemplugin.multimedia.mediaLibrary = { @@ -730,32 +856,32 @@ export function mockMultimediaAudio() { const AudioRingModeMock = '[PC Preview]: unknow AudioRingMode' const audioManagerMock = { on: function (...args) { - console.warn("AudioManager.on 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 (typeof args[len - 1] === 'function') { - if (args[0] == 'interrupt') { - args[len - 1].call(this, interruptActionMock); - } else if (args[0] == 'deviceChange') { - args[len - 1].call(this, DeviceChangeActionMock); - } else { - args[len - 1].call(this); - } + console.warn("AudioManager.on 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 (typeof args[len - 1] === 'function') { + if (args[0] == 'interrupt') { + args[len - 1].call(this, interruptActionMock); + } else if (args[0] == 'deviceChange') { + args[len - 1].call(this, DeviceChangeActionMock); + } else { + args[len - 1].call(this); } + } }, off: function (...args) { - console.warn("AudioManager.off 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 (typeof args[len - 1] === 'function') { - if (args[0] == 'interrupt') { - args[len - 1].call(this, interruptActionMock); - } else if (args[0] == 'deviceChange') { - args[len - 1].call(this); - } else { - args[len - 1].call(this); - } + console.warn("AudioManager.off 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 (typeof args[len - 1] === 'function') { + if (args[0] == 'interrupt') { + args[len - 1].call(this, interruptActionMock); + } else if (args[0] == 'deviceChange') { + args[len - 1].call(this); + } else { + args[len - 1].call(this); } + } }, getDevices: function (...args) { console.warn("AudioManager.getDevices interface mocked in the Previewer. How this interface works on the" + @@ -766,7 +892,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock, AudioDeviceDescriptors); } else { return new Promise((resolve, reject) => { - resolve(AudioDeviceDescriptors); + resolve(AudioDeviceDescriptors); }) } }, @@ -777,8 +903,8 @@ export function mockMultimediaAudio() { if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); }) } }, @@ -790,7 +916,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock); } else { return new Promise((resolve, reject) => { - resolve(); + resolve(); }) } }, @@ -802,7 +928,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock); } else { return new Promise((resolve, reject) => { - resolve(); + resolve(); }) } }, @@ -814,7 +940,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock); } else { return new Promise((resolve, reject) => { - resolve(); + resolve(); }) } }, @@ -825,8 +951,8 @@ export function mockMultimediaAudio() { if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); } else { - return new Promise((resolve, reject) => { - resolve(); + return new Promise((resolve, reject) => { + resolve(); }) } }, @@ -838,7 +964,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); + resolve(paramMock.paramNumberMock); }) } }, @@ -850,7 +976,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); + resolve(paramMock.paramNumberMock); }) } }, @@ -862,8 +988,8 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) + resolve(paramMock.paramNumberMock); + }) } }, isMute: function (...args) { @@ -874,7 +1000,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); + resolve(paramMock.paramBooleanMock); }) } }, @@ -886,7 +1012,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock); } else { return new Promise((resolve, reject) => { - resolve(); + resolve(); }) } }, @@ -898,8 +1024,8 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) + resolve(paramMock.paramBooleanMock); + }) } }, isMicrophoneMute: function (...args) { @@ -907,22 +1033,22 @@ export function mockMultimediaAudio() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); + resolve(paramMock.paramBooleanMock); }) } }, setMicrophoneMute: function (...args) { - console.warn("AudioManager.isMicrophoneMute interface mocked in the Previewer. How this interface works on the" + + console.warn("AudioManager.setMicrophoneMute 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); + args[len - 1].call(this, paramMock.businessErrorMock); } else { return new Promise((resolve, reject) => { - resolve(); + resolve(); }) } }, @@ -934,7 +1060,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); + resolve(paramMock.paramStringMock); }) } }, @@ -946,7 +1072,7 @@ export function mockMultimediaAudio() { args[len - 1].call(this, paramMock.businessErrorMock, AudioRingModeMock); } else { return new Promise((resolve, reject) => { - resolve(AudioRingModeMock); + resolve(AudioRingModeMock); }) } } @@ -985,7 +1111,7 @@ export function mockMultimediaAudio() { }, getAudioManager: function () { console.warn("multimedia.media.getAudioManager interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") + " on the Previewer may be different from that on a real device.") return audioManagerMock; } } diff --git a/runtime/main/extend/systemplugin/napi/application/abilityContext.js b/runtime/main/extend/systemplugin/napi/application/abilityContext.js new file mode 100644 index 00000000..c6ba91df --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/application/abilityContext.js @@ -0,0 +1,317 @@ +import {paramMock} from "../../utils" + +const ModuleInfoMock = { + moduleName: '[PC preview] unknow moduleName', + moduleSourceDir: '[PC preview] unknow moduleSourceDir', +} +export const AbilityInfoMock = { + bundleName: '[PC preview] unknow bundleName', + name: '[PC preview] unknow name', + label: '[PC preview] unknow label', + description: '[PC preview] unknow description', + icon: '[PC preview] unknow icon', + labelId: '[PC preview] unknow labelId', + descriptionId: '[PC preview] unknow descriptionId', + iconId: '[PC preview] unknow iconId', + moduleName: '[PC preview] unknow moduleName', + process: '[PC preview] unknow process', + targetAbility: '[PC preview] unknow targetAbility', + backgroundModes: '[PC preview] unknow backgroundModes', + isVisible: '[PC preview] unknow isVisible', + abilityTypeMock: '[PC preview] unknow abilityTypeMock', + AbilitySubTypeMock: '[PC preview] unknow AbilitySubTypeMock', + DisplayOrientationMock: '[PC preview] unknow DisplayOrientationMock', + launchModeMock: '[PC preview] unknow launchModeMock', + formEnabled: '[PC preview] unknow formEnabled', + permissions: [paramMock.paramStringMock], + deviceTypes: [paramMock.paramStringMock], + deviceCapabilities: [paramMock.paramStringMock], + readPermission: '[PC preview] unknow readPermission', + writePermission: '[PC preview] unknow writePermission', + applicationInfo: applicationInfoMock, + formEntity: '[PC preview] unknow formEntity', + minFormHeight: '[PC preview] unknow minFormHeight', + defaultFormHeight: '[PC preview] unknow defaultFormHeight', + minFormWidth: '[PC preview] unknow minFormWidth', + defaultFormWidth: '[PC preview] unknow defaultFormWidth', + uri: '[PC preview] unknow uri', + customizeData: new Map([["[PC Preview] unknow customizeDataKey", "[PC Preview] unknow customizeDataValue"]]) +} +const applicationInfoMock = { + name: '[PC preview] unknow name', + description: '[PC preview] unknow description', + descriptionId: '[PC preview] unknow descriptionId', + systemApp: '[PC preview] unknow systemApp', + enabled: '[PC preview] unknow enabled', + label: '[PC preview] unknow label', + labelId: '[PC preview] unknow labelId', + icon: '[PC preview] unknow icon', + iconId: '[PC preview] unknow iconId', + process: '[PC preview] unknow process', + supportedModes: '[PC preview] unknow supportedModes', + moduleSourceDirs: [paramMock.paramStringMock], + permissions: [paramMock.paramStringMock], + moduleInfo: [ModuleInfoMock], + entryDir: '[PC preview] unknow entryDir', + codepath: '[PC preview] unknow codepath', + removable: '[PC preview] unknow removable', + customizeData: new Map([["[PC Preview] unknow customizeDataKey", "[PC Preview] unknow customizeDataValue"]]) +} +const HapModuleInfoMock = { + name: '[PC preview] unknow name', + description: '[PC preview] unknow description', + descriptionId: '[PC preview] unknow descriptionId', + icon: '[PC preview] unknow icon', + label: '[PC preview] unknow label', + labelId: '[PC preview] unknow labelId', + iconId: '[PC preview] unknow iconId', + backgroundImg: '[PC preview] unknow backgroundImg', + supportedModes: '[PC preview] unknow supportedModes', + reqCapabilities: [paramMock.paramStringMock], + deviceTypes: [paramMock.paramStringMock], + abilityInfo: AbilityInfoMock, + moduleName: '[PC preview] unknow moduleName', + mainAbilityName: '[PC preview] unknow mainAbilityName', + installationFree: '[PC preview] unknow installationFree', +} +const screenDensityMock = { + SCREEN_SDPI: '[PC preview] unknow SCREEN_SDPI', + SCREEN_MDPI: '[PC preview] unknow SCREEN_MDPI', + SCREEN_LDPI: '[PC preview] unknow SCREEN_LDPI', + SCREEN_XLDPI: '[PC preview] unknow SCREEN_XLDPI', + SCREEN_XXLDPI: '[PC preview] unknow SCREEN_XXLDPI', + SCREEN_XXXLDPI: '[PC preview] unknow SCREEN_XXXLDPI' +} +const deviceTypeMock = { + DEVICE_TYPE_PHONE: '[PC preview] unknow DEVICE_TYPE_PHONE', + DEVICE_TYPE_TABLET: '[PC preview] unknow DEVICE_TYPE_TABLET', + DEVICE_TYPE_CAR: '[PC preview] unknow DEVICE_TYPE_CAR', + DEVICE_TYPE_PC: '[PC preview] unknow DEVICE_TYPE_PC', + DEVICE_TYPE_TV: '[PC preview] unknow DEVICE_TYPE_TV', + DEVICE_TYPE_WEARABLE: '[PC preview] unknow DEVICE_TYPE_WEARABLE' +} +const DeviceCapabilityClass = class DeviceCapability { + constructor() { + console.warn('DeviceCapability.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + screenDensity = screenDensityMock, + deviceType = deviceTypeMock + } +} +const configurationClass = class configuration{ + constructor() { + console.warn('configuration.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + directionMock = '[PC preview] unknow directionMock', + locale = '[PC preview] unknow locale' + } +} +const resourceManagerMock = { + getString: function (...args) { + console.warn("ResourceManager.getString 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); + }) + } + }, + getStringArray: function (...args) { + console.warn("ResourceManager.getStringArray 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]); + }) + } + }, + getMedia: function (...args) { + console.warn("ResourceManager.getMedia 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 Uint8Array()); + } else { + return new Promise((resolve, reject) => { + resolve(new Uint8Array()); + }) + } + }, + getMediaBase64: function (...args) { + console.warn("ResourceManager.getMediaBase64 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); + }) + } + }, + getDeviceCapability: function (...args) { + console.warn("ResourceManager.getDeviceCapability 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 DeviceCapabilityClass()); + } else { + return new Promise((resolve, reject) => { + resolve(new DeviceCapabilityClass()); + }) + } + }, + getConfiguration: function (...args) { + console.warn("ResourceManager.getConfiguration 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 configurationClass()); + } else { + return new Promise((resolve, reject) => { + resolve(new configurationClass()); + }) + } + }, + getPluralString: function (...args) { + console.warn("ResourceManager.getPluralString 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); + }) + } + }, + getRawFile: function (...args) { + console.warn("ResourceManager.getRawFile 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 Uint8Array()); + } else { + return new Promise((resolve, reject) => { + resolve(new Uint8Array()); + }) + } + }, +} +export const contextClass = class context{ + constructor() { + console.warn('context.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.resourceManager = resourceManagerMock; + this.applicationInfo = applicationInfoMock; + this.HapModuleInfo = HapModuleInfoMock; + this.cacheDir = '[PC preview] unknow cacheDir'; + this.tempDir = '[PC preview] unknow tempDir'; + this.filesDir = '[PC preview] unknow filesDir'; + this.databaseDir = '[PC preview] unknow databaseDir'; + this.storageDir = '[PC preview] unknow storageDir'; + this.bundleCodeDir = '[PC preview] unknow bundleCodeDir'; + this.distributedFilesDir = '[PC preview] unknow distributedFilesDir'; + } +}; +export const abilityStageContextClass = class abilityStageContext extends contextClass{ + constructor() { + super(); + console.warn('Context.abilityStageContext.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.currentHapModuleInfo = HapModuleInfoMock; + } +} +export const ExtensionContextClass = class ExtensionContext extends contextClass { + constructor() { + super(); + console.warn('Context.ExtensionContext.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + } +}; +export const AbilityResultMock = { + resultCode: "[PC Preview] unknow resultCode", +} +export const AbilityContextClass = class AbilityContext extends contextClass { + constructor() { + super(); + console.warn('Ability.AbilityContext.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.abilityInfo = AbilityInfoMock; + this.currentHapModuleInfo = HapModuleInfoMock; + this.startAbility = function (...args) { + console.warn("Ability.AbilityContext.startAbility 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(); + }) + } + }; + this.startAbilityForResult = function (...args) { + console.warn("Ability.AbilityContext.startAbilityForResult 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, AbilityResultMock); + } else { + return new Promise((resolve, reject) => { + resolve(AbilityResultMock); + }) + } + }; + this.terminateSelf = function (...args) { + console.warn("Ability.AbilityContext.terminateSelf 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(); + }) + } + }; + this.terminateSelfWithResult = function (...args) { + console.warn("Ability.AbilityContext.terminateSelfWithResult 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(); + }) + } + }; + this.connectAbility = function (...args) { + console.warn("Ability.AbilityContext.connectAbility interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock + }; + this.disconnectAbility = function (...args) { + console.warn("Ability.AbilityContext.disconnectAbility 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(); + }) + } + }; + } +} +export function mockAbilityContext() { + return new AbilityContextClass(); +} diff --git a/runtime/main/extend/systemplugin/napi/applicationAbility.js b/runtime/main/extend/systemplugin/napi/applicationAbility.js new file mode 100644 index 00000000..a4a29599 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/applicationAbility.js @@ -0,0 +1,54 @@ +import { paramMock } from "../utils" +import { AbilityContextClass } from "./application/abilityContext" + +const WantClass = class Want { + constructor() { + console.warn('Ability.Want.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.deviceId = "[PC Preview] unknow deviceId"; + this.bundleName = "[PC Preview] unknow bundleName"; + this.abilityName = "[PC Preview] unknow abilityName"; + this.uri = "[PC Preview] unknow uri"; + this.type = "[PC Preview] unknow type"; + this.flag = "[PC Preview] unknow flag"; + this.action = "[PC Preview] unknow action"; + this.parameters = {}; + this.entities = [paramMock.paramStringMock]; + } +} +export function mockAbility() { + const AbilityClass = class Ability { + constructor() { + console.warn('application.Ability.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.context = new AbilityContextClass(); + this.launchWant = new WantClass(); + this.lastRequestWant = new WantClass(); + this.onCreate = function (...args) { + console.warn("application.Ability.onCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onWindowStageCreate = function (...args) { + console.warn("application.Ability.onWindowStageCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onWindowStageDestroy = function () { + console.warn("application.Ability.onWindowStageDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onDestroy = function () { + console.warn("application.Ability.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onForeground = function () { + console.warn("application.Ability.onForeground interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onBackground = function () { + console.warn("application.Ability.onBackground interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + } + } + return new AbilityClass(); +} diff --git a/runtime/main/extend/systemplugin/napi/applicationAbilityStage.js b/runtime/main/extend/systemplugin/napi/applicationAbilityStage.js new file mode 100644 index 00000000..fb11cd4d --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/applicationAbilityStage.js @@ -0,0 +1,16 @@ +import { abilityStageContextClass } from "./application/abilityContext" + +export function mockAbilityStage(){ + const AbilityStageClass = class AbilityStage{ + constructor() { + console.warn('application.AbilityStage.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.context = new abilityStageContextClass(); + this.onCreate = function () { + console.warn("application.AbilityStage.onCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + } + } + } + return new AbilityStageClass(); +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/applicationFormExtension.js b/runtime/main/extend/systemplugin/napi/applicationFormExtension.js new file mode 100644 index 00000000..5bcc102c --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/applicationFormExtension.js @@ -0,0 +1,60 @@ +import { paramMock } from "../utils" +import { ExtensionContextClass } from "./application/abilityContext" + +export function mockFormExtension(){ + const formBindingDataMock = { + data: paramMock.paramObjectMock + } + const formExtensionContextClass = class formExtensionContext extends ExtensionContextClass { + constructor() { + super(); + console.warn('formExtension.formExtensionContext.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.updateForm = function (...args) { + console.warn("formExtension.formExtensionContext.updateForm 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(); + }) + } + } + } + } + const formExtensionClass = class formExtension { + constructor() { + console.warn('application.formExtension.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.context = new formExtensionContextClass(); + this.onCreate = function (...args) { + console.warn("application.formExtension.onCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return formBindingDataMock + }; + this.onCastToNormal = function (...args) { + console.warn("application.formExtension.onCastToNormal interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + this.onUpdate = function (...args) { + console.warn("application.formExtension.onUpdate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + this.onVisibilityChange = function (...args) { + console.warn("application.formExtension.onVisibilityChange interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + this.onEvent = function (...args) { + console.warn("application.formExtension.onEvent interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + this.onDestroy = function (...args) { + console.warn("application.formExtension.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + } + } + } + return new formExtensionClass(); +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/applicationServiceExtension.js b/runtime/main/extend/systemplugin/napi/applicationServiceExtension.js new file mode 100644 index 00000000..044c439d --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/applicationServiceExtension.js @@ -0,0 +1,201 @@ +import { paramMock } from "../utils" +import { ExtensionContextClass } from "./application/abilityContext" + +export function mockServiceExtension(){ + const IRemoteBrokerMock = { + asObject: function () { + console.warn("IRemoteBroker.asObject interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return IRemoteObjectMock; + }, + } + const IRemoteObjectMock = { + queryLocalInterface: function () { + console.warn("IRemoteObject.queryLocalInterface interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return IRemoteBrokerMock; + }, + sendRequest: function (...args) { + console.warn("IRemoteObject.sendRequest interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return new Promise((resolve, reject) => { + resolve(); + }) + }, + addDeathRecipient: function () { + console.warn("IRemoteObject.addDeathRecipient interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + removeDeathRecipient: function () { + console.warn("IRemoteObject.removeDeathRecipient interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + getInterfaceDescriptor: function () { + console.warn("IRemoteObject.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + isObjectDead: function () { + console.warn("IRemoteObject.isObjectDead interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + } + } + const RemoteObjectClass = class RemoteObject { + constructor() { + console.warn('RemoteObject.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.queryLocalInterface = function () { + console.warn("RemoteObject.queryLocalInterface interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return IRemoteBrokerMock; + }, + this.sendRequest = function (...args) { + console.warn("RemoteObject.sendRequest interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return new Promise((resolve, reject) => { + resolve(); + }) + }, + this.addDeathRecipient = function () { + console.warn("RemoteObject.addDeathRecipient interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + this.removeDeathRecipient = function () { + console.warn("RemoteObject.removeDeathRecipient interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + this.getInterfaceDescriptor = function () { + console.warn("RemoteObject.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + this.isObjectDead = function () { + console.warn("RemoteObject.isObjectDead interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + } + this.queryLocalInterface = function (...args) { + console.warn("RemoteObject.queryLocalInterface interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return IRemoteObjectMock + }, + this.getInterfaceDescriptor = function () { + console.warn("RemoteObject.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock + }, + this.onRemoteRequest = function (...args) { + console.warn("RemoteObject.onRemoteRequest interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + this.sendRequest = function (...args) { + console.warn("RemoteObject.sendRequest interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return new Promise((resolve, reject) => { + resolve(); + }) + }; + this.getCallingPid = function () { + console.warn("RemoteObject.getCallingPid interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock + }; + this.getCallingUid = function () { + console.warn("RemoteObject.getCallingUid interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock + }; + this.attachLocalInterface = function (...args) { + console.warn("RemoteObject.attachLocalInterface interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + } + } + const serviceExtensionContextClass = class serviceExtensionContext extends ExtensionContextClass{ + constructor() { + super(); + console.warn('ServiceExtension.serviceExtensionContext.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.startAbility = function (...args) { + console.warn("ServiceExtension.serviceExtensionContext.startAbility 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(); + }) + } + }; + this.terminateSelf = function (...args) { + console.warn("ServiceExtension.serviceExtensionContext.terminateSelf 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(); + }) + } + }; + this.connectAbility = function (...args) { + console.warn("ServiceExtension.serviceExtensionContext.connectAbility interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock + }; + this.disconnectAbility = function (...args) { + console.warn("ServiceExtension.serviceExtensionContext.disconnectAbility 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(); + }) + } + } + } + } + const ServiceExtensionClass = class ServiceExtension { + constructor() { + console.warn('application.ServiceExtension.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.context = new serviceExtensionContextClass(); + this.onCreate = function (...args) { + console.warn("application.ServiceExtension.onCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + this.onDestroy = function () { + console.warn("application.ServiceExtension.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + this.onRequest = function (...args) { + console.warn("application.ServiceExtension.onRequest interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + this.onConnect = function (...args) { + console.warn("application.ServiceExtension.onConnect interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return new RemoteObjectClass(); + }, + this.onDisconnect = function (...args) { + console.warn("application.ServiceExtension.onDisconnect interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + this.onReconnect = function (...args) { + console.warn("application.ServiceExtension.onReconnect interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + } + } + } + return new ServiceExtensionClass(); +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/dataAbility.js b/runtime/main/extend/systemplugin/napi/dataAbility.js index 92ea8b14..c4bdcd70 100644 --- a/runtime/main/extend/systemplugin/napi/dataAbility.js +++ b/runtime/main/extend/systemplugin/napi/dataAbility.js @@ -1,296 +1,160 @@ -import { paramMock } from "../utils" +import {paramMock} from '../utils'; +import {RdbPredicatesClass} from './rdb' export function mockDataAbility() { - const dataAbilityMock = { - createRdbPredicates: function (...args) { - console.warn("DataAbility.createRdbPredicates interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - }; - const rdbPredicates = { - equalTo: function (...args) { - console.warn("RdbPredicates.equalTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - notEqualTo: function (...args) { - console.warn("RdbPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - beginWrap: function (...args) { - console.warn("RdbPredicates.beginWrap interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - endWrap: function (...args) { - console.warn("RdbPredicates.endWrap interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - or: function (...args) { - console.warn("RdbPredicates.or interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - and: function (...args) { - console.warn("RdbPredicates.and interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - contains: function (...args) { - console.warn("RdbPredicates.contains interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - beginsWith: function (...args) { - console.warn("RdbPredicates.beginsWith interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - endsWith: function (...args) { - console.warn("RdbPredicates.endsWith interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - isNull: function (...args) { - console.warn("RdbPredicates.isNull interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - isNotNull: function (...args) { - console.warn("RdbPredicates.isNotNull interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - like: function (...args) { - console.warn("RdbPredicates.like interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - glob: function (...args) { - console.warn("RdbPredicates.glob interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - between: function (...args) { - console.warn("RdbPredicates.between interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - notBetween: function (...args) { - console.warn("RdbPredicates.notBetween interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - greaterThan: function (...args) { - console.warn("RdbPredicates.greaterThan interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - lessThan: function (...args) { - console.warn("RdbPredicates.lessThan interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - greaterThanOrEqualTo: function (...args) { - console.warn("RdbPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - lessThanOrEqualTo: function (...args) { - console.warn("RdbPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - orderByAsc: function (...args) { - console.warn("RdbPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - orderByDesc: function (...args) { - console.warn("RdbPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - distinct: function (...args) { - console.warn("RdbPredicates.distinct interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - limitAs: function (...args) { - console.warn("RdbPredicates.limitAs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - offsetAs: function (...args) { - console.warn("RdbPredicates.offsetAs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - groupBy: function (...args) { - console.warn("RdbPredicates.groupBy interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - indexedBy: function (...args) { - console.warn("RdbPredicates.indexedBy interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - in: function (...args) { - console.warn("RdbPredicates.in interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - notIn: function (...args) { - console.warn("RdbPredicates.notIn interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - }; - const dataAbilityPredicates = { - equalTo: function (...args) { - console.warn("DataAbilityPredicates.equalTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - notEqualTo: function (...args) { - console.warn("DataAbilityPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - beginWrap: function (...args) { - console.warn("DataAbilityPredicates.beginWrap interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - endWrap: function (...args) { - console.warn("DataAbilityPredicates.endWrap interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - or: function (...args) { - console.warn("DataAbilityPredicates.or interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - and: function (...args) { - console.warn("DataAbilityPredicates.and interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - contains: function (...args) { - console.warn("DataAbilityPredicates.contains interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - beginsWith: function (...args) { - console.warn("DataAbilityPredicates.beginsWith interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - endsWith: function (...args) { - console.warn("DataAbilityPredicates.endsWith interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - isNull: function (...args) { - console.warn("DataAbilityPredicates.isNull interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - isNotNull: function (...args) { - console.warn("DataAbilityPredicates.isNotNull interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - like: function (...args) { - console.warn("DataAbilityPredicates.like interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - glob: function (...args) { - console.warn("DataAbilityPredicates.glob interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - between: function (...args) { - console.warn("DataAbilityPredicates.between interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - notBetween: function (...args) { - console.warn("DataAbilityPredicates.notBetween interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - greaterThan: function (...args) { - console.warn("DataAbilityPredicates.greaterThan interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - lessThan: function (...args) { - console.warn("DataAbilityPredicates.lessThan interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - greaterThanOrEqualTo: function (...args) { - console.warn("DataAbilityPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - lessThanOrEqualTo: function (...args) { - console.warn("DataAbilityPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - orderByAsc: function (...args) { - console.warn("DataAbilityPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - orderByDesc: function (...args) { - console.warn("DataAbilityPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - distinct: function (...args) { - console.warn("DataAbilityPredicates.distinct interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - limitAs: function (...args) { - console.warn("DataAbilityPredicates.limitAs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - offsetAs: function (...args) { - console.warn("DataAbilityPredicates.offsetAs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - groupBy: function (...args) { - console.warn("DataAbilityPredicates.groupBy interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - indexedBy: function (...args) { - console.warn("DataAbilityPredicates.indexedBy interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - in: function (...args) { - console.warn("DataAbilityPredicates.in interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, - notIn: function (...args) { - console.warn("DataAbilityPredicates.notIn interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return dataAbilityPredicates; - }, + const DataAbilityPredicatesClass = class DataAbilityPredicates { + constructor() { + console.warn('DataAbility.DataAbilityPredicates.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.equalTo = function (...args) { + console.warn('DataAbilityPredicates.equalTo interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.notEqualTo = function (...args) { + console.warn('DataAbilityPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.beginWrap = function (...args) { + console.warn('DataAbilityPredicates.beginWrap interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.endWrap = function (...args) { + console.warn('DataAbilityPredicates.endWrap interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.or = function (...args) { + console.warn('DataAbilityPredicates.or interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.and = function (...args) { + console.warn('DataAbilityPredicates.and interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.contains = function (...args) { + console.warn('DataAbilityPredicates.contains interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.beginsWith = function (...args) { + console.warn('DataAbilityPredicates.beginsWith interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.endsWith = function (...args) { + console.warn('DataAbilityPredicates.endsWith interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.isNull = function (...args) { + console.warn('DataAbilityPredicates.isNull interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.isNotNull = function (...args) { + console.warn('DataAbilityPredicates.isNotNull interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.like = function (...args) { + console.warn('DataAbilityPredicates.like interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.glob = function (...args) { + console.warn('DataAbilityPredicates.glob interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.between = function (...args) { + console.warn('DataAbilityPredicates.between interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.notBetween = function (...args) { + console.warn('DataAbilityPredicates.notBetween interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.greaterThan = function (...args) { + console.warn('DataAbilityPredicates.greaterThan interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.lessThan = function (...args) { + console.warn('DataAbilityPredicates.lessThan interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.greaterThanOrEqualTo = function (...args) { + console.warn('DataAbilityPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.lessThanOrEqualTo = function (...args) { + console.warn('DataAbilityPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.orderByAsc = function (...args) { + console.warn('DataAbilityPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.orderByDesc = function (...args) { + console.warn('DataAbilityPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.distinct = function (...args) { + console.warn('DataAbilityPredicates.distinct interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.limitAs = function (...args) { + console.warn('DataAbilityPredicates.limitAs interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.offsetAs = function (...args) { + console.warn('DataAbilityPredicates.offsetAs interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.groupBy = function (...args) { + console.warn('DataAbilityPredicates.groupBy interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.indexedBy = function (...args) { + console.warn('DataAbilityPredicates.indexedBy interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.in = function (...args) { + console.warn('DataAbilityPredicates.in interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; + this.notIn = function (...args) { + console.warn('DataAbilityPredicates.notIn interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new DataAbilityPredicatesClass(); + }; } - return dataAbilityMock; -} \ No newline at end of file + }; + const dataAbilityMock = { + createRdbPredicates: function (...args) { + console.warn('DataAbility.createRdbPredicates.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + return new RdbPredicatesClass(); + }, + DataAbilityPredicates: DataAbilityPredicatesClass + }; + return dataAbilityMock; +} diff --git a/runtime/main/extend/systemplugin/napi/hilog.js b/runtime/main/extend/systemplugin/napi/hilog.js index 7c3a9abe..f1358295 100644 --- a/runtime/main/extend/systemplugin/napi/hilog.js +++ b/runtime/main/extend/systemplugin/napi/hilog.js @@ -1,32 +1,39 @@ -import { paramMock } from "../utils" +import {paramMock} from "../utils" export function mockHilog() { - const hilog = { - debug: function (...args) { - console.warn("hilog.debug interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - info: function (...args) { - console.warn("hilog.info interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - warn: function (...args) { - console.warn("hilog.warn interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - error: function (...args) { - console.warn("hilog.error interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - fatal: function (...args) { - console.warn("hilog.fatal interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - isLoggable: function (...args) { - console.warn("hilog.isLoggable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, + const hilog = { + LogLevel: { + DEBUG: 3, + INFO: 4, + WARN: 5, + ERROR: 6, + FATAL: 7 + }, + debug: function (...args) { + console.warn("hilog.debug interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + info: function (...args) { + console.warn("hilog.info interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + warn: function (...args) { + console.warn("hilog.warn interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + error: function (...args) { + console.warn("hilog.error interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + fatal: function (...args) { + console.warn("hilog.fatal interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + isLoggable: function (...args) { + console.warn("hilog.isLoggable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; } - return hilog; + } + return hilog; } diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 414fb346..e38f8109 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -1,4 +1,8 @@ import { mockSystemParameter } from './systemParameter' +import { mockAbility } from './applicationAbility' +import { mockFormExtension } from './applicationFormExtension' +import { mockServiceExtension } from './applicationServiceExtension' +import { mockAbilityStage } from './applicationAbilityStage' import { mockFileio } from './fileio' import { mockWorker } from './worker' import { mockUtil } from './util' @@ -11,7 +15,6 @@ import { mockwebgl } from './webgl' import { mockwebgl2 } from './webgl2' import { mockProcess } from './process' import { mockUrl } from './url' -import { mockMediaQuery } from './mediaquery' import { mockHiAppEvent } from './hiAppEvent' import { mockHilog } from './hilog' import { mockTv } from './tv' @@ -22,12 +25,24 @@ import { mockDistributedData } from './distributedData' import { mockDataAbility } from './dataAbility' import { mockStorage } from './storage' import { mockRdb } from './rdb' +import { mockInputDevice } from './inputDevice' +import { mockLight } from './light' +import { mockVibrator } from './vibrator' +import { mockSensor } from './sensor' export function mockRequireNapiFun() { global.requireNapi = function (...args) { switch (args[0]) { case "systemParameter": return mockSystemParameter(); + case "application.Ability": + return mockAbility(); + case "application.FormExtension": + return mockFormExtension(); + case "application.ServiceExtension": + return mockServiceExtension(); + case "application.AbilityStage": + return mockAbilityStage(); case "fileio": return mockFileio(); case "worker" : @@ -52,8 +67,6 @@ export function mockRequireNapiFun() { return mockBytrace(); case "url": return mockUrl(); - case "mediaquery": - return mockMediaQuery(); case "hiAppEvent": return mockHiAppEvent(); case "hilog": @@ -74,6 +87,16 @@ export function mockRequireNapiFun() { return mockStorage(); case "data.dataAbility": return mockDataAbility(); + case "multimodalInput.inputDevice": + return mockInputDevice(); + case "light": + return mockLight(); + case "vibrator": + return mockVibrator(); + case "sensor": + return mockSensor(); + default: + return global.requireNapiPreview(...args); } } } diff --git a/runtime/main/extend/systemplugin/napi/inputDevice.js b/runtime/main/extend/systemplugin/napi/inputDevice.js new file mode 100644 index 00000000..02c21259 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/inputDevice.js @@ -0,0 +1,106 @@ +import { paramMock } from "../utils" + +export function mockInputDevice() { + const AxisRange = { + source: '[PC preview] unknow source', + axis : '[PC preview] unknow axis', + max : '[PC preview] unknow max', + min: '[PC preview] unknow min' + } + const InputDeviceData = { + id: '[PC preview] unknow id', + name: '[PC preview] unknow name', + sources : ['[PC preview] unknow sources'], + axisRanges : [AxisRange] + } + + const EventType = ['add', 'remove', 'update'] + const DeviceIds = [-1,0,1,2,3,4,5,6,7] + const inputDevice = { + on: function (...args) { + console.warn("inputDevice.on 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 === 2) { + if (EventType.indexOf(args[0]) === -1) { + console.warn("the first parameter must be 'add'|'remove'|'update'") + } + if (typeof args[1] != 'function') { + console.warn("the second parameter type must be 'function'") + } + } else { + console.warn("the number of parameter must be two") + } + }, + off: function (...args) { + console.warn("inputDevice.off 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 < 1 || len >2) { + console.warn("the number of parameter must be one or two") + } else if (len === 1) { + if (EventType.indexOf(args[0]) === -1) { + console.warn("first parameter must be 'add'|'remove'|'update'") + } + } else { + if (EventType.indexOf(args[0]) === -1) { + console.warn("first parameter must be 'add'|'remove'|'update'") + } + if (typeof args[1] != 'function') { + console.warn("second parameter type must be 'function'") + } + } + }, + getDeviceSync: function (...args) { + console.warn("inputDevice.getDeviceSync 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 != 1) { + console.warn("the number of parameter must be one") + } else { + if (DeviceIds.indexOf(args[len - 1]) != -1) { + return InputDeviceData; + } else { + console.warn("parameter error") + return paramMock.businessErrorMock; + } + } + }, + getDeviceIdsSync: function () { + console.warn("inputDevice.getDeviceIdsSync interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return DeviceIds; + }, + getDeviceIds: function (...args) { + console.warn("inputDevice.getDeviceIds 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 != 1) { + console.warn("the number of parameter must be one") + } + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, DeviceIds); + } else { + console.warn("parameter type must be 'function") + } + }, + getDevice: function (...args) { + console.warn("inputDevice.getDevice 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 != 2) { + console.warn("the number of parameter must be two") + } + if (DeviceIds.indexOf(args[0]) === -1) { + console.warn("the first parameter error") + } + if (typeof args[1] === 'function') { + console.warn("asynchronous callback") + args[1].call(this, InputDeviceData); + } else { + console.warn("the second parameter type must be 'function'") + } + } + } + return inputDevice +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/light.js b/runtime/main/extend/systemplugin/napi/light.js new file mode 100644 index 00000000..221ff220 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/light.js @@ -0,0 +1,93 @@ +import { paramMock } from "../utils" + +export function mockLight() { + const LightId = { + LIGHT_ID_LED: 0, + LIGHT_ID_KEYBOARD: 1, + LIGHT_ID_BUTTONS: 2, + LIGHT_ID_BELT: 3, + UNKNOWN: 4 + } + const LightEffectId = { + LIGHT_ID_LED: "0", + LIGHT_ID_KEYBOARD: "1", + LIGHT_ID_BUTTONS: "2", + LIGHT_ID_BELT: "3", + UNKNOWN: "4" + } + const LightBrightness = { + redBrightness: "[PC preview] unknown redBrightness", + greenBrightness: "[PC preview] unknown greenBrightness", + blueBrightness: "[PC preview] unknown blueBrightness" + } + const LightEffect = { + lightBrightness: "[PC preview] unknown lightBrightness", + onDuration: "[PC preview] unknown onDuration", + offDuration: "[PC preview] unknown offDuration" + } + const light = { + turnOn: function (...args) { + console.warn("light.turnOn 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }) + } + }, + turnOff: function (...args) { + console.warn("light.turnOff 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }) + } + }, + getLightIdList: function (...args) { + console.warn("light.getLightIdList interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var lightIdArray = new Array(); + lightIdArray.push(paramMock.paramNumberMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, lightIdArray); + } else { + return new Promise((resolve) => { + resolve(lightIdArray); + }) + } + }, + isSupport: function (...args) { + console.warn("light.isSupport 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isEffectSupport: function (...args) { + console.warn("light.isEffectSupport 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }) + } + } + } + return light +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/rdb.js b/runtime/main/extend/systemplugin/napi/rdb.js index 97bbc6b3..ab3be2e5 100644 --- a/runtime/main/extend/systemplugin/napi/rdb.js +++ b/runtime/main/extend/systemplugin/napi/rdb.js @@ -1,318 +1,325 @@ -import { paramMock } from "../utils" +import {paramMock} from "../utils" + +export const RdbPredicatesClass = class RdbPredicates { + constructor(...args) { + console.warn('data.rdb.RdbPredicates.constructor interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + this.equalTo = function (...args) { + console.warn("RdbPredicates.equalTo interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.notEqualTo = function (...args) { + console.warn("RdbPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.beginWrap = function (...args) { + console.warn("RdbPredicates.beginWrap interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.endWrap = function (...args) { + console.warn("RdbPredicates.endWrap interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.or = function (...args) { + console.warn("RdbPredicates.or interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.and = function (...args) { + console.warn("RdbPredicates.and interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.contains = function (...args) { + console.warn("RdbPredicates.contains interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.beginsWith = function (...args) { + console.warn("RdbPredicates.beginsWith interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.endsWith = function (...args) { + console.warn("RdbPredicates.endsWith interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.isNull = function (...args) { + console.warn("RdbPredicates.isNull interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.isNotNull = function (...args) { + console.warn("RdbPredicates.isNotNull interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.like = function (...args) { + console.warn("RdbPredicates.like interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.glob = function (...args) { + console.warn("RdbPredicates.glob interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.between = function (...args) { + console.warn("RdbPredicates.between interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.notBetween = function (...args) { + console.warn("RdbPredicates.notBetween interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.greaterThan = function (...args) { + console.warn("RdbPredicates.greaterThan interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.lessThan = function (...args) { + console.warn("RdbPredicates.lessThan interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.greaterThanOrEqualTo = function (...args) { + console.warn("RdbPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.lessThanOrEqualTo = function (...args) { + console.warn("RdbPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.orderByAsc = function (...args) { + console.warn("RdbPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.orderByDesc = function (...args) { + console.warn("RdbPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.distinct = function (...args) { + console.warn("RdbPredicates.distinct interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.limitAs = function (...args) { + console.warn("RdbPredicates.limitAs interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.offsetAs = function (...args) { + console.warn("RdbPredicates.offsetAs interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.groupBy = function (...args) { + console.warn("RdbPredicates.groupBy interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.indexedBy = function (...args) { + console.warn("RdbPredicates.indexedBy interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.in = function (...args) { + console.warn("RdbPredicates.in interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + this.notIn = function (...args) { + console.warn("RdbPredicates.notIn interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return new RdbPredicatesClass(); + }; + } +}; export function mockRdb() { - const rdbMock = { - getRdbStore: function (...args) { - console.warn("Rdb.getRdbStore 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, rdbStore); - } else { - return new Promise((resolve, reject) => { - resolve(rdbStore); - }) - } - }, - deleteRdbStore: function (...args) { - console.warn("Rdb.deleteRdbStore 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(); - }) - } - }, - }; - const resultSetMock = { - columnNames: "[[PC Preview] unknow columnNames]", - columnCount: "[PC Preview] unknow columnCount", - rowCount: "[PC Preview] unknow rowCount", - rowIndex: "[PC Preview] unknow rowIndex", - isAtFirstRow: "[PC Preview] unknow isAtFirstRow", - isAtLastRow: "[PC Preview] unknow isAtLastRow", - isEnded: "[PC Preview] unknow isEnded", - isStarted: "[PC Preview] unknow isStarted", - isClosed: "[PC Preview] unknow isClosed", - getColumnIndex: function (...args) { - console.warn("ResultSet.getColumnIndex interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramNumberMock; - }, - getColumnName: function (...args) { - console.warn("ResultSet.getColumnName interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramStringMock; - }, - goTo: function (...args) { - console.warn("ResultSet.goTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - goToRow: function (...args) { - console.warn("ResultSet.goToRow interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - goToFirstRow: function (...args) { - console.warn("ResultSet.goToFirstRow interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - goToLastRow: function (...args) { - console.warn("ResultSet.goToLastRow interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - goToNextRow: function (...args) { - console.warn("ResultSet.goToNextRow interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - goToPreviousRow: function (...args) { - console.warn("ResultSet.goToPreviousRow interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - getBlob: function (...args) { - console.warn("ResultSet.getBlob interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramObjectMock; - }, - getString: function (...args) { - console.warn("ResultSet.getString interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramStringMock; - }, - getLong: function (...args) { - console.warn("ResultSet.getLong interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramNumberMock; - }, - getDouble: function (...args) { - console.warn("ResultSet.getDouble interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramNumberMock; - }, - isColumnNull: function (...args) { - console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - close: function (...args) { - console.warn("ResultSet.close interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, + const rdbMock = { + getRdbStore: function (...args) { + console.warn("Rdb.getRdbStore 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, rdbStore); + } else { + return new Promise((resolve, reject) => { + resolve(rdbStore); + }) + } + }, + deleteRdbStore: function (...args) { + console.warn("Rdb.deleteRdbStore 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(); + }) + } + }, + RdbPredicates: RdbPredicatesClass + }; + const resultSetMock = { + columnNames: "[[PC Preview] unknow columnNames]", + columnCount: "[PC Preview] unknow columnCount", + rowCount: "[PC Preview] unknow rowCount", + rowIndex: "[PC Preview] unknow rowIndex", + isAtFirstRow: "[PC Preview] unknow isAtFirstRow", + isAtLastRow: "[PC Preview] unknow isAtLastRow", + isEnded: "[PC Preview] unknow isEnded", + isStarted: "[PC Preview] unknow isStarted", + isClosed: "[PC Preview] unknow isClosed", + getColumnIndex: function (...args) { + console.warn("ResultSet.getColumnIndex interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + getColumnName: function (...args) { + console.warn("ResultSet.getColumnName interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock; + }, + goTo: function (...args) { + console.warn("ResultSet.goTo interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + goToRow: function (...args) { + console.warn("ResultSet.goToRow interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + goToFirstRow: function (...args) { + console.warn("ResultSet.goToFirstRow interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + goToLastRow: function (...args) { + console.warn("ResultSet.goToLastRow interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + goToNextRow: function (...args) { + console.warn("ResultSet.goToNextRow interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + goToPreviousRow: function (...args) { + console.warn("ResultSet.goToPreviousRow interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + getBlob: function (...args) { + console.warn("ResultSet.getBlob interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramObjectMock; + }, + getString: function (...args) { + console.warn("ResultSet.getString interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock; + }, + getLong: function (...args) { + console.warn("ResultSet.getLong interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + getDouble: function (...args) { + console.warn("ResultSet.getDouble interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + isColumnNull: function (...args) { + console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + close: function (...args) { + console.warn("ResultSet.close interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") } - const storeConfig = { - name: "[PC Preview] unknown name" + } + const storeConfig = { + name: "[PC Preview] unknown name" + } + const rdbStore = { + insert: function (...args) { + console.warn("RdbStore.insert 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.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + update: function (...args) { + console.warn("RdbStore.update 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.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + delete: function (...args) { + console.warn("RdbStore.delete 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.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + query: function (...args) { + console.warn("RdbStore.query 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, resultSetMock); + } else { + return new Promise((resolve, reject) => { + resolve(resultSetMock); + }) + } + }, + executeSql: function (...args) { + console.warn("RdbStore.executeSql 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(); + }) + } } - const rdbStore = { - insert: function (...args) { - console.warn("RdbStore.insert 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.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - update: function (...args) { - console.warn("RdbStore.update 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.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - delete: function (...args) { - console.warn("RdbStore.delete 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.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - query: function (...args) { - console.warn("RdbStore.query 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, resultSetMock); - } else { - return new Promise((resolve, reject) => { - resolve(resultSetMock); - }) - } - }, - executeSql: function (...args) { - console.warn("RdbStore.executeSql 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(); - }) - } - }, - }; - const rdbPredicates = { - equalTo: function (...args) { - console.warn("RdbPredicates.equalTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - notEqualTo: function (...args) { - console.warn("RdbPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - beginWrap: function (...args) { - console.warn("RdbPredicates.beginWrap interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - endWrap: function (...args) { - console.warn("RdbPredicates.endWrap interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - or: function (...args) { - console.warn("RdbPredicates.or interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - and: function (...args) { - console.warn("RdbPredicates.and interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - contains: function (...args) { - console.warn("RdbPredicates.contains interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - beginsWith: function (...args) { - console.warn("RdbPredicates.beginsWith interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - endsWith: function (...args) { - console.warn("RdbPredicates.endsWith interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - isNull: function (...args) { - console.warn("RdbPredicates.isNull interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - isNotNull: function (...args) { - console.warn("RdbPredicates.isNotNull interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - like: function (...args) { - console.warn("RdbPredicates.like interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - glob: function (...args) { - console.warn("RdbPredicates.glob interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - between: function (...args) { - console.warn("RdbPredicates.between interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - notBetween: function (...args) { - console.warn("RdbPredicates.notBetween interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - greaterThan: function (...args) { - console.warn("RdbPredicates.greaterThan interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - lessThan: function (...args) { - console.warn("RdbPredicates.lessThan interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - greaterThanOrEqualTo: function (...args) { - console.warn("RdbPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - lessThanOrEqualTo: function (...args) { - console.warn("RdbPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - orderByAsc: function (...args) { - console.warn("RdbPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - orderByDesc: function (...args) { - console.warn("RdbPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - distinct: function (...args) { - console.warn("RdbPredicates.distinct interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - limitAs: function (...args) { - console.warn("RdbPredicates.limitAs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - offsetAs: function (...args) { - console.warn("RdbPredicates.offsetAs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - groupBy: function (...args) { - console.warn("RdbPredicates.groupBy interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - indexedBy: function (...args) { - console.warn("RdbPredicates.indexedBy interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - in: function (...args) { - console.warn("RdbPredicates.in interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - notIn: function (...args) { - console.warn("RdbPredicates.notIn interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return rdbPredicates; - }, - }; - return rdbMock; -} \ No newline at end of file + }; + + return rdbMock; +} diff --git a/runtime/main/extend/systemplugin/napi/rpc.js b/runtime/main/extend/systemplugin/napi/rpc.js index 284d57f8..3e7fd57c 100644 --- a/runtime/main/extend/systemplugin/napi/rpc.js +++ b/runtime/main/extend/systemplugin/napi/rpc.js @@ -1,5 +1,37 @@ import { paramMock } from "../utils" +export const IRemoteObject = { + queryLocalInterface: function (...args) { + console.warn("rpc.queryLocalInterface interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return IRemoteBroker + }, + sendRequest: function (...args) { + console.warn("rpc.sendRequest interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + addDeathRecipient: function (...args) { + console.warn("rpc.addDeathRecipient interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + removeDeathRecipient: function (...args) { + console.warn("rpc.removeDeathRecipient interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + getInterfaceDescriptor: function () { + console.warn("rpc.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + isObjectDead: function () { + console.warn("rpc.isObjectDead interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + } +} export function mockRpc() { const MessageParcel = { reclaim: function () { @@ -272,38 +304,6 @@ export function mockRpc() { return paramMock.paramArrayMock; } }; - const IRemoteObject = { - queryLocalInterface: function (...args) { - console.warn("rpc.queryLocalInterface interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return IRemoteBroker - }, - sendRequest: function (...args) { - console.warn("rpc.sendRequest interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock - }, - addDeathRecipient: function (...args) { - console.warn("rpc.addDeathRecipient interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock - }, - removeDeathRecipient: function (...args) { - console.warn("rpc.removeDeathRecipient interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock - }, - getInterfaceDescriptor: function () { - console.warn("rpc.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramStringMock - }, - isObjectDead: function () { - console.warn("rpc.isObjectDead interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock - } - }; const IRemoteBroker = { asObject: function () { console.warn("rpc.asObject interface mocked in the Previewer. How this interface works on the" + diff --git a/runtime/main/extend/systemplugin/napi/sensor.js b/runtime/main/extend/systemplugin/napi/sensor.js new file mode 100644 index 00000000..73b2f4c6 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/sensor.js @@ -0,0 +1,341 @@ +import { paramMock } from "../utils" + +export function mockSensor() { + const AccelerometerResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z" + } + const LinearAccelerometerResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z" + } + const AccelerometerUncalibratedResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z", + biasX: "[PC preview] unknown biasX", + biasY: "[PC preview] unknown biasY", + biasZ: "[PC preview] unknown biasZ" + } + const GravityResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z" + } + const OrientationResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z" + } + const RotationVectorResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z" + } + const GyroscopeResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z" + } + const GyroscopeUncalibratedResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z", + biasX: "[PC preview] unknown biasX", + biasY: "[PC preview] unknown biasY", + biasZ: "[PC preview] unknown biasZ" + } + const SignificantMotionResponse = { + scalar: "[PC preview] unknown scalar" + } + const ProximityResponse = { + distance: "[PC preview] unknown distance" + } + const LightResponse = { + intensity: "[PC preview] unknown intensity" + } + const HallResponse = { + status: "[PC preview] unknown status" + } + const MagneticFieldResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z" + } + const MagneticFieldUncalibratedResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z", + biasX: "[PC preview] unknown biasX", + biasY: "[PC preview] unknown biasY", + biasZ: "[PC preview] unknown biasZ" + } + const PedometerResponse = { + steps: "[PC preview] unknown steps" + } + const HumidityResponse = { + humidity: "[PC preview] unknown humidity" + } + const PedometerDetectResponse = { + scalar: "[PC preview] unknown scalar" + } + const AmbientTemperatureResponse = { + temperature: "[PC preview] unknown temperature" + } + const BarometerResponse = { + pressure: "[PC preview] unknown pressure" + } + const HeartRateResponse = { + heartRate: "[PC preview] unknown heartRate" + } + const WearDetectionResponse = { + value: "[PC preview] unknown value" + } + const Options = { + interval: "[PC preview] unknown value" + } + const GeomagneticResponse = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y", + z: "[PC preview] unknown z", + biasX: "[PC preview] unknown biasX", + biasY: "[PC preview] unknown biasY", + biasZ: "[PC preview] unknown biasZ" + } + const LocationOptions = { + latitude: "[PC preview] unknown latitude", + longitude: "[PC preview] unknown longitude", + altitude: "[PC preview] unknown altitude", + } + const CoordinatesOptions = { + x: "[PC preview] unknown x", + y: "[PC preview] unknown y" + } + const SensorType = { + SENSOR_TYPE_ID_ACCELEROMETER: 1, + SENSOR_TYPE_ID_GYROSCOPE: 2, + SENSOR_TYPE_ID_AMBIENT_LIGHT: 5, + SENSOR_TYPE_ID_MAGNETIC_FIELD: 6, + SENSOR_TYPE_ID_BAROMETER: 8, + SENSOR_TYPE_ID_HALL: 10, + SENSOR_TYPE_ID_PROXIMITY: 12, + SENSOR_TYPE_ID_HUMIDITY: 13, + SENSOR_TYPE_ID_ORIENTATION: 256, + SENSOR_TYPE_ID_GRAVITY: 257, + SENSOR_TYPE_ID_LINEAR_ACCELERATION: 258, + SENSOR_TYPE_ID_ROTATION_VECTOR: 259, + SENSOR_TYPE_ID_AMBIENT_TEMPERATURE: 260, + SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED: 261, + SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED: 263, + SENSOR_TYPE_ID_SIGNIFICANT_MOTION: 264, + SENSOR_TYPE_ID_PEDOMETER_DETECTION: 265, + SENSOR_TYPE_ID_PEDOMETER: 266, + SENSOR_TYPE_ID_HEART_RATE: 278, + SENSOR_TYPE_ID_WEAR_DETECTION: 280, + SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED: 281 + } + const sensor = { + on: function (...args) { + console.warn("sensor.on 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; + const callback = typeof args[len - 1] == 'function' ? args[len - 1] : args[len - 2]; + if (args[0] == 1) { + callback.call(this, paramMock.businessErrorMock, AccelerometerResponse); + } else if (args[0] == 2) { + callback.call(this, paramMock.businessErrorMock, GyroscopeResponse); + } else if (args[0] == 5) { + callback.call(this, paramMock.businessErrorMock, LightResponse); + } else if (args[0] == 6) { + callback.call(this, paramMock.businessErrorMock, MagneticFieldResponse); + } else if (args[0] == 8) { + callback.call(this, paramMock.businessErrorMock, BarometerResponse); + } else if (args[0] == 10) { + callback.call(this, paramMock.businessErrorMock, HallResponse); + } else if (args[0] == 12) { + callback.call(this, paramMock.businessErrorMock, ProximityResponse); + } else if (args[0] == 13) { + callback.call(this, paramMock.businessErrorMock, HumidityResponse); + } else if (args[0] == 256) { + callback.call(this, paramMock.businessErrorMock, OrientationResponse); + } else if (args[0] == 257) { + callback.call(this, paramMock.businessErrorMock, GravityResponse); + } else if (args[0] == 258) { + callback.call(this, paramMock.businessErrorMock, LinearAccelerometerResponse); + } else if (args[0] == 259) { + callback.call(this, paramMock.businessErrorMock, RotationVectorResponse); + } else if (args[0] == 260) { + callback.call(this, paramMock.businessErrorMock, AmbientTemperatureResponse); + } else if (args[0] == 261) { + callback.call(this, paramMock.businessErrorMock, MagneticFieldUncalibratedResponse); + } else if (args[0] == 263) { + callback.call(this, paramMock.businessErrorMock, GyroscopeUncalibratedResponse); + } else if (args[0] == 264) { + callback.call(this, paramMock.businessErrorMock, SignificantMotionResponse); + } else if (args[0] == 265) { + callback.call(this, paramMock.businessErrorMock, PedometerDetectResponse); + } else if (args[0] == 266) { + callback.call(this, paramMock.businessErrorMock, PedometerResponse); + } else if (args[0] == 278) { + callback.call(this, paramMock.businessErrorMock, HeartRateResponse); + } else if (args[0] == 280) { + callback.call(this, paramMock.businessErrorMock, WearDetectionResponse); + } else if (args[0] == 281) { + callback.call(this, paramMock.businessErrorMock, AccelerometerUncalibratedResponse); + } + }, + once: function (...args) { + console.warn("sensor.once 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 (args[0] == 1) { + args[len - 1].call(this, paramMock.businessErrorMock, AccelerometerResponse); + } else if (args[0] == 2) { + args[len - 1].call(this, paramMock.businessErrorMock, GyroscopeResponse); + } else if (args[0] == 5) { + args[len - 1].call(this, paramMock.businessErrorMock, LightResponse); + } else if (args[0] == 6) { + args[len - 1].call(this, paramMock.businessErrorMock, MagneticFieldResponse); + } else if (args[0] == 8) { + args[len - 1].call(this, paramMock.businessErrorMock, BarometerResponse); + } else if (args[0] == 10) { + args[len - 1].call(this, paramMock.businessErrorMock, HallResponse); + } else if (args[0] == 12) { + args[len - 1].call(this, paramMock.businessErrorMock, ProximityResponse); + } else if (args[0] == 13) { + args[len - 1].call(this, paramMock.businessErrorMock, HumidityResponse); + } else if (args[0] == 256) { + args[len - 1].call(this, paramMock.businessErrorMock, OrientationResponse); + } else if (args[0] == 257) { + args[len - 1].call(this, paramMock.businessErrorMock, GravityResponse); + } else if (args[0] == 258) { + args[len - 1].call(this, paramMock.businessErrorMock, LinearAccelerometerResponse); + } else if (args[0] == 259) { + args[len - 1].call(this, paramMock.businessErrorMock, RotationVectorResponse); + } else if (args[0] == 260) { + args[len - 1].call(this, paramMock.businessErrorMock, AmbientTemperatureResponse); + } else if (args[0] == 261) { + args[len - 1].call(this, paramMock.businessErrorMock, MagneticFieldUncalibratedResponse); + } else if (args[0] == 263) { + args[len - 1].call(this, paramMock.businessErrorMock, GyroscopeUncalibratedResponse); + } else if (args[0] == 264) { + args[len - 1].call(this, paramMock.businessErrorMock, SignificantMotionResponse); + } else if (args[0] == 265) { + args[len - 1].call(this, paramMock.businessErrorMock, PedometerDetectResponse); + } else if (args[0] == 266) { + args[len - 1].call(this, paramMock.businessErrorMock, PedometerResponse); + } else if (args[0] == 278) { + args[len - 1].call(this, paramMock.businessErrorMock, HeartRateResponse); + } else if (args[0] == 280) { + args[len - 1].call(this, paramMock.businessErrorMock, WearDetectionResponse); + } else if (args[0] == 281) { + args[len - 1].call(this, paramMock.businessErrorMock, AccelerometerUncalibratedResponse); + } + }, + off: function (...args) { + console.warn("sensor.off 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 + args[len - 1].call(this, paramMock.businessErrorMock); + }, + getGeomagneticField: function (...args) { + console.warn("sensor.getGeomagneticField 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, GeomagneticResponse); + } else { + return new Promise((resolve, reject) => { + resolve(GeomagneticResponse); + }) + } + }, + getAltitude: function (...args) { + console.warn("sensor.getAltitude 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getGeomagneticDip: function (...args) { + console.warn("sensor.getGeomagneticDip 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getAngleModifiy: function (...args) { + console.warn("sensor.getAngleModifiy 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + createRotationMatrix: function (...args) { + console.warn("sensor.createRotationMatrix 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + transformCoordinateSystem: function (...args) { + console.warn("sensor.transformCoordinateSystem 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + createQuaternion: function (...args) { + console.warn("sensor.createQuaternion 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + getDirection: function (...args) { + console.warn("sensor.getDirection 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + } + } + return sensor +} diff --git a/runtime/main/extend/systemplugin/napi/url.js b/runtime/main/extend/systemplugin/napi/url.js index 32a4ed25..296e509d 100644 --- a/runtime/main/extend/systemplugin/napi/url.js +++ b/runtime/main/extend/systemplugin/napi/url.js @@ -1,104 +1,136 @@ -import { paramMock } from "../utils" +import {paramMock} from '../utils'; export function mockUrl() { - const result = { - URLSearchParams: function(...args) { - console.warn("url.URLSearchParams interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return URLSearchParamsMock; - }, - URL: function(...args) { - console.warn("url.URL interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return URLMock; + const URLSearchParamsClass = class URLSearchParams { + constructor(...args) { + console.warn('url.URLSearchParams.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer' + + ' may be different from that on a real device.'); + this.append = function(...args) { + console.warn('url.URLSearchParams.append interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + }; + this.delete = function(...args) { + console.warn('url.URLSearchParams.delete interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + }; + this.getAll = function(...args) { + console.warn('url.URLSearchParams.getAll interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return [paramMock.paramStringMock]; + }; + this.entries = function(...args) { + console.warn('url.URLSearchParams.entries interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + const IteratorTwoStringMock = { + *[Symbol.iterator]() { + yield [paramMock.paramStringMock, paramMock.paramStringMock]; + } + }; + return IteratorTwoStringMock; + }; + this.forEach = function(...args) { + console.warn('url.URLSearchParams.forEach interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + }; + this.get = function(...args) { + console.warn('url.URLSearchParams.get interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramStringMock; + }; + this.has = function(...args) { + console.warn('url.URLSearchParams.has interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramBooleanMock; + }; + this.set = function(...args) { + console.warn('url.URLSearchParams.set interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + }; + this.sort = function(...args) { + console.warn('url.URLSearchParams.sort interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + }; + this.keys = function(...args) { + console.warn('url.URLSearchParams.keys interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + const IteratorStringMock = { + *[Symbol.iterator]() { + yield paramMock.paramStringMock; + } + }; + return IteratorStringMock; + }; + this.values = function(...args) { + console.warn('url.URLSearchParams.values interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + const IteratorStringMock = { + *[Symbol.iterator]() { + yield paramMock.paramStringMock; + } + }; + return IteratorStringMock; + }; + this.toString = function(...args) { + console.warn('url.URLSearchParams.toString interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramStringMock; + }; + } + [Symbol.iterator]() { + console.warn('url.URLSearchParams.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + let index = 0; + const IteratorTwoStringMock = { + next: () => { + if (index < 1) { + const returnValue = [paramMock.paramStringMock, paramMock.paramStringMock]; + index++; + return { + value: returnValue, + done: false + }; + } else { + return { + done: true + }; + } } + }; + return IteratorTwoStringMock; } - const URLSearchParamsMock = { - append: function(...args) { - console.warn("URLSearchParams.append interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - delete: function(...args) { - console.warn("URLSearchParams.delete interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - getAll: function(...args) { - console.warn("URLSearchParams.getAll interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - var arrStr = new Array() - return arrStr; - }, - entries: function(...args) { - console.warn("URLSearchParams.entries interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramObjectMock; - }, - forEach: function(...args) { - console.warn("URLSearchParams.forEach interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - get: function(...args) { - console.warn("URLSearchParams.get interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramStringMock; - }, - has: function(...args) { - console.warn("URLSearchParams.has interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - set: function(...args) { - console.warn("URLSearchParams.set interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - sort: function(...args) { - console.warn("URLSearchParams.sort interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - keys: function(...args) { - console.warn("URLSearchParams.keys interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramObjectMock; - }, - values: function(...args) { - console.warn("URLSearchParams.values interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramObjectMock; - }, - [Symbol.iterator]: function(...args) { - console.warn("URLSearchParams.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramObjectMock; - }, - toString: function(...args) { - console.warn("URLSearchParams.toString interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramStringMock; - } + }; + const URLClass = class URL { + constructor(...args) { + console.warn('url.URL.constructor interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + this.toString = function(...args) { + console.warn('URL.toString interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramStringMock; + }; + this.toJSON = function(...args) { + console.warn('URL.toJSON interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramStringMock; + }; + this.hash = '[PC preview] unknow hash'; + this.host = '[PC preview] unknow host'; + this.hostname = '[PC preview] unknow hostname'; + this.href = '[PC preview] unknow href'; + this.origin = '[PC preview] unknow origin'; + this.password = '[PC preview] unknow password'; + this.pathname = '[PC preview] unknow pathname'; + this.port = '[PC preview] unknow port'; + this.protocol = '[PC preview] unknow protocol'; + this.search = '[PC preview] unknow search'; + this.searchParams = new URLSearchParamsClass(); + this.username = '[PC preview] unknow username'; } - const URLMock = { - toString: function(...args) { - console.warn("URL.toString interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramStringMock; - }, - toJSON: function(...args) { - console.warn("URL.toJSON interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramStringMock; - }, - hash: '[PC preview] unknow hash', - host: '[PC preview] unknow host', - hostname: '[PC preview] unknow hostname', - href: '[PC preview] unknow href', - origin: '[PC preview] unknow origin', - password: '[PC preview] unknow password', - pathname: '[PC preview] unknow pathname', - port: '[PC preview] unknow port', - protocol: '[PC preview] unknow protocol', - search: '[PC preview] unknow search', - searchParams: URLSearchParamsMock, - username: '[PC preview] unknow username', - } - return result; -} \ No newline at end of file + }; + const result = { + URLSearchParams: URLSearchParamsClass, + URL: URLClass + }; + return result; +} diff --git a/runtime/main/extend/systemplugin/napi/util.js b/runtime/main/extend/systemplugin/napi/util.js index 28d1ec17..22c40ca8 100644 --- a/runtime/main/extend/systemplugin/napi/util.js +++ b/runtime/main/extend/systemplugin/napi/util.js @@ -1,60 +1,77 @@ -import { paramMock } from "../utils" +import {paramMock} from '../utils'; export function mockUtil() { - const result = { - printf: function(...args) { - console.warn("util.printf interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramStringMock; - }, - getErrorString: function(...args) { - console.warn("util.getErrorString interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramStringMock; - }, - callbackWrapper: function(...args) { - console.warn("util.callbackWrapper interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - promiseWrapper: function(...args) { - console.warn("util.promiseWrapper interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramObjectMock; - }, - TextDecoder: function(...args) { - console.warn("util.TextDecoder interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return TextDecoderMock; - }, - TextEncoder: function(...args) { - console.warn("util.TextEncoder interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return TextEncoderMock; - } + const result = { + printf: function(...args) { + console.warn('util.printf interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramStringMock; + }, + getErrorString: function(...args) { + console.warn('util.getErrorString interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramStringMock; + }, + callbackWrapper: function(...args) { + console.warn('util.callbackWrapper interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return function(...args) { + console.warn('util.callbackWrapper.return function interface mocked in the Previewer. How this interface' + + ' works on the Previewer may be different from that on a real device.'); + }; + }, + promiseWrapper: function(func) { + console.warn('util.promiseWrapper interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + if (typeof func === 'function') { + return function(...args) { + return new Promise((resolve, reject) => { + const callback = function(err, ...values) { + if (err) { + reject(err); + } else { + resolve(values); + } + }; + func.apply(null, [...args, callback]); + }); + }; + } + }, + TextDecoder: function(...args) { + console.warn('util.TextDecoder interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return TextDecoderMock; + }, + TextEncoder: function(...args) { + console.warn('util.TextEncoder interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return TextEncoderMock; } - const TextDecoderMock = { - encoding: '[PC preview] unknow encoding', - fatal: '[PC preview] unknow fatal', - ignoreBOM: '[PC preview] unknow ignoreBOM', - decode: function (...args) { - console.warn("TextDecoder.decode interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramStringMock; - }, + }; + const TextDecoderMock = { + encoding: '[PC preview] unknow encoding', + fatal: '[PC preview] unknow fatal', + ignoreBOM: '[PC preview] unknow ignoreBOM', + decode: function(...args) { + console.warn('TextDecoder.decode interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramStringMock; } - const TextEncoderMock = { - encoding: '[PC preview] unknow encoding', - encode: function(...args) { - console.warn("TextEncoder.encode interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - const arr = new Uint8Array() - return arr; - }, - encodeInto: function(...args) { - console.warn("TextEncoder.encodeInto interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramObjectMock; - } + }; + const TextEncoderMock = { + encoding: '[PC preview] unknow encoding', + encode: function(...args) { + console.warn('TextEncoder.encode interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + const arr = new Uint8Array(); + return arr; + }, + encodeInto: function(...args) { + console.warn('TextEncoder.encodeInto interface mocked in the Previewer. How this interface works on the Previewer' + + ' may be different from that on a real device.'); + return paramMock.paramObjectMock; } - return result; + }; + return result; } diff --git a/runtime/main/extend/systemplugin/napi/vibrator.js b/runtime/main/extend/systemplugin/napi/vibrator.js new file mode 100644 index 00000000..d0eac90f --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/vibrator.js @@ -0,0 +1,38 @@ +import { paramMock } from "../utils" + +export function mockVibrator() { + const EffectId = { + EFFECT_CLOCK_TIMER: "haptic.clock.timer" + } + const VibratorStopMode = { + VIBRATOR_STOP_MODE_TIME: "time", + VIBRATOR_STOP_MODE_PRESET: "preset" + } + const vibrator = { + vibrate: function (...args) { + console.warn("vibrator.vibrate 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }) + } + }, + stop: function (...args) { + console.warn("vibrator.stop 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }) + } + } + } + return vibrator +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/net.js b/runtime/main/extend/systemplugin/net.js index 8a0356d2..3e75be63 100644 --- a/runtime/main/extend/systemplugin/net.js +++ b/runtime/main/extend/systemplugin/net.js @@ -1,500 +1,569 @@ -import {paramMock} from "./utils" +import { paramMock } from "./utils" export function mockWebSocket() { global.systemplugin.net = {} const WebSocketMock = { - connect: function (...args) { - console.warn("WebSocket.connect 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - send: function (...args) { - console.warn("WebSocket.send 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - close: function (...args) { - console.warn("WebSocket.close 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - on: function (...args) { - console.warn("WebSocket.on 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 (typeof args[len - 1] === 'function') { - if (args[0] === 'open') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); - } else if (args[0] === 'message') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else if (args[0] === 'close') { - args[len - 1].call(this, paramMock.businessErrorMock, { - code: "[PC Preview] unknow code", - reason: "[PC Preview] unknow reason" - }); - } else if (args[0] === 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } - } - }, - off: function (...args) { - console.warn("WebSocket.off 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 (typeof args[len - 1] === 'function') { - if (args[0] === 'open') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); - } else if (args[0] === 'message') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else if (args[0] === 'close') { - args[len - 1].call(this, paramMock.businessErrorMock,{ - code: "[PC Preview] unknow code", - reason: "[PC Preview] unknow reason" - }); - } else if (args[0] === 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } - } + connect: function (...args) { + console.warn("WebSocket.connect 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) } + }, + send: function (...args) { + console.warn("WebSocket.send 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + close: function (...args) { + console.warn("WebSocket.close 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + on: function (...args) { + console.warn("WebSocket.on 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 (typeof args[len - 1] === 'function') { + if (args[0] === 'open') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); + } else if (args[0] === 'message') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else if (args[0] === 'close') { + args[len - 1].call(this, paramMock.businessErrorMock, { + code: "[PC Preview] unknow code", + reason: "[PC Preview] unknow reason" + }); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + }, + off: function (...args) { + console.warn("WebSocket.off 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 (typeof args[len - 1] === 'function') { + if (args[0] === 'open') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); + } else if (args[0] === 'message') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else if (args[0] === 'close') { + args[len - 1].call(this, paramMock.businessErrorMock, { + code: "[PC Preview] unknow code", + reason: "[PC Preview] unknow reason" + }); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + } } global.systemplugin.net.webSocket = { - createWebSocket: function () { - console.warn("net.webSocket.createWebSocket interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return WebSocketMock; - } + createWebSocket: function () { + console.warn("net.webSocket.createWebSocket interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebSocketMock; + } } } export function mockHttp() { - const HttpResponseMock = { - result: "[PC Preview] unknow result", - responseCode: "[PC Preview] unknow responseCode", - header: "[PC Preview] unknow header" + const HttpResponseCacheOptions = { + filePath: "[PC Preview] unknow filePath", + fileChildPath: "[PC Preview] unknow fileChildPath", + cacheSize: "[PC Preview] unknow cacheSize" + } + const HttpResponseCache = { + close: function (...args) { + console.warn("net.HttpResponseCache.close 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + delete: function (...args) { + console.warn("net.HttpResponseCache.delete 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + flush: function (...args) { + console.warn("net.HttpResponseCache.flush 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } } - const HttpRequestMock = { - request: function (...args) { - console.warn("HttpRequest.request 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, HttpResponseMock); - } else { - return new Promise((resolve, reject) => { - resolve(HttpResponseMock); - }) - } - }, - destroy: function () { - console.warn("HttpRequest.destroy interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - on: function (...args) { - console.warn("HttpRequest.on 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); - } - }, - off: function (...args) { - console.warn("HttpRequest.off 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); - } - } + } + const HttpResponseMock = { + result: "[PC Preview] unknow result", + responseCode: "[PC Preview] unknow responseCode", + header: "[PC Preview] unknow header" + } + const HttpRequestMock = { + request: function (...args) { + console.warn("HttpRequest.request 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HttpResponseMock); + } else { + return new Promise((resolve, reject) => { + resolve(HttpResponseMock); + }) + } + }, + destroy: function () { + console.warn("HttpRequest.destroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + on: function (...args) { + console.warn("HttpRequest.on 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); + } + }, + off: function (...args) { + console.warn("HttpRequest.off 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); + } } - global.systemplugin.net.http = { - createHttp: function () { - console.warn("net.http.createHttp interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return HttpRequestMock; - } + } + global.systemplugin.net.http = { + createHttp: function () { + console.warn("net.http.createHttp interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return HttpRequestMock; + }, + getInstalledHttpResponseCache: function (...args) { + console.warn("net.http.getInstalledHttpResponseCache 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HttpResponseCache); + } else { + return new Promise((resolve, reject) => { + resolve(HttpResponseCache); + }) + } + }, + createHttpResponseCache: function (...args) { + console.warn("net.http.createHttpResponseCache 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HttpResponseCacheOptions); + } else { + return new Promise((resolve, reject) => { + resolve(HttpResponseCache); + }) + } } + } } export function mockMdns() { - const localServiceInfoMock = { - serviceType: "[PC Preview] unknow serviceType", - serviceName: "[PC Preview] unknow serviceName", - host: "[PC Preview] unknow host", - port: "[PC Preview] unknow port" - } - global.systemplugin.net.mdns = { - on: function (...args) { - console.warn("net.mdns.on 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 (typeof args[len - 1] === 'function') { - if (args[0] === 'serviceAdd') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceRemove') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceStart') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceStop') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceFound') { - args[len - 1].call(this, localServiceInfoMock); - } else if (args[0] === 'serviceLost') { - args[len - 1].call(this, localServiceInfoMock); - } else if (args[0] === 'serviceResolve') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceLost') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'error') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else { - args[len - 1].call(this); - } - } - }, - off: function (...args) { - console.warn("net.mdns.off 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 (args[0] === 'serviceAdd') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceRemove') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceStart') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceStop') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceFound') { - args[len - 1].call(this, localServiceInfoMock); - } else if (args[0] === 'serviceLost') { - args[len - 1].call(this, localServiceInfoMock); - } else if (args[0] === 'serviceResolve') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'serviceLost') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else if (args[0] === 'error') { - args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); - } else { - args[len - 1].call(this); - } - }, - addLocalService: function (...args) { - console.warn("net.mdns.addLocalService 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - removeLocalService: function (...args) { - console.warn("net.mdns.removeLocalService 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - startSearchingMDNS: function (...args) { - console.warn("net.mdns.startSearchingMDNS 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - stopSearchingMDNS: function (...args) { - console.warn("net.mdns.stopSearchingMDNS 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } + const localServiceInfoMock = { + serviceType: "[PC Preview] unknow serviceType", + serviceName: "[PC Preview] unknow serviceName", + host: "[PC Preview] unknow host", + port: "[PC Preview] unknow port" + } + global.systemplugin.net.mdns = { + on: function (...args) { + console.warn("net.mdns.on 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 (typeof args[len - 1] === 'function') { + if (args[0] === 'serviceAdd') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceRemove') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceStart') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceStop') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceFound') { + args[len - 1].call(this, localServiceInfoMock); + } else if (args[0] === 'serviceLost') { + args[len - 1].call(this, localServiceInfoMock); + } else if (args[0] === 'serviceResolve') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceLost') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'error') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else { + args[len - 1].call(this); } + } + }, + off: function (...args) { + console.warn("net.mdns.off 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 (typeof args[len - 1] === 'function') { + if (args[0] === 'serviceAdd') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceRemove') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceStart') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceStop') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceFound') { + args[len - 1].call(this, localServiceInfoMock); + } else if (args[0] === 'serviceLost') { + args[len - 1].call(this, localServiceInfoMock); + } else if (args[0] === 'serviceResolve') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'serviceLost') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else if (args[0] === 'error') { + args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 }); + } else { + args[len - 1].call(this); + } + } + }, + addLocalService: function (...args) { + console.warn("net.mdns.addLocalService 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + removeLocalService: function (...args) { + console.warn("net.mdns.removeLocalService 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + startSearchingMDNS: function (...args) { + console.warn("net.mdns.startSearchingMDNS 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + stopSearchingMDNS: function (...args) { + console.warn("net.mdns.stopSearchingMDNS 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } } + } } -export function mockSocket(){ - const SocketStateBase = { - isBound: "[PC Preview] unknow isBound", - isClose: "[PC Preview] unknow isClose", - isConnected: "[PC Preview] unknow isConnected" - } - const SocketRemoteInfo = { - address: "[PC Preview] unknow address", - family: "[PC Preview] unknow family", - port: "[PC Preview] unknow port", - size: "[PC Preview] unknow size" - } - const NetAddress = { - address: "[PC Preview] unknow saddressize", - family: "[PC Preview] unknow family", - port: "[PC Preview] unknow port " - } - const UDPSocket = { - bind: function (...args){ - console.warn("UDPSocket.bind 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - send: function (...args) { - console.warn("UDPSocket.send 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) +export function mockSocket() { + const SocketStateBase = { + isBound: "[PC Preview] unknow isBound", + isClose: "[PC Preview] unknow isClose", + isConnected: "[PC Preview] unknow isConnected" + } + const SocketRemoteInfo = { + address: "[PC Preview] unknow address", + family: "[PC Preview] unknow family", + port: "[PC Preview] unknow port", + size: "[PC Preview] unknow size" + } + const NetAddress = { + address: "[PC Preview] unknow saddressize", + family: "[PC Preview] unknow family", + port: "[PC Preview] unknow port " + } + const UDPSocket = { + bind: function (...args) { + console.warn("UDPSocket.bind 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + send: function (...args) { + console.warn("UDPSocket.send 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + close: function (...args) { + console.warn("UDPSocket.close 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getState: function (...args) { + console.warn("UDPSocket.getState 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, SocketStateBase) + } else { + return new Promise((resolve, reject) => { + resolve(SocketStateBase); + }) + } + }, + setExtraOptions: function (...args) { + console.warn("UDPSocket.setExtraOptions 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + on: function (...args) { + console.warn("UDPSocket.on 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 (typeof args[len - 1] === 'function') { + if (args[0] === 'message') { + args[len - 1].call(this, { + message: "[PC Preview] unknow message", + remoteInfo: SocketRemoteInfo + }); + } else if (args[0] === 'listening') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); } - }, - close: function (...args) { - console.warn("UDPSocket.close 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getState: function (...args) { - console.warn("UDPSocket.getState 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock, SocketStateBase) - } else { - return new Promise((resolve, reject) => { - resolve(SocketStateBase); - }) - } - }, - setExtraOptions: function (...args) { - console.warn("UDPSocket.setExtraOptions 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - on: function (...args) { - console.warn("UDPSocket.on 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 (typeof args[len - 1] === 'function') { - if (args[0] === 'message') { - args[len - 1].call(this, { - message: "[PC Preview] unknow message", - remoteInfo: SocketRemoteInfo - }); - } else if (args[0] === 'listening') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else if (args[0] === 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } - } - }, - off: function (...args) { - console.warn("UDPSocket.off 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 (typeof args[len - 1] === 'function') { - if (args[0] === 'message') { - args[len - 1].call(this, { - message: "[PC Preview] unknow message", - remoteInfo: SocketRemoteInfo - }); - } else if (args[0] === 'listening') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else if (args[0] === 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } + } + }, + off: function (...args) { + console.warn("UDPSocket.off 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 (typeof args[len - 1] === 'function') { + if (args[0] === 'message') { + args[len - 1].call(this, { + message: "[PC Preview] unknow message", + remoteInfo: SocketRemoteInfo + }); + } else if (args[0] === 'listening') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); } } } + } - const TCPSocket = { - bind: function (...args){ - console.warn("TcpSocket.bind 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - connect: function (...args) { - console.warn("TcpSocket.connect 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - send: function (...args) { - console.warn("TcpSocket.send 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) + const TCPSocket = { + bind: function (...args) { + console.warn("TcpSocket.bind 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + connect: function (...args) { + console.warn("TcpSocket.connect 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + send: function (...args) { + console.warn("TcpSocket.send 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + close: function (...args) { + console.warn("TcpSocket.close 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getRemoteAddress: function (...args) { + console.warn("TcpSocket.getRemoteAddress 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetAddress) + } else { + return new Promise((resolve, reject) => { + resolve(NetAddress); + }) + } + }, + getState: function (...args) { + console.warn("TcpSocket.getState 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, SocketStateBase) + } else { + return new Promise((resolve, reject) => { + resolve(SocketStateBase); + }) + } + }, + setExtraOptions: function (...args) { + console.warn("TcpSocket.setExtraOptions 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + on: function (...args) { + console.warn("TcpSocket.on 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 (typeof args[len - 1] === 'function') { + if (args[0] === 'message') { + args[len - 1].call(this, { + message: "[PC Preview] unknow message", + remoteInfo: SocketRemoteInfo + }); + } else if (args[0] === 'listening') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); } - }, - close: function (...args) { - console.warn("TcpSocket.close 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getRemoteAddress: function (...args) { - console.warn("TcpSocket.getRemoteAddress 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock, NetAddress) - } else { - return new Promise((resolve, reject) => { - resolve(NetAddress); - }) - } - }, - getState: function (...args) { - console.warn("TcpSocket.getState 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock, SocketStateBase) - } else { - return new Promise((resolve, reject) => { - resolve(SocketStateBase); - }) - } - }, - setExtraOptions: function (...args) { - console.warn("TcpSocket.setExtraOptions 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( typeof args[len - 1] === 'function') { - args[len -1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - on: function (...args) { - console.warn("TcpSocket.on 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 (typeof args[len - 1] === 'function') { - if (args[0] === 'message') { - args[len - 1].call(this, { - message: "[PC Preview] unknow message", - remoteInfo: SocketRemoteInfo - }); - } else if (args[0] === 'listening') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else if (args[0] === 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } - } - }, - off: function (...args) { - console.warn("TcpSocket.off 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 (typeof args[len - 1] === 'function') { - if (args[0] === 'message') { - args[len - 1].call(this, { - message: "[PC Preview] unknow message", - remoteInfo: SocketRemoteInfo - }); - } else if (args[0] === 'listening') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else if (args[0] === 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } + } + }, + off: function (...args) { + console.warn("TcpSocket.off 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 (typeof args[len - 1] === 'function') { + if (args[0] === 'message') { + args[len - 1].call(this, { + message: "[PC Preview] unknow message", + remoteInfo: SocketRemoteInfo + }); + } else if (args[0] === 'listening') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); } } } - global.systemplugin.net.socket ={ - constructUDPSocketInstance : function () { - console.warn("net.socket.constructUDPSocketInstance interface mocked in the Previewer. How this interface works on the Previewer" + + } + global.systemplugin.net.socket = { + constructUDPSocketInstance: function () { + console.warn("net.socket.constructUDPSocketInstance interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") - return UDPSocket; - }, - constructTCPSocketInstance : function () { - console.warn("net.socket.constructTCPSocketInstance interface mocked in the Previewer. How this interface works on the Previewer" + + return UDPSocket; + }, + constructTCPSocketInstance: function () { + console.warn("net.socket.constructTCPSocketInstance interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") - return TCPSocket; - } + return TCPSocket; } + } } export function mockHotspot() { @@ -835,12 +904,12 @@ export function mockConnection() { } else if (args[0] === 'netBlockStatusChange') { args[len - 1].call(this, paramMock.businessErrorMock, { NetHandle, blocked }); } else if (args[0] === 'netCapabilitiesChange') { - args[len - 1].call(this, { NetHandle, netCap }); + args[len - 1].call(this, { NetHandle, NetCap }); } else if (args[0] === 'netConnectionPropertiesChange') { - args[len - 1].call(this, { netHandle, connectionProperties }); + args[len - 1].call(this, { NetHandle, ConnectionProperties }); } else if (args[0] === 'netLosing') { args[len - 1].call(this, { - netHandle, + NetHandle, maxMsToLive: "[PC Preview] unknow maxMsToLive" }); } else if (args[0] === 'netLost') { @@ -860,12 +929,12 @@ export function mockConnection() { } else if (args[0] === 'netBlockStatusChange') { args[len - 1].call(this, { NetHandle, blocked }); } else if (args[0] === 'netCapabilitiesChange') { - args[len - 1].call(this, { NetHandle, netCap }); + args[len - 1].call(this, { NetHandle, NetCap }); } else if (args[0] === 'netConnectionPropertiesChange') { - args[len - 1].call(this, { netHandle, connectionProperties }); + args[len - 1].call(this, { NetHandle, ConnectionProperties }); } else if (args[0] === 'netLosing') { args[len - 1].call(this, { - netHandle, + NetHandle, maxMsToLive: "[PC Preview] unknow maxMsToLive" }); } else if (args[0] === 'netLost') { @@ -1067,5 +1136,29 @@ export function mockConnection() { }) } }, + reportNetConnected: function (...args) { + console.warn("net.connection.reportNetConnected 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + reportNetDisconnected: function (...args) { + console.warn("net.connection.reportNetDisconnected 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, } } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/ohos/bluetooth.js b/runtime/main/extend/systemplugin/ohos/bluetooth.js index 26e3aa76..191776e3 100644 --- a/runtime/main/extend/systemplugin/ohos/bluetooth.js +++ b/runtime/main/extend/systemplugin/ohos/bluetooth.js @@ -111,9 +111,9 @@ export function mockOhosBluetooth() { "How this interface works on the Previewer may be different from that on a real device.") return paramMock.paramBooleanMock }, - on: function(...args) { + on: function (...args) { console.warn("GattServer.on interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") + "How this interface works on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { if (args[0] == 'characteristicRead') { @@ -129,9 +129,9 @@ export function mockOhosBluetooth() { } } }, - off: function(...args) { + off: function (...args) { console.warn("GattServer.off interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") + "How this interface works on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { if (args[0] == 'characteristicRead') { @@ -164,53 +164,53 @@ export function mockOhosBluetooth() { "How this interface works on the Previewer may be different from that on a real device.") return paramMock.paramBooleanMock }, - getDeviceName: function(...args) { + getDeviceName: function (...args) { console.warn("GattClientDevice.getDeviceName 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } }, - getServices: function(...args) { + getServices: function (...args) { console.warn("GattClientDevice.getServices 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, gattServicesMock); - } else { - return new Promise((resolve, reject) => { - resolve(gattServicesMock); - }) - } + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, gattServicesMock); + } else { + return new Promise((resolve, reject) => { + resolve(gattServicesMock); + }) + } }, - readCharacteristicValue: function(...args) { + readCharacteristicValue: function (...args) { console.warn("GattClientDevice.readCharacteristicValue 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, BLECharacteristicMock); - } else { - return new Promise((resolve, reject) => { - resolve(BLECharacteristicMock); - }) - } + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, BLECharacteristicMock); + } else { + return new Promise((resolve, reject) => { + resolve(BLECharacteristicMock); + }) + } }, - readDescriptorValue: function(...args) { + readDescriptorValue: function (...args) { console.warn("GattClientDevice.readDescriptorValue 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, BLEDescriptorMock); - } else { - return new Promise((resolve, reject) => { - resolve(BLEDescriptorMock); - }) - } + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, BLEDescriptorMock); + } else { + return new Promise((resolve, reject) => { + resolve(BLEDescriptorMock); + }) + } }, writeCharacteristicValue: function (...args) { console.warn("GattClientDevice.writeCharacteristicValue interface mocked in the Previewer." + @@ -222,17 +222,17 @@ export function mockOhosBluetooth() { "How this interface works on the Previewer may be different from that on a real device.") return paramMock.paramBooleanMock }, - getRssiValue: function(...args) { + getRssiValue: function (...args) { console.warn("GattClientDevice.getRssiValue 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } }, setBLEMtuSize: function (...args) { console.warn("GattClientDevice.setBLEMtuSize interface mocked in the Previewer." + @@ -244,9 +244,9 @@ export function mockOhosBluetooth() { "How this interface works on the Previewer may be different from that on a real device.") return paramMock.paramBooleanMock }, - on: function(...args) { + on: function (...args) { console.warn("GattClientDevice.on interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") + "How this interface works on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { if (args[0] == 'BLECharacteristicChange') { @@ -256,9 +256,9 @@ export function mockOhosBluetooth() { } } }, - off: function(...args) { + off: function (...args) { console.warn("GattClientDevice.off interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") + "How this interface works on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { if (args[0] == 'BLECharacteristicChange') { @@ -286,49 +286,49 @@ export function mockOhosBluetooth() { return paramMock.paramBooleanMock }, }, - global.ohosplugin.bluetooth.BLE = { - createGattServer: function () { - console.warn("bluetooth.BLE.createGattServer interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - return GattServerMock - }, - createGattClientDevice: function (...args) { - console.warn("bluetooth.BLE.createGattClientDevice interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - return GattClientDeviceMock - }, - getConnectedBLEDevices: function () { - console.warn("bluetooth.BLE.startBLEScan interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - return connectedBLEDevicesMock - }, - startBLEScan: function (...args) { - console.warn("bluetooth.BLE.startBLEScan interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - }, - stopBLEScan: function () { - console.warn("bluetooth.BLE.stopBLEScan interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - }, - on: function(...args) { - console.warn("bluetooth.BLE.on 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 (typeof args[len - 1] === 'function') { - if (args[0] == 'BLEDeviceFind') { - args[len - 1].call(this, [scanResultMock]); + global.ohosplugin.bluetooth.BLE = { + createGattServer: function () { + console.warn("bluetooth.BLE.createGattServer interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + return GattServerMock + }, + createGattClientDevice: function (...args) { + console.warn("bluetooth.BLE.createGattClientDevice interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + return GattClientDeviceMock + }, + getConnectedBLEDevices: function () { + console.warn("bluetooth.BLE.getConnectedBLEDevices interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + return connectedBLEDevicesMock + }, + startBLEScan: function (...args) { + console.warn("bluetooth.BLE.startBLEScan interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + }, + stopBLEScan: function () { + console.warn("bluetooth.BLE.stopBLEScan interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + }, + on: function (...args) { + console.warn("bluetooth.BLE.on 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 (typeof args[len - 1] === 'function') { + if (args[0] == 'BLEDeviceFind') { + args[len - 1].call(this, [scanResultMock]); + } } - } - }, - off: function(...args) { - console.warn("bluetooth.BLE.off 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 (typeof args[len - 1] === 'function') { - if (args[0] == 'BLEDeviceFind') { - args[len - 1].call(this, [scanResultMock]); + }, + off: function (...args) { + console.warn("bluetooth.BLE.off 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 (typeof args[len - 1] === 'function') { + if (args[0] == 'BLEDeviceFind') { + args[len - 1].call(this, [scanResultMock]); + } } - } - }, - } + }, + } } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/ohos/bundleManager.js b/runtime/main/extend/systemplugin/ohos/bundleManager.js index c343f701..4396f8e7 100644 --- a/runtime/main/extend/systemplugin/ohos/bundleManager.js +++ b/runtime/main/extend/systemplugin/ohos/bundleManager.js @@ -1,15 +1,573 @@ import { paramMock } from "../utils" +import { PixelMapMock } from "../multimedia" export function mockBundleManager() { - const BundleInstallerMock= {} -const BundleInfoMock = { - name: "[PC preview] unknown name", - type: "[PC preview] unknown type", - appId: "[PC preview] unknown app id", - uid: "[PC preview] unknown uid", - installTime: "[PC preview] unknown install time", - updateTime: "[PC preview] unknown up date time", - appInfo: { + + const ArrayNumberMock = ["[PC preview] unknown array number"] + const ArrayStringMock = ["[PC preview] unknown array string"] + const LauncherAbilityInfosMock = [ + { + abilityInfo: { + bundleName: "[PC preview] unknown bundle name", + name: "[PC preview] unknown name", + label: "[PC preview] unknown label", + description: "[PC preview] unknown description", + icon: "[PC preview] unknown icon", + labelId: "[PC preview] unknown label id", + descriptionId: "[PC preview] unknown description id", + iconId: "[PC preview] unknown icon id", + moduleName: "[PC preview] unknown module name", + process: "[PC preview] unknown process", + targetAbility: "[PC preview] unknown target ability", + backgroundModes: "[PC preview] unknown background modes", + isVisible: "[PC preview] unknown is visible", + formEnabled: "[PC preview] unknown form enabled", + type: "[PC preview] unknown type", + subType: "[PC preview] unknown sub type", + orientation: "[PC preview] unknown orientation", + launchMode: "[PC preview] unknown launch mode", + permissions: ["[PC preview] unknown permission"], + deviceTypes: ["[PC preview] unknown device type"], + deviceCapabilities: ["[PC preview] unknown device capability"], + readPermission: "[PC preview] unknown read permission", + writePermission: "[PC preview] unknown write permission", + applicationInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + formEntity: "[PC preview] unknown form entity", + minFormHeight: "[PC preview] unknown min form height", + defaultFormHeight: "[PC preview] unknown default form height", + minFormWidth: "[PC preview] unknown min form width", + uri: "[PC preview] unknown uri", + customizeData: { + key: "[PC preview] unknown key", + value: [ + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + }, + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + } + ] + }, + }, + elementName: { + deviceId: "[PC preview] unknown device id", + bundleName: "[PC preview] unknown bundle name", + abilityName: "[PC preview] unknown ability name", + uri: "[PC preview] unknown uri", + shortName: "[PC preview] unknown short name", + }, + userId: "[PC preview] unknown user id", + installTime: "[PC preview] unknown install time", + }, + ] + const ModeleUsageRecordsMock = [ + { + bundleName: "[PC preview] unknown bundle name", + appLabelId: "[PC preview] unknown app label id", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + descriptionId: "[PC preview] unknown description id", + abilityName: "[PC preview] unknown ability name", + abilityLabelId: "[PC preview] unknown ability label id", + abilityDescriptionId: "[PC preview] unknown ability description id", + abilityIconId: "[PC preview] unknown ability icon id", + launchedCount: "[PC preview] unknown launched count", + lastLaunchTime: "[PC preview] unknown last launch time", + isRemoved: "[PC preview] unknown is removed", + installationFreeSupported: "[PC preview] unknown installation free supported", + }, + ] + const ShortcutInfosMock = [ + { + id: "[PC preview] unknown id", + bundleName: "[PC preview] unknown bundle name", + hostAbility: "[PC preview] unknown host ability", + icon: "[PC preview] unknown icon", + label: "[PC preview] unknown label", + disableMessage: "[PC preview] unknown disable message", + wants: [ + { + targetBundle: "[PC preview] unknown target bundle", + targetClass: "[PC preview] unknown target class", + }], + isStatic: "[PC preview] unknown is static", + isHomeShortcut: "[PC preview] unknown is home shortcut", + isEnabled: "[PC preview] unknown is enabled", + }, + ] + const WantMock = { + deviceId: "[PC preview] unknown device id", + bundleName: "[PC preview] unknown bundle name", + abilityName: "[PC preview] unknown ability name", + uri: "[PC preview] unknown uri", + type: "[PC preview] unknown type", + action: "[PC preview] unknown action", + entities: "[PC preview] unknown entities", + flags: "[PC preview] unknown flags", + } + const BundleInstallerMock = {} + const BundleInfoMock = { + name: "[PC preview] unknown name", + type: "[PC preview] unknown type", + appId: "[PC preview] unknown app id", + uid: "[PC preview] unknown uid", + installTime: "[PC preview] unknown install time", + updateTime: "[PC preview] unknown up date time", + appInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + abilityInfo: [ + { + bundleName: "[PC preview] unknown bundle name", + name: "[PC preview] unknown name", + label: "[PC preview] unknown label", + description: "[PC preview] unknown description", + icon: "[PC preview] unknown icon", + labelId: "[PC preview] unknown label id", + descriptionId: "[PC preview] unknown description id", + iconId: "[PC preview] unknown icon id", + moduleName: "[PC preview] unknown module name", + process: "[PC preview] unknown process", + targetAbility: "[PC preview] unknown target ability", + backgroundModes: "[PC preview] unknown background modes", + isVisible: "[PC preview] unknown is visible", + formEnabled: "[PC preview] unknown form enabled", + type: "[PC preview] unknown type", + subType: "[PC preview] unknown sub type", + orientation: "[PC preview] unknown orientation", + launchMode: "[PC preview] unknown launch mode", + permissions: ["[PC preview] unknown permission"], + deviceTypes: ["[PC preview] unknown device type"], + deviceCapabilities: ["[PC preview] unknown device capability"], + readPermission: "[PC preview] unknown read permission", + writePermission: "[PC preview] unknown write permission", + applicationInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + formEntity: "[PC preview] unknown form entity", + minFormHeight: "[PC preview] unknown min form height", + defaultFormHeight: "[PC preview] unknown default form height", + minFormWidth: "[PC preview] unknown min form width", + defaultFormWidth: "[PC preview] unknown default form width", + uri: "[PC preview] unknown uri", + customizeData: { + key: "[PC preview] unknown key", + value: [ + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + }, + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + } + ] + }, + } + ], + reqPermissions: ["[PC preview] unknown repermission"], + reqPermissionDetails: [ + { + name: "[PC preview] unknown name", + reason: "[PC preview] unknown reason", + usedScene: { + abilities: ["[PC preview] unknown ability"], + when: "[PC preview] unknown when", + } + } + ], + vendor: "[PC preview] unknown vendor", + versionCode: "[PC preview] unknown versionCode", + versionName: "[PC preview] unknown versionName", + compatibleVersion: "[PC preview] unknown compatibleVersion", + targetVersion: "[PC preview] unknown targetVersion", + isCompressNativeLibs: "[PC preview] unknown isCompressNativeLibs", + hapModuleInfo: [ + { + name: "[PC preview] unknown name", + description: "[PC preview] unknown desciption", + descriptionId: "[PC preview] unknown description id", + icon: "[PC preview] unknown icon", + label: "[PC preview] unknown label", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown iconid", + backgroundImg: "[PC preview] unknown back ground img", + supportedModes: "[PC preview] unknown supported modes", + reqCapabilities: ["[PC preview] unknown reqcapability"], + deviceTypes: ["[PC preview] unknown device type"], + abilityInfo: [ + { + bundleName: "[PC preview] unknown bundle name", + name: "[PC preview] unknown name", + label: "[PC preview] unknown label", + description: "[PC preview] unknown description", + icon: "[PC preview] unknown icon", + labelId: "[PC preview] unknown label id", + descriptionId: "[PC preview] unknown description id", + iconId: "[PC preview] unknown icon id", + moduleName: "[PC preview] unknown module name", + process: "[PC preview] unknown process", + targetAbility: "[PC preview] unknown target ability", + backgroundModes: "[PC preview] unknown back ground modes", + isVisible: "[PC preview] unknown is visible", + formEnabled: "[PC preview] unknown form enabled", + type: "[PC preview] unknown bundle.AbilityType", + subType: " [PC preview] unknown bundle.AbilitySubType", + orientation: "[PC preview] unknown bundle.DisplayOrientation", + launchMode: " [PC preview] unknown bundle.LaunchMode", + permissions: ["[PC preview] unknown permission"], + deviceTypes: ["[PC preview] unknown device type"], + deviceCapabilities: ["[PC preview] unknown device capability "], + readPermission: "[PC preview] unknown read permission", + writePermission: "[PC preview] unknown write permission", + applicationInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + formEntity: "[PC preview] unknown form entity", + minFormHeight: "[PC preview] unknown min form height", + defaultFormHeight: "[PC preview] unknown default form height", + minFormWidth: "[PC preview] unknown min form width", + defaultFormWidth: "[PC preview] unknown default form width", + uri: "[PC preview] unknown uri", + customizeData: { + key: "[PC preview] unknown key", + value: [ + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + }, + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + } + ] + }, + } + ], + moduleName: "[PC preview] unknown module name", + mainAbilityName: "[PC preview] unknown main ability name", + installationFree: "[PC preview] unknown installation free", + } + ], + entryModuleName: "[PC preview] unknown entry module name", + cpuAbi: "[PC preview] unknown cpu abi", + isSilentInstallation: "[PC preview] unknown is silent installation", + minCompatibleVersionCode: "[PC preview] unknown min compatible version code", + entryInstallationFree: "[PC preview] unknown entry installation free", + } + const PermissionDefMock = { + name: "[PC preview] unknown name", + permissionFlags: "[PC preview] unknown permission flags", + grantMode: "[PC preview] unknown grant mode", + availableScope: "[PC preview] unknown available scope", + labelRes: "[PC preview] unknown label res", + descriptionRes: "[PC preview] unknown description res", + group: "[PC preview] unknown group", + usageInfo: "[PC preview] unknown usage info", + reminderDesc: "[PC preview] unknown reminder desc", + reminderIcon: "[PC preview] unknown reminder icon" + } + const PermissionDefsMock = [ + { + name: "[PC preview] unknown name", + permissionFlags: "[PC preview] unknown permission flags", + grantMode: "[PC preview] unknown grant mode", + availableScope: "[PC preview] unknown available scope", + labelRes: "[PC preview] unknown label res", + descriptionRes: "[PC preview] unknown description res", + group: "[PC preview] unknown group", + usageInfo: "[PC preview] unknown usage info", + reminderDesc: "[PC preview] unknown reminder desc", + reminderIcon: "[PC preview] unknown reminder icon" + } + ] + const BundlePackInfoMock = { + packages: [ + { + deviceType: ["[PC preview] unknown device type"], + name: "[PC preview] unknown name", + moduleType: "[PC preview] unknown module type", + deliveryWithInstall: "[PC preview] unknown deliver with install", + } + ], + summary: { + app: { + bundleName: "[PC preview] unknown bundle name", + version: { + minCompatibleVersionCode: "[PC preview] unknown min compatible version code", + name: "[PC preview] unknown name", + code: " [PC preview] unknown code", + } + }, + modules: [ + { + apiVersion: { + releaseType: "[PC preview] unknown release type", + compatible: "[PC preview] unknown compatible", + target: "[PC preview] unknown target", + }, + deviceType: ["[PC preview] unknown device type"], + distro: { + deliveryWithInstall: "[PC preview] unknown deliver with install", + installationFree: "[PC preview] unknown installation free", + moduleName: "[PC preview] unknown module name", + moduleType: "[PC preview] unknown module type", + mainAbility: "[PC preview] unknown main ability", + }, + abilities: [ + { + name: "[PC preview] unknown name", + label: "[PC preview] unknown label", + visible: '[PC preview] unknown visible', + forms: [ + { + name: "[PC preview] unknown name", + type: "[PC preview] unknown type", + updateEnabled: "[PC preview] unknown update enabled", + scheduledUpateTime: "[PC preview] unknown scheduled updte time", + updateDuration: "[PC preview] unknown update duration", + supportDimensions: ["[PC preview] unknown support dimension"], + defaultDimension: "[PC preview] unknown default dimension", + } + ] + } + ] + } + ] + }, + } + const ApplicationInfosMock = [ + { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + ] + + const AbilityInfosMock = [ + { + bundleName: "[PC preview] unknown bundle name", + name: "[PC preview] unknown name", + label: "[PC preview] unknown label", + description: "[PC preview] unknown descrption", + icon: "[PC preview] unknown icon", + labelId: "[PC preview] unknown label id", + descriptionId: "[PC preview] unknown description id", + iconId: "[PC preview] unknown icon id", + moduleName: "[PC preview] unknown module name", + process: "[PC preview] unknown process", + targetAbility: "[PC preview] unknown target ability", + backgroundModes: "[PC preview] unknown background modes ", + isVisible: "[PC preview] unknown is visible", + formEnabled: "[PC preview] unknown form enabled", + type: "[PC preview] unknown bundle.AbilityType", + subType: "[PC preview] unknown bundle.AbilitySubType", + orientation: "[PC preview] unknown bundle.DisplayOrientation", + launchMode: "[PC preview] unknown bundle.LaunchMode", + permissions: ["[PC preview] unknown permission"], + deviceTypes: ["[PC preview] unknown device type"], + deviceCapabilities: ["[PC preview] unknown device capability"], + readPermission: "[PC preview] unknown read permission", + writePermission: "[PC preview] unknown write permission", + applicationInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + formEntity: "[PC preview] unknown form entitty", + minFormHeight: "[PC preview] unknown minForm Height", + defaultFormHeight: "[PC preview] unknown default Form Height", + minFormWidth: "[PC preview] unknown default min Form Width", + defaultFormWidth: "[PC preview] unknown default form width", + uri: "[PC preview] unknown uri", + customizeData: { + key: "[PC preview] unknown key", + value: [ + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + }, + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + } + ] + }, + } + ] + const AbilityInfoMock = { + bundleName: "[PC preview] unknown bundle name", + name: "[PC preview] unknown name", + label: "[PC preview] unknown label", + description: "[PC preview] unknown descrption", + icon: "[PC preview] unknown icon", + labelId: "[PC preview] unknown label id", + descriptionId: "[PC preview] unknown description id", + iconId: "[PC preview] unknown icon id", + moduleName: "[PC preview] unknown module name", + process: "[PC preview] unknown process", + targetAbility: "[PC preview] unknown target ability", + backgroundModes: "[PC preview] unknown background modes ", + isVisible: "[PC preview] unknown is visible", + formEnabled: "[PC preview] unknown form enabled", + type: "[PC preview] unknown bundle.AbilityType", + subType: "[PC preview] unknown bundle.AbilitySubType", + orientation: "[PC preview] unknown bundle.DisplayOrientation", + launchMode: "[PC preview] unknown bundle.LaunchMode", + permissions: ["[PC preview] unknown permission"], + deviceTypes: ["[PC preview] unknown device type"], + deviceCapabilities: ["[PC preview] unknown device capability"], + readPermission: "[PC preview] unknown read permission", + writePermission: "[PC preview] unknown write permission", + applicationInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + formEntity: "[PC preview] unknown form entitty", + minFormHeight: "[PC preview] unknown minForm Height", + defaultFormHeight: "[PC preview] unknown default Form Height", + minFormWidth: "[PC preview] unknown default min Form Width", + defaultFormWidth: "[PC preview] unknown default form width", + uri: "[PC preview] unknown uri", + customizeData: { + key: "[PC preview] unknown key", + value: [ + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + }, + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + } + ] + }, + } + const ApplicationInfoMock = { packageName: "[PC preview] unknown package name", className: "[PC preview] unknown class name", name: "[PC preview] unknown name", @@ -26,9 +584,218 @@ const BundleInfoMock = { } } } - }, - abilityInfo: [ + } + + const BundleInfosMock = [ { + name: "[PC preview] unknown name", + type: "[PC preview] unknown type", + appId: "[PC preview] unknown app id", + uid: "[PC preview] unknown uid", + installTime: "[PC preview] unknown install time", + updateTime: "[PC preview] unknown up date time", + appInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + abilityInfo: [ + { + bundleName: "[PC preview] unknown bundle name", + name: "[PC preview] unknown name", + label: "[PC preview] unknown label", + description: "[PC preview] unknown description", + icon: "[PC preview] unknown icon", + labelId: "[PC preview] unknown label id", + descriptionId: "[PC preview] unknown description id", + iconId: "[PC preview] unknown icon id", + moduleName: "[PC preview] unknown module name", + process: "[PC preview] unknown process", + targetAbility: "[PC preview] unknown target ability", + backgroundModes: "[PC preview] unknown background modes", + isVisible: "[PC preview] unknown is visible", + formEnabled: "[PC preview] unknown form enabled", + type: "[PC preview] unknown type", + subType: "[PC preview] unknown sub type", + orientation: "[PC preview] unknown orientation", + launchMode: "[PC preview] unknown launch mode", + permissions: ["[PC preview] unknown permission"], + deviceTypes: ["[PC preview] unknown device type"], + deviceCapabilities: ["[PC preview] unknown device capability"], + readPermission: "[PC preview] unknown read permission", + writePermission: "[PC preview] unknown write permission", + applicationInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + formEntity: "[PC preview] unknown form entity", + minFormHeight: "[PC preview] unknown min form height", + defaultFormHeight: "[PC preview] unknown default form height", + minFormWidth: "[PC preview] unknown min form width", + defaultFormWidth: "[PC preview] unknown default form width", + uri: "[PC preview] unknown uri", + customizeData: { + key: "[PC preview] unknown key", + value: [ + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + }, + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + } + ] + }, + } + ], + reqPermissions: ["[PC preview] unknown repermission"], + reqPermissionDetails: [ + { + name: "[PC preview] unknown name", + reason: "[PC preview] unknown reason", + usedScene: { + abilities: ["[PC preview] unknown ability"], + when: "[PC preview] unknown when", + } + } + ], + vendor: "[PC preview] unknown vendor", + versionCode: "[PC preview] unknown versionCode", + versionName: "[PC preview] unknown versionName", + compatibleVersion: "[PC preview] unknown compatibleVersion", + targetVersion: "[PC preview] unknown targetVersion", + isCompressNativeLibs: "[PC preview] unknown isCompressNativeLibs", + hapModuleInfo: [ + { + name: "[PC preview] unknown name", + description: "[PC preview] unknown desciption", + descriptionId: "[PC preview] unknown description id", + icon: "[PC preview] unknown icon", + label: "[PC preview] unknown label", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown iconid", + backgroundImg: "[PC preview] unknown back ground img", + supportedModes: "[PC preview] unknown supported modes", + reqCapabilities: ["[PC preview] unknown reqcapability"], + deviceTypes: ["[PC preview] unknown device type"], + abilityInfo: [ + { + bundleName: "[PC preview] unknown bundle name", + name: "[PC preview] unknown name", + label: "[PC preview] unknown label", + description: "[PC preview] unknown description", + icon: "[PC preview] unknown icon", + labelId: "[PC preview] unknown label id", + descriptionId: "[PC preview] unknown description id", + iconId: "[PC preview] unknown icon id", + moduleName: "[PC preview] unknown module name", + process: "[PC preview] unknown process", + targetAbility: "[PC preview] unknown target ability", + backgroundModes: "[PC preview] unknown back ground modes", + isVisible: "[PC preview] unknown is visible", + formEnabled: "[PC preview] unknown form enabled", + type: "[PC preview] unknown bundle.AbilityType", + subType: " [PC preview] unknown bundle.AbilitySubType", + orientation: "[PC preview] unknown bundle.DisplayOrientation", + launchMode: " [PC preview] unknown bundle.LaunchMode", + permissions: ["[PC preview] unknown permission"], + deviceTypes: ["[PC preview] unknown device type"], + deviceCapabilities: ["[PC preview] unknown device capability "], + readPermission: "[PC preview] unknown read permission", + writePermission: "[PC preview] unknown write permission", + applicationInfo: { + packageName: "[PC preview] unknown package name", + className: "[PC preview] unknown class name", + name: "[PC preview] unknown name", + labelId: "[PC preview] unknown label id", + iconId: "[PC preview] unknown icon id", + sourceDir: "[PC preview] unknown source dir", + flags: "[PC preview] unknown flags", + customizeData: { + key: "[PC preview] unknown key", + value: { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + } + } + } + }, + formEntity: "[PC preview] unknown form entity", + minFormHeight: "[PC preview] unknown min form height", + defaultFormHeight: "[PC preview] unknown default form height", + minFormWidth: "[PC preview] unknown min form width", + defaultFormWidth: "[PC preview] unknown default form width", + uri: "[PC preview] unknown uri", + customizeData: { + key: "[PC preview] unknown key", + value: [ + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + }, + { + CustomizeData: { + name: "[PC preview] unknown name", + value: "[PC preview] unknown value", + }, + } + ] + }, + } + ], + moduleName: "[PC preview] unknown module name", + mainAbilityName: "[PC preview] unknown main ability name", + installationFree: "[PC preview] unknown installation free", + } + ], + entryModuleName: "[PC preview] unknown entry module name", + cpuAbi: "[PC preview] unknown cpu abi", + isSilentInstallation: "[PC preview] unknown is silent installation", + minCompatibleVersionCode: "[PC preview] unknown min compatible version code", + entryInstallationFree: "[PC preview] unknown entry installation free" + } + ] + const BundleOptionsMock = { + userId: "[PC preview] unknown user id", + networkId: "[PC preview] unknown network id", + } + const LauncherAbilityInfoMock = { + abilityInfo: { bundleName: "[PC preview] unknown bundle name", name: "[PC preview] unknown name", label: "[PC preview] unknown label", @@ -74,7 +841,6 @@ const BundleInfoMock = { minFormHeight: "[PC preview] unknown min form height", defaultFormHeight: "[PC preview] unknown default form height", minFormWidth: "[PC preview] unknown min form width", - defaultFormWidth: "[PC preview] unknown default form width", uri: "[PC preview] unknown uri", customizeData: { key: "[PC preview] unknown key", @@ -93,586 +859,23 @@ const BundleInfoMock = { } ] }, - } - ], - reqPermissions: ["[PC preview] unknown repermission"], - reqPermissionDetails: [ - { - name: "[PC preview] unknown name", - reason: "[PC preview] unknown reason", - usedScene: { - abilities: ["[PC preview] unknown ability"], - when: "[PC preview] unknown when", - } - } - ], - vendor: "[PC preview] unknown vendor", - versionCode: "[PC preview] unknown versionCode", - versionName: "[PC preview] unknown versionName", - compatibleVersion: "[PC preview] unknown compatibleVersion", - targetVersion: "[PC preview] unknown targetVersion", - isCompressNativeLibs: "[PC preview] unknown isCompressNativeLibs", - hapModuleInfo: [ - { - name: "string", - description: "string", - descriptionId: 1, - icon: "string", - label: "string", - labelId: 2, - iconId: 3, - backgroundImg: "string", - supportedModes: 4, - reqCapabilities: ["1", "2"], - deviceTypes: ["1", "2"], - abilityInfo: [ - { - bundleName: "string", - name: "string", - label: "string", - description: "string", - icon: "string", - labelId: 1, - descriptionId: 2, - iconId: 3, - moduleName: "string", - process: "string", - targetAbility: "string", - backgroundModes: 4, - isVisible: true, - formEnabled: true, - type: "bundle.AbilityType", - subType: "bundle.AbilitySubType", - orientation: "bundle.DisplayOrientation", - launchMode: "bundle.LaunchMode", - permissions: ["1"], - deviceTypes: ["2"], - deviceCapabilities: ["3"], - readPermission: "string", - writePermission: "string", - applicationInfo: { - packageName: "[PC preview] unknown package name", - className: "[PC preview] unknown class name", - name: "[PC preview] unknown name", - labelId: 2, - iconId: 3, - sourceDir: "[PC preview] unknown source dir", - flags: 1, - customizeData: { - key: "[PC preview] unknown key", - value: { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - } - } - } - }, - formEntity: 5, - minFormHeight: 6, - defaultFormHeight: 7, - minFormWidth: 8, - defaultFormWidth: 9, - uri: "string", - customizeData: { - key: "[PC preview] unknown key", - value: [ - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - }, - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - } - ] - }, - } - ], - moduleName: "string", - mainAbilityName: "string", - installationFree: true, - } - ], - entryModuleName: "string", - cpuAbi: "string", - isSilentInstallation: "string", - minCompatibleVersionCode: 7, - entryInstallationFree: true, -} -const PermissionDefsMock = [ - { - name:1, - permissionFlags:2, - grantMode:3, - availableScope:4, - labelRes:5, - descriptionRes:6, - group:"string", - usageInfo:7, - reminderDesc:"string", - reminderDesc:8 - } -] -const BundlePackInfoMock = { - packages: [ - { - deviceType: ["1", "2", "3"], - name: "1", - moduleType: "2", - deliveryWithInstall: true, - } - ], - summary: { - app: { - bundleName: "1", - version: { - minCompatibleVersionCode: 1, - name: "1", - code: 1, - } }, - modules: [ - { - apiVersion: { - releaseType: "1", - compatible: 1, - target: 1, - }, - deviceType: ["1", "2"], - distro: { - deliveryWithInstall: true, - installationFree: true, - moduleName: "1", - moduleType: "2", - mainAbility: "3", - }, - abilities: [ - { - name: "1", - label: "2", - visible: true, - forms: [ - { - name: "1", - type: "2", - updateEnabled: true, - scheduledUpateTime: "3", - updateDuration: 4, - supportDimensions: [1, 2, 3], - defaultDimension: 1, - } - ] - } - ] - } - - ] - }, -} -const ApplicationInfosMock = [ - { - packageName: "[PC preview] unknown package name", - className: "[PC preview] unknown class name", - name: "[PC preview] unknown name", - labelId: 1, - iconId: 2, - sourceDir: "[PC preview] unknown source dir", - flags: 3, - customizeData: { - key: "[PC preview] unknown key", - value: { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - } - } - } - }, -] - -const AbilityInfosMock = [ - { - bundleName: "string", - name: "string", - label: "string", - description: "string", - icon: "string", - labelId: 1, - descriptionId: 2, - iconId: 3, - moduleName: "string", - process: "string", - targetAbility: "string", - backgroundModes: 4, - isVisible: true, - formEnabled: true, - type: "bundle.AbilityType", - subType: "bundle.AbilitySubType", - orientation: "bundle.DisplayOrientation", - launchMode: "bundle.LaunchMode", - permissions: ["1"], - deviceTypes: ["2"], - deviceCapabilities: ["3"], - readPermission: "string", - writePermission: "string", - applicationInfo: { - packageName: "[PC preview] unknown package name", - className: "[PC preview] unknown class name", - name: "[PC preview] unknown name", - labelId: "[PC preview] unknown label id", - iconId: "[PC preview] unknown icon id", - sourceDir: "[PC preview] unknown source dir", - flags: "[PC preview] unknown flags", - customizeData: { - key: "[PC preview] unknown key", - value: { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - } - } - } + elementName: { + deviceId: "[PC preview] unknown device id", + bundleName: "[PC preview] unknown bundle name", + abilityName: "[PC preview] unknown ability name", + uri: "[PC preview] unknown uri", + shortName: "[PC preview] unknown short name", }, - formEntity: 5, - minFormHeight: 6, - defaultFormHeight: 7, - minFormWidth: 8, - defaultFormWidth: 9, - uri: "string", - customizeData: { - key: "[PC preview] unknown key", - value: [ - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - }, - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - } - ] - }, - } -] -const AbilityInfoMock = { - bundleName: "string", - name: "string", - label: "string", - description: "string", - icon: "string", - labelId: 1, - descriptionId: 2, - iconId: 3, - moduleName: "string", - process: "string", - targetAbility: "string", - backgroundModes: 4, - isVisible: true, - formEnabled: true, - type: "bundle.AbilityType", - subType: "bundle.AbilitySubType", - orientation: "bundle.DisplayOrientation", - launchMode: "bundle.LaunchMode", - permissions: ["1"], - deviceTypes: ["2"], - deviceCapabilities: ["3"], - readPermission: "string", - writePermission: "string", - applicationInfo: { - packageName: "[PC preview] unknown package name", - className: "[PC preview] unknown class name", - name: "[PC preview] unknown name", - labelId: 1, - iconId: 2, - sourceDir: "[PC preview] unknown source dir", - flags: 3, - customizeData: { - key: "[PC preview] unknown key", - value: { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - } - } - } - }, - formEntity: 5, - minFormHeight: 6, - defaultFormHeight: 7, - minFormWidth: 8, - defaultFormWidth: 9, - uri: "string", - customizeData: { - key: "[PC preview] unknown key", - value: [ - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - }, - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - } - ] - }, -} -const ApplicationInfoMock = { - packageName: "[PC preview] unknown package name", - className: "[PC preview] unknown class name", - name: "[PC preview] unknown name", - labelId: 1, - iconId: 2, - sourceDir: "[PC preview] unknown source dir", - flags: 3, - customizeData: { - key: "[PC preview] unknown key", - value: { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - } - } - } -} - -const BundleInfosMock = [ - { - name: "string", - type: "string", - appId: "string", - uid: 1, - installTime: 2, - updateTime: 3, - appInfo: { - packageName: "[PC preview] unknown package name", - className: "[PC preview] unknown class name", - name: "[PC preview] unknown name", - labelId: "[PC preview] unknown label id", - iconId: "[PC preview] unknown icon id", - sourceDir: "[PC preview] unknown source dir", - flags: "[PC preview] unknown flags", - customizeData: { - key: "[PC preview] unknown key", - value: { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - } - } - } - }, - abilityInfo: [ - { - bundleName: "string", - name: "string", - label: "string", - description: "string", - icon: "string", - labelId: 1, - descriptionId: 2, - iconId: 3, - moduleName: "string", - process: "string", - targetAbility: "string", - backgroundModes: 4, - isVisible: true, - formEnabled: true, - type: "bundle.AbilityType", - subType: "bundle.AbilitySubType", - orientation: "bundle.DisplayOrientation", - launchMode: "bundle.LaunchMode", - permissions: ["1"], - deviceTypes: ["2"], - deviceCapabilities: ["3"], - readPermission: "string", - writePermission: "string", - applicationInfo: { - packageName: "[PC preview] unknown package name", - className: "[PC preview] unknown class name", - name: "[PC preview] unknown name", - labelId: "[PC preview] unknown label id", - iconId: "[PC preview] unknown icon id", - sourceDir: "[PC preview] unknown source dir", - flags: "[PC preview] unknown flags", - customizeData: { - key: "[PC preview] unknown key", - value: { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - } - } - } - }, - formEntity: 5, - minFormHeight: 6, - defaultFormHeight: 7, - minFormWidth: 8, - defaultFormWidth: 9, - uri: "string", - customizeData: { - key: "[PC preview] unknown key", - value: [ - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - }, - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - } - ], - }, - } - ], - reqPermissions: ["1", "2", "3"], - reqPermissionDetails: [ - { - name: "string", - reason: "string", - usedScene: { - abilities: ["1,", "2"], - when: "string", - } - } - ], - vendor: "string", - versionCode: 1, - versionName: "string", - compatibleVersion: 2, - targetVersion: 3, - isCompressNativeLibs: true, - hapModuleInfo: [ - { - name: "string", - description: "string", - descriptionId: 1, - icon: "string", - label: "string", - labelId: 2, - iconId: 3, - backgroundImg: "string", - supportedModes: 4, - reqCapabilities: ["1", "2"], - deviceTypes: ["1", "2"], - abilityInfo: [ - { - bundleName: "string", - name: "string", - label: "string", - description: "string", - icon: "string", - labelId: 1, - descriptionId: 2, - iconId: 3, - moduleName: "string", - process: "string", - targetAbility: "string", - backgroundModes: 4, - isVisible: true, - formEnabled: true, - type: "bundle.AbilityType", - subType: "bundle.AbilitySubType", - orientation: "bundle.DisplayOrientation", - launchMode: "bundle.LaunchMode", - permissions: ["1"], - deviceTypes: ["2"], - deviceCapabilities: ["3"], - readPermission: "string", - writePermission: "string", - applicationInfo: { - packageName: "[PC preview] unknown package name", - className: "[PC preview] unknown class name", - name: "[PC preview] unknown name", - labelId: "[PC preview] unknown label id", - iconId: "[PC preview] unknown icon id", - sourceDir: "[PC preview] unknown source dir", - flags: "[PC preview] unknown flags", - customizeData: { - key: "[PC preview] unknown key", - value: { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - } - } - } - }, - formEntity: 5, - minFormHeight: 6, - defaultFormHeight: 7, - minFormWidth: 8, - defaultFormWidth: 9, - uri: "string", - customizeData: { - key: "[PC preview] unknown key", - value: [ - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - }, - { - CustomizeData: { - name: "[PC preview] unknown name", - value: "[PC preview] unknown value", - }, - } - ] - }, - } - ], - moduleName: "string", - mainAbilityName: "string", - installationFree: true, - } - ], - entryModuleName: "string", - cpuAbi: "string", - isSilentInstallation: "string", - minCompatibleVersionCode: 7, - entryInstallationFree: true, + userId: "[PC preview] unknown user id", + installTime: "[PC preview] unknown install time", } -] - - - -const BundleOptionsMock = { - userId: 1, - networkId: "[PC preview] unknown network id", -} -const PermissionDefMock = { - name:"string", - permissionFlags : "string", - grantMode:1, - availableScope:2, - labelRes:3, - descriptionRes:4, - group:"string", - usageInfo:5, - reminderDesc:"string", - reminderIcon:6 -} - + const ModuleUpdateFlagMock = { + FLAG_MODULE_UPGRADE_CHECK: 0, + FLAG_MODULE_UPGRADE_INSTALL: 1, + FLAG_MODULE_UPGRADE_INSTALL_WITH_CONFIG_WINDOWS: 2, + } const BundleFlagMock = { GET_BUNDLE_DEFAULT: 0x00000000, GET_BUNDLE_WITH_ABILITIES: 0x00000001, @@ -687,6 +890,25 @@ const PermissionDefMock = { DARK_MODE: 0, LIGHT_MODE: 1, } + const ModuleRemoveFlagMock = { + FLAG_MODULE_NOT_USED_BY_FORM: 0, + FLAG_MODULE_USED_BY_FORM: 1, + FLAG_MODULE_NOT_USED_BY_SHORTCUT: 2, + FLAG_MODULE_USED_BY_SHORTCUT: 3, + } + const SignatureCompareResultMock = { + SIGNATURE_MATCHED: 0, + SIGNATURE_NOT_MATCHED: 1, + SIGNATURE_UNKNOWN_BUNDLE: 2, + } + const ShortcutExistenceMock = { + SHORTCUT_EXISTENCE_EXISTS: 0, + SHORTCUT_EXISTENCE_NOT_EXISTS: 1, + SHORTCUT_EXISTENCE_UNKNOWN: 2, + } + const QueryShortCutFlagMock = { + QUERY_SHORYCUT_HOME: 0, + } const GrantStatusMock = { PERMISSION_DENIED: -1, PERMISSION_GRANTED: 0, @@ -702,10 +924,10 @@ const PermissionDefMock = { CA: 1, } const DisplayOrientationMock = { - UNSPECIFIED:0, - LANDSCAPE:1, - PORTRAIT:2, - FOLLOW_RECENT:3 + UNSPECIFIED: 0, + LANDSCAPE: 1, + PORTRAIT: 2, + FOLLOW_RECENT: 3 } const LaunchModeMock = { SINGLETON: 0, @@ -729,13 +951,13 @@ const PermissionDefMock = { STATUS_BMS_SERVICE_ERROR: 0x41 } const BundleErrorMock = { - REMOTE_EXCEPTION:0, - SECURITY_EXCEPTION:1 + REMOTE_EXCEPTION: 0, + SECURITY_EXCEPTION: 1 } global.ohosplugin.bundle = { getBundleInfo: function (...args) { - console.warn("BundleManger.getBundleInfo interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.getBundleInfo 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 (typeof args[len - 1] === 'function') { @@ -747,7 +969,7 @@ const PermissionDefMock = { } }, getBundleInstaller: function (...args) { - console.warn("BundleManger.getBundleInstaller interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.getBundleInstaller 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 (typeof args[len - 1] === 'function') { @@ -759,7 +981,7 @@ const PermissionDefMock = { } }, getApplicationInfo: function (...args) { - console.warn("BundleManger.getApplicationInfo interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.getApplicationInfo 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 (typeof args[len - 1] === 'function') { @@ -770,8 +992,20 @@ const PermissionDefMock = { }); } }, + checkPermission: function (...args) { + console.warn("bundle.checkPermission 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, GrantStatusMock.PERMISSION_GRANTED) + } else { + return new Promise((resolve) => { + resolve(GrantStatusMock.PERMISSION_GRANTED) + }); + } + }, queryAbilityByWant: function (...args) { - console.warn("BundleManger.queryAbilityByWant interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.queryAbilityByWant 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 (typeof args[len - 1] === 'function') { @@ -783,7 +1017,7 @@ const PermissionDefMock = { } }, getAllBundleInfo: function (...args) { - console.warn("BundleManger.getAllBundleInfo interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.getAllBundleInfo 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 (typeof args[len - 1] === 'function') { @@ -794,8 +1028,20 @@ const PermissionDefMock = { }); } }, + getBundlesForUid: function (...args) { + console.warn("bundle.getBundlesForUid 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ArrayStringMock) + } else { + return new Promise((resolve) => { + resolve(ArrayStringMock) + }); + } + }, getAllApplicationInfo: function (...args) { - console.warn("BundleManger.getAllApplicationInfo interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.getAllApplicationInfo 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 (typeof args[len - 1] === 'function') { @@ -806,8 +1052,68 @@ const PermissionDefMock = { }); } }, + getSystemAvailableCapabilities: function (...args) { + console.warn("bundle.getSystemAvailableCapabilities 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ArrayStringMock) + } else { + return new Promise((resolve) => { + resolve(ArrayStringMock) + }); + } + }, + hasSystemCapability: function (...args) { + console.warn("bundle.hasSystemCapability 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + getBundleGids: function (...args) { + console.warn("bundle.getBundleGids 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ArrayNumberMock) + } else { + return new Promise((resolve) => { + resolve(ArrayNumberMock) + }); + } + }, + checkPublicKeys: function (...args) { + console.warn("bundle.checkPublicKeys 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, SignatureCompareResultMock.SIGNATURE_MATCHED) + } else { + return new Promise((resolve) => { + resolve(SignatureCompareResultMock.SIGNATURE_MATCHED) + }); + } + }, + getNameForUid: function (...args) { + console.warn("bundle.getNameForUid 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramStringMock) + }); + } + }, getBundleArchiveInfo: function (...args) { - console.warn("BundleManger.getBundleArchiveInfo interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.getBundleArchiveInfo 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 (typeof args[len - 1] === 'function') { @@ -818,8 +1124,272 @@ const PermissionDefMock = { }); } }, + isSafeMode: function (...args) { + console.warn("bundle.isSafeMode 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + getLaunchWantForBundle: function (...args) { + console.warn("bundle.getLaunchWantForBundle 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, WantMock) + } else { + return new Promise((resolve) => { + resolve(WantMock) + }); + } + }, + setApplicationEnabled: function (...args) { + console.warn("bundle.setApplicationEnabled 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + setAbilityEnabled: function (...args) { + console.warn("bundle.setAbilityEnabled 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + isApplicationEnabled: function (...args) { + console.warn("bundle.isApplicationEnabled 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + isAbilityEnabled: function (...args) { + console.warn("bundle.isAbilityEnabled 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + getAllShortcutInfo: function (...args) { + console.warn("bundle.getAllShortcutInfo 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ShortcutInfosMock) + } else { + return new Promise((resolve) => { + resolve(ShortcutInfosMock) + }); + } + }, + cleanBundleCacheFiles: function (...args) { + console.warn("bundle.cleanBundleCacheFiles 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + startShortcut: function (...args) { + console.warn("bundle.startShortcut 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + getAppType: function (...args) { + console.warn("bundle.getAppType 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramStringMock) + }); + } + }, + isShortcutExist: function (...args) { + console.warn("bundle.isShortcutExist 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ShortcutExistenceMock.SHORTCUT_EXISTENCE_EXISTS) + } else { + return new Promise((resolve) => { + resolve(ShortcutExistenceMock.SHORTCUT_EXISTENCE_EXISTS) + }); + } + }, + isHomeShortcutSupported: function (...args) { + console.warn("bundle.isHomeShortcutSupported 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + addHomeShortcut: function (...args) { + console.warn("bundle.addHomeShortcut 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + updateShortcuts: function (...args) { + console.warn("bundle.updateShortcuts 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + disableHomeShortcuts: function (...args) { + console.warn("bundle.disableHomeShortcuts 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + enableHomeShortcuts: function (...args) { + console.warn("bundle.enableHomeShortcuts 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, + getAllHomeShortcutInfo: function (...args) { + console.warn("bundle.getAllHomeShortcutInfo 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ShortcutInfosMock) + } else { + return new Promise((resolve) => { + resolve(ShortcutInfosMock) + }); + } + }, + getAppsGrantedPermissions: function (...args) { + console.warn("bundle.getAppsGrantedPermissions 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ArrayStringMock) + } else { + return new Promise((resolve) => { + resolve(ArrayStringMock) + }); + } + }, + getAbilityIcon: function (...args) { + console.warn("bundle.getAbilityIcon 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, PixelMapMock) + } else { + return new Promise((resolve) => { + resolve(PixelMapMock) + }); + } + }, + getAbilityLabel: function (...args) { + console.warn("bundle.getAbilityLabel 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramStringMock) + }); + } + }, + getClearUserDataFlag: function (...args) { + console.warn("bundle.getClearUserDataFlag 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + setClearUserDataFlag: function (...args) { + console.warn("bundle.setClearUserDataFlag 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }); + } + }, getBundlePackInfo: function (...args) { - console.warn("BundleManger.getBundlePackInfo interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.getBundlePackInfo 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 (typeof args[len - 1] === 'function') { @@ -830,20 +1400,90 @@ const PermissionDefMock = { }); } }, - getAbilityInfo: function (...args) { - console.warn("BundleManger.getAbilityInfo interface mocked in the Previewer. How this interface works on the" + + getAbilityList: function (...args) { + console.warn("bundle.getAbilityList 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, AbilityInfoMock) + args[len - 1].call(this, paramMock.businessErrorMock, LauncherAbilityInfosMock) } else { return new Promise((resolve) => { - resolve(AbilityInfoMock) + resolve(LauncherAbilityInfosMock) + }); + } + }, + getAbilityInfo: function (...args) { + console.warn("bundle.getAbilityInfo 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 (typeof args[0] === 'string') { + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AbilityInfoMock) + } else { + return new Promise((resolve) => { + resolve(AbilityInfoMock) + }); + } + } else if (typeof args[0] === 'object') { + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, LauncherAbilityInfoMock) + } else { + return new Promise((resolve) => { + resolve(LauncherAbilityInfoMock) + }); + } + } + }, + isBundleEnabled: function (...args) { + console.warn("bundle.isBundleEnabled 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + getPermissionDef: function (...args) { + console.warn("bundle.getPermissionDef 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, PermissionDefMock) + } else { + return new Promise((resolve) => { + resolve(PermissionDefMock) + }); + } + }, + getPermissionGroupDef: function (...args) { + console.warn("bundle.getPermissionGroupDef 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, PermissionDefMock) + } else { + return new Promise((resolve) => { + resolve(PermissionDefMock) + }); + } + }, + getAllPermissionGroupDefs: function (...args) { + console.warn("bundle.getAllPermissionGroupDefs 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, PermissionDefsMock) + } else { + return new Promise((resolve) => { + resolve(PermissionDefsMock) }); } }, getPermissionDefByGroup: function (...args) { - console.warn("BundleManger.getPermissionDefByGroup interface mocked in the Previewer. How this interface works on the" + + console.warn("bundle.getPermissionDefByGroup 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 (typeof args[len - 1] === 'function') { diff --git a/runtime/main/extend/systemplugin/ohos/commonEvent.js b/runtime/main/extend/systemplugin/ohos/commonEvent.js index b6b07992..887d7ffe 100644 --- a/runtime/main/extend/systemplugin/ohos/commonEvent.js +++ b/runtime/main/extend/systemplugin/ohos/commonEvent.js @@ -1,10 +1,10 @@ -import {paramMock} from "../utils" +import { paramMock } from "../utils" export function mockCommonEvent() { const CommonEventSubscriberMock = { getCode: function (...args) { console.warn("CommonEventSubscriber.getCode interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); @@ -16,7 +16,7 @@ export function mockCommonEvent() { }, setCode: function (...args) { console.warn("CommonEventSubscriber.setCode interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -28,7 +28,7 @@ export function mockCommonEvent() { }, getData: function (...args) { console.warn("CommonEventSubscriber.getData interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); @@ -40,7 +40,7 @@ export function mockCommonEvent() { }, setData: function (...args) { console.warn("CommonEventSubscriber.setData interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -52,7 +52,7 @@ export function mockCommonEvent() { }, setCodeAndData: function (...args) { console.warn("CommonEventSubscriber.setCodeAndData interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -64,7 +64,7 @@ export function mockCommonEvent() { }, isOrderedCommonEvent: function (...args) { console.warn("CommonEventSubscriber.isOrderedCommonEvent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); @@ -76,7 +76,7 @@ export function mockCommonEvent() { }, isStickyCommonEvent: function (...args) { console.warn("CommonEventSubscriber.isStickyCommonEvent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); @@ -88,7 +88,7 @@ export function mockCommonEvent() { }, abortCommonEvent: function (...args) { console.warn("CommonEventSubscriber.abortCommonEvent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -100,7 +100,7 @@ export function mockCommonEvent() { }, clearAbortCommonEvent: function (...args) { console.warn("CommonEventSubscriber.clearAbortCommonEvent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -112,7 +112,7 @@ export function mockCommonEvent() { }, getAbortCommonEvent: function (...args) { console.warn("CommonEventSubscriber.getAbortCommonEvent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); @@ -124,7 +124,7 @@ export function mockCommonEvent() { }, getSubscribeInfo: function (...args) { console.warn("CommonEventSubscriber.getSubscribeInfo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, CommonEventSubscribeInfoMock); @@ -152,7 +152,7 @@ export function mockCommonEvent() { global.ohosplugin.commonEvent = { publish: function (...args) { console.warn("commonEvent.publish interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -160,7 +160,7 @@ export function mockCommonEvent() { }, createSubscriber: function (...args) { console.warn("commonEvent.createSubscriber interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, CommonEventSubscriberMock); @@ -172,15 +172,15 @@ export function mockCommonEvent() { }, subscribe: function (...args) { console.warn("commonEvent.subscribe interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, CommonEventDataMock); } }, unsubscribe: function (...args) { - console.warn("commonEvent.subscribe interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + console.warn("commonEvent.unsubscribe 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 (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); diff --git a/runtime/main/extend/systemplugin/ohos/notification.js b/runtime/main/extend/systemplugin/ohos/notification.js index 5b437e3a..54a700b3 100644 --- a/runtime/main/extend/systemplugin/ohos/notification.js +++ b/runtime/main/extend/systemplugin/ohos/notification.js @@ -1,451 +1,487 @@ -import {paramMock} from "../utils" +import {paramMock} from '../utils'; export function mockOhosNotification() { - const NotificationSlotMock = { - type: '[PC preview] unknow type', - level: '[PC preview] unknow level', - desc: '[PC preview] unknow desc', - badgeFlag: '[PC preview] unknow badgeFlag', - bypassDnd: '[PC preview] unknow bypassDnd', - lockscreenVisibility: '[PC preview] unknow lockscreenVisibility', - vibrationEnabled: '[PC preview] unknow vibrationEnabled', - sound: '[PC preview] unknow sound', - lightEnabled: '[PC preview] unknow lightEnabled', - lightColor: '[PC preview] unknow lightColor', - vibrationValues: '[PC preview] unknow vibrationValues' - } - const DoNotDisturbDateMock = { - type: '[PC preview] unknow type', - begin: '[PC preview] unknow begin', - end: '[PC preview] unknow end', - } - const NotificationRequestMock = { - content: '[PC preview] unknow content', - id: '[PC preview] unknow id', - slotType: '[PC preview] unknow slotType', - isOngoing: '[PC preview] unknow isOngoing', - isUnremovable: '[PC preview] unknow isUnremovable', - deliveryTime: '[PC preview] unknow deliveryTime', - tapDismissed: '[PC preview] unknow tapDismissed', - autoDeletedTime: '[PC preview] unknow autoDeletedTime', - wantAgent: '[PC preview] unknow wantAgent', - extraInfo: '[PC preview] unknow extraInfo', - color: '[PC preview] unknow color', - colorEnabled: '[PC preview] unknow colorEnabled', - isAlertOnce: '[PC preview] unknow isAlertOnce', - isStopwatch: '[PC preview] unknow isStopwatch', - isCountDown: '[PC preview] unknow isCountDown', - isFloatingIcon: '[PC preview] unknow isFloatingIcon', - label: '[PC preview] unknow label', - badgeIconStyle: '[PC preview] unknow badgeIconStyle', - showDeliveryTime: '[PC preview] unknow showDeliveryTime', - actionButtons: '[PC preview] unknow actionButtons', - creatorBundleName: '[PC preview] unknow creatorBundleName', - creatorUid: '[PC preview] unknow creatorUid', - creatorPid: '[PC preview] unknow creatorPid', - classification: '[PC preview] unknow classification', - hashCode: '[PC preview] unknow hashCode', - groupName: '[PC preview] unknow groupName', - template: '[PC preview] unknow template', - } - global.ohosplugin.notification = { - publish: function (...args) { - console.warn("notification.publish 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - cancel: function (...args) { - console.warn("notification.cancel 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - cancelAll: function (...args) { - console.warn("notification.cancelAll 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - addSlot: function (...args) { - console.warn("notification.addSlot 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - addSlots: function (...args) { - console.warn("notification.addSlots 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - getSlot: function (...args) { - console.warn("notification.getSlot 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, NotificationSlotMock); - } else { - return new Promise((resolve) => { - resolve(NotificationSlotMock); - }); - } - }, - getSlots: function (...args) { - console.warn("notification.getSlots 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [NotificationSlotMock]); - } else { - return new Promise((resolve) => { - resolve([NotificationSlotMock]); - }); - } - }, - removeSlot: function (...args) { - console.warn("notification.removeSlot 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - removeAllSlots: function (...args) { - console.warn("notification.removeAllSlots 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - subscribe: function (...args) { - console.warn("notification.subscribe 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - unsubscribe: function (...args) { - console.warn("notification.unsubscribe 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - enableNotification: function (...args) { - console.warn("notification.enableNotification 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - isNotificationEnabled: function (...args) { - console.warn("notification.isNotificationEnabled 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }); - } - }, - displayBadge: function (...args) { - console.warn("notification.displayBadge 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - isBadgeDisplayed: function (...args) { - console.warn("notification.isBadgeDisplayed 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }); - } - }, - setSlotByBundle: function (...args) { - console.warn("notification.setSlotByBundle 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - getSlotsByBundle: function (...args) { - console.warn("notification.getSlotsByBundle 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [NotificationSlotMock]); - } else { - return new Promise((resolve) => { - resolve([NotificationSlotMock]); - }); - } - }, - getSlotNumByBundle: function (...args) { - console.warn("notification.getSlotNumByBundle 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve) => { - resolve(paramMock.paramNumberMock); - }); - } - }, - remove: function (...args) { - console.warn("notification.remove 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - removeAll: function (...args) { - console.warn("notification.removeAll 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - getAllActiveNotifications: function (...args) { - console.warn("notification.getAllActiveNotifications 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [NotificationRequestMock]); - } else { - return new Promise((resolve) => { - resolve([NotificationRequestMock]); - }); - } - }, - getActiveNotificationCount: function (...args) { - console.warn("notification.getActiveNotificationCount 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve) => { - resolve(paramMock.paramNumberMock); - }); - } - }, - getActiveNotifications: function (...args) { - console.warn("notification.getActiveNotifications 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [NotificationRequestMock]); - } else { - return new Promise((resolve) => { - resolve([NotificationRequestMock]); - }); - } - }, - isDistributedEnabled: function (...args) { - console.warn("notification.isDistributedEnabled 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }); - } - }, - enableDistributed: function (...args) { - console.warn("notification.enableDistributed 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - enableDistributedSelf: function (...args) { - console.warn("notification.enableDistributedSelf 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - enableDistributedByBundle: function (...args) { - console.warn("notification.enableDistributedByBundle 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - isDistributedEnabledByBundle: function (...args) { - console.warn("notification.isDistributedEnabledByBundle 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }); - } - }, - cancelGroup: function (...args) { - console.warn("notification.cancelGroup 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - removeGroupByBundle: function (...args) { - console.warn("notification.removeGroupByBundle 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }); - } - }, - isSupportDoNotDisturbMode: function (...args) { - console.warn("notification.isSupportDoNotDisturbMode 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }); - } - }, - setDoNotDisturbDate: function (...args) { - console.warn("notification.setDoNotDisturbDate 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve) => { - resolve(); - }); - } - }, - getDoNotDisturbDate: function (...args) { - console.warn("notification.getDoNotDisturbDate 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 (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, DoNotDisturbDateMock); - } else { - return new Promise((resolve) => { - resolve(DoNotDisturbDateMock); - }); - } - }, + const NotificationSlotMock = { + type: '[PC preview] unknow type', + level: '[PC preview] unknow level', + desc: '[PC preview] unknow desc', + badgeFlag: '[PC preview] unknow badgeFlag', + bypassDnd: '[PC preview] unknow bypassDnd', + lockscreenVisibility: '[PC preview] unknow lockscreenVisibility', + vibrationEnabled: '[PC preview] unknow vibrationEnabled', + sound: '[PC preview] unknow sound', + lightEnabled: '[PC preview] unknow lightEnabled', + lightColor: '[PC preview] unknow lightColor', + vibrationValues: '[PC preview] unknow vibrationValues' + }; + const DoNotDisturbDateMock = { + type: '[PC preview] unknow type', + begin: '[PC preview] unknow begin', + end: '[PC preview] unknow end' + }; + const NotificationRequestMock = { + content: '[PC preview] unknow content', + id: '[PC preview] unknow id', + slotType: '[PC preview] unknow slotType', + isOngoing: '[PC preview] unknow isOngoing', + isUnremovable: '[PC preview] unknow isUnremovable', + deliveryTime: '[PC preview] unknow deliveryTime', + tapDismissed: '[PC preview] unknow tapDismissed', + autoDeletedTime: '[PC preview] unknow autoDeletedTime', + wantAgent: '[PC preview] unknow wantAgent', + extraInfo: '[PC preview] unknow extraInfo', + color: '[PC preview] unknow color', + colorEnabled: '[PC preview] unknow colorEnabled', + isAlertOnce: '[PC preview] unknow isAlertOnce', + isStopwatch: '[PC preview] unknow isStopwatch', + isCountDown: '[PC preview] unknow isCountDown', + isFloatingIcon: '[PC preview] unknow isFloatingIcon', + label: '[PC preview] unknow label', + badgeIconStyle: '[PC preview] unknow badgeIconStyle', + showDeliveryTime: '[PC preview] unknow showDeliveryTime', + actionButtons: '[PC preview] unknow actionButtons', + creatorBundleName: '[PC preview] unknow creatorBundleName', + creatorUid: '[PC preview] unknow creatorUid', + creatorPid: '[PC preview] unknow creatorPid', + classification: '[PC preview] unknow classification', + hashCode: '[PC preview] unknow hashCode', + groupName: '[PC preview] unknow groupName', + template: '[PC preview] unknow template' + }; + global.ohosplugin.notification = { + SlotType: { + UNKNOWN_TYPE: 0, + SOCIAL_COMMUNICATION: 1, + SERVICE_INFORMATION: 2, + CONTENT_INFORMATION: 3, + OTHER_TYPES: 0xFFFF + }, + ContentType: { + NOTIFICATION_CONTENT_BASIC_TEXT: 0, + NOTIFICATION_CONTENT_LONG_TEXT: 1, + NOTIFICATION_CONTENT_PICTURE: 2, + NOTIFICATION_CONTENT_CONVERSATION: 3, + NOTIFICATION_CONTENT_MULTILINE: 4 + }, + SlotLevel: { + LEVEL_NONE: 0, + LEVEL_MIN: 1, + LEVEL_LOW: 2, + LEVEL_DEFAULT: 3, + LEVEL_HIGH: 4 + }, + publish: function(...args) { + console.warn('notification.publish 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + cancel: function(...args) { + console.warn('notification.cancel 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + cancelAll: function(...args) { + console.warn('notification.cancelAll 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + addSlot: function(...args) { + console.warn('notification.addSlot 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + addSlots: function(...args) { + console.warn('notification.addSlots 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + getSlot: function(...args) { + console.warn('notification.getSlot 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NotificationSlotMock); + } else { + return new Promise((resolve) => { + resolve(NotificationSlotMock); + }); + } + }, + getSlots: function(...args) { + console.warn('notification.getSlots 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [NotificationSlotMock]); + } else { + return new Promise((resolve) => { + resolve([NotificationSlotMock]); + }); + } + }, + removeSlot: function(...args) { + console.warn('notification.removeSlot 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + removeAllSlots: function(...args) { + console.warn('notification.removeAllSlots 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + subscribe: function(...args) { + console.warn('notification.subscribe 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + unsubscribe: function(...args) { + console.warn('notification.unsubscribe 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + enableNotification: function(...args) { + console.warn('notification.enableNotification 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + isNotificationEnabled: function(...args) { + console.warn('notification.isNotificationEnabled 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + displayBadge: function(...args) { + console.warn('notification.displayBadge 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + isBadgeDisplayed: function(...args) { + console.warn('notification.isBadgeDisplayed 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + setSlotByBundle: function(...args) { + console.warn('notification.setSlotByBundle 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + getSlotsByBundle: function(...args) { + console.warn('notification.getSlotsByBundle 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [NotificationSlotMock]); + } else { + return new Promise((resolve) => { + resolve([NotificationSlotMock]); + }); + } + }, + getSlotNumByBundle: function(...args) { + console.warn('notification.getSlotNumByBundle 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramNumberMock); + }); + } + }, + remove: function(...args) { + console.warn('notification.remove 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + removeAll: function(...args) { + console.warn('notification.removeAll 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + getAllActiveNotifications: function(...args) { + console.warn('notification.getAllActiveNotifications 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [NotificationRequestMock]); + } else { + return new Promise((resolve) => { + resolve([NotificationRequestMock]); + }); + } + }, + getActiveNotificationCount: function(...args) { + console.warn('notification.getActiveNotificationCount 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramNumberMock); + }); + } + }, + getActiveNotifications: function(...args) { + console.warn('notification.getActiveNotifications 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [NotificationRequestMock]); + } else { + return new Promise((resolve) => { + resolve([NotificationRequestMock]); + }); + } + }, + isDistributedEnabled: function(...args) { + console.warn('notification.isDistributedEnabled 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + enableDistributed: function(...args) { + console.warn('notification.enableDistributed 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + enableDistributedSelf: function(...args) { + console.warn('notification.enableDistributedSelf 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + enableDistributedByBundle: function(...args) { + console.warn('notification.enableDistributedByBundle 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + isDistributedEnabledByBundle: function(...args) { + console.warn('notification.isDistributedEnabledByBundle 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + cancelGroup: function(...args) { + console.warn('notification.cancelGroup 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + removeGroupByBundle: function(...args) { + console.warn('notification.removeGroupByBundle 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + isSupportDoNotDisturbMode: function(...args) { + console.warn('notification.isSupportDoNotDisturbMode 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + setDoNotDisturbDate: function(...args) { + console.warn('notification.setDoNotDisturbDate 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve) => { + resolve(); + }); + } + }, + getDoNotDisturbDate: function(...args) { + console.warn('notification.getDoNotDisturbDate 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, DoNotDisturbDateMock); + } else { + return new Promise((resolve) => { + resolve(DoNotDisturbDateMock); + }); + } + }, + DoNotDisturbType: { + TYPE_NONE: 0, + TYPE_ONCE: 1, + TYPE_DAILY: 2, + TYPE_CLEARLY: 3 + }, + TemplateType: { + TYPE_NONE: 0, + TYPE_PROCESS_BAR: 0x100 + }, + DoNotDisturbMode: { + ALLOW_UNKNOWN: 0, + ALLOW_ALL: 1, + ALLOW_PRIORITY: 2, + ALLOW_NONE: 3, + ALLOW_ALARMS: 4 } + }; } - - diff --git a/runtime/main/extend/systemplugin/ohos/wantAgent.js b/runtime/main/extend/systemplugin/ohos/wantAgent.js index 5f642a79..c9ee234a 100644 --- a/runtime/main/extend/systemplugin/ohos/wantAgent.js +++ b/runtime/main/extend/systemplugin/ohos/wantAgent.js @@ -1,4 +1,4 @@ -import {paramMock} from "../utils" +import { paramMock } from "../utils" export function mockWantAgent() { const WantMock = { @@ -21,9 +21,28 @@ export function mockWantAgent() { } const WantAgentMock = {} global.ohosplugin.wantAgent = { + OperationType: { + UNKNOWN_TYPE: 0, + START_ABILITY: 1, + START_ABILITIES: 2, + START_SERVICE: 3, + SEND_COMMON_EVENT: 4 + }, + WantAgentFlags: { + ONE_TIME_FLAG: 0, + NO_BUILD_FLAG: 1, + CANCEL_PRESENT_FLAG: 2, + UPDATE_PRESENT_FLAG: 3, + CONSTANT_FLAG: 4, + REPLACE_ELEMENT: 5, + REPLACE_ACTION: 6, + REPLACE_URI: 7, + REPLACE_ENTITIES: 8, + REPLACE_BUNDLE: 9 + }, getBundleName: function (...args) { console.warn("wantAgent.getBundleName interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); @@ -35,7 +54,7 @@ export function mockWantAgent() { }, getUid: function (...args) { console.warn("wantAgent.getUid interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); @@ -47,7 +66,7 @@ export function mockWantAgent() { }, getWant: function (...args) { console.warn("wantAgent.getWant interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, WantMock); @@ -59,7 +78,7 @@ export function mockWantAgent() { }, cancel: function (...args) { console.warn("wantAgent.cancel interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -71,7 +90,7 @@ export function mockWantAgent() { }, trigger: function (...args) { console.warn("wantAgent.trigger interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, CompleteDataMock); @@ -79,7 +98,7 @@ export function mockWantAgent() { }, equal: function (...args) { console.warn("wantAgent.equal interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); @@ -91,7 +110,7 @@ export function mockWantAgent() { }, getWantAgent: function (...args) { console.warn("wantAgent.getWantAgent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); + " Previewer may be different from that on a real device."); const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, WantAgentMock); diff --git a/runtime/main/extend/systemplugin/telephony.js b/runtime/main/extend/systemplugin/telephony.js index 2f118c9a..aa4d8b23 100644 --- a/runtime/main/extend/systemplugin/telephony.js +++ b/runtime/main/extend/systemplugin/telephony.js @@ -1,4 +1,4 @@ -import {paramMock} from "./utils" +import { paramMock } from "./utils" const CallState = "[PC Preview] unknow CallState"; export function mockCall() { @@ -459,7 +459,7 @@ export function mockCall() { }) } }, - setCallRestriction :function (...args) { + setCallRestriction: function (...args) { console.warn("telephony.call.setCallRestriction 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 @@ -681,17 +681,17 @@ const NetworkState = { } const SignalInformation = { signalType: "[PC Preview] unknow signalType", - signalLevel:"[PC Preview] unknow signalLevel" + signalLevel: "[PC Preview] unknow signalLevel" } const DataFlowType = "[PC Preview] unknow DataFlowType" const DataConnectState = "[PC Preview] unknow DataConnectState" const CellInformation = { networkType: "[PC Preview] unknow networkType", isCamped: "[PC Preview] unknow isCamped", - timeStamp:"[PC Preview] unknow timeStamp", - signalInformation:"[PC Preview] unknow signalInformation", - data:"[PC Preview] unknow unkown data" - } + timeStamp: "[PC Preview] unknow timeStamp", + signalInformation: "[PC Preview] unknow signalInformation", + data: "[PC Preview] unknow unkown data" +} export function mockRadio() { const NetworkSearchResult = { isNetworkSearchSuccess: "[PC Preview] unknow isNetworkSearchSuccess", @@ -703,7 +703,7 @@ export function mockRadio() { }] } const PreferredNetworkMode = "[PC Preview] unknow PreferredNetworkMode" - const NrOptionMode ="[PC Preview] unknow NrOptionMode" + const NrOptionMode = "[PC Preview] unknow NrOptionMode" const NetworkSelectionMode = "[PC Preview] unknow unkown NetworkSelectionMode" global.systemplugin.telephony.radio = { getRadioTech: function (...args) { @@ -956,6 +956,18 @@ export function mockRadio() { resolve(PreferredNetworkMode); }) } + }, + getIMEISV: function (...args) { + console.warn("telephony.radio.getIMEISV 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 (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } } } } @@ -1637,7 +1649,7 @@ export function mockObserver() { } global.systemplugin.telephony.observer = { on: function (...args) { - console.warn("telephony.on interface mocked in the Previewer. How this interface works on the Previewer may " + + console.warn("telephony.observer.on 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 (typeof args[len - 1] === 'function') { @@ -1667,7 +1679,7 @@ export function mockObserver() { } }, off: function (...args) { - console.warn("telephony.off interface mocked in the Previewer. How this interface works on the Previewer may " + + console.warn("telephony.observer.off 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 (typeof args[len - 1] === 'function') { @@ -1697,7 +1709,7 @@ export function mockObserver() { } }, once: function (...args) { - console.warn("telephony.once interface mocked in the Previewer. How this interface works on the Previewer may " + + console.warn("telephony.observer.once 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 (typeof args[len - 1] === 'function') { diff --git a/runtime/main/extend/systemplugin/utils.js b/runtime/main/extend/systemplugin/utils.js index 1d652d8b..d9e8592e 100644 --- a/runtime/main/extend/systemplugin/utils.js +++ b/runtime/main/extend/systemplugin/utils.js @@ -1,8 +1,8 @@ export function hasComplete(...args) { if (args[0] === undefined) { - return + return; } - args[0].call(this) + args[0].call(this); } export function getRandomArbitrary(min, max) { @@ -11,9 +11,9 @@ export function getRandomArbitrary(min, max) { export const paramMock = { businessErrorMock: null, - paramNumberMock: "[PC Preview] unknow number", - paramStringMock: "[PC Preview] unknow string", - paramBooleanMock: "[PC Preview] unknow boolean", - paramObjectMock: "[PC Preview] unknow object", - paramArrayMock: "[PC Preview] unknow Array" -} \ No newline at end of file + paramNumberMock: '[PC Preview] unknow number', + paramStringMock: '[PC Preview] unknow string', + paramBooleanMock: '[PC Preview] unknow boolean', + paramObjectMock: '[PC Preview] unknow object', + paramArrayMock: '[PC Preview] unknow Array' +}; diff --git a/runtime/main/extend/systemplugin/window.js b/runtime/main/extend/systemplugin/window.js index dc7ea16c..42033044 100644 --- a/runtime/main/extend/systemplugin/window.js +++ b/runtime/main/extend/systemplugin/window.js @@ -1,8 +1,8 @@ import { paramMock } from "./utils" export const windowPropertiesMock = { - windowRect:'[PC preview] unknow windowRect', - type:'[PC preview] unknow type', + windowRect: '[PC preview] unknow windowRect', + type: '[PC preview] unknow type', brightness: '[PC preview] unknow brightness', isTransparent: '[PC preview] unknow isTransparent', isFullScreen: '[PC preview] unknow isFullScreen', @@ -29,7 +29,7 @@ export const AvoidAreaMock = { export const windowMock = { setBrightness: function (...args) { console.warn("Window.setBrightness interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -41,7 +41,7 @@ export const windowMock = { }, setBackgroundColor: function (...args) { console.warn("Window.setBackgroundColor interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -53,7 +53,7 @@ export const windowMock = { }, setTransparent: function (...args) { console.warn("Window.setTransparent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -65,7 +65,7 @@ export const windowMock = { }, setFullScreen: function (...args) { console.warn("Window.setFullScreen interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -77,7 +77,7 @@ export const windowMock = { }, setKeepScreenOn: function (...args) { console.warn("Window.setKeepScreenOn interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -89,7 +89,7 @@ export const windowMock = { }, setDimBehind: function (...args) { console.warn("Window.setDimBehind interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -101,7 +101,7 @@ export const windowMock = { }, setLayoutFullScreen: function (...args) { console.warn("Window.setLayoutFullScreen interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -113,7 +113,7 @@ export const windowMock = { }, setFocusable: function (...args) { console.warn("Window.setFocusable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -125,7 +125,7 @@ export const windowMock = { }, setTouchable: function (...args) { console.warn("Window.setTouchable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -137,7 +137,7 @@ export const windowMock = { }, setPrivacyMode: function (...args) { console.warn("Window.setPrivacyMode interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -149,7 +149,7 @@ export const windowMock = { }, setSystemBarEnable: function (...args) { console.warn("Window.setSystemBarEnable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -161,7 +161,7 @@ export const windowMock = { }, setSystemBarProperties: function (...args) { console.warn("Window.setSystemBarProperties interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -173,7 +173,7 @@ export const windowMock = { }, getProperties: function (...args) { console.warn("Window.getProperties interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, windowPropertiesMock) @@ -185,7 +185,7 @@ export const windowMock = { }, getAvoidArea: function (...args) { console.warn("Window.getAvoidArea interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, AvoidAreaMock) @@ -197,7 +197,7 @@ export const windowMock = { }, moveTo: function (...args) { console.warn("Window.moveTo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -209,7 +209,7 @@ export const windowMock = { }, resetSize: function (...args) { console.warn("Window.resetSize interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -221,7 +221,7 @@ export const windowMock = { }, loadContent: function (...args) { console.warn("Window.loadContent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -233,7 +233,7 @@ export const windowMock = { }, hide: function (...args) { console.warn("Window.hide interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -245,7 +245,7 @@ export const windowMock = { }, show: function (...args) { console.warn("Window.show interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -257,7 +257,7 @@ export const windowMock = { }, isShowing: function (...args) { console.warn("Window.isShowing interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) @@ -269,7 +269,7 @@ export const windowMock = { }, destroy: function (...args) { console.warn("Window.destroy interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -281,7 +281,7 @@ export const windowMock = { }, setOutsideTouchable: function (...args) { console.warn("Window.setOutsideTouchable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -293,15 +293,19 @@ export const windowMock = { }, on: function (...args) { console.warn("Window.on interface mocked in the Previewer. How this interface works on the Previewer may be" + - " different from that on a real device.") + " different from that on a real device.") const len = args.length - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + } }, off: function (...args) { console.warn("Window.off interface mocked in the Previewer. How this interface works on the Previewer may be" + - " different from that on a real device.") + " different from that on a real device.") const len = args.length - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + } }, } export function mockWindow() { @@ -317,7 +321,7 @@ export function mockWindow() { global.systemplugin.window = { getTopWindow: function (...args) { console.warn("window.getTopWindow interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, windowMock) @@ -329,7 +333,7 @@ export function mockWindow() { }, create: function (...args) { console.warn("Window.create interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, windowMock) @@ -341,7 +345,7 @@ export function mockWindow() { }, find: function (...args) { console.warn("Window.find interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, windowMock) @@ -351,8 +355,8 @@ export function mockWindow() { }) } }, - getWindowMode: function (...args) { - console.warn("Window.getWindowMode interface mocked in the Previewer. How this interface works on the Previewer" + + getAbilityWindowMode: function (...args) { + console.warn("Window.getAbilityWindowMode 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 (typeof args[len - 1] === 'function') { diff --git a/runtime/main/manage/event/TaskCenter.ts b/runtime/main/manage/event/TaskCenter.ts index 1b5b4cc5..484c87b4 100644 --- a/runtime/main/manage/event/TaskCenter.ts +++ b/runtime/main/manage/event/TaskCenter.ts @@ -24,7 +24,8 @@ import { Log, - typof + typof, + bufferToBase64 } from '../../../utils/index'; import CallbackManager from './CallbackManager'; @@ -81,6 +82,58 @@ export class TaskCenter { return this.callbackManager.isEmpty(); } + /** + * Normalize args. + * @param {*} v - Original args. + * @return {*} - Normalized args. + */ + public normalizePrimitive(v: any): any { + const type = typof(v); + + switch (type) { + case 'undefined': + case 'null': + return ''; + + case 'regexp': + return v.toString(); + case 'date': + return v.toISOString(); + + case 'number': + case 'string': + case 'boolean': + case 'array': + case 'object': + return v; + + case 'arraybuffer': + return { + '@type': 'binary', + dataType: type, + base64: bufferToBase64(v) + }; + + case 'int8array': + case 'uint8array': + case 'uint8clampedarray': + case 'int16array': + case 'uint16array': + case 'int32array': + case 'uint32array': + case 'float32array': + case 'float64array': + return { + '@type': 'binary', + dataType: type, + base64: bufferToBase64(v.buffer) + }; + + default: + return JSON.stringify(v); + } + } + /** * Standardizing a value. Specially, if the value is a function, generate a function id. * @param {*} arg - Any type. @@ -99,7 +152,7 @@ export class TaskCenter { } else if (type === 'array') { return arg.map(i => this.standardization(i)); } else { - return arg; + return this.normalizePrimitive(arg); } } diff --git a/runtime/main/model/compiler.ts b/runtime/main/model/compiler.ts index beb497be..07dcfca4 100644 --- a/runtime/main/model/compiler.ts +++ b/runtime/main/model/compiler.ts @@ -36,10 +36,12 @@ import { setClass, setIdStyle, setTagStyle, + setUniversalStyle, setId, bindSubVm, bindSubVmAfterInitialized, - newWatch + newWatch, + bindDir } from './directive'; import { createBlock, @@ -80,6 +82,7 @@ export interface AttrInterface { slot: string; name: string; data: () => any | string; + $data: () => any | string; } export interface TemplateInterface { @@ -118,15 +121,15 @@ interface ConfigInterface { } export function build(vm: Vm) { - const opt: any = vm.vmOptions || {}; + const opt: any = vm._vmOptions || {}; const template: any = opt.template || {}; - compile(vm, template, vm.parentEl); - Log.debug(`"OnReady" lifecycle in Vm(${vm.type}).`); + compile(vm, template, vm._parentEl); + Log.debug(`"OnReady" lifecycle in Vm(${vm._type}).`); vm.$emit('hook:onReady'); - if (vm.parent) { + if (vm._parent) { vm.$emit('hook:onAttached'); } - vm.ready = true; + vm._ready = true; } /** @@ -137,7 +140,7 @@ export function build(vm: Vm) { * @param {MetaInterface} [meta] - To transfer data. */ function compile(vm: Vm, target: TemplateInterface, dest: FragBlockInterface | Element, meta?: Partial): void { - const app: any = vm.app || {}; + const app: any = vm._app || {}; if (app.lastSignal === -1) { return; } @@ -169,6 +172,10 @@ function compile(vm: Vm, target: TemplateInterface, dest: FragBlockInterface | E compileCustomComponent(vm, component, target, dest, type, meta); return; } + if (type === 'compontent') { + compileDyanmicComponent(vm, target, dest, type, meta); + return; + } if (targetIsBlock(target)) { compileBlock(vm, target, dest); return; @@ -176,6 +183,61 @@ function compile(vm: Vm, target: TemplateInterface, dest: FragBlockInterface | E compileNativeComponent(vm, target, dest, type); } +/** + * Compile a dynamic component. + * @param {Vm} vm - Vm object needs to be compiled. + * @param {TemplateInterface} target - Node needs to be compiled. Structure of the label in the template. + * @param {Element | FragBlockInterface} dest - Parent Node's VM of current. + * @param {string} type - Component Type. + * @param {MetaInterface} meta - To transfer data. + */ +export function compileDyanmicComponent( + vm: Vm, + target: TemplateInterface, + dest: Element | FragBlockInterface, + type: string, + meta: Partial +): void { + const attr: object = target.attr; + let dynamicType: string; + for (const key in attr) { + const value = attr[key]; + if (key === 'name') { + if (typeof value === 'function') { + dynamicType = value.call(vm, vm); + } else if (typeof value === 'string') { + dynamicType = value; + } else { + Log.error('compontent attr name is unkonwn'); + return; + } + } + } + + const elementDiv = createElement(vm, 'div'); + attachTarget(elementDiv, dest); + + const element = createElement(vm, type); + element.vm = vm; + element.target = target; + element.destroyHook = function() { + if (element.watchers !== undefined) { + element.watchers.forEach(function(watcher) { + watcher.teardown(); + }); + element.watchers = []; + } + }; + bindDir(vm, element, 'attr', attr); + attachTarget(element, elementDiv); + + const component: VmOptions | null = targetIsComposed(vm, dynamicType); + if (component) { + compileCustomComponent(vm, component, target, elementDiv, dynamicType, meta); + return; + } +} + /** * Check if target type is slot. * @@ -212,17 +274,18 @@ function targetNeedCheckShown(target: TemplateInterface, meta: Partial { @@ -356,7 +419,7 @@ function compileBlock(vm: Vm, target: TemplateInterface, dest: Element | FragBlo * @param {string} type - Component Type. * @param {MetaInterface} meta - To transfer data. */ -function compileCustomComponent( +export function compileCustomComponent( vm: Vm, component: VmOptions, target: TemplateInterface, @@ -384,11 +447,11 @@ function compileCustomComponent( } }); } - this.slotContext = { content: namedContents, parentVm: vm }; + this.__slotContext = { content: namedContents, parentVm: vm }; setId(vm, null, target.id, this); // Bind template earlier because of lifecycle issues. - this.externalBinding = { + this.__externalBinding = { parent: vm, template: target }; @@ -411,7 +474,7 @@ function resetElementStyle(vm: Vm, element: Element): void { if (element.children !== undefined) { len = element.children.length; } - const css = vm.css || {}; + const css = vm._css || {}; const mqArr = css['@MEDIA']; for (let ii = 0; ii < len; ii++) { const el = element.children[ii] as Element; @@ -419,6 +482,7 @@ function resetElementStyle(vm: Vm, element: Element): void { resetElementStyle(vm, el); } } + setUniversalStyle(vm, element); if (element.type) { setTagStyle(vm, element, element.type); } @@ -447,28 +511,28 @@ function resetElementStyle(vm: Vm, element: Element): void { */ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragBlockInterface | Element, type: string): void { function handleViewSizeChanged(e) { - if (!vm.mediaStatus) { - vm.mediaStatus = {}; + if (!vm._mediaStatus) { + vm._mediaStatus = {}; } - vm.mediaStatus.orientation = e.orientation; - vm.mediaStatus.width = e.width; - vm.mediaStatus.height = e.height; - vm.mediaStatus.resolution = e.resolution; - vm.mediaStatus['device-type'] = e.deviceType; - vm.mediaStatus['aspect-ratio'] = e.aspectRatio; - vm.mediaStatus['device-width'] = e.deviceWidth; - vm.mediaStatus['device-height'] = e.deviceHeight; - vm.mediaStatus['round-screen'] = e.roundScreen; - vm.mediaStatus['dark-mode'] = e.darkMode; - const css = vm.vmOptions && vm.vmOptions.style || {}; + vm._mediaStatus.orientation = e.orientation; + vm._mediaStatus.width = e.width; + vm._mediaStatus.height = e.height; + vm._mediaStatus.resolution = e.resolution; + vm._mediaStatus['device-type'] = e['device-type']; + vm._mediaStatus['aspect-ratio'] = e['aspect-ratio']; + vm._mediaStatus['device-width'] = e['device-width']; + vm._mediaStatus['device-height'] = e['device-height']; + vm._mediaStatus['round-screen'] = e['round-screen']; + vm._mediaStatus['dark-mode'] = e['dark-mode']; + const css = vm._vmOptions && vm._vmOptions.style || {}; const mqArr = css['@MEDIA']; if (!mqArr) { return; } - if (e.isInit && vm.init) { + if (e.isInit && vm._init) { return; } - vm.init = true; + vm._init = true; resetElementStyle(vm, e.currentTarget); e.currentTarget.addEvent('show'); } @@ -492,11 +556,11 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB }; } - if (!vm.rootEl) { - vm.rootEl = element; + if (!vm._rootEl) { + vm._rootEl = element; // Bind event earlier because of lifecycle issues. - const binding: any = vm.externalBinding || {}; + const binding: any = vm._externalBinding || {}; const target = binding.template; const parentVm = binding.parent; if (target && target.events && parentVm && element) { @@ -511,7 +575,7 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB bindPageLifeCycle(vm, element); element.setCustomFlag(); element.customFlag = true; - vm.init = true; + vm._init = true; element.addEvent('viewsizechanged', handleViewSizeChanged); } @@ -529,7 +593,7 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB element.attr.append = template.append; } let treeMode = template.append === 'tree'; - const app: any = vm.app || {}; + const app: any = vm._app || {}; // Record the parent node of treeMode, used by class selector. if (treeMode) { @@ -559,7 +623,7 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB * @return {void | boolean} If there is no children, return null. Return true if has node. */ function compileChildren(vm: Vm, template: any, dest: Element | FragBlockInterface): void | boolean { - const app: any = vm.app || {}; + const app: any = vm._app || {}; const children = template.children; if (children && children.length) { children.every((child) => { @@ -614,6 +678,7 @@ function bindRepeat(vm: Vm, target: TemplateInterface, fragBlock: FragBlockInter // Remove unused element foreach old item. const reusedList: any[] = []; + const cacheList: any[] = []; oldData.forEach((item, index) => { const key = trackBy && item[trackBy] !== undefined ? item[trackBy] : index; if (hasOwn(trackMap, key)) { @@ -624,7 +689,10 @@ function bindRepeat(vm: Vm, target: TemplateInterface, fragBlock: FragBlockInter }; reusedList.push(item); } else { - removeTarget(oldChildren[index]); + cacheList.push({ + target: oldChildren[index], + vm: oldVms[index] + }); } }); @@ -651,10 +719,25 @@ function bindRepeat(vm: Vm, target: TemplateInterface, fragBlock: FragBlockInter reused.vm[keyName] = index; fragBlock.updateMark = reused.target; } else { - compileItem(item, index, vm); + if (cacheList.length > 0) { + const reusedItem = cacheList[0]; + cacheList.shift(); + moveTarget(reusedItem.target, fragBlock.updateMark); + children.push(reusedItem.target); + vms.push(reusedItem.vm); + reusedItem.vm[valueName] = item; + + reusedItem.vm[keyName] = index; + fragBlock.updateMark = reusedItem.target; + } else { + compileItem(item, index, vm); + } } }); delete fragBlock.updateMark; + cacheList.forEach((item) => { + removeTarget(item.target); + }); } ); if (list && Array.isArray(list)) { @@ -709,7 +792,7 @@ function bindShown( * @return {*} Init value of calc. */ function watchBlock(vm: Vm, fragBlock: FragBlockInterface, calc: Function, type: string, handler: Function): any { - const differ = vm && vm.app && vm.app.differ; + const differ = vm && vm._app && vm._app.differ; const config: Partial = {}; const newWatcher = newWatch(vm, calc, (value) => { config.latestValue = value; @@ -735,11 +818,11 @@ function watchBlock(vm: Vm, fragBlock: FragBlockInterface, calc: Function, type: */ function mergeContext(context: Vm, mergedData: object): any { const newContext = Object.create(context); - newContext._data = mergedData; - newContext._shareData = {}; + newContext.__data = mergedData; + newContext.__shareData = {}; initData(newContext); initComputed(newContext); - newContext._realParent = context; + newContext.__realParent = context; return newContext; } diff --git a/runtime/main/model/directive.ts b/runtime/main/model/directive.ts index 0d3aaf08..47cb24cd 100644 --- a/runtime/main/model/directive.ts +++ b/runtime/main/model/directive.ts @@ -53,9 +53,11 @@ const SETTERS = { attr: 'setAttr', style: 'setStyle', data: 'setData', + $data: 'setData', event: 'addEvent', idStyle: 'setIdStyle', - tagStyle: 'setTagStyle' + tagStyle: 'setTagStyle', + universalStyle: 'setUniversalStyle' }; /** @@ -68,7 +70,7 @@ const SETTERS = { export function bindElement(vm: Vm, el: Element, template: TemplateInterface, parentElement: Element | FragBlockInterface): void { // Set descendant style. setDescendantStyle( - vm.selector, + vm._selector, { id: template.id, class: template.classList, @@ -80,7 +82,7 @@ export function bindElement(vm: Vm, el: Element, template: TemplateInterface, pa if (!style) { return; } - const css = vm.css || {}; + const css = vm._css || {}; setAnimation(style, css); setFontFace(style, css); setStyle(vm, el, style); @@ -108,6 +110,7 @@ export function bindElement(vm: Vm, el: Element, template: TemplateInterface, pa setIdStyle(vm, el, template.id); setClass(vm, el, template.classList); setTagStyle(vm, el, template.type); + setUniversalStyle(vm, el); applyStyle(vm, el); bindEvents(vm, el, template.events); @@ -116,9 +119,9 @@ export function bindElement(vm: Vm, el: Element, template: TemplateInterface, pa bindEvents(vm, el, template.catchBubbleEvents, 'catchbubble'); bindEvents(vm, el, template.catchCaptureEvents, 'catchcapture'); - if (!vm.isHide && !vm.init) { + if (!vm._isHide && !vm._init) { el.addEvent('hide'); - vm.isHide = true; + vm._isHide = true; } } @@ -133,7 +136,7 @@ export function bindElement(vm: Vm, el: Element, template: TemplateInterface, pa export function bindSubVm(vm: Vm, rawSubVm: Vm, rawTemplate: TemplateInterface, repeatItem: object): void { const subVm: any = rawSubVm || {}; const template: any = rawTemplate || {}; - const options: any = subVm.vmOptions || {}; + const options: any = subVm._vmOptions || {}; let props = options.props; if (isArray(props) || !props) { @@ -209,7 +212,7 @@ function bindSubEvent(vm: Vm, subVm: Vm, template: TemplateInterface): void { * @return {*} Sub vm object. */ function mergePropsObject(key: string, value: any, vm: Vm, subVm: Vm): any { - subVm.props.push(key); + subVm._props.push(key); if (typeof value === 'function') { const returnValue = watch(vm, value, function(v) { subVm[key] = v; @@ -241,7 +244,7 @@ function mergeProps(target: object, props: any, vm: Vm, subVm: Vm): void { } for (const key in target) { if (!props || props[key] || key === 'show') { - subVm.props.push(key); + subVm._props.push(key); const value = target[key]; if (typeof value === 'function') { const returnValue = watch(vm, value, function(v) { @@ -271,14 +274,14 @@ function mergeStyle(target: { [key: string]: any }, vm: Vm, subVm: Vm): void { const value = target[key]; if (typeof value === 'function') { const returnValue = watch(vm, value, function(v) { - if (subVm.rootEl) { - subVm.rootEl.setStyle(key, v); + if (subVm._rootEl) { + subVm._rootEl.setStyle(key, v); } }); - subVm.rootEl.setStyle(key, returnValue); + subVm._rootEl.setStyle(key, returnValue); } else { - if (subVm.rootEl) { - subVm.rootEl.setStyle(key, value); + if (subVm._rootEl) { + subVm._rootEl.setStyle(key, value); } } } @@ -291,8 +294,8 @@ function mergeStyle(target: { [key: string]: any }, vm: Vm, subVm: Vm): void { * @param {Vm} subVm - Sub vm. */ function mergeClassStyle(target: Function | string[], vm: Vm, subVm: Vm): void { - const css = vm.css || {}; - if (!subVm.rootEl) { + const css = vm._css || {}; + if (!subVm._rootEl) { return; } @@ -301,7 +304,7 @@ function mergeClassStyle(target: Function | string[], vm: Vm, subVm: Vm): void { * @constant {string} */ const CLASS_NAME = '@originalRootEl'; - css['.' + CLASS_NAME] = subVm.rootEl.classStyle; + css['.' + CLASS_NAME] = subVm._rootEl.classStyle; function addClassName(list, name) { if (typof(list) === 'array') { @@ -312,13 +315,13 @@ function mergeClassStyle(target: Function | string[], vm: Vm, subVm: Vm): void { if (typeof target === 'function') { const value = watch(vm, target, v => { addClassName(v, CLASS_NAME); - setClassStyle(subVm.rootEl, css, v); + setClassStyle(subVm._rootEl, css, v); }); addClassName(value, CLASS_NAME); - setClassStyle(subVm.rootEl, css, value); + setClassStyle(subVm._rootEl, css, value); } else if (target !== undefined) { addClassName(target, CLASS_NAME); - setClassStyle(subVm.rootEl, css, target); + setClassStyle(subVm._rootEl, css, target); } } @@ -338,7 +341,7 @@ export function setId(vm: Vm, el: Element, id: Function | string, target: Vm): v configurable: false }, el: { - get: () => el || target.rootEl, + get: () => el || target._rootEl, configurable: false } }); @@ -347,17 +350,17 @@ export function setId(vm: Vm, el: Element, id: Function | string, target: Vm): v const newId = handler.call(vm); if (newId || newId === 0) { setElementId(el, newId); - vm.ids[newId] = map; + vm._ids[newId] = map; } watch(vm, handler, (newId) => { if (newId) { setElementId(el, newId); - vm.ids[newId] = map; + vm._ids[newId] = map; } }); } else if (id && typeof id === 'string') { setElementId(el, id); - vm.ids[id] = map; + vm._ids[id] = map; } } @@ -378,10 +381,14 @@ function setElementId(el: Element, id: string): void { * @param {Element} el - Element. * @param {AttrInterface} attr - Attr to bind. */ -function setAttr(vm: Vm, el: Element, attr: Partial): void { - if (attr && attr.data) { - // address data independently - bindDir(vm, el, 'data', attr.data); +export function setAttr(vm: Vm, el: Element, attr: Partial): void { + if (attr) { + // address $data or data independently + if (attr.$data) { + bindDir(vm, el, '$data', attr.$data); + } else if (attr.data && Object.prototype.toString.call(attr.data) === '[object Object]') { + bindDir(vm, el, 'data', attr.data); + } } bindDir(vm, el, 'attr', attr); } @@ -483,13 +490,13 @@ function selectStyle(css: object, key: string, vm: Vm): any { if (!vm) { return style; } - const mediaStatus = vm.mediaStatus; + const mediaStatus = vm._mediaStatus; if (!mediaStatus) { return style; } const mqArr = css['@MEDIA']; if (!mqArr) { - vm.init = true; + vm._init = true; return style; } const classStyle = {}; @@ -582,7 +589,9 @@ function setClassStyle(el: Element, css: object, classList: string[], vm?: Vm): const animationName = classStyle['animationName']; if (animationName) { classStyle['animationName'] = keyframes[animationName]; - classStyle['animationName'].push({'animationName': animationName}); + if (classStyle['animationName']) { + classStyle['animationName'].push({'animationName': animationName}); + } } const transitionEnter = classStyle['transitionEnter']; if (transitionEnter) { @@ -620,7 +629,7 @@ export function setClass(vm: Vm, el: Element, classList: Function | string[]): v el.setClassStyle({}); return; } - const style = vm.css || {}; + const style = vm._css || {}; if (typeof classList === 'function') { const value = watch(vm, classList, v => { setClassStyle(el, style, v, vm); @@ -639,7 +648,7 @@ export function setClass(vm: Vm, el: Element, classList: Function | string[]): v */ export function setIdStyle(vm: Vm, el: Element, id: Function | string): void { if (id) { - const css = vm.css || {}; + const css = vm._css || {}; if (typeof id === 'function') { const value = watch(vm, id, v => { doSetStyle(vm, el, selectIdStyle(css, v, vm), css, 'idStyle'); @@ -706,12 +715,22 @@ function setAnimation(style: any, css: any): void { * @param {string} tag - Tag. */ export function setTagStyle(vm: Vm, el: Element, tag: string): void { - const css = vm.css || {}; + const css = vm._css || {}; if (tag && typeof tag === 'string') { doSetStyle(vm, el, selectStyle(css, tag, vm), css, 'tagStyle'); } } +/** + * Set * style. + * @param {Vm} vm - Vm object. + * @param {Element} el - ELement component. + */ +export function setUniversalStyle(vm: Vm, el: Element): void { + const css = vm._css || {}; + doSetStyle(vm, el, selectStyle(css, "*", vm), css, 'universalStyle'); +} + /** * Bind style to an element. * @param {Vm} vm - Vm object. @@ -769,7 +788,7 @@ function bindEvents(vm: Vm, el: Element, events: object, eventType?: string): vo * @param {string} name - Method name. * @param {Object} data - Data that needed. */ -function bindDir(vm: Vm, el: Element, name: string, data: object): void { +export function bindDir(vm: Vm, el: Element, name: string, data: object): void { if (!data) { return; } @@ -781,6 +800,11 @@ function bindDir(vm: Vm, el: Element, name: string, data: object): void { const methodName = SETTERS[name]; const method = el[methodName]; const isSetStyle = methodName === 'setStyle'; + if (methodName === 'setIdStyle') { + for (const id in el.idStyle) { + el.idStyle[id] = ''; + } + } while (i--) { const key = keys[i]; const value = data[key]; @@ -815,7 +839,7 @@ function bindKey(vm: Vm, el: Element, setValue: Function, calc: Function): void function handler() { setValue(value); } - const differ = vm && vm.app && vm.app.differ; + const differ = vm && vm._app && vm._app.differ; if (differ) { differ.append('element', el.ref, handler); } else { @@ -833,7 +857,7 @@ function bindKey(vm: Vm, el: Element, setValue: Function, calc: Function): void * @return {*} FontFamily Filter. */ export function filterFontFamily(vm: Vm, fontFamilyName: string): any[] { - const css = vm.css || {}; + const css = vm._css || {}; return _getFontFamily(css, fontFamilyName); } @@ -877,7 +901,7 @@ export function watch(vm: Vm, calc: Function, callback: Function): any { * @param {Element} el - Element object. */ function applyStyle(vm: Vm, el: Element): void { - const css = vm.css || {}; + const css = vm._css || {}; const allStyle = el.style; setAnimation(allStyle, css); } diff --git a/runtime/main/model/domHelper.ts b/runtime/main/model/domHelper.ts index 94e206af..2001a33f 100644 --- a/runtime/main/model/domHelper.ts +++ b/runtime/main/model/domHelper.ts @@ -38,7 +38,7 @@ import { emitSubVmLife } from './pageLife'; * @return {Node} Body of Node by type. */ export function createBody(vm: Vm, type: string): Node { - const doc = vm.app.doc; + const doc = vm._app.doc; return doc.createBody(type); } @@ -49,7 +49,7 @@ export function createBody(vm: Vm, type: string): Node { * @return {Element} Element of Node by type. */ export function createElement(vm: Vm, type: string): Element { - const doc = vm.app.doc; + const doc = vm._app.doc; return doc.createElement(type); } @@ -95,7 +95,7 @@ let lastestBlockId = 1; * @return {Comment} A block starter. */ function createBlockStart(vm: Vm): Comment { - const doc = vm.app.doc; + const doc = vm._app.doc; const anchor = doc.createComment('start'); return anchor; } @@ -106,7 +106,7 @@ function createBlockStart(vm: Vm): Comment { * @return {Comment} A block starter. */ function createBlockEnd(vm: Vm): Comment { - const doc = vm.app.doc; + const doc = vm._app.doc; const anchor = doc.createComment('end'); anchor.destroyHook = function() { if (anchor.watchers !== undefined) { diff --git a/runtime/main/model/events.ts b/runtime/main/model/events.ts index 58b49efe..c2f328db 100644 --- a/runtime/main/model/events.ts +++ b/runtime/main/model/events.ts @@ -136,7 +136,7 @@ export const LIFE_CYCLE_TYPES: Array = [ * @param {ExternalEvent} externalEvents - External events. */ export function initEvents(vm: Vm, externalEvents: ExternalEvent): void { - const options = vm.vmOptions || {}; + const options = vm._vmOptions || {}; for (const externalEvent in externalEvents) { vm.$on(externalEvent, externalEvents[externalEvent]); } diff --git a/runtime/main/model/index.ts b/runtime/main/model/index.ts index 4d3b86f1..f710d6d2 100644 --- a/runtime/main/model/index.ts +++ b/runtime/main/model/index.ts @@ -72,40 +72,40 @@ import { * VM constructor. * @param {string} type - Type. * @param {null | VmOptions} options - Component options. - * @param {Vm} parentVm which contains _app. + * @param {Vm} parentVm which contains __app. * @param {Element | FragBlockInterface} parentEl - root element or frag block. * @param {Object} mergedData - External data. * @param {ExternalEvent} externalEvents - External events. */ export default class Vm { - private _parent: Vm; - private _app: Page; - private _computed: ComputedInterface; - private _css: cssType; - private _type: string; - private readonly _descriptor: string; - private _props: Props; - private _vmOptions: VmOptions; - private _selector: object; - private _ids: Record; - private _init: boolean; - private _ready: boolean; - private _valid: boolean; - private _vmEvents: object; - private _childrenVms: Vm[]; - private _visible: boolean; - private _data: any; - private _shareData: any; - private _realParent: Vm - private _parentEl: Element | FragBlockInterface; - private _rootEl: Element; - private _$refs: Record; - private _externalBinding: ExternalBindingInterface; - private _isHide: boolean; - private _mediaStatus: Partial>; - private _methods: Record any>; - private _slotContext: { content: Record, parentVm: Vm }; private _$app: any; + private __methods: Record any>; + private __type: string; + private __css: cssType; + private __vmOptions: VmOptions; + private __parent: Vm; + private __realParent: Vm; + private __computed: ComputedInterface; + private __selector: object; + private __parentEl: Element | FragBlockInterface; + private __app: Page; + private __shareData: any; + private __data: any; + private __props: Props; + private __init: boolean; + private __valid: boolean; + private __visible: boolean; + private __ready: boolean; + private __rootEl: Element; + private __ids: Record; + private __vmEvents: object; + private __childrenVms: Vm[]; + private __externalBinding: ExternalBindingInterface; + private readonly __descriptor: string; + private __isHide: boolean; + private __mediaStatus: Partial>; + private _$refs: Record; + private __slotContext: { content: Record, parentVm: Vm }; constructor( type: string, @@ -116,38 +116,38 @@ export default class Vm { externalEvents: ExternalEvent ) { this._$app = global.aceapp; - this._parent = parentVm._realParent ? parentVm._realParent : parentVm; - this._app = parentVm._app; - parentVm._childrenVms && parentVm._childrenVms.push(this); + this.__parent = parentVm.__realParent ? parentVm.__realParent : parentVm; + this.__app = parentVm.__app; + parentVm.__childrenVms && parentVm.__childrenVms.push(this); - if (!options && this._app.customComponentMap) { - options = this._app.customComponentMap[type]; + if (!options && this.__app.customComponentMap) { + options = this.__app.customComponentMap[type]; } const data = options.data || {}; const shareData = options.shareData || {}; - this._vmOptions = options; - this._computed = options.computed; - this._css = options.style; - this._selector = selector(this._css); - this._ids = {}; + this.__vmOptions = options; + this.__computed = options.computed; + this.__css = options.style; + this.__selector = selector(this.__css); + this.__ids = {}; this._$refs = {}; - this._vmEvents = {}; - this._childrenVms = []; - this._type = type; - this._valid = true; - this._props = []; - this._methods = {}; + this.__vmEvents = {}; + this.__childrenVms = []; + this.__type = type; + this.__valid = true; + this.__props = []; + this.__methods = {}; // Bind events and lifecycles. initEvents(this, externalEvents); Log.debug( - `'_innerInit' lifecycle in Vm(${this._type}) and mergedData = ${JSON.stringify(mergedData)}.` + `'_innerInit' lifecycle in Vm(${this.__type}) and mergedData = ${JSON.stringify(mergedData)}.` ); this.$emit('hook:_innerInit'); - this._data = (typeof data === 'function' ? data.apply(this) : data) || {}; - this._shareData = (typeof shareData === 'function' ? shareData.apply(this) : shareData) || {}; - this._descriptor = options._descriptor; + this.__data = (typeof data === 'function' ? data.apply(this) : data) || {}; + this.__shareData = (typeof shareData === 'function' ? shareData.apply(this) : shareData) || {}; + this.__descriptor = options._descriptor; if (global.aceapp && global.aceapp.i18n && global.aceapp.i18n.extend) { global.aceapp.i18n.extend(this); } @@ -158,10 +158,10 @@ export default class Vm { // MergedData means extras params. if (mergedData) { if (hasOwn(mergedData, 'paramsData') && hasOwn(mergedData, 'dontOverwrite') && mergedData['dontOverwrite'] === false) { - dataAccessControl(this, mergedData['paramsData'], this._app.options && this._app.options.appCreate); + dataAccessControl(this, mergedData['paramsData'], this.__app.options && this.__app.options.appCreate); extend(this._data, mergedData['paramsData']); } else { - dataAccessControl(this, mergedData, this._app.options && this._app.options.appCreate); + dataAccessControl(this, mergedData, this.__app.options && this.__app.options.appCreate); extend(this._data, mergedData); } } @@ -169,7 +169,7 @@ export default class Vm { initPropsToData(this); initState(this); initBases(this); - Log.debug(`"onInit" lifecycle in Vm(${this._type})`); + Log.debug(`"onInit" lifecycle in Vm(${this.__type})`); if (mergedData && hasOwn(mergedData, 'paramsData') && hasOwn(mergedData, 'dontOverwrite')) { if (mergedData['dontOverwrite'] === false) { @@ -181,23 +181,23 @@ export default class Vm { this.$emit('hook:onInit'); } - if (!this._app.doc) { + if (!this.__app.doc) { return; } - this.mediaStatus = {}; - this.mediaStatus.orientation = this._app.options.orientation; - this.mediaStatus.width = this._app.options.width; - this.mediaStatus.height = this._app.options.height; - this.mediaStatus.resolution = this._app.options.resolution; - this.mediaStatus['device-type'] = this._app.options['device-type']; - this.mediaStatus['aspect-ratio'] = this._app.options['aspect-ratio']; - this.mediaStatus['device-width'] = this._app.options['device-width']; - this.mediaStatus['device-height'] = this._app.options['device-height']; - this.mediaStatus['round-screen'] = this._app.options['round-screen']; - this.mediaStatus['dark-mode'] = this._app.options['dark-mode']; + this.__mediaStatus = {}; + this.__mediaStatus.orientation = this.__app.options.orientation; + this.__mediaStatus.width = this.__app.options.width; + this.__mediaStatus.height = this.__app.options.height; + this.__mediaStatus.resolution = this.__app.options.resolution; + this.__mediaStatus['device-type'] = this.__app.options['device-type']; + this.__mediaStatus['aspect-ratio'] = this.__app.options['aspect-ratio']; + this.__mediaStatus['device-width'] = this.__app.options['device-width']; + this.__mediaStatus['device-height'] = this.__app.options['device-height']; + this.__mediaStatus['round-screen'] = this.__app.options['round-screen']; + this.__mediaStatus['dark-mode'] = this.__app.options['dark-mode']; // If there is no parentElement, specify the documentElement. - this._parentEl = parentEl || this._app.doc.documentElement; + this.__parentEl = parentEl || this.__app.doc.documentElement; build(this); } @@ -212,12 +212,12 @@ export default class Vm { Log.warn(`Invalid parameter type: The type of 'id' should be string or number, not ${typeof id}.`); return; } - const info: any = this.ids[id]; + const info: any = this._ids[id]; if (info) { return info.el; } } else { - return this.rootEl; + return this.__rootEl; } } @@ -227,7 +227,7 @@ export default class Vm { * @return {Vm} Vm object. */ public $vm(id: string): Vm { - const info = this.ids[id]; + const info = this._ids[id]; if (info) { return info.vm; } @@ -237,7 +237,7 @@ export default class Vm { * Get parent Vm of current. */ public $parent(): Vm { - return this.parent; + return this._parent; } /** @@ -255,7 +255,7 @@ export default class Vm { * Get root element of current. */ public $rootElement(): Element { - return this.rootEl; + return this.__rootEl; } /** @@ -277,7 +277,7 @@ export default class Vm { Log.warn(`Invalid parameter type: The type of 'type' should be string, not ${typeof type}.`); return; } - const events = this._vmEvents; + const events = this.__vmEvents; const handlerList = events[type]; if (handlerList) { const results = []; @@ -300,7 +300,7 @@ export default class Vm { Log.warn(`Invalid parameter type: The type of 'type' should be string, not ${typeof type}.`); return; } - const events = this._vmEvents; + const events = this.__vmEvents; const handlerList = events[type]; if (handlerList) { const results = []; @@ -323,8 +323,8 @@ export default class Vm { } const evt = new Evt(type, detail); this.$emit(type, evt); - if (!evt.hasStopped() && this._parent && this._parent.$dispatch) { - this._parent.$dispatch(type, evt); + if (!evt.hasStopped() && this.__parent && this.__parent.$dispatch) { + this.__parent.$dispatch(type, evt); } } @@ -340,8 +340,8 @@ export default class Vm { } const evt = new Evt(type, detail); this.$emit(type, evt); - if (!evt.hasStopped() && this._childrenVms) { - this._childrenVms.forEach((subVm) => { + if (!evt.hasStopped() && this.__childrenVms) { + this.__childrenVms.forEach((subVm) => { subVm.$broadcast(type, evt); }); } @@ -361,11 +361,11 @@ export default class Vm { Log.warn(`Invalid parameter type: The type of 'handler' should be function, not ${typeof handler}.`); return; } - const events = this._vmEvents; + const events = this.__vmEvents; const handlerList = events[type] || []; handlerList.push(handler); events[type] = handlerList; - if (type === 'hook:onReady' && this._ready) { + if (type === 'hook:onReady' && this.__ready) { this.$emit('hook:onReady'); } } @@ -384,7 +384,7 @@ export default class Vm { Log.warn(`Invalid parameter type: The type of 'handler' should be function, not ${typeof handler}.`); return; } - const events = this._vmEvents; + const events = this.__vmEvents; if (!handler) { delete events[type]; return; @@ -411,7 +411,7 @@ export default class Vm { Log.warn(`Invalid parameter type: The type of 'id' should be string, not ${typeof id}.`); return; } - const info = this.ids[id]; + const info = this._ids[id]; if (info) { const element = info.el; const evt = new Evt(type, data); @@ -470,33 +470,33 @@ export default class Vm { * Delete Vm object. */ public destroy(): void { - Log.debug(`[JS Framework] "onDestroy" lifecycle in Vm(${this.type})`); + Log.debug(`[JS Framework] "onDestroy" lifecycle in Vm(${this.__type})`); this.$emit('hook:onDestroy'); this.$emit('hook:onDetached'); - fireNodeDetached(this._rootEl); - this._valid = false; + fireNodeDetached(this.__rootEl); + this.__valid = false; - delete this._app; - delete this._computed; - delete this._css; - delete this._data; - delete this._ids; - delete this._vmOptions; - delete this._parent; - delete this._parentEl; - delete this._rootEl; + delete this.__app; + delete this.__computed; + delete this.__css; + delete this.__data; + delete this.__ids; + delete this.__vmOptions; + delete this.__parent; + delete this.__parentEl; + delete this.__rootEl; delete this._$refs; // Destroy child vms recursively. - if (this._childrenVms) { - let vmCount: number = this._childrenVms.length; + if (this.__childrenVms) { + let vmCount: number = this.__childrenVms.length; while (vmCount--) { - this.destroy.call(this._childrenVms[vmCount], this._childrenVms[vmCount]); + this.destroy.call(this.__childrenVms[vmCount], this.__childrenVms[vmCount]); } - delete this._childrenVms; + delete this.__childrenVms; } - delete this._type; - delete this._vmEvents; + delete this.__type; + delete this.__vmEvents; } /** @@ -539,8 +539,8 @@ export default class Vm { * @type {Object} * @readonly */ - public get methods() { - return this._methods; + public get _methods() { + return this.__methods; } /** @@ -548,12 +548,12 @@ export default class Vm { * @type {string} * @readonly */ - public get type() { - return this._type; + public get _type() { + return this.__type; } - public set type(newType: string) { - this._type = newType; + public set _type(newType: string) { + this.__type = newType; } /** @@ -561,20 +561,20 @@ export default class Vm { * @type {[key: string]: any} * @readonly */ - public get css() { - return this._css; + public get _css() { + return this.__css; } /** * Options of this Vm. * @type {VmOptions} */ - public get vmOptions() { - return this._vmOptions; + public get _vmOptions() { + return this.__vmOptions; } - public set vmOptions(newOptions: VmOptions) { - this._vmOptions = newOptions; + public set _vmOptions(newOptions: VmOptions) { + this.__vmOptions = newOptions; } /** @@ -582,20 +582,20 @@ export default class Vm { * @type {Vm} * @readonly */ - public get parent() { - return this._parent; + public get _parent() { + return this.__parent; } /** * RealParent of this Vm. * @type {Vm} */ - public get realParent() { - return this._realParent; + public get _realParent() { + return this.__realParent; } - public set realParent(realParent: Vm) { - this._realParent = realParent; + public set _realParent(realParent: Vm) { + this.__realParent = realParent; } /** @@ -603,11 +603,11 @@ export default class Vm { * @type {ComputedInterface} */ public get computed() { - return this._computed; + return this.__computed; } public set computed(newComputed: ComputedInterface) { - this._computed = newComputed; + this.__computed = newComputed; } /** @@ -615,56 +615,56 @@ export default class Vm { * @type {Object} * @readonly */ - public get selector() { - return this._selector; + public get _selector() { + return this.__selector; } /** * ParentEl of this Vm. * @type {FragBlockInterface | Element} */ - public get parentEl() { - return this._parentEl; + public get _parentEl() { + return this.__parentEl; } - public set parentEl(newParentEl: FragBlockInterface | Element) { - this._parentEl = newParentEl; + public set _parentEl(newParentEl: FragBlockInterface | Element) { + this.__parentEl = newParentEl; } /** * App of this Vm. * @type {Page} */ - public get app() { - return this._app; + public get _app() { + return this.__app; } - public set app(newApp: Page) { - this._app = newApp; + public set _app(newApp: Page) { + this.__app = newApp; } /** * ShareData of this Vm. * @type {*} */ - public get shareData() { - return this._shareData; + public get _shareData() { + return this.__shareData; } - public set shareData(newShareData: object) { - this._shareData = newShareData; + public set _shareData(newShareData: object) { + this.__shareData = newShareData; } /** * Data of this Vm. * @type {*} */ - public get __data() { - return this._data; + public get _data() { + return this.__data; } - public set __data(newData: any) { - this._data = newData; + public set _data(newData: any) { + this.__data = newData; } /** @@ -672,20 +672,20 @@ export default class Vm { * @type {Props} * @readonly */ - public get props() { - return this._props; + public get _props() { + return this.__props; } /** * Init of this Vm. * @type {boolean} */ - public get init() { - return this._init; + public get _init() { + return this.__init; } - public set init(newInit: boolean) { - this._init = newInit; + public set _init(newInit: boolean) { + this.__init = newInit; } /** @@ -693,44 +693,44 @@ export default class Vm { * @type {boolean} * @readonly */ - public get valid() { - return this._valid; + public get _valid() { + return this.__valid; } /** * Visible of this Vm. * @type {boolean} */ - public get visible() { - return this._visible; + public get _visible() { + return this.__visible; } - public set visible(newVisible) { - this._visible = newVisible; + public set _visible(newVisible) { + this.__visible = newVisible; } /** * Ready of this Vm. * @type {boolean} */ - public get ready() { - return this._ready; + public get _ready() { + return this.__ready; } - public set ready(newReady: boolean) { - this._ready = newReady; + public set _ready(newReady: boolean) { + this.__ready = newReady; } /** * RootEl of this Vm. * @type {Element} */ - public get rootEl() { - return this._rootEl; + public get _rootEl() { + return this.__rootEl; } - public set rootEl(newRootEl: Element) { - this._rootEl = newRootEl; + public set _rootEl(newRootEl: Element) { + this.__rootEl = newRootEl; } /** @@ -738,8 +738,8 @@ export default class Vm { * @type {{[key: string]: { vm: Vm, el: Element}}} * @readonly */ - public get ids() { - return this._ids; + public get _ids() { + return this.__ids; } /** @@ -747,28 +747,28 @@ export default class Vm { * @type {Object} * @readonly */ - public get vmEvents() { - return this._vmEvents; + public get _vmEvents() { + return this.__vmEvents; } /** * children of vm. * @return {Array} - children of Vm. */ - public get childrenVms() { - return this._childrenVms; + public get _childrenVms() { + return this.__childrenVms; } /** * ExternalBinding of this Vm. * @type {ExternalBinding} */ - public get externalBinding() { - return this._externalBinding; + public get _externalBinding() { + return this.__externalBinding; } - public set externalBinding(newExternalBinding: ExternalBindingInterface) { - this._externalBinding = newExternalBinding; + public set _externalBinding(newExternalBinding: ExternalBindingInterface) { + this.__externalBinding = newExternalBinding; } /** @@ -776,32 +776,32 @@ export default class Vm { * @type {string} * @readonly */ - public get descriptor() { - return this._descriptor; + public get _descriptor() { + return this.__descriptor; } /** * IsHide of this Vm. * @type {boolean} */ - public get isHide() { - return this._isHide; + public get _isHide() { + return this.__isHide; } - public set isHide(newIsHide: boolean) { - this._isHide = newIsHide; + public set _isHide(newIsHide: boolean) { + this.__isHide = newIsHide; } /** * MediaStatus of this Vm. * @type {MediaStatusInterface} */ - public get mediaStatus() { - return this._mediaStatus; + public get _mediaStatus() { + return this.__mediaStatus; } - public set mediaStatus(newMediaStatus: Partial>) { - this._mediaStatus = newMediaStatus; + public set _mediaStatus(newMediaStatus: Partial>) { + this.__mediaStatus = newMediaStatus; } /** @@ -817,12 +817,12 @@ export default class Vm { * slotContext of this Vm. * @type { content: Record, parentVm: Vm } */ - public get slotContext() { - return this._slotContext; + public get _slotContext() { + return this.__slotContext; } - public set slotContext(newMSoltContext: { content: Record, parentVm: Vm }) { - this._slotContext = newMSoltContext; + public set _slotContext(newMSoltContext: { content: Record, parentVm: Vm }) { + this.__slotContext = newMSoltContext; } } @@ -877,11 +877,11 @@ function dataAccessControl(vm: any, mergedData: object, external: boolean): void * @return {Vm} Root vm. */ function getRoot(vm: any): Vm { - const parent = vm.parent; + const parent = vm._parent; if (!parent) { return vm; } - if (parent._rootVm) { + if (parent.__rootVm) { return vm; } return getRoot(parent); diff --git a/runtime/main/model/pageLife.ts b/runtime/main/model/pageLife.ts index 4deada95..aff44b3e 100644 --- a/runtime/main/model/pageLife.ts +++ b/runtime/main/model/pageLife.ts @@ -123,7 +123,7 @@ const PAGE_LIFE_CYCLE_TYPES: Array = [ * @param {Element} element - Element object. */ export function bindPageLifeCycle(vm: Vm, element: Element): void { - const options = vm.vmOptions || {}; + const options = vm._vmOptions || {}; PAGE_LIFE_CYCLE_TYPES.forEach(type => { let eventType; if (type === PageLifecycleHooks.ONSHOW) { @@ -166,10 +166,10 @@ export function bindPageLifeCycle(vm: Vm, element: Element): void { function eventHandle(event, ...args: any[]): any { if (type === PageLifecycleHooks.ONSHOW) { emitSubVmLife(vm, 'onPageShow'); - vm.visible = true; + vm._visible = true; } else if (type === PageLifecycleHooks.ONHIDE) { emitSubVmLife(vm, 'onPageHide'); - vm.visible = false; + vm._visible = false; } else if (type === PageLifecycleHooks.ONCONFIGURATIONUPDATED) { return vm.$emitDirect(`hook:${type}`, ...args); } @@ -203,7 +203,7 @@ export function bindPageLifeCycle(vm: Vm, element: Element): void { if (!result) { return false; } - const shareResult = vm.shareData || {}; + const shareResult = vm._shareData || {}; if (shareResult instanceof Object && !(shareResult instanceof Array)) { allData.shareData = shareResult; } @@ -219,11 +219,11 @@ export function bindPageLifeCycle(vm: Vm, element: Element): void { const saveData = restoreData.saveData || {}; const shareData = restoreData.shareData || {}; - Object.assign(vm.shareData, shareData); + Object.assign(vm._shareData, shareData); return vm.$emitDirect(`hook:${type}`, saveData); } function handleNewRequest(data: any) { - Object.assign(vm.__data, data); + Object.assign(vm._data, data); return vm.$emitDirect(`hook:${type}`); } }); @@ -255,8 +255,8 @@ export function watch(vm: Vm, data: string, callback: ((...args: any) => any) | if (typeof callback === 'function') { callback(value, oldValue); } else { - if (vm.methods[callback] && typeof vm.methods[callback] === 'function') { - vm.methods[callback](value, oldValue); + if (vm._methods[callback] && typeof vm._methods[callback] === 'function') { + vm._methods[callback](value, oldValue); } } }, null); @@ -268,9 +268,9 @@ export function watch(vm: Vm, data: string, callback: ((...args: any) => any) | * @param {Vm} vm - Vm object. */ export function initPropsToData(vm: Vm): void { - vm.props.forEach(prop => { - if (vm.__data) { - vm.__data[prop] = vm[prop]; + vm._props.forEach(prop => { + if (vm._data) { + vm._data[prop] = vm[prop]; } }); } @@ -281,8 +281,8 @@ export function initPropsToData(vm: Vm): void { * @param {String} type - event type */ export function emitSubVmLife(vm: Vm, type:string) { - if (vm.childrenVms) { - vm.childrenVms.forEach((subVm) => { + if (vm._childrenVms) { + vm._childrenVms.forEach((subVm) => { subVm.$emit(`hook:${type}`); emitSubVmLife(subVm, type); }); diff --git a/runtime/main/page/Image.ts b/runtime/main/page/Image.ts index 5efe28b4..e88348e5 100644 --- a/runtime/main/page/Image.ts +++ b/runtime/main/page/Image.ts @@ -51,8 +51,10 @@ export class Image { width: this._width, height: this._height, success: data => { + this._width = data.width; + this._height = data.height; if (this.onload && typeof this.onload === 'function') { - this.onload(data); + this.onload(); } }, fail: data => { diff --git a/runtime/main/page/entry/bundle.ts b/runtime/main/page/entry/bundle.ts index 74e93a58..4b79cfe2 100644 --- a/runtime/main/page/entry/bundle.ts +++ b/runtime/main/page/entry/bundle.ts @@ -117,5 +117,5 @@ export function bootstrap(page: Page, name: string, data: any): any { } // Create a new Vm and mark rootVm. - page.vm = new Vm(componentName, null, { _app: page, _rootVm: true }, null, data, null); + page.vm = new Vm(componentName, null, { __app: page, __rootVm: true }, null, data, null); } diff --git a/runtime/main/page/entry/init.ts b/runtime/main/page/entry/init.ts index 0dff7754..24244da5 100644 --- a/runtime/main/page/entry/init.ts +++ b/runtime/main/page/entry/init.ts @@ -104,6 +104,10 @@ export function init(page: Page, code: string | Function, data: object, services // Support page global and init language. global.__appProto__ = getPageGlobal(page.packageName); global.language = page.options.language; + global.$app_define$ = pageDefine; + global.$app_require$ = pageRequireModule; + global.Image = imageObj; + global.OffscreenCanvas = offscreenCanvasObj; let functionCode: string; if (typeof code !== 'function') { diff --git a/runtime/main/reactivity/state.js b/runtime/main/reactivity/state.js index 21ba24b3..503051d1 100644 --- a/runtime/main/reactivity/state.js +++ b/runtime/main/reactivity/state.js @@ -18,9 +18,9 @@ export function initState (vm) { } export function initData (vm) { - let data = vm._data; + let data = vm.__data; initDataSegment(vm, data); - let shareData = vm._shareData; + let shareData = vm.__shareData; initDataSegment(vm, shareData); } @@ -40,7 +40,7 @@ export function initDataSegment (vm, data) { } export function initBases(vm) { - const options = vm.vmOptions + const options = vm.__vmOptions // mixins exist? if(hasOwn(options, 'mixins')) { options['mixins'].forEach(mixin => { @@ -63,7 +63,7 @@ function noop () { } export function initComputed (vm) { - const computed = vm._computed; + const computed = vm.__computed; if (computed) { for (let key in computed) { const userDef = computed[key]; @@ -105,7 +105,7 @@ function makeComputedGetter (getter, owner) { } export function initMethods (vm) { - const options = vm._vmOptions; + const options = vm.__vmOptions; for (let key in options) { if (typeof options[key] === 'function' && key !== 'data') { vm._methods[key] = options[key].bind(vm); @@ -119,10 +119,10 @@ function proxyMethods(vm, key) { configurable: true, enumerable: true, get: function proxyGetter () { - return vm._methods[key]; + return vm.__methods[key]; }, set: function proxySetter(newValue) { - vm._methods[key] = typeof newValue === 'function' && key !== 'data' ? + vm.__methods[key] = typeof newValue === 'function' && key !== 'data' ? newValue.bind(vm) : newValue; } }) diff --git a/runtime/main/util/shared.js b/runtime/main/util/shared.js index eed03320..cc59f8d1 100644 --- a/runtime/main/util/shared.js +++ b/runtime/main/util/shared.js @@ -78,3 +78,19 @@ export function isObject(any) { export function isPlainObject(any) { return Object.prototype.toString.call(any) === '[object Object]'; } + +/** + * Convert ArrayBuffer to Base64. + * @param {*} buffer - Binary data buffer. + * @return {string} Base64 encoding string. + */ +export function bufferToBase64 (buffer) { + if (typeof btoa !== 'function') { + return ''; + } + const string = Array.prototype.map.call( + new Uint8Array(buffer), + code => String.fromCharCode(code) + ).join(''); + return btoa(string); +} \ No newline at end of file diff --git a/runtime/preparation/init.ts b/runtime/preparation/init.ts index 3f4167b8..037c73f1 100644 --- a/runtime/preparation/init.ts +++ b/runtime/preparation/init.ts @@ -111,91 +111,92 @@ type components = { } const ComponentsInfo: components[] = [ - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'clock'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'image'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'label'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'list-item'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'list-item-group'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'progress'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'rating'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'select'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'switch'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tabs'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tab-bar'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tab-content'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'text'}, - {'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'div'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'clock'}, + {'methods': ['show'], 'type': 'colorpicker'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'image'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'label'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'list-item'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'list-item-group'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'progress'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'rating'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'select'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'switch'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tabs'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tab-bar'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tab-content'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'text'}, + {'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'div'}, { - 'methods': ['setProgress', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['setProgress', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'button' }, - {'methods': ['append', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'chart'}, - {'methods': ['goto', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'calendar'}, + {'methods': ['append', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'chart'}, + {'methods': ['goto', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'calendar'}, { - 'methods': ['getContext', 'toDataURL', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['getContext', 'toDataURL', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'canvas' }, { - 'methods': ['getXComponentContext', 'createIntersectionObserver'], + 'methods': ['getXComponentContext', 'createIntersectionObserver', 'addChild'], 'type': 'xcomponent' }, - {'methods': ['show', 'close', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'dialog'}, - {'methods': ['animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'divider'}, + {'methods': ['show', 'close', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'dialog'}, + {'methods': ['animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'divider'}, { - 'methods': ['getColumns', 'getColumnWidth', 'getGutterWidth', 'getSizeType', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['getColumns', 'getColumnWidth', 'getGutterWidth', 'getSizeType', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'grid-container' }, { - 'methods': ['start', 'stop', 'pause', 'resume', 'getState', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['start', 'stop', 'pause', 'resume', 'getState', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'image-animator' }, { - 'methods': ['showError', 'delete', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['showError', 'delete', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'input' }, { - 'methods': ['scrollTo', 'scrollBy', 'focus', 'scrollArrow', 'scrollTop', 'scrollBottom', 'scrollPage', 'collapseGroup', 'expandGroup', 'currentOffset', 'rotation', 'animate', 'chainanimation', 'getBoundingClientRect', 'getScrollOffset', 'createIntersectionObserver'], + 'methods': ['scrollTo', 'scrollBy', 'focus', 'addChild', 'scrollArrow', 'scrollTop', 'scrollBottom', 'scrollPage', 'collapseGroup', 'expandGroup', 'currentOffset', 'rotation', 'animate', 'chainanimation', 'getBoundingClientRect', 'getScrollOffset', 'createIntersectionObserver'], 'type': 'list' }, { - 'methods': ['start', 'stop', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['start', 'stop', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'marquee' }, - {'methods': ['show', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'menu'}, - {'methods': ['focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'option'}, - {'methods': ['show', 'close', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'panel'}, - {'methods': ['show', 'animate', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'picker'}, + {'methods': ['show', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'menu'}, + {'methods': ['focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'option'}, + {'methods': ['show', 'close', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'panel'}, + {'methods': ['show', 'animate', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'picker'}, { - 'methods': ['rotation', 'animate', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['rotation', 'animate', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'picker-view' }, - {'methods': ['focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'piece'}, - {'methods': ['focus', 'show', 'hide', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'popup'}, - {'methods': ['animate', 'focus', 'delete', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'search'}, + {'methods': ['focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'piece'}, + {'methods': ['focus', 'addChild', 'show', 'hide', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'popup'}, + {'methods': ['animate', 'focus', 'addChild', 'delete', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'search'}, { - 'methods': ['rotation', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['rotation', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'slider' }, - {'methods': ['focus', 'animate', 'getScrollOffset', 'scrollBy', 'getBoundingClientRect', 'scrollTo', 'createIntersectionObserver'], 'type': 'stack'}, + {'methods': ['focus', 'addChild', 'animate', 'getScrollOffset', 'scrollBy', 'getBoundingClientRect', 'scrollTo', 'createIntersectionObserver'], 'type': 'stack'}, { - 'methods': ['swipeTo', 'focus', 'showPrevious', 'showNext', 'rotation', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['swipeTo', 'focus', 'addChild', 'showPrevious', 'showNext', 'rotation', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'swiper' }, { - 'methods': ['start', 'pause', 'stop', 'setCurrentTime', 'requestFullscreen', 'exitFullscreen', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['start', 'pause', 'stop', 'setCurrentTime', 'requestFullscreen', 'exitFullscreen', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'video' }, { - 'methods': ['setNextButtonStatus', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['setNextButtonStatus', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'stepper' }, { - 'methods': ['focus', 'animate', 'delete', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['focus', 'addChild', 'animate', 'delete', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'textarea' }, - {'methods': ['reload', 'createIntersectionObserver'], 'type': 'web'}, + {'methods': ['reload', 'createIntersectionObserver', 'addChild'], 'type': 'web'}, { - 'methods': ['takePhoto', 'startRecorder', 'closeRecorder', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['takePhoto', 'startRecorder', 'closeRecorder', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'camera' } ]; diff --git a/runtime/utils/index.ts b/runtime/utils/index.ts index b865879e..e5fcaf3f 100644 --- a/runtime/utils/index.ts +++ b/runtime/utils/index.ts @@ -30,7 +30,8 @@ export { remove, hasOwn, isObject, - isPlainObject + isPlainObject, + bufferToBase64 } from '../main/util/shared'; export { diff --git a/runtime/vdom/DocumentElement.ts b/runtime/vdom/DocumentElement.ts index 5b8f4c7f..976355bb 100644 --- a/runtime/vdom/DocumentElement.ts +++ b/runtime/vdom/DocumentElement.ts @@ -74,7 +74,9 @@ class DocumentElement extends Element { element.docId = document.id; element.ownerDocument = document; this.linkChild(this); - delete this.ownerDocument.nodeMap[element.nodeId]; + if (this.ownerDocument) { + delete this.ownerDocument.nodeMap[element.nodeId]; + } } this.pureChildren.push(element); this.ownerDocument.sentBodyToNative(element); diff --git a/runtime/vdom/Element.ts b/runtime/vdom/Element.ts index 29cf4b3c..0ffac2d4 100644 --- a/runtime/vdom/Element.ts +++ b/runtime/vdom/Element.ts @@ -26,13 +26,17 @@ import Node from './Node'; import NativeElementClassFactory from './NativeElementClassFactory'; import Document from './Document'; import { TaskCenter } from '../main/manage/event/TaskCenter'; -import { FragBlockInterface } from '../main/model/compiler'; +import { FragBlockInterface, + TemplateInterface, + compileCustomComponent, + targetIsComposed +} from '../main/model/compiler'; import Vm from '../main/model'; import { CSS_INHERITANCE } from '../main/app/bundle'; -import { interceptCallback } from '../main/manage/event/callbackIntercept'; -import { mockwebgl } from '../main/extend/systemplugin/napi/webgl'; -import { mockwebgl2 } from '../main/extend/systemplugin/napi/webgl2'; - +import {interceptCallback} from '../main/manage/event/callbackIntercept'; +import {mockwebgl} from '../main/extend/systemplugin/napi/webgl'; +import {mockwebgl2} from '../main/extend/systemplugin/napi/webgl2'; +import { VmOptions } from '../main/model/vmOptions'; /** * Element is a basic class to describe a tree node in vdom. * @extends Node @@ -43,18 +47,21 @@ class Element extends Node { private _event: any; private _idStyle: any; private _tagStyle: any; + private _universalStyle: any; private _id: string | null; private _classList: any[]; private _block: FragBlockInterface; private _vm: Vm; private _isCustomComponent: boolean; private _inheritedStyle: object; + private _target:TemplateInterface; protected _children: Node[]; protected _pureChildren: Element[]; protected _role: string; protected _attr: any; protected _dataSet: any; + protected _isFirstDyanmicName: boolean; constructor(type = 'div', props:any = {}, isExtended: boolean = false) { super(); @@ -97,6 +104,7 @@ class Element extends Node { this._event = {}; this._idStyle = {}; this._tagStyle = {}; + this._universalStyle = {}; this._id = null; this._classList = []; this._children = []; @@ -104,6 +112,7 @@ class Element extends Node { this._isCustomComponent = false; this._inheritedStyle = {}; this._dataSet = {}; + this._isFirstDyanmicName = true; } /** @@ -163,13 +172,21 @@ class Element extends Node { } /** - * Style object of this Element, which keys is style name, and values is style values. + * Class style object of this Element, which keys is style name, and values is style values. * @type {JSON} */ public get classStyle() { return this._classStyle; } + /** + * Id style object of this Element, which keys is style name, and values is style values. + * @type {JSON} + */ + public get idStyle() { + return this._idStyle; + } + /** * Block in this Element. * @type {FragBlock} @@ -266,6 +283,18 @@ class Element extends Node { return this._style; } + /** + * target object of this Element. + * @type {Object} + */ + public set target(target: TemplateInterface) { + this._target = target; + } + + public get target() { + return this._target; + } + /** * Get TaskCenter instance by id. * @param {string} id @@ -288,7 +317,9 @@ class Element extends Node { if (this._docId) { child.docId = this._docId; child.ownerDocument = this._ownerDocument; - child.ownerDocument.nodeMap[child.nodeId] = child; + if (child.ownerDocument) { + child.ownerDocument.nodeMap[child.nodeId] = child; + } child.depth = this._depth + 1; } if (child.nodeType === Node.NodeType.Element) { @@ -656,6 +687,26 @@ class Element extends Node { result[key] = value; taskCenter.send('dom', { action: 'updateAttrs' }, [this.ref, result]); } + + if (this._type === 'compontent' && key === 'name') { + if (this._isFirstDyanmicName === true) { + Log.info('compontent first setAttr name = ' + value); + this._isFirstDyanmicName = false; + } else { + Log.info('compontent second setAttr name,' + value); + if (taskCenter) { + const node = this._nextSibling; + taskCenter.send('dom', { action: 'removeElement' }, [node.ref]); + } + const parentNode = this._parentNode as Element; + const component: VmOptions | null = targetIsComposed(this._vm, value.toString()); + const meta = {}; + if (component) { + compileCustomComponent(this._vm, component, this._target, parentNode, value.toString(), meta); + return; + } + } + } } /** @@ -732,9 +783,7 @@ class Element extends Node { this._idStyle[key] = value; const taskCenter = this.getTaskCenter(this.docId); if (!silent && taskCenter) { - const result = {}; - result[key] = value; - taskCenter.send('dom', { action: 'updateStyle' }, [this.ref, result]); + taskCenter.send('dom', { action: 'updateStyle' }, [this.ref, this._idStyle]); if (CSS_INHERITANCE.includes(key)) { this.broadcastStyle(); } @@ -764,6 +813,24 @@ class Element extends Node { } } + public setUniversalStyle(key: string, value: string | number, silent: boolean = false): void { + if (this._universalStyle[key] === value && silent !== false) { + return; + } + // If inline id class style has define return. + if (this.style[key] || this._idStyle[key] || this._classStyle[key] || this._tagStyle[key]) { + return; + } + this._universalStyle[key] = value; + const taskCenter = this.getTaskCenter(this.docId); + if (!silent && taskCenter) { + const result = {}; + result[key] = value; + taskCenter.send('dom', { action: 'updateStyle' }, [this.ref, result]); + } + + } + /** * Add an event handler. * @param {string} type - Event name. @@ -853,6 +920,7 @@ class Element extends Node { public toStyle(): any { // Selector Specificity inline > #id > .class > tag > inheritance. const style = Object.assign({}, this._inheritedStyle); + this.assignStyle(style, this._universalStyle); this.assignStyle(style, this._tagStyle); this.assignStyle(style, this._classStyle); this.assignStyle(style, this._idStyle); @@ -956,6 +1024,7 @@ class Element extends Node { this._event = {}; this._idStyle = {}; this._tagStyle = {}; + this._universalStyle = {}; this._classList.length = 0; if (this.destroyHook) { @@ -1057,7 +1126,9 @@ class Element extends Node { private registerNode(node) { const doc = this._ownerDocument; - doc.nodeMap[node.nodeId] = node; + if (doc) { + doc.nodeMap[node.nodeId] = node; + } } } diff --git a/test/ut/manage/bridge.ts b/test/ut/manage/bridge.ts index ef9f74fb..166a3a23 100644 --- a/test/ut/manage/bridge.ts +++ b/test/ut/manage/bridge.ts @@ -45,7 +45,7 @@ describe('receiveTasks', () => { 'aspect-ratio': 'string', 'device-width': '1176', 'device-height': '2400', - roundScreen: false, + 'round-screen': false, width: '0', height: '0', isInit: true, diff --git a/test/ut/model/directive.ts b/test/ut/model/directive.ts index dd7659de..645da690 100644 --- a/test/ut/model/directive.ts +++ b/test/ut/model/directive.ts @@ -30,7 +30,8 @@ import { } from '../../fakeLog'; import { bindSubVm, - bindSubVmAfterInitialized + bindSubVmAfterInitialized, + setAttr } from '../../../runtime/main/model/directive'; import { initState } from '../../../runtime/main/reactivity/state'; import config from '../../../runtime/main/config'; @@ -97,7 +98,7 @@ describe('bind external infomations to sub vm', () => { b: String } }, - props: [] + _props: [] }; }); @@ -112,7 +113,7 @@ describe('bind external infomations to sub vm', () => { }, {}); expect(subVm.a).eql(3); expect(subVm.b).to.be.undefined; - expect(subVm.rootEl).to.be.undefined; + expect(subVm._rootEl).to.be.undefined; }); it('bind props with external data', () => { @@ -126,7 +127,7 @@ describe('bind external infomations to sub vm', () => { }); it('bind styles to a sub vm with root element', () => { - subVm.rootEl = { + subVm._rootEl = { attr: {}, style: {}, event: [] @@ -136,14 +137,161 @@ describe('bind external infomations to sub vm', () => { return this.data.a; } } }; - initElement(subVm.rootEl); + initElement(subVm._rootEl); bindSubVm(vm, subVm, template, {}); // @ts-ignore bindSubVmAfterInitialized(vm, subVm, template, {}); - expect(subVm.rootEl.style.aaa).eql(2); - expect(subVm.rootEl.style.bbb).eql(1); + expect(subVm._rootEl.style.aaa).eql(2); + expect(subVm._rootEl.style.bbb).eql(1); }); fakeLogRestore(); }); + +/* +1. api 7 data* ->$data set to dataset ,data ->data data set to attr; +2. api 6 data* -> data set to dataset,data -> data set to attr(data and data* are not compatible ar compile time); +3. api 5 data -> data set to attr. +*/ +describe('set $data and data to element to check API 7 scene', () => { + fakeLog(); + + let vm: any; + let attr1: any; + let attr2: any; + let element: any + let SETTERS = { + attr: 'setAttr', + data: 'setData', + $data: 'setData' + } + + before(() => { + vm = { + __data: { c: '333', d: '444'}, + _watchers: [], + }; + attr1 = { + data: '111', + $data: { b: '222' } + }; + attr2 = { + data: function () {return vm.__data.c}, + $data: { url: function () {return vm.__data.d} } + }; + element = { + dataSet: {}, + attr: {}, + watchers: [], + setData: function setData(key: string, value: string): void { + this.dataSet[key] = value; + }, + setAttr: function(key: string, value: string | number): void { + if (this.attr[key] === value) { + return; + } + this.attr[key] = value; + } + }; + }); + + it('set data and $data to element', () => { + setAttr(vm, element, attr1) + expect(element.attr.data).eql('111'); + expect(element.dataSet.b).eql('222'); + }) + + it('set data and $data which is function to element', () => { + setAttr(vm, element, attr2) + expect(element.attr.data).eql('333'); + expect(element.dataSet.url).eql('444'); + }) + + fakeLogRestore(); +}); + +describe('set data and data* to element to check API 6 scene', () => { + fakeLog(); + + let vm: any; + let attr1: any; + let attr2: any; + let element: any + let SETTERS = { + attr: 'setAttr', + data: 'setData' + } + + before(() => { + vm = {}; + attr1 = { + data: '111' + }; + attr2 = { + data: { url: '222'} + }; + element = { + dataSet: {}, + attr: {}, + setData: function setData(key: string, value: string): void { + this.dataSet[key] = value; + }, + setAttr: function(key: string, value: string | number): void { + if (this.attr[key] === value) { + return; + } + this.attr[key] = value; + } + }; + }); + + it('set data to element', () => { + setAttr(vm, element, attr1) + expect(element.attr.data).eql('111'); + }) + + it('set data* to element', () => { + setAttr(vm, element, attr2) + expect(element.dataSet.url).eql('222'); + }) + + fakeLogRestore(); +}); + +describe('set data only to element attr to to check API 5 scene', () => { + fakeLog(); + + let vm: any; + let attr: any; + let element: any + let SETTERS = { + attr: 'setAttr', + data: 'setData' + } + + before(() => { + vm = {}; + attr = { + data: '111' + }; + element = { + dataSet: {}, + attr: {}, + setData: function setData() {}, + setAttr: function(key: string, value: string | number): void { + if (this.attr[key] === value) { + return; + } + this.attr[key] = value; + } + }; + }); + + it('set data to element', () => { + setAttr(vm, element, attr) + expect(element.attr.data).eql('111'); + }) + + fakeLogRestore(); +}); \ No newline at end of file diff --git a/test/ut/model/index.ts b/test/ut/model/index.ts index 5195282c..eec93c24 100644 --- a/test/ut/model/index.ts +++ b/test/ut/model/index.ts @@ -40,9 +40,9 @@ describe('api of communication between vm and data methods', () => { orientation: 1, width: 1, height: 1, - aspectRatio: 1, - deviceWidth: 1, - deviceHeight: 1, + 'aspect-ratio': 1, + 'device-width': 1, + 'device-height': 1, resolution: 1, accessType: 1 }; @@ -87,8 +87,8 @@ describe('api of communication between vm and data methods', () => { 'parent', null, { - _app: page, - _rootVm: true + __app: page, + __rootVm: true }, null, null, @@ -97,24 +97,24 @@ describe('api of communication between vm and data methods', () => { const spyParent = sinon.spy(); const spyChild = sinon.spy(); - const subVm = vm.childrenVms[0]; + const subVm = vm._childrenVms[0]; vm.$on('event1', spyParent); subVm.$on('event1', spyChild); it('$on && $off', () => { const fn = function() {}; vm.$on('event1', fn); - expect(vm.vmEvents['event1'].length).eql(2); - expect(typeof vm.vmEvents['event1'][1]).eql('function'); + expect(vm._vmEvents['event1'].length).eql(2); + expect(typeof vm._vmEvents['event1'][1]).eql('function'); vm.$off('event1', fn); - expect(vm.vmEvents['event1'].length).eql(1); - expect(typeof vm.vmEvents['event1'][1]).eql('undefined'); + expect(vm._vmEvents['event1'].length).eql(1); + expect(typeof vm._vmEvents['event1'][1]).eql('undefined'); }); it('$emit', () => { - expect(vm.type).eql('parent'); - expect(subVm.type).eql('child'); + expect(vm._type).eql('parent'); + expect(subVm._type).eql('child'); let detail = { lunch: 'banana' }; vm.$emit('event1', detail); @@ -164,15 +164,15 @@ describe('api of communication between vm and data methods', () => { }); it('$root', () => { - expect(subVm.$root().type).eql('parent'); + expect(subVm.$root()._type).eql('parent'); }); it('$parent', () => { - expect(subVm.$parent().type).eql('parent'); + expect(subVm.$parent()._type).eql('parent'); }); it('$child', () => { - expect(vm.$child('myChild').type).eql('child'); + expect(vm.$child('myChild')._type).eql('child'); }); it('$element', () => { @@ -199,13 +199,13 @@ describe('api of communication between vm and data methods', () => { }; const app = { doc, customComponentMap, differ, options }; - const vm = new Vm('foo', customComponentMap.foo, { _app: app, _rootVm: true }, null, data, null); + const vm = new Vm('foo', customComponentMap.foo, { __app: app, __rootVm: true }, null, data, null); doc.destroy(); const detail = { aaa: 1 }; vm.$set('test.aaa', detail); - expect(typeof vm.__data['test.aaa']).eql('object'); + expect(typeof vm._data['test.aaa']).eql('object'); vm.$delete('test.aaa'); - expect(typeof vm.__data['test.aaa']).eql('undefined'); + expect(typeof vm._data['test.aaa']).eql('undefined'); }); it('$watch', () => { @@ -222,8 +222,8 @@ describe('api of communication between vm and data methods', () => { }; const app = { doc, customComponentMap, differ, options }; - const vm = new Vm('foo', customComponentMap.foo, { _app: app, _rootVm: true }, null, data, null); - expect(vm.app).to.deep.equal(app); + const vm = new Vm('foo', customComponentMap.foo, { __app: app, __rootVm: true }, null, data, null); + expect(vm._app).to.deep.equal(app); expect(typeof doc.body).eql('object'); data.x.y = 5; diff --git a/test/ut/runtime.ts b/test/ut/runtime.ts index 7bfe22f2..f43da5b0 100644 --- a/test/ut/runtime.ts +++ b/test/ut/runtime.ts @@ -54,16 +54,16 @@ describe('framework entry', () => { let instanceId; const options = { orientation: 'portrait', - deviceType: 'phone', + 'device-type': 'phone', resolution: '3.0', - aspectRatio: 'string', - deviceWidth: '1176', - deviceHeight: '2400', - roundScreen: false, + 'aspect-ratio': 'string', + 'device-width': '1176', + 'device-height': '2400', + 'round-screen': false, width: '0', height: '0', isInit: true, - darkMode: 'false', + 'dark-mode': 'false', pcPreview: 'disable', appInstanceId: '10002', packageName: 'com.example.helloworld',