1import { paramMock } from "./utils" 2 3export function mockAbilityFeatureAbility() { 4 global.systemplugin.ability = {} 5 const WantMock = { 6 deviceId: "[PC Preview] unknow deviceId", 7 bundleName: "[PC Preview] unknow bundleName", 8 abilityName: "[PC Preview] unknow abilityName", 9 uri: "[PC Preview] unknow uri", 10 type: "[PC Preview] unknow type", 11 flag: "[PC Preview] unknow flag", 12 action: "[PC Preview] unknow action", 13 parameters: "[PC Preview] unknow parameters", 14 entities: "[PC Preview] unknow entities" 15 } 16 const AbilityResultMock = { 17 resultCode: "[PC Preview] unknow resultCode", 18 want: WantMock 19 } 20 const DataAbilityHelperMock = { 21 openFile: function (...args) { 22 console.warn("DataAbilityHelper.openFile interface mocked in the Previewer. How this interface works on the Previewer" + 23 " may be different from that on a real device.") 24 const len = args.length 25 if (typeof args[len - 1] === 'function') { 26 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 27 } else { 28 return new Promise((resolve, reject) => { 29 resolve(paramMock.paramNumberMock); 30 }) 31 } 32 }, 33 on: function (...args) { 34 console.warn("DataAbilityHelper.on interface mocked in the Previewer. How this interface works on the Previewer" + 35 " may be different from that on a real device.") 36 const len = args.length 37 if (typeof args[len - 1] === 'function') { 38 args[len - 1].call(this, paramMock.businessErrorMock) 39 } 40 }, 41 off: function (...args) { 42 console.warn("DataAbilityHelper.off interface mocked in the Previewer. How this interface works on the Previewer" + 43 " may be different from that on a real device.") 44 const len = args.length 45 if (typeof args[len - 1] === 'function') { 46 args[len - 1].call(this, paramMock.businessErrorMock) 47 } 48 }, 49 call: function (...args) { 50 console.warn("DataAbilityHelper.call interface mocked in the Previewer. How this interface works on the Previewer" + 51 " may be different from that on a real device.") 52 const len = args.length 53 if (typeof args[len - 1] === 'function') { 54 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock) 55 } else { 56 return new Promise((resolve, reject) => { 57 resolve(paramMock.paramObjectMock); 58 }) 59 } 60 } 61 } 62 const ContextMock = { 63 getCacheDir: function (...args) { 64 console.warn("Context.getCacheDir interface mocked in the Previewer. How this interface works on the Previewer" + 65 " may be different from that on a real device.") 66 const len = args.length 67 if (typeof args[len - 1] === 'function') { 68 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 69 } else { 70 return new Promise((resolve) => { 71 resolve("[PC Preview] unknow string") 72 }) 73 } 74 }, 75 getFilesDir: function (...args) { 76 console.warn("Context.getFilesDir interface mocked in the Previewer. How this interface works on the Previewer" + 77 " may be different from that on a real device.") 78 const len = args.length 79 if (typeof args[len - 1] === 'function') { 80 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 81 } else { 82 return new Promise((resolve) => { 83 resolve("[PC Preview] unknow string") 84 }) 85 } 86 }, 87 getExternalCacheDir: function (...args) { 88 console.warn("Context.getExternalCacheDir interface mocked in the Previewer. How this interface works on the" + 89 " Previewer may be different from that on a real device.") 90 const len = args.length 91 if (typeof args[len - 1] === 'function') { 92 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 93 } else { 94 return new Promise((resolve) => { 95 resolve("[PC Preview] unknow string") 96 }) 97 } 98 } 99 } 100 global.systemplugin.ability.featureAbility = { 101 getWant: function (...args) { 102 console.warn("ability.featureAbility.getWant interface mocked in the Previewer. How this interface works on" + 103 " the Previewer may be different from that on a real device.") 104 const len = args.length 105 if (typeof args[len - 1] === 'function') { 106 args[len - 1].call(this, paramMock.businessErrorMock, WantMock) 107 } else { 108 return new Promise((resolve) => { 109 resolve(WantMock) 110 }) 111 } 112 }, 113 startAbility: function (...args) { 114 console.warn("ability.featureAbility.startAbility interface mocked in the Previewer. How this interface works" + 115 " on the Previewer may be different from that on a real device.") 116 const len = args.length 117 if (typeof args[len - 1] === 'function') { 118 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 119 } else { 120 return new Promise((resolve) => { 121 resolve(paramMock.paramNumberMock) 122 }) 123 } 124 }, 125 startAbilityForResult: function (...args) { 126 console.warn("ability.featureAbility.startAbilityForResult interface mocked in the Previewer. How this interface works" + 127 " on the Previewer may be different from that on a real device.") 128 const len = args.length 129 if (typeof args[len - 1] === 'function') { 130 args[len - 1].call(this, paramMock.businessErrorMock, AbilityResultMock) 131 } else { 132 return new Promise((resolve) => { 133 resolve(AbilityResultMock) 134 }) 135 } 136 }, 137 terminateSelfWithResult: function (...args) { 138 console.warn("ability.featureAbility.terminateSelfWithResult interface mocked in the Previewer. How this interface works" + 139 " on the Previewer may be different from that on a real device.") 140 const len = args.length 141 if (typeof args[len - 1] === 'function') { 142 args[len - 1].call(this, paramMock.businessErrorMock) 143 } else { 144 return new Promise((resolve) => { 145 resolve() 146 }) 147 } 148 }, 149 terminateSelf: function (...args) { 150 console.warn("ability.featureAbility.terminateSelf interface mocked in the Previewer. How this interface works on" + 151 " the Previewer may be different from that on a real device.") 152 const len = args.length 153 if (typeof args[len - 1] === 'function') { 154 args[len - 1].call(this) 155 } else { 156 return new Promise((resolve) => { 157 resolve() 158 }) 159 } 160 }, 161 acquireDataAbilityHelper: function (...args) { 162 console.warn("ability.featureAbility.acquireDataAbilityHelper mocked in the Previewer. How this interface works on the Previewer may be" + 163 " different from that on a real device.") 164 return DataAbilityHelperMock; 165 }, 166 getContext: function () { 167 console.warn("ability.featureAbility.getContext interface mocked in the Previewer. How this interface works on" + 168 " the Previewer may be different from that on a real device.") 169 return ContextMock; 170 } 171 } 172} 173export function mockAbilityParticleAbility() { 174 global.systemplugin.ability.particleAbility = { 175 startAbility: function (...args) { 176 console.warn("ability.particleAbility.startAbility interface mocked in the Previewer. How this interface works" + 177 " on the Previewer may be different from that on a real device.") 178 const len = args.length 179 if (typeof args[len - 1] === 'function') { 180 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 181 } else { 182 return new Promise((resolve) => { 183 resolve(paramMock.paramNumberMock) 184 }) 185 } 186 } 187 } 188} 189export function mockAbilityFormManager() { 190 const FormInfoMock = { 191 bundleName: "[PC Preview] unknow bundleName", 192 moduleName: "[PC Preview] unknow moduleName", 193 abilityName: "[PC Preview] unknow abilityName", 194 name: "[PC Preview] unknow name", 195 description: "[PC Preview] unknow description", 196 type: "[PC Preview] unknow type", 197 jsComponentName: "[PC Preview] unknow jsComponentName", 198 colorMode: "[PC Preview] unknow colorMode", 199 isDefault: "[PC Preview] unknow isDefault", 200 updateEnabled: "[PC Preview] unknow updateEnabled", 201 formVisibleNotify: "[PC Preview] unknow formVisibleNotify", 202 relatedBundleName: "[PC Preview] unknow relatedBundleName", 203 scheduledUpdateTime: "[PC Preview] unknow scheduledUpdateTime", 204 formConfigAbility: "[PC Preview] unknow formConfigAbility", 205 updateDuration: "[PC Preview] unknow updateDuration", 206 defaultDimension: "[PC Preview] unknow defaultDimension", 207 supportDimensions: "[PC Preview] unknow supportDimensions", 208 customizeDatas: "[PC Preview] unknow customizeDatas", 209 jsonObject: "[PC Preview] unknow jsonObject" 210 } 211 const FormInfoArrayMock = [ 212 FormInfoMock 213 ] 214 global.systemplugin.ability.formManager = { 215 requestForm: function (...args) { 216 console.warn("ability.formManager.requestForm interface mocked in the Previewer. How this interface works" + 217 " on the Previewer may be different from that on a real device.") 218 const len = args.length 219 if (typeof args[len - 1] === 'function') { 220 args[len - 1].call(this, paramMock.businessErrorMock) 221 } else { 222 return new Promise((resolve) => { 223 resolve() 224 }) 225 } 226 }, 227 deleteForm: function (...args) { 228 console.warn("ability.formManager.deleteForm interface mocked in the Previewer. How this interface works" + 229 " on the Previewer may be different from that on a real device.") 230 const len = args.length 231 if (typeof args[len - 1] === 'function') { 232 args[len - 1].call(this, paramMock.businessErrorMock) 233 } else { 234 return new Promise((resolve) => { 235 resolve() 236 }) 237 } 238 }, 239 releaseForm: function (...args) { 240 console.warn("ability.formManager.releaseForm interface mocked in the Previewer. How this interface works on the Previewer may" + 241 " be different from that on a real device.") 242 const len = args.length 243 if (typeof args[len - 1] === 'function') { 244 args[len - 1].call(this, paramMock.businessErrorMock); 245 } else { 246 return new Promise((resolve) => { 247 resolve() 248 }) 249 } 250 }, 251 notifyVisibleForms: function (...args) { 252 console.warn("ability.formManager.notifyVisibleForms interface mocked in the Previewer. How this interface works" + 253 " on the Previewer may be different from that on a real device.") 254 const len = args.length 255 if (typeof args[len - 1] === 'function') { 256 args[len - 1].call(this, paramMock.businessErrorMock) 257 } else { 258 return new Promise((resolve) => { 259 resolve() 260 }) 261 } 262 }, 263 notifyInvisibleForms: function (...args) { 264 console.warn("ability.formManager.notifyInvisibleForms interface mocked in the Previewer. How this interface works" + 265 " on the Previewer may be different from that on a real device.") 266 const len = args.length 267 if (typeof args[len - 1] === 'function') { 268 args[len - 1].call(this, paramMock.businessErrorMock) 269 } else { 270 return new Promise((resolve) => { 271 resolve() 272 }) 273 } 274 }, 275 enableFormsUpdate: function (...args) { 276 console.warn("ability.formManager.enableFormsUpdate interface mocked in the Previewer. How this interface works" + 277 " on the Previewer may be different from that on a real device.") 278 const len = args.length 279 if (typeof args[len - 1] === 'function') { 280 args[len - 1].call(this, paramMock.businessErrorMock) 281 } else { 282 return new Promise((resolve) => { 283 resolve() 284 }) 285 } 286 }, 287 disableFormsUpdate: function (...args) { 288 console.warn("ability.formManager.disableFormsUpdate interface mocked in the Previewer. How this interface works" + 289 " on the Previewer may be different from that on a real device.") 290 const len = args.length 291 if (typeof args[len - 1] === 'function') { 292 args[len - 1].call(this, paramMock.businessErrorMock) 293 } else { 294 return new Promise((resolve) => { 295 resolve() 296 }) 297 } 298 }, 299 getAllFormsInfo: function (...args) { 300 console.warn("ability.formManager.getAllFormsInfo interface mocked in the Previewer. How this interface works" + 301 " on the Previewer may be different from that on a real device.") 302 const len = args.length 303 if (typeof args[len - 1] === 'function') { 304 args[len - 1].call(this, paramMock.businessErrorMock, FormInfoArrayMock) 305 } else { 306 return new Promise((resolve) => { 307 resolve(FormInfoArrayMock) 308 }) 309 } 310 }, 311 getFormsInfoByApp: function (...args) { 312 console.warn("ability.formManager.getFormsInfoByApp interface mocked in the Previewer. How this interface works" + 313 " on the Previewer may be different from that on a real device.") 314 const len = args.length 315 if (typeof args[len - 1] === 'function') { 316 args[len - 1].call(this, paramMock.businessErrorMock, FormInfoArrayMock) 317 } else { 318 return new Promise((resolve) => { 319 resolve(FormInfoArrayMock) 320 }) 321 } 322 }, 323 getFormsInfoByModule: function (...args) { 324 console.warn("ability.formManager.getFormsInfoByModule interface mocked in the Previewer. How this interface works" + 325 " on the Previewer may be different from that on a real device.") 326 const len = args.length 327 if (typeof args[len - 1] === 'function') { 328 args[len - 1].call(this, paramMock.businessErrorMock, FormInfoArrayMock) 329 } else { 330 return new Promise((resolve) => { 331 resolve(FormInfoArrayMock) 332 }) 333 } 334 } 335 } 336}