From 0044ead92f4b32ac7d44eee01da775133c276e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E=E5=8D=8E=E5=B0=8F=E4=BB=99=E5=A5=B3?= Date: Wed, 1 Feb 2023 17:04:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96callback=E5=92=8Cpromise?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 华华小仙女 --- .../entry/src/main/ets/test/List.test.ets | 6 +- .../src/main/ets/test/windowCallback.test.ets | 440 +++++++---- .../src/main/ets/test/windowPromise.test.ets | 717 ++++++++++++------ 3 files changed, 762 insertions(+), 401 deletions(-) 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 5fcf10403..60595543d 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,9 @@ 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) - windowRefactorInterfaceTest(globalThis.abilityContext,globalThis.windowStage,globalThis.abilityStorage) - displayAndWindowRefactorInterfaceTest(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/windowCallback.test.ets b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets index a79bef775..86c5702a8 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)}`) } @@ -137,10 +141,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) listenerData.typeStr = 'systemBarTintChange'; function ohosWindowOn() { - return new Promise(function (resolve, reject) { +// return new Promise(function (resolve, reject) { ohosWindow.on('systemBarTintChange', systembartintstate => { console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); - if (flagStatus || flagNav) { + 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(); @@ -148,10 +155,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`ohosWindow.on ${JSON.stringify(error)}`) } console.log(msgStr + 'flagStatus || flagNav' + msgStr + 'ohosWindow.on systemBarTintChange regionTint:' + JSON.stringify(systembartintstate.regionTint)); - done(); + done(); } +// resolve(systembartintstate); }) - }) +// }) } let mainWnd = null; @@ -166,6 +174,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(data, caseName, 'windowStage.getMainWindow', done); } try { + mainWnd = data; expect(!!data).assertTrue(); } catch (error) { console.info(`ohosWindow.on ${JSON.stringify(error)}`) @@ -184,7 +193,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) if (err && err.code) { unexpectedError(data, caseName, 'mainWnd.show', done); } - expect(!data).assertTrue(); + try{ + expect(!data).assertTrue(); + }catch(err){ + console.info(`mainWnd.show err: ${JSON.stringify(err)}`) + } console.log(msgStr + 'mainWnd.show success'); resolve(data) }) @@ -211,6 +224,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } 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)); @@ -243,33 +257,39 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`ohosWindow.on ${JSON.stringify(error)}`) } resolve(data) +// done(); }) }) } - 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 setSystemBarEnableNavigation() - }) - .then(function (params) { - console.log(msgStr + 'setSystemBarEnableStatus then: ' + JSON.stringify(params)) - return setSystemBarEnableStatus() - }) - .then(function (params) { - console.log(msgStr + 'ohosWindowOn then: ' + JSON.stringify(params)) - return ohosWindowOn() - }) - console.log(msgStr + 'finished!!'); + 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 @@ -427,6 +447,8 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.log(msgStr + 'begin'); let mainWnd = null; console.log(msgStr + 'mainWnd = null'); + listenerData.on = true; + listenerData.typeStr = 'systemBarTintChange'; function getMainWindow() { return new Promise(function (resolve, reject) { @@ -840,7 +862,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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'; @@ -849,7 +871,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) return new Promise(function (resolve, reject) { ohosWindow.on('systemBarTintChange', (systemBarData) => { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { + if (listenerFlag) { try { expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); @@ -857,9 +879,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) } 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!'); @@ -872,14 +892,31 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } 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++ { console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); - listenerFlag = listenerStatus.finished; + listenerFlag = false; done(); }, 10000) }) @@ -969,9 +1006,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) function setSystemBarProperties() { return new Promise(function (resolve, reject) { let loopCount = commonRGBColorArr.length - getData(0, loopCount) - - function getData(i, length) { + for (let i = 0; i < loopCount; i++) { let tempColor = commonRGBColorArr[i]; let systemBarProperties = { statusBarColor: tempColor, @@ -988,15 +1023,37 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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 + '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 + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { + if (listenerFlag) { try { expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); @@ -1194,7 +1251,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`tempWnd.setSystemBatEnable catch error: ${JSON.stringify(error)}`) } console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); - listenerFlag = listenerStatus.pending; + listenerFlag = true; resolve(data) }) }) @@ -1203,9 +1260,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) function setSystemBarProperties() { return new Promise(function (resolve, reject) { let loopCount = commonNUMBERColorArr.length - getData(0, loopCount) - - function getData(i, length) { + for (let i = 0; i < loopCount; i++) { console.log(msgStr + 'tempWnd.setSystemBarEnable i:' + i); let tempColor = commonNUMBERColorArr[i]; let systemBarProperties = { @@ -1226,15 +1281,41 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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++ { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); - if (listenerFlag === listenerStatus.pending) { + if (listenerFlag) { try { expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); @@ -1287,9 +1368,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) } 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!'); @@ -1302,14 +1381,31 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } 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) { @@ -1384,7 +1479,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) } console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); - listenerFlag = listenerStatus.pending; + listenerFlag = true; resolve(data) }) }) @@ -1393,9 +1488,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) function setSystemBarProperties() { return new Promise(function (resolve, reject) { let loopCount = commonRGBColorArr.length - getData(0, loopCount) - - function getData(i, length) { + for (let i = 0; i < loopCount; i++) { let tempColor = commonKEYColorArr[i]; let systemBarProperties = { statusBarColor: tempColor, @@ -1414,21 +1507,47 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } 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++ { console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); - listenerFlag = listenerStatus.finished; + listenerFlag = false; done(); }, 10000) }) @@ -1460,9 +1579,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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'); @@ -1476,12 +1593,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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++ { @@ -1835,6 +1948,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) unexpectedError(err, caseName, 'tempWnd.show', done); } tempWnd = data + newWindowObj = data console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); try { expect(!!tempWnd).assertTrue(); @@ -1884,8 +1998,8 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) return new Promise(function (resolve, reject) { tempWnd.on('systemAvoidAreaChange', avoidAreaData => { console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, avoidAreaData : ' + JSON.stringify(avoidAreaData)); - if (listenerOnFlag === listenerStatus.pending) { - listenerOnFlag = listenerStatus.finished; + if (listenerOnFlag === true) { + listenerOnFlag = false; try { expect(!!avoidAreaData).assertTrue(); } catch (error) { @@ -1893,7 +2007,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } } resolve(avoidAreaData) - done(); }) }) } @@ -1910,8 +2023,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) } console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success'); - listenerOnFlag = listenerStatus.pending; - + listenerOnFlag = true; resolve(data) }) }) @@ -1924,9 +2036,10 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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(); }) }) } @@ -1992,8 +2105,8 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) } -// function setWindowType(tempType) { - function setWindowType(i) { + // 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'); @@ -2067,24 +2180,24 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) } catch (err) { console.log(msgStr + 'tempWnd.getProperties catch err: ' + JSON.stringify(err)); } -// resolve(dataProper.type) + // 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(); -// } -// } -// + // 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) => { @@ -2132,13 +2245,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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 { + expect(true).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } resolve(data) done(); @@ -2259,13 +2372,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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 { + expect(true).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } resolve(data) done(); @@ -2461,13 +2574,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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 { + expect(true).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } resolve(data) done(); @@ -2588,13 +2701,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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 { + expect(true).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } resolve(data) done(); @@ -2841,13 +2954,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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 { + expect(true).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } resolve(data) done(); @@ -3131,13 +3244,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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 { + expect(true).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } resolve(data) done(); @@ -3372,13 +3485,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) 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 { + expect(true).assertTrue(); } catch (error) { console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } + } else { + unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } resolve(data) done(); @@ -3450,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]; - await 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]); @@ -3471,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); @@ -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); @@ -271,68 +277,74 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) * @tc.name Test listenerTest4 * @tc.desc Verify whether the window size change monitoring can be closed normally. */ -// it('listenerTest4', 0, async function (done) { -// let caseName = 'listenerTest4'; -// let msgStr = 'jsunittest ' + caseName + ' '; -// let wndId = 'listenerTest4'; -// let baseType = 2; -// let changedModel = 102; -// let listenerOffFlag = listenerStatus.ready; -// console.log(msgStr + 'begin'); -// let createWindowObj = { -// name: wndId, windowType: baseType, ctx: context -// } -// console.log(msgStr + 'ohosWindow.create createWindowObj:' + JSON.stringify(createWindowObj)); -// let tempWnd = null; -// try { -// await ohosWindow.create(context, wndId, baseType).then((data) => { -// console.log(msgStr + 'ohosWindow.create data:' + JSON.stringify(data)); -// tempWnd = 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(); -// tempWnd.destroy(); -// done(); -// } -// }) -// }).catch((err) => { -// unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); -// }); -// } catch (err) { -// } -// await tempWnd.show().catch((err) => { -// unexpectedError(err, caseName, 'tempWnd.show', done); -// }); -// console.log(msgStr + 'tempWnd.show success'); -// await tempWnd.setWindowMode(changedModel).catch((err) => { -// unexpectedError(err, caseName, 'tempWnd.setWindowMode ' + changedModel, done); -// }); -// console.log(msgStr + 'tempWnd.setWindowMode ' + changedModel + ' success'); -// await tempWnd.resetSize(100, 100).then(()=>{ -// listenerOffFlag = listenerStatus.pending; -// }).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'); -// await sleep(1000); -// tempWnd.off('windowSizeChange'); -// console.log(msgStr + 'tempWnd.off windowSizeChange finished'); -// 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)); -// }); -// console.log(msgStr + 'tempWnd.resetSize(200, 200) success'); -// }) + it('listenerTest4', 0, async function (done) { + let caseName = 'listenerTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let wndId = 'listenerTest4'; + let baseType = 2; + let changedModel = 102; + let listenerOffFlag = false; + listenerData.on = true; + listenerData.typeStr = 'windowSizeChange'; + console.log(msgStr + 'begin'); + let createWindowObj = { + name: wndId, windowType: baseType, ctx: context + } + console.log(msgStr + 'ohosWindow.create createWindowObj:' + JSON.stringify(createWindowObj)); + let tempWnd = null; + try { + 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(); + }).catch((err) => { + unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); + }); + } catch (err) { + } + + await tempWnd.show().catch((err) => { + unexpectedError(err, caseName, 'tempWnd.show', done); + }); + console.log(msgStr + 'tempWnd.show success'); + await tempWnd.setWindowMode(changedModel).catch((err) => { + unexpectedError(err, caseName, 'tempWnd.setWindowMode ' + changedModel, done); + }); + console.log(msgStr + 'tempWnd.setWindowMode ' + changedModel + ' success'); + 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'); + await sleep(1000); + await tempWnd.off('windowSizeChange'); + console.log(msgStr + 'tempWnd.off windowSizeChange finished'); + 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'); + }) /** * @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_001 * @tc.name Test setWindowTypeTest1 @@ -411,9 +423,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'ohosWindow.create !!tempWnd' + !!tempWnd); if (!!tempWnd) { expect(!!tempWnd).assertTrue(); - // let windowTypeData = null; await tempWnd.setWindowType(changedWndType).then(() => { - // windowTypeData = data; }).catch((err) => { console.log(msgStr + 'tempWnd.setWindowType err.code: ' + JSON.stringify(err.code)); tempWnd.destroy(); @@ -422,15 +432,8 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) if (flag) { expect(true).assertTrue(); } - // expect(flag).assertTrue(); - // expectedError(err, caseName, 'tempWnd.setWindowType', done, 1003); done(); }) - // console.log(msgStr + 'tempWnd.setWindowType windowTypeData:' + JSON.stringify(windowTypeData)); - // console.log(msgStr + 'tempWnd.setWindowType !!windowTypeData:' + !!windowTypeData); - // if (!!windowTypeData) { - // expect(false).assertFail(); - // } } }) /** @@ -444,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); @@ -458,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 @@ -535,9 +536,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - await 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) { @@ -547,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++ { + 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(); + // }) + // } }) /** @@ -872,9 +934,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - await 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!'); @@ -903,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(); + // }) + // } }) /** @@ -981,9 +1090,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) expect(!!systemBarData).assertTrue(); expect(!!systemBarData.regionTint).assertTrue(); let arrLength = systemBarData.regionTint.length; - await 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) { @@ -993,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(); + // }) + // } }) /** @@ -1064,9 +1203,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) console.log(msgStr + 'begin'); let loopCount = systemWindowTypeDicArr.length; console.log(msgStr + 'loopCount: ' + loopCount); - await 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'); @@ -1082,13 +1219,32 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) 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++ { + // 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++ { console.log(msgStr + 'screen.setDensityDpi success set DPI ' + dpiItem[i]); let defaultDpi = null; @@ -1559,17 +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(); }) @@ -1591,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']; - await 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 -- GitLab