From 398415f88ec21ba5df35e7daa676e581fd82d0c4 Mon Sep 17 00:00:00 2001 From: zhangxingxia Date: Thu, 14 Jul 2022 09:19:19 +0800 Subject: [PATCH] update jsmock Signed-off-by: zhangxingxia --- .../main/extend/systemplugin/napi/index.js | 5 +- .../systemplugin/napi/ohos_fileManager.js | 16 +++++-- .../systemplugin/napi/ohos_securitylabel.js | 46 ------------------- 3 files changed, 13 insertions(+), 54 deletions(-) delete mode 100644 runtime/main/extend/systemplugin/napi/ohos_securitylabel.js diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 3d162e22..0ac50157 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -74,7 +74,6 @@ import { mockAbilityAccessCtrl } from './ohos_abilityAccessCtrl' import { mockConfigPolicy } from './ohos_configPolicy' import { mockUpdate } from './ohos_update' import { mockBackgroundTaskManager } from './ohos_backgroundTaskManager' -import { mockSecurityLabel } from './ohos_securitylabel' import { mockWorkScheduler } from './ohos_workScheduler' import { mockWorkSchedulerExtensionAbility } from './ohos_WorkSchedulerExtensionAbility' import { mockUserAuth } from './ohos_userIAM_userAuth' @@ -342,7 +341,7 @@ export function mockRequireNapiFun() { return mockConvertXml(); case "statfs": return mockStatfs(); - case "filemanager": + case "fileManager": return mockFileManager(); case "environment": return mockEnvironment(); @@ -360,8 +359,6 @@ export function mockRequireNapiFun() { return mockUpdate(); case "backgroundTaskManager": return mockBackgroundTaskManager(); - case "securitylabel": - return mockSecurityLabel(); case "workScheduler": return mockWorkScheduler(); case "WorkSchedulerExtensionAbility": diff --git a/runtime/main/extend/systemplugin/napi/ohos_fileManager.js b/runtime/main/extend/systemplugin/napi/ohos_fileManager.js index f06e905c..47ae70a4 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_fileManager.js +++ b/runtime/main/extend/systemplugin/napi/ohos_fileManager.js @@ -16,16 +16,24 @@ import { paramMock } from "../utils" export function mockFileManager() { + const fileInfoMock = { + name: '[PC preview] unknow name', + path: '[PC preview] unknow path', + type: '[PC preview] unknow type', + size: '[PC preview] unknow size', + addedTime: '[PC preview] unknow addedTime', + modifiedTime: '[PC preview] unknow modifiedTime', + }; const filemanager = { getRoot: function (...args) { console.warn("filemanager.getRoot interface mocked 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.paramArrayMock) + args[len - 1].call(this, paramMock.businessErrorMock, Array(fileInfoMock)) } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); + resolve(Array(fileInfoMock)); }) } }, @@ -34,10 +42,10 @@ export function mockFileManager() { " Previewer may be 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.paramArrayMock) + args[len - 1].call(this, paramMock.businessErrorMock, Array(fileInfoMock)) } else { return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); + resolve(Array(fileInfoMock)); }) } }, diff --git a/runtime/main/extend/systemplugin/napi/ohos_securitylabel.js b/runtime/main/extend/systemplugin/napi/ohos_securitylabel.js deleted file mode 100644 index 3189193f..00000000 --- a/runtime/main/extend/systemplugin/napi/ohos_securitylabel.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { paramMock } from "../utils" - -export function mockSecurityLabel() { - const securitylabel = { - setSecurityLabel: function (...args) { - console.warn("securitylabel.setSecurityLabel interface mocked 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(); - }) - } - }, - getSecurityLabel: function (...args) { - console.warn("securitylabel.getSecurityLabel interface mocked 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); - }) - } - }, - } - return securitylabel; -}