From 06c7bd1e2eb58c07884ba6166724e0f21c3100db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E=E5=8D=8E=E5=B0=8F=E4=BB=99=E5=A5=B3?= Date: Wed, 30 Nov 2022 16:53:59 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96displayAndWindowRefactorInt?= =?UTF-8?q?erface.test=E7=94=A8=E4=BE=8BsetWindowModeTest2=20=202=E3=80=81?= =?UTF-8?q?=E8=A1=A5=E5=85=85callback=E7=94=A8=E4=BE=8BcreateTest5?= =?UTF-8?q?=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 华华小仙女 --- ...displayAndWindowRefactorInterface.test.ets | 2044 +++++++++++++++ .../src/main/ets/test/windowCallback.test.ets | 2202 +++++++++++++++++ 2 files changed, 4246 insertions(+) create mode 100644 graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets create mode 100644 graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets diff --git a/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets b/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets new file mode 100644 index 000000000..60e1a470e --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets @@ -0,0 +1,2044 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" +import ohosWindow from '@ohos.window'; +import screenManager from '@ohos.screen'; +import display from '@ohos.display'; + +export default function displayAndWindowRefactorInterfaceTest(context, windowStage, abilityStorage) { + console.log('windowTest context: ' + JSON.stringify(context)) + console.log('windowTest abilityStorage: ' + JSON.stringify(abilityStorage)) + describe('displayAndWindowRefactorInterface_test', function () { + console.log('describe window_api_test3 start!!!') + const TRUE_FLAG = true; + var appWindowTypeArr = []; + var windowTypeArr = []; + var appWindowTypeDic = { + 'TYPE_BASE': 0, + 'TYPE_APP': 0, + 'TYPE_APP_SUB_WINDOW': 1, + }; + var systemWindowValueArr = []; + var systemWindowTypeArr = []; + var systemWindowTypeDicArr = []; + var systemWindowTypeDic = { + 'TYPE_SYSTEM_ALERT': 1, + 'TYPE_INPUT_METHOD': 2, + 'TYPE_STATUS_BAR': 3, + 'TYPE_PANEL': 4, + 'TYPE_KEYGUARD': 5, + 'TYPE_VOLUME_OVERLAY': 6, + 'TYPE_NAVIGATION_BAR': 7, + 'TYPE_FLOAT': 8, + // 'TYPE_FLOAT_CAMERA': 9 + } + var windowLayoutModeArr = []; + var windowLayoutModeDic = { + 'WINDOW_LAYOUT_MODE_TILE': 1, + 'WINDOW_LAYOUT_MODE_CASCADE': 0 + }; + var windowCount = 2022; + var listenerStatus = { + ready: 'ready', + pending: 'pending', + finished: 'finished' + }; + var listenerData = { + on: false, + typeStr: '', + }; + var newWindowObj = null; + const WINDOW_NAME = 'windowName'; + + beforeAll(function () { + console.log('jsunittest beforeall ohosWindow.WindowType=' + JSON.stringify(ohosWindow.WindowType)); + systemWindowTypeDicArr = Object.keys(systemWindowTypeDic); + console.log('jsunittest beforeall systemWindowTypeDicArr=' + JSON.stringify(systemWindowTypeDicArr) + ' ,length=' + systemWindowTypeDicArr.length); + systemWindowValueArr = Object.keys(systemWindowTypeDic); + systemWindowTypeArr = Object.keys(systemWindowTypeDic); + for (var i in ohosWindow.WindowType) { + console.log('jsunittest beforeall i=' + i); + windowTypeArr.push(ohosWindow.WindowType[i]) + } + }) + beforeEach(function () { + }) + afterEach(async function (done) { + windowCount++; + if (listenerData.on) { + listenerData.on = false; + console.log('jsunittest afterEach listener off, listenerData:' + JSON.stringify(listenerData)); + if (listenerData.typeStr === 'systemBarTintChange') { + ohosWindow.off(listenerData.typeStr); + } else if (newWindowObj) { + newWindowObj.off(listenerData.typeStr); + } + await sleep(3000); + } + done(); + }) + afterAll(function () { + }) + + function expectedError(error, caseName, apiName, done, code) { + let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; + console.log(msgStr + JSON.stringify(error)); + if (error.code === code) { + expect(TRUE_FLAG).assertTrue(); + } + done(); + } + + function unexpectedError(error, caseName, apiName, done) { + let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; + console.log(msgStr + JSON.stringify(error)); + try { + + expect(TRUE_FLAG).assertFail(); + } catch (error) { + console.info(`unexpectedError catch error: ${JSON.stringify(error)}`) + } + done(); + } + + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + /** + * @tc.number SUB_WINDOW_GETALLDISPLAYS_JSAPI_001 + * @tc.name Test getAllDisplaysTest1 + * @tc.desc Gets all current display objects + */ + it('getAllDisplaysTest1', 0, async function (done) { + let caseName = 'getAllDisplaysTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + display.getAllDisplays().then((data) => { + console.info(msgStr + 'Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)); + expect(data[0].id != null).assertTrue(); + expect(data[0].refreshRate != null).assertTrue(); + expect(data[0].width != null).assertTrue(); + expect(data[0].height != null).assertTrue(); + expect(data[0].rotation != null).assertTrue(); + expect(data[0].densityDPI != null).assertTrue(); + expect(data[0].name != null).assertTrue(); + expect(data[0].alive).assertTrue(); + expect(data[0].state != null).assertTrue(); + expect(data[0].densityPixels != null).assertTrue(); + expect(data[0].scaledDensity != null).assertTrue(); + expect(data[0].xDPI != null).assertTrue(); + expect(data[0].yDPI != null).assertTrue(); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to obtain all the display objects. Code: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + }) + /** + * @tc.number SUB_WINDOW_GETALLDISPLAYS_JSAPI_002 + * @tc.name Test getAllDisplaysTest2 + * @tc.desc Gets all current display objects + */ + it('getAllDisplaysTest2', 0, async function (done) { + let caseName = 'getAllDisplaysTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + display.getAllDisplays((err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to obtain all the display objects. Code: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`display.getAllDisplays catch error: ${JSON.stringify(error)}`) + } + done(); + return; + } + console.info(msgStr + 'Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)); + expect(data[0].refreshRate != null).assertTrue(); + expect(data[0].width != null).assertTrue(); + expect(data[0].height != null).assertTrue(); + expect(data[0].rotation != null).assertTrue(); + expect(data[0].densityDPI != null).assertTrue(); + expect(data[0].name != null).assertTrue(); + expect(data[0].alive).assertTrue(); + expect(data[0].state != null).assertTrue(); + expect(data[0].densityPixels != null).assertTrue(); + expect(data[0].scaledDensity != null).assertTrue(); + expect(data[0].xDPI != null).assertTrue(); + expect(data[0].yDPI != null).assertTrue(); + done(); + console.log(msgStr + 'done '); + }); + }) + /** + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_001 + * @tc.name Test createWindowTest1 + * @tc.desc Verify the scenario of creating the application type window + */ + it('createWindowTest1', 0, async function (done) { + let caseName = 'createWindowTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let loopCount = systemWindowTypeDicArr.length; + console.log(msgStr + 'loopCount: ' + loopCount); + let num = 0 + for (let i = 0; i < loopCount; i++) { + sleep(500) + let tempType = Number(ohosWindow.WindowType[systemWindowTypeDicArr[i]]) + let windId = 'createWindowTest1' + i; + console.log(msgStr + 'ohosWindow.createWindow: ' + tempType + ' start'); + let windowConfig = { + name: windId, + windowType: tempType, + ctx: context, + displayId: 0, + parentId: 0 + }; + try { + let tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + 'catched, err: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }); + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + 'finished, wnd: ' + JSON.stringify(tempWnd)); + expect(!!tempWnd).assertTrue(); + num++; + if (num == loopCount) done(); + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + } + }) + + /** + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_002 + * @tc.name Test createWindowTest2 + * @tc.desc Verify the scenario of creating a window with duplicate IDs + */ + it('createWindowTest2', 0, async function (done) { + let caseName = 'createWindowTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let windowId = 'createWindowSameidsTest2' + let windowConfig = { + name: windowId, windowType: 1, ctx: context + }; + try { + let ohosData = await ohosWindow.createWindow(windowConfig).catch((err) => { + console.log(msgStr + 'ohosWindow.createWindow 1 once err: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }) + expect(!!ohosData).assertTrue(); + try { + let ohosDataError = await ohosWindow.createWindow(windowConfig).catch((errSencond) => { + console.log(msgStr + 'ohosWindow.createWindow 1 twice err: ' + JSON.stringify(errSencond)); + expect(errSencond.code).assertEqual(1300002) + done(); + }) + console.log(msgStr + 'ohosWindow.createWindow 1 twice ohosDataError: ' + JSON.stringify(ohosDataError)); + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + + }) + /** + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_004 + * @tc.name Test createWindowTest4 + * @tc.desc Verify the scenario of creating the application type window + */ + it('createWindowTest4', 0, done => { + sleep(1000) + let caseName = 'createWindowTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin context==' + JSON.stringify(context)); + let tempType = 1; + let windId = 'createWindowTest4_0'; + let windIdTwo = 'createWindowTest4_1'; + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + ' start'); + let windowConfig = { + name: windId, windowType: tempType, ctx: context + }; + let windowConfigTwo = { + name: windIdTwo, windowType: tempType, ctx: context + }; + try { + ohosWindow.createWindow(windowConfig, (err, data) => { + if (err && err.code) { + console.log(msgStr + 'ohosWindow.createWindow err.code==' + JSON.stringify(err.code)) + return; + } + console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.crreateWindow catch error: ${JSON.stringify(error)}`) + } + try { + ohosWindow.createWindow(windowConfigTwo, (err, dataTwo) => { + console.log(msgStr + 'ohosWindow.createWindow two twice' + JSON.stringify(err)); + if (err && err.code) { + console.log(msgStr + 'ohosWindow.createWindow two twice data: ' + JSON.stringify(dataTwo)); + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + } else { + console.log(msgStr + 'ohosWindow.createWindow two success twice data: ' + JSON.stringify(dataTwo)); + done(); + } + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_005 + * @tc.name Test createWindowTest5 + * @tc.desc Verify the scenario of creating the system type window + */ + it('createWindowTest5', 0, done => { + let caseName = 'createWindowTest5'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let loopCount = systemWindowTypeArr.length; + console.log('jsunittest loopCount: ' + loopCount); + let tempType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT; + let windId = 'createWindowTest5'; + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + ' start'); + let windowConfig = { + name: windId, windowType: tempType, ctx: context + }; + try { + ohosWindow.createWindow(windowConfig, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); + return; + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + let tempWnd = data + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + ' wnd: ' + tempWnd); + try { + let proData = tempWnd.getWindowProperties(); + console.log(msgStr + 'proData.type:' + proData.type); + expect(proData.type == tempType).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); + } + ; + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_006 + * @tc.name Test createWindowTest6 + * @tc.desc Verify the scenario of creating a window with duplicate IDs + */ + it('createWindowTest6', 0, done => { + let caseName = 'createWindowTest6'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let windowId = 'createWindowSameidTest6' + let winsowConfig = { + name: windowId, windowType: 1, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (err, data) => { + console.log(msgStr + 'ohosWindow.createWindow 1 once err: ' + JSON.stringify(err)); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + return + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + try { + ohosWindow.createWindow(winsowConfig, (err, dataTwo) => { + console.log(msgStr + 'ohosWindow.createWindow 1 twice err: ' + JSON.stringify(err)); + if (err && err.code) { + console.log(msgStr + 'ohosWindow.createWindow 1 twice data: ' + JSON.stringify(dataTwo)); + try { + expect(err.code).assertEqual(1300002) + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + console.log(msgStr + 'ohosWindow.createWindow 1 twice data: ' + JSON.stringify(dataTwo)); + } + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + + }) + /** + * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_001 + * @tc.name Test getWindowAvoidAreaTest1 + * @tc.desc Obtain the area that the window content avoids + */ + it('getWindowAvoidAreaTest1', 0, async function (done) { + let caseName = 'getWindowAvoidAreaTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + try { + let tempWnd = windowStage.getMainWindowSync(); + expect(!!tempWnd).assertTrue(); + try { + let type = ohosWindow.AvoidAreaType.TYPE_SYSTEM; + let avoidArea = tempWnd.getWindowAvoidArea(type); + console.log(msgStr + 'avoidArea: ' + JSON.stringify(avoidArea)); + expect(avoidArea.visible).assertTrue(); + expect(avoidArea.topRect != null).assertTrue(); + expect(avoidArea.rightRect != null).assertTrue(); + expect(avoidArea.bottomRect != null).assertTrue(); + expect(avoidArea.leftRect != null).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the area. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + + /** + * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_002 + * @tc.name Test getWindowAvoidAreaTest2 + * @tc.desc Obtain the area that the window content avoids + */ + it('getWindowAvoidAreaTest2', 0, async function (done) { + let caseName = 'getWindowAvoidAreaTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + try { + let tempWnd = windowStage.getMainWindowSync(); + expect(tempWnd != null).assertTrue(); + try { + let type = ohosWindow.AvoidAreaType.TYPE_CUTOUT; + let avoidArea = tempWnd.getWindowAvoidArea(type); + console.log(msgStr + 'avoidArea: ' + JSON.stringify(avoidArea)); + expect(!avoidArea.visible).assertTrue(); + expect(avoidArea.topRect != null).assertTrue(); + expect(avoidArea.rightRect != null).assertTrue(); + expect(avoidArea.bottomRect != null).assertTrue(); + expect(avoidArea.leftRect != null).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the area. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_003 + * @tc.name Test getWindowAvoidAreaTest3 + * @tc.desc Obtain the area that the window content avoids + */ + it('getWindowAvoidAreaTest3', 0, async function (done) { + let caseName = 'getWindowAvoidAreaTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + try { + let tempWnd = windowStage.getMainWindowSync(); + expect(!!tempWnd).assertTrue(); + try { + let type = ohosWindow.AvoidAreaType.TYPE_SYSTEM_GESTURE; + let avoidArea = tempWnd.getWindowAvoidArea(type); + console.log(msgStr + 'avoidArea: ' + JSON.stringify(avoidArea)); + expect(avoidArea.visible).assertTrue(); + expect(avoidArea.topRect != null).assertTrue(); + expect(avoidArea.rightRect != null).assertTrue(); + expect(avoidArea.bottomRect != null).assertTrue(); + expect(avoidArea.leftRect != null).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the area. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_004 + * @tc.name Test getWindowAvoidAreaTest4 + * @tc.desc Obtain the area that the window content avoids + */ + it('getWindowAvoidAreaTest4', 0, async function (done) { + let caseName = 'getWindowAvoidAreaTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + try { + let tempWnd = windowStage.getMainWindowSync(); + expect(!!tempWnd).assertTrue(); + try { + let type = ohosWindow.AvoidAreaType.TYPE_KEYBOARD; + let avoidArea = tempWnd.getWindowAvoidArea(type); + console.log(msgStr + 'avoidArea: ' + JSON.stringify(avoidArea)); + expect(avoidArea.visible).assertTrue(); + expect(avoidArea.topRect != null).assertTrue(); + expect(avoidArea.rightRect != null).assertTrue(); + expect(avoidArea.bottomRect != null).assertTrue(); + expect(avoidArea.leftRect != null).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the area. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_GETWINDOWPROPERTIES_JSAPI_001 + * @tc.name Test getWindowPropertiesTest1 + * @tc.desc Gets the properties of the current window + */ + it('getWindowPropertiesTest1', 0, async function (done) { + let caseName = 'getWindowPropertiesTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + try { + let tempWnd = windowStage.getMainWindowSync(); + expect(!!tempWnd).assertTrue(); + try { + let data = tempWnd.getWindowProperties(); + console.log(msgStr + 'ohosWindow.getWindowProperties ' + JSON.stringify(data)); + expect(data.type != null).assertTrue(); + expect(data.windowRect.height != null).assertTrue(); + expect(data.windowRect.left != null).assertTrue(); + expect(data.windowRect.top != null).assertTrue(); + expect(data.windowRect.width != null).assertTrue(); + expect(data.isFullScreen != null).assertTrue(); + expect(data.isLayoutFullScreen != null).assertTrue(); + expect(data.focusable != null).assertTrue(); + expect(data.touchable != null).assertTrue(); + expect(data.isKeepScreenOn != null).assertTrue(); + expect(data.isTransparent != null).assertTrue(); + expect(data.brightness != null).assertTrue(); + expect(data.dimBehindValue).assertEqual(0); + expect(data.isRoundCorner != null).assertTrue(); + expect(data.isPrivacyMode != null).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the main window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_GETLASTWINDOW_JSAPI_001 + * @tc.name Test getLastWindowTest1 + * @tc.desc Get the final show window + */ + it('getLastWindowTest1', 0, async function (done) { + let caseName = 'getLastWindowTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let proData = null + try { + let lastWindow = await ohosWindow.getLastWindow(context).catch((err) => { + console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + }) + expect(lastWindow != null).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_GETLASTWINDOW_JSAPI_002 + * @tc.name Test getLastWindowTest2 + * @tc.desc Get the final show window + */ + it('getLastWindowTest2', 0, async function (done) { + let caseName = 'getLastWindowTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + try { + ohosWindow.getLastWindow(context, (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + return; + } + console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SHOWWINDOW_JSAPI_001 + * @tc.name Test showWindowTest1 + * @tc.desc show window + */ + it('showWindowTest1', 0, async function (done) { + let caseName = 'showWindowTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let baseWndType = 1; + let windowId = 'showWindowTest1'; + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let tempWnd = null; + try { + tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }); + console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + JSON.stringify(tempWnd)); + expect(!!tempWnd).assertTrue(); + tempWnd.showWindow().then((data) => { + console.info(msgStr + 'Succeeded in showing the window. Data: ' + JSON.stringify(data)); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.showWindow', done); + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SHOWWINDOW_JSAPI_002 + * @tc.name Test showWindowTest2 + * @tc.desc show window + */ + it('showWindowTest2', 0, async function (done) { + let caseName = 'showWindowTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let baseWndType = 1; + let windowId = 'showWindowTest2'; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); + return; + } + try { + expect(!!create_data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + create_data.showWindow((err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + return; + } + console.info(msgStr + 'Succeeded in showing the window. Data: ' + JSON.stringify(data)); + done(); + }) + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_001 + * @tc.name Test moveWindowToTest1 + * @tc.desc Set the position of a window. + */ + it('moveWindowToTest1', 0, async function (done) { + let caseName = 'moveWindowToTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'moveWindowToTest1'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(windowConfig).then((wnd) => { + console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(wnd)); + expect(wnd != null).assertTrue(); + try { + wnd.moveWindowTo(300, 300).then(() => { + console.info(msgStr + 'Succeeded in moving the window.'); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to move the window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.moveWindowTo', done); + }); + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + } + ; + }).catch((err) => { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + }); + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_002 + * @tc.name Test moveWindowToTest2 + * @tc.desc Set the position of a window. + */ + it('moveWindowToTest2', 0, async function (done) { + let caseName = 'moveWindowToTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'moveWindowToTest2'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(windowConfig).then((wnd) => { + console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(wnd)); + expect(wnd != null).assertTrue(); + try { + wnd.moveWindowTo(100, 50).then(() => { + console.info(msgStr + 'Succeeded in moving the window.'); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to move the window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.moveWindowTo', done); + }); + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + } + ; + }).catch((err) => { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + }); + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_003 + * @tc.name Test moveWindowToTest3 + * @tc.desc Set the position of a window. + */ + it('moveWindowToTest3', 0, async function (done) { + let caseName = 'moveWindowToTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'moveWindowToTest3'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(windowConfig).then((wnd) => { + console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(wnd)); + expect(wnd != null).assertTrue(); + try { + wnd.moveWindowTo(20000, 20000).then(() => { + console.info(msgStr + 'Succeeded in moving the window.'); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to move the window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.moveWindowTo', done); + }); + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + } + ; + }).catch((err) => { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + }); + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_004 + * @tc.name Test moveWindowToTest4 + * @tc.desc Set the position of a window. + */ + it('moveWindowToTest4', 0, async function (done) { + let caseName = 'moveWindowToTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'moveWindowToTest4'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(windowConfig).then((wnd) => { + console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(wnd)); + expect(wnd != null).assertTrue(); + try { + wnd.moveWindowTo(-200, -200).then(() => { + console.info(msgStr + 'Succeeded in moving the window.'); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to move the window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.moveWindowTo', done); + }); + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + } + ; + }).catch((err) => { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + }); + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_005 + * @tc.name Test moveWindowToTest5 + * @tc.desc Set the position of a window. + */ + it('moveWindowToTest5', 0, async function (done) { + let caseName = 'moveWindowToTest5'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let baseWndType = 1; + let windowId = 'moveWindowToTest5'; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); + return; + } + try { + create_data.moveWindowTo(300, 300, (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.moveWindowTo', done); + return; + } + console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + } + ; + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_006 + * @tc.name Test moveWindowToTest6 + * @tc.desc Set the position of a window. + */ + it('moveWindowToTest6', 0, async function (done) { + let caseName = 'moveWindowToTest6'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let baseWndType = 1; + let windowId = 'moveWindowToTest6'; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); + return; + } + try { + create_data.moveWindowTo(100, 50, (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.moveWindowTo', done); + return; + } + console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + } + ; + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_007 + * @tc.name Test moveWindowToTest7 + * @tc.desc Set the position of a window. + */ + it('moveWindowToTest7', 0, async function (done) { + let caseName = 'moveWindowToTest7'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let baseWndType = 1; + let windowId = 'moveWindowToTest7'; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); + return; + } + try { + create_data.moveWindowTo(20000, 20000, (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.moveWindowTo', done); + return; + } + console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + } + ; + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_008 + * @tc.name Test moveWindowToTest8 + * @tc.desc Set the position of a window. + */ + it('moveWindowToTest8', 0, async function (done) { + let caseName = 'moveWindowToTest8'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let baseWndType = 1; + let windowId = 'moveWindowToTest8'; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); + return; + } + try { + create_data.moveWindowTo(-200, -200, (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.moveWindowTo', done); + return; + } + console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + } + ; + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_RESIZE_JSAPI_001 + * @tc.name Test resizeTest1 + * @tc.desc Set the size of a window + */ + it('resizeTest1', 0, async function (done) { + let caseName = 'resizeTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'resizeTest1'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let tempWnd = null; + try { + tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }); + console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); + expect(!!tempWnd).assertTrue(); + try { + tempWnd.resize(200, 600).then((data) => { + console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.resize', done); + }) + } catch (exception) { + console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_RESIZE_JSAPI_002 + * @tc.name Test resizeTest2 + * @tc.desc Set the size of a window + */ + it('resizeTest2', 0, async function (done) { + let caseName = 'resizeTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'resizeTest2'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let tempWnd = null; + try { + tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }); + console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); + expect(!!tempWnd).assertTrue(); + try { + tempWnd.resize(20000, 20000).then((data) => { + console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.resize', done); + }) + } catch (exception) { + console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_RESIZE_JSAPI_003 + * @tc.name Test resizeTest3 + * @tc.desc Set the size of a window + */ + it('resizeTest3', 0, async function (done) { + let caseName = 'resizeTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'resizeTest3'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let tempWnd = null; + try { + tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }); + console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); + expect(!!tempWnd).assertTrue(); + try { + tempWnd.resize(0, 0).then((data) => { + console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); + expect(err.code).assertEqual(401); + done(); + }) + } catch (exception) { + console.error(msgStr + 'try catch Failed to change the window size. Cause: ' + JSON.stringify(exception)); + expect(exception.code).assertEqual(401); + done(); + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_RESIZE_JSAPI_004 + * @tc.name Test resizeTest4 + * @tc.desc Set the size of a window + */ + it('resizeTest4', 0, async function (done) { + let caseName = 'resizeTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'resizeTest4'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let tempWnd = null; + try { + tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }); + console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); + expect(!!tempWnd).assertTrue(); + try { + tempWnd.resize(-1, -1).then((data) => { + console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); + expect(err.code).assertEqual(401); + done(); + }) + } catch (exception) { + console.error(msgStr + 'try catch Failed to change the window size. Cause: ' + JSON.stringify(exception)); + expect(exception.code).assertEqual(401); + done(); + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_RESIZE_JSAPI_005 + * @tc.name Test resizeTest5 + * @tc.desc Set the size of a window + */ + it('resizeTest5', 0, async function (done) { + let caseName = 'resizeTest5'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'resizeTest5'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let tempWnd = null; + try { + tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }); + console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); + expect(!!tempWnd).assertTrue(); + for (var i = 1; i <= 5; i++) { + try { + tempWnd.resize(100, 100).then((data) => { + console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); + expect(err.code).assertEqual(6); + done(); + tempWnd.detroyWindow(); + }) + } catch (exception) { + console.error(msgStr + 'try catch Failed to change the window size. Cause: ' + JSON.stringify(exception)); + } + ; + } + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_RESIZE_JSAPI_006 + * @tc.name Test resizeTest6 + * @tc.desc Set the size of a window + */ + it('resizeTest6', 0, async function (done) { + let caseName = 'resizeTest6'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let baseWndType = 1; + let windowId = 'resizeTest6'; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); + return; + } + try { + create_data.resize(200, 200, (err) => { + if (err.code) { + console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.resize', done); + return; + } + console.info(msgStr + 'Succeeded in changing the window size.'); + done(); + }); + } catch (exception) { + console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(exception)); + } + ; + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_RESIZE_JSAPI_007 + * @tc.name Test resizeTest7 + * @tc.desc Set the size of a window + */ + it('resizeTest7', 0, async function (done) { + let caseName = 'resizeTest6'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let baseWndType = 1; + let windowId = 'resizeTest7'; + let width = 100; + let height = 100; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); + return; + } + for (let i = 1; i <= 5; i++) { + width = width * i; + height = height * i; + try { + create_data.resize(width, height, (err) => { + if (err.code) { + console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.resize', done); + return; + } + console.info(msgStr + 'Succeeded in changing the window size.'); + done(); + }); + } catch (exception) { + console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(exception)); + } + ; + } + + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_DESTROYWINDOW_JSAPI_001 + * @tc.name Test destroyWindowTest1 + * @tc.desc Verification window destruction scenario. + */ + it('destroyWindowTest1', 0, async function (done) { + let caseName = 'destroyWindowTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT; + let windowId = 'destroyWindowTest1'; + console.log(msgStr + 'begin'); + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let tempWnd = null; + try { + tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + }); + console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + JSON.stringify(tempWnd)); + expect(!!tempWnd).assertTrue(); + tempWnd.destroyWindow().then(() => { + console.info(msgStr + 'Succeeded in destroying the window.'); + try { + let findWnd = ohosWindow.findWindow(windowId) + expect(!findWnd).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'try catch Failed to find the Window. Cause: ' + JSON.stringify(exception)); + expect(exception.code === 1300002).assertTrue(); + done(); + } + ; + }).catch((err) => { + console.error(msgStr + 'try catch Failed to destroy the window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.destroyWindow', done); + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_DESTROYWINDOW_JSAPI_002 + * @tc.name Test destroyWindowTest2 + * @tc.desc Verification window destruction scenario + */ + it('destroyWindowTest2', 0, function (done) { + let caseName = 'destroyWindowTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'destroyWindowTest2'; + console.log(msgStr + 'begin'); + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); + return; + } + try { + expect(!!create_data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + create_data.destroyWindow((err) => { + if (err.code != 0) { + console.log('windowTest DestroyTest2 create callback fail' + JSON.stringify(err)); + unexpectedError(create_err, caseName, 'ohosWindow.destroyWindow', done); + } else { + try { + let findWnd = ohosWindow.findWindow(windowId) + expect(!findWnd).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'try catch Failed to find the Window. Cause: ' + JSON.stringify(exception)); + expect(exception.code === 1300002).assertTrue(); + done(); + } + ; + } + }) + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_001 + * @tc.name Test setWindowSystemBarEnableTest1 + * @tc.desc Set the visible mode of navigation bar and status bar + */ + it('setWindowSystemBarEnableTest1', 0, async function (done) { + let caseName = 'setWindowSystemBarEnableTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wnd = null; + try { + wnd = await ohosWindow.getLastWindow(context).catch((err) => { + console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + }) + expect(wnd != null).assertTrue(); + try { + wnd.setWindowSystemBarEnable([]).then(() => { + console.info(msgStr + 'Succeeded in setting the system bar to be invisible.'); + expect(TRUE_FLAG).assertTrue(); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_002 + * @tc.name Test setWindowSystemBarEnableTest2 + * @tc.desc Set the visible mode of navigation bar and status bar + */ + it('setWindowSystemBarEnableTest2', 0, async function (done) { + let caseName = 'setWindowSystemBarEnableTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wnd = null; + try { + wnd = await ohosWindow.getLastWindow(context).catch((err) => { + console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + }) + expect(wnd != null).assertTrue(); + try { + wnd.setWindowSystemBarEnable(['status', 'navigation']).then(() => { + console.info(msgStr + 'Succeeded in setting the system bar to be invisible.'); + expect(TRUE_FLAG).assertTrue(); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_003 + * @tc.name Test setWindowSystemBarEnableTest3 + * @tc.desc Set the visible mode of navigation bar and status bar + */ + it('setWindowSystemBarEnableTest3', 0, async function (done) { + let caseName = 'setWindowSystemBarEnableTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wnd = null; + try { + wnd = await ohosWindow.getLastWindow(context).catch((err) => { + console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + }) + expect(wnd != null).assertTrue(); + try { + wnd.setWindowSystemBarEnable(['status']).then(() => { + console.info(msgStr + 'Succeeded in setting the system bar to be invisible.'); + expect(TRUE_FLAG).assertTrue(); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_004 + * @tc.name Test setWindowSystemBarEnableTest4 + * @tc.desc Set the visible mode of navigation bar and status bar + */ + it('setWindowSystemBarEnableTest4', 0, async function (done) { + let caseName = 'setWindowSystemBarEnableTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wnd = null; + try { + wnd = await ohosWindow.getLastWindow(context).catch((err) => { + console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + }) + expect(wnd != null).assertTrue(); + try { + wnd.setWindowSystemBarEnable(['navigation']).then(() => { + console.info(msgStr + 'Succeeded in setting the system bar to be invisible.'); + expect(TRUE_FLAG).assertTrue(); + done(); + }).catch((err) => { + console.error(msgStr + 'Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_005 + * @tc.name Test setWindowSystemBarEnableTest5 + * @tc.desc Set the visible mode of navigation bar and status bar + */ + it('setWindowSystemBarEnableTest5', 0, async function (done) { + let caseName = 'setWindowSystemBarEnableTest5'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'setWindowSystemBarEnableTest5'; + console.log(msgStr + 'begin'); + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let wnd = null; + try { + wnd = await ohosWindow.getLastWindow(context).catch((err) => { + console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + }) + expect(wnd != null).assertTrue(); + try { + wnd.setWindowSystemBarEnable(['status', 'navigation'], (err) => { + console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen(true) callback begin'); + if (err.code != 0) { + console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen callback fail' + JSON.stringify(err)); + expect().assertFail(); + done(); + } else { + expect(TRUE_FLAG).assertTrue(); + done(); + } + }) + } catch (exception) { + console.error(msgStr + ' try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to get the last window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_006 + * @tc.name Test setWindowSystemBarEnableTest6 + * @tc.desc Set the visible mode of navigation bar and status bar + */ + it('setWindowSystemBarEnableTest6', 0, async function (done) { + let caseName = 'setWindowSystemBarEnableTest6'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'setWindowSystemBarEnableTest6'; + console.log(msgStr + 'begin'); + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let wnd = null; + try { + wnd = await ohosWindow.getLastWindow(context).catch((err) => { + console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + }) + expect(wnd != null).assertTrue(); + try { + wnd.setWindowSystemBarEnable([], (err) => { + console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen(true) callback begin'); + if (err.code != 0) { + console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen callback fail' + JSON.stringify(err)); + expect().assertFail(); + done(); + } else { + expect(TRUE_FLAG).assertTrue(); + done(); + } + }) + } catch (exception) { + console.error(msgStr + ' try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to get the last window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_003 + * @tc.name Test createWindowTest3 + * @tc.desc Verify the scenario of creating a window of a type that does not exist + */ + it('createWindowTest3', 0, async function (done) { + let caseName = 'createWindowTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let tempType = 5000; + let windId = 'nonExistWindowType'; + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + ' start'); + let windowConfig = { + name: windId, windowType: tempType, ctx: context + }; + let nonExistWnd = null; + try { + nonExistWnd = await ohosWindow.createWindow(windowConfig).then((data) => { + console.log(msgStr + 'ohosWindow.createWindow success: ' + JSON.stringify(nonExistWnd)); + done(); + }).catch((err) => { + console.log(msgStr + 'ohosWindow.createWindow err: ' + JSON.stringify(err)); + expect(err.code === 401).assertTrue(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect(exception.code === 401).assertTrue(); + done(); + } + ; + }) + /** + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_007 + * @tc.name Test createWindowTest7 + * @tc.desc Verify the scenario of creating a window of a type that does not exist + */ + it('createWindowTest7', 0, done => { + let caseName = 'createWindowTest7'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let tempType = 5000; + let windId = 'createTest7'; + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + ' start'); + let winsowConfig = { + name: windId, windowType: tempType, ctx: context + }; + try { + ohosWindow.createWindow(winsowConfig, (err, data) => { + if (err && err.code) { + console.log(msgStr + 'ohosWindow.createWindow err' + JSON.stringify(err)); + try { + expect(err.code === 401).assertTrue(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + done(); + } + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect(exception.code === 401).assertTrue(); + done(); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_001 + * @tc.name Test setWindowLayoutFullScreenTest1 + * @tc.desc set the property of the window can layout in full screen + */ + it('setWindowLayoutFullScreenTest1', 0, async function (done) { + let caseName = 'setWindowLayoutFullScreenTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wnd = null; + try { + wnd = windowStage.getMainWindowSync(); + console.log(msgStr + 'ohosWindow.getLastWindow ' + JSON.stringify(wnd)); + expect(wnd != null).assertTrue(); + try { + let isLayoutFullScreen = true; + wnd.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { + console.info(msgStr + 'Succeeded in setting the window layout to full-screen mode.'); + try { + let propData = wnd.getWindowProperties() + console.info(msgStr + 'wnd.getWindowProperties propData: ' + JSON.stringify(propData)); + expect(propData.isLayoutFullScreen).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + }).catch((err) => { + console.error(msgStr + 'Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_002 + * @tc.name Test setWindowLayoutFullScreenTest2 + * @tc.desc set the property of the window can layout in full screen + */ + it('setWindowLayoutFullScreenTest2', 0, async function (done) { + let caseName = 'setWindowLayoutFullScreenTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wnd = null; + try { + wnd = windowStage.getMainWindowSync(); + expect(wnd != null).assertTrue(); + try { + let isLayoutFullScreen = false; + wnd.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { + console.info(msgStr + 'Succeeded in setting the window layout to full-screen mode.'); + try { + let propData = wnd.getWindowProperties() + console.info(msgStr + 'wnd.getWindowProperties propData: ' + JSON.stringify(propData)); + expect(!propData.isLayoutFullScreen).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + }).catch((err) => { + console.error(msgStr + 'Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); + } + ; + } catch (exception) { + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_003 + * @tc.name Test setWindowLayoutFullScreenTest3 + * @tc.desc set the property of the window can layout in full screen + */ + it('setWindowLayoutFullScreenTest3', 0, async function (done) { + let caseName = 'setWindowLayoutFullScreenTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wnd = null; + try { + wnd = windowStage.getMainWindowSync(); + expect(wnd != null).assertTrue(); + let isLayoutFullScreen = true; + try { + wnd.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => { + if (err.code) { + console.error(msgStr + 'err Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + done(); + return; + } + console.info(msgStr + 'Succeeded in setting the window layout to full-screen mode.'); + try { + let propData = wnd.getWindowProperties() + console.log(msgStr + JSON.stringify(propData)); + expect(propData.isLayoutFullScreen).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to get the main window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_004 + * @tc.name Test setWindowLayoutFullScreenTest4 + * @tc.desc set the property of the window can layout in full screen + */ + it('setWindowLayoutFullScreenTest4', 0, async function (done) { + let caseName = 'setWindowLayoutFullScreenTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wnd = null; + try { + wnd = windowStage.getMainWindowSync(); + expect(wnd != null).assertTrue(); + let isLayoutFullScreen = false; + try { + wnd.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => { + if (err.code) { + console.error(msgStr + 'err Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + done(); + return; + } + console.info(msgStr + 'Succeeded in setting the window layout to full-screen mode.'); + try { + let propData = wnd.getWindowProperties() + console.log(msgStr + JSON.stringify(propData)); + expect(!propData.isLayoutFullScreen).assertTrue(); + done(); + } catch (exception) { + console.error(msgStr + 'Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to create the main window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_001 + * @tc.name Test setWindowModeTest1 + * @tc.desc Test window.setWindowMode API function test. + */ + it('setWindowModeTest1', 0, function (done) { + //['UNDEFINED','FULLSCREEN','PRIMARY','SECONDARY','FLOATING'] + let windowModeArr = ['FULLSCREEN', 'PRIMARY', 'SECONDARY', 'FLOATING'] + let caseName = 'setWindowModeTest1'; + let msgStr = 'jsunittest ' + caseName + ' '; + let sumCount = 0 + try { + let tempWnd = windowStage.getMainWindowSync(); + expect(!!tempWnd).assertTrue(); + let loopCount = windowModeArr; + console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount)) + for (let i = 0; i < loopCount.length; i++) { + sleep(500) + let tempType = ohosWindow.WindowMode[loopCount[i]]; + console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); + try { + tempWnd.setWindowMode(tempType).then(() => { + sumCount++ + console.info(msgStr + 'Succeeded in setting the window mode. count: ' + sumCount); + console.info(msgStr + 'Succeeded in setting the window mode. loopCount.length: ' + loopCount.length); + if (sumCount == loopCount.length) done(); + }).catch((err) => { + console.log(msgStr + 'currentType: ' + tempType) + console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the window mode. Cause: ' + JSON.stringify(exception)); + } + ; + } + } catch (exception) { + console.error('try catch Failed to obtain the getMainWindowSync. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_002 + * @tc.name Test setWindowModeTest2 + * @tc.desc Verify the scenario where the normal window mode is set + */ + it('setWindowModeTest2', 0, function (done) { + let windowModeArr = ['FULLSCREEN', 'PRIMARY', 'SECONDARY', 'FLOATING'] + let caseName = 'setWindowModeTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + let sumCount = 0 + try { + let wnd = windowStage.getMainWindowSync(); + expect(!!wnd).assertTrue(); + let loopCount = windowModeArr; + console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount)) + getData(0, loopCount.length) + + function getData(i, length) { + try { + let tempType = ohosWindow.WindowMode[loopCount[i]]; + console.log(msgStr + 'tempWnd.setWindowMode tempType:' + tempType + ' start i:' + i); + wnd.setWindowMode(tempType, (err, data) => { + if (err && err.code) { + console.log(msgStr + 'currentType: ' + tempType) + console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + sumCount++ + console.info(msgStr + 'Succeeded in setting the window mode. count: ' + sumCount); + console.info(msgStr + 'Succeeded in setting the window mode. loopCount.length: ' + loopCount.length); + if (sumCount == loopCount.length) done(); + } + if (++i < length) { + getData(i, length) + console.log(msgStr + 'jixuzhixing i: ' + i); + } else { + console.log(msgStr + 'i++ { + sumCount++ + console.info(msgStr + 'Succeeded in setting the window mode. count: ' + sumCount); + console.info(msgStr + 'Succeeded in setting the window mode. loopCount.length: ' + loopCount.length); + }).catch((err) => { + console.log(msgStr + 'currentType: ' + tempType) + console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); + expect(err.code == 401).assertTrue(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the window mode. Cause: ' + JSON.stringify(exception)); + } + ; + } + } catch (exception) { + console.error('try catch Failed to obtain the getMainWindowSync. Cause: ' + JSON.stringify(exception)); + } + ; + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_004 + * @tc.name Test setWindowModeTest4 + * @tc.desc Verify the scenario where the normal window mode is set + */ + it('setWindowModeTest4', 0, function (done) { + let windowModeArr = ['UNDEFINED'] + let caseName = 'setWindowModeTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let sumCount = 0 + try { + let wnd = windowStage.getMainWindowSync(); + expect(!!wnd).assertTrue(); + let loopCount = windowModeArr; + console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount)) + for (let i = 0; i < loopCount.length; i++) { + sleep(500) + let tempType = ohosWindow.WindowMode[loopCount[i]]; + console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); + try { + wnd.setWindowMode(tempType, (err, data) => { + if (err && err.code) { + console.log(msgStr + 'currentType: ' + tempType) + console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); + try { + expect(err.code == 401).assertTrue(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + sumCount++ + console.info(msgStr + 'Succeeded in setting the window mode. count: ' + sumCount); + console.info(msgStr + 'Succeeded in setting the window mode. loopCount.length: ' + loopCount.length); + } + }) + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the window mode. Cause: ' + JSON.stringify(exception)); + } + ; + } + } catch (exception) { + console.error(msgStr + 'try catch Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + }) +} diff --git a/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets new file mode 100644 index 000000000..79fc0d7ab --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets @@ -0,0 +1,2202 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" +import ohosWindow from '@ohos.window'; +import display from '@ohos.display'; +import screenManager from '@ohos.screen'; + +export default function windowCallbackTest(context, windowStage, abilityStorage) { + console.log('testets context: ' + JSON.stringify(context)) + console.log('testets context windowStage: ' + JSON.stringify(windowStage)); + console.log('testets context abilityStorage: ' + JSON.stringify(abilityStorage)); + + describe('windowCallback_test', function () { + console.log('describe testets start!!') + const TRUE_FLAG = true; + console.log('describe window_api_test start!!!'); + var commonRGBColorArr = ['rgb(255,0,0)', 'rgb(0,255,0)', 'rgb(0,0,255)', 'rgb(255,255,255)', 'rgb(0,0,0)', 'rgb(249,0,230)', 'rgb(102,102,102)', 'rgb(255,247,0)']; + var commonNUMBERColorArr = ['#00FF0000', '#0000FF00', '#000000FF', '#00FFFFFF', '#00000000', '#00F900E6', '#00666666', '#00FFF700']; + var commonKEYColorArr = ['red', 'green', 'blue', 'white', 'black', 'pink', 'grey', 'yellow']; + var appWindowTypeArr = []; + var windowTypeArr = []; + var appWindowTypeDic = { + 'TYPE_BASE': 0, + 'TYPE_APP': 0, + 'TYPE_APP_SUB_WINDOW': 1, + }; + var systemWindowTypeArr = []; + var systemWindowTypeDic = { + 'TYPE_SYSTEM_ALERT': 1, + 'TYPE_INPUT_METHOD': 2, + 'TYPE_STATUS_BAR': 3, + 'TYPE_PANEL': 4, + 'TYPE_KEYGUARD': 5, + 'TYPE_VOLUME_OVERLAY': 6, + 'TYPE_NAVIGATION_BAR': 7, + 'TYPE_FLOAT': 8, + 'TYPE_FLOAT_CAMERA': 9 + } + var windowLayoutModeArr = []; + var windowLayoutModeDic = { + 'WINDOW_LAYOUT_MODE_TILE': 1, + 'WINDOW_LAYOUT_MODE_CASCADE': 0 + }; + var windowCount = 2022; + var listenerStatus = { + ready: 'ready', + pending: 'pending', + finished: 'finished' + }; + var listenerData = { + on: false, + typeStr: '', + }; + var newWindowObj = null; + beforeAll(function () { + appWindowTypeArr = Object.keys(appWindowTypeDic); + systemWindowTypeArr = Object.keys(systemWindowTypeDic); + for (var i in ohosWindow.WindowType) { + windowTypeArr.push(ohosWindow.WindowType[i]); + } + console.log('jsunittest beforeall'); + console.log('beforeall ohosWindow.windowType' + JSON.stringify(ohosWindow.WindowType)) + }) + beforeEach(function () { + }) + afterEach(async function (done) { + windowCount++; + console.log('jsunittest afterEach listenerData:' + JSON.stringify(listenerData)); + if (listenerData.on) { + listenerData.on = false; + if (listenerData.typeStr === 'systemBarTintChange') { + console.log('jsunittest systemBarTintChange start on'); + console.log('jsunittest systemBarTintChange end off listenerData.typeStr==' + JSON.stringify(listenerData.typeStr)); + ohosWindow.off(listenerData.typeStr); + console.log('jsunittest systemBarTintChange end off'); + } else if (newWindowObj) { + newWindowObj.off(listenerData.typeStr); + } + await sleep(3000); + } + done(); + }) + afterAll(function () { + }) + + function expectedError(error, caseName, apiName, done, code) { + let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; + console.log(msgStr + JSON.stringify(error)); + expect(TRUE_FLAG).assertTrue(); + expect(error.code === code).assertTrue(); + done(); + } + + function unexpectedError(error, caseName, apiName, done) { + let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; + console.log(msgStr + JSON.stringify(error)); + try { + expect(TRUE_FLAG).assertFail(); + ; + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + done(); + } + + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + /** + * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_006 + * @tc.name Test setSystemBarEnableTest6 + * @tc.desc Test ohosWindow.setSystemBarEnable API function test1. + */ + it('setSystemBarEnableTest6', 0, function (done) { + let caseName = 'setSystemBarEnableTest6'; + let msgStr = 'jsunittest ' + caseName + ' '; + let [flagStatus, flagNav] = [false, false]; + console.log(msgStr + 'begin'); + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + ohosWindow.on('systemBarTintChange', systembartintstate => { + console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + if (flagStatus || flagNav) { + try { + expect(!!systembartintstate).assertTrue(); + expect(!!systembartintstate.regionTint).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + console.log(msgStr + 'flagStatus || flagNav' + msgStr + 'ohosWindow.on systemBarTintChange regionTint:' + JSON.stringify(systembartintstate.regionTint)); + done(); + } + }) + let mainWnd = null; + console.log(msgStr + 'mainWnd = null'); + console.log(msgStr + 'windowStage = ' + JSON.stringify(windowStage)); + windowStage.getMainWindow((err, data) => { + console.log(msgStr + 'getMainWindow data2' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + mainWnd = data; + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + mainWnd.show((err, data) => { + console.log(msgStr + 'mainWnd.show err' + JSON.stringify(err)); + console.log(msgStr + 'mainWnd.show data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + expect(!data).assertTrue(); + console.log(msgStr + 'mainWnd.show success'); + mainWnd.setFullScreen(true, (err, data) => { + console.log(msgStr + 'mainWnd.setFullScreen data:' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setFullScreen success'); + flagNav = true; + mainWnd.setSystemBarEnable(['navigation'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable navigation JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navigation]', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setSystemBarEnable success flagNav==' + flagNav); + }) + flagStatus = true; + mainWnd.setSystemBarEnable(['status'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)===' + JSON.stringify(data)); + if (err && err.code) { + console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(err)===' + JSON.stringify(err)); + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + }) + }) + }) + }) + console.log(msgStr + 'finished!!'); + }); + /** + * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_007 + * @tc.name Test setSystemBarEnableTest7 + * @tc.desc Verify that the scene hides the status bar and displays the navigation bar. + */ + it('setSystemBarEnableTest7', 0, function (done) { + let caseName = 'setSystemBarEnableTest7'; + let msgStr = 'jsunittest ' + caseName + ' '; + let [flagStatus, flagNav] = [false, false]; + console.log(msgStr + 'begin'); + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + ohosWindow.on('systemBarTintChange', systembartintstate => { + console.log(msgStr + 'ohosWindow.on systembartintstate :' + JSON.stringify(systembartintstate)); + console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + if (flagStatus || flagNav) { + console.log(msgStr + 'ohosWindow.on flagStatus || flagNav:'); + try { + expect(!!systembartintstate).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) + } + done(); + } + }) + let mainWnd = null; + console.log(msgStr + 'mainWnd = null') + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch err: ${JSON.stringify(error)}`) + } + mainWnd = data; + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + mainWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + console.log(msgStr + 'mainWnd.show success'); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`) + } + mainWnd.setFullScreen(true, (err, data) => { + console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`) + } + mainWnd.setSystemBarEnable(['status'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); + } + flagStatus = true; + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + mainWnd.setSystemBarEnable(['navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navitgation]', done); + } + flagNav = true; + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + }) + }) + }) + }) + }) + }); + /** + * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_008 + * @tc.name Test setSystemBarEnableTest8 + * @tc.desc Verify that the scene displays both the status bar and the navigation bar. + */ + it('setSystemBarEnableTest8', 0, function (done) { + let caseName = 'setSystemBarEnableTest8'; + let msgStr = 'jsunittest ' + caseName + ' '; + let [flagStatus, flagNav] = [false, false]; + console.log(msgStr + 'begin'); + let mainWnd = null; + console.log(msgStr + 'mainWnd = null'); + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.getMainWindow catch err: ${JSON.stringify(error)}`) + } + mainWnd = data; + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + mainWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + console.log(msgStr + 'mainWnd.show success'); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`) + } + mainWnd.setFullScreen(true, (err, data) => { + console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`) + } + mainWnd.setSystemBarEnable([], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + setTimeout(() => { + ohosWindow.on('systemBarTintChange', systembartintstate => { + console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate)); + console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + setTimeout(() => { + if (flagStatus || flagNav) { + let enable = systembartintstate.regionTint[0].isEnable + let numType = systembartintstate.regionTint[0].type + console.log(msgStr + 'ohosWindow.on isEnable : ' + JSON.stringify(enable)); + console.log(msgStr + 'ohosWindow.on numType : ' + JSON.stringify(numType)); + try { + expect(numType === ohosWindow.WindowType.TYPE_NAVIGATION_BAR || enable).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) + } + } + done(); + }, 3000) + }) + }, 2300) + mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done); + } + flagStatus = true; + flagNav = true; + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + }) + }) + }) + }) + }) + }); + /** + * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_009 + * @tc.name Test setSystemBarEnableTest9 + * @tc.desc Verify that the scene hides both the status bar and the navigation bar. + */ + it('setSystemBarEnableTest9', 0, function (done) { + let caseName = 'setSystemBarEnableTest9'; + let msgStr = 'jsunittest ' + caseName + ' '; + let [flagStatus, flagNav] = [false, false]; + console.log(msgStr + 'begin'); + let mainWnd = null; + console.log(msgStr + 'mainWnd = null'); + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch err: ${JSON.stringify(error)}`) + } + mainWnd = data; + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + mainWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + console.log(msgStr + 'mainWnd.show success'); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`) + } + mainWnd.setFullScreen(true, (err, data) => { + console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setFullScreen', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`) + } + mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable status,navigation JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done); + } + flagStatus = true; + flagNav = true; + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + ohosWindow.on('systemBarTintChange', (systembartintstate) => { + console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate)); + console.log(msgStr + 'ohosWindow.on systemBarTintChange systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + if (flagStatus || flagNav) { + try { + expect(!!systembartintstate).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) + } + done(); + } + }) + mainWnd.setSystemBarEnable([], (err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + }) + }) + }) + }) + }) + }); + /** + * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_010 + * @tc.name Test setSystemBarEnableTest10 + * @tc.desc Verify the scene where illegal values are entered when the navigation bar and status bar are displayed or hidden + */ + it('setSystemBarEnableTest10', 0, function (done) { + let caseName = 'setSystemBarEnableTest10'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let mainWnd = null; + console.log(msgStr + 'mainWnd = null'); + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + console.log(msgStr + 'windowStage.getMainWindow JSON.stringify(!!data)===' + JSON.stringify(!!data)); + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + mainWnd = data; + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + mainWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + console.log(msgStr + 'mainWnd.show success'); + try { + console.log(msgStr + 'mainWnd.show JSON.stringify(!data)===' + JSON.stringify(!data)); + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`) + } + mainWnd.setFullScreen(true, (err, data) => { + console.log(msgStr + 'mainWnd.setFullScreen: ' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); + } + try { + console.log(msgStr + 'mainWnd.setFullScreen JSON.stringify(!data)===' + JSON.stringify(!data)); + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setFullScreen catch error: ${JSON.stringify(error)}`) + } + mainWnd.setSystemBarEnable([], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); + } + try { + console.log(msgStr + 'mainWnd.setSystemBarEnable JSON.stringify(!data)===' + JSON.stringify(!data)); + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + mainWnd.setSystemBarEnable([null, '123'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(data)==' + JSON.stringify(data)); + console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(err)==' + JSON.stringify(err)); + if (err && err.code) { + try { + console.log(msgStr + 'mainWnd.setSystemBarEnable JSON.stringify(err.code)===' + JSON.stringify(err.code)); + expect(err.code === 1003).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [null,123]', done); + } + }) + }) + }) + }) + }) + }); + /** + * @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_004 + * @tc.name Test setSystemBarPropertiesTest1 + * @tc.desc TVerify the scene where the colors of the status bar and navigation bar are set in RGB + */ + it('setSystemBarPropertiesTest4', 0, done => { + let caseName = 'setSystemBarPropertiesTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let cloneColorArr = JSON.parse(JSON.stringify(commonRGBColorArr)); + let compareCount = 0; + let listenerFlag = listenerStatus.ready; + console.log(msgStr + 'begin'); + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + ohosWindow.on('systemBarTintChange', (systemBarData) => { + console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); + if (listenerFlag === listenerStatus.pending) { + try { + expect(!!systemBarData).assertTrue(); + expect(!!systemBarData.regionTint).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + let arrLength = systemBarData.regionTint.length; + for (let i = 0; i < arrLength; i++) { + let tempData = systemBarData.regionTint[i]; + if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { + console.log(msgStr + 'systemBarTintChange compare start!'); + compareCount++; + let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor); + let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); + try { + expect(backgroundIndex === -1).assertTrue(); + expect(contentColorIndex === -1).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + } + } + } + }) + console.log(msgStr + 'tempWnd.on systemBarTintChange finished'); + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + } + let tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); + tempWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.show success'); + tempWnd.setFullScreen(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setFullScreen(true) success'); + tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); + listenerFlag = listenerStatus.pending; + let loopCount = commonRGBColorArr.length + for (let i = 0; i < loopCount; i++) { + let tempColor = commonRGBColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: false, + navigationBarContentColor: tempColor, + }; + tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { + console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarProperties' + tempColor + ' ', done); + } + console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); + }) + } + setTimeout(() => { + console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); + listenerFlag = listenerStatus.finished; + done(); + }, 10000) + }) + }) + }) + }) + }) + /** + * @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_005 + * @tc.name Test setSystemBarPropertiesTest5 + * @tc.desc Verify the scene where the status bar and navigation bar colors are set in hexadecimal form + */ + it('setSystemBarPropertiesTest5', 0, done => { + let caseName = 'setSystemBarPropertiesTest5'; + let msgStr = 'jsunittest ' + caseName + ' '; + let cloneColorArr = { + SBC: JSON.parse(JSON.stringify(commonNUMBERColorArr)), + SCC: JSON.parse(JSON.stringify(commonNUMBERColorArr)), + NBC: JSON.parse(JSON.stringify(commonNUMBERColorArr)), + NCC: JSON.parse(JSON.stringify(commonNUMBERColorArr)) + }; + let compareCount = 0; + let endNum = 0; + let listenerFlag = listenerStatus.ready; + console.log(msgStr + 'begin'); + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + ohosWindow.on('systemBarTintChange', (systemBarData) => { + console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); + if (listenerFlag === listenerStatus.pending) { + try { + expect(!!systemBarData).assertTrue(); + expect(!!systemBarData.regionTint).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + let arrLength = systemBarData.regionTint.length; + for (let i = 0; i < arrLength; i++) { + console.log(msgStr + 'for arrLenght compareCount: ' + compareCount + ' ,i:'+i+' ,arrLength:'+arrLength); + let tempData = systemBarData.regionTint[i]; + if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR) { + console.log(msgStr + 'systemBarTintChange compare start! arrLength= ' + arrLength); + compareCount++; + let backgroundIndex = cloneColorArr.SBC.indexOf(tempData.backgroundColor); + let contentColorIndex = cloneColorArr.SCC.indexOf(tempData.contentColor); + if (backgroundIndex >= 0) { + cloneColorArr.SBC.splice(backgroundIndex, 1); + } else { + console.log(msgStr + 'SBC tempData.backgroundColor:' + JSON.stringify(tempData.backgroundColor)); + } + if (contentColorIndex >= 0) { + cloneColorArr.SCC.splice(contentColorIndex, 1); + } else { + console.log(msgStr + 'SCC tempData.contentColor:' + JSON.stringify(tempData.contentColor)); + } + let ca = cloneColorArr; + let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length + if (compareCount === 18 && !flag) { + console.log(msgStr + 'if compareCount: ' + compareCount + ' ,true flag:' + flag); + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + } else { + console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag); + } + console.log(msgStr + 'compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.SCC.length) + ' ,cloneColorArr.SBC:' + JSON.stringify(cloneColorArr.SBC)); + console.log(msgStr + 'compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.SCC.length) + ' ,cloneColorArr.SCC' + JSON.stringify(cloneColorArr.SCC)); + done(); + } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { + console.log(msgStr + 'systemBarTintChange compare start!'); + compareCount++; + let backgroundIndex = cloneColorArr.NBC.indexOf(tempData.backgroundColor); + let contentColorIndex = cloneColorArr.NCC.indexOf(tempData.contentColor); + if (backgroundIndex >= 0) { + cloneColorArr.NBC.splice(backgroundIndex, 1); + } else { + console.log(msgStr + 'NBC tempData.backgroundColor:' + JSON.stringify(tempData.backgroundColor)); + } + if (contentColorIndex >= 0) { + cloneColorArr.NCC.splice(contentColorIndex, 1); + } else { + console.log(msgStr + 'NCC tempData.contentColor:' + JSON.stringify(tempData.contentColor)); + } + let ca = cloneColorArr; + let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length + if (compareCount === 18 && !flag) { + console.log(msgStr + 'else compareCount: ' + compareCount + ' ,true flag:' + flag); + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + } else { + console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag); + } + console.log(msgStr + 'compareCount: ' + endNum + ' ,compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.NBC.length) + ' ,cloneColorArr.SBC:' + JSON.stringify(cloneColorArr.NBC)); + console.log(msgStr + 'compareCount: ' + endNum + ' ,compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.NCC.length) + ' ,cloneColorArr.SCC' + JSON.stringify(cloneColorArr.NCC)); + endNum = compareCount + done(); + } + } + } + }) + console.log(msgStr + 'tempWnd.on systemBarTintChange finished'); + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + } + let tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); + tempWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.show success'); + tempWnd.setFullScreen(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setFullScreen(true) success'); + tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBatEnable catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); + listenerFlag = listenerStatus.pending; + let loopCount = commonNUMBERColorArr.length + for (let i = 0; i < loopCount; i++) { + console.log(msgStr+'tempWnd.setSystemBarEnable i:'+i); + let tempColor = commonNUMBERColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: true, + navigationBarContentColor: tempColor, + }; + tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { + console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); + if (err && err.code) { + try { + expect(TRUE_FLAG).assertFail(); + } catch (error) { + console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) + } + } + }) + } + }) + }) + }) + }) + }) + /** + * @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_006 + * @tc.name Test setSystemBarPropertiesTest6 + * @tc.desc TVerify the scene where the status bar and navigation bar colors are set as keywords + */ + it('setSystemBarPropertiesTest6', 0, done => { + let caseName = 'setSystemBarPropertiesTest6'; + let msgStr = 'jsunittest ' + caseName + ' '; + let cloneColorArr = JSON.parse(JSON.stringify(commonKEYColorArr)); + let compareCount = 0; + let listenerFlag = listenerStatus.ready; + console.log(msgStr + 'begin'); + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + ohosWindow.on('systemBarTintChange', (systemBarData) => { + console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); + if (listenerFlag === listenerStatus.pending) { + try { + expect(!!systemBarData).assertTrue(); + expect(!!systemBarData.regionTint).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + let arrLength = systemBarData.regionTint.length; + for (let i = 0; i < arrLength; i++) { + let tempData = systemBarData.regionTint[i]; + if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { + console.log(msgStr + 'systemBarTintChange compare start!'); + compareCount++; + let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor); + let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); + try { + expect(backgroundIndex === -1).assertTrue(); + expect(contentColorIndex === -1).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + } + } + } + }) + console.log(msgStr + 'tempWnd.on systemBarTintChange finished'); + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + } + let tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`winsowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); + tempWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.show success'); + tempWnd.setFullScreen(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setFullScreen(true) success'); + tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); + listenerFlag = listenerStatus.pending; + let loopCount = commonRGBColorArr.length + for (let i = 0; i < loopCount; i++) { + let tempColor = commonKEYColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: false, + navigationBarContentColor: tempColor, + }; + tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { + console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); + if (err && err.code) { + try { + expect(TRUE_FLAG).assertFail(); + } catch (error) { + console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) + } + done(); + } + }) + } + setTimeout(() => { + console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); + listenerFlag = listenerStatus.finished; + done(); + }, 10000) + }) + }) + }) + }) + }) + /** + * @tc.number SUB_WINDOW_CREATE_JSAPI_005 + * @tc.name Test create5 + * @tc.desc Scheme of Failed to Create Application Type Window in Stage Mode + */ + it('createTest5', 0, done => { + let caseName = 'createTest5'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin context==' + JSON.stringify(context)); + let loopCount = appWindowTypeArr.length; + console.log(msgStr + 'loopCount: ' + loopCount); + for (let i = 0; i < loopCount; i++) { + let tempType = ohosWindow.WindowType.TYPE_APP; + let windId = 'createTest5' + i; + console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); + ohosWindow.create(context, windId, tempType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + if (err && err.code) { + try { + expect(err.code === 1003).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'ohosWindow.create err.code==' + JSON.stringify(err.code)) + if (i === loopCount - 1) { + done(); + } + } else { + unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); + } + }) + } + }) + /** + * @tc.number SUB_WINDOW_CREATE_JSAPI_006 + * @tc.name Test createTest6 + * @tc.desc Verify the scenario of creating the system type window + */ + it('createTest6', 0, done => { + let caseName = 'createTest6'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let loopCount = systemWindowTypeArr.length; + console.log('jsunittest loopCount: ' + loopCount); + for (let i = 0; i < loopCount; i++) { + let tempType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT; + let windId = 'createTest6' + i; + console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); + ohosWindow.create(context, windId, tempType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); + return; + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + let tempWnd = data + console.log(msgStr + 'ohosWindow.create ' + tempType + ' wnd: ' + tempWnd); + tempWnd.getProperties((err, data) => { + console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.getProperties data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.getProperties', done); + console.log(msgStr + 'tempWnd.getProperties err&&err.code' + JSON.stringify(err)); + return; + } + console.log(msgStr + 'tempWnd.getProperties success, !!data : ' + !!data); + try { + expect(!!data).assertTrue(); + expect(data.type == tempType).assertTrue(); + } catch (error) { + console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + }) + }) + } + done(); + }) + /** + * @tc.number SUB_WINDOW_CREATE_JSAPI_007 + * @tc.name Test createTest7 + * @tc.desc Verify the scenario of creating a window of a type that does not exist + */ + it('createTest7', 0, done => { + let caseName = 'createTest7'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let tempType = 5000; + let windId = 'createTest7'; + console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); + ohosWindow.create(context, windId, tempType, (err, data) => { + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + if (err && err.code) { + try { + expect(err.code === 1003).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + done(); + return; + } + unexpectedError(err, caseName, 'ohosWindow.create', done); + }) + }) + + /** + * @tc.number SUB_WINDOW_CREATE_JSAPI_008 + * @tc.name Test createTest8 + * @tc.desc Verify the scenario of creating a window with duplicate IDs + */ + it('createTest8', 0, done => { + let caseName = 'createTest8'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let windowId = 'sameid' + ohosWindow.create(context, windowId, 1, (err, data) => { + console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err)); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + expect(!!data).assertTrue(); + ohosWindow.create(context, windowId, 1, (err, data) => { + console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err)); + if (err && err.code) { + console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data)); + try { + expect(err.code).assertEqual(1001) + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data)); + } + }) + }) + }) + /** + * @tc.number SUB_WINDOW_ON_OFF_JSAPI_005 + * @tc.name Test listenerTest5 + * @tc.desc Verify whether the change of avoidance area and change monitoring can be turned on normally + */ + it('listenerTest5', 0, function (done) { + let caseName = 'listenerTest5'; + let msgStr = 'jsunittest ' + caseName + ' '; + let listenerOnFlag = listenerStatus.ready; + console.log(msgStr + 'begin'); + let tempWnd = null; + windowStage.getMainWindow((err, data) => { + console.log(msgStr + 'windowStage.getMainWindow err: ' + JSON.stringify(err)); + console.log(msgStr + 'windowStage.getMainWindow data: ' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + tempWnd = data + console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + tempWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.show success'); + tempWnd.setFullScreen(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setFullScreen(true) success'); + tempWnd.on('systemAvoidAreaChange', avoidAreaData => { + console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, avoidAreaData : ' + JSON.stringify(avoidAreaData)); + if (listenerOnFlag === listenerStatus.pending) { + listenerOnFlag = listenerStatus.finished; + try { + expect(!!avoidAreaData).assertTrue(); + } catch (error) { + console.info(`tempWnd.on catch error: ${JSON.stringify(error)}`) + } + } + done(); + }) + tempWnd.setSystemBarEnable([], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success'); + listenerOnFlag = listenerStatus.pending; + }) + tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); + }) + console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished'); + }) + }) + }) + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_003 + * @tc.name Test setWindowTypeTest3 + * @tc.desc Verify the scenario where the normal window type is set + */ + it('setWindowTypeTest3', 0, function (done) { + let caseName = 'setWindowTypeTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'setWindowTypeTest3'; + console.log(msgStr + 'begin'); + let tempWnd = null + let tempTypeArr = []; + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + try { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd); + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`ohosWindwo.create catch error: ${JSON.stringify(error)}`) + } + let loopCount1 = systemWindowTypeArr; + console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount1)) + getData(0, loopCount1.length) + + function getData(i, length) { + let tempType = ohosWindow.WindowType[loopCount1[i]]; + console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' start'); + tempTypeArr.push(tempType); + tempWnd.setWindowType(tempType, (err, data) => { + try { + console.log(msgStr + 'tempWnd.setWindowType i: ' + i); + console.log(msgStr + 'tempWnd.setWindowType err: ' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setWindowType data: ' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.setWindowType !data: ' + !data); + if (!data) { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.getProperties start'); + tempWnd.getProperties((err, dataProper) => { + try { + console.log(msgStr + 'tempWnd.getProperties err: ' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.getProperties dataProper: ' + JSON.stringify(dataProper)); + console.log(msgStr + 'tempWnd.getProperties !!dataProper: ' + !!dataProper); + try { + expect(!!dataProper).assertTrue(); + } catch (error) { + console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + if (!!dataProper) { + console.log(msgStr + 'tempWnd.getProperties true tempTypeArr: ' + JSON.stringify(tempTypeArr)); + console.log(msgStr + 'tempWnd.getProperties true i: ' + i); + tempTypeArr.splice(tempTypeArr.findIndex(item => item === dataProper.type), 1); + console.log(msgStr + 'tempWnd.getProperties true tempTypeArr.length: ' + tempTypeArr.length); + console.log(msgStr + 'tempWnd.getProperties true loopCount1.length: ' + loopCount1.length); + console.log(msgStr + 'tempWnd.getProperties true tempTypeArr.length + 1: ' + Number(tempTypeArr.length + 1)); + console.log(msgStr + 'tempWnd.getProperties true (loopCount1.length - i): ' + (loopCount1.length - i)); + console.log(msgStr + 'tempWnd.getProperties true (tempTypeArr.length + 1): ' + (tempTypeArr.length + 1)); + try { + expect(tempTypeArr.length === 0).assertTrue(); + if (++i < length) { + getData(i, length) + console.log(msgStr + 'jixuzhixing i: ' + i); + } + } catch (error) { + console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + if (i == loopCount1.length - 1) { + console.log(msgStr + 'tempWnd.getProperties i=' + i + ' , loopCount1.length-1==' + loopCount1.length); + done(); + } + } + } catch (err) { + console.log(msgStr + 'tempWnd.getProperties catch err: ' + JSON.stringify(err)); + } + }) + } + console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' end'); + } catch (err) { + console.log(msgStr + 'tempWnd.setWindowType catch err: ' + JSON.stringify(err)); + } + }) + } + } + } catch (err) { + console.log(msgStr + 'ohosWindow.create catch err: ' + JSON.stringify(err)); + } + }) + }) + /** + * @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_004 + * @tc.name Test setWindowTypeTest4 + * @tc.desc Verify the scene of setting illegal window type + */ + it('setWindowTypeTest4', 0, function (done) { + let caseName = 'setWindowTypeTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let changedWndType = null; + let windowId = 'setWindowTypeTest4'; + console.log(msgStr + 'begin'); + let tempWnd = null + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + tempWnd.setWindowType(changedWndType, (err, data) => { + console.log(msgStr + 'tempWnd.setWindowType err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setWindowType data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.setWindowType !!data' + !!data); + if (!!data) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + try { + expect(err.code == 1003).assertTrue(); + } catch (error) { + console.info(`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`) + } + done(); + } + }) + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + }) + }) + /** + * @tc.number SUB_WINDOW_DESTROY_JSAPI_002 + * @tc.name Test destroyTest2 + * @tc.desc Verification window destruction scenario + */ + it('destroyTest2', 0, function (done) { + let caseName = 'destroyTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'destroyTest2'; + console.log(msgStr + 'begin'); + let tempWnd = null + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + tempWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + ohosWindow.find(windowId, (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(err.code == 1001).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + }) + } + }) + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + }) + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_007 + * @tc.name Test loadContentTest7 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest7', 0, function (done) { + let caseName = 'loadContentTest7'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'loadContentTest7'; + console.log(msgStr + 'begin'); + let tempWnd = null + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + tempWnd.loadContent('pages/index', (err, data) => { + console.log(msgStr + 'tempWnd.loadContent err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.loadContent data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.loadContent !data' + !data); + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.loadContent', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) + } + done(); + } + }) + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + }) + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_008 + * @tc.name Test loadContentTest8 + * @tc.desc Verify the scenario of loading a page that does not exist + */ + it('loadContentTest8', 0, function (done) { + let caseName = 'loadContentTest8'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'loadContentTest8'; + console.log(msgStr + 'begin'); + let tempWnd = null + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + tempWnd.loadContent(null, (err, data) => { + console.log(msgStr + 'tempWnd.loadContent err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.loadContent data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.loadContent !!data' + !!data); + if (err && err.code) { + try { + expect(err.code === 1003).assertTrue(); + } catch (error) { + console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + unexpectedError(err, caseName, 'tempWnd.loadContent', done); + } + }) + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + }) + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_009 + * @tc.name Test loadContentTest9 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest9', 0, function (done) { + let caseName = 'loadContentTest9'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + windowStage.loadContent('pages/index/index.ets', (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.loadContent', done); + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data)); + } + done(); + }); + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_010 + * @tc.name Test loadContentTest10 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest10', 0, function (done) { + let caseName = 'loadContentTest10'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + try { + windowStage.loadContent(null, (err, data) => { + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); + try { + expect(false).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + }); + } catch (err) { + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets) catch err' + JSON.stringify(err)); + try { + expect(err.code == 401).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + } + console.log(msgStr + 'end'); + done(); + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_011 + * @tc.name Test loadContentTest11 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest11', 0, async function (done) { + let caseName = 'loadContentTest11'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + windowStage.loadContent('pages/index/index.ets', abilityStorage, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.loadContent', done); + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data)); + } + done(); + }); + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_012 + * @tc.name Test loadContentTest12 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest12', 0, function (done) { + let caseName = 'loadContentTest12'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + try { + windowStage.loadContent(null, abilityStorage, (err, data) => { + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); + try { + expect(false).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + }); + } catch (err) { + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets) catch err ' + JSON.stringify(err)); + try { + expect(err.code === 401).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + } + done(); + }) + /** + * @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_003 + * @tc.name Test createSubWindowTest3 + * @tc.desc Verify the scenario of creating an auxiliary window + */ + it('createSubWindowTest3', 0, function (done) { + let caseName = 'createSubWindowTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + windowStage.createSubWindow('createSubWindowTest3', (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.createSubWindow', done); + console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest3) err=' + JSON.stringify(err)); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.createSubWindow end data=' + JSON.stringify(data)); + } + done(); + }); + }) + /** + * @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_004 + * @tc.name Test createSubWindowTest4 + * @tc.desc Verify the scene of entering illegal values to create an auxiliary window + */ + it('createSubWindowTest4', 0, function (done) { + let caseName = 'createSubWindowTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + try { + windowStage.createSubWindow(null, (err, data) => { + console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err)); + try { + expect(false).assertTrue(); + } catch (error) { + console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`) + } + }); + } catch (err) { + try { + expect(err.code === 401).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.createSubWindow(null) catch err=' + JSON.stringify(err)); + } + done(); + }) + /** + * @tc.number SUB_WINDOW_GETSUBWINDOW_JSAPI_002 + * @tc.name Test getSubWindowTest2 + * @tc.desc Verify the scene of obtaining all auxiliary sub windows + */ + it('getSubWindowTest2', 0, async function (done) { + let caseName = 'getSubWindowTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + windowStage.getSubWindow((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.getSubWindow', done); + console.log(msgStr + 'windowStage.getSubWindow(null) err=' + JSON.stringify(err)); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.getSubWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.getSubWindow end data=' + JSON.stringify(data)); + } + done(); + }); + }) + /** + * @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_002 + * @tc.name Test setPrivacyModeTest2 + * @tc.desc Verify the scene where the application sub window is set as a security layer + */ + it('setPrivacyModeTest2', 0, async function (done) { + let caseName = 'setPrivacyModeTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow)); + let mainWnd = null; + ohosWindow.create(context, 'setPrivacyModeTest2', ohosWindow.WindowType.TYPE_SYSTEM_ALERT, (err, data) => { + if (err && err.code) { + console.log(msgStr + 'ohosWindow.create fail err:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + try { + expect(data != null).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'ohosWindow.create success data' + data); + mainWnd = data; + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data)); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + mainWnd.setPrivacyMode(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); + console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setPrivacyMode catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data)); + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data)); + try { + expect(data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + mainWnd.setPrivacyMode(false, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); + console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setPrivacyMode catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data)); + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data)); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + } + done(); + }) + } + }); + } + }) + } + }); + } + }) + } + }) + }) + /** + * @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_003 + * @tc.name Test setPrivacyModeTest3 + * @tc.desc Verify that the auxiliary window is set as the security layer + */ + it('setPrivacyModeTest3', 0, async function (done) { + let caseName = 'setPrivacyModeTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow)); + let mainWnd = null; + windowStage.createSubWindow('setPrivacyModeTest3', (err, data) => { + if (err && err.code) { + console.log(msgStr + 'windowStage.createSubWindow fail err:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + try { + expect(data != null).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.createSubWindow success data' + data); + mainWnd = data; + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data)); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + mainWnd.setPrivacyMode(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); + console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data)); + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data)); + try { + expect(data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + mainWnd.setPrivacyMode(false, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); + console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data)); + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data)); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + done(); + }) + } + }); + } + }) + } + }); + } + }) + } + }) + }) + /** + * @tc.number SUB_WINDOW_SETDENSITTYDPI_JSAPI_002 + * @tc.name Test setDensityDpiTest2 + * @tc.desc Verify Sets the screen pixel + */ + it('setDensityDpiTest2', 0, async function (done) { + let caseName = 'setDensityDpiTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let screens = await screenManager.getAllScreens().catch(errScreen => { + unexpectedError(errScreen, caseName, 'screenManager.getAllScreen', done); + }) + console.log(msgStr + 'screenManager.getAllScreen' + JSON.stringify(screens)); + try { + expect(!!screens).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + let currentDeviceDefaultDpi; + let currentDeviceDefault = null; + display.getDefaultDisplay(async (err, data) => { + if (err.code) { + console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); + currentDeviceDefault = data; + currentDeviceDefaultDpi = parseInt(currentDeviceDefault.densityDPI) + let dpiItem = [-80, 80, 1000, 160, 0, 320, 188.88, 0, 640, 300, currentDeviceDefaultDpi]; + for (let i = 0;i < dpiItem.length; i++) { + await sleep(1000); + screens[0].setDensityDpi(dpiItem[i], (errDpi, dataDpi) => { + if (errDpi.code) { + console.error('Failed to set DensityDpi. Cause: ' + JSON.stringify(err) + dpiItem[i]); + return; + } + console.log(msgStr + 'screen.setDensityDpi success set DPI ' + dpiItem[i]); + display.getDefaultDisplay((error, result) => { + if (error.code) { + console.error(msgStr + 'screen.setDensityDpi display.getDefaultDisplay failed'); + return; + console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay' + JSON.stringify(result)); + let isEqual = Number(result.densityDPI) == parseInt(dpiItem[i]) + console.log(msgStr + 'same ? ' + isEqual) + try { + expect(isEqual).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + }) + }) + } + }); + console.log(msgStr + 'done '); + done(); + }) + /** + * @tc.number SUB_WINDOW_SETPREFERREDORIENTATION_JSAPI_002 + * @tc.name Test setPreferredOrientationTest2 + * @tc.desc Sets the display direction property of the window + */ + it('setPreferredOrientationTest2', 0, async function (done) { + let caseName = 'setPreferredOrientationTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let mainWin = await windowStage.getMainWindow().catch(err => { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + }); + console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); + try { + expect(!!mainWin).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + let num = 0 + let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED', + 'LANDSCAPE_INVERTED', 'AUTO_ROTATION', 'AUTO_ROTATION_PORTRAIT', 'AUTO_ROTATION_LANDSCAPE', + 'AUTO_ROTATION_RESTRICTED', 'AUTO_ROTATION_PORTRAIT_RESTRICTED', 'AUTO_ROTATION_LANDSCAPE_RESTRICTED', 'LOCKED', 'UNSPECIFIED']; + for (let i = 0;i < orientationItem.length; i++) { + await sleep(1000); + let orientation = ohosWindow.Orientation[orientationItem[i]] + await mainWin.setPreferredOrientation(orientation, (err, data) => { + if (err && err.code) { + console.log(msgStr + 'window.setPreferredOrientation failed set error' + orientation); + } + num++ + if (num == orientationItem.length) done(); + console.log(msgStr + 'success set window.setPreferredOrientation ' + orientation + JSON.stringify(data)); + }) + } + }) + /** + * @tc.number SUB_WINDOW_SETFORBIDSPLITMOVE_JSAPI_002 + * @tc.name Test setForbidSplitMoveTest2 + * @tc.desc Sets whether Windows are forbidden to move in split screen mode + */ + it('setForbidSplitMoveTest2', 0, async function (done) { + let caseName = 'setForbidSplitMoveTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let mainWin = await windowStage.getMainWindow().catch(err => { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + }); + console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); + try { + expect(!!mainWin).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + await mainWin.setForbidSplitMove(true, (err, data) => { + if (err.code) { + console.log(msgStr + 'failed set window.setForbidSplitMove drag is prohibited'); + return; + } + console.log(msgStr + 'success set window.setForbidSplitMove drag is prohibited' + JSON.stringify(data)); + }) + await mainWin.setForbidSplitMove(false, (err, data) => { + if (err.code) { + console.log(msgStr + 'failed set window.setForbidSplitMove you can drag it now'); + return; + } + console.log(msgStr + 'success set window.setForbidSplitMove you can drag it now' + JSON.stringify(data)); + }) + console.log(msgStr + 'done '); + done(); + }) + /** + * @tc.number SUB_WINDOW_SNAPSHOT_JSAPI_002 + * @tc.name Test snapshotTest2 + * @tc.desc Scenario of screenshot of verification window + */ + it('snapshotTest2', 0, async function (done) { + let caseName = 'snapshotTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let mainWin = await windowStage.getMainWindow().catch(err => { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + }); + console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); + try { + expect(!!mainWin).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + await mainWin.snapshot((err, data) => { + if (err && err.code) { + console.log(msgStr + 'snapshot err.code:' + JSON.stringify(err.code)); + return; + } + console.log(msgStr + 'snapshot success data:' + JSON.stringify(data)); + mainWin.on('snapshot', (err, data) => { + if (err && err.code) { + console.log(msgStr + 'mainWin.on(snapshot) err.code:' + JSON.stringify(err.code)); + return; + } + mainWin.off('snapshot', (err, data) => { + if (err && err.code) { + console.log(msgStr + 'mainWin.off(snapshot) err.code:' + JSON.stringify(err.code)); + return; + } + }) + }) + }) + done(); + }) + /** + * @tc.number SUB_WINDOW_DIALOGTARGETTOUCH_JSAPI_002 + * @tc.name Test dialogTargetTouchTest2 + * @tc.desc Verify the scenario of opening modal window + */ + it('dialogTargetTouchTest2', 0, done => { + let caseName = 'dialogTargetTouchTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin context==' + JSON.stringify(context)); + let tempType = ohosWindow.WindowType.TYPE_DIALOG + ohosWindow.create(context, 'dialogTargetTouchTest2', tempType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } else { + let dialogTargetTouchTest2Win = data + try { + expect(!!dialogTargetTouchTest2Win).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + dialogTargetTouchTest2Win.destroy(); + done(); + } + }) + }) + /** + * @tc.number SUB_WINDOW_ANIMATIONFORSHOWN_JSAPI_002 + * @tc.name Test animationForShownTest2 + * @tc.desc Verify window custom animation configuration of the scene + */ + it('animationForShownTest2', 0, async function (done) { + let caseName = 'animationForShownTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin context==' + JSON.stringify(context)); + console.log(msgStr + 'begin ohosWindow==' + JSON.stringify(ohosWindow)); + let wndId = 'animationForShownTest2'; + let baseType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT; + let tempWnd = null; + ohosWindow.create(context, wndId, baseType, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); + } else { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + tempWnd); + let controller = tempWnd.getTransitionController(); + controller.animationForShown = (context: ohosWindow.TransitionContext) => { + let toWindow = context.toWindow + animateTo({ + duration: 1000, + tempo: 0.5, + curve: Curve.EaseInOut, + delay: 0, + iterations: 1, + playMode: PlayMode.Normal, + }, () => { + var obj: ohosWindow.TranslateOptions; + obj.x = 100.0; + obj.y = 0.0; + obj.z = 0.0; + toWindow.translate(obj); + console.info(msgStr + 'toWindow translate end'); + } + ) + context.completeTransition(true) + console.info(msgStr + 'complete transition end'); + } + done(); + } + }); + + }) + /** + * @tc.number SUB_WINDOW_GETCUTOUTINFO_JSAPI_002 + * @tc.name Test getCutoutInfoTest2 + * @tc.desc Obtain information about unavailable screen areas such as the hole screen, fringe screen, and waterfall screen + */ + it('getCutoutInfoTest2', 0, async function (done) { + let caseName = 'getCutoutInfoTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin context==' + JSON.stringify(context)); + let dpClass = display.getDefaultDisplaySync(); + try { + expect(!!dpClass).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + dpClass.getCutoutInfo((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'displayClass.getCutoutInfo', done); + } else { + console.info(msgStr + 'Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data)); + done(); + } + }) + }) + /** + * @tc.number SUB_WINDOW_SHOWWITHANIMATION_JSAPI_002 + * @tc.name Test showWithAnimationTest2 + * @tc.desc Displays the current window, playing an animation in the process + */ + it('showWithAnimationTest2', 0, async function (done) { + let caseName = 'showWithAnimationTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin context==' + JSON.stringify(context)); + let wndId = 'showWithAnimationTest2'; + let baseType = ohosWindow.WindowType.TYPE_FLOAT; + ohosWindow.create(context, wndId, baseType, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); + } else { + let tempWnd = data; + console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + JSON.stringify(tempWnd)); + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + tempWnd.showWithAnimation((error, animationData) => { + if (error && error.code) { + unexpectedError(error, caseName, 'Failed to show the window with animation', done); + } else { + console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(animationData)); + done(); + } + }) + } + }) + }) + /** + * @tc.number SUB_WINDOW_HIDEWITHANIMATION_JSAPI_002 + * @tc.name Test hideWithAnimationTest2 + * @tc.desc Hide the current window and play an animation in the process + */ + it('hideWithAnimationTest2', 0, async function (done) { + let caseName = 'hideWithAnimationTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin context==' + JSON.stringify(context)); + let wndId = 'hideWithAnimationTest2'; + let baseType = ohosWindow.WindowType.TYPE_FLOAT; + ohosWindow.create(context, wndId, baseType, (creare_err, tempWnd) => { + if (creare_err && creare_err.code) { + unexpectedError(creare_err, caseName, 'ohosWindow.create ' + baseType, done); + } + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + ohosWindow.find(wndId, (findErr, findWnd) => { + if (findErr && findErr.code) { + unexpectedError(findErr, caseName, 'Failed to hide the window with animation', done); + } else { + findWnd.hideWithAnimation((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'Failed to hide the window with animation', done); + } else { + console.info('Succeeded in hiding the window with animation. Data: ' + JSON.stringify(data)); + done(); + } + }) + } + }) + }) + }) + }) +} -- GitLab