diff --git a/graphic/windowStage/entry/src/main/ets/test/List.test.ets b/graphic/windowStage/entry/src/main/ets/test/List.test.ets index 5fcf104031c3f3ed65a3eb19502054af540fc515..a548c635d4584e7ecd7d79f3d4ee38d32e07c4c8 100644 --- a/graphic/windowStage/entry/src/main/ets/test/List.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/List.test.ets @@ -18,9 +18,8 @@ import windowRefactorInterfaceTest from './windowRefactorInterface.test' import displayAndWindowRefactorInterfaceTest from './displayAndWindowRefactorInterface.test' export default function testsuite() { - windowPromiseTest(globalThis.abilityContext,globalThis.windowStage,globalThis.abilityStorage) windowCallbackTest(globalThis.abilityContext,globalThis.windowStage,globalThis.abilityStorage) + windowPromiseTest(globalThis.abilityContext,globalThis.windowStage,globalThis.abilityStorage) windowRefactorInterfaceTest(globalThis.abilityContext,globalThis.windowStage,globalThis.abilityStorage) displayAndWindowRefactorInterfaceTest(globalThis.abilityContext,globalThis.windowStage,globalThis.abilityStorage) - } \ No newline at end of file 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 33ef4bdf3af299e0ddf38205d7e75cad9caddd17..73b9f52630bd997790b101a011eb187d191e2326 100644 --- a/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/displayAndWindowRefactorInterface.test.ets @@ -113,23 +113,26 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta done(); } - function sleep(time) { - return new Promise(resolve => { - setTimeout(() => { + async function sleep(time) { + let timeoutId= null; + let promise = new Promise(resolve => { + timeoutId = setTimeout(() => { resolve('sleep finished'); }, time); }) + let result = await promise; + clearTimeout(timeoutId) } /** - * @tc.number SUB_WINDOW_GETALLDISPLAYS_JSAPI_001 - * @tc.name Test getAllDisplaysTest1 - * @tc.desc Gets all current display objects - */ + * @tc.number SUB_WINDOW_GETALLDISPLAYS_JSAPI_001 + * @tc.name Test getAllDisplaysTest1 + * @tc.desc Gets all current display objects + */ it('getAllDisplaysTest1', 0, async function (done) { let caseName = 'getAllDisplaysTest1'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); - display.getAllDisplays().then((data) => { + await display.getAllDisplays().then((data) => { console.info(msgStr + 'Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)); expect(data[0].id != null).assertTrue(); expect(data[0].refreshRate != null).assertTrue(); @@ -152,10 +155,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta }); }) /** - * @tc.number SUB_WINDOW_GETALLDISPLAYS_JSAPI_002 - * @tc.name Test getAllDisplaysTest2 - * @tc.desc Gets all current display objects - */ + * @tc.number SUB_WINDOW_GETALLDISPLAYS_JSAPI_002 + * @tc.name Test getAllDisplaysTest2 + * @tc.desc Gets all current display objects + */ it('getAllDisplaysTest2', 0, async function (done) { let caseName = 'getAllDisplaysTest2'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -189,20 +192,17 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta }); }) /** - * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_001 - * @tc.name Test createWindowTest1 - * @tc.desc Verify the scenario of creating the application type window - */ + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_001 + * @tc.name Test createWindowTest1 + * @tc.desc Verify the scenario of creating the application type window + */ it('createWindowTest1', 0, async function (done) { let caseName = 'createWindowTest1'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); let loopCount = systemWindowTypeDicArr.length; console.log(msgStr + 'loopCount: ' + loopCount); - let num = 0 - getData(0, loopCount) - - async function getData(i, length) { + for(let i=0;i { - console.log(msgStr + 'ohosWindow.createWindow ' + tempType + 'catched, err: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); - }); - console.log(msgStr + 'ohosWindow.createWindow ' + tempType + 'finished, wnd: ' + JSON.stringify(tempWnd)); - expect(!!tempWnd).assertTrue(); - num++; - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + 'catched, err: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + return; + }); + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + 'finished, wnd: ' + JSON.stringify(tempWnd)); + console.log(msgStr + 'ohosWindow.createWindow ' + tempType + 'finished, step: ' + i); + expect(!!tempWnd).assertTrue(); + await tempWnd.destroyWindow(); + if (i == loopCount-1) done(); } }) /** - * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_002 - * @tc.name Test createWindowTest2 - * @tc.desc Verify the scenario of creating a window with duplicate IDs - */ + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_002 + * @tc.name Test createWindowTest2 + * @tc.desc Verify the scenario of creating a window with duplicate IDs + */ it('createWindowTest2', 0, async function (done) { let caseName = 'createWindowTest2'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -248,16 +241,20 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let windowConfig = { name: windowId, windowType: 1, ctx: context }; + let ohosData; try { - let ohosData = await ohosWindow.createWindow(windowConfig).catch((err) => { + 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().assertFail(); + done(); + return; }) expect(!!ohosData).assertTrue(); try { - let ohosDataError = await ohosWindow.createWindow(windowConfig).catch((errSencond) => { + let ohosDataError = await ohosWindow.createWindow(windowConfig).catch(async (errSencond) => { console.log(msgStr + 'ohosWindow.createWindow 1 twice err: ' + JSON.stringify(errSencond)); expect(errSencond.code).assertEqual(1300002) + await ohosData.destroyWindow(); done(); }) console.log(msgStr + 'ohosWindow.createWindow 1 twice ohosDataError: ' + JSON.stringify(ohosDataError)); @@ -269,14 +266,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); } ; - }) /** - * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_004 - * @tc.name Test createWindowTest4 - * @tc.desc Verify the scenario of creating the application type window + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_004 + * @tc.name Test createWindowTest4 + * @tc.desc Verify the scenario of creating the application type window */ - it('createWindowTest4', 0, done => { + it('createWindowTest4', 0, async function (done) { sleep(1000) let caseName = 'createWindowTest4'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -291,43 +287,60 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let windowConfigTwo = { name: windIdTwo, windowType: tempType, ctx: context }; - try { - ohosWindow.createWindow(windowConfig, (err, data) => { - if (err && err.code) { - console.log(msgStr + 'ohosWindow.createWindow err.code==' + JSON.stringify(err.code)) - return; - } - console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`ohosWindow.crreateWindow catch error: ${JSON.stringify(error)}`) - } + + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - ohosWindow.createWindow(windowConfigTwo, (err, dataTwo) => { - console.log(msgStr + 'ohosWindow.createWindow two twice' + JSON.stringify(err)); + ohosWindow.createWindow(windowConfig, (err, data) => { if (err && err.code) { - console.log(msgStr + 'ohosWindow.createWindow two twice data: ' + JSON.stringify(dataTwo)); - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); - } else { - console.log(msgStr + 'ohosWindow.createWindow two success twice data: ' + JSON.stringify(dataTwo)); + console.log(msgStr + 'ohosWindow.createWindow err.code==' + JSON.stringify(err.code)) + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } done(); + reject(null) } + console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); + resolve(data) }) } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); } ; }) + } + + let dataOne; + dataOne = await createFirstWindow(); + expect(!!dataOne).assertTrue(); + try { + ohosWindow.createWindow(windowConfigTwo, async (err, dataTwo) => { + console.log(msgStr + 'ohosWindow.createWindow two twice' + JSON.stringify(err)); + if (err && err.code) { + console.log(msgStr + 'ohosWindow.createWindow two twice data: ' + JSON.stringify(dataTwo)); + try { + expect().assertFail(); + } catch (error) { + console.info(`ohosWindow.createWindow two twice catch error: ${JSON.stringify(error)}`) + } + } else { + console.log(msgStr + 'ohosWindow.createWindow two success twice data: ' + JSON.stringify(dataTwo)); + await dataOne.destroyWindow(); + await dataTwo.destroyWindow(); + } + done(); + }) } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); } ; }) /** - * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_005 - * @tc.name Test createWindowTest5 - * @tc.desc Verify the scenario of creating the system type window + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_005 + * @tc.name Test createWindowTest5 + * @tc.desc Verify the scenario of creating the system type window */ it('createWindowTest5', 0, done => { let caseName = 'createWindowTest5'; @@ -342,15 +355,20 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta name: windId, windowType: tempType, ctx: context }; try { - ohosWindow.createWindow(windowConfig, (err, data) => { + ohosWindow.createWindow(windowConfig, async (err, data) => { if (err && err.code) { - unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); + try { + expect().assertFail(); + } catch (error) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + done(); return; } try { expect(!!data).assertTrue(); } catch (error) { - console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) } let tempWnd = data console.log(msgStr + 'ohosWindow.createWindow ' + tempType + ' wnd: ' + tempWnd); @@ -358,6 +376,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let proData = tempWnd.getWindowProperties(); console.log(msgStr + 'proData.type:' + proData.type); expect(proData.type == tempType).assertTrue(); + await tempWnd.destroyWindow(); done(); } catch (exception) { console.error(msgStr + 'Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); @@ -370,11 +389,11 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_006 - * @tc.name Test createWindowTest6 - * @tc.desc Verify the scenario of creating a window with duplicate IDs + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_006 + * @tc.name Test createWindowTest6 + * @tc.desc Verify the scenario of creating a window with duplicate IDs */ - it('createWindowTest6', 0, done => { + it('createWindowTest6', 0, async function (done) { let caseName = 'createWindowTest6'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); @@ -382,50 +401,60 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let winsowConfig = { name: windowId, windowType: 1, ctx: context }; - try { - ohosWindow.createWindow(winsowConfig, (err, data) => { - console.log(msgStr + 'ohosWindow.createWindow 1 once err: ' + JSON.stringify(err)); - if (err && err.code) { - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); - return - } - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) - } + + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - ohosWindow.createWindow(winsowConfig, (err, dataTwo) => { - console.log(msgStr + 'ohosWindow.createWindow 1 twice err: ' + JSON.stringify(err)); + ohosWindow.createWindow(winsowConfig, (err, data) => { + console.log(msgStr + 'ohosWindow.createWindow 1 once err: ' + JSON.stringify(err)); if (err && err.code) { - console.log(msgStr + 'ohosWindow.createWindow 1 twice data: ' + JSON.stringify(dataTwo)); try { - expect(err.code).assertEqual(1300002) + expect().assertFail(); } catch (error) { - console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + console.info(msgStr + `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)); + reject(null) } + resolve(data) }) } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); } ; + }) + } + let dataOne; + dataOne = await createFirstWindow(); + expect(!!dataOne).assertTrue(); + try { + ohosWindow.createWindow(winsowConfig, async (err, dataTwo) => { + console.log(msgStr + 'ohosWindow.createWindow 1 twice err: ' + JSON.stringify(err)); + if (err && err.code) { + console.log(msgStr + 'ohosWindow.createWindow 1 twice data: ' + JSON.stringify(dataTwo)); + try { + expect(err.code).assertEqual(1300002) + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + } else { + console.log(msgStr + 'ohosWindow.createWindow 1 twice data: ' + JSON.stringify(dataTwo)); + } + await dataOne.destroyWindow(); + done(); }) } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; - }) /** - * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_001 - * @tc.name Test getWindowAvoidAreaTest1 - * @tc.desc Obtain the area that the window content avoids + * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_001 + * @tc.name Test getWindowAvoidAreaTest1 + * @tc.desc Obtain the area that the window content avoids */ it('getWindowAvoidAreaTest1', 0, async function (done) { let caseName = 'getWindowAvoidAreaTest1'; @@ -456,9 +485,9 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta }) /** - * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_002 - * @tc.name Test getWindowAvoidAreaTest2 - * @tc.desc Obtain the area that the window content avoids + * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_002 + * @tc.name Test getWindowAvoidAreaTest2 + * @tc.desc Obtain the area that the window content avoids */ it('getWindowAvoidAreaTest2', 0, async function (done) { let caseName = 'getWindowAvoidAreaTest2'; @@ -489,9 +518,9 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_003 - * @tc.name Test getWindowAvoidAreaTest3 - * @tc.desc Obtain the area that the window content avoids + * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_003 + * @tc.name Test getWindowAvoidAreaTest3 + * @tc.desc Obtain the area that the window content avoids */ it('getWindowAvoidAreaTest3', 0, async function (done) { let caseName = 'getWindowAvoidAreaTest3'; @@ -521,9 +550,9 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_004 - * @tc.name Test getWindowAvoidAreaTest4 - * @tc.desc Obtain the area that the window content avoids + * @tc.number SUB_WINDOW_GETWINDOWAVOIDAREA_JSAPI_004 + * @tc.name Test getWindowAvoidAreaTest4 + * @tc.desc Obtain the area that the window content avoids */ it('getWindowAvoidAreaTest4', 0, async function (done) { let caseName = 'getWindowAvoidAreaTest4'; @@ -553,9 +582,9 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_GETWINDOWPROPERTIES_JSAPI_001 - * @tc.name Test getWindowPropertiesTest1 - * @tc.desc Gets the properties of the current window + * @tc.number SUB_WINDOW_GETWINDOWPROPERTIES_JSAPI_001 + * @tc.name Test getWindowPropertiesTest1 + * @tc.desc Gets the properties of the current window */ it('getWindowPropertiesTest1', 0, async function (done) { let caseName = 'getWindowPropertiesTest1'; @@ -584,6 +613,8 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta done(); } catch (exception) { console.error(msgStr + 'Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; } catch (exception) { @@ -592,10 +623,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_GETLASTWINDOW_JSAPI_001 - * @tc.name Test getLastWindowTest1 - * @tc.desc Get the final show window - */ + * @tc.number SUB_WINDOW_GETLASTWINDOW_JSAPI_001 + * @tc.name Test getLastWindowTest1 + * @tc.desc Get the final show window + */ it('getLastWindowTest1', 0, async function (done) { let caseName = 'getLastWindowTest1'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -604,20 +635,23 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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().assertFail(); + done(); }) expect(lastWindow != null).assertTrue(); done(); } catch (exception) { console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_GETLASTWINDOW_JSAPI_002 - * @tc.name Test getLastWindowTest2 - * @tc.desc Get the final show window - */ + * @tc.number SUB_WINDOW_GETLASTWINDOW_JSAPI_002 + * @tc.name Test getLastWindowTest2 + * @tc.desc Get the final show window + */ it('getLastWindowTest2', 0, async function (done) { let caseName = 'getLastWindowTest2'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -626,7 +660,12 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ohosWindow.getLastWindow(context, (err, data) => { if (err.code) { console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + try { + expect().assertFail(); + } catch (error) { + console.info(msgStr + `ohosWindow.getLastWindow catch error: ${JSON.stringify(error)}`) + } + done(); return; } console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); @@ -638,10 +677,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_SHOWWINDOW_JSAPI_001 - * @tc.name Test showWindowTest1 - * @tc.desc show window - */ + * @tc.number SUB_WINDOW_SHOWWINDOW_JSAPI_001 + * @tc.name Test showWindowTest1 + * @tc.desc show window + */ it('showWindowTest1', 0, async function (done) { let caseName = 'showWindowTest1'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -654,27 +693,32 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let tempWnd = null; try { tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + expect().assertFail(); + done(); }); console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + JSON.stringify(tempWnd)); expect(!!tempWnd).assertTrue(); - tempWnd.showWindow().then((data) => { + await tempWnd.showWindow().then(async (data) => { console.info(msgStr + 'Succeeded in showing the window. Data: ' + JSON.stringify(data)); + await tempWnd.destroyWindow(); done(); }).catch((err) => { console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.showWindow', done); + expect().assertFail(); + done(); }) } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_SHOWWINDOW_JSAPI_002 - * @tc.name Test showWindowTest2 - * @tc.desc show window - */ + * @tc.number SUB_WINDOW_SHOWWINDOW_JSAPI_002 + * @tc.name Test showWindowTest2 + * @tc.desc show window + */ it('showWindowTest2', 0, async function (done) { let caseName = 'showWindowTest2'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -684,38 +728,55 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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; - } + + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - expect(!!create_data).assertTrue(); - } catch (error) { - console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) + } + done(); + reject(null) + } + resolve(create_data) + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); } - create_data.showWindow((err, data) => { - if (err.code) { - console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); - return; - } - console.info(msgStr + 'Succeeded in showing the window. Data: ' + JSON.stringify(data)); - done(); - }) + ; }) - } catch (exception) { - console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); } - ; + + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + winData.showWindow(async (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.showWindow catch error: ${JSON.stringify(err)}`) + } + done(); + return; + } + console.info(msgStr + 'Succeeded in showing the window. Data: ' + JSON.stringify(data)); + await winData.destroyWindow(); + done(); + }) + }) /** - * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_001 - * @tc.name Test moveWindowToTest1 - * @tc.desc Set the position of a window. - */ + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_001 + * @tc.name Test moveWindowToTest1 + * @tc.desc Set the position of a window. + */ it('moveWindowToTest1', 0, async function (done) { let caseName = 'moveWindowToTest1'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -726,34 +787,43 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta name: windowId, windowType: baseWndType, ctx: context }; try { - ohosWindow.createWindow(windowConfig).then((wnd) => { + await ohosWindow.createWindow(windowConfig).then(async (wnd) => { console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(wnd)); expect(wnd != null).assertTrue(); try { - wnd.moveWindowTo(300, 300).then(() => { + await wnd.moveWindowTo(300, 300).then(async () => { console.info(msgStr + 'Succeeded in moving the window.'); + await wnd.destroyWindow(); done(); - }).catch((err) => { + }).catch(async (err) => { console.error(msgStr + 'Failed to move the window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'tempWnd.moveWindowTo', done); + expect().assertFail(); + await wnd.destroyWindow(); + done(); }); } catch (exception) { console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }).catch((err) => { console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_002 - * @tc.name Test moveWindowToTest2 - * @tc.desc Set the position of a window. - */ + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_002 + * @tc.name Test moveWindowToTest2 + * @tc.desc Set the position of a window. + */ it('moveWindowToTest2', 0, async function (done) { let caseName = 'moveWindowToTest2'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -764,34 +834,43 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta name: windowId, windowType: baseWndType, ctx: context }; try { - ohosWindow.createWindow(windowConfig).then((wnd) => { + await ohosWindow.createWindow(windowConfig).then(async (wnd) => { console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(wnd)); expect(wnd != null).assertTrue(); try { - wnd.moveWindowTo(100, 50).then(() => { + await wnd.moveWindowTo(100, 50).then(async () => { console.info(msgStr + 'Succeeded in moving the window.'); + await wnd.destroyWindow(); done(); - }).catch((err) => { + }).catch(async (err) => { console.error(msgStr + 'Failed to move the window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'tempWnd.moveWindowTo', done); + expect().assertFail(); + await wnd.destroyWindow(); + done(); }); } catch (exception) { console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }).catch((err) => { console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_003 - * @tc.name Test moveWindowToTest3 - * @tc.desc Set the position of a window. - */ + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_003 + * @tc.name Test moveWindowToTest3 + * @tc.desc Set the position of a window. + */ it('moveWindowToTest3', 0, async function (done) { let caseName = 'moveWindowToTest3'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -802,34 +881,43 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta name: windowId, windowType: baseWndType, ctx: context }; try { - ohosWindow.createWindow(windowConfig).then((wnd) => { + await ohosWindow.createWindow(windowConfig).then(async (wnd) => { console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(wnd)); expect(wnd != null).assertTrue(); try { - wnd.moveWindowTo(20000, 20000).then(() => { + await wnd.moveWindowTo(20000, 20000).then(async () => { console.info(msgStr + 'Succeeded in moving the window.'); + await wnd.destroyWindow(); done(); - }).catch((err) => { + }).catch(async (err) => { console.error(msgStr + 'Failed to move the window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'tempWnd.moveWindowTo', done); + expect().assertFail(); + await wnd.destroyWindow(); + done(); }); } catch (exception) { console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }).catch((err) => { console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_004 - * @tc.name Test moveWindowToTest4 - * @tc.desc Set the position of a window. - */ + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_004 + * @tc.name Test moveWindowToTest4 + * @tc.desc Set the position of a window. + */ it('moveWindowToTest4', 0, async function (done) { let caseName = 'moveWindowToTest4'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -840,34 +928,43 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta name: windowId, windowType: baseWndType, ctx: context }; try { - ohosWindow.createWindow(windowConfig).then((wnd) => { + await ohosWindow.createWindow(windowConfig).then(async (wnd) => { console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(wnd)); expect(wnd != null).assertTrue(); try { - wnd.moveWindowTo(-200, -200).then(() => { + await wnd.moveWindowTo(-200, -200).then(async () => { console.info(msgStr + 'Succeeded in moving the window.'); + await wnd.destroyWindow(); done(); - }).catch((err) => { + }).catch(async (err) => { console.error(msgStr + 'Failed to move the window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'tempWnd.moveWindowTo', done); + expect().assertFail(); + await wnd.destroyWindow(); + done(); }); } catch (exception) { console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }).catch((err) => { console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); + expect().assertFail(); + done(); }); } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_005 - * @tc.name Test moveWindowToTest5 - * @tc.desc Set the position of a window. - */ + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_005 + * @tc.name Test moveWindowToTest5 + * @tc.desc Set the position of a window. + */ it('moveWindowToTest5', 0, async function (done) { let caseName = 'moveWindowToTest5'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -877,38 +974,57 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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; - } + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - create_data.moveWindowTo(300, 300, (err, data) => { - if (err.code) { - console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.moveWindowTo', done); - return; + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) + } + done(); + reject(null) } - console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); - done(); + resolve(create_data) }) } catch (exception) { - console.error(msgStr + 'Failed to move 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)); } - ; + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + try { + winData.moveWindowTo(300, 300, async (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'ohosWindow.moveWindow catch' + JSON.stringify(err)); + } + await winData.destroyWindow(); + done(); + return; + } + console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + await winData.destroyWindow(); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + }; }) /** - * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_006 - * @tc.name Test moveWindowToTest6 - * @tc.desc Set the position of a window. - */ + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_006 + * @tc.name Test moveWindowToTest6 + * @tc.desc Set the position of a window. + */ it('moveWindowToTest6', 0, async function (done) { let caseName = 'moveWindowToTest6'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -918,38 +1034,57 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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; - } + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - create_data.moveWindowTo(100, 50, (err, data) => { - if (err.code) { - console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.moveWindowTo', done); - return; + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) + } + done(); + reject(null) } - console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); - done(); + resolve(create_data) }) } catch (exception) { - console.error(msgStr + 'Failed to move 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)); } - ; + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + try { + winData.moveWindowTo(100, 50, async (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } + await winData.destroyWindow(); + done(); + return; + } + console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + await winData.destroyWindow(); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + }; }) /** - * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_007 - * @tc.name Test moveWindowToTest7 - * @tc.desc Set the position of a window. - */ + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_007 + * @tc.name Test moveWindowToTest7 + * @tc.desc Set the position of a window. + */ it('moveWindowToTest7', 0, async function (done) { let caseName = 'moveWindowToTest7'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -959,38 +1094,57 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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; - } + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - create_data.moveWindowTo(20000, 20000, (err, data) => { - if (err.code) { - console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.moveWindowTo', done); - return; + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) + } + done(); + reject(null) } - console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); - done(); + resolve(create_data) }) } catch (exception) { - console.error(msgStr + 'Failed to move 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)); } - ; + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + try { + winData.moveWindowTo(20000, 20000, async (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } + await winData.destroyWindow(); + done(); + return; + } + console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + await winData.destroyWindow(); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + }; }) /** - * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_008 - * @tc.name Test moveWindowToTest8 - * @tc.desc Set the position of a window. - */ + * @tc.number SUB_WINDOW_MOVEWINDOWTO_JSAPI_008 + * @tc.name Test moveWindowToTest8 + * @tc.desc Set the position of a window. + */ it('moveWindowToTest8', 0, async function (done) { let caseName = 'moveWindowToTest8'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1000,38 +1154,57 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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; - } + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - create_data.moveWindowTo(-200, -200, (err, data) => { - if (err.code) { - console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.moveWindowTo', done); - return; - } - console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); - done(); + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) + } + done(); + reject(null) + } + resolve(create_data) }) } catch (exception) { - console.error(msgStr + 'Failed to move 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)); } - ; + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + try { + winData.moveWindowTo(-200, -200, async (err, data) => { + if (err.code) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } + await winData.destroyWindow(); + done(); + return; + } + console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + await winData.destroyWindow(); + done(); + }) + } catch (exception) { + console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(exception)); + }; }) /** - * @tc.number SUB_WINDOW_RESIZE_JSAPI_001 - * @tc.name Test resizeTest1 - * @tc.desc Set the size of a window - */ + * @tc.number SUB_WINDOW_RESIZE_JSAPI_001 + * @tc.name Test resizeTest1 + * @tc.desc Set the size of a window + */ it('resizeTest1', 0, async function (done) { let caseName = 'resizeTest1'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1049,27 +1222,34 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); expect(!!tempWnd).assertTrue(); try { - tempWnd.resize(200, 600).then((data) => { + await tempWnd.resize(200, 600).then(async (data) => { console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + await tempWnd.destroyWindow(); done(); - }).catch((err) => { + }).catch(async (err) => { console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'tempWnd.resize', done); + expect().assertFail(); + await tempWnd.destroyWindow(); + done(); }) } catch (exception) { console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_RESIZE_JSAPI_002 - * @tc.name Test resizeTest2 - * @tc.desc Set the size of a window - */ + * @tc.number SUB_WINDOW_RESIZE_JSAPI_002 + * @tc.name Test resizeTest2 + * @tc.desc Set the size of a window + */ it('resizeTest2', 0, async function (done) { let caseName = 'resizeTest2'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1087,27 +1267,34 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); expect(!!tempWnd).assertTrue(); try { - tempWnd.resize(20000, 20000).then((data) => { + await tempWnd.resize(20000, 20000).then(async (data) => { console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + await tempWnd.destroyWindow(); done(); - }).catch((err) => { + }).catch(async (err) => { console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'tempWnd.resize', done); + expect().assertFail(); + await tempWnd.destroyWindow(); + done(); }) } catch (exception) { console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_RESIZE_JSAPI_003 - * @tc.name Test resizeTest3 - * @tc.desc Set the size of a window - */ + * @tc.number SUB_WINDOW_RESIZE_JSAPI_003 + * @tc.name Test resizeTest3 + * @tc.desc Set the size of a window + */ it('resizeTest3', 0, async function (done) { let caseName = 'resizeTest3'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1120,35 +1307,42 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let tempWnd = null; try { tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + expect().assertFail(); + done(); + return; }); console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); expect(!!tempWnd).assertTrue(); try { - tempWnd.resize(0, 0).then((data) => { + await tempWnd.resize(0, 0).then(async (data) => { console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + await tempWnd.destroyWindow(); done(); - }).catch((err) => { + }).catch(async (err) => { console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); expect(err.code).assertEqual(401); + await tempWnd.destroyWindow(); done(); }) } catch (exception) { console.error(msgStr + 'try catch Failed to change the window size. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); + await tempWnd.destroyWindow(); done(); } ; } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_RESIZE_JSAPI_004 - * @tc.name Test resizeTest4 - * @tc.desc Set the size of a window - */ + * @tc.number SUB_WINDOW_RESIZE_JSAPI_004 + * @tc.name Test resizeTest4 + * @tc.desc Set the size of a window + */ it('resizeTest4', 0, async function (done) { let caseName = 'resizeTest4'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1161,35 +1355,42 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let tempWnd = null; try { tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + expect().assertFail(); + done(); + return; }); console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); expect(!!tempWnd).assertTrue(); try { - tempWnd.resize(-1, -1).then((data) => { + await tempWnd.resize(-1, -1).then(async (data) => { console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); + await tempWnd.destroyWindow(); done(); - }).catch((err) => { + }).catch(async (err) => { console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); expect(err.code).assertEqual(401); + await tempWnd.destroyWindow(); done(); }) } catch (exception) { console.error(msgStr + 'try catch Failed to change the window size. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); + await tempWnd.destroyWindow(); done(); } ; } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_RESIZE_JSAPI_005 - * @tc.name Test resizeTest5 - * @tc.desc Set the size of a window - */ + * @tc.number SUB_WINDOW_RESIZE_JSAPI_005 + * @tc.name Test resizeTest5 + * @tc.desc Set the size of a window + */ it('resizeTest5', 0, async function (done) { let caseName = 'resizeTest5'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1202,44 +1403,39 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let tempWnd = null; try { tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + expect().assertFail(); + done(); + return; }); console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + tempWnd); expect(!!tempWnd).assertTrue(); - getData(1, 5) - - function getData(i, length) { - try { - tempWnd.resize(100, 100).then((data) => { - console.info(msgStr + 'Succeeded in changing the window size. Data:' + JSON.stringify(data)); - done(); - }).catch((err) => { - console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); - expect(err.code).assertEqual(6); - if (++i <= length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + console.error(msgStr + 'Failed to change the window size. Cause: ' + JSON.stringify(err)); + expect(err.code).assertEqual(6); + done() + return; + }) + console.log(msgStr + 'success resize current step:' + i) + if(i==4){ + console.log(msgStr + 'finish resize current step:' + i) + done() } - ; } + await tempWnd.destroyWindow(); } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_RESIZE_JSAPI_006 - * @tc.name Test resizeTest6 - * @tc.desc Set the size of a window - */ + * @tc.number SUB_WINDOW_RESIZE_JSAPI_006 + * @tc.name Test resizeTest6 + * @tc.desc Set the size of a window + */ it('resizeTest6', 0, async function (done) { let caseName = 'resizeTest6'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1249,93 +1445,133 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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; - } + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - create_data.resize(200, 200, (err) => { - if (err.code) { - console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.resize', done); - return; + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) + } + done(); + reject(null) } - console.info(msgStr + 'Succeeded in changing the window size.'); - done(); - }); + resolve(create_data) + }) } catch (exception) { - console.error(msgStr + 'Failed to change the window size. 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)); } - ; + + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + try { + winData.resize(200, 200, async (err) => { + if (err.code) { + console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } + await winData.destroyWindow(); + done(); + return; + } + console.info(msgStr + 'Succeeded in changing the window size.'); + await winData.destroyWindow(); + done(); + }); + } catch (exception) { + console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(exception)); + }; }) /** - * @tc.number SUB_WINDOW_RESIZE_JSAPI_007 - * @tc.name Test resizeTest7 - * @tc.desc Set the size of a window - */ + * @tc.number SUB_WINDOW_RESIZE_JSAPI_007 + * @tc.name Test resizeTest7 + * @tc.desc Set the size of a window + */ it('resizeTest7', 0, async function (done) { - let caseName = 'resizeTest6'; + let caseName = 'resizeTest7'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); let baseWndType = 1; let windowId = 'resizeTest7'; - let width = 100; - let height = 100; let winsowConfig = { name: windowId, windowType: baseWndType, ctx: context }; - try { - ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { - console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); - if (create_err && create_err.code) { - unexpectedError(create_err, caseName, 'ohosWindow.createWindow', done); - return; - } - getData(1, 5) - - function getData(i, length) { - width = width * i; - height = height * i; - try { - create_data.resize(width, height, (err) => { - if (err.code) { - console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.resize', done); - return; - } - console.info(msgStr + 'Succeeded in changing the window size.'); - if (++i <= length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + try { + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) } done(); - }); - } catch (exception) { - console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(exception)); - } - ; + reject(null) + } + resolve(create_data) + }) + } 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)); } - ; + function resizeFun(width, height,i){ + console.log(msgStr + 'resize begin step:'+i) + return new Promise((resolve,reject)=>{ + try { + winData.resize(width, height, async (err) => { + if (err.code) { + console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } + done(); + reject(null) + } + console.info(msgStr + 'Succeeded in changing the window size. step:'+i); + resolve(true) + }); + } catch (exception) { + console.error(msgStr + 'Failed to change the window size. Cause:' + JSON.stringify(exception)); + }; + }) + } + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + let width = 100; + let height = 100; + for(let i=1;i<5;i++){ + width = width * i; + height = height * i; + await resizeFun(width, height,i); + if(i==4){ + console.log(msgStr + 'resize finished step:'+i) + await winData.destroyWindow(); + done() + } + } }) /** - * @tc.number SUB_WINDOW_DESTROYWINDOW_JSAPI_001 - * @tc.name Test destroyWindowTest1 - * @tc.desc Verification window destruction scenario. - */ + * @tc.number SUB_WINDOW_DESTROYWINDOW_JSAPI_001 + * @tc.name Test destroyWindowTest1 + * @tc.desc Verification window destruction scenario. + */ it('destroyWindowTest1', 0, async function (done) { let caseName = 'destroyWindowTest1'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1348,11 +1584,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta let tempWnd = null; try { tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { - unexpectedError(err, caseName, 'ohosWindow.createWindow', done); + expect().assertFail(); + done(); + return; }); console.log(msgStr + 'ohosWindow.createWindow ' + baseWndType + ' wnd: ' + JSON.stringify(tempWnd)); expect(!!tempWnd).assertTrue(); - tempWnd.destroyWindow().then(() => { + await tempWnd.destroyWindow().then(() => { console.info(msgStr + 'Succeeded in destroying the window.'); try { let findWnd = ohosWindow.findWindow(windowId) @@ -1366,19 +1604,22 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }).catch((err) => { console.error(msgStr + 'try catch Failed to destroy the window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'tempWnd.destroyWindow', done); + expect().assertFail(); + done(); }) } catch (exception) { console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_DESTROYWINDOW_JSAPI_002 - * @tc.name Test destroyWindowTest2 - * @tc.desc Verification window destruction scenario - */ - it('destroyWindowTest2', 0, function (done) { + * @tc.number SUB_WINDOW_DESTROYWINDOW_JSAPI_002 + * @tc.name Test destroyWindowTest2 + * @tc.desc Verification window destruction scenario + */ + it('destroyWindowTest2', 0, async function (done) { let caseName = 'destroyWindowTest2'; let msgStr = 'jsunittest ' + caseName + ' '; let baseWndType = 1; @@ -1387,45 +1628,57 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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; - } + function createFirstWindow() { + return new Promise((resolve, reject) => { 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(); + ohosWindow.createWindow(winsowConfig, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) + } done(); + reject(null) } - ; - } - }) + resolve(create_data) + }) + } 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)); } - ; + + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + winData.destroyWindow((err) => { + if (err.code != 0) { + console.log('windowTest DestroyTest2 create callback fail' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } + } else { + try { + let findWnd = ohosWindow.findWindow(windowId) + expect(!findWnd).assertTrue(); + } catch (exception) { + console.error(msgStr + 'try catch Failed to find the Window. Cause: ' + JSON.stringify(exception)); + expect(exception.code === 1300002).assertTrue(); + } + ; + } + done(); + }) }) /** - * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_001 - * @tc.name Test setWindowSystemBarEnableTest1 - * @tc.desc Set the visible mode of navigation bar and status bar + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_001 + * @tc.name Test setWindowSystemBarEnableTest1 + * @tc.desc Set the visible mode of navigation bar and status bar */ it('setWindowSystemBarEnableTest1', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest1'; @@ -1434,11 +1687,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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().assertFail(); + done(); + return; }) expect(wnd != null).assertTrue(); try { - wnd.setWindowSystemBarEnable([]).then(() => { + await wnd.setWindowSystemBarEnable([]).then(() => { console.info(msgStr + 'Succeeded in setting the system bar to be invisible.'); expect(TRUE_FLAG).assertTrue(); done(); @@ -1449,17 +1704,21 @@ 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)); + expect().assertFail(); + done(); } ; } catch (exception) { console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_002 - * @tc.name Test setWindowSystemBarEnableTest2 - * @tc.desc Set the visible mode of navigation bar and status bar + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_002 + * @tc.name Test setWindowSystemBarEnableTest2 + * @tc.desc Set the visible mode of navigation bar and status bar */ it('setWindowSystemBarEnableTest2', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest2'; @@ -1468,11 +1727,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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().assertFail(); + done(); + return; }) expect(wnd != null).assertTrue(); try { - wnd.setWindowSystemBarEnable(['status', 'navigation']).then(() => { + await wnd.setWindowSystemBarEnable(['status', 'navigation']).then(() => { console.info(msgStr + 'Succeeded in setting the system bar to be invisible.'); expect(TRUE_FLAG).assertTrue(); done(); @@ -1483,17 +1744,21 @@ 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)); + expect().assertFail(); + done(); } ; } catch (exception) { console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_003 - * @tc.name Test setWindowSystemBarEnableTest3 - * @tc.desc Set the visible mode of navigation bar and status bar + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_003 + * @tc.name Test setWindowSystemBarEnableTest3 + * @tc.desc Set the visible mode of navigation bar and status bar */ it('setWindowSystemBarEnableTest3', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest3'; @@ -1502,11 +1767,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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().assertFail(); + done(); + return; }) expect(wnd != null).assertTrue(); try { - wnd.setWindowSystemBarEnable(['status']).then(() => { + await wnd.setWindowSystemBarEnable(['status']).then(() => { console.info(msgStr + 'Succeeded in setting the system bar to be invisible.'); expect(TRUE_FLAG).assertTrue(); done(); @@ -1517,17 +1784,21 @@ 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)); + expect().assertFail(); + done(); } ; } catch (exception) { console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_004 - * @tc.name Test setWindowSystemBarEnableTest4 - * @tc.desc Set the visible mode of navigation bar and status bar + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_004 + * @tc.name Test setWindowSystemBarEnableTest4 + * @tc.desc Set the visible mode of navigation bar and status bar */ it('setWindowSystemBarEnableTest4', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest4'; @@ -1536,11 +1807,13 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta 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().assertFail(); + done(); + return; }) expect(wnd != null).assertTrue(); try { - wnd.setWindowSystemBarEnable(['navigation']).then(() => { + await wnd.setWindowSystemBarEnable(['navigation']).then(() => { console.info(msgStr + 'Succeeded in setting the system bar to be invisible.'); expect(TRUE_FLAG).assertTrue(); done(); @@ -1551,32 +1824,33 @@ 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)); + expect().assertFail(); + done(); } ; } catch (exception) { console.error(msgStr + 'try catch Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); + expect().assertFail(); + done(); } ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_005 - * @tc.name Test setWindowSystemBarEnableTest5 - * @tc.desc Set the visible mode of navigation bar and status bar - */ + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_005 + * @tc.name Test setWindowSystemBarEnableTest5 + * @tc.desc Set the visible mode of navigation bar and status bar + */ it('setWindowSystemBarEnableTest5', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest5'; let msgStr = 'jsunittest ' + caseName + ' '; - let baseWndType = 1; - let windowId = 'setWindowSystemBarEnableTest5'; console.log(msgStr + 'begin'); - let winsowConfig = { - name: windowId, windowType: baseWndType, ctx: context - }; let wnd = null; try { wnd = await ohosWindow.getLastWindow(context).catch((err) => { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + expect().assertFail(); + done(); + return; }) expect(wnd != null).assertTrue(); try { @@ -1584,12 +1858,20 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen(true) callback begin'); if (err.code != 0) { console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen callback fail' + JSON.stringify(err)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } done(); - } else { + return; + } + try { expect(TRUE_FLAG).assertTrue(); - done(); + } catch (err) { + console.log(msgStr + 'assertTrue catch' + JSON.stringify(err)); } + done(); }) } catch (exception) { console.error(msgStr + ' try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); @@ -1601,37 +1883,42 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_006 - * @tc.name Test setWindowSystemBarEnableTest6 - * @tc.desc Set the visible mode of navigation bar and status bar - */ + * @tc.number SUB_WINDOW_SETWINDOWSYSTEMBARENABLE_JSAPI_006 + * @tc.name Test setWindowSystemBarEnableTest6 + * @tc.desc Set the visible mode of navigation bar and status bar + */ it('setWindowSystemBarEnableTest6', 0, async function (done) { let caseName = 'setWindowSystemBarEnableTest6'; let msgStr = 'jsunittest ' + caseName + ' '; - let baseWndType = 1; - let windowId = 'setWindowSystemBarEnableTest6'; console.log(msgStr + 'begin'); - let winsowConfig = { - name: windowId, windowType: baseWndType, ctx: context - }; let wnd = null; try { wnd = await ohosWindow.getLastWindow(context).catch((err) => { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.getLastWindow', done); + expect().assertFail(); + done(); + return; }) expect(wnd != null).assertTrue(); try { - wnd.setWindowSystemBarEnable([], (err) => { + await wnd.setWindowSystemBarEnable([], (err) => { console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen(true) callback begin'); if (err.code != 0) { console.log(msgStr + 'windowTest SetLayoutFullScreenTest2 wnd.setFullScreen callback fail' + JSON.stringify(err)); - expect().assertFail(); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } done(); - } else { + return; + } + try { expect(TRUE_FLAG).assertTrue(); - done(); + } catch (err) { + console.log(msgStr + 'assertTrue catch' + JSON.stringify(err)); } + done(); }) } catch (exception) { console.error(msgStr + ' try catch Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); @@ -1643,10 +1930,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_003 - * @tc.name Test createWindowTest3 - * @tc.desc Verify the scenario of creating a window of a type that does not exist - */ + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_003 + * @tc.name Test createWindowTest3 + * @tc.desc Verify the scenario of creating a window of a type that does not exist + */ it('createWindowTest3', 0, async function (done) { let caseName = 'createWindowTest3'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1675,9 +1962,9 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_007 - * @tc.name Test createWindowTest7 - * @tc.desc Verify the scenario of creating a window of a type that does not exist + * @tc.number SUB_WINDOW_CREATEWINDOW_JSAPI_007 + * @tc.name Test createWindowTest7 + * @tc.desc Verify the scenario of creating a window of a type that does not exist */ it('createWindowTest7', 0, done => { let caseName = 'createWindowTest7'; @@ -1709,10 +1996,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_001 - * @tc.name Test setWindowLayoutFullScreenTest1 - * @tc.desc set the property of the window can layout in full screen - */ + * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_001 + * @tc.name Test setWindowLayoutFullScreenTest1 + * @tc.desc set the property of the window can layout in full screen + */ it('setWindowLayoutFullScreenTest1', 0, async function (done) { let caseName = 'setWindowLayoutFullScreenTest1'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1723,7 +2010,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta expect(wnd != null).assertTrue(); try { let isLayoutFullScreen = true; - wnd.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { + await wnd.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { console.info(msgStr + 'Succeeded in setting the window layout to full-screen mode.'); try { let propData = wnd.getWindowProperties() @@ -1750,10 +2037,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_002 - * @tc.name Test setWindowLayoutFullScreenTest2 - * @tc.desc set the property of the window can layout in full screen - */ + * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_002 + * @tc.name Test setWindowLayoutFullScreenTest2 + * @tc.desc set the property of the window can layout in full screen + */ it('setWindowLayoutFullScreenTest2', 0, async function (done) { let caseName = 'setWindowLayoutFullScreenTest2'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1763,7 +2050,7 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta expect(wnd != null).assertTrue(); try { let isLayoutFullScreen = false; - wnd.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { + await wnd.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { console.info(msgStr + 'Succeeded in setting the window layout to full-screen mode.'); try { let propData = wnd.getWindowProperties() @@ -1790,10 +2077,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_003 - * @tc.name Test setWindowLayoutFullScreenTest3 - * @tc.desc set the property of the window can layout in full screen - */ + * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_003 + * @tc.name Test setWindowLayoutFullScreenTest3 + * @tc.desc set the property of the window can layout in full screen + */ it('setWindowLayoutFullScreenTest3', 0, async function (done) { let caseName = 'setWindowLayoutFullScreenTest3'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1839,10 +2126,10 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_004 - * @tc.name Test setWindowLayoutFullScreenTest4 - * @tc.desc set the property of the window can layout in full screen - */ + * @tc.number SUB_WINDOW_SETWINDOWLAYOUTFULLSCREEN_JSAPI_004 + * @tc.name Test setWindowLayoutFullScreenTest4 + * @tc.desc set the property of the window can layout in full screen + */ it('setWindowLayoutFullScreenTest4', 0, async function (done) { let caseName = 'setWindowLayoutFullScreenTest4'; let msgStr = 'jsunittest ' + caseName + ' '; @@ -1888,94 +2175,108 @@ export default function displayAndWindowRefactorInterfaceTest(context, windowSta ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_001 - * @tc.name Test setWindowModeTest1 - * @tc.desc Test window.setWindowMode API function test. - */ - it('setWindowModeTest1', 0, function (done) { - let windowModeArr = ['FULLSCREEN', 'PRIMARY', 'SECONDARY', 'FLOATING'] + * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_001 + * @tc.name Test setWindowModeTest1 + * @tc.desc Test window.setWindowMode API function test. + */ + it('setWindowModeTest1', 0, async function (done) { + let windowModeArr = ['FULLSCREEN', 'PRIMARY', 'SECONDARY', 'FLOATING','FULLSCREEN'] let caseName = 'setWindowModeTest1'; let msgStr = 'jsunittest ' + caseName + ' '; let sumCount = 0 + let baseWndType = 1; + let windowId = 'setWindowModeTest1'; + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let tempWnd; try { - let tempWnd = windowStage.getMainWindowSync(); + tempWnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + console.info(msgStr + 'fail createWindow. Data: ' + JSON.stringify(err)); + }) expect(!!tempWnd).assertTrue(); - let loopCount = windowModeArr; - console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount)) - getData(0, loopCount.length) - - function getData(i, length) { - let tempType = ohosWindow.WindowMode[loopCount[i]]; - console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); + console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(windowModeArr)) + for(let i=0;i { - sumCount++ - console.info(msgStr + 'Succeeded in setting the window mode. count: ' + sumCount); - console.info(msgStr + 'Succeeded in setting the window mode. loopCount.length: ' + loopCount.length); - - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + console.info(msgStr + 'Succeeded in setting the window mode. current tempType:' + tempType); + console.info(msgStr + 'Succeeded in setting the window mode. current step:' + i); + if(i == windowModeArr.length-1){ + console.info(msgStr + 'finished in setting the window mode. current step:' + i); + done() } - 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); + expect().assertFail(); + done(); }); } catch (exception) { console.error(msgStr + 'try catch Failed to set the window mode. Cause: ' + JSON.stringify(exception)); } ; } + await tempWnd.destroyWindow() } catch (exception) { console.error('try catch Failed to obtain the getMainWindowSync. Cause: ' + JSON.stringify(exception)); } ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_002 - * @tc.name Test setWindowModeTest2 - * @tc.desc Verify the scenario where the normal window mode is set - */ - it('setWindowModeTest2', 0, function (done) { - let windowModeArr = ['FULLSCREEN', 'PRIMARY', 'SECONDARY', 'FLOATING'] + * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_002 + * @tc.name Test setWindowModeTest2 + * @tc.desc Verify the scenario where the normal window mode is set + */ + it('setWindowModeTest2', 0, async function (done) { + let windowModeArr = ['FULLSCREEN', 'PRIMARY', 'SECONDARY', 'FLOATING','FULLSCREEN'] let caseName = 'setWindowModeTest2'; let msgStr = 'jsunittest ' + caseName + ' '; let sumCount = 0 + let baseWndType = 1; + let windowId = 'setWindowModeTest2'; + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let wnd; try { - let wnd = windowStage.getMainWindowSync(); + wnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + console.info(msgStr + 'fail createWindow. Data: ' + JSON.stringify(err)); + }) expect(!!wnd).assertTrue(); - let loopCount = windowModeArr; - console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount)) - getData(0, loopCount.length) - function getData(i, length) { - try { - let tempType = ohosWindow.WindowMode[loopCount[i]]; - console.log(msgStr + 'tempWnd.setWindowMode tempType:' + tempType + ' start i:' + i); - wnd.setWindowMode(tempType, (err, data) => { - if (err && err.code) { - console.log(msgStr + 'currentType: ' + tempType) - console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'tempWnd.setWindowType', done); - } else { - sumCount++ - console.info(msgStr + 'Succeeded in setting the window mode. count: ' + sumCount); - console.info(msgStr + 'Succeeded in setting the window mode. loopCount.length: ' + loopCount.length); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++{ + try { + wnd.setWindowMode(tempType, (err, data) => { + if (err && err.code) { + console.log(msgStr + 'currentType: ' + tempType) + console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (err) { + console.log(msgStr + 'assertFail catch' + JSON.stringify(err)); + } + done(); + reject(false) } - if (sumCount == loopCount.length) done(); - } - }) - } catch (exception) { - console.error(msgStr + 'try catch Failed to set the window mode. Cause: ' + JSON.stringify(exception)); + resolve(true) + console.log(msgStr + 'tempWnd.setWindowMode tempType:' + tempType + ' successed i:' + i); + }) + } catch (exception) { + console.error(msgStr + 'try catch Failed to set the window mode. Cause: ' + JSON.stringify(exception)); + } + }) + } + for(let i=0;i { + console.info(msgStr + 'fail createWindow. Data: ' + JSON.stringify(err)); + }) expect(!!tempWnd).assertTrue(); - let loopCount = windowModeArr; - console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount)) - getData(0, loopCount.length) - - function getData(i, length) { - let tempType = ohosWindow.WindowMode[loopCount[i]]; - console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); - try { - tempWnd.setWindowMode(tempType).then(() => { - sumCount++ - console.info(msgStr + 'Succeeded in setting the window mode. count: ' + sumCount); - console.info(msgStr + 'Succeeded in setting the window mode. loopCount.length: ' + loopCount.length); - }).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(); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); + expect(err.code == 401).assertTrue(); + await tempWnd.destroyWindow() + console.log(msgStr + 'tempWnd.setWindowMode failed ' + 'finished'); + done(); + }); } catch (exception) { console.error('try catch Failed to obtain the getMainWindowSync. Cause: ' + JSON.stringify(exception)); } ; }) /** - * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_004 - * @tc.name Test setWindowModeTest4 - * @tc.desc Verify the scenario where the normal window mode is set - */ - it('setWindowModeTest4', 0, function (done) { - let windowModeArr = ['UNDEFINED'] + * @tc.number SUB_WINDOW_SETWINDOWMODE_JSAPI_004 + * @tc.name Test setWindowModeTest4 + * @tc.desc Verify the scenario where the normal window mode is set + */ + it('setWindowModeTest4', 0, async function (done) { let caseName = 'setWindowModeTest4'; let msgStr = 'jsunittest ' + caseName + ' '; - let sumCount = 0 + let baseWndType = 1; + let windowId = 'setWindowModeTest4'; + let windowConfig = { + name: windowId, windowType: baseWndType, ctx: context + }; + let wnd; try { - let wnd = windowStage.getMainWindowSync(); + wnd = await ohosWindow.createWindow(windowConfig).catch((err) => { + console.info(msgStr + 'fail createWindow. Data: ' + JSON.stringify(err)); + }) expect(!!wnd).assertTrue(); - let loopCount = windowModeArr; - console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount)) - getData(0, loopCount.length) - - function getData(i, length) { - let tempType = ohosWindow.WindowMode[loopCount[i]]; - console.log(msgStr + 'tempWnd.setWindowMode ' + tempType + ' start'); - try { - wnd.setWindowMode(tempType, (err, data) => { - if (err && err.code) { - console.log(msgStr + 'currentType: ' + tempType) - console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); - try { - expect(err.code == 401).assertTrue(); - } catch (error) { - console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) - } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + if (err && err.code) { + console.log(msgStr + 'currentType: ' + tempType) + console.error(msgStr + 'Failed to set the window mode. Cause: ' + JSON.stringify(err)); + try { + expect(err.code == 401).assertTrue(); + } catch (error) { + console.info(`ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) } - }) - } catch (exception) { - console.error(msgStr + 'try catch Failed to set the window mode. Cause: ' + JSON.stringify(exception)); - } - ; - } + await wnd.destroyWindow() + done(); + } else { + console.info(msgStr + 'Succeeded in setting the window mode'); + } + }) + } 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)); - } - ; + }; }) /** - * @tc.number SUB_WMS_ENUM_WINDOWSTAGEEVENTTYPERENAME_JSAPI_001 - * @tc.name Test enumWindowStageEventTypeReName_Test_001. - * @tc.desc To test the enum value of WindowStageEventType. + * @tc.number SUB_WMS_ENUM_WINDOWSTAGEEVENTTYPERENAME_JSAPI_001 + * @tc.name Test enumWindowStageEventTypeReName_Test_001. + * @tc.desc To test the enum value of WindowStageEventType. */ it('enumWindowStageEventTypeReName_Test_001', 0, async function (done) { console.info('test the enum value of WindowStageEventType begin'); 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 18858e0d66a6b254b79d41e1dc524a5dd80ecf19..86c5702a8285c768a45bbb96426c990e8ff1ecb8 100644 --- a/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets @@ -88,6 +88,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log('jsunittest systemBarTintChange end off'); } else if (newWindowObj) { newWindowObj.off(listenerData.typeStr); + console.log('jsunittest newWindowObj listenerData.typeStr:'+ JSON.stringify(listenerData.typeStr) ); } await sleep(3000); } @@ -99,8 +100,12 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) function expectedError(error, caseName, apiName, done, code) { let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; console.log(msgStr + JSON.stringify(error)); - expect(TRUE_FLAG).assertTrue(); - expect(error.code === code).assertTrue(); + try { + expect(TRUE_FLAG).assertTrue(); + expect(error.code === code).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } done(); } @@ -109,7 +114,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + JSON.stringify(error)); try { expect(TRUE_FLAG).assertFail(); - ; } catch (error) { console.info(`ohosWindow.on ${JSON.stringify(error)}`) } @@ -128,49 +132,80 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) * @tc.name Test setSystemBarEnableTest6 * @tc.desc Test ohosWindow.setSystemBarEnable API function test1. */ - it('setSystemBarEnableTest6', 0, function (done) { + it('setSystemBarEnableTest6', 0, async function (done) { let caseName = 'setSystemBarEnableTest6'; let msgStr = 'jsunittest ' + caseName + ' '; let [flagStatus, flagNav] = [false, false]; console.log(msgStr + 'begin'); listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', systembartintstate => { - console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); - if (flagStatus || flagNav) { - try { - expect(!!systembartintstate).assertTrue(); - expect(!!systembartintstate.regionTint).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on ${JSON.stringify(error)}`) - } - console.log(msgStr + 'flagStatus || flagNav' + msgStr + 'ohosWindow.on systemBarTintChange regionTint:' + JSON.stringify(systembartintstate.regionTint)); - done(); - } - }) + + function ohosWindowOn() { +// return new Promise(function (resolve, reject) { + ohosWindow.on('systemBarTintChange', systembartintstate => { + console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + console.log(msgStr + 'ohosWindow.on flagNav : ' + JSON.stringify(flagNav)); + console.log(msgStr + 'ohosWindow.on flagStatus : ' + JSON.stringify(flagStatus)); + console.log(msgStr + 'ohosWindow.on flagStatus && flagNav : ' + (flagStatus && flagNav)); + if (flagStatus && flagNav) { + try { + expect(!!systembartintstate).assertTrue(); + expect(!!systembartintstate.regionTint).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + console.log(msgStr + 'flagStatus || flagNav' + msgStr + 'ohosWindow.on systemBarTintChange regionTint:' + JSON.stringify(systembartintstate.regionTint)); + done(); + } +// resolve(systembartintstate); + }) +// }) + } + let mainWnd = null; console.log(msgStr + 'mainWnd = null'); console.log(msgStr + 'windowStage = ' + JSON.stringify(windowStage)); - windowStage.getMainWindow((err, data) => { - console.log(msgStr + 'getMainWindow data2' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(data, caseName, 'windowStage.getMainWindow', done); - } - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on ${JSON.stringify(error)}`) - } - mainWnd = data; - console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); - mainWnd.show((err, data) => { - console.log(msgStr + 'mainWnd.show err' + JSON.stringify(err)); - console.log(msgStr + 'mainWnd.show data' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.show', done); - } - expect(!data).assertTrue(); - console.log(msgStr + 'mainWnd.show success'); + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + console.log(msgStr + 'getMainWindow data2' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + mainWnd = data; + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + resolve(data); + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + mainWnd.show((err, data) => { + console.log(msgStr + 'mainWnd.show err' + JSON.stringify(err)); + console.log(msgStr + 'mainWnd.show data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + try{ + expect(!data).assertTrue(); + }catch(err){ + console.info(`mainWnd.show err: ${JSON.stringify(err)}`) + } + console.log(msgStr + 'mainWnd.show success'); + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { mainWnd.setFullScreen(true, (err, data) => { console.log(msgStr + 'mainWnd.setFullScreen data:' + JSON.stringify(data)); if (err && err.code) { @@ -183,84 +218,150 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } console.log(msgStr + 'mainWnd.setFullScreen success'); flagNav = true; - mainWnd.setSystemBarEnable(['navigation'], (err, data) => { - console.log(msgStr + 'mainWnd.setSystemBarEnable navigation JSON.stringify(data)==' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navigation]', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on ${JSON.stringify(error)}`) - } - console.log(msgStr + 'mainWnd.setSystemBarEnable success flagNav==' + flagNav); - }) - flagStatus = true; - mainWnd.setSystemBarEnable(['status'], (err, data) => { - console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)===' + JSON.stringify(data)); - if (err && err.code) { - console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(err)===' + JSON.stringify(err)); - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on ${JSON.stringify(error)}`) - } - }) + resolve(data) }) }) - }) - console.log(msgStr + 'finished!!'); + } + + function setSystemBarEnableNavigation() { + console.log(msgStr + 'flagStatus==' + flagStatus); + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable(['navigation'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable navigation JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navigation]', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setSystemBarEnable success flagNav==' + flagNav); + resolve(data) + }) + flagStatus = true; + }) + } + + function setSystemBarEnableStatus() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable(['status'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)===' + JSON.stringify(data)); + if (err && err.code) { + console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(err)===' + JSON.stringify(err)); + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + resolve(data) +// done(); + }) + }) + } + await getMainWindow() + await show() + await setFullScreen() + ohosWindowOn() + await setSystemBarEnableNavigation() + await setSystemBarEnableStatus() + +// await getMainWindow() +// .then(function (params) { +// mainWnd = params; +// console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) +// return show() +// }) +// .then(function (params) { +// console.log(msgStr + 'show then: ' + JSON.stringify(params)) +// return setFullScreen() +// }) +// .then(function (params) { +// console.log(msgStr + 'setFullScreen then: ' + JSON.stringify(params)) +// return ohosWindowOn() +// }) +// .then(function (params) { +// console.log(msgStr + 'ohosWindowOn then: ' + JSON.stringify(params)) +// return setSystemBarEnableNavigation() +// }) +// .then(function (params) { +// console.log(msgStr + 'setSystemBarEnableNavigation then: ' + JSON.stringify(params)) +// return setSystemBarEnableStatus() +// }) }); /** * @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) { + it('setSystemBarEnableTest7', 0, async function (done) { let caseName = 'setSystemBarEnableTest7'; let msgStr = 'jsunittest ' + caseName + ' '; let [flagStatus, flagNav] = [false, false]; console.log(msgStr + 'begin'); listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', systembartintstate => { - console.log(msgStr + 'ohosWindow.on systembartintstate :' + JSON.stringify(systembartintstate)); - console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); - if (flagStatus || flagNav) { - console.log(msgStr + 'ohosWindow.on flagStatus || flagNav:'); - try { - expect(!!systembartintstate).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) - } - done(); - } - }) + + function ohosWindowOn() { + return new Promise(function (resolve, reject) { + ohosWindow.on('systemBarTintChange', systembartintstate => { + console.log(msgStr + 'ohosWindow.on systembartintstate :' + JSON.stringify(systembartintstate)); + console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + if (flagStatus || flagNav) { + console.log(msgStr + 'ohosWindow.on flagStatus || flagNav:'); + try { + expect(!!systembartintstate).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) + } + done(); + } + }) + }) + } + let mainWnd = null; console.log(msgStr + 'mainWnd = null') - windowStage.getMainWindow((err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'windowStage.getMainWindow', done); - } - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`windowStage.getMainWindow catch err: ${JSON.stringify(error)}`) - } - mainWnd = data; - console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); - mainWnd.show((err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.show', done); - } - console.log(msgStr + 'mainWnd.show success'); - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`) - } + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + console.log(msgStr + 'getMainWindow data2' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + resolve(data); + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + mainWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + console.log(msgStr + 'mainWnd.show success'); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { mainWnd.setFullScreen(true, (err, data) => { console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); if (err && err.code) { @@ -271,66 +372,121 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } catch (error) { console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`) } - mainWnd.setSystemBarEnable(['status'], (err, data) => { - console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)==' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); - } - flagStatus = true; - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) - } - mainWnd.setSystemBarEnable(['navigation'], (err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navitgation]', done); - } - flagNav = true; - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) - } - }) - }) + resolve(data) }) }) - }) + } + + function setSystemBarEnableStatus() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable(['status'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); + } + flagStatus = true; + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + function setSystemBarEnableNavigation() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable(['navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navitgation]', done); + } + flagNav = true; + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + await getMainWindow() + .then(function (params) { + mainWnd = params; + console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) + return show() + }) + .then(function (params) { + console.log(msgStr + 'show then: ' + JSON.stringify(params)) + return setFullScreen() + }) + .then(function (params) { + console.log(msgStr + 'setSystemBarEnableNavigation then: ' + JSON.stringify(params)) + return setSystemBarEnableStatus() + }) + .then(function (params) { + console.log(msgStr + 'setSystemBarEnableStatus then: ' + JSON.stringify(params)) + return setSystemBarEnableNavigation() + }) + .then(function (params) { + console.log(msgStr + 'ohosWindowOn then: ' + JSON.stringify(params)) + return ohosWindowOn() + }) }); /** * @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) { + it('setSystemBarEnableTest8', 0, async function (done) { let caseName = 'setSystemBarEnableTest8'; let msgStr = 'jsunittest ' + caseName + ' '; let [flagStatus, flagNav] = [false, false]; console.log(msgStr + 'begin'); let mainWnd = null; console.log(msgStr + 'mainWnd = null'); - windowStage.getMainWindow((err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'windowStage.getMainWindow', done); - } - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.getMainWindow catch err: ${JSON.stringify(error)}`) - } - mainWnd = data; - console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); - mainWnd.show((err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.show', done); - } - console.log(msgStr + 'mainWnd.show success'); - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`) - } + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.getMainWindow catch err: ${JSON.stringify(error)}`) + } + mainWnd = data; + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + resolve(data) + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + mainWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + console.log(msgStr + 'mainWnd.show success'); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { mainWnd.setFullScreen(true, (err, data) => { console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); if (err && err.code) { @@ -341,173 +497,290 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } catch (error) { console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`) } - mainWnd.setSystemBarEnable([], (err, data) => { - console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) - } - listenerData.on = true; - listenerData.typeStr = 'systemBarTintChange'; - setTimeout(() => { - ohosWindow.on('systemBarTintChange', systembartintstate => { - console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate)); - console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); - setTimeout(() => { - if (flagStatus || flagNav) { - let enable = systembartintstate.regionTint[0].isEnable - let numType = systembartintstate.regionTint[0].type - console.log(msgStr + 'ohosWindow.on isEnable : ' + JSON.stringify(enable)); - console.log(msgStr + 'ohosWindow.on numType : ' + JSON.stringify(numType)); - try { - expect(numType === ohosWindow.WindowType.TYPE_NAVIGATION_BAR || enable).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) - } - } - done(); - }, 3000) - }) - }, 2300) - mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done); - } - flagStatus = true; - flagNav = true; - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) - } - }) - }) + resolve(data) }) }) - }) - }); - /** - * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_009 - * @tc.name Test setSystemBarEnableTest9 - * @tc.desc Verify that the scene hides both the status bar and the navigation bar. - */ - it('setSystemBarEnableTest9', 0, function (done) { - let caseName = 'setSystemBarEnableTest9'; - let msgStr = 'jsunittest ' + caseName + ' '; - let [flagStatus, flagNav] = [false, false]; - console.log(msgStr + 'begin'); - let mainWnd = null; - console.log(msgStr + 'mainWnd = null'); - windowStage.getMainWindow((err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'windowStage.getMainWindow', done); - } - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`windowStage.getMainWindow catch err: ${JSON.stringify(error)}`) - } - mainWnd = data; - console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); - mainWnd.show((err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.show', done); - } - console.log(msgStr + 'mainWnd.show success'); - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`) - } - mainWnd.setFullScreen(true, (err, data) => { - console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); + } + + function setSystemBarEnable() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable([], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(data)); if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.setFullScreen', done); + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); } try { expect(!data).assertTrue(); } catch (error) { - console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`) + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) } - mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { - console.log(msgStr + 'mainWnd.setSystemBarEnable status,navigation JSON.stringify(data)==' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done); - } - flagStatus = true; - flagNav = true; + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + resolve(data) + }) + }) + } + + function ohosWindowOn() { + return new Promise(function (resolve, reject) { + ohosWindow.on('systemBarTintChange', systembartintstate => { + console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate)); + console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + if (flagStatus || flagNav) { + let enable = systembartintstate.regionTint[0].isEnable + let numType = systembartintstate.regionTint[0].type + console.log(msgStr + 'ohosWindow.on isEnable : ' + JSON.stringify(enable)); + console.log(msgStr + 'ohosWindow.on numType : ' + JSON.stringify(numType)); try { - expect(!data).assertTrue(); + expect(numType === ohosWindow.WindowType.TYPE_NAVIGATION_BAR || enable).assertTrue(); } catch (error) { - console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) } - listenerData.on = true; - listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systembartintstate) => { - console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate)); - console.log(msgStr + 'ohosWindow.on systemBarTintChange systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); - if (flagStatus || flagNav) { - try { - expect(!!systembartintstate).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) - } - done(); - } - }) - mainWnd.setSystemBarEnable([], (err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) - } - }) - }) + } + resolve(systembartintstate) + done(); }) }) - }) + } + + function setSystemBarEnableT() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done); + } + flagStatus = true; + flagNav = true; + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + await getMainWindow() + .then(function (params) { + mainWnd = params; + console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) + return show() + }) + .then(function (params) { + console.log(msgStr + 'show then: ' + JSON.stringify(params)) + return setFullScreen() + }) + .then(function (params) { + console.log(msgStr + 'setFullScreen then: ' + JSON.stringify(params)) + return setSystemBarEnable() + }) + .then(function (params) { + console.log(msgStr + 'setSystemBarEnable then: ' + JSON.stringify(params)) + return ohosWindowOn() + }) + .then(function (params) { + console.log(msgStr + 'ohosWindowOn then: ' + JSON.stringify(params)) + return setSystemBarEnableT() + }) + + }); + /** + * @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, async function (done) { + let caseName = 'setSystemBarEnableTest9'; + let msgStr = 'jsunittest ' + caseName + ' '; + let [flagStatus, flagNav] = [false, false]; + console.log(msgStr + 'begin'); + let mainWnd = null; + console.log(msgStr + 'mainWnd = null'); + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch err: ${JSON.stringify(error)}`) + } + mainWnd = data; + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + resolve(data) + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + mainWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + console.log(msgStr + 'mainWnd.show success'); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { + mainWnd.setFullScreen(true, (err, data) => { + console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setFullScreen', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + function setSystemBarEnableT() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable status,navigation JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done); + } + flagStatus = true; + flagNav = true; + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + resolve(data) + }) + }) + } + + function ohosWindowOn() { + return new Promise(function (resolve, reject) { + ohosWindow.on('systemBarTintChange', (systembartintstate) => { + console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate)); + console.log(msgStr + 'ohosWindow.on systemBarTintChange systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + if (flagStatus || flagNav) { + try { + expect(!!systembartintstate).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`) + } + resolve(systembartintstate) + done(); + } + }) + }) + } + + function setSystemBarEnable() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable([], (err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + await getMainWindow() + .then(function (params) { + mainWnd = params; + console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) + return show() + }) + .then(function (params) { + console.log(msgStr + 'show then: ' + JSON.stringify(params)) + return setFullScreen() + }) + .then(function (params) { + console.log(msgStr + 'setFullScreen then: ' + JSON.stringify(params)) + return setSystemBarEnableT() + }) + .then(function (params) { + console.log(msgStr + 'setSystemBarEnable then: ' + JSON.stringify(params)) + return ohosWindowOn() + }) + .then(function (params) { + console.log(msgStr + 'ohosWindowOn then: ' + JSON.stringify(params)) + return setSystemBarEnable() + }) + + }); /** * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_010 * @tc.name Test setSystemBarEnableTest10 * @tc.desc Verify the scene where illegal values are entered when the navigation bar and status bar are displayed or hidden */ - it('setSystemBarEnableTest10', 0, function (done) { + it('setSystemBarEnableTest10', 0, async function (done) { let caseName = 'setSystemBarEnableTest10'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); let mainWnd = null; console.log(msgStr + 'mainWnd = null'); - windowStage.getMainWindow((err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'windowStage.getMainWindow', done); - } - try { - console.log(msgStr + 'windowStage.getMainWindow JSON.stringify(!!data)===' + JSON.stringify(!!data)); - expect(!!data).assertTrue(); - } catch (error) { - console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) - } - mainWnd = data; - console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); - mainWnd.show((err, data) => { - if (err && err.code) { - unexpectedError(data, caseName, 'mainWnd.show', done); - } - console.log(msgStr + 'mainWnd.show success'); - try { - console.log(msgStr + 'mainWnd.show JSON.stringify(!data)===' + JSON.stringify(!data)); - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`) - } + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + console.log(msgStr + 'windowStage.getMainWindow JSON.stringify(!!data)===' + JSON.stringify(!!data)); + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + mainWnd = data; + console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd)); + resolve(data) + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + mainWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.show', done); + } + console.log(msgStr + 'mainWnd.show success'); + try { + console.log(msgStr + 'mainWnd.show JSON.stringify(!data)===' + JSON.stringify(!data)); + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { mainWnd.setFullScreen(true, (err, data) => { console.log(msgStr + 'mainWnd.setFullScreen: ' + JSON.stringify(data)); if (err && err.code) { @@ -519,108 +792,177 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } 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); - } + resolve(data) + }) + }) + } + + function setSystemBarEnable() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable([], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); + } + try { + console.log(msgStr + 'mainWnd.setSystemBarEnable JSON.stringify(!data)===' + JSON.stringify(!data)); + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + function setSystemBarEnableError() { + return new Promise(function (resolve, reject) { + mainWnd.setSystemBarEnable([null, '123'], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(data)==' + JSON.stringify(data)); + console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(err)==' + JSON.stringify(err)); + if (err && err.code) { try { - console.log(msgStr + 'mainWnd.setSystemBarEnable JSON.stringify(!data)===' + JSON.stringify(!data)); - expect(!data).assertTrue(); + 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)}`) } - mainWnd.setSystemBarEnable([null, '123'], (err, data) => { - console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(data)==' + JSON.stringify(data)); - console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(err)==' + JSON.stringify(err)); - if (err && err.code) { - try { - console.log(msgStr + 'mainWnd.setSystemBarEnable JSON.stringify(err.code)===' + JSON.stringify(err.code)); - expect(err.code === 1003).assertTrue(); - } catch (error) { - console.info(`mainWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [null,123]', done); - } - }) - }) + done(); + } else { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [null,123]', done); + } + resolve(data) }) }) - }) + } + + await getMainWindow() + .then(function (params) { + mainWnd = params; + console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) + return show() + }).then(function (params) { + console.log(msgStr + 'show then: ' + JSON.stringify(params)) + return setFullScreen() + }).then(function (params) { + console.log(msgStr + 'setFullScreen then: ' + JSON.stringify(params)) + return setSystemBarEnable() + }).then(function (params) { + console.log(msgStr + 'setSystemBarEnable then: ' + JSON.stringify(params)) + return setSystemBarEnableError() + }) }); /** * @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_004 * @tc.name Test setSystemBarPropertiesTest1 * @tc.desc TVerify the scene where the colors of the status bar and navigation bar are set in RGB */ - it('setSystemBarPropertiesTest4', 0, done => { + it('setSystemBarPropertiesTest4', 0, async done => { let caseName = 'setSystemBarPropertiesTest4'; let msgStr = 'jsunittest ' + caseName + ' '; let cloneColorArr = JSON.parse(JSON.stringify(commonRGBColorArr)); let compareCount = 0; - let listenerFlag = listenerStatus.ready; + let listenerFlag = false; console.log(msgStr + 'begin'); listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systemBarData) => { - console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { - try { - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) - } - let arrLength = systemBarData.regionTint.length; - getData(0, arrLength) - function getData(i, length) { - let tempData = systemBarData.regionTint[i]; - if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { - console.log(msgStr + 'systemBarTintChange compare start!'); - compareCount++; - let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor); - let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); + function ohosWindowOn() { + return new Promise(function (resolve, reject) { + ohosWindow.on('systemBarTintChange', (systemBarData) => { + console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); + if (listenerFlag) { try { - expect(backgroundIndex === -1).assertTrue(); - expect(contentColorIndex === -1).assertTrue(); + expect(!!systemBarData).assertTrue(); + expect(!!systemBarData.regionTint).assertTrue(); } catch (error) { console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { - if (err && err.code) { - unexpectedError(err, caseName, 'windowStage.getMainWindow', done); - } - let tempWnd = data - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); - tempWnd.show((err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.show', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.show success'); + resolve(systemBarData) + console.log(msgStr + 'tempWnd.on systemBarTintChange finished'); + }) + }) + } + + let tempWnd = null + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + } + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); + resolve(data) + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + tempWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.show success'); + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { tempWnd.setFullScreen(true, (err, data) => { if (err && err.code) { unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); @@ -631,64 +973,120 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) } console.log(msgStr + 'tempWnd.setFullScreen(true) success'); - tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); - listenerFlag = listenerStatus.pending; - let loopCount = commonRGBColorArr.length - getData(0, loopCount) - - function getData(i, length) { - let tempColor = commonRGBColorArr[i]; - let systemBarProperties = { - statusBarColor: tempColor, - isStatusBarLightIcon: true, - statusBarContentColor: tempColor, - navigationBarColor: tempColor, - isNavigationBarLightIcon: false, - navigationBarContentColor: tempColor, - }; - tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { - console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); - console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.setSystemBarProperties' + tempColor + ' ', done); - } - console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { - console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); - listenerFlag = listenerStatus.finished; - done(); - }, 10000) - }) + resolve(data) }) }) - }) - }) - /** - * @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_005 - * @tc.name Test setSystemBarPropertiesTest5 - * @tc.desc Verify the scene where the status bar and navigation bar colors are set in hexadecimal form - */ - it('setSystemBarPropertiesTest5', 0, done => { - let caseName = 'setSystemBarPropertiesTest5'; - let msgStr = 'jsunittest ' + caseName + ' '; + } + + function setSystemBarEnableNavigationT() { + return new Promise(function (resolve, reject) { + tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); + listenerFlag = true; + + resolve(data) + + setTimeout(() => { + console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); + listenerFlag = false; + done(); + }, 10000) + }) + }) + } + + function setSystemBarProperties() { + return new Promise(function (resolve, reject) { + let loopCount = commonRGBColorArr.length + for (let i = 0; i < loopCount; i++) { + let tempColor = commonRGBColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: false, + navigationBarContentColor: tempColor, + }; + tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { + console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarProperties' + tempColor + ' ', done); + } + console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); + resolve(data) + }) + } + // getData(0, loopCount) + // + // function getData(i, length) { + // let tempColor = commonRGBColorArr[i]; + // let systemBarProperties = { + // statusBarColor: tempColor, + // isStatusBarLightIcon: true, + // statusBarContentColor: tempColor, + // navigationBarColor: tempColor, + // isNavigationBarLightIcon: false, + // navigationBarContentColor: tempColor, + // }; + // tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { + // console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + // console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); + // if (err && err.code) { + // unexpectedError(err, caseName, 'tempWnd.setSystemBarProperties' + tempColor + ' ', done); + // } + // console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + let caseName = 'setSystemBarPropertiesTest5'; + let msgStr = 'jsunittest ' + caseName + ' '; let cloneColorArr = { SBC: JSON.parse(JSON.stringify(commonNUMBERColorArr)), SCC: JSON.parse(JSON.stringify(commonNUMBERColorArr)), @@ -697,110 +1095,135 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }; let compareCount = 0; let endNum = 0; - let listenerFlag = listenerStatus.ready; + let listenerFlag = false; console.log(msgStr + 'begin'); listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systemBarData) => { - console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { - try { - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) - } - let arrLength = systemBarData.regionTint.length; - for (let i = 0; i < arrLength; i++) { - console.log(msgStr + 'for arrLenght compareCount: ' + compareCount + ' ,i:'+i+' ,arrLength:'+arrLength); - let tempData = systemBarData.regionTint[i]; - if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR) { - console.log(msgStr + 'systemBarTintChange compare start! arrLength= ' + arrLength); - compareCount++; - let backgroundIndex = cloneColorArr.SBC.indexOf(tempData.backgroundColor); - let contentColorIndex = cloneColorArr.SCC.indexOf(tempData.contentColor); - if (backgroundIndex >= 0) { - cloneColorArr.SBC.splice(backgroundIndex, 1); - } else { - console.log(msgStr + 'SBC tempData.backgroundColor:' + JSON.stringify(tempData.backgroundColor)); - } - if (contentColorIndex >= 0) { - cloneColorArr.SCC.splice(contentColorIndex, 1); - } else { - console.log(msgStr + 'SCC tempData.contentColor:' + JSON.stringify(tempData.contentColor)); - } - let ca = cloneColorArr; - let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length - if (compareCount === 18 && !flag) { - console.log(msgStr + 'if compareCount: ' + compareCount + ' ,true flag:' + flag); - try { - expect(true).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) - } - } else { - console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag); - } - console.log(msgStr + 'compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.SCC.length) + ' ,cloneColorArr.SBC:' + JSON.stringify(cloneColorArr.SBC)); - console.log(msgStr + 'compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.SCC.length) + ' ,cloneColorArr.SCC' + JSON.stringify(cloneColorArr.SCC)); - done(); - } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { - console.log(msgStr + 'systemBarTintChange compare start!'); - compareCount++; - let backgroundIndex = cloneColorArr.NBC.indexOf(tempData.backgroundColor); - let contentColorIndex = cloneColorArr.NCC.indexOf(tempData.contentColor); - if (backgroundIndex >= 0) { - cloneColorArr.NBC.splice(backgroundIndex, 1); - } else { - console.log(msgStr + 'NBC tempData.backgroundColor:' + JSON.stringify(tempData.backgroundColor)); - } - if (contentColorIndex >= 0) { - cloneColorArr.NCC.splice(contentColorIndex, 1); - } else { - console.log(msgStr + 'NCC tempData.contentColor:' + JSON.stringify(tempData.contentColor)); + + function ohosWindowOn() { + return new Promise(function (resolve, reject) { + ohosWindow.on('systemBarTintChange', (systemBarData) => { + console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); + if (listenerFlag) { + try { + expect(!!systemBarData).assertTrue(); + expect(!!systemBarData.regionTint).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) } - let ca = cloneColorArr; - let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length - if (compareCount === 18 && !flag) { - console.log(msgStr + 'else compareCount: ' + compareCount + ' ,true flag:' + flag); - try { - expect(true).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + let arrLength = systemBarData.regionTint.length; + for (let i = 0; i < arrLength; i++) { + console.log(msgStr + 'for arrLenght compareCount: ' + compareCount + ' ,i:' + i + ' ,arrLength:' + arrLength); + let tempData = systemBarData.regionTint[i]; + if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR) { + console.log(msgStr + 'systemBarTintChange compare start! arrLength= ' + arrLength); + compareCount++; + let backgroundIndex = cloneColorArr.SBC.indexOf(tempData.backgroundColor); + let contentColorIndex = cloneColorArr.SCC.indexOf(tempData.contentColor); + if (backgroundIndex >= 0) { + cloneColorArr.SBC.splice(backgroundIndex, 1); + } else { + console.log(msgStr + 'SBC tempData.backgroundColor:' + JSON.stringify(tempData.backgroundColor)); + } + if (contentColorIndex >= 0) { + cloneColorArr.SCC.splice(contentColorIndex, 1); + } else { + console.log(msgStr + 'SCC tempData.contentColor:' + JSON.stringify(tempData.contentColor)); + } + let ca = cloneColorArr; + let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length + if (compareCount === 18 && !flag) { + console.log(msgStr + 'if compareCount: ' + compareCount + ' ,true flag:' + flag); + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + } else { + console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag); + } + console.log(msgStr + 'compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.SCC.length) + ' ,cloneColorArr.SBC:' + JSON.stringify(cloneColorArr.SBC)); + console.log(msgStr + 'compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.SCC.length) + ' ,cloneColorArr.SCC' + JSON.stringify(cloneColorArr.SCC)); + done(); + } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { + console.log(msgStr + 'systemBarTintChange compare start!'); + compareCount++; + let backgroundIndex = cloneColorArr.NBC.indexOf(tempData.backgroundColor); + let contentColorIndex = cloneColorArr.NCC.indexOf(tempData.contentColor); + if (backgroundIndex >= 0) { + cloneColorArr.NBC.splice(backgroundIndex, 1); + } else { + console.log(msgStr + 'NBC tempData.backgroundColor:' + JSON.stringify(tempData.backgroundColor)); + } + if (contentColorIndex >= 0) { + cloneColorArr.NCC.splice(contentColorIndex, 1); + } else { + console.log(msgStr + 'NCC tempData.contentColor:' + JSON.stringify(tempData.contentColor)); + } + let ca = cloneColorArr; + let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length + if (compareCount === 18 && !flag) { + console.log(msgStr + 'else compareCount: ' + compareCount + ' ,true flag:' + flag); + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) + } + } else { + console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag); + } + console.log(msgStr + 'compareCount: ' + endNum + ' ,compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.NBC.length) + ' ,cloneColorArr.SBC:' + JSON.stringify(cloneColorArr.NBC)); + console.log(msgStr + 'compareCount: ' + endNum + ' ,compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.NCC.length) + ' ,cloneColorArr.SCC' + JSON.stringify(cloneColorArr.NCC)); + endNum = compareCount + done(); } - } else { - console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag); } - console.log(msgStr + 'compareCount: ' + endNum + ' ,compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.NBC.length) + ' ,cloneColorArr.SBC:' + JSON.stringify(cloneColorArr.NBC)); - console.log(msgStr + 'compareCount: ' + endNum + ' ,compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.NCC.length) + ' ,cloneColorArr.SCC' + JSON.stringify(cloneColorArr.NCC)); - endNum = compareCount - done(); } - } - } - }) - console.log(msgStr + 'tempWnd.on systemBarTintChange finished'); - windowStage.getMainWindow((err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'windowStage.getMainWindow', done); - } - let tempWnd = data - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); - tempWnd.show((err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.show', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.show success'); + resolve(systemBarData) + console.log(msgStr + 'tempWnd.on systemBarTintChange finished'); + }) + }) + } + + let tempWnd = null + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + } + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); + resolve(data) + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + tempWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.show success'); + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { tempWnd.setFullScreen(true, (err, data) => { if (err && err.code) { unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); @@ -811,125 +1234,224 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) } console.log(msgStr + 'tempWnd.setFullScreen(true) success'); - tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + resolve(data) + }) + }) + } + + function setSystemBarEnableNavigationT() { + return new Promise(function (resolve, reject) { + tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBatEnable catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); + listenerFlag = true; + resolve(data) + }) + }) + } + + function setSystemBarProperties() { + return new Promise(function (resolve, reject) { + let loopCount = commonNUMBERColorArr.length + for (let i = 0; i < loopCount; i++) { + console.log(msgStr + 'tempWnd.setSystemBarEnable i:' + i); + let tempColor = commonNUMBERColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: true, + navigationBarContentColor: tempColor, + }; + tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { + console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.setSystemBatEnable catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); - listenerFlag = listenerStatus.pending; - let loopCount = commonNUMBERColorArr.length - getData(0, loopCount) - - function getData(i, length) { - console.log(msgStr+'tempWnd.setSystemBarEnable i:'+i); - let tempColor = commonNUMBERColorArr[i]; - let systemBarProperties = { - statusBarColor: tempColor, - isStatusBarLightIcon: true, - statusBarContentColor: tempColor, - navigationBarColor: tempColor, - isNavigationBarLightIcon: true, - navigationBarContentColor: tempColor, - }; - tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { - console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); - console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); - if (err && err.code) { - try { - expect(TRUE_FLAG).assertFail(); - } catch (error) { - console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) - } - } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + // console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + // console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); + // if (err && err.code) { + // try { + // expect(TRUE_FLAG).assertFail(); + // } catch (error) { + // console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) + // } + // } + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + it('setSystemBarPropertiesTest6', 0, async done => { let caseName = 'setSystemBarPropertiesTest6'; let msgStr = 'jsunittest ' + caseName + ' '; let cloneColorArr = JSON.parse(JSON.stringify(commonKEYColorArr)); let compareCount = 0; - let listenerFlag = listenerStatus.ready; + let listenerFlag = false; console.log(msgStr + 'begin'); listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systemBarData) => { - console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { - try { - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); - } catch (error) { - console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) - } - let arrLength = systemBarData.regionTint.length; - getData(0, arrLength) - function getData(i, length) { - let tempData = systemBarData.regionTint[i]; - if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { - console.log(msgStr + 'systemBarTintChange compare start!'); - compareCount++; - let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor); - let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); + function ohosWindowOn() { + return new Promise(function (resolve, reject) { + ohosWindow.on('systemBarTintChange', (systemBarData) => { + console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); + if (listenerFlag) { try { - expect(backgroundIndex === -1).assertTrue(); - expect(contentColorIndex === -1).assertTrue(); + expect(!!systemBarData).assertTrue(); + expect(!!systemBarData.regionTint).assertTrue(); } catch (error) { console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { - if (err && err.code) { - unexpectedError(err, caseName, 'windowStage.getMainWindow', done); - } - let tempWnd = data - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`winsowStage.getMainWindow catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); - tempWnd.show((err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.show', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.show success'); + resolve(systemBarData) + console.log(msgStr + 'tempWnd.on systemBarTintChange finished'); + }) + }) + } + + let tempWnd = null + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + } + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`winsowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); + resolve(data) + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + tempWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.show success'); + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { tempWnd.setFullScreen(true, (err, data) => { if (err && err.code) { unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); @@ -940,73 +1462,124 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) } console.log(msgStr + 'tempWnd.setFullScreen(true) success'); - tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + resolve(data) + }) + }) + } + + function setSystemBarEnableNavigationT() { + return new Promise(function (resolve, reject) { + tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); + listenerFlag = true; + resolve(data) + }) + }) + } + + function setSystemBarProperties() { + return new Promise(function (resolve, reject) { + let loopCount = commonRGBColorArr.length + for (let i = 0; i < loopCount; i++) { + let tempColor = commonKEYColorArr[i]; + let systemBarProperties = { + statusBarColor: tempColor, + isStatusBarLightIcon: true, + statusBarContentColor: tempColor, + navigationBarColor: tempColor, + isNavigationBarLightIcon: false, + navigationBarContentColor: tempColor, + }; + tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { + console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); - listenerFlag = listenerStatus.pending; - let loopCount = commonRGBColorArr.length - getData(0, loopCount) - - function getData(i, length) { - let tempColor = commonKEYColorArr[i]; - let systemBarProperties = { - statusBarColor: tempColor, - isStatusBarLightIcon: true, - statusBarContentColor: tempColor, - navigationBarColor: tempColor, - isNavigationBarLightIcon: false, - navigationBarContentColor: tempColor, - }; - tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { - console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); - console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); - if (err && err.code) { - try { - expect(TRUE_FLAG).assertFail(); - } catch (error) { - console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) - } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { - console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); - listenerFlag = listenerStatus.finished; + try { + expect(TRUE_FLAG).assertFail(); + } catch (error) { + console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) + } + resolve(data) done(); - }, 10000) + } }) - }) + } + // getData(0, loopCount) + // + // function getData(i, length) { + // let tempColor = commonKEYColorArr[i]; + // let systemBarProperties = { + // statusBarColor: tempColor, + // isStatusBarLightIcon: true, + // statusBarContentColor: tempColor, + // navigationBarColor: tempColor, + // isNavigationBarLightIcon: false, + // navigationBarContentColor: tempColor, + // }; + // tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { + // console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); + // console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); + // if (err && err.code) { + // try { + // expect(TRUE_FLAG).assertFail(); + // } catch (error) { + // console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`) + // } + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); + listenerFlag = false; + done(); + }, 10000) + }) + } + + await getMainWindow() + .then(function (params) { + console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) + return show() + }).then(function (params) { + console.log(msgStr + 'show then: ' + JSON.stringify(params)) + return setFullScreen() + }).then(function (params) { + console.log(msgStr + 'setFullScreen then: ' + JSON.stringify(params)) + return setSystemBarEnableNavigationT() + }).then(function (params) { + console.log(msgStr + 'setSystemBarEnableNavigationT then: ' + JSON.stringify(params)) + return setSystemBarProperties() }) - }) }) /** * @tc.number SUB_WINDOW_CREATE_JSAPI_005 * @tc.name Test create5 * @tc.desc Scheme of Failed to Create Application Type Window in Stage Mode */ - it('createTest5', 0, done => { + it('createTest5', 0, async done => { let caseName = 'createTest5'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin context==' + JSON.stringify(context)); let loopCount = appWindowTypeArr.length; console.log(msgStr + 'loopCount: ' + loopCount); - getData(0, loopCount) - - function getData(i, length) { + for (let i = 0; i < loopCount; i++) { let tempType = ohosWindow.WindowType.TYPE_APP; let windId = 'createTest5' + i; console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); @@ -1016,17 +1589,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { try { expect(err.code === 1003).assertTrue(); - } catch (error) { console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) } console.log(msgStr + 'ohosWindow.create err.code==' + JSON.stringify(err.code)) - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + it('createTest6', 0, async done => { let caseName = 'createTest6'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); let loopCount = systemWindowTypeArr.length; - console.log('jsunittest loopCount: ' + loopCount); - getData(0, loopCount) + console.log(msgStr + 'loopCount: ' + loopCount); + let tempWnd = null + let tempType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT; - function getData(i, length) { - let tempType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT; - let windId = 'createTest6' + i; - console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); - ohosWindow.create(context, windId, tempType, (err, data) => { - console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); - console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); - return; - } - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) - } - let tempWnd = data - console.log(msgStr + 'ohosWindow.create ' + tempType + ' wnd: ' + tempWnd); + function create(i) { + return new Promise(function (resolve, reject) { + let windId = 'createTest6' + i; + console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); + console.log(msgStr + 'ohosWindow.create windId: ' + windId + ' start'); + ohosWindow.create(context, windId, tempType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); + return; + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + tempWnd = data + console.log(msgStr + 'ohosWindow.create ' + tempType + ' wnd: ' + tempWnd); + resolve(i) + }) + }) + } + + function getProperties(i) { + return new Promise(function (resolve, reject) { tempWnd.getProperties((err, data) => { console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err)); console.log(msgStr + 'tempWnd.getProperties data' + JSON.stringify(data)); @@ -1082,276 +1657,223 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } catch (error) { console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`) } - if (++i < length) { - getData(i, length) + resolve(i) + }) + }) + } + + function find(i) { + return new Promise(function (resolve, reject) { + console.log(msgStr + 'ohosWindow.find createTest6' + i); + ohosWindow.find('createTest6' + i, (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) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(i) + }) + }) + } + + function destroy(i) { + return new Promise(function (resolve, reject) { + tempWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(i) + }) + }) + } + + function findAgain(i) { + return new Promise(function (resolve, reject) { + console.log(msgStr + 'ohosWindow.findAgain createTest6' + i); + ohosWindow.find('createTest6' + i, (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(true).assertTrue(); + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + try { + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(i) + if (++i < loopCount) { + getData(i, loopCount) console.log(msgStr + 'jixuzhixing i: ' + i); } else { - console.log(msgStr + 'i++ { + it('createTest7', 0, async done => { let caseName = 'createTest7'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); let tempType = 5000; let windId = 'createTest7'; console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); - ohosWindow.create(context, windId, tempType, (err, data) => { - console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); - if (err && err.code) { - try { - expect(err.code === 1003).assertTrue(); - } catch (error) { - console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) - } - done(); - return; - } - unexpectedError(err, caseName, 'ohosWindow.create', done); - }) + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, windId, tempType, (err, data) => { + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + if (err && err.code) { + try { + expect(err.code === 1003).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + done(); + return; + } + unexpectedError(err, caseName, 'ohosWindow.create', done); + resolve(data) + }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + }) }) + /** - * @tc.number SUB_WINDOW_ON_OFF_JSAPI_005 - * @tc.name Test listenerTest5 - * @tc.desc Verify whether the change of avoidance area and change monitoring can be turned on normally + * @tc.number SUB_WINDOW_CREATE_JSAPI_008 + * @tc.name Test createTest8 + * @tc.desc Verify the scenario of creating a window with duplicate IDs */ - it('listenerTest5', 0, function (done) { - let caseName = 'listenerTest5'; + it('createTest8', 0, async done => { + let caseName = 'createTest8'; let msgStr = 'jsunittest ' + caseName + ' '; - let listenerOnFlag = listenerStatus.ready; console.log(msgStr + 'begin'); + let windowId = 'sameid' let tempWnd = null; - windowStage.getMainWindow((err, data) => { - console.log(msgStr + 'windowStage.getMainWindow err: ' + JSON.stringify(err)); - console.log(msgStr + 'windowStage.getMainWindow data: ' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.show', done); - } - tempWnd = data - console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) - } - tempWnd.show((err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.show', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.show success'); - tempWnd.setFullScreen(true, (err, data) => { + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, windowId, 1, (err, data) => { + console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err)); if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); - } - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) + unexpectedError(err, caseName, 'ohosWindow.create', done); } - 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(!!data).assertTrue(); + tempWnd = data; + ohosWindow.create(context, windowId, 1, (err, data) => { + console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err)); + if (err && err.code) { + console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data)); try { - expect(!!avoidAreaData).assertTrue(); + expect(err.code).assertEqual(1001) } catch (error) { - console.info(`tempWnd.on catch error: ${JSON.stringify(error)}`) + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data)); } - done(); }) - tempWnd.setSystemBarEnable([], (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done); - } + resolve(data) + }) + }) + } + + function createAgain() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, windowId, 1, (err, data) => { + console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err)); + if (err && err.code) { + console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data)); try { - expect(!data).assertTrue(); + expect(err.code).assertEqual(1001) } catch (error) { - console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success'); - listenerOnFlag = listenerStatus.pending; - }) - tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); - }) - console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished'); + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data)); + } + resolve(data) }) }) - }) - }) - /** - * @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 + ' '; - console.log(msgStr + 'begin'); - let tempWnd = null - let tempTypeArr = []; - try { - let data = windowStage.getMainWindowSync(); - console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); - console.log(msgStr + 'ohosWindow.create !!data' + !!data); - if (!!data) { - tempWnd = data -// console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd); - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`ohosWindwo.create catch error: ${JSON.stringify(error)}`) - } - let loopCount1 = systemWindowTypeArr; - console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount1)) - getData(0, loopCount1.length) + } - function getData(i, length) { - let tempType = ohosWindow.WindowType[loopCount1[i]]; - console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' start'); - tempTypeArr.push(tempType); - tempWnd.setWindowType(tempType, (err, data) => { - try { - console.log(msgStr + 'tempWnd.setWindowType i: ' + i); - console.log(msgStr + 'tempWnd.setWindowType err: ' + JSON.stringify(err)); - console.log(msgStr + 'tempWnd.setWindowType data: ' + JSON.stringify(data)); - console.log(msgStr + 'tempWnd.setWindowType !data: ' + !data); - if (!data) { - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'tempWnd.getProperties start'); - tempWnd.getProperties((err, dataProper) => { - try { - console.log(msgStr + 'tempWnd.getProperties err: ' + JSON.stringify(err)); - console.log(msgStr + 'tempWnd.getProperties dataProper: ' + JSON.stringify(dataProper)); - console.log(msgStr + 'tempWnd.getProperties !!dataProper: ' + !!dataProper); - try { - expect(!!dataProper).assertTrue(); - } catch (error) { - console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`) - } - if (!!dataProper) { - console.log(msgStr + 'tempWnd.getProperties true tempTypeArr: ' + JSON.stringify(tempTypeArr)); - console.log(msgStr + 'tempWnd.getProperties true i: ' + i); - tempTypeArr.splice(tempTypeArr.findIndex(item => item === dataProper.type), 1); - console.log(msgStr + 'tempWnd.getProperties true tempTypeArr.length: ' + tempTypeArr.length); - console.log(msgStr + 'tempWnd.getProperties true loopCount1.length: ' + loopCount1.length); - console.log(msgStr + 'tempWnd.getProperties true tempTypeArr.length + 1: ' + Number(tempTypeArr.length + 1)); - console.log(msgStr + 'tempWnd.getProperties true (loopCount1.length - i): ' + (loopCount1.length - i)); - console.log(msgStr + 'tempWnd.getProperties true (tempTypeArr.length + 1): ' + (tempTypeArr.length + 1)); - try { - expect(tempTypeArr.length === 0).assertTrue(); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } - } catch (error) { - console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`) - } - if (i == loopCount1.length - 1) { - console.log(msgStr + 'tempWnd.getProperties i=' + i + ' , loopCount1.length-1==' + loopCount1.length); - done(); - } - } - } catch (err) { - console.log(msgStr + 'tempWnd.getProperties catch err: ' + JSON.stringify(err)); - } - }) - } - console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' end'); - } catch (err) { - console.log(msgStr + 'tempWnd.setWindowType catch err: ' + JSON.stringify(err)); - } - }) - } - } - } catch (err) { - console.log(msgStr + 'ohosWindow.create catch err: ' + JSON.stringify(err)); - } - }) - /** - * @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_004 - * @tc.name Test setWindowTypeTest4 - * @tc.desc Verify the scene of setting illegal window type - */ - it('setWindowTypeTest4', 0, function (done) { - let caseName = 'setWindowTypeTest4'; - let msgStr = 'jsunittest ' + caseName + ' '; - let changedWndType = null; - console.log(msgStr + 'begin'); - let tempWnd = null - let data = windowStage.getMainWindowSync(); - console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); - console.log(msgStr + 'ohosWindow.create !!data' + !!data); - if (!!data) { - tempWnd = data - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) - } - tempWnd.setWindowType(changedWndType, (err, data) => { - console.log(msgStr + 'tempWnd.setWindowType err' + JSON.stringify(err)); - console.log(msgStr + 'tempWnd.setWindowType data' + JSON.stringify(data)); - console.log(msgStr + 'tempWnd.setWindowType !!data' + !!data); - if (!!data) { + function find() { + return new Promise(function (resolve, reject) { + 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) { unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } else { try { - expect(err.code == 1003).assertTrue(); + expect(!!data).assertTrue(); } catch (error) { - console.info(`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`) + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - done(); } + resolve(data) }) - } - }) - /** - * @tc.number SUB_WINDOW_DESTROY_JSAPI_002 - * @tc.name Test destroyTest2 - * @tc.desc Verification window destruction scenario - */ - it('destroyTest2', 0, function (done) { - let caseName = 'destroyTest2'; - let msgStr = 'jsunittest ' + caseName + ' '; - let baseWndType = 1; - let windowId = 'destroyTest2'; - console.log(msgStr + 'begin'); - let tempWnd = null - ohosWindow.create(context, windowId, baseWndType, (err, data) => { - console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); - console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); - console.log(msgStr + 'ohosWindow.create !!data' + !!data); - if (!!data) { - tempWnd = data - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } + }) + } + + function destroy(params) { + return new Promise(function (resolve, reject) { tempWnd.destroy((err, data) => { console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); @@ -1364,517 +1886,1654 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - ohosWindow.find(windowId, (err, data) => { - console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); - console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); - console.log(msgStr + 'ohosWindow.find !!data' + !!data); - if (err && err.code) { - try { - expect(err.code == 1001).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - unexpectedError(err, caseName, 'tempWnd.setWindowType', done); - } - }) } + resolve(data) }) - } else { - unexpectedError(err, caseName, 'ohosWindow.create', done); - } - }) + }) + } + + function findAgain(params) { + return new Promise(function (resolve, reject) { + 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(true).assertTrue(); + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + try { + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + done(); + }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return createAgain() + }).then(function (params) { + return find() + }).then(function (params) { + return destroy(params) + }).then(function (params) { + return findAgain(params) + }) }) + /** - * @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_ON_OFF_JSAPI_005 + * @tc.name Test listenerTest5 + * @tc.desc Verify whether the change of avoidance area and change monitoring can be turned on normally */ - it('loadContentTest7', 0, function (done) { - let caseName = 'loadContentTest7'; + it('listenerTest5', 0, async function (done) { + let caseName = 'listenerTest5'; let msgStr = 'jsunittest ' + caseName + ' '; - let baseWndType = 1; - let windowId = 'loadContentTest7'; + let listenerOnFlag = false; console.log(msgStr + 'begin'); - let tempWnd = null - ohosWindow.create(context, windowId, baseWndType, (err, data) => { - console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); - console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); - console.log(msgStr + 'ohosWindow.create !!data' + !!data); - if (!!data) { - tempWnd = data - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - tempWnd.loadContent('pages/index', (err, data) => { - console.log(msgStr + 'tempWnd.loadContent err' + JSON.stringify(err)); - console.log(msgStr + 'tempWnd.loadContent data' + JSON.stringify(data)); - console.log(msgStr + 'tempWnd.loadContent !data' + !data); + let tempWnd = null; + listenerData.on = true; + listenerData.typeStr = 'systemAvoidAreaChange'; + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + console.log(msgStr + 'windowStage.getMainWindow err: ' + JSON.stringify(err)); + console.log(msgStr + 'windowStage.getMainWindow data: ' + JSON.stringify(data)); if (err && err.code) { - unexpectedError(err, caseName, 'tempWnd.loadContent', done); - } else { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + tempWnd = data + newWindowObj = data + console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`) + } + resolve(data) + }) + }) + } + + function show() { + return new Promise(function (resolve, reject) { + tempWnd.show((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.show', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.show success'); + resolve(data) + }) + }) + } + + function setFullScreen() { + return new Promise(function (resolve, reject) { + tempWnd.setFullScreen(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setFullScreen catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setFullScreen(true) success'); + resolve(data) + }) + }) + } + + function tempWndOn() { + return new Promise(function (resolve, reject) { + tempWnd.on('systemAvoidAreaChange', avoidAreaData => { + console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, avoidAreaData : ' + JSON.stringify(avoidAreaData)); + if (listenerOnFlag === true) { + listenerOnFlag = false; try { - expect(!data).assertTrue(); + expect(!!avoidAreaData).assertTrue(); } catch (error) { - console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) + console.info(`tempWnd.on catch error: ${JSON.stringify(error)}`) } - done(); } + resolve(avoidAreaData) }) - } else { - unexpectedError(err, caseName, 'ohosWindow.create', done); - } - }) + }) + } + + function setSystemBarEnable() { + return new Promise(function (resolve, reject) { + tempWnd.setSystemBarEnable([], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done); + } + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success'); + listenerOnFlag = true; + resolve(data) + }) + }) + } + + function setSystemBarEnableT() { + return new Promise(function (resolve, reject) { + tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); + } + console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); + console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished'); + resolve(data) + tempWnd.off('systemAvoidAreaChange') + done(); + }) + }) + } + + await getMainWindow() + .then(function (params) { + console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) + return show() + }) + .then(function (params) { + console.log(msgStr + 'show then: ' + JSON.stringify(params)) + return setFullScreen() + }) + .then(function (params) { + console.log(msgStr + 'setFullScreen then: ' + JSON.stringify(params)) + return tempWndOn() + }) + .then(function (params) { + console.log(msgStr + 'tempWndOn then: ' + JSON.stringify(params)) + return setSystemBarEnable() + }) + .then(function (params) { + console.log(msgStr + 'setSystemBarEnable then: ' + JSON.stringify(params)) + return setSystemBarEnableT() + }) }) /** - * @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_SETWINDOWTYPE_JSAPI_003 + * @tc.name Test setWindowTypeTest3 + * @tc.desc Verify the scenario where the normal window type is set */ - it('loadContentTest8', 0, function (done) { - let caseName = 'loadContentTest8'; + it('setWindowTypeTest3', 0, async function (done) { + let caseName = 'setWindowTypeTest3'; let msgStr = 'jsunittest ' + caseName + ' '; let baseWndType = 1; - let windowId = 'loadContentTest8'; + let windowId = 'setWindowTypeTest3'; console.log(msgStr + 'begin'); let tempWnd = null - ohosWindow.create(context, windowId, baseWndType, (err, data) => { - console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); - console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); - console.log(msgStr + 'ohosWindow.create !!data' + !!data); - if (!!data) { - tempWnd = data - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) - } - tempWnd.loadContent(null, (err, data) => { - console.log(msgStr + 'tempWnd.loadContent err' + JSON.stringify(err)); - console.log(msgStr + 'tempWnd.loadContent data' + JSON.stringify(data)); - console.log(msgStr + 'tempWnd.loadContent !!data' + !!data); + let tempTypeArr = []; + let loopCount1 = systemWindowTypeArr; + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + try { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd); + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`ohosWindwo.create catch error: ${JSON.stringify(error)}`) + } + } + } catch (err) { + console.log(msgStr + 'ohosWindow.create catch err: ' + JSON.stringify(err)); + } + resolve(0) + }) + }) + } + + // function setWindowType(tempType) { + function setWindowType(i) { + return new Promise(function (resolve, reject) { + let tempType = ohosWindow.WindowType[loopCount1[i]]; + console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' start'); + tempTypeArr.push(tempType); + tempWnd.setWindowType(tempType, (err, data) => { + try { + console.log(msgStr + 'tempWnd.setWindowType i: ' + i); + console.log(msgStr + 'tempWnd.setWindowType err: ' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setWindowType data: ' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.setWindowType !data: ' + !data); + if (!data) { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'tempWnd.getProperties start'); + } + console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' end'); + } catch (err) { + console.log(msgStr + 'tempWnd.setWindowType catch err: ' + JSON.stringify(err)); + } + resolve(i) + }) + }) + } + + function getProperties(i) { + return new Promise(function (resolve, reject) { + 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) { + resolve(dataProper) + console.log(msgStr + 'tempWnd.getProperties true tempTypeArr: ' + JSON.stringify(tempTypeArr)); + console.log(msgStr + 'tempWnd.getProperties true i: ' + i); + tempTypeArr.splice(tempTypeArr.findIndex(item => item === dataProper.type), 1); + console.log(msgStr + 'tempWnd.getProperties true tempTypeArr.length: ' + tempTypeArr.length); + console.log(msgStr + 'tempWnd.getProperties true loopCount1.length: ' + loopCount1.length); + console.log(msgStr + 'tempWnd.getProperties true tempTypeArr.length + 1: ' + Number(tempTypeArr.length + 1)); + console.log(msgStr + 'tempWnd.getProperties true (loopCount1.length - i): ' + (loopCount1.length - i)); + console.log(msgStr + 'tempWnd.getProperties true (tempTypeArr.length + 1): ' + (tempTypeArr.length + 1)); + try { + expect(tempTypeArr.length === 0).assertTrue(); + if (++i < loopCount1.length) { + setWindowType(i).then(function (params) { + return getProperties(params) + }) + console.log(msgStr + 'jixuzhixing i: ' + i); + } else { + find().then(function (params) { + return destroy(params) + }).then(function (params) { + return findAgain(params) + }) + } + } 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); + } + } + } catch (err) { + console.log(msgStr + 'tempWnd.getProperties catch err: ' + JSON.stringify(err)); + } + // resolve(dataProper.type) + resolve(i) + }) + }) + } + // await create(); + // for (var i = 0; i < loopCount1.length; i++) { + // let tempType = ohosWindow.WindowType[loopCount1[i]]; + // await setWindowType(tempType) + // let propertiesData = await getProperties(); + // tempTypeArr.splice(tempTypeArr.findIndex(item => item === propertiesData), 1); + // expect(tempTypeArr.length === 0).assertTrue(); + // // expect(dataProper.type == tempType).assertTrue(); + // if ((i + 1) === loopCount1.length) { + // await tempWnd.destroy(); + // } + // } + // + function find() { + return new Promise(function (resolve, reject) { + 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) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { try { - expect(err.code === 1003).assertTrue(); + expect(!!data).assertTrue(); } catch (error) { - console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - done(); + } + resolve(data) + }) + }) + } + + function destroy(params) { + return new Promise(function (resolve, reject) { + tempWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); } else { - unexpectedError(err, caseName, 'tempWnd.loadContent', done); + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } } + resolve(data) }) - } else { - unexpectedError(err, caseName, 'ohosWindow.create', done); - } - }) - }) - /** - * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_009 - * @tc.name Test loadContentTest9 - * @tc.desc Verify the scenario of loading an existing page - */ - it('loadContentTest9', 0, function (done) { - let caseName = 'loadContentTest9'; - let msgStr = 'jsunittest ' + caseName + ' '; - console.log(msgStr + 'begin'); - windowStage.loadContent('pages/index/index.ets', (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'windowStage.loadContent', done); - console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); - } else { - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data)); - } - done(); - }); - }) - /** - * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_010 - * @tc.name Test loadContentTest10 - * @tc.desc Verify the scenario of loading an existing page - */ - it('loadContentTest10', 0, function (done) { - let caseName = 'loadContentTest10'; - let msgStr = 'jsunittest ' + caseName + ' '; - console.log(msgStr + 'begin'); - try { - windowStage.loadContent(null, (err, data) => { - console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); - try { - expect(false).assertTrue(); - } catch (error) { - console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) - } - }); - } catch (err) { - console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets) catch err' + JSON.stringify(err)); - try { - expect(err.code == 401).assertTrue(); - } catch (error) { - console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) - } + }) } - console.log(msgStr + 'end'); - done(); - }) - /** - * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_011 - * @tc.name Test loadContentTest11 - * @tc.desc Verify the scenario of loading an existing page - */ - it('loadContentTest11', 0, async function (done) { - let caseName = 'loadContentTest11'; - let msgStr = 'jsunittest ' + caseName + ' '; - console.log(msgStr + 'begin'); - windowStage.loadContent('pages/index/index.ets', abilityStorage, (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'windowStage.loadContent', done); - console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); - } else { - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data)); - } - done(); - }); + + function findAgain(params) { + return new Promise(function (resolve, reject) { + ohosWindow.find(windowId, (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + resolve(data) + done(); + }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return setWindowType(0) + }).then(function (params) { + console.log(msgStr + 'setWindowType then: ' + JSON.stringify(params)) + return getProperties(params) + }) + }) /** - * @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_SETWINDOWTYPE_JSAPI_004 + * @tc.name Test setWindowTypeTest4 + * @tc.desc Verify the scene of setting illegal window type */ - it('loadContentTest12', 0, function (done) { - let caseName = 'loadContentTest12'; + it('setWindowTypeTest4', 0, async function (done) { + let caseName = 'setWindowTypeTest4'; let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let changedWndType = null; + let windowId = 'setWindowTypeTest4'; console.log(msgStr + 'begin'); - try { - windowStage.loadContent(null, abilityStorage, (err, data) => { - console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); - try { - expect(false).assertTrue(); - } catch (error) { - console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) - } - }); - } catch (err) { - console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets) catch err ' + JSON.stringify(err)); - try { - expect(err.code === 401).assertTrue(); - } catch (error) { - console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) - } - } - done(); + let tempWnd = null + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + resolve(data) + } + else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + }) + }) + } + + function setWindowType() { + return new Promise(function (resolve, reject) { + tempWnd.setWindowType(changedWndType, (err, data) => { + console.log(msgStr + 'tempWnd.setWindowType err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.setWindowType data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.setWindowType !!data' + !!data); + if (!!data) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + try { + expect(err.code == 1003).assertTrue(); + } catch (error) { + console.info(`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function find() { + return new Promise(function (resolve, reject) { + 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) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function destroy(params) { + return new Promise(function (resolve, reject) { + tempWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function findAgain(params) { + return new Promise(function (resolve, reject) { + ohosWindow.find(windowId, (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + resolve(data) + done(); + }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return setWindowType() + }).then(function (params) { + return find() + }).then(function (params) { + return destroy(params) + }).then(function (params) { + return findAgain(params) + }) }) /** - * @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_DESTROY_JSAPI_002 + * @tc.name Test destroyTest2 + * @tc.desc Verification window destruction scenario */ - it('createSubWindowTest3', 0, function (done) { - let caseName = 'createSubWindowTest3'; + it('destroyTest2', 0, async function (done) { + let caseName = 'destroyTest2'; let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'destroyTest2'; console.log(msgStr + 'begin'); - windowStage.createSubWindow('createSubWindowTest3', (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'windowStage.createSubWindow', done); - console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest3) err=' + JSON.stringify(err)); - } else { - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.createSubWindow end data=' + JSON.stringify(data)); - } - done(); - }); + let tempWnd = null + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + resolve(data) + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + }) + }) + } + + function destroy() { + return new Promise(function (resolve, reject) { + tempWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + ohosWindow.find(windowId, (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(err.code == 1001).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + }) + } + resolve(data) + }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return destroy() + }) }) /** - * @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_LOADCONTENT_JSAPI_007 + * @tc.name Test loadContentTest7 + * @tc.desc Verify the scenario of loading an existing page */ - it('createSubWindowTest4', 0, function (done) { - let caseName = 'createSubWindowTest4'; + it('loadContentTest7', 0, async function (done) { + let caseName = 'loadContentTest7'; let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'loadContentTest7'; console.log(msgStr + 'begin'); - try { - windowStage.createSubWindow(null, (err, data) => { - console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err)); - try { - expect(false).assertTrue(); - } catch (error) { - console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`) - } - }); - } catch (err) { - try { - expect(err.code === 401).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.createSubWindow(null) catch err=' + JSON.stringify(err)); + let tempWnd = null + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + resolve(data) + }) + }) } - done(); + + function loadContent() { + return new Promise(function (resolve, reject) { + tempWnd.loadContent('pages/index', (err, data) => { + console.log(msgStr + 'tempWnd.loadContent err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.loadContent data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.loadContent !data' + !data); + if (err && err.code) { + unexpectedError(err, caseName, 'tempWnd.loadContent', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function find() { + return new Promise(function (resolve, reject) { + 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) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function destroy(params) { + return new Promise(function (resolve, reject) { + tempWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function findAgain(params) { + return new Promise(function (resolve, reject) { + ohosWindow.find(windowId, (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + resolve(data) + done(); + }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return loadContent() + }).then(function (params) { + return find() + }).then(function (params) { + return destroy(params) + }).then(function (params) { + return findAgain(params) + }) }) /** - * @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_LOADCONTENT_JSAPI_008 + * @tc.name Test loadContentTest8 + * @tc.desc Verify the scenario of loading a page that does not exist */ - it('getSubWindowTest2', 0, async function (done) { - let caseName = 'getSubWindowTest2'; + it('loadContentTest8', 0, async function (done) { + let caseName = 'loadContentTest8'; let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'loadContentTest8'; console.log(msgStr + 'begin'); - windowStage.getSubWindow((err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'windowStage.getSubWindow', done); - console.log(msgStr + 'windowStage.getSubWindow(null) err=' + JSON.stringify(err)); - } else { - try { - expect(!!data).assertTrue(); - } catch (error) { - console.info(`windowStage.getSubWindow catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.getSubWindow end data=' + JSON.stringify(data)); - } - done(); - }); - }) - /** - * @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_002 - * @tc.name Test setPrivacyModeTest2 - * @tc.desc Verify the scene where the application sub window is set as a security layer - */ - it('setPrivacyModeTest2', 0, async function (done) { - let caseName = 'setPrivacyModeTest2'; - let msgStr = 'jsunittest ' + caseName + ' '; - console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow)); - let mainWnd = null; - ohosWindow.create(context, 'setPrivacyModeTest2', ohosWindow.WindowType.TYPE_SYSTEM_ALERT, (err, data) => { - if (err && err.code) { - console.log(msgStr + 'ohosWindow.create fail err:' + JSON.stringify(err)); + let tempWnd = null + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, windowId, baseWndType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.create !!data' + !!data); + if (!!data) { + tempWnd = data + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } + resolve(data) + }) + }) + } + + function loadContent() { + return new Promise(function (resolve, reject) { + tempWnd.loadContent(null, (err, data) => { + console.log(msgStr + 'tempWnd.loadContent err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.loadContent data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.loadContent !!data' + !!data); + if (err && err.code) { + try { + expect(err.code === 1003).assertTrue(); + } catch (error) { + console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'tempWnd.loadContent', done); + } + resolve(data) + }) + }) + } + + function find() { + return new Promise(function (resolve, reject) { + 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) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function destroy(params) { + return new Promise(function (resolve, reject) { + tempWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function findAgain(params) { + return new Promise(function (resolve, reject) { + ohosWindow.find(windowId, (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + resolve(data) + done(); + }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return loadContent() + }).then(function (params) { + return find() + }).then(function (params) { + return destroy(params) + }).then(function (params) { + return findAgain(params) + }) + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_009 + * @tc.name Test loadContentTest9 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest9', 0, async function (done) { + let caseName = 'loadContentTest9'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + + function loadContent() { + return new Promise(function (resolve, reject) { + windowStage.loadContent('pages/index/index.ets', (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.loadContent', done); + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data)); + } + resolve(data) + done(); + }) + }) + } + + await loadContent() + .then(function (params) { + console.log(msgStr + 'loadContent then: ' + JSON.stringify(params)) + }) + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_010 + * @tc.name Test loadContentTest10 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest10', 0, async function (done) { + let caseName = 'loadContentTest10'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + + function loadContent() { + return new Promise(function (resolve, reject) { try { - expect().assertFail(); - } catch (error) { - console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + windowStage.loadContent(null, (err, data) => { + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); + try { + expect(false).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + resolve(data) + }); + } catch (err) { + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets) catch err' + JSON.stringify(err)); + try { + expect(err.code == 401).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } } + console.log(msgStr + 'end'); done(); - } else { + }) + } + + await loadContent() + .then(function (params) { + console.log(msgStr + 'loadContent then: ' + JSON.stringify(params)) + }) + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_011 + * @tc.name Test loadContentTest11 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest11', 0, async function (done) { + let caseName = 'loadContentTest11'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + + function loadContent() { + return new Promise(function (resolve, reject) { + windowStage.loadContent('pages/index/index.ets', abilityStorage, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.loadContent', done); + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data)); + } + resolve(data) + done(); + }) + }) + } + + await loadContent() + .then(function (params) { + console.log(msgStr + 'loadContent then: ' + JSON.stringify(params)) + }) + }) + /** + * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_012 + * @tc.name Test loadContentTest12 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest12', 0, async function (done) { + let caseName = 'loadContentTest12'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + + function loadContent() { + return new Promise(function (resolve, reject) { try { - expect(data != null).assertTrue(); - } catch (error) { - console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + windowStage.loadContent(null, abilityStorage, (err, data) => { + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); + try { + expect(false).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + resolve(data) + }); + } catch (err) { + console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets) catch err ' + JSON.stringify(err)); + try { + expect(err.code === 401).assertTrue(); + } catch (error) { + console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + } + } + done(); + }) + } + + await loadContent() + .then(function (params) { + console.log(msgStr + 'loadContent then: ' + JSON.stringify(params)) + }) + }) + /** + * @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_003 + * @tc.name Test createSubWindowTest3 + * @tc.desc Verify the scenario of creating an auxiliary window + */ + it('createSubWindowTest3', 0, async function (done) { + let caseName = 'createSubWindowTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let tempWnd = null + + function createSubWindow() { + return new Promise(function (resolve, reject) { + windowStage.createSubWindow('createSubWindowTest3', (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.createSubWindow', done); + console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest3) err=' + JSON.stringify(err)); + } else { + try { + tempWnd = data + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.createSubWindow end data=' + JSON.stringify(data)); + } + resolve(data) + }) + }) + } + + function find() { + return new Promise(function (resolve, reject) { + ohosWindow.find('createSubWindowTest3', (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) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function destroy(params) { + return new Promise(function (resolve, reject) { + tempWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function findAgain(params) { + return new Promise(function (resolve, reject) { + ohosWindow.find('createSubWindowTest3', (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + resolve(data) + done(); + }) + }) + } + + await createSubWindow() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return find() + }).then(function (params) { + return destroy(params) + }).then(function (params) { + return findAgain(params) + }) + }) + /** + * @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, async function (done) { + let caseName = 'createSubWindowTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + + function createSubWindow() { + return new Promise(function (resolve, reject) { + try { + windowStage.createSubWindow(null, (err, data) => { + console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err)); + try { + expect(false).assertTrue(); + } catch (error) { + console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`) + } + resolve(data) + }); + } catch (err) { + try { + expect(err.code === 401).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.createSubWindow(null) catch err=' + JSON.stringify(err)); } - console.log(msgStr + 'ohosWindow.create success data' + data); - mainWnd = data; + done(); + }) + } + + await createSubWindow() + .then(function (params) { + console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) + }) + }) + /** + * @tc.number SUB_WINDOW_GETSUBWINDOW_JSAPI_002 + * @tc.name Test getSubWindowTest2 + * @tc.desc Verify the scene of obtaining all auxiliary sub windows + */ + it('getSubWindowTest2', 0, async function (done) { + let caseName = 'getSubWindowTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + + function getSubWindow() { + return new Promise(function (resolve, reject) { + windowStage.getSubWindow((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.getSubWindow', done); + console.log(msgStr + 'windowStage.getSubWindow(null) err=' + JSON.stringify(err)); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`windowStage.getSubWindow catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.getSubWindow end data=' + JSON.stringify(data)); + } + resolve(data) + done(); + }) + }) + } + + await getSubWindow() + .then(function (params) { + console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params)) + }) + }) + /** + * @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_002 + * @tc.name Test setPrivacyModeTest2 + * @tc.desc Verify the scene where the application sub window is set as a security layer + */ + it('setPrivacyModeTest2', 0, async function (done) { + let caseName = 'setPrivacyModeTest2'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow)); + let mainWnd = null; + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, 'setPrivacyModeTest2', ohosWindow.WindowType.TYPE_SYSTEM_ALERT, (err, data) => { + if (err && err.code) { + console.log(msgStr + 'ohosWindow.create fail err:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + } else { + try { + expect(data != null).assertTrue(); + } catch (error) { + console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'ohosWindow.create success data' + data); + mainWnd = data; + resolve(data) + } + }) + }) + } + + function getProperties() { + return new Promise(function (resolve, reject) { + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data)); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function setPrivacyModeTrue() { + return new Promise(function (resolve, reject) { + mainWnd.setPrivacyMode(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); + console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setPrivacyMode catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data)); + } + resolve(data) + }) + }) + } + + function getProperties2() { + return new Promise(function (resolve, reject) { + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data)); + try { + expect(data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function setPrivacyModeFalse() { + return new Promise(function (resolve, reject) { + mainWnd.setPrivacyMode(false, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); + console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`mainWnd.setPrivacyMode catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data)); + } + resolve(data) + }) + }) + } + + function getProperties3() { + return new Promise(function (resolve, reject) { + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data)); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function find() { + return new Promise(function (resolve, reject) { + ohosWindow.find('setPrivacyModeTest2', (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) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function destroy(params) { + return new Promise(function (resolve, reject) { + mainWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function findAgain(params) { + return new Promise(function (resolve, reject) { + ohosWindow.find('setPrivacyModeTest2', (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + resolve(data) + done(); + }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return getProperties() + }) + .then(function (params) { + console.log(msgStr + 'getProperties then: ' + JSON.stringify(params)) + return setPrivacyModeTrue() + }) + .then(function (params) { + console.log(msgStr + 'setPrivacyModeTrue then: ' + JSON.stringify(params)) + return getProperties2() + }) + .then(function (params) { + console.log(msgStr + 'getProperties2 then: ' + JSON.stringify(params)) + return setPrivacyModeFalse() + }) + .then(function (params) { + console.log(msgStr + 'setPrivacyModeFalse then: ' + JSON.stringify(params)) + return getProperties3() + }) + .then(function (params) { + console.log(msgStr + 'getProperties3 then: ' + JSON.stringify(params)) + return find() + }) + .then(function (params) { + console.log(msgStr + 'find then: ' + JSON.stringify(params)) + return destroy(params) + }) + .then(function (params) { + console.log(msgStr + 'destroy then: ' + JSON.stringify(params)) + return findAgain(params) + }) + }) + /** + * @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_003 + * @tc.name Test setPrivacyModeTest3 + * @tc.desc Verify that the auxiliary window is set as the security layer + */ + it('setPrivacyModeTest3', 0, async function (done) { + let caseName = 'setPrivacyModeTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow)); + let mainWnd = null; + + function createSubWindow() { + return new Promise(function (resolve, reject) { + windowStage.createSubWindow('setPrivacyModeTest3', (err, data) => { + if (err && err.code) { + console.log(msgStr + 'windowStage.createSubWindow fail err:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + try { + expect(data != null).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'windowStage.createSubWindow success data' + data); + mainWnd = data; + } + resolve(data) + }) + }) + } + + function getProperties() { + return new Promise(function (resolve, reject) { + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data)); + try { + expect(!data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function setPrivacyModeTrue() { + return new Promise(function (resolve, reject) { + mainWnd.setPrivacyMode(true, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); + console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data)); + } + resolve(data) + }) + }) + } + + function getProperties2() { + return new Promise(function (resolve, reject) { + mainWnd.getProperties((err, data) => { + if (err.code != 0) { + console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data)); + try { + expect(data.isPrivacyMode).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function setPrivacyModeFalse() { + return new Promise(function (resolve, reject) { + mainWnd.setPrivacyMode(false, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); + console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err)); + } else { + try { + expect(!data).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data)); + } + resolve(data) + }) + }) + } + + function getProperties3() { + return new Promise(function (resolve, reject) { mainWnd.getProperties((err, data) => { if (err.code != 0) { - console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err)); + console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err)); try { expect().assertFail(); } catch (error) { - console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } done(); } else { - console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data)); + console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data)); try { expect(!data.isPrivacyMode).assertTrue(); } catch (error) { - console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - mainWnd.setPrivacyMode(true, (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); - console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err)); - } else { - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.setPrivacyMode catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data)); - mainWnd.getProperties((err, data) => { - if (err.code != 0) { - console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err)); - try { - expect().assertFail(); - } catch (error) { - console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data)); - try { - expect(data.isPrivacyMode).assertTrue(); - } catch (error) { - console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) - } - mainWnd.setPrivacyMode(false, (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); - console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err)); - } else { - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`mainWnd.setPrivacyMode catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data)); - mainWnd.getProperties((err, data) => { - if (err.code != 0) { - console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err)); - try { - expect().assertFail(); - } catch (error) { - console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data)); - try { - expect(!data.isPrivacyMode).assertTrue(); - } catch (error) { - console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`) - } - } - done(); - }) - } - }); - } - }) - } - }); } + resolve(data) }) - } - }) - }) - /** - * @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_003 - * @tc.name Test setPrivacyModeTest3 - * @tc.desc Verify that the auxiliary window is set as the security layer - */ - it('setPrivacyModeTest3', 0, async function (done) { - let caseName = 'setPrivacyModeTest3'; - let msgStr = 'jsunittest ' + caseName + ' '; - console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow)); - let mainWnd = null; - windowStage.createSubWindow('setPrivacyModeTest3', (err, data) => { - if (err && err.code) { - console.log(msgStr + 'windowStage.createSubWindow fail err:' + JSON.stringify(err)); - try { - expect().assertFail(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - try { - expect(data != null).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'windowStage.createSubWindow success data' + data); - mainWnd = data; - mainWnd.getProperties((err, data) => { - if (err.code != 0) { - console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err)); + }) + } + + function find() { + return new Promise(function (resolve, reject) { + ohosWindow.find('setPrivacyModeTest3', (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) { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } else { try { - expect().assertFail(); + expect(!!data).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - done(); + } + resolve(data) + }) + }) + } + + function destroy(params) { + return new Promise(function (resolve, reject) { + mainWnd.destroy((err, data) => { + console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.destroy !!data' + !!data); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.destroy', done); } else { - console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data)); try { - expect(!data.isPrivacyMode).assertTrue(); + expect(!data).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - mainWnd.setPrivacyMode(true, (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); - console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err)); - } else { - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data)); - mainWnd.getProperties((err, data) => { - if (err.code != 0) { - console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err)); - try { - expect().assertFail(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data)); - try { - expect(data.isPrivacyMode).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - mainWnd.setPrivacyMode(false, (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); - console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err)); - } else { - try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data)); - mainWnd.getProperties((err, data) => { - if (err.code != 0) { - console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err)); - try { - expect().assertFail(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data)); - try { - expect(!data.isPrivacyMode).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - } - done(); - }) - } - }); - } - }) - } - }); } + resolve(data) }) - } - }) + }) + } + + function findAgain(params) { + return new Promise(function (resolve, reject) { + ohosWindow.find('setPrivacyModeTest2', (err, data) => { + console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); + console.log(msgStr + 'ohosWindow.find !!data' + !!data); + if (err && err.code) { + try { + expect(true).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); + } + resolve(data) + done(); + }) + }) + } + + await createSubWindow() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return getProperties() + }) + .then(function (params) { + console.log(msgStr + 'getProperties then: ' + JSON.stringify(params)) + return setPrivacyModeTrue() + }) + .then(function (params) { + console.log(msgStr + 'setPrivacyModeTrue then: ' + JSON.stringify(params)) + return getProperties2() + }) + .then(function (params) { + console.log(msgStr + 'getProperties2 then: ' + JSON.stringify(params)) + return setPrivacyModeFalse() + }) + .then(function (params) { + console.log(msgStr + 'setPrivacyModeFalse then: ' + JSON.stringify(params)) + return getProperties3() + }) + .then(function (params) { + console.log(msgStr + 'getProperties3 then: ' + JSON.stringify(params)) + return find() + }) + .then(function (params) { + console.log(msgStr + 'find then: ' + JSON.stringify(params)) + return destroy(params) + }) + .then(function (params) { + console.log(msgStr + 'destroy then: ' + JSON.stringify(params)) + return findAgain(params) + }) }) + /** * @tc.number SUB_WINDOW_SETDENSITTYDPI_JSAPI_002 * @tc.name Test setDensityDpiTest2 @@ -1904,9 +3563,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) currentDeviceDefault = data; currentDeviceDefaultDpi = parseInt(currentDeviceDefault.densityDPI) let dpiItem = [-80, 80, 1000, 160, 0, 320, 188.88, 0, 640, 300, currentDeviceDefaultDpi]; - getData(0, dpiItem.length) - - function getData(i, length) { + for (let i = 0; i < dpiItem.length; i++) { screens[0].setDensityDpi(dpiItem[i], (errDpi, dataDpi) => { if (errDpi.code) { console.error('Failed to set DensityDpi. Cause: ' + JSON.stringify(err) + dpiItem[i]); @@ -1925,16 +3582,41 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + // if (errDpi.code) { + // console.error('Failed to set DensityDpi. Cause: ' + JSON.stringify(err) + dpiItem[i]); + // return; + // } + // console.log(msgStr + 'screen.setDensityDpi success set DPI ' + dpiItem[i]); + // display.getDefaultDisplay((error, result) => { + // if (error.code) { + // console.error(msgStr + 'screen.setDensityDpi display.getDefaultDisplay failed'); + // return; + // console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay' + JSON.stringify(result)); + // let isEqual = Number(result.densityDPI) == parseInt(dpiItem[i]) + // console.log(msgStr + 'same ? ' + isEqual) + // try { + // expect(isEqual).assertTrue(); + // } catch (error) { + // console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + // } + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { - unexpectedError(err, caseName, 'windowStage.getMainWindow', done); - }); - console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); - try { - expect(!!mainWin).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + let mainWin = null; + + function getMainWindow() { + return new Promise(function (resolve, reject) { + windowStage.getMainWindow((err, data) => { + console.log(msgStr + 'getMainWindow data:' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'windowStage.getMainWindow', done); + } + try { + expect(!!data).assertTrue(); + } catch (error) { + console.info(`ohosWindow.on ${JSON.stringify(error)}`) + } + mainWin = data + resolve(data); + console.log(msgStr + 'await windowStage JSON.stringify(mainWin)===' + JSON.stringify(mainWin)); + }) + }) } + 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']; - getData(0, orientationItem.length) - async function getData(i, length) { - let orientation = ohosWindow.Orientation[orientationItem[i]] - await mainWin.setPreferredOrientation(orientation, (err, data) => { - if (err && err.code) { - console.log(msgStr + 'window.setPreferredOrientation failed set error' + orientation); - } - num++ - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + if (err && err.code) { + console.log(msgStr + 'window.setPreferredOrientation failed set error' + orientation); + } + num++ + if (++i < orientationItem.length) { + setPreferredOrientation(i) + console.log(msgStr + 'jixuzhixing i: ' + i); + } else { + console.log(msgStr + 'i++ { + it('dialogTargetTouchTest2', 0, async done => { let caseName = 'dialogTargetTouchTest2'; let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin context==' + JSON.stringify(context)); let tempType = ohosWindow.WindowType.TYPE_DIALOG - ohosWindow.create(context, 'dialogTargetTouchTest2', tempType, (err, data) => { - console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); - console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); - if (err && err.code) { - unexpectedError(err, caseName, 'ohosWindow.create', done); - } else { - let dialogTargetTouchTest2Win = data - try { - expect(!!dialogTargetTouchTest2Win).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } + let dialogTargetTouchTest2Win = null + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, 'dialogTargetTouchTest2', tempType, (err, data) => { + console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create', done); + } else { + dialogTargetTouchTest2Win = data + try { + expect(!!dialogTargetTouchTest2Win).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + } + resolve(data) + }) + }) + } + + function destroy() { + return new Promise(function (resolve, reject) { dialogTargetTouchTest2Win.destroy(); + resolve(true) done(); - } - }) + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return destroy() + }) }) /** * @tc.number SUB_WINDOW_ANIMATIONFORSHOWN_JSAPI_002 @@ -2128,6 +3849,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) context.completeTransition(true) console.info(msgStr + 'complete transition end'); } + tempWnd.destroy(); done(); } }); @@ -2168,27 +3890,57 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'begin context==' + JSON.stringify(context)); let wndId = 'showWithAnimationTest2'; let baseType = ohosWindow.WindowType.TYPE_FLOAT; - ohosWindow.create(context, wndId, baseType, (err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); - } else { - let tempWnd = data; - console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + JSON.stringify(tempWnd)); - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } + let tempWnd = null; + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, wndId, baseType, (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); + } else { + tempWnd = data; + console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + JSON.stringify(tempWnd)); + try { + expect(!!tempWnd).assertTrue(); + } catch (error) { + console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) + } + + } + resolve(data) + }) + }) + } + + function showWithAnimation() { + return new Promise(function (resolve, reject) { tempWnd.showWithAnimation((error, animationData) => { if (error && error.code) { unexpectedError(error, caseName, 'Failed to show the window with animation', done); } else { console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(animationData)); - done(); + resolve(animationData) } }) - } - }) + }) + } + + function destroy() { + return new Promise(function (resolve, reject) { + tempWnd.destroy(); + resolve(true) + done(); + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return showWithAnimation() + }).then(function (params) { + console.log(msgStr + 'showWithAnimation then: ' + JSON.stringify(params)) + return destroy() + }) }) /** * @tc.number SUB_WINDOW_HIDEWITHANIMATION_JSAPI_002 @@ -2201,85 +3953,62 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'begin context==' + JSON.stringify(context)); let wndId = 'hideWithAnimationTest2'; let baseType = ohosWindow.WindowType.TYPE_FLOAT; - ohosWindow.create(context, wndId, baseType, (creare_err, tempWnd) => { - if (creare_err && creare_err.code) { - unexpectedError(creare_err, caseName, 'ohosWindow.create ' + baseType, done); - } - try { - expect(!!tempWnd).assertTrue(); - } catch (error) { - console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) - } - ohosWindow.find(wndId, (findErr, findWnd) => { - if (findErr && findErr.code) { - unexpectedError(findErr, caseName, 'Failed to hide the window with animation', done); - } else { - findWnd.hideWithAnimation((err, data) => { - if (err && err.code) { - unexpectedError(err, caseName, 'Failed to hide the window with animation', done); - } else { - console.info('Succeeded in hiding the window with animation. Data: ' + JSON.stringify(data)); - done(); - } - }) - } - }) - }) - }) - /** - * @tc.number SUB_WINDOW_CREATE_JSAPI_008 - * @tc.name Test createTest8 - * @tc.desc Verify the scenario of creating a window with duplicate IDs - */ - it('createTest8', 0, done => { - let caseName = 'createTest8'; - let msgStr = 'jsunittest ' + caseName + ' '; - console.log(msgStr + 'begin'); - let windowId = 'sameid' - ohosWindow.create(context, windowId, 1, (err, data) => { - console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err)); - if (err && err.code) { - unexpectedError(err, caseName, 'ohosWindow.create', done); - } - expect(!!data).assertTrue(); - ohosWindow.create(context, windowId, 1, (err, data) => { - console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err)); - if (err && err.code) { - console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data)); + let tempWnd = null + + function create() { + return new Promise(function (resolve, reject) { + ohosWindow.create(context, wndId, baseType, (creare_err, data) => { + if (creare_err && creare_err.code) { + unexpectedError(creare_err, caseName, 'ohosWindow.create ' + baseType, done); + } try { - expect(err.code).assertEqual(1001) + tempWnd = data + expect(!!tempWnd).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } - done(); - } else { - unexpectedError(err, caseName, 'ohosWindow.create', done); - console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data)); - } + resolve(data) + }) + }) + } + + function find() { + return new Promise(function (resolve, reject) { + ohosWindow.find(wndId, (findErr, findWnd) => { + if (findErr && findErr.code) { + unexpectedError(findErr, caseName, 'Failed to hide the window with animation', done); + } else { + findWnd.hideWithAnimation((err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'Failed to hide the window with animation', done); + } else { + console.info('Succeeded in hiding the window with animation. Data: ' + JSON.stringify(data)); + done(); + } + }) + } + resolve(findWnd) + }) + }) + } + + function destroy() { + return new Promise(function (resolve, reject) { + tempWnd.destroy(); + resolve(true) + done(); + }) + } + + await create() + .then(function (params) { + console.log(msgStr + 'create then: ' + JSON.stringify(params)) + return find() + }).then(function (params) { + console.log(msgStr + 'find then: ' + JSON.stringify(params)) + return destroy() }) - }) - }) - /** - * @tc.number SUB_WINDOW_CREATE_JSAPI_004 - * @tc.name Test createTest4 - * @tc.desc Verify the scenario of creating a window with duplicate IDs - */ - it('createTest4', 0, async function (done) { - let caseName = 'createTest4'; - let msgStr = 'jsunittest ' + caseName + ' '; - console.log(msgStr + 'begin'); - let windowId = 'sameids' - let ohosData = await ohosWindow.create(context, windowId, 1).catch((err) => { - console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err)); - unexpectedError(err, caseName, 'ohosWindow.create', done); - }) - expect(!!ohosData).assertTrue(); - let ohosDataError = await ohosWindow.create(context, windowId, 1).catch((err) => { - console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err)); - expect(err.code).assertEqual(1001) - done(); - }) - console.log(msgStr + 'ohosWindow.create 1 twice ohosDataError: ' + JSON.stringify(ohosDataError)); }) - }) + } + ) } diff --git a/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets b/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets index eea62d513e33a66d030a64e6fd7bd4cd09733822..bc390350f4a89279a0ff04c8e8a46ede36422566 100644 --- a/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets @@ -75,6 +75,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) }) afterEach(async function (done) { windowCount++; + console.log('promise jsunittest afterEach listenerData:' + JSON.stringify(listenerData)); if (listenerData.on) { listenerData.on = false; console.log('jsunittest afterEach listener off, listenerData:' + JSON.stringify(listenerData)); @@ -121,7 +122,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) it('listenerTest1', 0, async function (done) { let caseName = 'listenerTest1'; let msgStr = 'jsunittest ' + caseName + ' '; - let listenerOnFlag = listenerStatus.ready; + let listenerOnFlag = false; console.log(msgStr + 'begin'); let tempWnd = await windowStage.getMainWindow().catch((err) => { unexpectedError(err, caseName, 'windowStage.getMainWindow', done); @@ -129,12 +130,12 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); listenerData.on = true; listenerData.typeStr = 'systemAvoidAreaChange'; + tempWnd.on('systemAvoidAreaChange', (avoidAreaData) => { - console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, systemBatData : ' + JSON.stringify(avoidAreaData)); - if (listenerOnFlag === listenerStatus.pending) { - listenerOnFlag = listenerStatus.finished; + console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, avoidAreaData : ' + JSON.stringify(avoidAreaData)); + console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, listenerOnFlag : ' + JSON.stringify(listenerOnFlag)); + if (listenerOnFlag) { expect(!!avoidAreaData).assertTrue(); - done(); } }) expect(!!tempWnd).assertTrue(); @@ -153,10 +154,12 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished'); await sleep(1000); - listenerOnFlag = listenerStatus.pending; + listenerOnFlag = true; await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => { unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); }); + await tempWnd.off('systemAvoidAreaChange'); + done(); console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); }) @@ -176,9 +179,12 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) let listenerOnFlag = listenerStatus.ready; console.log(msgStr + 'begin'); let tempWnd = null; + listenerData.on = true; + listenerData.typeStr = 'windowSizeChange'; try { await ohosWindow.create(context, wndId, baseType).then((data) => { tempWnd = data + newWindowObj = tempWnd console.log(msgStr + 'ohosWindow.create data:' + JSON.stringify(data)); }).catch((err) => { unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); @@ -197,7 +203,6 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) expect(!!sizeData).assertTrue(); expect(sizeData.width === resizeValue).assertTrue(); expect(sizeData.height === resizeValue).assertTrue(); - done(); } }) await tempWnd.show().catch((err) => { @@ -218,6 +223,8 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) await tempWnd.resetSize(resizeValue, resizeValue).catch((err) => { unexpectedError(err, caseName, 'tempWnd.resetSize(' + resizeValue + ', ' + resizeValue + ')', done); }); + await tempWnd.destroy(); + done(); console.log(msgStr + 'tempWnd.resetSize(' + resizeValue + ', ' + resizeValue + ') success'); }) /** @@ -276,7 +283,9 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) let wndId = 'listenerTest4'; let baseType = 2; let changedModel = 102; - let listenerOffFlag = listenerStatus.ready; + let listenerOffFlag = false; + listenerData.on = true; + listenerData.typeStr = 'windowSizeChange'; console.log(msgStr + 'begin'); let createWindowObj = { name: wndId, windowType: baseType, ctx: context @@ -287,20 +296,9 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) await ohosWindow.create(context, wndId, baseType).then((data) => { console.log(msgStr + 'ohosWindow.create data:' + JSON.stringify(data)); tempWnd = data + newWindowObj = data console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + tempWnd); expect(!!tempWnd).assertTrue(); - listenerData.on = true; - listenerData.typeStr = 'windowSizeChange'; - tempWnd.on('windowSizeChange', (sizeData) => { - console.log(msgStr + 'tempWnd.on windowSizeChange, sizeData : ' + JSON.stringify(sizeData)); - if (listenerOffFlag === listenerStatus.pending) { - listenerOffFlag = listenerStatus.finished; - console.log(msgStr + 'tempWnd.on windowSizeChange, listenerOffFlag === listenerStatus.pending : ' + JSON.stringify(sizeData)); - expect(sizeData.width === 100).assertTrue(); - expect(sizeData.height === 100).assertTrue(); - done(); - } - }) }).catch((err) => { unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); }); @@ -315,20 +313,36 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'tempWnd.setWindowMode ' + changedModel, done); }); console.log(msgStr + 'tempWnd.setWindowMode ' + changedModel + ' success'); - await tempWnd.resetSize(100, 100).catch((err) => { + await tempWnd.on('windowSizeChange', (sizeData) => { + console.log(msgStr + 'tempWnd.on windowSizeChange, sizeData : ' + JSON.stringify(sizeData)); + if (listenerOffFlag) { + listenerOffFlag = false; + console.log(msgStr + 'tempWnd.on windowSizeChange, listenerOffFlag === listenerStatus.pending : ' + JSON.stringify(sizeData)); + expect(sizeData.width === 100).assertTrue(); + expect(sizeData.height === 100).assertTrue(); + done(); + } else { + console.log(msgStr + 'tempWnd.on windowSizeChange,else listenerOffFlag : ' + listenerOffFlag); + console.log(msgStr + 'tempWnd.on windowSizeChange,else sizeData : ' + JSON.stringify(sizeData)); + } + }) + console.log(msgStr + 'tempWnd.on windowSizeChange finished'); + await tempWnd.resetSize(100, 100).then(() => { + listenerOffFlag = true; + console.log(msgStr + 'listenerOffFlag:' + listenerOffFlag); + }).catch((err) => { unexpectedError(err, caseName, 'tempWnd.resetSize(100, 100)', done); }); console.log(msgStr + 'tempWnd.resetSize(100, 100) success'); - console.log(msgStr + 'tempWnd.on windowSizeChange finished'); - listenerOffFlag = listenerStatus.pending; await sleep(1000); - tempWnd.off('windowSizeChange'); + await tempWnd.off('windowSizeChange'); console.log(msgStr + 'tempWnd.off windowSizeChange finished'); - sleep(1000); + await sleep(1000); await tempWnd.resetSize(200, 200).catch((err) => { unexpectedError(err, caseName, 'tempWnd.resetSize(200, 200)', done); console.log(msgStr + 'tempWnd.resetSize(200, 200) err: ' + JSON.stringify(err)); }); + await tempWnd.destroy(); console.log(msgStr + 'tempWnd.resetSize(200, 200) success'); }) /** @@ -351,11 +365,9 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) expect(!!tempWnd).assertTrue(); let loopCount1 = systemWindowTypeArr; console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount1)) - getData(1, loopCount1.length) - - async function getData(i, length) { + for (let i = 1; i < loopCount1.length; i++) { let tempType = ohosWindow.WindowType[loopCount1[i]]; - console.log(msgStr + 'tempWnd.setWindowType: ' + tempType + ' ,start ,i:'+i); + console.log(msgStr + 'tempWnd.setWindowType: ' + tempType + ' ,start'); tempTypeArr.push(tempType); console.log(msgStr + 'tempTypeArr: ' + JSON.stringify(tempTypeArr)); let windowTypeData = await tempWnd.setWindowType(tempType).catch((err) => { @@ -377,18 +389,12 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) tempTypeArr.splice(tempTypeArr.findIndex(item => item === prodata.type), 1); console.log(msgStr + '(loopCount1.length - i): ' + (loopCount1.length - i)); console.log(msgStr + '(tempTypeArr.length + 1): ' + (tempTypeArr.length + 1)); - console.log(msgStr + '(loopCount1.length - 1): ' + (loopCount1.length - 1)); if (i == loopCount1.length - 1) { expect((loopCount1.length - i) == (tempTypeArr.length + 1)).assertTrue(); console.log(msgStr + 'tempWnd.getProperties i=' + i + ' , loopCount1.length-1==' + loopCount1.length); + await tempWnd.destroy(); + done(); } - if (++i <= length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + await ohosWindow.create(context, windowId, baseWndType).then( + (data) => { + tempWnd = data + } + ).catch((err) => { unexpectedError(err, caseName, 'ohosWindow.create', done); }) console.log(msgStr + 'ohosWindow.create tempWnd' + JSON.stringify(tempWnd)); console.log(msgStr + 'ohosWindow.create !!tempWnd' + !!tempWnd); if (!!tempWnd) { expect(!!tempWnd).assertTrue(); - let windowTypeData = await tempWnd.setWindowType(changedWndType).catch((err) => { - console.log(msgStr + 'tempWnd.setWindowType err: ' + JSON.stringify(err)); - expectedError(err, caseName, 'tempWnd.setWindowType', done, 1003); + await tempWnd.setWindowType(changedWndType).then(() => { + }).catch((err) => { + console.log(msgStr + 'tempWnd.setWindowType err.code: ' + JSON.stringify(err.code)); + tempWnd.destroy(); + let flag = (err.code == 1003) + console.log(msgStr + 'tempWnd.setWindowType flag: ' + flag); + if (flag) { + expect(true).assertTrue(); + } done(); }) - console.log(msgStr + 'tempWnd.setWindowType windowTypeData' + JSON.stringify(windowTypeData)); - console.log(msgStr + 'tempWnd.setWindowType !windowTypeData' + !windowTypeData); - if (!!windowTypeData) { - expect(false).assertFail(); - } } }) /** @@ -436,6 +447,48 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) let statusFlag = listenerStatus.ready; let navigationFlag = listenerStatus.ready; console.log(msgStr + 'begin'); + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; + ohosWindow.on('systemBarTintChange', async (systemBarData) => { + console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); + if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) { + console.log(msgStr + 'systemBarTintChange compare start!'); + expect(!!systemBarData).assertTrue(); + expect(!!systemBarData.regionTint).assertTrue(); + let arrLength = systemBarData.regionTint.length; + for (let i = 0; i < arrLength; i++) { + let tempData = systemBarData.regionTint[i]; + console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable); + if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) { + statusFlag = listenerStatus.finished; + expect(tempData.isEnable).assertTrue(); + } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) { + navigationFlag = listenerStatus.finished; + expect(!tempData.isEnable).assertTrue(); + } + } + // await getData(0, arrLength) + // + // function getData(i, length) { + // let tempData = systemBarData.regionTint[i]; + // console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable); + // if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) { + // statusFlag = listenerStatus.finished; + // expect(tempData.isEnable).assertTrue(); + // } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) { + // navigationFlag = listenerStatus.finished; + // expect(!tempData.isEnable).assertTrue(); + // } + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { unexpectedError(err, caseName, 'windowStage.getMainWindow', done); @@ -450,62 +503,18 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done); }); console.log(msgStr + 'tempWnd.setFullScreen(true) success'); + await tempWnd.setSystemBarEnable(['navigation']).catch((err) => { unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([navigation])', done); }); - console.log(msgStr + 'tempWnd.setSystemBarEnable([navigation]) success'); + console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success'); await sleep(1000); statusFlag = listenerStatus.pending; navigationFlag = listenerStatus.pending; - if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) { - console.log(msgStr + 'start on !!!!'); - listenerData.on = true; - listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systemBarData) => { - console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); - console.log(msgStr + 'tempWnd.on , statusFlag : ' + JSON.stringify(statusFlag)); - console.log(msgStr + 'tempWnd.on , listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending)); - console.log(msgStr + 'tempWnd.on , navigationFlag : ' + JSON.stringify(navigationFlag)); - console.log(msgStr + 'tempWnd.on , listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending)); - - setTimeout(() => { - console.log(msgStr + 'tempWnd.on , 3 statusFlag : ' + JSON.stringify(statusFlag)); - console.log(msgStr + 'tempWnd.on , 3 listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending)); - console.log(msgStr + 'tempWnd.on , 3 navigationFlag : ' + JSON.stringify(navigationFlag)); - console.log(msgStr + 'tempWnd.on , 3 listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending)); - - if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) { - console.log(msgStr + 'systemBarTintChange compare start!'); - expect(!!systemBarData).assertTrue(); - expect(!!systemBarData.regionTint).assertTrue(); - let arrLength = systemBarData.regionTint.length; - for (let i = 0; i < arrLength; i++) { - let tempData = systemBarData.regionTint[i]; - console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable); - if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) { - statusFlag = listenerStatus.finished; - expect(!tempData.isEnable).assertTrue(); - } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) { - navigationFlag = listenerStatus.finished; - expect(tempData.isEnable).assertTrue(); - } - } - ohosWindow.off('systemBarTintChange'); - } - done(); - }, 3000) - }) - } - - await tempWnd.setSystemBarEnable(['status']).catch((err) => { unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status])', done); }); - console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success'); - console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success, statusFlag : ' + JSON.stringify(statusFlag)); - console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success, listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending)); - console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success, navigationFlag : ' + JSON.stringify(navigationFlag)); - console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success, listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending)); + console.log(msgStr + 'tempWnd.setSystemBarEnable([navigation]) success'); }) /** * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_002 @@ -520,16 +529,14 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'begin'); listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systemBarData) => { + ohosWindow.on('systemBarTintChange', async (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) { console.log(msgStr + 'systemBarTintChange compare start!'); expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - getData(0, arrLength) - - function getData(i, length) { + for (let i = 0; i < arrLength; i++) { let tempData = systemBarData.regionTint[i]; console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable); if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) { @@ -539,13 +546,26 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) navigationFlag = listenerStatus.finished; expect(tempData.isEnable).assertTrue(); } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + ohosWindow.on('systemBarTintChange', async (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) { console.log(msgStr + 'systemBarTintChange compare start!'); expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - getData(0, arrLength) - - function getData(i, length) { + for (let i = 0; i < arrLength; i++) { let tempData = systemBarData.regionTint[i]; console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable); if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) { @@ -608,13 +626,26 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) navigationFlag = listenerStatus.finished; expect(tempData.isEnable).assertTrue(); } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + ohosWindow.on('systemBarTintChange', async (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) { console.log(msgStr + 'systemBarTintChange compare start!'); expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - getData(0, arrLength) - - function getData(i, length) { + for (let i = 0; i < arrLength; i++) { let tempData = systemBarData.regionTint[i]; console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable); if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) { @@ -677,13 +706,26 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) navigationFlag = listenerStatus.finished; expect(!tempData.isEnable).assertTrue(); } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + ohosWindow.on('systemBarTintChange', async (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (listenerFlag === listenerStatus.pending) { expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - getData(0, arrLength) - - function getData(i, length) { + for (let i = 0; i < arrLength; i++) { let tempData = systemBarData.regionTint[i]; if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { console.log(msgStr + 'systemBarTintChange compare start!'); @@ -780,14 +820,27 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); expect(backgroundIndex === -1).assertTrue(); expect(contentColorIndex === -1).assertTrue(); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + await tempWnd.setSystemBarProperties(systemBarProperties).then(() => { console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err)); expect(TRUE_FLAG).assertFail(); }) } + // await getData(0, loopCount) + // + // async function getData(i, length) { + // let tempColor = commonRGBColorArr[i]; + // let systemBarProperties = { + // statusBarColor: tempColor, + // isStatusBarLightIcon: true, + // statusBarContentColor: tempColor, + // navigationBarColor: tempColor, + // isNavigationBarLightIcon: false, + // navigationContentColor: tempColor, + // }; + // tempWnd.setSystemBarProperties(systemBarProperties).then(() => { + // console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + // console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err)); + // expect(TRUE_FLAG).assertFail(); + // }) + // } }) /** @@ -858,15 +928,13 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'begin'); listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systemBarData) => { + ohosWindow.on('systemBarTintChange', async (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (listenerFlag === listenerStatus.pending) { expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - getData(0, arrLength) - - function getData(i, length) { + for (let i = 0; i < arrLength; i++) { let tempData = systemBarData.regionTint[i]; if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR) { console.log(msgStr + 'systemBarTintChange compare start!'); @@ -895,13 +963,45 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) expect(backgroundIndex !== -1).assertTrue(); expect(contentColorIndex !== -1).assertTrue(); } - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++= 0) { + // cloneColorArr.SBC.splice(backgroundIndex, 1); + // } + // if (contentColorIndex >= 0) { + // cloneColorArr.SCC.splice(contentColorIndex, 1); + // } + // expect(backgroundIndex !== -1).assertTrue(); + // expect(contentColorIndex !== -1).assertTrue(); + // } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { + // console.log(msgStr + 'systemBarTintChange compare start!'); + // compareCount++; + // let backgroundIndex = cloneColorArr.NBC.indexOf(tempData.backgroundColor); + // let contentColorIndex = cloneColorArr.NCC.indexOf(tempData.contentColor); + // if (backgroundIndex >= 0) { + // cloneColorArr.NBC.splice(backgroundIndex, 1); + // } + // if (contentColorIndex >= 0) { + // cloneColorArr.NCC.splice(contentColorIndex, 1); + // } + // expect(backgroundIndex !== -1).assertTrue(); + // expect(contentColorIndex !== -1).assertTrue(); + // } + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + await tempWnd.setSystemBarProperties(systemBarProperties).then(() => { console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err)); expect(TRUE_FLAG).assertFail(); }) } + // await getData(0, loopCount) + // + // function getData(i, length) { + // let tempColor = commonNUMBERColorArr[i]; + // let systemBarProperties = { + // statusBarColor: tempColor, + // isStatusBarLightIcon: true, + // statusBarContentColor: tempColor, + // navigationBarColor: tempColor, + // isNavigationBarLightIcon: true, + // navigationBarContentColor: tempColor, + // }; + // tempWnd.setSystemBarProperties(systemBarProperties).then(() => { + // console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + // console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err)); + // expect(TRUE_FLAG).assertFail(); + // }) + // } }) /** @@ -967,15 +1084,13 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'begin'); listenerData.on = true; listenerData.typeStr = 'systemBarTintChange'; - ohosWindow.on('systemBarTintChange', (systemBarData) => { + ohosWindow.on('systemBarTintChange', async (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); if (listenerFlag === listenerStatus.pending) { expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - getData(0, loopCount) - - function getData(i, length) { + for (let i = 0; i < arrLength; i++) { let tempData = systemBarData.regionTint[i]; console.log(msgStr + 'i=' + i + ' , ohosWindow.on for=' + JSON.stringify(tempData)); if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { @@ -985,14 +1100,28 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); expect(backgroundIndex === -1).assertTrue(); expect(contentColorIndex === -1).assertTrue(); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + await tempWnd.setSystemBarProperties(systemBarProperties).then(() => { console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err)); expect(TRUE_FLAG).assertFail(); done(); }) } + // await getData(0, loopCount) + // + // function getData(i, length) { + // let tempColor = commonKEYColorArr[i]; + // let systemBarProperties = { + // statusBarColor: tempColor, + // isStatusBarLightIcon: true, + // statusBarContentColor: tempColor, + // navigationBarColor: tempColor, + // isNavigationBarLightIcon: false, + // navigationContentColor: tempColor, + // }; + // tempWnd.setSystemBarProperties(systemBarProperties).then(() => { + // console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + // console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err)); + // expect(TRUE_FLAG).assertFail(); + // done(); + // }) + // } }) /** @@ -1056,25 +1203,49 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'begin'); let loopCount = systemWindowTypeDicArr.length; console.log(msgStr + 'loopCount: ' + loopCount); - getData(0, loopCount) - - async function getData(i, length) { + for (let i = 0; i < loopCount; i++) { let tempType = systemWindowTypeDic[systemWindowTypeDicArr[i]]; let windId = 'createTest1' + i; console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); - let tempWnd = await ohosWindow.create(context, windId, tempType).catch((err) => { + let tempWnd = null + await ohosWindow.create(context, windId, tempType).then( + (data) => { + tempWnd = data; + } + ).catch((err) => { console.log(msgStr + 'ohosWindow.create ' + tempType + 'catched, err: ' + JSON.stringify(err)); unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); }); console.log(msgStr + 'ohosWindow.create ' + tempType + 'finished, wnd: ' + tempWnd); expect(!!tempWnd).assertTrue(); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + // tempWnd = data; + // } + // ).catch((err) => { + // console.log(msgStr + 'ohosWindow.create ' + tempType + 'catched, err: ' + JSON.stringify(err)); + // unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); + // }); + // console.log(msgStr + 'ohosWindow.create ' + tempType + 'finished, wnd: ' + tempWnd); + // expect(!!tempWnd).assertTrue(); + // await tempWnd.destroy(); + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + // createData = data + // expect(!!createData).assertTrue(); + // }).catch((err) => { + // console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); + // unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); + // return; + // }) + // } + // catch (err) { + // console.log(msgStr + 'ohosWindow.create catch err' + JSON.stringify(err)); + // } + // let tempWnd = createData + // console.log(msgStr + 'ohosWindow.create ' + tempType + ' wnd: ' + tempWnd); + // let proData = await tempWnd.getProperties().catch((err) => { + // console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err)); + // unexpectedError(err, caseName, 'tempWnd.getProperties', done); + // console.log(msgStr + 'tempWnd.getProperties err&&err.code' + JSON.stringify(err)); + // }) + // expect(!!proData).assertTrue(); + // expect(proData.type == tempType).assertTrue(); + // await createData.destroy(); + // console.log(msgStr + 'n:' + n); + // if (proData.type == tempType) n++ + // console.log(msgStr + 'n++:' + n); + // console.log(msgStr + 'i:' + i); + // if (i + 1 == loopCount) { + // if (n === loopCount) { + // expect(true).assertTrue(); + // } else { + // expect(true).assertFail(); + // } + // } + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + ohosData = data; + }).catch((err) => { + console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err)); + unexpectedError(err, caseName, 'ohosWindow.create', done); + }) + expect(!!ohosData).assertTrue(); + let ohosDataError = await ohosWindow.create(context, windowId, 1).catch((err) => { + console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err)); + expect(err.code).assertEqual(1001) + done(); + }) + await ohosData.destroy(); + console.log(msgStr + 'ohosWindow.create 1 twice ohosDataError: ' + JSON.stringify(ohosDataError)); + }) + /** * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_001 * @tc.name Test loadContentTest1 * @tc.desc Verify the scenario of loading an existing page @@ -1190,6 +1430,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) }); console.log(msgStr + 'tempWnd.loadContent(pages/second/second) load=' + JSON.stringify(load)); expect(!load).assertTrue(); + await tempWnd.destroy(); done(); }) @@ -1221,6 +1462,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'ohosWindow.createWindow catch err:' + JSON.stringify(err)); } console.log(msgStr + 'tempWnd.loadContent start'); + await tempWnd.destroy(); let errFlag = false; let loadContentData = null; try { @@ -1333,6 +1575,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest1)=' + JSON.stringify(err)); }); expect(!!subWindow).assertTrue(); + await subWindow.destroy(); console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow)); console.log(msgStr + 'windowStage.createSubWindow end !!subWindow=' + !!subWindow); done(); @@ -1386,8 +1629,11 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin '); let mainWnd = null; - let windowData = await ohosWindow.create(context, 'setPrivacyModeTest1', ohosWindow.WindowType.TYPE_SYSTEM_ALERT) - .catch((err) => { + let windowData = null + await ohosWindow.create(context, 'setPrivacyModeTest1', ohosWindow.WindowType.TYPE_SYSTEM_ALERT) + .then((data) => { + windowData = data; + }).catch((err) => { unexpectedError(err, caseName, 'ohosWindow.create', done); }) expect(!!windowData).assertTrue(); @@ -1420,6 +1666,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) }) console.log(msgStr + 'mainWnd.getProperties lastPro:' + JSON.stringify(lastPro.isPrivacyMode)); expect(!lastPro.isPrivacyMode).assertTrue(); + await windowData.destroy(); done(); }) /** @@ -1492,10 +1739,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay current device' + JSON.stringify(currentDeviceDefault)); let currentDeviceDefaultDpi = parseInt(currentDeviceDefault.densityDPI) let dpiItem = [-80, 80, 1000, 160, 0, 320, 188.88, 0, 640, 300, currentDeviceDefaultDpi]; - getData(0, dpiItem.length) - - async function getData(i, length) { - await sleep(1000); + for (let i = 0; i < dpiItem.length; i++) { await screens[0].setDensityDpi(dpiItem[i]).then(async () => { console.log(msgStr + 'screen.setDensityDpi success set DPI ' + dpiItem[i]); let defaultDpi = null; @@ -1508,16 +1752,37 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) let isEqual = Number(defaultDpi.densityDPI) == dpiItem[i] console.log(msgStr + 'same ? ' + isEqual) expect(isEqual).assertTrue() - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { console.log(msgStr + 'screen.setDensityDpi failed set DPI error' + dpiItem[i]); }); } + + // await getData(0, dpiItem.length) + // + // async function getData(i, length) { + // await sleep(1000); + // await screens[0].setDensityDpi(dpiItem[i]).then(async () => { + // console.log(msgStr + 'screen.setDensityDpi success set DPI ' + dpiItem[i]); + // let defaultDpi = null; + // display.getDefaultDisplay().then((data) => { + // defaultDpi = data + // }).catch(err => { + // console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay failed'); + // }); + // console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay' + JSON.stringify(defaultDpi)); + // let isEqual = Number(defaultDpi.densityDPI) == dpiItem[i] + // console.log(msgStr + 'same ? ' + isEqual) + // expect(isEqual).assertTrue() + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + // console.log(msgStr + 'screen.setDensityDpi failed set DPI error' + dpiItem[i]); + // }); + // } console.log(msgStr + 'done '); done(); }) @@ -1539,27 +1804,39 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) 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']; - getData(0, orientationItem.length) - - async function getData(i, length) { - await sleep(1000); + for (let i = 0; i < orientationItem.length; i++) { let orientation = ohosWindow.Orientation[orientationItem[i]] console.log(msgStr + 'i : ' + i + ' ,orientation : ' + orientation); console.log(msgStr + 'i : ' + i + ' ,ohosWindow.Orientation : ' + JSON.stringify(ohosWindow.Orientation)); await mainWin.setPreferredOrientation(orientation).then(() => { console.log(msgStr + 'success set window.setPreferredOrientation : ' + orientation); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { console.log(msgStr + 'window.setPreferredOrientation failed set error:' + orientation); }); } + // await getData(0, orientationItem.length) + // + // async function getData(i, length) { + // await sleep(1000); + // let orientation = ohosWindow.Orientation[orientationItem[i]] + // console.log(msgStr + 'i : ' + i + ' ,orientation : ' + orientation); + // console.log(msgStr + 'i : ' + i + ' ,ohosWindow.Orientation : ' + JSON.stringify(ohosWindow.Orientation)); + // await mainWin.setPreferredOrientation(orientation).then(() => { + // console.log(msgStr + 'success set window.setPreferredOrientation : ' + orientation); + // if (++i < length) { + // getData(i, length) + // console.log(msgStr + 'jixuzhixing i: ' + i); + // } else { + // console.log(msgStr + 'i++ { + // console.log(msgStr + 'window.setPreferredOrientation failed set error:' + orientation); + // }); + // } }) /** * @tc.number SUB_WINDOW_SETFORBIDSPLITMOVE_JSAPI_001 @@ -1687,6 +1964,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) context.completeTransition(true) console.info(msgStr + 'complete transition end'); } + await tempWnd.destroy(); done(); }) /** @@ -1738,10 +2016,12 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) await tempWnd.showWithAnimation().then((data) => { console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(data)); + tempWnd.destroy(); done(); }).catch((err) => { unexpectedError(err, caseName, 'Failed to show the window with animation', done); }) + }) /** * @tc.number SUB_WINDOW_HIDEWITHANIMATION_JSAPI_001 @@ -1767,7 +2047,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); }); } - catch(err) { + catch (err) { console.log(msgStr + 'ohosWindow.create catch err:' + JSON.stringify(err)); } let findWnd = null; @@ -1781,6 +2061,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) let promise = findWnd.hideWithAnimation(); promise.then((data) => { console.info('Succeeded in hiding the window with animation. Data: ' + JSON.stringify(data)); + tempWnd.destroy(); done(); }).catch((err) => { console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); 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 6c8d6bf105e5ea9fba3d2520a8da2e35536cc48d..1aa699202d8ce193f9efd368f247c823e9f19711 100644 --- a/graphic/windowStage/entry/src/main/ets/test/windowRefactorInterface.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/windowRefactorInterface.test.ets @@ -71,12 +71,15 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit afterAll(function () { }) - function sleep(time) { - return new Promise(resolve => { - setTimeout(() => { + async function sleep(time) { + let timeoutId= null; + let promise = new Promise(resolve => { + timeoutId = setTimeout(() => { resolve('sleep finished'); }, time); }) + let result = await promise; + clearTimeout(timeoutId) } /** @@ -102,9 +105,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) } let arrLength = systemBarData.regionTint.length; - getData(0, arrLength) - - function getData(i, length) { + console.log('setWindowSystemBarPropertiesTest1 arrLength is: '+systemBarData.regionTint.length) + for(let i=0;i { - console.info('setWindowSystemBarPropertiesTest1 success'); + await mainWsync.setWindowSystemBarProperties(systemBarProperties).then(() => { + console.info('setWindowSystemBarPropertiesTest1 success step:'+i); expect(TRUE_FLAG).assertTrue(); - if (++i < length) { - getData(i, length) - console.log(msgStr+'jixuzhixing i: ' + i); - } else { - console.log(msgStr+'i++ { console.info('setWindowSystemBarPropertiesTest1 error : ' + JSON.stringify(err)); expect().assertFail() @@ -258,10 +252,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit }); await sleep(1000); listenerFlag = listenerStatus.pending; - let loopCount = commonNUMBERColorArr.length; - getData(0, loopCount) - - function getData(i, length) { + for(let i =0;i { - console.info('setWindowSystemBarPropertiesTest2 success'); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + console.info('setWindowSystemBarPropertiesTest2 success step:'+i); expect(TRUE_FLAG).assertTrue(); - done(); + if(i == commonNUMBERColorArr.length-1){ + console.info('setWindowSystemBarPropertiesTest2 finished step:'+i); + done(); + } }).catch(err => { console.info('setWindowSystemBarPropertiesTest2 error : ' + JSON.stringify(err)); expect().assertFail() @@ -343,10 +332,8 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit }); await sleep(1000); listenerFlag = listenerStatus.pending; - let loopCount = commonKEYColorArr.length; - getData(0, loopCount) - - function getData(i, length) { + for(let i=0;i { - console.info('setWindowSystemBarPropertiesTest3 success'); - if (++i < length) { - getData(i, length) - console.log(msgStr + 'jixuzhixing i: ' + i); - } else { - console.log(msgStr + 'i++ { + console.info('setWindowSystemBarPropertiesTest3 success step:'+i); expect(TRUE_FLAG).assertTrue(); - done(); + if(i == commonKEYColorArr.length-1){ + console.info('setWindowSystemBarPropertiesTest3 finished step:'+i); + done(); + } }).catch(err => { console.info('setWindowSystemBarPropertiesTest3 error : ' + JSON.stringify(err)); expect().assertFail() @@ -428,25 +412,26 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit 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 => { + let wnd; + wnd = await ohosWindow.createWindow(config).catch(err => { console.error('Failed to create the Windowshow1. Cause:' + JSON.stringify(err)); expect().assertFail(); done(); }) + expect(wnd != null).assertTrue(); + let isWindowShowing = wnd.isWindowShowing(); + expect(!isWindowShowing).assertTrue(); + await wnd.showWindow().then(async () => { + let isWindowShowing2 = wnd.isWindowShowing(); + expect(isWindowShowing2).assertTrue(); + await wnd.destroyWindow(); + done(); + }).catch(async (err) => { + console.error('Failed to show window1. Cause:' + JSON.stringify(err)); + expect().assertFail(); + await wnd.destroyWindow(); + done(); + }) }) /** * @tc.number SUB_WINDOW_setUIContent_JSAPI_001 @@ -457,25 +442,27 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit let config = { name: "alertWindow", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context }; + let win; + let promise; 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) => { + promise = ohosWindow.createWindow(config); + win = await promise.catch((err) => { console.error('Failed to create the Window1. Cause:' + JSON.stringify(err)); expect().assertFail(); done(); }); + expect(win != null); + await win.setUIContent('pages/second/second').then(async () => { + console.info('setUIContent1 . Cause: success'); + expect(TRUE_FLAG).assertTrue(); + await win.destroyWindow(); + done(); + }).catch(async (err) => { + console.error('Failed to setUIContent . Cause:' + JSON.stringify(err)); + expect().assertFail(); + await win.destroyWindow(); + done(); + }); } catch (exception) { console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); expect().assertFail(); @@ -491,47 +478,58 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit */ it('setUIContentTestCallBack1', 0, async function (done) { let windowClass = null; + let msgStr='setUIContentTestCallBack1' let config = { name: "alertWindowcallBack", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context }; - try { - let promise = ohosWindow.createWindow(config); - promise.then(win => { - console.info('Succeededcall in creating the window2. Data:' + JSON.stringify(win)); - windowClass = win; - expect(win != null).assertTrue(); - // 设置setUIContent + function createFirstWindow() { + return new Promise((resolve, reject) => { try { - windowClass.setUIContent('pages/second/second', (err) => { - if (err.code) { - console.error('Failed to load the content callback. Cause:' + JSON.stringify(err)); - expect().assertFail(); - done(); - } else { - console.info('Succeeded in loading the content.'); - expect(TRUE_FLAG).assertTrue(); + ohosWindow.createWindow(config, (create_err, create_data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(create_data)); + if (create_err && create_err.code) { + try { + expect().assertFail(); + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) + } done(); + reject(null) } - }); + resolve(create_data) + }) } catch (exception) { - console.error('Failed callback to load the content. Cause:' + JSON.stringify(exception)); - expect().assertFail(); - done(); + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); } ; + }) + } + let winData; + winData = await createFirstWindow(); + expect(!!winData).assertTrue(); + try { + winData.setUIContent('pages/second/second', async (err) => { + try{ + if (err.code) { + console.error('Failed to load the content callback. Cause:' + JSON.stringify(err)); + expect().assertFail(); - }).catch((err) => { - console.error('Failedcaa to create the inner Window2. Cause:' + JSON.stringify(err)); - expect().assertFail(); + } else { + console.info('Succeeded in loading the content.'); + expect(TRUE_FLAG).assertTrue(); + } + }catch(err){ + console.log('setUIContentTestCallBack1 assert result catch' + JSON.stringify(err)); + } done(); + await winData.destroyWindow(); }); } catch (exception) { - console.error('Failed to create the window2. Cause: ' + JSON.stringify(exception)); + console.error('Failed callback to load the content. Cause:' + JSON.stringify(exception)); expect().assertFail(); + await winData.destroyWindow(); done(); - } - ; - + }; }) /** @@ -544,43 +542,38 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit let config = { name: "alertWindow2", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context }; + let win; try { - let promise = ohosWindow.createWindow(config); - promise.then(win => { - console.info('Succeeded in creating the window2. Data:' + JSON.stringify(win)); - windowClass = win; - expect(win != null).assertTrue(); - // 设置setUIContent - try { - let promise = windowClass.setUIContent(null); - promise.then(() => { - console.info('Succeeded in loading the content.'); - expect().assertFail(); - done(); - }).catch((err) => { - console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); - expect(err.code).assertEqual(401); - done() - }); - } catch (exception) { - console.error('Failed to load the content. exception: ' + JSON.stringify(exception)); - expect(exception.code).assertEqual(401); - done() - } - ; - - }).catch((err) => { + win = await ohosWindow.createWindow(config).catch((err) => { console.error('Failed to create the inner Window2. Cause:' + JSON.stringify(err)); expect().assertFail(); done(); }); + expect(win != null).assertTrue(); + try { + await win.setUIContent(null).then(async () => { + console.info('Succeeded in loading the content.'); + expect().assertFail(); + await win.destroyWindow(); + done(); + }).catch(async (err) => { + console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); + expect(err.code).assertEqual(401); + await win.destroyWindow(); + done() + }); + } catch (exception) { + console.error('Failed to load the content. exception: ' + JSON.stringify(exception)); + expect(exception.code).assertEqual(401); + await win.destroyWindow(); + done() + } + ; } catch (exception) { console.error('Failed to create the window2. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - } - ; - + }; }) /** @@ -592,26 +585,26 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit let config = { name: "alertWindow3", windowType: ohosWindow.WindowType.TYPE_SYSTEM_ALERT, ctx: context }; + let win; try { - let promise = ohosWindow.createWindow(config); - promise.then(win => { - console.info('Succeeded in creating the window3. Data:' + JSON.stringify(win)); - expect(win != null).assertTrue(); - // 设置setUIContent - win.setUIContent('pages/second/he').then(() => { - console.info('setUIContent3 . Cause: success'); - expect(TRUE_FLAG).assertTrue(); - done(); - }).catch(err => { - console.error('Failed to setUIContent3 . Cause:' + JSON.stringify(err)); - expect().assertFail(); - done(); - }); - }).catch((err) => { + win = await ohosWindow.createWindow(config).catch((err) => { console.error('Failed to create the inner Window3. Cause:' + JSON.stringify(err)); expect().assertFail(); done(); }); + expect(win != null).assertTrue(); + // 设置setUIContent + await win.setUIContent('pages/second/he').then(async () => { + console.info('setUIContent3 . Cause: success'); + expect(TRUE_FLAG).assertTrue(); + await win.destroyWindow(); + done(); + }).catch(async (err) => { + console.error('Failed to setUIContent3 . Cause:' + JSON.stringify(err)); + expect().assertFail(); + await win.destroyWindow(); + done(); + }); } catch (exception) { console.error('Failed to create the window3. Cause: ' + JSON.stringify(exception)); expect().assertFail(); @@ -629,25 +622,22 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowColorSpace1 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowColorSpace(ohosWindow.ColorSpace.WIDE_GAMUT).then(() => { - console.info('windowTest SetWindowColorSpaceTest1 setColorSpace WIDE_GAMUT'); - let windowColorSpace = wnd.getWindowColorSpace(); - expect(windowColorSpace == ohosWindow.ColorSpace.WIDE_GAMUT).assertTrue(); - console.info('windowTest SetWindowColorSpaceTest1 setColorSpace WIDE_GAMUT success'); - wnd.isWindowSupportWideGamut().then(data => { - expect(data).assertTrue(); - done(); - }, (err) => { - console.info('windowTest SetColorSpaceTest1 wnd.isWindowSupportWideGamut failed, err :' + JSON.stringify(err)); - expect().assertFail(); - done(); - }) - }, (err) => { + await wnd.setWindowColorSpace(ohosWindow.ColorSpace.WIDE_GAMUT).catch((err) => { console.info('windowTest SetWindowColorSpaceTest1 wnd.setColorSpace failed, err :' + JSON.stringify(err)); expect().assertFail(); done(); }) - + let windowColorSpace = wnd.getWindowColorSpace(); + expect(windowColorSpace == ohosWindow.ColorSpace.WIDE_GAMUT).assertTrue(); + console.info('windowTest SetWindowColorSpaceTest1 setColorSpace WIDE_GAMUT success'); + await wnd.isWindowSupportWideGamut().then(data => { + expect(data).assertTrue(); + done(); + }, (err) => { + console.info('windowTest SetColorSpaceTest1 wnd.isWindowSupportWideGamut failed, err :' + JSON.stringify(err)); + expect().assertFail(); + done(); + }) }) /** @@ -661,7 +651,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit expect(wnd != null).assertTrue(); try { let promise = wnd.setWindowColorSpace(-5); - promise.then(() => { + await promise.then(() => { console.info('Succeeded in setting window2 colorspace.'); expect().assertFail(); done(); @@ -687,25 +677,47 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit it('setColorSpace_Test_003', 0, async function (done) { console.info('windowTest SetWindowColorSpaceTest3 begin'); let wnd = windowStage.getMainWindowSync(); + let msgStr = 'setColorSpace_Test_003' expect(wnd != null).assertTrue(); - wnd.setColorSpace(ohosWindow.ColorSpace.WIDE_GAMUT, (err) => { - if (err.code != 0) { - console.info('windowTest SetWindowColorSpaceTest3 setColorSpace fail' + JSON.stringify(err)); - expect().assertFail(); - done(); - } else { - let windowColorSpace = wnd.getWindowColorSpace(); - 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)); - expect().assertFail(); - done(); - } else { - expect(data).assertTrue(); - done(); - } - }) + function setColorSpaceFun() { + return new Promise((resolve, reject) => { + try { + wnd.setColorSpace(ohosWindow.ColorSpace.WIDE_GAMUT, (err,data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(data)); + if (err && err.code) { + try { + expect().assertFail(); + } catch (error) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + done(); + reject(null) + } + resolve(true) + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + } + ; + }) + } + let isResultTrue; + isResultTrue = await setColorSpaceFun(); + expect(isResultTrue).assertTrue(); + let windowColorSpace = wnd.getWindowColorSpace(); + expect(windowColorSpace == ohosWindow.ColorSpace.WIDE_GAMUT).assertTrue(); + wnd.isWindowSupportWideGamut((err, data) => { + try{ + if (err.code != 0) { + console.log('windowTest SetWindowColorSpaceTest3 getColorSpace callback fail' + JSON.stringify(err)); + expect().assertFail(); + done(); + } else { + expect(data).assertTrue(); + done(); + } + }catch(exception){ + console.log('assertFail catch' + JSON.stringify(exception)); } }) }) @@ -737,10 +749,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the background1 color. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - } - ; - - + }; }) /** @@ -770,10 +779,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the background2 color. Cause: ' + JSON.stringify(exception)); expect().assertFail(); done(); - } - ; - - + }; }) /** @@ -854,9 +860,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.error('Failed to set the background5 color. Cause: ' + JSON.stringify(exception)); expect(exception.code).assertEqual(401); done() - } - ; - + }; }) /** @@ -876,8 +880,7 @@ 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() - } - ; + }; }) /** @@ -889,34 +892,30 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowBrightnessTest1 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowBrightness(0).then(() => { - console.info('windowTest setWindowBrightnessTest1 setBrightness(0) success '); - let data = wnd.getWindowProperties(); - expect(data.brightness).assertEqual(0); - wnd.setWindowBrightness(0.5).then(() => { - console.info('windowTest setWindowBrightnessTest1 setBrightness(0.5) success '); - let data1 = wnd.getWindowProperties(); - expect(data1.brightness).assertEqual(0.5); - wnd.setWindowBrightness(1).then(() => { - console.info('windowTest setWindowBrightnessTest1 setBrightness(1) success '); - let data2 = wnd.getWindowProperties(); - expect(data2.brightness).assertEqual(1); - done(); - }, (err) => { - console.log('windowTest setWindwoBrightnessTest1 setBrightness failed: err' + JSON.stringify(err)); - expect().assertFail(); - done(); - }) - }, (err) => { - console.log('windowTest setBrightnessTest1 setWindowBrightness failed: err' + JSON.stringify(err)); - expect().assertFail(); - done(); - }) - }, (err) => { + await wnd.setWindowBrightness(0).catch((err) => { console.info('windowTest setWindowBrightnessTest1 setBrightness failed: err' + JSON.stringify(err)); expect().assertFail(); done(); }) + let data = wnd.getWindowProperties(); + expect(data.brightness).assertEqual(0); + await wnd.setWindowBrightness(0.5).catch((err) => { + console.log('windowTest setBrightnessTest1 setWindowBrightness failed: err' + JSON.stringify(err)); + expect().assertFail(); + done(); + }) + let data1 = wnd.getWindowProperties(); + expect(data1.brightness).assertEqual(0.5); + await wnd.setWindowBrightness(1).then(() => { + console.info('windowTest setWindowBrightnessTest1 setBrightness(1) success '); + let data2 = wnd.getWindowProperties(); + expect(data2.brightness).assertEqual(1); + done(); + }, (err) => { + console.log('windowTest setWindwoBrightnessTest1 setBrightness failed: err' + JSON.stringify(err)); + expect().assertFail(); + done(); + }) }) /** @@ -928,7 +927,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowBrightnessTest2 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowBrightness(0.564789).then(() => { + await wnd.setWindowBrightness(0.564789).then(() => { console.log('windowTest setBrightnessTest2 setBrightness(0.564789) success '); expect(TRUE_FLAG).assertTrue(); done(); @@ -952,7 +951,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit let brightness = Number.MAX_VALUE; try { let promise = wnd.setWindowBrightness(brightness); - promise.then(() => { + await promise.then(() => { console.info('Succeeded3 in setting the brightness.'); expect().assertFail(); done(); @@ -979,7 +978,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowBrightnessTest4 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowBrightness(Number.MIN_VALUE).then(() => { + await wnd.setWindowBrightness(Number.MIN_VALUE).then(() => { console.info('windowTest setWindowBrightnessTest3 setBrightness(Number.MAX_VALUE) success '); expect(TRUE_FLAG).assertTrue(); done(); @@ -1002,7 +1001,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit let brightness = 1.1; try { let promise = wnd.setWindowBrightness(brightness); - promise.then(() => { + await promise.then(() => { console.info('Succeeded5 in setting the brightness.'); expect().assertFail(); done(); @@ -1020,7 +1019,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit try { let promise = wnd.setWindowBrightness(-0.5); - promise.then(() => { + await promise.then(() => { console.info('Succeeded55 in setting the brightness.'); expect().assertFail(); done(); @@ -1210,8 +1209,35 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit it('setWindowFocusableCallBack_Test_001', 0, async function (done) { console.info('windowTest setFocusableTest1 begin'); let wnd = windowStage.getMainWindowSync(); + let msgStr ='setWindowFocusableCallBack_Test_001' expect(wnd != null).assertTrue(); - wnd.setWindowFocusable(false, (err, data) => { + function setWindowFocusableFun(){ + return new Promise((resolve, reject) => { + try { + wnd.setWindowFocusable(false, (err, data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(data)); + if (err && err.code) { + try { + expect().assertFail(); + } catch (error) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(error)}`) + } + done(); + reject(null) + } + resolve(true) + }) + } catch (exception) { + console.error(msgStr + 'Failed to create the window. Cause: ' + JSON.stringify(exception)); + }; + }) + } + let isResultTrue; + isResultTrue = await setWindowFocusableFun() + expect(isResultTrue).assertTrue(); + let data = wnd.getWindowProperties(); + expect(!data.focusable).assertTrue(); + wnd.setWindowFocusable(true, (err, data) => { if (err.code) { console.error('Failed to set the window to be setFocusable. Cause:' + JSON.stringify(err)); try { @@ -1221,31 +1247,13 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit } done(); } else { - let data = wnd.getWindowProperties(); + let data2 = wnd.getWindowProperties(); try { - expect(!data.focusable).assertTrue(); + expect(data2.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)); - try { - expect().assertFail(); - } catch (error) { - console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - let data2 = wnd.getWindowProperties(); - try { - expect(data2.focusable).assertTrue(); - } catch (error) { - console.info(`wnd.setWindowBrightness catch error: ${JSON.stringify(error)}`) - } - done(); - } - }) + done(); } }) }) @@ -1259,24 +1267,24 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowFocusableTest1 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowFocusable(false).then(() => { + await wnd.setWindowFocusable(false).then(async () => { console.info('windowTest setFocusableTest1 setFocusable(false) success '); let data2 = wnd.getWindowProperties(); expect(!data2.focusable).assertTrue(); - wnd.setWindowFocusable(true).then(() => { - console.info('windowTest setFocusableTest1 setFocusable(true) success '); - expect(TRUE_FLAG).assertTrue(); - done(); - }, err => { - 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(); }) + await wnd.setWindowFocusable(true).then(() => { + console.info('windowTest setFocusableTest1 setFocusable(true) success '); + expect(TRUE_FLAG).assertTrue(); + done(); + }, err => { + console.info('windowTest setFocusableTest1 setFocusable failed: err' + JSON.stringify(err)); + expect().assertFail(); + done(); + }) }) /** @@ -1290,25 +1298,25 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit expect(wnd != null).assertTrue(); let data = wnd.getWindowProperties(); expect(data.touchable).assertTrue(); - wnd.setWindowTouchable(false).then(() => { + await wnd.setWindowTouchable(false).then(async() => { console.info('windowTest setTouchableTest1 setTouchable(false) success '); let data2 = wnd.getWindowProperties(); expect(!data2.touchable).assertTrue(); - wnd.setWindowTouchable(true).then(() => { - console.info('windowTest setTouchableTest1 setTouchable(true) success '); - let data3 = wnd.getWindowProperties(); - expect(data3.touchable).assertTrue(); - done(); - }, (err) => { - console.info('windowTest setTouchableTest1 setTouchable failed: err' + JSON.stringify(err)); - expect().assertFail(); - done(); - }) }, (err) => { console.log('windowTest setTouchableTest1 setTouchable failed: err' + JSON.stringify(err)); expect().assertFail(); done(); }) + await wnd.setWindowTouchable(true).then(() => { + console.info('windowTest setTouchableTest1 setTouchable(true) success '); + let data3 = wnd.getWindowProperties(); + expect(data3.touchable).assertTrue(); + done(); + }, (err) => { + console.info('windowTest setTouchableTest1 setTouchable failed: err' + JSON.stringify(err)); + expect().assertFail(); + done(); + }) }) /** @@ -1317,35 +1325,48 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit * @tc.desc Set whether the window can be touched or not */ it('setWindowTouchableCallBack_Test_001', 0, async function (done) { + let msgStr ='setWindowTouchableCallBack_Test_001' let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowTouchable(false, (err, data) => { - if (err.code) { - console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); - expect().assertFail(); - done(); - } else { - let data = wnd.getWindowProperties(); - expect(!data.touchable).assertTrue(); - wnd.setWindowTouchable(true, (err, data) => { - if (err.code) { - console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); + function setWindowTouchableFun(){ + return new Promise((resolve, reject) => { + wnd.setWindowTouchable(false, (err, data) => { + console.log(msgStr + 'ohosWindow.createWindow data' + JSON.stringify(data)); + if (err && err.code) { try { expect().assertFail(); - } catch (error) { - console.info(`wnd.setWindowTouchable catch error: ${JSON.stringify(error)}`) - } - done(); - } else { - let data2 = wnd.getWindowProperties(); - try { - expect(data2.touchable).assertTrue(); - } catch (error) { - console.info(`wnd.setWindowTouchable catch error: ${JSON.stringify(error)}`) + } catch (err) { + console.info(msgStr + `ohosWindow.createWindow catch error: ${JSON.stringify(err)}`) } done(); + reject(null) } + resolve(true) }) + }) + } + let isResultTrue; + isResultTrue=await setWindowTouchableFun() + expect(isResultTrue).assertTrue(); + let data = wnd.getWindowProperties(); + expect(!data.touchable).assertTrue(); + wnd.setWindowTouchable(true, (err, data) => { + if (err.code) { + console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); + try { + expect().assertFail(); + } catch (error) { + console.info(`wnd.setWindowTouchable catch error: ${JSON.stringify(error)}`) + } + done(); + } else { + let data2 = wnd.getWindowProperties(); + try { + expect(data2.touchable).assertTrue(); + } catch (error) { + console.info(`wnd.setWindowTouchable catch error: ${JSON.stringify(error)}`) + } + done(); } }) }) @@ -1359,9 +1380,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowKeepScreenOnTest2 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - let data = wnd.getWindowProperties(); - expect(!data.isKeepScreenOn).assertTrue(); - wnd.setWindowKeepScreenOn(true).then(() => { +// let data = wnd.getWindowProperties(); +// expect(!data.isKeepScreenOn).assertTrue(); + await wnd.setWindowKeepScreenOn(true).then(() => { console.info('windowTest setKeepScreenOnTest2 setKeepScreenOn(false) success '); let data2 = wnd.getWindowProperties(); expect(data2.isKeepScreenOn).assertTrue(); @@ -1382,7 +1403,7 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowKeepScreenOnTest1 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowKeepScreenOn(false).then(() => { + await wnd.setWindowKeepScreenOn(false).then(() => { console.info('windowTest setKeepScreenOnTest1 setKeepScreenOn(false) success '); let data2 = wnd.getWindowProperties(); expect(!data2.isKeepScreenOn).assertTrue(); @@ -1434,9 +1455,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowPrivacyMode begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - let data = wnd.getWindowProperties(); - expect(!data.isPrivacyMode).assertTrue(); - wnd.setWindowPrivacyMode(false).then(() => { +// let data = wnd.getWindowProperties(); +// expect(!data.isPrivacyMode).assertTrue(); + await wnd.setWindowPrivacyMode(false).then(() => { console.info('windowTest setWindowPrivacyMode1 success '); let data2 = wnd.getWindowProperties(); expect(!data2.isPrivacyMode).assertTrue(); @@ -1457,9 +1478,9 @@ export default function windowRefactorInterfaceTest(context, windowStage, abilit console.info('windowTest setWindowPrivacyMode2 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - let data = wnd.getWindowProperties(); - expect(!data.isPrivacyMode).assertTrue(); - wnd.setWindowPrivacyMode(true).then(() => { +// let data = wnd.getWindowProperties(); +// expect(!data.isPrivacyMode).assertTrue(); + await wnd.setWindowPrivacyMode(true).then(() => { console.info('windowTest setWindowPrivacyMode2 success '); let data2 = wnd.getWindowProperties(); expect(data2.isPrivacyMode).assertTrue();