From 96c58190aa4b558495be18d963727fb74eb3b19c Mon Sep 17 00:00:00 2001 From: xpeng Date: Sat, 6 Aug 2022 16:58:23 +0800 Subject: [PATCH 1/2] 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() { From 7c1fba0764791e9432554ef8b6dc5dc1ccadb791 Mon Sep 17 00:00:00 2001 From: xpeng Date: Mon, 8 Aug 2022 10:47:38 +0800 Subject: [PATCH 2/2] update review comments Signed-off-by: xpeng Change-Id: Ia302f91154c15e2a95273cd5fa224f52130d896c --- .../extend/systemplugin/napi/ohos_display.js | 95 +++++++++---------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/runtime/main/extend/systemplugin/napi/ohos_display.js b/runtime/main/extend/systemplugin/napi/ohos_display.js index c6d7ff2c..c6ab2df2 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_display.js +++ b/runtime/main/extend/systemplugin/napi/ohos_display.js @@ -30,59 +30,54 @@ 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 function mockDisplay() { + const Rect = { + left: '[PC preview] unknow left', + top: '[PC preview] unknow top', + width: '[PC preview] unknow width', + height: '[PC preview] unknow height', + } + + const WaterfallDisplayAreaRects = { + left: Rect, + top: Rect, + width: Rect, + height: Rect + } -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', - alive: '[PC preview] unknow alive', - state: DisplayState, - refreshRate: '[PC preview] unknow refreshRate', - rotation: '[PC preview] unknow rotation', - width: '[PC preview] unknow width', - height: '[PC preview] unknow height', - densityDPI: '[PC preview] unknow densityDPI', - densityPixels: '[PC preview] unknow densityPixels', - scaledDensity: '[PC preview] unknow scaledDensity', - xDPI: '[PC preview] unknow xDPI', - 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); - }); + const CutoutInfo = { + boundingRects: Array(Rect), + waterfallDisplayAreaRects: WaterfallDisplayAreaRects + } + + const Display = { + id: '[PC preview] unknow id', + name: '[PC preview] unknow name', + alive: '[PC preview] unknow alive', + state: DisplayState, + refreshRate: '[PC preview] unknow refreshRate', + rotation: '[PC preview] unknow rotation', + width: '[PC preview] unknow width', + height: '[PC preview] unknow height', + densityDPI: '[PC preview] unknow densityDPI', + densityPixels: '[PC preview] unknow densityPixels', + scaledDensity: '[PC preview] unknow scaledDensity', + xDPI: '[PC preview] unknow xDPI', + 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() { - + const display = { getDefaultDisplay: function (...args) { console.warn("Display.getDefaultDisplay interface mocked in the Previewer. How this interface works on the" +