From a952eed7c48891c440deb7216bfa9ec4a9f8ff95 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: Fri, 4 Nov 2022 21:28:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0try=20catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 华华小仙女 --- ...displayAndWindowRefactorInterface.test.ets | 1142 ++++++++++------- .../src/main/ets/test/windowCallback.test.ets | 1011 +++++++++++---- .../ets/test/windowRefactorInterface.test.ets | 803 +++++++----- 3 files changed, 1883 insertions(+), 1073 deletions(-) diff --git a/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets b/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets index 1ccee057a..7b5a5f9f4 100644 --- a/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets @@ -42,7 +42,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 'TYPE_VOLUME_OVERLAY': 6, 'TYPE_NAVIGATION_BAR': 7, 'TYPE_FLOAT': 8, -// 'TYPE_FLOAT_CAMERA': 9 + // 'TYPE_FLOAT_CAMERA': 9 } var windowLayoutModeArr = []; var windowLayoutModeDic = { @@ -104,7 +104,12 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta function unexpectedError(error, caseName, apiName, done) { let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; console.log(msgStr + JSON.stringify(error)); - expect(TRUE_FLAG).assertFail(); + try { + + expect(TRUE_FLAG).assertFail(); + } catch (error) { + console.info(`unexpectedError catch error: ${JSON.stringify(error)}`) + } done(); } @@ -125,7 +130,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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)); + 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(); @@ -136,12 +141,12 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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].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)); + console.error(msgStr + 'Failed to obtain all the display objects. Code: ' + JSON.stringify(err)); expect().assertFail(); done(); }); @@ -157,12 +162,16 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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)); - expect().assertFail(); + 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)); + 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(); @@ -172,7 +181,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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].scaledDensity != null).assertTrue(); expect(data[0].xDPI != null).assertTrue(); expect(data[0].yDPI != null).assertTrue(); done(); @@ -190,14 +199,20 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'begin'); let loopCount = systemWindowTypeDicArr.length; console.log(msgStr + 'loopCount: ' + loopCount); - let num =0 + 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 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); @@ -205,10 +220,11 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'ohosWindow.createWindow ' + tempType + 'finished, wnd: ' + JSON.stringify(tempWnd)); expect(!!tempWnd).assertTrue(); num++; - if(num==loopCount) done(); + if (num == loopCount) done(); } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); - }; + } + ; } }) @@ -222,14 +238,16 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); let windowId = 'createWindowSameidsTest2' - let windowConfig = {name: windowId, windowType: 1, ctx: context}; - try{ + 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{ + 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) @@ -237,11 +255,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta }) 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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** @@ -258,17 +278,25 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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{ + 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)); - expect(!!data).assertTrue(); - try{ + 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) { @@ -279,13 +307,15 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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)); + } + ; }) } catch (exception) { - console.error(msgStr +'Failed to create the window. Cause: ' + JSON.stringify(exception)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_005 @@ -301,14 +331,20 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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{ + 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; } - expect(!!data).assertTrue(); + 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 { @@ -317,12 +353,14 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta expect(proData.type == tempType).assertTrue(); done(); } catch (exception) { - console.error(msgStr +'Failed to obtain the window properties. Cause: ' + JSON.stringify(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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_006 @@ -334,35 +372,47 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); let windowId = 'createWindowSameidTest6' - let winsowConfig = {name: windowId, windowType:1, ctx: context}; - try{ + 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 } - expect(!!data).assertTrue(); - try{ + 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)); - expect(err.code).assertEqual(1300002) + 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)); + } + ; }) } catch (exception) { - console.error(msgStr +'Failed to create the window. Cause: ' + JSON.stringify(exception)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** @@ -373,7 +423,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('getWindowAvoidAreaTest1', 0, async function (done) { let caseName = 'getWindowAvoidAreaTest1'; let msgStr = 'jsunittest ' + caseName + ' '; - try{ + try { let tempWnd = windowStage.getMainWindowSync(); expect(!!tempWnd).assertTrue(); try { @@ -387,13 +437,15 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta expect(avoidArea.leftRect != null).assertTrue(); done(); } catch (exception) { - console.error(msgStr +'Failed to obtain the area. Cause:' + JSON.stringify(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)); - }; + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** @@ -404,7 +456,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('getWindowAvoidAreaTest2', 0, async function (done) { let caseName = 'getWindowAvoidAreaTest2'; let msgStr = 'jsunittest ' + caseName + ' '; - try{ + try { let tempWnd = windowStage.getMainWindowSync(); expect(tempWnd != null).assertTrue(); try { @@ -418,14 +470,16 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta expect(avoidArea.leftRect != null).assertTrue(); done(); } catch (exception) { - console.error(msgStr +'Failed to obtain the area. Cause:' + JSON.stringify(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)); - }; + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_003 @@ -435,7 +489,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('getWindowAvoidAreaTest3', 0, async function (done) { let caseName = 'getWindowAvoidAreaTest3'; let msgStr = 'jsunittest ' + caseName + ' '; - try{ + try { let tempWnd = windowStage.getMainWindowSync(); expect(!!tempWnd).assertTrue(); try { @@ -449,13 +503,15 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta expect(avoidArea.leftRect != null).assertTrue(); done(); } catch (exception) { - console.error(msgStr +'Failed to obtain the area. Cause:' + JSON.stringify(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)); - }; + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_004 @@ -465,7 +521,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('getWindowAvoidAreaTest4', 0, async function (done) { let caseName = 'getWindowAvoidAreaTest4'; let msgStr = 'jsunittest ' + caseName + ' '; - try{ + try { let tempWnd = windowStage.getMainWindowSync(); expect(!!tempWnd).assertTrue(); try { @@ -479,13 +535,15 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta expect(avoidArea.leftRect != null).assertTrue(); done(); } catch (exception) { - console.error(msgStr +'Failed to obtain the area. Cause:' + JSON.stringify(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)); - }; + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_GETWINDOWPROPERTIES_JSAPI_001 @@ -495,34 +553,36 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('getWindowPropertiesTest1', 0, async function (done) { let caseName = 'getWindowPropertiesTest1'; let msgStr = 'jsunittest ' + caseName + ' '; - try{ + try { let tempWnd = windowStage.getMainWindowSync(); expect(!!tempWnd).assertTrue(); try { let data = tempWnd.getWindowProperties(); - console.log(msgStr + 'ohosWindow.getWindowProperties ' + JSON.stringify(data)); + 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.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.isRoundCorner != null).assertTrue(); expect(data.isPrivacyMode != null).assertTrue(); done(); } catch (exception) { - console.error(msgStr +'Failed to obtain the window properties. Cause: ' + JSON.stringify(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)); - }; + console.error(msgStr + 'try catch Failed to obtain the main window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_GETLASTWINDOW_JSAPI_001 @@ -533,17 +593,18 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let caseName = 'getLastWindowTest1'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); - let proData=null - try{ - let lastWindow = await ohosWindow.getLastWindow(context).catch((err)=>{ + 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)); - }; + } catch (exception) { + console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_GETLASTWINDOW_JSAPI_002 @@ -566,7 +627,8 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta }) } catch (exception) { console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); - }; + } + ; }) /** * @tc.number SUB_WINDOW_SHOWWINDOW_JSAPI_001 @@ -579,24 +641,27 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'begin'); let baseWndType = 1; let windowId = 'showWindowTest1'; - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; - let tempWnd =null; - try{ + 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)); + 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)); + }).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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SHOWWINDOW_JSAPI_002 @@ -609,28 +674,35 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'begin'); let baseWndType = 1; let windowId = 'showWindowTest2'; - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - try{ + 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; } - expect(!!create_data).assertTrue(); + 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)); + 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)); + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_001 @@ -643,28 +715,32 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'moveWindowToTest1'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; + 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)); + 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.'); + 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)); + }).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)); + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_002 @@ -677,28 +753,32 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'moveWindowToTest2'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; + 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)); + 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.'); + 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)); + }).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)); + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_003 @@ -711,28 +791,32 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'moveWindowToTest3'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; + 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)); + 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.'); + 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)); + }).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)); + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_004 @@ -745,28 +829,32 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'moveWindowToTest4'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; + 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)); + 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.'); + 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)); + }).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)); + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_005 @@ -779,31 +867,35 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'begin'); let baseWndType = 1; let windowId = 'moveWindowToTest5'; - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - try{ + 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{ + try { create_data.moveWindowTo(300, 300, (err, data) => { if (err.code) { - console.error(msgStr +'Failed to move the window. Cause:' + JSON.stringify(err)); + 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)); + 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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_006 @@ -816,31 +908,35 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'begin'); let baseWndType = 1; let windowId = 'moveWindowToTest6'; - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - try{ + 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{ + try { create_data.moveWindowTo(100, 50, (err, data) => { if (err.code) { - console.error(msgStr +'Failed to move the window. Cause:' + JSON.stringify(err)); + 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)); + 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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_007 @@ -853,31 +949,35 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'begin'); let baseWndType = 1; let windowId = 'moveWindowToTest7'; - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - try{ + 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{ + try { create_data.moveWindowTo(20000, 20000, (err, data) => { if (err.code) { - console.error(msgStr +'Failed to move the window. Cause:' + JSON.stringify(err)); + 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)); + 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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_008 @@ -890,31 +990,35 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'begin'); let baseWndType = 1; let windowId = 'moveWindowToTest8'; - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - try{ + 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{ + try { create_data.moveWindowTo(-200, -200, (err, data) => { if (err.code) { - console.error(msgStr +'Failed to move the window. Cause:' + JSON.stringify(err)); + 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)); + 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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_RESIZE_JSAPI_001 @@ -927,28 +1031,32 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'resizeTest1'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; - let tempWnd=null; - try{ + 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)); + 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)); + }).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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_RESIZE_JSAPI_002 @@ -961,28 +1069,32 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'resizeTest2'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; - let tempWnd=null; - try{ + 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)); + 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)); + }).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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_RESIZE_JSAPI_003 @@ -995,31 +1107,35 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'resizeTest3'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; - let tempWnd=null; - try{ + 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)); + 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)); + }).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)); + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_RESIZE_JSAPI_004 @@ -1032,31 +1148,35 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'resizeTest4'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; - let tempWnd=null; - try{ + 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)); + 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)); + }).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)); + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_RESIZE_JSAPI_005 @@ -1069,32 +1189,36 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'resizeTest5'; console.log(msgStr + 'begin'); - let windowConfig = {name: windowId, windowType: baseWndType, ctx: context}; - let tempWnd=null; - try{ + 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)); + 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)); + }).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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_RESIZE_JSAPI_006 @@ -1107,8 +1231,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'begin'); let baseWndType = 1; let windowId = 'resizeTest6'; - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - try{ + 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) { @@ -1118,20 +1244,22 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta try { create_data.resize(200, 200, (err) => { if (err.code) { - console.error(msgStr +'Failed to change the window size. Cause:' + JSON.stringify(err)); + 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.'); + 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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_RESIZE_JSAPI_007 @@ -1146,8 +1274,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let windowId = 'resizeTest7'; let width = 100; let height = 100; - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - try{ + 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) { @@ -1160,22 +1290,24 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta try { create_data.resize(width, height, (err) => { if (err.code) { - console.error(msgStr +'Failed to change the window size. Cause:' + JSON.stringify(err)); + 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.'); + 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)); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_DESTROYWINDOW_JSAPI_001 @@ -1188,32 +1320,36 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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{ + 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.'); + 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)); + 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)); + } + ; + }).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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_DESTROYWINDOW_JSAPI_002 @@ -1226,35 +1362,43 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'destroyWindowTest2'; console.log(msgStr + 'begin'); - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - try{ + 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; } - expect(!!create_data).assertTrue(); + 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(); - }; + 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)); - }; + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_001 @@ -1264,29 +1408,31 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('setWindowSystemBarEnableTest1', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest1'; let msgStr = 'jsunittest ' + caseName + ' '; - let wnd=null; - try{ - wnd = await ohosWindow.getLastWindow(context).catch((err)=>{ + 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.'); + 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)); + }).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)); - }; + 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)); - }; + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_002 @@ -1296,29 +1442,31 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('setWindowSystemBarEnableTest2', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest2'; let msgStr = 'jsunittest ' + caseName + ' '; - let wnd=null; - try{ - wnd = await ohosWindow.getLastWindow(context).catch((err)=>{ + 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.'); + 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)); + }).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)); - }; + 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)); - }; + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_003 @@ -1328,29 +1476,31 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('setWindowSystemBarEnableTest3', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest3'; let msgStr = 'jsunittest ' + caseName + ' '; - let wnd=null; - try{ - wnd = await ohosWindow.getLastWindow(context).catch((err)=>{ + 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.'); + 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)); + }).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)); - }; + 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)); - }; + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_004 @@ -1360,29 +1510,31 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('setWindowSystemBarEnableTest4', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest4'; let msgStr = 'jsunittest ' + caseName + ' '; - let wnd=null; - try{ - wnd = await ohosWindow.getLastWindow(context).catch((err)=>{ + 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.'); + 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)); + }).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)); - }; + 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)); - }; + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_005 @@ -1395,19 +1547,21 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'setWindowSystemBarEnableTest5'; console.log(msgStr + 'begin'); - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - let wnd=null; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let wnd = null; try { - wnd = await ohosWindow.getLastWindow(context).catch((err)=>{ + 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{ + try { wnd.setWindowSystemBarEnable(['status', 'navigation'], (err) => { - console.log(msgStr +'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen(true) callback begin'); + 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)); + console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen callback fail' + JSON.stringify(err)); expect().assertFail(); done(); } else { @@ -1416,11 +1570,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta } }) } catch (exception) { - console.error(msgStr +' try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(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)); - }; + console.error(msgStr + 'try catch Failed to get the last window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_006 @@ -1433,19 +1589,21 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let baseWndType = 1; let windowId = 'setWindowSystemBarEnableTest6'; console.log(msgStr + 'begin'); - let winsowConfig = {name: windowId, windowType:baseWndType, ctx: context}; - let wnd=null; + let winsowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let wnd = null; try { - wnd = await ohosWindow.getLastWindow(context).catch((err)=>{ + 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{ + try { wnd.setWindowSystemBarEnable([], (err) => { - console.log(msgStr +'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen(true) callback begin'); + 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)); + console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen callback fail' + JSON.stringify(err)); expect().assertFail(); done(); } else { @@ -1454,11 +1612,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta } }) } catch (exception) { - console.error(msgStr +' try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(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)); - }; + console.error(msgStr + 'try catch Failed to get the last window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_003 @@ -1472,10 +1632,12 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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)=> { + 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) => { @@ -1483,11 +1645,12 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta expect(err.code === 401).assertTrue(); done(); }); - }catch (exception) { + } 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 @@ -1501,20 +1664,27 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let tempType = 5000; let windId = 'createTest7'; console.log(msgStr + 'ohosWindow.createWindow ' + tempType + ' start'); - let winsowConfig = {name: windId, windowType:tempType, ctx: context}; - try{ + 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)); - expect(err.code === 401).assertTrue(); + 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)); + 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 @@ -1524,36 +1694,38 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('setWindowLayoutFullScreenTest1', 0, async function (done) { let caseName = 'setWindowLayoutFullScreenTest1'; let msgStr = 'jsunittest ' + caseName + ' '; - let wnd=null; - try{ + let wnd = null; + try { wnd = windowStage.getMainWindowSync(); - console.log(msgStr +'ohosWindow.getLastWindow ' + JSON.stringify(wnd)); + 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.'); + 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) { + } 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)); + }).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)); - }; + 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 @@ -1563,35 +1735,37 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('setWindowLayoutFullScreenTest2', 0, async function (done) { let caseName = 'setWindowLayoutFullScreenTest2'; let msgStr = 'jsunittest ' + caseName + ' '; - let wnd=null; - try{ + 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.'); + 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) { + } 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)); + }).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)); - }; + 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)); - }; + console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_003 @@ -1601,39 +1775,46 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('setWindowLayoutFullScreenTest3', 0, async function (done) { let caseName = 'setWindowLayoutFullScreenTest3'; let msgStr = 'jsunittest ' + caseName + ' '; - let wnd=null; + let wnd = null; try { wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - let isLayoutFullScreen= true; + 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)); - expect().assertFail(); + 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{ + 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)); + 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)); + 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)); - }; + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to get the main window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_004 @@ -1643,39 +1824,46 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta it('setWindowLayoutFullScreenTest4', 0, async function (done) { let caseName = 'setWindowLayoutFullScreenTest4'; let msgStr = 'jsunittest ' + caseName + ' '; - let wnd=null; + let wnd = null; try { wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - let isLayoutFullScreen= false; + 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)); - expect().assertFail(); + 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{ + 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)); + 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)); + 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)); - }; + } + ; + } catch (exception) { + console.error(msgStr + 'Failed to create the main window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_001 @@ -1684,10 +1872,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta */ it('setWindowModeTest1', 0, function (done) { //['UNDEFINED','FULLSCREEN','PRIMARY','SECONDARY','FLOATING'] - let windowModeArr=['FULLSCREEN','PRIMARY','SECONDARY','FLOATING'] + let windowModeArr = ['FULLSCREEN', 'PRIMARY', 'SECONDARY', 'FLOATING'] let caseName = 'setWindowModeTest1'; let msgStr = 'jsunittest ' + caseName + ' '; - let sumCount=0 + let sumCount = 0 try { let tempWnd = windowStage.getMainWindowSync(); expect(!!tempWnd).assertTrue(); @@ -1698,23 +1886,25 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let tempType = ohosWindow.WindowMode[loopCount[i]]; console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); try { - tempWnd.setWindowMode(tempType).then(()=> { + 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)); + 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)); - }; + 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 @@ -1722,11 +1912,11 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta * @tc.desc Verify the scenario where the normal window mode is set */ it('setWindowModeTest2', 0, function (done) { - let windowModeArr=['FULLSCREEN','PRIMARY','SECONDARY','FLOATING'] + let windowModeArr = ['FULLSCREEN', 'PRIMARY', 'SECONDARY', 'FLOATING'] let caseName = 'setWindowModeTest2'; let msgStr = 'jsunittest ' + caseName + ' '; - let sumCount=0 - try{ + let sumCount = 0 + try { let wnd = windowStage.getMainWindowSync(); expect(!!wnd).assertTrue(); let loopCount = windowModeArr; @@ -1735,26 +1925,28 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta sleep(500) let tempType = ohosWindow.WindowMode[loopCount[i]]; console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); - try{ + 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)); + 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(); + 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 (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 set the window mode. Cause: ' + JSON.stringify(exception)); + } + ; } } catch (exception) { - console.error(msgStr +'try catch Failed to create the window. Cause: ' + JSON.stringify(exception)); - }; + console.error(msgStr + 'try catch Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; }) /** * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_003 @@ -1762,10 +1954,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta * @tc.desc Test window.setWindowMode API function test. */ it('setWindowModeTest3', 0, function (done) { - let windowModeArr=['UNDEFINED'] + let windowModeArr = ['UNDEFINED'] let caseName = 'setWindowModeTest3'; let msgStr = 'jsunittest ' + caseName + ' '; - let sumCount=0 + let sumCount = 0 try { let tempWnd = windowStage.getMainWindowSync(); expect(!!tempWnd).assertTrue(); @@ -1776,23 +1968,25 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let tempType = ohosWindow.WindowMode[loopCount[i]]; console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); try { - tempWnd.setWindowMode(tempType).then(()=> { + 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); - }).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(); + 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)); - }; + 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 @@ -1800,11 +1994,11 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta * @tc.desc Verify the scenario where the normal window mode is set */ it('setWindowModeTest4', 0, function (done) { - let windowModeArr=['UNDEFINED'] + let windowModeArr = ['UNDEFINED'] let caseName = 'setWindowModeTest4'; let msgStr = 'jsunittest ' + caseName + ' '; - let sumCount=0 - try{ + let sumCount = 0 + try { let wnd = windowStage.getMainWindowSync(); expect(!!wnd).assertTrue(); let loopCount = windowModeArr; @@ -1813,26 +2007,32 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta sleep(500) let tempType = ohosWindow.WindowMode[loopCount[i]]; console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); - try{ + 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)); - expect(err.code==401).assertTrue(); + 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); + 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 set the window mode. Cause: ' + JSON.stringify(exception)); + } + ; } } catch (exception) { - console.error(msgStr +'try catch Failed to create the window. Cause: ' + JSON.stringify(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 index cd4a0d2fb..c561adee0 100644 --- a/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets @@ -107,7 +107,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) function unexpectedError(error, caseName, apiName, done) { let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; console.log(msgStr + JSON.stringify(error)); - expect(TRUE_FLAG).assertFail(); + try { + expect(TRUE_FLAG).assertFail(); + ; + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } done(); } @@ -119,10 +124,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) } /** - * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_006 - * @tc.name Test setSystemBarEnableTest6 - * @tc.desc Test ohosWindow.setSystemBarEnable API function test1. - */ + * @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 + ' '; @@ -133,8 +138,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ohosWindow.on('systemBarTintChange', systembartintstate => { console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); if (flagStatus || flagNav) { - expect(!!systembartintstate).assertTrue(); - expect(!!systembartintstate.regionTint).assertTrue(); + 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(); } @@ -147,7 +156,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'windowStage.getMainWindow', done); } - expect(!!data).assertTrue(); + 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) => { @@ -163,7 +176,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); } - expect(!data).assertTrue(); + 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) => { @@ -171,7 +188,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navigation]', done); } - expect(!data).assertTrue(); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } console.log(msgStr + 'mainWnd.setSystemBarEnable success flagNav==' + flagNav); }) flagStatus = true; @@ -181,7 +202,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(err)===' + JSON.stringify(err)); unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); } - expect(!data).assertTrue(); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } }) }) }) @@ -189,10 +214,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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. - */ + * @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 + ' '; @@ -205,7 +230,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); if (flagStatus || flagNav) { console.log(msgStr + 'ohosWindow.on flagStatus || flagNav:'); - expect(!!systembartintstate).assertTrue(); + try { + expect(!!systembartintstate).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) + } done(); } }) @@ -215,7 +244,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'windowStage.getMainWindow', done); } - expect(!!data).assertTrue(); + 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) => { @@ -223,38 +256,53 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(data, caseName, 'mainWnd.show', done); } console.log(msgStr + 'mainWnd.show success'); - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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; - expect(!data).assertTrue(); + 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; - expect(!data).assertTrue(); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } }) }) }) }) }) - console.log(msgStr + 'finished!!'); }); /** - * @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. - */ + * @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 + ' '; @@ -266,7 +314,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'windowStage.getMainWindow', done); } - expect(!!data).assertTrue(); + 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) => { @@ -274,19 +326,31 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(data, caseName, 'mainWnd.show', done); } console.log(msgStr + 'mainWnd.show success'); - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; setTimeout(() => { @@ -299,8 +363,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) let numType = systembartintstate.regionTint[0].type console.log(msgStr + 'ohosWindow.on isEnable : ' + JSON.stringify(enable)); console.log(msgStr + 'ohosWindow.on numType : ' + JSON.stringify(numType)); - - expect(numType === ohosWindow.WindowType.TYPE_NAVIGATION_BAR || enable).assertTrue(); + try { + expect(numType === ohosWindow.WindowType.TYPE_NAVIGATION_BAR || enable).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) + } } done(); }, 3000) @@ -312,7 +379,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } flagStatus = true; flagNav = true; - expect(!data).assertTrue(); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } }) }) }) @@ -320,10 +391,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }); /** - * @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. - */ + * @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 + ' '; @@ -335,7 +406,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'windowStage.getMainWindow', done); } - expect(!!data).assertTrue(); + 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) => { @@ -343,13 +418,21 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(data, caseName, 'mainWnd.show', done); } console.log(msgStr + 'mainWnd.show success'); - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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) { @@ -357,14 +440,22 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } flagStatus = true; flagNav = true; - expect(!data).assertTrue(); + 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) { - expect(!!systembartintstate).assertTrue(); + try { + expect(!!systembartintstate).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) + } done(); } }) @@ -372,7 +463,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); } - expect(!data).assertTrue(); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } }) }) }) @@ -394,7 +489,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'windowStage.getMainWindow', done); } - expect(!!data).assertTrue(); + 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) => { @@ -402,25 +502,44 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(data, caseName, 'mainWnd.show', done); } console.log(msgStr + 'mainWnd.show success'); - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - - expect(!data).assertTrue(); + 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) { - expect(err.code === 1003).assertTrue(); + 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); @@ -448,8 +567,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ohosWindow.on('systemBarTintChange', (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (listenerFlag === listenerStatus.pending) { - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); + 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]; @@ -458,8 +581,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) compareCount++; let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor); let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); - expect(backgroundIndex === -1).assertTrue(); - expect(contentColorIndex === -1).assertTrue(); + try { + expect(backgroundIndex === -1).assertTrue(); + expect(contentColorIndex === -1).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } } } } @@ -470,25 +597,41 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.getMainWindow', done); } let tempWnd = data - expect(!!tempWnd).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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 @@ -544,8 +687,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ohosWindow.on('systemBarTintChange', (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (listenerFlag === listenerStatus.pending) { - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); + 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]; @@ -585,7 +732,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length if (compareCount === 18 && !flag) { console.log(msgStr + 'compareCount: ' + compareCount + ' ,true flag:' + flag); - expect(true).assertTrue(); + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } done(); } else { console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag); @@ -603,25 +754,41 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.getMainWindow', done); } let tempWnd = data - expect(!!tempWnd).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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 @@ -639,7 +806,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); if (err && err.code) { - expect(TRUE_FLAG).assertFail(); + try { + expect(TRUE_FLAG).assertFail(); + } catch (error) { + console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) + } done(); } }) @@ -666,8 +837,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ohosWindow.on('systemBarTintChange', (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (listenerFlag === listenerStatus.pending) { - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); + 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]; @@ -676,8 +851,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) compareCount++; let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor); let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); - expect(backgroundIndex === -1).assertTrue(); - expect(contentColorIndex === -1).assertTrue(); + try { + expect(backgroundIndex === -1).assertTrue(); + expect(contentColorIndex === -1).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } } } } @@ -688,25 +867,41 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.getMainWindow', done); } let tempWnd = data - expect(!!tempWnd).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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 @@ -724,7 +919,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); if (err && err.code) { - expect(TRUE_FLAG).assertFail(); + try { + expect(TRUE_FLAG).assertFail(); + } catch (error) { + console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) + } done(); } }) @@ -758,7 +957,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); if (err && err.code) { - expect(err.code === 1003).assertTrue(); + 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(); @@ -791,7 +994,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); return; } - expect(!!data).assertTrue(); + 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) => { @@ -803,8 +1010,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) return; } console.log(msgStr + 'tempWnd.getProperties success, !!data : ' + !!data); - expect(!!data).assertTrue(); - expect(data.type == tempType).assertTrue(); + try { + expect(!!data).assertTrue(); + expect(data.type == tempType).assertTrue(); + } catch (error) { + console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`) + } }) }) } @@ -825,7 +1036,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ohosWindow.create(context, windId, tempType, (err, data) => { console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); if (err && err.code) { - expect(err.code === 1003).assertTrue(); + try { + expect(err.code === 1003).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } done(); return; } @@ -853,7 +1068,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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)); - expect(err.code).assertEqual(1001) + 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); @@ -881,25 +1100,40 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } tempWnd = data console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); - expect(!!tempWnd).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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); } - expect(!data).assertTrue(); + 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; - expect(!!avoidAreaData).assertTrue(); + try { + expect(!!avoidAreaData).assertTrue(); + } catch (error) { + console.info(`tempWnd.on catch error: ${JSON.stringify(error)}`) + } } done(); }) @@ -907,7 +1141,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done); } - expect(!data).assertTrue(); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success'); listenerOnFlag = listenerStatus.pending; }) @@ -923,10 +1161,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_003 - * @tc.name Test setWindowTypeTest3 - * @tc.desc Verify the scenario where the normal window type is set - */ + * @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 + ' '; @@ -936,64 +1174,87 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) let tempWnd = null let tempTypeArr = []; 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 - console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd); - expect(!!tempWnd).assertTrue(); - let loopCount1 = systemWindowTypeArr; - console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount1)) - for (let i = 0; i < loopCount1.length; i++) { - let tempType = ohosWindow.WindowType[loopCount1[i]]; - console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' start'); - tempTypeArr.push(tempType); - tempWnd.setWindowType(tempType, (err, data) => { - 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) { - expect(!data).assertTrue(); - console.log(msgStr + 'tempWnd.getProperties start'); - tempWnd.getProperties((err, dataProper) => { - 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); - expect(!!dataProper).assertTrue(); - 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: ' + tempTypeArr.length + 1); - expect((loopCount1.length - i) == (tempTypeArr.length + 1)).assertTrue(); - if (i == loopCount1.length - 1) { - console.log(msgStr + 'tempWnd.getProperties i=' + i + ' , loopCount1.length-1==' + loopCount1.length); - done(); + 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)) + for (let i = 0; i < loopCount1.length; i++) { + 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)}`) } - } else { - unexpectedError(err, caseName, 'tempWnd.getProperties aa', done); + 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)); + try { + expect((loopCount1.length - i) == (tempTypeArr.length + 1)).assertTrue(); + } 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)); + } + }) } - }) - } else { - unexpectedError(err, caseName, 'tempWnd.setWindowType', done); - } - console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' end'); - }) + console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' end'); + } catch (err) { + console.log(msgStr + 'tempWnd.setWindowType catch err: ' + JSON.stringify(err)); + } + }) + } } - } else { - unexpectedError(err, caseName, 'ohosWindow.create', done); + } 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 - */ + * @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 + ' '; @@ -1008,7 +1269,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'ohosWindow.create !!data' + !!data); if (!!data) { tempWnd = data - expect(!!tempWnd).assertTrue(); + 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)); @@ -1016,7 +1281,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (!!data) { unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } else { - expect(err.code == 1003).assertTrue(); + try { + expect(err.code == 1003).assertTrue(); + } catch (error) { + console.info(`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`) + } done(); } }) @@ -1026,10 +1295,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_DESTROY_JSAPI_002 - * @tc.name Test destroyTest2 - * @tc.desc Verification window destruction scenario - */ + * @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 + ' '; @@ -1043,7 +1312,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'ohosWindow.create !!data' + !!data); if (!!data) { tempWnd = data - expect(!!tempWnd).assertTrue(); + 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)); @@ -1051,13 +1324,21 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(err, caseName, 'ohosWindow.destroy', done); } else { - expect(!data).assertTrue(); + 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) { - expect(err.code == 1001).assertTrue(); + 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); @@ -1071,10 +1352,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_007 - * @tc.name Test loadContentTest7 - * @tc.desc Verify the scenario of loading an existing page - */ + * @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 + ' '; @@ -1088,7 +1369,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'ohosWindow.create !!data' + !!data); if (!!data) { tempWnd = data - expect(!!tempWnd).assertTrue(); + 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)); @@ -1096,7 +1381,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(err, caseName, 'tempWnd.loadContent', done); } else { - expect(!data).assertTrue(); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) + } done(); } }) @@ -1106,10 +1395,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_008 - * @tc.name Test loadContentTest8 - * @tc.desc Verify the scenario of loading a page that does not exist - */ + * @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 + ' '; @@ -1123,13 +1412,21 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'ohosWindow.create !!data' + !!data); if (!!data) { tempWnd = data - expect(!!tempWnd).assertTrue(); + 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) { - expect(err.code === 1003).assertTrue(); + 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); @@ -1141,10 +1438,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_009 - * @tc.name Test loadContentTest9 - * @tc.desc Verify the scenario of loading an existing page - */ + * @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 + ' '; @@ -1154,17 +1451,21 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.loadContent', done); console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); } else { - expect(!data).assertTrue(); + 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 - */ + * @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 + ' '; @@ -1172,20 +1473,28 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) try { windowStage.loadContent(null, (err, data) => { console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); - expect(false).assertTrue(); + 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)); - expect(err.code == 401).assertTrue(); + 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 - */ + * @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 + ' '; @@ -1195,17 +1504,21 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.loadContent', done); console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); } else { - expect(!data).assertTrue(); + 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 - */ + * @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 + ' '; @@ -1213,20 +1526,27 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) try { windowStage.loadContent(null, abilityStorage, (err, data) => { console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); - expect(false).assertTrue(); - + 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)); - expect(err.code === 401).assertTrue(); + 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 - */ + * @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 + ' '; @@ -1236,17 +1556,21 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.createSubWindow', done); console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest3) err=' + JSON.stringify(err)); } else { - expect(!!data).assertTrue(); + 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 - */ + * @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 + ' '; @@ -1254,19 +1578,27 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) try { windowStage.createSubWindow(null, (err, data) => { console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err)); - expect(false).assertTrue(); + try { + expect(false).assertTrue(); + } catch (error) { + console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`) + } }); } catch (err) { - expect(err.code === 401).assertTrue(); + 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 - */ + * @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 + ' '; @@ -1276,17 +1608,21 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.getSubWindow', done); console.log(msgStr + 'windowStage.getSubWindow(null) err=' + JSON.stringify(err)); } else { - expect(!!data).assertTrue(); + 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 - */ + * @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 + ' '; @@ -1295,50 +1631,90 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } done(); } else { - expect(data != null).assertTrue(); + 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)); - expect().assertFail(); + 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)); - expect(!data.isPrivacyMode).assertTrue(); + 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 { - expect(!data).assertTrue(); + 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)); - expect().assertFail(); + 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)); - expect(data.isPrivacyMode).assertTrue(); + 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 { - expect(!data).assertTrue(); + 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)); - expect().assertFail(); + 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)); - expect(!data.isPrivacyMode).assertTrue(); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } } done(); }) @@ -1354,10 +1730,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_003 - * @tc.name Test setPrivacyModeTest3 - * @tc.desc Verify that the auxiliary window is set as the security layer - */ + * @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 + ' '; @@ -1366,50 +1742,90 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) windowStage.createSubWindow('setPrivacyModeTest3', (err, data) => { if (err && err.code) { console.log(msgStr + 'windowStage.createSubWindow fail err:' + JSON.stringify(err)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } done(); } else { - expect(data != null).assertTrue(); + 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)); - expect().assertFail(); + 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)); - expect(!data.isPrivacyMode).assertTrue(); + 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 { - expect(!data).assertTrue(); + 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)); - expect().assertFail(); + 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)); - expect(data.isPrivacyMode).assertTrue(); + 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 { - expect(!data).assertTrue(); + 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)); - expect().assertFail(); + 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)); - expect(!data.isPrivacyMode).assertTrue(); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } } done(); }) @@ -1425,10 +1841,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_SETDENSITTYDPI_JSAPI_002 - * @tc.name Test setDensityDpiTest2 - * @tc.desc Verify Sets the screen pixel - */ + * @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 + ' '; @@ -1437,8 +1853,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(errScreen, caseName, 'screenManager.getAllScreen', done); }) console.log(msgStr + 'screenManager.getAllScreen' + JSON.stringify(screens)); - expect(!!screens).assertTrue(); - + 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) => { @@ -1465,21 +1884,24 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay' + JSON.stringify(result)); let isEqual = Number(result.densityDPI) == parseInt(dpiItem[i]) console.log(msgStr + 'same ? ' + isEqual) - expect(isEqual).assertTrue() + 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 - */ + * @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 + ' '; @@ -1488,26 +1910,33 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.getMainWindow', done); }); console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); - expect(!!mainWin).assertTrue(); - let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE']; + 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.code) { + 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)); }) } - console.log(msgStr + 'done '); - done(); }) /** - * @tc.number SUB_WINDOW_SETFORBIDSPLITMOVE_JSAPI_002 - * @tc.name Test setForbidSplitMoveTest2 - * @tc.desc Sets whether Windows are forbidden to move in split screen mode - */ + * @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 + ' '; @@ -1516,7 +1945,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.getMainWindow', done); }); console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); - expect(!!mainWin).assertTrue(); + 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'); @@ -1535,10 +1968,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) done(); }) /** - * @tc.number SUB_WINDOW_SNAPSHOT_JSAPI_002 - * @tc.name Test snapshotTest2 - * @tc.desc Scenario of screenshot of verification window - */ + * @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 + ' '; @@ -1547,7 +1980,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'windowStage.getMainWindow', done); }); console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); - expect(!!mainWin).assertTrue(); + 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)); @@ -1586,17 +2023,21 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'ohosWindow.create', done); } else { let dialogTargetTouchTest2Win = data - expect(!!dialogTargetTouchTest2Win).assertTrue(); + 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 - */ + * @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 + ' '; @@ -1610,7 +2051,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); } else { tempWnd = data - expect(!!tempWnd).assertTrue(); + 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) => { @@ -1640,16 +2085,20 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) /** - * @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 - */ + * @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(); - expect(!!dpClass).assertTrue(); + 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); @@ -1660,10 +2109,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_SHOWWITHANIMATION_JSAPI_002 - * @tc.name Test showWithAnimationTest2 - * @tc.desc Displays the current window, playing an animation in the process - */ + * @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 + ' '; @@ -1676,7 +2125,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } else { let tempWnd = data; console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + JSON.stringify(tempWnd)); - expect(!!tempWnd).assertTrue(); + 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); @@ -1689,10 +2142,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) /** - * @tc.number SUB_WINDOW_HIDEWITHANIMATION_JSAPI_002 - * @tc.name Test hideWithAnimationTest2 - * @tc.desc Hide the current window and play an animation in the process - */ + * @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 + ' '; @@ -1703,7 +2156,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (creare_err && creare_err.code) { unexpectedError(creare_err, caseName, 'ohosWindow.create ' + baseType, done); } - expect(!!tempWnd).assertTrue(); + 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); diff --git a/graphic/windowStage/entry/src/main/ets/test/windowRefactorInterface.test.ets b/graphic/windowStage/entry/src/main/ets/test/windowRefactorInterface.test.ets index 45758236b..006e9d89a 100644 --- a/graphic/windowStage/entry/src/main/ets/test/windowRefactorInterface.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/windowRefactorInterface.test.ets @@ -36,7 +36,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit 'TYPE_VOLUME_OVERLAY': 6, 'TYPE_NAVIGATION_BAR': 7, 'TYPE_FLOAT': 8, - 'TYPE_FLOAT_CAMERA':9 + 'TYPE_FLOAT_CAMERA': 9 } var listenerStatus = { ready: 'ready', @@ -58,8 +58,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit }) afterEach(async function (done) { if (listenerData.on) { - listenerData.on = false; - console.info('jsunittest afterEach listener off, listenerData:' + JSON.stringify(listenerData)); + listenerData.on = false; + console.info('jsunittest afterEach listener off, listenerData:' + JSON.stringify(listenerData)); if (listenerData.typeStr === 'systemBarTintChange') { ohosWindow.off(listenerData.typeStr); } else if (newWindowObj) { @@ -92,60 +92,68 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; ohosWindow.on('systemBarTintChange', (systemBarData) => { - console.info('setWindowSystemBarPropertiesTest1 systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); - let arrLength = systemBarData.regionTint.length; - for (let i = 0; i < arrLength; i++) { - // 单个导航栏或者系统状态信息 - let SystemBarRegionTint = systemBarData.regionTint[i]; - if (SystemBarRegionTint.type === ohosWindow.WindowType.TYPE_STATUS_BAR || SystemBarRegionTint.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { - console.info('setWindowSystemBarPropertiesTest1 assert1 start!'); - let backgroundIndex = cloneColorArr.indexOf(SystemBarRegionTint.backgroundColor); - let contentColorIndex = cloneColorArr.indexOf(SystemBarRegionTint.contentColor); - expect(backgroundIndex === -1).assertTrue(); - expect(contentColorIndex === -1).assertTrue(); - done(); - } + console.info('setWindowSystemBarPropertiesTest1 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 SystemBarRegionTint = systemBarData.regionTint[i]; + if (SystemBarRegionTint.type === ohosWindow.WindowType.TYPE_STATUS_BAR || SystemBarRegionTint.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { + console.info('setWindowSystemBarPropertiesTest1 assert1 start!'); + let backgroundIndex = cloneColorArr.indexOf(SystemBarRegionTint.backgroundColor); + let contentColorIndex = cloneColorArr.indexOf(SystemBarRegionTint.contentColor); + try { + expect(backgroundIndex === -1).assertTrue(); + expect(contentColorIndex === -1).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) } + done(); + } } + } }) console.info('setWindowSystemBarPropertiesTest1 on systemBarTintChange finished'); - let mainWsync = windowStage.getMainWindowSync(); + let mainWsync = windowStage.getMainWindowSync(); expect(mainWsync != null).assertTrue(); await mainWsync.showWindow().catch(err => { - console.info('setWindowSystemBarPropertiesTest1 mainWsync.showWindow() error : ' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info('setWindowSystemBarPropertiesTest1 mainWsync.showWindow() error : ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); await mainWsync.setWindowSystemBarEnable(['status', 'navigation']).catch((err) => { - console.info('setWindowSystemBarPropertiesTest1 mainWsync.setWindowSystemBarEnable error : ' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info('setWindowSystemBarPropertiesTest1 mainWsync.setWindowSystemBarEnable error : ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); await sleep(1000); 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, - navigationContentColor: tempColor, - }; - mainWsync.setWindowSystemBarProperties(systemBarProperties).then(() => { - console.info('setWindowSystemBarPropertiesTest1 success'); - expect(TRUE_FLAG).assertTrue(); - done(); - }).catch(err => { - console.info('setWindowSystemBarPropertiesTest1 error : ' + JSON.stringify(err)); - expect().assertFail() - done(); - }) + let tempColor = commonRGBColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: false, + navigationContentColor: tempColor, + }; + mainWsync.setWindowSystemBarProperties(systemBarProperties).then(() => { + console.info('setWindowSystemBarPropertiesTest1 success'); + expect(TRUE_FLAG).assertTrue(); + done(); + }).catch(err => { + console.info('setWindowSystemBarPropertiesTest1 error : ' + JSON.stringify(err)); + expect().assertFail() + done(); + }) } }) @@ -156,89 +164,101 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit */ it('setWindowSystemBarPropertiesTest2', 0, async function (done) { 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)) + 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 listenerFlag = listenerStatus.ready; listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; console.info('setWindowSystemBarPropertiesTest2'); ohosWindow.on('systemBarTintChange', (systemBarData) => { - console.info('setWindowSystemBarPropertiesTest2 systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { + console.info('setWindowSystemBarPropertiesTest2 systemBatData : ' + JSON.stringify(systemBarData)); + if (listenerFlag === listenerStatus.pending) { // 单个导航栏或者系统状态信息 + try { expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); - let arrLength = systemBarData.regionTint.length; - for (let i = 0; i < arrLength; i++) { - let systemBarRegionTint = systemBarData.regionTint[i]; - if (systemBarRegionTint.type === ohosWindow.WindowType.TYPE_STATUS_BAR) { - console.info('setWindowSystemBarPropertiesTest2 assert2 start!'); - let backgroundIndex = cloneColorArr.SBC.indexOf(systemBarRegionTint.backgroundColor); - let contentColorIndex = cloneColorArr.SCC.indexOf(systemBarRegionTint.contentColor); - if (backgroundIndex >= 0) { - cloneColorArr.SBC.splice(backgroundIndex, 1); - } - if (contentColorIndex >= 0) { - cloneColorArr.SCC.splice(contentColorIndex, 1); - } - expect(backgroundIndex !== -1).assertTrue(); - expect(contentColorIndex !== -1).assertTrue(); - done(); - } else if (systemBarRegionTint.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { - let backgroundIndex = cloneColorArr.NBC.indexOf(systemBarRegionTint.backgroundColor); - let contentColorIndex = cloneColorArr.NCC.indexOf(systemBarRegionTint.contentColor); - if (backgroundIndex >= 0) { - cloneColorArr.NBC.splice(backgroundIndex, 1); - } - if (contentColorIndex >= 0) { - cloneColorArr.NCC.splice(contentColorIndex, 1); - } - expect(backgroundIndex !== -1).assertTrue(); - expect(contentColorIndex !== -1).assertTrue(); - done(); - } + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + let arrLength = systemBarData.regionTint.length; + for (let i = 0; i < arrLength; i++) { + let systemBarRegionTint = systemBarData.regionTint[i]; + if (systemBarRegionTint.type === ohosWindow.WindowType.TYPE_STATUS_BAR) { + console.info('setWindowSystemBarPropertiesTest2 assert2 start!'); + let backgroundIndex = cloneColorArr.SBC.indexOf(systemBarRegionTint.backgroundColor); + let contentColorIndex = cloneColorArr.SCC.indexOf(systemBarRegionTint.contentColor); + if (backgroundIndex >= 0) { + cloneColorArr.SBC.splice(backgroundIndex, 1); + } + if (contentColorIndex >= 0) { + cloneColorArr.SCC.splice(contentColorIndex, 1); + } + try { + expect(backgroundIndex !== -1).assertTrue(); + expect(contentColorIndex !== -1).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + done(); + } else if (systemBarRegionTint.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { + let backgroundIndex = cloneColorArr.NBC.indexOf(systemBarRegionTint.backgroundColor); + let contentColorIndex = cloneColorArr.NCC.indexOf(systemBarRegionTint.contentColor); + if (backgroundIndex >= 0) { + cloneColorArr.NBC.splice(backgroundIndex, 1); + } + if (contentColorIndex >= 0) { + cloneColorArr.NCC.splice(contentColorIndex, 1); + } + try { + expect(backgroundIndex !== -1).assertTrue(); + expect(contentColorIndex !== -1).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + done(); } + } } }) console.info('setWindowSystemBarPropertiesTest2 on systemBarTintChange finished'); let mainWsync = windowStage.getMainWindowSync(); expect(mainWsync != null).assertTrue(); await mainWsync.showWindow().catch((err) => { - console.info('setWindowSystemBarPropertiesTest2 mainWsync.showWindow() error : ' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info('setWindowSystemBarPropertiesTest2 mainWsync.showWindow() error : ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); await mainWsync.setWindowSystemBarEnable(['status', 'navigation']).catch((err) => { - console.info('setWindowSystemBarPropertiesTest2 mainWsync.setWindowSystemBarEnable error : ' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info('setWindowSystemBarPropertiesTest2 mainWsync.setWindowSystemBarEnable error : ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); await sleep(1000); listenerFlag = listenerStatus.pending; let loopCount = commonNUMBERColorArr.length; for (let i = 0; i < loopCount; i++) { - let tempColor = commonNUMBERColorArr[i]; - let systemBarProperties = { - statusBarColor: tempColor, - isStatusBarLightIcon: true, - statusBarContentColor: tempColor, - navigationBarColor: tempColor, - isNavigationBarLightIcon: true, - navigationBarContentColor: tempColor, - }; - mainWsync.setWindowSystemBarProperties(systemBarProperties).then(() => { - console.info('setWindowSystemBarPropertiesTest2 success'); - expect(TRUE_FLAG).assertTrue(); - done(); - }).catch(err => { - console.info('setWindowSystemBarPropertiesTest2 error : ' + JSON.stringify(err)); - expect().assertFail() - done(); - }) + let tempColor = commonNUMBERColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: true, + navigationBarContentColor: tempColor, + }; + mainWsync.setWindowSystemBarProperties(systemBarProperties).then(() => { + console.info('setWindowSystemBarPropertiesTest2 success'); + expect(TRUE_FLAG).assertTrue(); + done(); + }).catch(err => { + console.info('setWindowSystemBarPropertiesTest2 error : ' + JSON.stringify(err)); + expect().assertFail() + done(); + }) } }) @@ -248,64 +268,72 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc Verify the scene where the status bar and navigation bar colors are set as keywords */ it('setWindowSystemBarPropertiesTest3', 0, async function (done) { - let cloneColorArr = JSON.parse(JSON.stringify(commonKEYColorArr)); - let listenerFlag = listenerStatus.ready; - console.info('setWindowSystemBarPropertiesTest3 start'); - listenerData.on = true; - listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systemBarData) => { - console.info('setWindowSystemBarPropertiesTest3 systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); - 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) { - let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor); - let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); - expect(backgroundIndex === -1).assertTrue(); - expect(contentColorIndex === -1).assertTrue(); - done(); - } - } + let cloneColorArr = JSON.parse(JSON.stringify(commonKEYColorArr)); + let listenerFlag = listenerStatus.ready; + console.info('setWindowSystemBarPropertiesTest3 start'); + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + ohosWindow.on('systemBarTintChange', (systemBarData) => { + console.info('setWindowSystemBarPropertiesTest3 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) { + 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)}`) + } + done(); + } + } } }) - let tempWnd = windowStage.getMainWindowSync(); + let tempWnd = windowStage.getMainWindowSync(); expect(tempWnd != null).assertTrue(); await tempWnd.showWindow().catch((err) => { - console.info('setWindowSystemBarPropertiesTest3 mainWsync.showWindow() error : ' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info('setWindowSystemBarPropertiesTest3 mainWsync.showWindow() error : ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); await tempWnd.setWindowSystemBarEnable(['status', 'navigation']).catch((err) => { - console.info('setWindowSystemBarPropertiesTest3 mainWsync.setWindowSystemBarEnable error : ' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info('setWindowSystemBarPropertiesTest3 mainWsync.setWindowSystemBarEnable error : ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); await sleep(1000); listenerFlag = listenerStatus.pending; let loopCount = commonKEYColorArr.length; for (let i = 0; i < loopCount; i++) { - let tempColor = commonKEYColorArr[i]; - let systemBarProperties = { - statusBarColor: tempColor, - isStatusBarLightIcon: true, - statusBarContentColor: tempColor, - navigationBarColor: tempColor, - isNavigationBarLightIcon: false, - navigationContentColor: tempColor, - }; - tempWnd.setWindowSystemBarProperties(systemBarProperties).then(() => { - console.info('setWindowSystemBarPropertiesTest3 success'); - expect(TRUE_FLAG).assertTrue(); - done(); - }).catch(err => { - console.info('setWindowSystemBarPropertiesTest3 error : ' + JSON.stringify(err)); - expect().assertFail() - done(); - }) + let tempColor = commonKEYColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: false, + navigationContentColor: tempColor, + }; + tempWnd.setWindowSystemBarProperties(systemBarProperties).then(() => { + console.info('setWindowSystemBarPropertiesTest3 success'); + expect(TRUE_FLAG).assertTrue(); + done(); + }).catch(err => { + console.info('setWindowSystemBarPropertiesTest3 error : ' + JSON.stringify(err)); + expect().assertFail() + done(); + }) } }) @@ -319,9 +347,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit statusBarColor: '#ff00ff', navigationBarColor: '#00ff00', isStatusBarLightIcon: true, - isNavigationBarLightIcon:false, - statusBarContentColor:'#ffffff', - navigationBarContentColor:'#00ffff' + isNavigationBarLightIcon: false, + statusBarContentColor: '#ffffff', + navigationBarContentColor: '#00ffff' }; let tempWnd = windowStage.getMainWindowSync(); expect(tempWnd != null).assertTrue(); @@ -329,19 +357,28 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit tempWnd.setWindowSystemBarProperties(SystemBarProperties, (err) => { console.info('Succeeded in setting the system bar properties.' + JSON.stringify(err)); if (err.code) { + try { expect(err.code).assertEqual(401); - done() + } catch (error) { + console.info(`tempWnd.setWindowSystemBarProperties catch error: ${JSON.stringify(error)}`) + } + done() } else { - console.info('Succeeded in setting the system bar properties.'); + console.info('Succeeded in setting the system bar properties.'); + try { expect(TRUE_FLAG).assertTrue(); - done(); - } + } catch (error) { + console.info(`tempWnd.setWindowSystemBarProperties catch error: ${JSON.stringify(error)}`) + } + done(); + } }); } catch (exception) { console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - }; + } + ; }) /** @@ -350,27 +387,29 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc To verify the widow isshowing */ it('iswindowShowing_Test_001', 0, async function (done) { - console.info('windowTest isWindowShowing begin'); - let config = {name: "alertWindowshow", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context}; - ohosWindow.createWindow(config).then(wnd => { - expect(wnd != null).assertTrue(); - let isWindowShowing = wnd.isWindowShowing(); - expect(!isWindowShowing).assertTrue(); - wnd.showWindow().then(() => { - let isWindowShowing2 = wnd.isWindowShowing(); - expect(isWindowShowing2).assertTrue(); - wnd.destroyWindow(); - done(); - }).catch(err => { - console.error('Failed to show window1. Cause:' + JSON.stringify(err)); - expect().assertFail(); - done(); - }) - }).catch(err => { - console.error('Failed to create the Windowshow1. Cause:' + JSON.stringify(err)); - expect().assertFail(); - done(); - }) + console.info('windowTest isWindowShowing begin'); + let config = { + name: "alertWindowshow", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context + }; + ohosWindow.createWindow(config).then(wnd => { + expect(wnd != null).assertTrue(); + let isWindowShowing = wnd.isWindowShowing(); + expect(!isWindowShowing).assertTrue(); + wnd.showWindow().then(() => { + let isWindowShowing2 = wnd.isWindowShowing(); + expect(isWindowShowing2).assertTrue(); + wnd.destroyWindow(); + done(); + }).catch(err => { + console.error('Failed to show window1. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }) + }).catch(err => { + console.error('Failed to create the Windowshow1. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }) }) /** * @tc.number SUB_WINDOW_setUIContent_JSAPI_001 @@ -378,31 +417,34 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc Verify the scenario of loading an existing page */ it('setUIContentTest1', 0, async function (done) { - let config = {name: "alertWindow", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context}; - try { - let promise = ohosWindow.createWindow(config); - promise.then(win => { - console.info('Succeeded in creating the window1. Data:' + JSON.stringify(win)); - expect(win != null); - win.setUIContent('pages/second/second').then(() => { - console.info('setUIContent1 . Cause: success'); - expect(TRUE_FLAG).assertTrue(); - done(); - }).catch(err => { - console.error('Failed to setUIContent . Cause:' + JSON.stringify(err)); - expect().assertFail(); - done(); - }); - }).catch((err) => { - console.error('Failed to create the Window1. Cause:' + JSON.stringify(err)); - expect().assertFail(); - done(); + let config = { + name: "alertWindow", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context + }; + try { + let promise = ohosWindow.createWindow(config); + promise.then(win => { + console.info('Succeeded in creating the window1. Data:' + JSON.stringify(win)); + expect(win != null); + win.setUIContent('pages/second/second').then(() => { + console.info('setUIContent1 . Cause: success'); + expect(TRUE_FLAG).assertTrue(); + done(); + }).catch(err => { + console.error('Failed to setUIContent . Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); }); - } catch (exception) { - console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); - expect().assertFail(); - done(); - }; + }).catch((err) => { + console.error('Failed to create the Window1. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (exception) { + console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); + } + ; }) /** @@ -412,7 +454,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit */ it('setUIContentTestCallBack1', 0, async function (done) { let windowClass = null; - let config = {name: "alertWindowcallBack", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context}; + let config = { + name: "alertWindowcallBack", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context + }; try { let promise = ohosWindow.createWindow(config); promise.then(win => { @@ -436,7 +480,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed callback to load the content. Cause:' + JSON.stringify(exception)); expect().assertFail(); done(); - }; + } + ; }).catch((err) => { console.error('Failedcaa to create the inner Window2. Cause:' + JSON.stringify(err)); @@ -447,7 +492,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to create the window2. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - }; + } + ; }) @@ -458,7 +504,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit */ it('setUIContentTest2', 0, async function (done) { let windowClass = null; - let config = {name: "alertWindow2", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context}; + let config = { + name: "alertWindow2", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context + }; try { let promise = ohosWindow.createWindow(config); promise.then(win => { @@ -468,11 +516,11 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit // 设置setUIContent try { let promise = windowClass.setUIContent(null); - promise.then(()=> { + promise.then(() => { console.info('Succeeded in loading the content.'); expect().assertFail(); done(); - }).catch((err)=>{ + }).catch((err) => { console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); expect(err.code).assertEqual(401); done() @@ -481,18 +529,20 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to load the content. exception: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - }; + } + ; }).catch((err) => { - console.error('Failed to create the inner Window2. Cause:' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.error('Failed to create the inner Window2. Cause:' + JSON.stringify(err)); + expect().assertFail(); + done(); }); } catch (exception) { console.error('Failed to create the window2. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - }; + } + ; }) @@ -502,7 +552,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc Verify the scene of loading the page with illegal values */ it('setUIContentTest3', 0, async function (done) { - let config = {name: "alertWindow3", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context}; + let config = { + name: "alertWindow3", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context + }; try { let promise = ohosWindow.createWindow(config); promise.then(win => { @@ -527,7 +579,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to create the window3. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - }; + } + ; }) /** @@ -566,25 +619,26 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc To verify that the color space of invaild values is set successfully */ it('setWindowColorSpace_Test_002', 0, async function (done) { - console.info('windowTest setWindowColorSpaceTest2 begin'); - let wnd = windowStage.getMainWindowSync(); - expect(wnd != null).assertTrue(); - try { - let promise = wnd.setWindowColorSpace(-5); - promise.then(()=> { - console.info('Succeeded in setting window2 colorspace.'); - expect().assertFail(); - done(); - }).catch((err)=>{ - console.error('Failed to set window colorspacecatch2. Cause: ' + JSON.stringify(err)); - expect(err.code).assertEqual(401); - done(); + console.info('windowTest setWindowColorSpaceTest2 begin'); + let wnd = windowStage.getMainWindowSync(); + expect(wnd != null).assertTrue(); + try { + let promise = wnd.setWindowColorSpace(-5); + promise.then(() => { + console.info('Succeeded in setting window2 colorspace.'); + expect().assertFail(); + done(); + }).catch((err) => { + console.error('Failed to set window colorspacecatch2. Cause: ' + JSON.stringify(err)); + expect(err.code).assertEqual(401); + done(); }); } catch (exception) { console.error('Failed to set window colorspaceexception2. Cause:' + JSON.stringify(exception)); - expect(exception.code).assertEqual(401); - done(); - }; + expect(exception.code).assertEqual(401); + done(); + } + ; }) @@ -607,7 +661,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit expect(windowColorSpace == ohosWindow.ColorSpace.WIDE_GAMUT).assertTrue(); wnd.isWindowSupportWideGamut((err, data) => { if (err.code != 0) { - console.log('windowTest SetWindowColorSpaceTest3 getColorSpace callback fail' + JSON.stringify(err)); + console.log('windowTest SetWindowColorSpaceTest3 getColorSpace callback fail' + JSON.stringify(err)); expect().assertFail(); done(); } else { @@ -625,27 +679,29 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc Set the window background color to red and Default opacity */ it('setWindowBackgroundColor_Test_001', 0, async function (done) { - console.info('windowTest01 setWindowBackgroundColorTest1 begin'); - let wnd = windowStage.getMainWindowSync(); - expect(wnd != null).assertTrue(); - let color = '#00ff33'; - try { - wnd.setWindowBackgroundColor(color); - done(); - try { - let properties = wnd.getWindowProperties(); - expect(!properties.isTransparent).assertTrue(); - done() - } catch (exception) { - console.error('Failed to obtain the window properties001. Cause: ' + JSON.stringify(exception)); - expect(exception.code).assertEqual(401); - done(); - }; - } catch (exception) { + console.info('windowTest01 setWindowBackgroundColorTest1 begin'); + let wnd = windowStage.getMainWindowSync(); + expect(wnd != null).assertTrue(); + let color = '#00ff33'; + try { + wnd.setWindowBackgroundColor(color); + done(); + try { + let properties = wnd.getWindowProperties(); + expect(!properties.isTransparent).assertTrue(); + done() + } catch (exception) { + console.error('Failed to obtain the window properties001. Cause: ' + JSON.stringify(exception)); + expect(exception.code).assertEqual(401); + done(); + } + ; + } catch (exception) { console.error('Failed to set the background1 color. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - }; + } + ; }) @@ -656,27 +712,29 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc Set the window background color to red opaque */ it('setWindowBackgroundColor_Test_002', 0, async function (done) { - console.info('windowTest setWindowBackgroundColorTest2 begin'); - let wnd = windowStage.getMainWindowSync(); - expect(wnd != null).assertTrue(); - let color = '#ffffff00'; - try { - wnd.setWindowBackgroundColor(color); - done(); - try { - let properties = wnd.getWindowProperties(); - expect(!properties.isTransparent).assertTrue(); - done() - } catch (exception) { - console.error('Failed to obtain the window properties002. Cause: ' + JSON.stringify(exception)); - expect(exception.code).assertEqual(401); - done(); - }; + console.info('windowTest setWindowBackgroundColorTest2 begin'); + let wnd = windowStage.getMainWindowSync(); + expect(wnd != null).assertTrue(); + let color = '#ffffff00'; + try { + wnd.setWindowBackgroundColor(color); + done(); + try { + let properties = wnd.getWindowProperties(); + expect(!properties.isTransparent).assertTrue(); + done() + } catch (exception) { + console.error('Failed to obtain the window properties002. Cause: ' + JSON.stringify(exception)); + expect(exception.code).assertEqual(401); + done(); + } + ; } catch (exception) { console.error('Failed to set the background2 color. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - }; + } + ; }) @@ -702,12 +760,14 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to obtain the window properties003. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done(); - }; + } + ; } catch (exception) { console.error('Failed to set the background3 color. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - }; + } + ; }) /** @@ -727,7 +787,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the background4 color. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - }; + } + ; }) /** @@ -750,12 +811,14 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to obtain the window properties005. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - }; + } + ; } catch (exception) { console.error('Failed to set the background5 color. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - }; + } + ; }) @@ -776,7 +839,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the background6 color. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - }; + } + ; }) /** @@ -851,11 +915,11 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit let brightness = Number.MAX_VALUE; try { let promise = wnd.setWindowBrightness(brightness); - promise.then(()=> { + promise.then(() => { console.info('Succeeded3 in setting the brightness.'); expect().assertFail(); done(); - }).catch((err)=>{ + }).catch((err) => { console.error('Failed3 to set the brightness. Cause: ' + JSON.stringify(err)); expect(err.code).assertEqual(401); done(); @@ -864,7 +928,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed3 to set the brightnessexception. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - }; + } + ; }) @@ -874,7 +939,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc Set the brightness bar input parameter to number min */ it('setWindowBrightness_Test_004', 0, async function (done) { - console.info('windowTest setWindowBrightnessTest4 begin'); + console.info('windowTest setWindowBrightnessTest4 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); wnd.setWindowBrightness(Number.MIN_VALUE).then(() => { @@ -882,9 +947,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit expect(TRUE_FLAG).assertTrue(); done(); }, (err) => { - console.info('windowTest setWindowBrightnessTest4 setBrightness failed: err' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info('windowTest setWindowBrightnessTest4 setBrightness failed: err' + JSON.stringify(err)); + expect().assertFail(); + done(); }) }) @@ -900,11 +965,11 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit let brightness = 1.1; try { let promise = wnd.setWindowBrightness(brightness); - promise.then(()=> { + promise.then(() => { console.info('Succeeded5 in setting the brightness.'); expect().assertFail(); done(); - }).catch((err)=>{ + }).catch((err) => { console.error('Failed5 to set the brightness. Cause: ' + JSON.stringify(err)); expect(err.code).assertEqual(401); done(); @@ -913,15 +978,16 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed5 to set the brightness. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - }; + } + ; try { let promise = wnd.setWindowBrightness(-0.5); - promise.then(()=> { + promise.then(() => { console.info('Succeeded55 in setting the brightness.'); expect().assertFail(); done(); - }).catch((err)=>{ + }).catch((err) => { console.error('Failed55 to set the brightness. Cause: ' + JSON.stringify(err)); expect(err.code).assertEqual(401); done(); @@ -930,7 +996,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed55 to set the brightness. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done(); - }; + } + ; }) /** @@ -946,26 +1013,44 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit wnd.setWindowBrightness(1, (err) => { if (err.code) { console.error('Failed to set the brightnesscallback01. Cause: ' + JSON.stringify(err)); - expect(err.code).assertEqual(401); + try { + expect(err.code).assertEqual(401); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } else { - expect(TRUE_FLAG).assertTrue(); + try { + expect(TRUE_FLAG).assertTrue(); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } try { let properties = wnd.getWindowProperties(); - expect(properties.brightness).assertEqual(1); + try { + expect(properties.brightness).assertEqual(1); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } catch (exception) { console.error('Failed04 to obtain the window properties. Cause: ' + JSON.stringify(exception)); - expect(exception.code).assertEqual(401); + try { + expect(exception.code).assertEqual(401); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); - }; + } + ; } }); } catch (exception) { - console.error('Failedca02 to set the brightness. Cause: ' + JSON.stringify(exception)); - expect(exception.code).assertEqual(401); - done() - }; + console.error('Failedca02 to set the brightness. Cause: ' + JSON.stringify(exception)); + expect(exception.code).assertEqual(401); + done() + } + ; }) /** @@ -982,11 +1067,19 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit wnd.setWindowBrightness(brightness, (err) => { if (err.code) { console.error('Failed to set the brightnesscallback3. Cause: ' + JSON.stringify(err)); - expect(err.code).assertEqual(401); + try { + expect(err.code).assertEqual(401); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } else { console.info('windowTest setBrightnessTest3CallBack setBrightness(Number.MAX_VALUE) success '); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } }); @@ -994,7 +1087,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the brightnesscall3CallBack. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done(); - }; + } + ; }) /** @@ -1010,11 +1104,19 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit wnd.setWindowBrightness(Number.MIN_VALUE, (err) => { if (err.code) { console.error('Failed to set the brightnesscallback4. Cause: ' + JSON.stringify(err)); - expect(err.code).assertEqual(401); + try { + expect(err.code).assertEqual(401); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } else { console.info('windowTest setBrightnessTest4CallBack setBrightness(Number.MAX_VALUE) success '); - expect(TRUE_FLAG).assertTrue(); + try { + expect(TRUE_FLAG).assertTrue(); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } }); @@ -1022,7 +1124,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the brightnesscall4CallBack. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done(); - }; + } + ; }) /** @@ -1038,11 +1141,19 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit wnd.setWindowBrightness(1.1, (err) => { if (err.code) { console.error('Failed to set the brightnesscallback5. Cause: ' + JSON.stringify(err)); - expect(err.code).assertEqual(401); + try { + expect(err.code).assertEqual(401); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } else { console.info('windowTest setBrightnessTest5CallBack setBrightness(Number.MAX_VALUE) success '); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } }); @@ -1050,7 +1161,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the brightnesscall5CallBack. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done(); - }; + } + ; }) /** @@ -1065,20 +1177,36 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit wnd.setWindowFocusable(false, (err, data) => { if (err.code) { console.error('Failed to set the window to be setFocusable. Cause:' + JSON.stringify(err)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } else { let data = wnd.getWindowProperties(); - expect(!data.focusable).assertTrue(); + try { + expect(!data.focusable).assertTrue(); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } wnd.setWindowFocusable(true, (err, data) => { if (err.code) { console.error('Failed to set the window to be setFocusable. Cause:' + JSON.stringify(err)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } done(); } else { - let data2 = wnd.getWindowProperties(); - expect(data2.focusable).assertTrue(); - done(); + let data2 = wnd.getWindowProperties(); + try { + expect(data2.focusable).assertTrue(); + } catch (error) { + console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) + } + done(); } }) } @@ -1103,14 +1231,14 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit expect(TRUE_FLAG).assertTrue(); done(); }, err => { - console.info('windowTest setFocusableTest1 setFocusable failed: err' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info('windowTest setFocusableTest1 setFocusable failed: err' + JSON.stringify(err)); + expect().assertFail(); + done(); }) }, (err) => { - console.log('windowTest setWinFocusableTest1 setFocusable failed: err' + JSON.stringify(err)); - expect().assertFail(); - done(); + console.log('windowTest setWinFocusableTest1 setFocusable failed: err' + JSON.stringify(err)); + expect().assertFail(); + done(); }) }) @@ -1165,11 +1293,19 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit wnd.setWindowTouchable(true, (err, data) => { if (err.code) { console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`wnd.setWindowTouchable catch error: ${JSON.stringify(error)}`) + } done(); } else { let data2 = wnd.getWindowProperties(); - expect(data2.touchable).assertTrue(); + try { + expect(data2.touchable).assertTrue(); + } catch (error) { + console.info(`wnd.setWindowTouchable catch error: ${JSON.stringify(error)}`) + } done(); } }) @@ -1233,12 +1369,20 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit wnd.setWindowKeepScreenOn(true, (err, data) => { if (err.code) { console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`wnd.setWindowKeepScreenOn catch error: ${JSON.stringify(error)}`) + } done(); } else { console.info('success set the screen to be always on. Cause: ' + JSON.stringify(data)); let data2 = wnd.getWindowProperties(); - expect(data2.isKeepScreenOn).assertTrue(); + try { + expect(data2.isKeepScreenOn).assertTrue(); + } catch (error) { + console.info(`wnd.setWindowKeepScreenOn catch error: ${JSON.stringify(error)}`) + } done(); } }) @@ -1300,15 +1444,23 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); try { - wnd.setWindowPrivacyMode(true, (err) => { + wnd.setWindowPrivacyMode(true, (err) => { if (err.code) { console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (error) { + console.info(`wnd.setWindowPrivacyMode catch error: ${JSON.stringify(error)}`) + } done(); } else { console.info('Succeeded in setting the window to privacy mode.'); let data2 = wnd.getWindowProperties(); - expect(data2.isPrivacyMode).assertTrue(); + try { + expect(data2.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`wnd.setWindowPrivacyMode catch error: ${JSON.stringify(error)}`) + } done(); } }); @@ -1316,7 +1468,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done(); - }; + } + ; }) }) -- GitLab