From 96c58190aa4b558495be18d963727fb74eb3b19c Mon Sep 17 00:00:00 2001 From: xpeng Date: Sat, 6 Aug 2022 16:58:23 +0800 Subject: [PATCH] add mock for getCutoutInfo Signed-off-by: xpeng Change-Id: I2ff8847d1cb9a04acbfdd3d5779cd6a507f0d0df --- .../extend/systemplugin/napi/ohos_display.js | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/runtime/main/extend/systemplugin/napi/ohos_display.js b/runtime/main/extend/systemplugin/napi/ohos_display.js index a4673244..c6d7ff2c 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_display.js +++ b/runtime/main/extend/systemplugin/napi/ohos_display.js @@ -30,6 +30,29 @@ const DisplayType = { change: 'change' } +export const Rect = { + left: '[PC preview] unknow left', + top: '[PC preview] unknow top', + width: '[PC preview] unknow width', + height: '[PC preview] unknow height', +} + +export const WaterfallDisplayAreaRects = { + left: Rect, + top: Rect, + width: Rect, + height: Rect +} + +export const allBoudingRectsMock = [ + Rect +] + +export const CutoutInfo = { + boundingRects: allBoudingRectsMock, + waterfallDisplayAreaRects: WaterfallDisplayAreaRects +} + export const Display = { id: '[PC preview] unknow id', name: '[PC preview] unknow name', @@ -43,7 +66,19 @@ export const Display = { densityPixels: '[PC preview] unknow densityPixels', scaledDensity: '[PC preview] unknow scaledDensity', xDPI: '[PC preview] unknow xDPI', - yDPI: '[PC preview] unknow yDPI' + yDPI: '[PC preview] unknow yDPI', + getCutoutInfo: function(...args) { + console.warn('Display.getCutoutInfo interface mocked 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, CutoutInfo); + } else { + return new Promise((resolve) => { + resolve(CutoutInfo); + }); + } + } } export function mockDisplay() {