提交 3c0a6354 编写于 作者: 华华小仙女

解决冲突

Signed-off-by: N华华小仙女 <zhurong18@h-partners.com>
上级 fddba063
...@@ -101,7 +101,8 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -101,7 +101,8 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: ';
console.log(msgStr + JSON.stringify(error)); console.log(msgStr + JSON.stringify(error));
try { try {
expect(error.code == code).assertTrue(); expect(TRUE_FLAG).assertTrue();
expect(error.code === code).assertTrue();
} catch (error) { } catch (error) {
console.info(`ohosWindow.on ${JSON.stringify(error)}`) console.info(`ohosWindow.on ${JSON.stringify(error)}`)
} }
...@@ -119,781 +120,680 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -119,781 +120,680 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
done(); done();
} }
function sleep(time) { async function sleep(time) {
return new Promise(resolve => { let timeoutId = null;
setTimeout(() => { let promise = new Promise(resolve => {
timeoutId = setTimeout(() => {
resolve('sleep finished'); resolve('sleep finished');
}, time); }, time);
}) })
let result = await promise;
clearTimeout(timeoutId)
} }
/** /**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_006 * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_006
* @tc.name Test setSystemBarEnableTest6 * @tc.name Test setSystemBarEnableTest6
* @tc.desc Verify that the scene shows the status bar and hides the navigation bar * @tc.desc Test ohosWindow.setSystemBarEnable API function test1.
*/ */
it('setSystemBarEnableTest6', 0, async function (done) { it('setSystemBarEnableTest6', 0, async function (done) {
let caseName = 'setSystemBarEnableTest6'; let caseName = 'setSystemBarEnableTest6';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let flagStatus = false; let [flagStatus, flagNav] = [false, false];
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
listenerData.on = true; listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange'; listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', systembartintstate => {
function ohosWindowOn() { console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint));
ohosWindow.on('systemBarTintChange', systembartintstate => { console.log(msgStr + 'ohosWindow.on flagNav : ' + JSON.stringify(flagNav));
console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); console.log(msgStr + 'ohosWindow.on flagStatus : ' + JSON.stringify(flagStatus));
if (flagStatus) { console.log(msgStr + 'ohosWindow.on flagStatus && flagNav : ' + (flagStatus && flagNav));
console.log(msgStr + 'systembartintstate.regionTint[0].type : ' + JSON.stringify(systembartintstate.regionTint[0].type)); if (flagStatus || flagNav) {
console.log(msgStr + 'systembartintstate.regionTint[0].isEnable : ' + JSON.stringify(systembartintstate.regionTint[0].isEnable)); try {
try { expect(!!systembartintstate).assertTrue();
expect(!!systembartintstate).assertTrue(); expect(!!systembartintstate.regionTint).assertTrue();
expect(systembartintstate.regionTint[0].type == 3 && systembartintstate.regionTint[0].isEnable).assertTrue(); } catch (error) {
} catch (error) { console.info(`ohosWindow.on ${JSON.stringify(error)}`)
console.info(msgStr + `ohosWindow.on ${JSON.stringify(error)}`)
}
done();
} }
}) console.log(msgStr + 'flagStatus || flagNav' + msgStr + 'ohosWindow.on systemBarTintChange regionTint:' + JSON.stringify(systembartintstate.regionTint));
} ohosWindow.off('systemBarTintChange')
done();
let mainWnd = null; }
console.log(msgStr + 'windowStage = ' + JSON.stringify(windowStage)); })
function getMainWindow() { function getMainWindow() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
windowStage.getMainWindow((err, data) => { windowStage.getMainWindow((err, data) => {
console.log(msgStr + 'getMainWindow data:' + JSON.stringify(data)); console.log(msgStr + 'getMainWindow data' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done); console.log(msgStr + 'windowStage getMainWindow failed');
} reject(null)
try { } else {
mainWnd = data; resolve(data);
expect(!!data).assertTrue(); console.log(msgStr + 'windowStage getMainWindow successed');
} catch (error) {
console.info(msgStr + `getMainWindow ${JSON.stringify(error)}`)
} }
resolve(data);
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
}) })
}) })
} }
function show() { function show(win) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.show((err, data) => { win.show((err) => {
console.log(msgStr + 'mainWnd.show err' + JSON.stringify(err));
console.log(msgStr + 'mainWnd.show data' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done); console.log(msgStr + 'mainWnd.show failed');
} reject(null)
try { } else {
expect(!data).assertTrue(); console.log(msgStr + 'mainWnd.show success');
} catch (err) { resolve(true)
console.info(msgStr + `mainWnd.show err: ${JSON.stringify(err)}`)
} }
console.log(msgStr + 'mainWnd.show success');
resolve(data)
}) })
}) })
} }
function setFullScreen() { function setFullScreen(win) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setFullScreen(true, (err, data) => { win.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen data:' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setFullScreen data:' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); console.log(msgStr + 'mainWnd.setFullScreen failed');
} reject(null)
try { } else {
expect(!data).assertTrue(); console.log(msgStr + 'mainWnd.setFullScreen success');
} catch (error) { flagNav = true;
console.info(msgStr + `setFullScreen ${JSON.stringify(error)}`) resolve(true)
} }
console.log(msgStr + 'mainWnd.setFullScreen success');
resolve(data)
}) })
}) })
} }
function setSystemBarEnableStatus() { function setSystemBarEnableNavigation(win) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable(['status'], (err, data) => { win.setSystemBarEnable(['navigation'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable status data===' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setSystemBarEnable navigation JSON.stringify(data)==' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
console.log(msgStr + 'mainWnd.setSystemBarEnable status err===' + JSON.stringify(err)); console.log(msgStr + 'mainWnd.setSystemBarEnable failed');
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); reject(null)
} else {
console.log(msgStr + 'mainWnd.setSystemBarEnable success');
flagStatus = true;
resolve(true)
} }
try { })
flagStatus = true })
expect(!data).assertTrue(); }
} catch (error) {
console.info(msgStr + `setSystemBarEnable ${JSON.stringify(error)}`) function setSystemBarEnableStatus(win) {
return new Promise(function (resolve, reject) {
win.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));
reject(null)
} else {
console.log(msgStr + 'mainWnd.setSystemBarEnable status successed');
resolve(true)
} }
resolve(data)
}) })
}) })
} }
await getMainWindow() let mainWnd = null;
await show() mainWnd = await getMainWindow().catch((err) => {
await setFullScreen() console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
await setSystemBarEnableStatus() expect().assertFail()
ohosWindowOn() done();
});
expect(!!mainWnd).assertTrue();
await show(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setFullScreen(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setSystemBarEnableNavigation(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
await setSystemBarEnableStatus(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
console.log(msgStr + 'finished!!');
}); });
/** /**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_007 * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_007
* @tc.name Test setSystemBarEnableTest7 * @tc.name Test setSystemBarEnableTest7
* @tc.desc Verify that the scene hides the status bar and displays the navigation bar. * @tc.desc Verify that the scene hides the status bar and displays the navigation bar.
*/ */
it('setSystemBarEnableTest7', 0, async function (done) { it('setSystemBarEnableTest7', 0, async function (done) {
let caseName = 'setSystemBarEnableTest7'; let caseName = 'setSystemBarEnableTest7';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let [flagStatus, flagNav] = [false, false]; let [flagStatus, flagNav] = [false, false];
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
function ohosWindowOn() { ohosWindow.on('systemBarTintChange', systembartintstate => {
ohosWindow.on('systemBarTintChange', systembartintstate => { console.log(msgStr + 'ohosWindow.on systembartintstate :' + JSON.stringify(systembartintstate));
console.log(msgStr + 'ohosWindow.on systembartintstate :' + JSON.stringify(systembartintstate)); console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint));
console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); if (flagStatus || flagNav) {
if (flagStatus || flagNav) { console.log(msgStr + 'ohosWindow.on flagStatus || flagNav:');
console.log(msgStr + 'ohosWindow.on flagStatus || flagNav:'); try {
try { expect(!!systembartintstate).assertTrue();
expect(!!systembartintstate).assertTrue(); } catch (error) {
} catch (error) { console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`)
console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`)
}
done();
} }
}) ohosWindow.off('systemBarTintChange')
} done();
}
let mainWnd = null; })
console.log(msgStr + 'mainWnd = null')
function getMainWindow() { function getMainWindow() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
windowStage.getMainWindow((err, data) => { windowStage.getMainWindow((err, data) => {
console.log(msgStr + 'getMainWindow data:' + JSON.stringify(data)); console.log(msgStr + 'getMainWindow data:' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done); console.log(msgStr + 'mainWnd getMainWindow success');
} reject(null)
try { } else {
mainWnd = data; resolve(data);
expect(!!data).assertTrue(); console.log(msgStr + 'windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
} catch (error) {
console.info(`ohosWindow.on ${JSON.stringify(error)}`)
} }
resolve(data);
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
}) })
}) })
} }
function show() { function show(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.show((err, data) => { mainWnd.show((err) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done); reject(null)
} } else {
console.log(msgStr + 'mainWnd.show success'); console.log(msgStr + 'mainWnd.show success');
try { resolve(true)
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
function setFullScreen() { function setFullScreen(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setFullScreen(true, (err, data) => { mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); reject(null)
} } else {
try { console.log(msgStr + 'mainWnd.setFullScreen successed');
expect(!data).assertTrue(); resolve(true)
} catch (error) {
console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
function setSystemBarEnableStatus() { function setSystemBarEnableStatus(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable(['status'], (err, data) => { mainWnd.setSystemBarEnable(['status'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)==' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)==' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done); reject(null)
} } else {
flagStatus = true; flagStatus = true;
try { resolve(true)
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
function setSystemBarEnableNavigation() { function setSystemBarEnableNavigation(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable(['navigation'], (err, data) => { mainWnd.setSystemBarEnable(['navigation'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)==' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navitgation]', done); reject(null)
} } else {
flagNav = true; flagNav = true;
try { resolve(true)
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
await getMainWindow() let mainWnd = null;
await show() mainWnd = await getMainWindow().catch((err) => {
await setFullScreen() console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
ohosWindowOn() expect().assertFail()
await setSystemBarEnableStatus() done();
await setSystemBarEnableNavigation() });
expect(!!mainWnd).assertTrue();
await show(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setFullScreen(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setSystemBarEnableStatus(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
await setSystemBarEnableNavigation(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
}); });
/** /**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_008 * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_008
* @tc.name Test setSystemBarEnableTest8 * @tc.name Test setSystemBarEnableTest8
* @tc.desc Verify that the scene displays both the status bar and the navigation bar. * @tc.desc Verify that the scene displays both the status bar and the navigation bar.
*/ */
it('setSystemBarEnableTest8', 0, async function (done) { it('setSystemBarEnableTest8', 0, async function (done) {
let caseName = 'setSystemBarEnableTest8'; let caseName = 'setSystemBarEnableTest8';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let [flagStatus, flagNav] = [false, false]; let [flagStatus, flagNav] = [false, false];
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let mainWnd = null;
console.log(msgStr + 'mainWnd = null'); ohosWindow.on('systemBarTintChange', systembartintstate => {
listenerData.on = true; console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate));
listenerData.typeStr = 'systemBarTintChange'; 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(numType === ohosWindow.WindowType.TYPE_NAVIGATION_BAR || enable).assertTrue();
} catch (error) {
console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`)
}
ohosWindow.off('systemBarTintChange')
done();
}
})
function getMainWindow() { function getMainWindow() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
windowStage.getMainWindow((err, data) => { windowStage.getMainWindow((err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done); reject(null)
} } else {
try { console.log(msgStr + 'windowStage JSON.stringify(mainWnd)===' + JSON.stringify(data));
expect(!!data).assertTrue(); resolve(data)
} 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() { function show(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.show((err, data) => { mainWnd.show((err) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done); reject(null)
} } else {
console.log(msgStr + 'mainWnd.show success'); console.log(msgStr + 'mainWnd.show success');
try { resolve(true)
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
function setFullScreen() { function setFullScreen(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setFullScreen(true, (err, data) => { mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); reject(null)
} } else {
try { console.log(msgStr + 'mainWnd.setFullScreen successed');
expect(!data).assertTrue(); resolve(true)
} catch (error) {
console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
function setSystemBarEnable() { function setSystemBarEnable(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable([], (err, data) => { mainWnd.setSystemBarEnable([], (err) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(err));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); reject(null)
} } else {
try { resolve(true)
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
} }
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
resolve(data)
}) })
}) })
} }
function ohosWindowOn() { function setSystemBarEnableT(mainWnd) {
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
let enableNav = systembartintstate.regionTint[1].isEnable
let numTypeNav = systembartintstate.regionTint[1].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_STATUS_BAR || enable).assertTrue();
expect(numTypeNav === ohosWindow.WindowType.TYPE_NAVIGATION_BAR || enableNav).assertTrue();
} catch (error) {
console.info(`ohosWindow.on catch err: ${JSON.stringify(error)}`)
}
}
done();
})
}
function setSystemBarEnableT() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done); reject(null)
} } else {
flagStatus = true; flagStatus = true;
flagNav = true; flagNav = true;
try { resolve(true)
expect(!data).assertTrue(); console.log(msgStr + 'mainWnd.setSystemBarEnable [status, navigation] JSON.stringify(data)==' + JSON.stringify(data));
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
await getMainWindow() let mainWnd = null;
await show() mainWnd = await getMainWindow().catch((err) => {
await setFullScreen() console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
await setSystemBarEnable() expect().assertFail()
await setSystemBarEnableT() done();
ohosWindowOn() });
expect(!!mainWnd).assertTrue();
await show(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setFullScreen(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setSystemBarEnable(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
await setSystemBarEnableT(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
}); });
/** /**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_009 * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_009
* @tc.name Test setSystemBarEnableTest9 * @tc.name Test setSystemBarEnableTest9
* @tc.desc Verify that the scene hides both the status bar and the navigation bar. * @tc.desc Verify that the scene hides both the status bar and the navigation bar.
*/ */
it('setSystemBarEnableTest9', 0, async function (done) { it('setSystemBarEnableTest9', 0, async function (done) {
let caseName = 'setSystemBarEnableTest9'; let caseName = 'setSystemBarEnableTest9';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let [flagStatus, flagNav] = [false, false]; let [flagStatus, flagNav] = [false, false];
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let mainWnd = null; ohosWindow.on('systemBarTintChange', (systembartintstate) => {
console.log(msgStr + 'mainWnd = null'); 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)}`)
}
ohosWindow.off('systemBarTintChange')
done();
}
})
function getMainWindow() { function getMainWindow() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
windowStage.getMainWindow((err, data) => { windowStage.getMainWindow((err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done); reject(null)
} } else {
try { console.log(msgStr + 'windowStage JSON.stringify(mainWnd)===' + JSON.stringify(data));
expect(!!data).assertTrue(); resolve(data)
} 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() { function show(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.show((err, data) => { mainWnd.show((err) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done); reject(null)
} } else {
console.log(msgStr + 'mainWnd.show success'); console.log(msgStr + 'mainWnd.show success');
try { resolve(true)
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
function setFullScreen() { function setFullScreen(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setFullScreen(true, (err, data) => { mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen', done); reject(null)
} } else {
try { console.log(msgStr + 'mainWnd.setFullScreen successed');
expect(!data).assertTrue(); resolve(true)
} catch (error) {
console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
function setSystemBarEnableT() { function setSystemBarEnable(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { mainWnd.setSystemBarEnable([], (err) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable status,navigation JSON.stringify(data)==' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(err));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done); reject(null)
} } else {
flagStatus = true; resolve(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() { function setSystemBarEnableT(mainWnd) {
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();
}
})
}
function setSystemBarEnable() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable([], (err, data) => { mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); reject(null)
} } else {
try { flagStatus = true;
expect(!data).assertTrue(); flagNav = true;
} catch (error) { resolve(true)
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
await getMainWindow() let mainWnd = null;
await show() mainWnd = await getMainWindow().catch((err) => {
await setFullScreen() console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
await setSystemBarEnableT() expect().assertFail()
ohosWindowOn() done();
await setSystemBarEnable() });
expect(!!mainWnd).assertTrue();
await show(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setFullScreen(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setSystemBarEnableT(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
await setSystemBarEnable(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
}); });
/** /**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_010 * @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_010
* @tc.name Test setSystemBarEnableTest10 * @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 * @tc.desc Verify the scene where illegal values are entered when the navigation bar and status bar are displayed or hidden
*/ */
it('setSystemBarEnableTest10', 0, async function (done) { it('setSystemBarEnableTest10', 0, async function (done) {
let caseName = 'setSystemBarEnableTest10'; let caseName = 'setSystemBarEnableTest10';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let mainWnd = null;
console.log(msgStr + 'mainWnd = null');
function getMainWindow() { function getMainWindow() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
windowStage.getMainWindow((err, data) => { windowStage.getMainWindow((err, data) => {
console.log(msgStr + 'getMainWindow data:' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done); reject(null)
} } else {
try { resolve(data);
console.log(msgStr + 'windowStage.getMainWindow JSON.stringify(!!data)===' + JSON.stringify(!!data)); console.log(msgStr + 'windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
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() { function show(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.show((err, data) => { mainWnd.show((err) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done); reject(null)
} } else {
console.log(msgStr + 'mainWnd.show success'); console.log(msgStr + 'mainWnd.show success');
try { resolve(true)
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() { function setFullScreen(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setFullScreen(true, (err, data) => { mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen: ' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done); reject(null)
} } else {
try { console.log(msgStr + 'mainWnd.setFullScreen successed');
console.log(msgStr + 'mainWnd.setFullScreen JSON.stringify(!data)===' + JSON.stringify(!data)); resolve(true)
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setFullScreen catch error: ${JSON.stringify(error)}`)
} }
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() { function setSystemBarEnable(mainWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable([null, '123'], (err, data) => { mainWnd.setSystemBarEnable([], (err) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(data)==' + JSON.stringify(data)); console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(err));
console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(err)==' + JSON.stringify(err));
if (err && err.code) { if (err && err.code) {
try { reject(null)
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 { } else {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [null,123]', done); resolve(true)
} }
resolve(data)
}) })
}) })
} }
await getMainWindow() let mainWnd = null;
await show() mainWnd = await getMainWindow().catch((err) => {
await setFullScreen() console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
await setSystemBarEnable() expect().assertFail()
await setSystemBarEnableError() done();
});
expect(!!mainWnd).assertTrue();
await show(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setFullScreen(mainWnd).catch((err) => {
console.error(msgStr + 'Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await setSystemBarEnable(mainWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
mainWnd.setSystemBarEnable([null, '123'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(data)==' + JSON.stringify(data));
console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(err)==' + JSON.stringify(err));
if (err && err.code) {
try {
console.log(msgStr + 'mainWnd.setSystemBarEnable JSON.stringify(err.code)===' + JSON.stringify(err.code));
expect(err.code === 1003).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`)
}
done();
} else {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [null,123]', done);
}
})
}); });
/** /**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_004 * @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_004
* @tc.name Test setSystemBarPropertiesTest1 * @tc.name Test setSystemBarPropertiesTest1
* @tc.desc TVerify the scene where the colors of the status bar and navigation bar are set in RGB * @tc.desc TVerify the scene where the colors of the status bar and navigation bar are set in RGB
*/ */
it('setSystemBarPropertiesTest4', 0, async done => { it('setSystemBarPropertiesTest4', 0, async done => {
let caseName = 'setSystemBarPropertiesTest4'; let caseName = 'setSystemBarPropertiesTest4';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let cloneColorArr = JSON.parse(JSON.stringify(commonRGBColorArr)); let cloneColorArr = JSON.parse(JSON.stringify(commonRGBColorArr));
let compareCount = 0; let compareCount = 0;
let listenerFlag = false;
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
function ohosWindowOn() { function setSystemBarPropertiesFun(tempWnd, systemBarProperties) {
ohosWindow.on('systemBarTintChange', (systemBarData) => { return new Promise((resolve, reject) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => {
if (listenerFlag) { if (err && err.code) {
try { reject(null)
expect(!!systemBarData).assertTrue(); } else {
expect(!!systemBarData.regionTint).assertTrue(); console.log(msgStr + 'tempWnd.setSystemBarProperties ' + JSON.stringify(systemBarProperties)+ ' success');
} catch (error) { resolve(true)
console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`)
} }
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) {
console.log(msgStr + 'systemBarTintChange compare start!');
compareCount++;
let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor);
let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor);
try {
expect(backgroundIndex === -1).assertTrue();
expect(contentColorIndex === -1).assertTrue();
} catch (error) {
console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`)
}
}
if (i === arrLength - 1) {
done();
}
}
}
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(!!data).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);
}
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 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() { let tempWnd;
return new Promise(function (resolve, reject) { tempWnd = await windowStage.getMainWindow().catch((err) => {
let loopCount = commonRGBColorArr.length console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
for (let i = 0; i < loopCount; i++) { expect().assertFail()
let tempColor = commonRGBColorArr[i]; done();
let systemBarProperties = { });
statusBarColor: tempColor, expect(!!tempWnd).assertTrue();
isStatusBarLightIcon: true, let loopCount = commonRGBColorArr.length
statusBarContentColor: tempColor, for (let i = 0; i < loopCount; i++) {
navigationBarColor: tempColor, let tempColor = commonRGBColorArr[i];
isNavigationBarLightIcon: false, let systemBarProperties = {
navigationBarContentColor: tempColor, statusBarColor: tempColor,
}; isStatusBarLightIcon: true,
tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => { statusBarContentColor: tempColor,
console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err)); navigationBarColor: tempColor,
console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data)); isNavigationBarLightIcon: false,
if (err && err.code) { navigationBarContentColor: tempColor,
unexpectedError(err, caseName, 'tempWnd.setSystemBarProperties' + tempColor + ' ', done); };
} await setSystemBarPropertiesFun(tempWnd,systemBarProperties).catch((err) => {
console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success'); console.info(msgStr + 'setSystemBarProperties error : ' + JSON.stringify(err));
resolve(data) expect().assertFail();
}) done();
} });
})
} }
done();
await getMainWindow()
await show()
await setFullScreen()
ohosWindowOn()
await setSystemBarEnableNavigationT()
await setSystemBarProperties()
}) })
/** /**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_005 * @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_005
* @tc.name Test setSystemBarPropertiesTest5 * @tc.name Test setSystemBarPropertiesTest5
* @tc.desc Verify the scene where the status bar and navigation bar colors are set in hexadecimal form * @tc.desc Verify the scene where the status bar and navigation bar colors are set in hexadecimal form
*/ */
it('setSystemBarPropertiesTest5', 0, async done => { it('setSystemBarPropertiesTest5', 0, async done => {
let caseName = 'setSystemBarPropertiesTest5'; let caseName = 'setSystemBarPropertiesTest5';
...@@ -910,202 +810,145 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -910,202 +810,145 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
listenerData.on = true; listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange'; listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
function ohosWindowOn() { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
ohosWindow.on('systemBarTintChange', (systemBarData) => { if (listenerFlag) {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); try {
if (listenerFlag) { expect(!!systemBarData).assertTrue();
try { expect(!!systemBarData.regionTint).assertTrue();
expect(!!systemBarData).assertTrue(); } catch (error) {
expect(!!systemBarData.regionTint).assertTrue(); console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`)
} catch (error) { }
console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) let arrLength = systemBarData.regionTint.length;
} for (let i = 0; i < arrLength; i++) {
let arrLength = systemBarData.regionTint.length; console.log(msgStr + 'for arrLenght compareCount: ' + compareCount + ' ,i:' + i + ' ,arrLength:' + arrLength);
for (let i = 0; i < arrLength; i++) { let tempData = systemBarData.regionTint[i];
console.log(msgStr + 'for arrLenght compareCount: ' + compareCount + ' ,i:' + i + ' ,arrLength:' + arrLength); if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR) {
let tempData = systemBarData.regionTint[i]; console.log(msgStr + 'systemBarTintChange compare start! arrLength= ' + arrLength);
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR) { compareCount++;
console.log(msgStr + 'systemBarTintChange compare start! arrLength= ' + arrLength); let backgroundIndex = cloneColorArr.SBC.indexOf(tempData.backgroundColor);
compareCount++; let contentColorIndex = cloneColorArr.SCC.indexOf(tempData.contentColor);
let backgroundIndex = cloneColorArr.SBC.indexOf(tempData.backgroundColor); if (backgroundIndex >= 0) {
let contentColorIndex = cloneColorArr.SCC.indexOf(tempData.contentColor); cloneColorArr.SBC.splice(backgroundIndex, 1);
if (backgroundIndex >= 0) { } else {
cloneColorArr.SBC.splice(backgroundIndex, 1); console.log(msgStr + 'SBC tempData.backgroundColor:' + JSON.stringify(tempData.backgroundColor));
} else { }
console.log(msgStr + 'SBC tempData.backgroundColor:' + JSON.stringify(tempData.backgroundColor)); if (contentColorIndex >= 0) {
} cloneColorArr.SCC.splice(contentColorIndex, 1);
if (contentColorIndex >= 0) { } else {
cloneColorArr.SCC.splice(contentColorIndex, 1); console.log(msgStr + 'SCC tempData.contentColor:' + JSON.stringify(tempData.contentColor));
} 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
let ca = cloneColorArr; if (compareCount === 18 && !flag) {
let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length console.log(msgStr + 'if compareCount: ' + compareCount + ' ,true flag:' + flag);
if (compareCount === 18 && !flag) { try {
console.log(msgStr + 'if compareCount: ' + compareCount + ' ,true flag:' + flag); expect(true).assertTrue();
try { } catch (error) {
expect(true).assertTrue(); console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`)
} 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; } else {
let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag);
if (compareCount === 18 && !flag) { }
console.log(msgStr + 'else compareCount: ' + compareCount + ' ,true flag:' + flag); console.log(msgStr + 'compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.SCC.length) + ' ,cloneColorArr.SBC:' + JSON.stringify(cloneColorArr.SBC));
try { console.log(msgStr + 'compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.SCC.length) + ' ,cloneColorArr.SCC' + JSON.stringify(cloneColorArr.SCC));
expect(true).assertTrue(); done();
} catch (error) { } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) {
console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) console.log(msgStr + 'systemBarTintChange compare start!');
} compareCount++;
} else { let backgroundIndex = cloneColorArr.NBC.indexOf(tempData.backgroundColor);
console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag); 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)}`)
} }
console.log(msgStr + 'compareCount: ' + endNum + ' ,compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.NBC.length) + ' ,cloneColorArr.SBC:' + JSON.stringify(cloneColorArr.NBC)); } else {
console.log(msgStr + 'compareCount: ' + endNum + ' ,compareCount: ' + compareCount + ' ,length: ' + JSON.stringify(cloneColorArr.NCC.length) + ' ,cloneColorArr.SCC' + JSON.stringify(cloneColorArr.NCC)); console.log(msgStr + 'compareCount: ' + compareCount + ' ,flag:' + flag);
endNum = compareCount
done();
} }
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'); }
}) 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(!!data).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);
}
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 setSystemBarEnableNavigationT() { let tempWnd;
return new Promise(function (resolve, reject) { tempWnd = await windowStage.getMainWindow().catch((err) => {
tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
if (err && err.code) { expect().assertFail()
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); done();
} });
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await tempWnd.setFullScreen(true).catch((err) => {
console.error(msgStr + 'Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
await sleep(1000);
listenerFlag = true
let loopCount = commonNUMBERColorArr.length
for (let i = 0; i < loopCount; i++) {
console.log(msgStr + 'tempWnd.setSystemBarEnable i:' + i);
let tempColor = commonNUMBERColorArr[i];
let systemBarProperties = {
statusBarColor: tempColor,
isStatusBarLightIcon: true,
statusBarContentColor: tempColor,
navigationBarColor: tempColor,
isNavigationBarLightIcon: true,
navigationBarContentColor: tempColor,
};
tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => {
console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data));
if (err && err.code) {
try { try {
expect(!data).assertTrue(); expect(TRUE_FLAG).assertFail();
} catch (error) { } catch (error) {
console.info(`tempWnd.setSystemBatEnable catch error: ${JSON.stringify(error)}`) console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`)
} }
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); done();
listenerFlag = true; return;
resolve(data) }
}) if (i == commonNUMBERColorArr.length - 1) {
}) console.info(msgStr + 'setSystemBarPropertiesTest5 finished step:' + i);
} done();
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) {
try {
expect(TRUE_FLAG).assertFail();
} catch (error) {
console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
} }
}) })
} }
await getMainWindow()
await show()
await setFullScreen()
ohosWindowOn()
await setSystemBarEnableNavigationT()
await setSystemBarProperties()
}) })
/** /**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_006 * @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_006
* @tc.name Test setSystemBarPropertiesTest6 * @tc.name Test setSystemBarPropertiesTest6
* @tc.desc TVerify the scene where the status bar and navigation bar colors are set as keywords * @tc.desc TVerify the scene where the status bar and navigation bar colors are set as keywords
*/ */
it('setSystemBarPropertiesTest6', 0, async done => { it('setSystemBarPropertiesTest6', 0, async done => {
let caseName = 'setSystemBarPropertiesTest6'; let caseName = 'setSystemBarPropertiesTest6';
...@@ -1116,153 +959,91 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -1116,153 +959,91 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
listenerData.on = true; listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange'; listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
function ohosWindowOn() { console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
ohosWindow.on('systemBarTintChange', (systemBarData) => { if (listenerFlag) {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData)); try {
if (listenerFlag) { expect(!!systemBarData).assertTrue();
try { expect(!!systemBarData.regionTint).assertTrue();
expect(!!systemBarData).assertTrue(); } catch (error) {
expect(!!systemBarData.regionTint).assertTrue(); console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`)
} catch (error) { }
console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`) let arrLength = systemBarData.regionTint.length;
} for (let i = 0; i < arrLength; i++) {
let arrLength = systemBarData.regionTint.length; let tempData = systemBarData.regionTint[i];
for (let i = 0; i < arrLength; i++) { if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) {
let tempData = systemBarData.regionTint[i]; console.log(msgStr + 'systemBarTintChange compare start!');
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) { compareCount++;
console.log(msgStr + 'systemBarTintChange compare start!'); let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor);
compareCount++; let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor);
let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor); try {
let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor); expect(backgroundIndex === -1).assertTrue();
try { expect(contentColorIndex === -1).assertTrue();
expect(backgroundIndex === -1).assertTrue(); } catch (error) {
expect(contentColorIndex === -1).assertTrue(); console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`)
} catch (error) {
console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`)
}
} }
} }
} }
console.log(msgStr + 'tempWnd.on systemBarTintChange finished'); }
}) console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
} })
let tempWnd;
let tempWnd = null tempWnd = await windowStage.getMainWindow().catch((err) => {
console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
function getMainWindow() { expect().assertFail()
return new Promise(function (resolve, reject) { done();
windowStage.getMainWindow((err, data) => { });
if (err && err.code) { expect(!!tempWnd).assertTrue();
unexpectedError(err, caseName, 'windowStage.getMainWindow', done); await tempWnd.show().catch((err) => {
} console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
tempWnd = data expect().assertFail()
try { done();
expect(!!data).assertTrue(); });
} catch (error) { await tempWnd.setFullScreen(true).catch((err) => {
console.info(`winsowStage.getMainWindow catch error: ${JSON.stringify(error)}`) console.error(msgStr + 'Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
} expect().assertFail()
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd); done();
resolve(data) });
}) await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
}) console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
} expect().assertFail();
done();
function show() { });
return new Promise(function (resolve, reject) { await sleep(1000);
tempWnd.show((err, data) => { listenerFlag = true
if (err && err.code) { let loopCount = commonRGBColorArr.length
unexpectedError(err, caseName, 'tempWnd.show', done); for (let i = 0; i < loopCount; i++) {
} let tempColor = commonKEYColorArr[i];
try { let systemBarProperties = {
expect(!data).assertTrue(); statusBarColor: tempColor,
} catch (error) { isStatusBarLightIcon: true,
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) statusBarContentColor: tempColor,
} navigationBarColor: tempColor,
console.log(msgStr + 'tempWnd.show success'); isNavigationBarLightIcon: false,
resolve(data) 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));
function setFullScreen() { if (err && err.code) {
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 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 { try {
expect(!data).assertTrue(); expect(TRUE_FLAG).assertFail();
} catch (error) { } catch (error) {
console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`) console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`)
} }
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success'); done();
listenerFlag = true; }
resolve(data) if (i == commonRGBColorArr.length - 1) {
}) console.info(msgStr + 'setSystemBarPropertiesTest5 finished step:' + i);
}) done();
}
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) {
try {
expect(TRUE_FLAG).assertFail();
} catch (error) {
console.info(`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`)
}
resolve(data)
done();
}
})
} }
listenerFlag = false;
done();
}) })
} }
await getMainWindow()
await show()
await setFullScreen()
ohosWindowOn()
await setSystemBarEnableNavigationT()
await setSystemBarProperties()
}) })
/** /**
* @tc.number SUB_WINDOW_CREATE_JSAPI_005 * @tc.number SUB_WINDOW_CREATE_JSAPI_005
* @tc.name Test create5 * @tc.name Test create5
* @tc.desc Scheme of Failed to Create Application Type Window in Stage Mode * @tc.desc Scheme of Failed to Create Application Type Window in Stage Mode
*/ */
it('createTest5', 0, async done => { it('createTest5', 0, async done => {
let caseName = 'createTest5'; let caseName = 'createTest5';
...@@ -1270,34 +1051,38 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -1270,34 +1051,38 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console.log(msgStr + 'begin context==' + JSON.stringify(context)); console.log(msgStr + 'begin context==' + JSON.stringify(context));
let loopCount = appWindowTypeArr.length; let loopCount = appWindowTypeArr.length;
console.log(msgStr + 'loopCount: ' + loopCount); console.log(msgStr + 'loopCount: ' + loopCount);
function createWin(id, type) {
return new Promise((resolve, reject) => {
ohosWindow.create(context, id, type, (err, data) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
if (err && err.code) {
resolve(err)
} else {
reject(null)
}
})
})
}
for (let i = 0; i < loopCount; i++) { for (let i = 0; i < loopCount; i++) {
let tempType = ohosWindow.WindowType.TYPE_APP; let tempType = ohosWindow.WindowType.TYPE_APP;
let windId = 'createTest5' + i; let windId = 'createTest5' + i;
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); console.log(msgStr + 'ohosWindow.create ' + tempType + ' step: ' + i);
ohosWindow.create(context, windId, tempType, (err, data) => { let errCode;
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); errCode = await createWin(windId, tempType)
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); expect(errCode.code === 1003).assertTrue();
if (err && err.code) { if (i === loopCount - 1) {
try { done();
expect(err.code === 1003).assertTrue(); console.log(msgStr + 'ohosWindow.create i==' + i)
} catch (error) { }
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
}
if (i === loopCount - 1) {
done();
console.log(msgStr + 'ohosWindow.create i==' + i)
console.log(msgStr + 'ohosWindow.create loopCount - 1==' + (loopCount - 1))
}
} else {
unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done);
}
})
} }
}) })
/** /**
* @tc.number SUB_WINDOW_CREATE_JSAPI_006 * @tc.number SUB_WINDOW_CREATE_JSAPI_006
* @tc.name Test createTest6 * @tc.name Test createTest6
* @tc.desc Verify the scenario of creating the system type window * @tc.desc Verify the scenario of creating the system type window
*/ */
it('createTest6', 0, async done => { it('createTest6', 0, async done => {
let caseName = 'createTest6'; let caseName = 'createTest6';
...@@ -1308,127 +1093,61 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -1308,127 +1093,61 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let tempWnd = null let tempWnd = null
let tempType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT; let tempType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT;
function create(i) { function createWin(windId) {
return new Promise(function (resolve, reject) { 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) => { 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) { if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done); reject(null)
return; } else {
} console.log(msgStr + 'ohosWindow.create ' + tempType + ' wnd: ' + tempWnd);
try { resolve(data)
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) { function getProperties(win) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
tempWnd.getProperties((err, data) => { win.getProperties((err, data) => {
console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err)); console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.getProperties data' + JSON.stringify(data)); console.log(msgStr + 'tempWnd.getProperties data' + JSON.stringify(data));
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.getProperties', done);
console.log(msgStr + 'tempWnd.getProperties err&&err.code' + JSON.stringify(err)); console.log(msgStr + 'tempWnd.getProperties err&&err.code' + JSON.stringify(err));
return; reject(null)
} } else {
console.log(msgStr + 'tempWnd.getProperties success, !!data : ' + !!data); console.log(msgStr + 'tempWnd.getProperties success, !!data : ' + !!data);
try { resolve(data)
expect(!!data).assertTrue();
expect(data.type == tempType).assertTrue();
} catch (error) {
console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`)
} }
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)
done();
}) })
}) })
} }
for (let i = 0; i < loopCount; i++) { for (let i = 0; i < loopCount; i++) {
await create(i) let windId = 'createTest6' + i;
await getProperties(i) let tempWnd;
await find(i) tempWnd = await createWin(windId).catch(err => {
await destroy(i) console.info(msgStr + `ohosWindow.create catch error: ${JSON.stringify(err)}`)
await findAgain(i) expect().assertFail();
done();
})
expect(!!tempWnd).assertTrue();
let winProperties;
winProperties = await getProperties(tempWnd).catch(err => {
console.info(msgStr + `tempWnd.getProperties catch error: ${JSON.stringify(err)}`)
})
expect(!!winProperties).assertTrue();
console.info(msgStr + `windowType: ` + winProperties.type + "step: " + i)
expect(winProperties.type == tempType).assertTrue();
await tempWnd.destroyWindow();
if (i == loopCount - 1) {
done()
}
} }
}) })
/** /**
* @tc.number SUB_WINDOW_CREATE_JSAPI_007 * @tc.number SUB_WINDOW_CREATE_JSAPI_007
* @tc.name Test createTest7 * @tc.name Test createTest7
* @tc.desc Verify the scenario of creating a window of a type that does not exist * @tc.desc Verify the scenario of creating a window of a type that does not exist
*/ */
it('createTest7', 0, async done => { it('createTest7', 0, async done => {
let caseName = 'createTest7'; let caseName = 'createTest7';
...@@ -1437,33 +1156,25 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -1437,33 +1156,25 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let tempType = 5000; let tempType = 5000;
let windId = 'createTest7'; let windId = 'createTest7';
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
ohosWindow.create(context, windId, tempType, (err, data) => {
function create() { console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
return new Promise(function (resolve, reject) { if (err && err.code) {
ohosWindow.create(context, windId, tempType, (err, data) => { try {
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); expect(err.code === 1003).assertTrue();
if (err && err.code) { } catch (error) {
try { console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
expect(err.code === 1003).assertTrue(); }
} catch (error) { done();
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`) return;
} }
done(); unexpectedError(err, caseName, 'ohosWindow.create', done);
return; })
}
unexpectedError(err, caseName, 'ohosWindow.create', done);
resolve(data)
})
})
}
await create()
}) })
/** /**
* @tc.number SUB_WINDOW_CREATE_JSAPI_008 * @tc.number SUB_WINDOW_CREATE_JSAPI_008
* @tc.name Test createTest8 * @tc.name Test createTest8
* @tc.desc Verify the scenario of creating a window with duplicate IDs * @tc.desc Verify the scenario of creating a window with duplicate IDs
*/ */
it('createTest8', 0, async done => { it('createTest8', 0, async done => {
let caseName = 'createTest8'; let caseName = 'createTest8';
...@@ -1472,242 +1183,135 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -1472,242 +1183,135 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let windowId = 'sameid' let windowId = 'sameid'
let tempWnd = null; let tempWnd = null;
function create() { function createFirstWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.create(context, windowId, 1, (err, data) => { ohosWindow.create(context, windowId, 1, (err, data) => {
console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err)); console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err));
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.create', done); reject(null)
}
expect(!!data).assertTrue();
tempWnd = data;
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(err.code).assertEqual(1300001)
} catch (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));
}
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) {
expect(true).assertTrue();
} else { } else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done); resolve(data)
try {
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} }
resolve(data)
done();
}) })
}) })
} }
await create() let dataOne;
.then(function (params) { dataOne = await createFirstWin().catch((err) => {
console.log(msgStr + 'create then: ' + JSON.stringify(params)) console.error(msgStr + 'Failed to create window. Cause: ' + JSON.stringify(err));
return createAgain() expect().assertFail()
}).then(function (params) { done();
return find() });
}).then(function (params) { expect(!!dataOne).assertTrue();
return destroy(params) ohosWindow.create(context, windowId, 1, async (err, data) => {
}).then(function (params) { console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err));
return findAgain(params) if (err && err.code) {
}) console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data));
try {
expect(err.code).assertEqual(1300001)
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
await dataOne.destroyWindow();
done();
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data));
}
})
}) })
/** /**
* @tc.number SUB_WINDOW_ON_OFF_JSAPI_005 * @tc.number SUB_WINDOW_ON_OFF_JSAPI_005
* @tc.name Test listenerTest5 * @tc.name Test listenerTest5
* @tc.desc Verify whether the change of avoidance area and change monitoring can be turned on normally * @tc.desc Verify whether the change of avoidance area and change monitoring can be turned on normally
*/ */
it('listenerTest5', 0, async function (done) { it('listenerTest5', 0, async function (done) {
let caseName = 'listenerTest5'; let caseName = 'listenerTest5';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let listenerOnFlag = false; let listenerOnFlag = false;
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let tempWnd = null;
listenerData.on = true; listenerData.on = true;
listenerData.typeStr = 'systemAvoidAreaChange'; listenerData.typeStr = 'systemAvoidAreaChange';
function getMainWindow() { function setSystemBarEnable(tempWnd) {
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.show', done);
}
tempWnd = data
newWindowObj = data
console.log(msgStr + 'newWindowObj 1: ' + JSON.stringify(newWindowObj));
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
try {
expect(!!data).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() {
tempWnd.on('systemAvoidAreaChange', avoidAreaData => {
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, avoidAreaData : ' + JSON.stringify(avoidAreaData));
if (listenerOnFlag === true) {
listenerOnFlag = false;
try {
expect(!!avoidAreaData).assertTrue();
} catch (error) {
console.info(`tempWnd.on catch error: ${JSON.stringify(error)}`)
}
}
})
}
function setSystemBarEnable() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
tempWnd.setSystemBarEnable([], (err, data) => { tempWnd.setSystemBarEnable([], (err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done); reject(false)
} } else {
try { console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
expect(!data).assertTrue(); listenerOnFlag = true;
} catch (error) { resolve(true)
console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`)
} }
console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
listenerOnFlag = true;
resolve(data)
}) })
}) })
} }
function setSystemBarEnableT() { function setSystemBarEnableT(tempWnd) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => { tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done); reject(false)
} else {
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished');
resolve(true)
} }
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished');
resolve(data)
tempWnd.off('systemAvoidAreaChange')
done();
}) })
}) })
} }
await getMainWindow() let tempWnd;
await show() tempWnd = await windowStage.getMainWindow().catch((err) => {
await setFullScreen() console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
tempWndOn() expect().assertFail()
await setSystemBarEnable() done();
await setSystemBarEnableT() });
expect(!!tempWnd).assertTrue();
tempWnd.on('systemAvoidAreaChange', avoidAreaData => {
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, avoidAreaData : ' + JSON.stringify(avoidAreaData));
if (listenerOnFlag === true) {
try {
expect(!!avoidAreaData).assertTrue();
} catch (error) {
console.info(`tempWnd.on catch error: ${JSON.stringify(error)}`)
}
tempWnd.off('systemAvoidAreaChange')
done()
}
})
await tempWnd.show().catch((err) => {
console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await tempWnd.setFullScreen(true).catch((err) => {
console.error(msgStr + 'Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
expect().assertFail()
done();
});
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
await setSystemBarEnable(tempWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
await setSystemBarEnableT(tempWnd).catch((err) => {
console.info(msgStr + 'setWindowSystemBarEnable error : ' + JSON.stringify(err));
expect().assertFail();
done();
});
}) })
/** /**
* @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_003 * @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_003
* @tc.name Test setWindowTypeTest3 * @tc.name Test setWindowTypeTest3
* @tc.desc Verify the scenario where the normal window type is set * @tc.desc Verify the scenario where the normal window type is set
*/ */
it('setWindowTypeTest3', 0, async function (done) { it('setWindowTypeTest3', 0, async function (done) {
let caseName = 'setWindowTypeTest3'; let caseName = 'setWindowTypeTest3';
...@@ -1717,86 +1321,73 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -1717,86 +1321,73 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
console.log(msgStr + 'newWindowObj 2: ' + JSON.stringify(newWindowObj)); console.log(msgStr + 'newWindowObj 2: ' + JSON.stringify(newWindowObj));
let tempWnd = null let tempWnd = null
let tempTypeArr = [];
let loopCount1 = systemWindowTypeArr; let loopCount1 = systemWindowTypeArr;
console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount1)) console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount1))
function create() { function createWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.create(context, windowId, baseWndType, (err, data) => { ohosWindow.create(context, windowId, baseWndType, (err, data) => {
try { 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) { if (!!data) {
tempWnd = data resolve(data)
console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd); } else {
try { reject(null)
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`ohosWindwo.create catch error: ${JSON.stringify(error)}`)
}
} }
} catch (err) { } catch (err) {
console.log(msgStr + 'ohosWindow.create catch err: ' + JSON.stringify(err)); console.log(msgStr + 'ohosWindow.create catch err: ' + JSON.stringify(err));
} }
resolve(0)
}) })
}) })
} }
function setWindowType(tempType, i) { function setWindowType(win, tempType, i) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
tempWnd.setWindowType(tempType, (err, data) => { win.setWindowType(tempType, (err, data) => {
console.log(msgStr + 'tempWnd.setWindowType i: ' + i); console.log(msgStr + 'tempWnd.setWindowType i: ' + i);
console.log(msgStr + 'tempWnd.setWindowType err: ' + JSON.stringify(err)); if (err && err.code) {
console.log(msgStr + 'tempWnd.setWindowType data: ' + JSON.stringify(data)); reject(null)
console.log(msgStr + 'tempWnd.setWindowType !data: ' + !data);
if (!data) {
expect(!data).assertTrue();
} else { } else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done); console.log(msgStr + 'tempWnd.setWindowType success' + tempType);
resolve(true)
} }
console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' end');
resolve(data)
}) })
}) })
} }
function getProperties(tempType, i) { tempWnd = await createWin().catch(err => {
console.log(msgStr + 'getProperties start tempTypeArr:' + JSON.stringify(tempTypeArr) + ',i:' + i); console.log(msgStr + 'ohosWindow.create failed' + JSON.stringify(err));
return new Promise(function (resolve, reject) { expect().assertFail();
tempWnd.getProperties((err, dataProper) => { done();
console.log(msgStr + 'tempWnd.getProperties err: ' + JSON.stringify(err)); })
console.log(msgStr + 'tempWnd.getProperties dataProper: ' + JSON.stringify(dataProper)); expect(!!tempWnd).assertTrue();
console.log(msgStr + 'tempWnd.getProperties !!dataProper: ' + !!dataProper);
expect(!!dataProper).assertTrue();
expect(dataProper.type === tempType).assertTrue();
resolve(dataProper)
})
})
}
await create()
for (let i = 0; i < loopCount1.length; i++) { for (let i = 0; i < loopCount1.length; i++) {
let tempType = ohosWindow.WindowType[loopCount1[i]]; let tempType = ohosWindow.WindowType[loopCount1[i]];
console.log(msgStr + 'tempWnd.setWindowType :' + tempType + ' start'); console.log(msgStr + "step: " + i);
tempTypeArr.push(tempType); await setWindowType(tempWnd, tempType, i).catch(err => {
console.log(msgStr + 'for tempTypeArr:' + JSON.stringify(tempTypeArr) + ',i:' + i); console.log(msgStr + 'setWindowType failed' + JSON.stringify(err));
await setWindowType(tempType, i) expect().assertFail();
done();
})
console.log(msgStr + 'getProperties start'); console.log(msgStr + 'getProperties start');
await getProperties(tempType, i) let winProperties;
winProperties = await tempWnd.getProperties().catch((err) => {
console.error(msgStr + 'Failed to obtain the window properties. Cause: ' + JSON.stringify(err));
expect().assertFail();
done();
});
expect(!!winProperties).assertTrue();
expect(winProperties.type === tempType).assertTrue();
if (i == loopCount1.length - 1) { if (i == loopCount1.length - 1) {
console.log(msgStr + 'tempWnd.getProperties i=' + i + ' , loopCount1.length-1==' + loopCount1.length); await tempWnd.destroy();
tempWnd.destroy();
done(); done();
} }
} }
}) })
/** /**
* @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_004 * @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_004
* @tc.name Test setWindowTypeTest4 * @tc.name Test setWindowTypeTest4
* @tc.desc Verify the scene of setting illegal window type * @tc.desc Verify the scene of setting illegal window type
*/ */
it('setWindowTypeTest4', 0, async function (done) { it('setWindowTypeTest4', 0, async function (done) {
let caseName = 'setWindowTypeTest4'; let caseName = 'setWindowTypeTest4';
...@@ -1807,125 +1398,45 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -1807,125 +1398,45 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let tempWnd = null let tempWnd = null
function create() { function createWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.create(context, windowId, baseWndType, (err, data) => { 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) { if (!!data) {
tempWnd = data
try {
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
}
resolve(data) resolve(data)
} }
else { else {
unexpectedError(err, caseName, 'ohosWindow.create', done); reject(null)
}
})
})
}
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) { tempWnd = await createWin().catch(err => {
return new Promise(function (resolve, reject) { console.info(`ohosWindow.create failed error: ${JSON.stringify(err)}`)
ohosWindow.find(windowId, (err, data) => { expect().assertFail();
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); done();
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); })
console.log(msgStr + 'ohosWindow.find !!data' + !!data); expect(!!tempWnd).assertTrue();
if (err && err.code) { tempWnd.setWindowType(changedWndType, async (err, data) => {
try { if (!!data) {
expect(true).assertTrue(); await tempWnd.destroy();
} catch (error) { unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } else {
} try {
} else { expect(err.code == 1003).assertTrue();
unexpectedError(err, caseName, 'tempWnd.setWindowType', done); } catch (error) {
} console.info(`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`)
resolve(data) }
done(); await tempWnd.destroy();
}) 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_DESTROY_JSAPI_002 * @tc.number SUB_WINDOW_DESTROY_JSAPI_002
* @tc.name Test destroyTest2 * @tc.name Test destroyTest2
* @tc.desc Verification window destruction scenario * @tc.desc Verification window destruction scenario
*/ */
it('destroyTest2', 0, async function (done) { it('destroyTest2', 0, async function (done) {
let caseName = 'destroyTest2'; let caseName = 'destroyTest2';
...@@ -1935,72 +1446,47 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -1935,72 +1446,47 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let tempWnd = null let tempWnd = null
function create() { function createWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.create(context, windowId, baseWndType, (err, data) => { 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) { if (!!data) {
tempWnd = data
try {
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
resolve(data) resolve(data)
} else { } else {
unexpectedError(err, caseName, 'ohosWindow.create', done); reject(null)
} }
}) })
}) })
} }
function destroy() { tempWnd = await createWin().catch(err => {
return new Promise(function (resolve, reject) { console.info(`ohosWindow.create failed error: ${JSON.stringify(err)}`)
tempWnd.destroy((err, data) => { expect().assertFail();
console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); done();
console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); })
console.log(msgStr + 'tempWnd.destroy !!data' + !!data); expect(!!tempWnd).assertTrue();
if (err && err.code) { tempWnd.destroy(async (err, data) => {
unexpectedError(err, caseName, 'ohosWindow.destroy', done); if (err && err.code) {
} else { unexpectedError(err, caseName, 'ohosWindow.destroy', done);
try { } else {
expect(!data).assertTrue(); try {
} catch (error) { expect(!data).assertTrue();
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) } 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)); await ohosWindow.find(windowId).then((data) => {
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data); }).catch((err) => {
if (err && err.code) { console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
try { expect(err.code == 1001).assertTrue();
expect(err.code == 1001).assertTrue(); done();
} 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_LOADCONTENT_JSAPI_007 * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_007
* @tc.name Test loadContentTest7 * @tc.name Test loadContentTest7
* @tc.desc Verify the scenario of loading an existing page * @tc.desc Verify the scenario of loading an existing page
*/ */
it('loadContentTest7', 0, async function (done) { it('loadContentTest7', 0, async function (done) {
let caseName = 'loadContentTest7'; let caseName = 'loadContentTest7';
...@@ -2010,124 +1496,43 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -2010,124 +1496,43 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let tempWnd = null let tempWnd = null
function create() { function createWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.create(context, windowId, baseWndType, (err, data) => { 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) { if (!!data) {
tempWnd = data resolve(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)
})
})
}
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 { } else {
try { reject(null)
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} }
resolve(data)
}) })
}) })
} }
function destroy(params) { tempWnd = await createWin().catch(err => {
return new Promise(function (resolve, reject) { console.info(`ohosWindow.create failed error: ${JSON.stringify(err)}`)
tempWnd.destroy((err, data) => { expect().assertFail();
console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); done();
console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); })
console.log(msgStr + 'tempWnd.destroy !!data' + !!data); expect(!!tempWnd).assertTrue();
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() tempWnd.loadContent('pages/index', async (err, data) => {
.then(function (params) { if (err && err.code) {
console.log(msgStr + 'create then: ' + JSON.stringify(params)) unexpectedError(err, caseName, 'tempWnd.loadContent', done);
return loadContent() } else {
}).then(function (params) { try {
return find() expect(!data).assertTrue();
}).then(function (params) { } catch (error) {
return destroy(params) console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`)
}).then(function (params) { }
return findAgain(params) await tempWnd.destroy();
}) done()
}
})
}) })
/** /**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_008 * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_008
* @tc.name Test loadContentTest8 * @tc.name Test loadContentTest8
* @tc.desc Verify the scenario of loading a page that does not exist * @tc.desc Verify the scenario of loading a page that does not exist
*/ */
it('loadContentTest8', 0, async function (done) { it('loadContentTest8', 0, async function (done) {
let caseName = 'loadContentTest8'; let caseName = 'loadContentTest8';
...@@ -2137,1111 +1542,575 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -2137,1111 +1542,575 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let tempWnd = null let tempWnd = null
function create() { function createWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.create(context, windowId, baseWndType, (err, data) => { 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) { if (!!data) {
tempWnd = data resolve(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 { } else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done); reject(null)
} }
resolve(data)
done();
}) })
}) })
} }
await create() tempWnd = await createWin().catch(err => {
.then(function (params) { console.info(`ohosWindow.create failed error: ${JSON.stringify(err)}`)
console.log(msgStr + 'create then: ' + JSON.stringify(params)) expect().assertFail();
return loadContent() done();
}).then(function (params) { })
return find() expect(!!tempWnd).assertTrue();
}).then(function (params) { tempWnd.loadContent(null, async (err, data) => {
return destroy(params) if (err && err.code) {
}).then(function (params) { try {
return findAgain(params) expect(err.code === 1003).assertTrue();
}) } catch (error) {
console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`)
}
await tempWnd.destroy();
done()
} else {
await tempWnd.destroy();
unexpectedError(err, caseName, 'tempWnd.loadContent', done);
}
})
}) })
/** /**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_009 * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_009
* @tc.name Test loadContentTest9 * @tc.name Test loadContentTest9
* @tc.desc Verify the scenario of loading an existing page * @tc.desc Verify the scenario of loading an existing page
*/ */
it('loadContentTest9', 0, async function (done) { it('loadContentTest9', 0, async function (done) {
let caseName = 'loadContentTest9'; let caseName = 'loadContentTest9';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
windowStage.loadContent('pages/index/index.ets', (err, data) => {
function loadContent() { if (err && err.code) {
return new Promise(function (resolve, reject) { unexpectedError(err, caseName, 'windowStage.loadContent', done);
windowStage.loadContent('pages/index/index.ets', (err, data) => { console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err));
if (err && err.code) { } else {
unexpectedError(err, caseName, 'windowStage.loadContent', done); try {
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); expect(!data).assertTrue();
} else { } catch (error) {
try { console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`)
expect(!data).assertTrue(); }
} catch (error) { console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data));
console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) done();
} }
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.number SUB_WINDOW_LOADCONTENT_JSAPI_010
* @tc.name Test loadContentTest10 * @tc.name Test loadContentTest10
* @tc.desc Verify the scenario of loading an existing page * @tc.desc Verify the scenario of loading an existing page
*/ */
it('loadContentTest10', 0, async function (done) { it('loadContentTest10', 0, async function (done) {
let caseName = 'loadContentTest10'; let caseName = 'loadContentTest10';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
function loadContent() { try {
return new Promise(function (resolve, reject) { windowStage.loadContent(null, (err, data) => {
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err));
try { try {
windowStage.loadContent(null, (err, data) => { expect(false).assertTrue();
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); } catch (error) {
try { console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`)
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(); done();
}) });
} 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();
} }
console.log(msgStr + 'end');
await loadContent()
.then(function (params) {
console.log(msgStr + 'loadContent then: ' + JSON.stringify(params))
})
}) })
/** /**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_011 * @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_011
* @tc.name Test loadContentTest11 * @tc.name Test loadContentTest11
* @tc.desc Verify the scenario of loading an existing page * @tc.desc Verify the scenario of loading an existing page
*/ */
it('loadContentTest11', 0, async function (done) { it('loadContentTest11', 0, async function (done) {
let caseName = 'loadContentTest11'; let caseName = 'loadContentTest11';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
function loadContent() { windowStage.loadContent('pages/index/index.ets', abilityStorage, (err, data) => {
return new Promise(function (resolve, reject) { if (err && err.code) {
windowStage.loadContent('pages/index/index.ets', abilityStorage, (err, data) => { unexpectedError(err, caseName, 'windowStage.loadContent', done);
if (err && err.code) { console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err));
unexpectedError(err, caseName, 'windowStage.loadContent', done); } else {
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); try {
} else { expect(!data).assertTrue();
try { } catch (error) {
expect(!data).assertTrue(); console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`)
} catch (error) { }
console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) done();
} console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data));
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.number SUB_WINDOW_LOADCONTENT_JSAPI_012
* @tc.name Test loadContentTest12 * @tc.name Test loadContentTest12
* @tc.desc Verify the scenario of loading an existing page * @tc.desc Verify the scenario of loading an existing page
*/ */
it('loadContentTest12', 0, async function (done) { it('loadContentTest12', 0, async function (done) {
let caseName = 'loadContentTest12'; let caseName = 'loadContentTest12';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
function loadContent() { try {
return new Promise(function (resolve, reject) { windowStage.loadContent(null, abilityStorage, (err, data) => {
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err));
try { try {
windowStage.loadContent(null, abilityStorage, (err, data) => { expect(false).assertTrue();
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err)); } catch (error) {
try { console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`)
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(); done();
}) });
} 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.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_003
* @tc.name Test createSubWindowTest3 * @tc.name Test createSubWindowTest3
* @tc.desc Verify the scenario of creating an auxiliary window * @tc.desc Verify the scenario of creating an auxiliary window
*/ */
it('createSubWindowTest3', 0, async function (done) { it('createSubWindowTest3', 0, async function (done) {
let caseName = 'createSubWindowTest3'; let caseName = 'createSubWindowTest3';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let tempWnd = null let subWnd = null
function createSubWindow() { function createSubWindow() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
windowStage.createSubWindow('createSubWindowTest3', (err, data) => { windowStage.createSubWindow('createSubWindowTest3', (err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.createSubWindow', done); reject(null)
console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest3) err=' + JSON.stringify(err)); console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest3) err=' + JSON.stringify(err));
} else { } else {
try { resolve(data)
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() { function findWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.find('createSubWindowTest3', (err, data) => { 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) { if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done); reject(false)
} else { } else {
try { resolve(data)
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} }
resolve(data)
}) })
}) })
} }
function destroy(params) { function destroyWin(win) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
tempWnd.destroy((err, data) => { win.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) { if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.destroy', done); reject(null)
} else { } else {
try { resolve(true)
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} }
resolve(data)
}) })
}) })
} }
function findAgain(params) { subWnd = await createSubWindow().catch(err => {
return new Promise(function (resolve, reject) { console.info(`ohosWindow.create failed error: ${JSON.stringify(err)}`)
ohosWindow.find('createSubWindowTest3', (err, data) => { expect().assertFail();
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err)); done();
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data)); })
console.log(msgStr + 'ohosWindow.find !!data' + !!data); expect(!!subWnd).assertTrue();
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() let subWindow;
.then(function (params) { subWindow = await findWin().catch(err => {
console.log(msgStr + 'create then: ' + JSON.stringify(params)) console.info(`ohosWindow.find failed error: ${JSON.stringify(err)}`)
return find() expect().assertFail();
}).then(function (params) { done();
return destroy(params) })
}).then(function (params) {
return findAgain(params) await destroyWin(subWindow).catch(err => {
}) console.info(`ohosWindow.destroy failed error: ${JSON.stringify(err)}`)
expect().assertFail();
done();
})
let subWindowLast;
subWindowLast = await findWin().catch(err => {
console.info(`ohosWindow.find failed error: ${JSON.stringify(err)}`)
expect(!err).assertTrue();
done()
})
}) })
/** /**
* @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_004 * @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_004
* @tc.name Test createSubWindowTest4 * @tc.name Test createSubWindowTest4
* @tc.desc Verify the scene of entering illegal values to create an auxiliary window * @tc.desc Verify the scene of entering illegal values to create an auxiliary window
*/ */
it('createSubWindowTest4', 0, async function (done) { it('createSubWindowTest4', 0, async function (done) {
let caseName = 'createSubWindowTest4'; let caseName = 'createSubWindowTest4';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
try {
function createSubWindow() { windowStage.createSubWindow(null, (err, data) => {
return new Promise(function (resolve, reject) { console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err));
try { try {
windowStage.createSubWindow(null, (err, data) => { expect(false).assertTrue();
console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err)); } catch (error) {
try { console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`)
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));
} }
done(); done();
}) });
} catch (err) {
try {
expect(err.code === 401).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
done();
console.log(msgStr + 'windowStage.createSubWindow(null) catch err=' + JSON.stringify(err));
} }
await createSubWindow()
.then(function (params) {
console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params))
})
}) })
/** /**
* @tc.number SUB_WINDOW_GETSUBWINDOW_JSAPI_002 * @tc.number SUB_WINDOW_GETSUBWINDOW_JSAPI_002
* @tc.name Test getSubWindowTest2 * @tc.name Test getSubWindowTest2
* @tc.desc Verify the scene of obtaining all auxiliary sub windows * @tc.desc Verify the scene of obtaining all auxiliary sub windows
*/ */
it('getSubWindowTest2', 0, async function (done) { it('getSubWindowTest2', 0, async function (done) {
let caseName = 'getSubWindowTest2'; let caseName = 'getSubWindowTest2';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
function getSubWindow() { windowStage.getSubWindow((err, data) => {
return new Promise(function (resolve, reject) { if (err && err.code) {
windowStage.getSubWindow((err, data) => { unexpectedError(err, caseName, 'windowStage.getSubWindow', done);
if (err && err.code) { console.log(msgStr + 'windowStage.getSubWindow(null) err=' + JSON.stringify(err));
unexpectedError(err, caseName, 'windowStage.getSubWindow', done); } else {
console.log(msgStr + 'windowStage.getSubWindow(null) err=' + JSON.stringify(err)); try {
} else { expect(!!data).assertTrue();
try { } catch (error) {
expect(!!data).assertTrue(); console.info(`windowStage.getSubWindow catch error: ${JSON.stringify(error)}`)
} catch (error) { }
console.info(`windowStage.getSubWindow catch error: ${JSON.stringify(error)}`) done();
} console.log(msgStr + 'windowStage.getSubWindow end data=' + JSON.stringify(data));
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.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_002
* @tc.name Test setPrivacyModeTest3 * @tc.name Test setPrivacyModeTest2
* @tc.desc Verify that the auxiliary window is set as the security layer * @tc.desc Verify the scene where the application sub window is set as a security layer
*/ */
it('setPrivacyModeTest3', 0, async function (done) { it('setPrivacyModeTest2', 0, async function (done) {
let caseName = 'setPrivacyModeTest3'; let caseName = 'setPrivacyModeTest2';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow)); console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow));
let mainWnd = null; let tempWnd = null;
function createSubWindow() { function createWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
windowStage.createSubWindow('setPrivacyModeTest3', (err, data) => { ohosWindow.create(context, 'setPrivacyModeTest2', ohosWindow.WindowType.TYPE_SYSTEM_ALERT, (err, data) => {
if (err && err.code) { if (err && err.code) {
console.log(msgStr + 'windowStage.createSubWindow fail err:' + JSON.stringify(err)); console.log(msgStr + 'ohosWindow.create fail err:' + JSON.stringify(err));
try { reject(null)
expect().assertFail();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
done();
} else { } else {
try { resolve(data)
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() { function getWinProperties(win) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.getProperties((err, data) => { win.getProperties((err, data) => {
if (err.code != 0) { if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err)); reject(null)
try {
expect().assertFail();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
done();
} else { } else {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data)); resolve(data)
try {
expect(!data.isPrivacyMode).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} }
resolve(data)
}) })
}) })
} }
function setPrivacyModeTrue() { function setPrivacyModeWin(win, boolean) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.setPrivacyMode(true, (err, data) => { win.setPrivacyMode(boolean, (err) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err)); console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err));
reject(null)
} else { } else {
try { resolve(true)
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() { tempWnd = await createWin().catch(err => {
return new Promise(function (resolve, reject) { console.info(msgStr + `ohosWindow.create failed error: ${JSON.stringify(err)}`)
mainWnd.setPrivacyMode(false, (err, data) => { expect().assertFail();
if (err && err.code) { done();
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done); })
console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err)); expect(!!tempWnd).assertTrue();
} else { await setPrivacyModeWin(tempWnd, true).catch(err => {
try { console.info(msgStr + `ohosWindow.setPrivacyMode failed error: ${JSON.stringify(err)}`)
expect(!data).assertTrue(); expect().assertFail();
} catch (error) { done();
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) })
} let windowProperties_true;
console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data)); windowProperties_true = await getWinProperties(tempWnd).catch(err => {
} console.info(msgStr + `ohosWindow.getProperties failed error: ${JSON.stringify(err)}`)
resolve(data) expect().assertFail();
}) done();
}) })
} console.info(msgStr + `ohosWindow.windowProperties_true : ${JSON.stringify(windowProperties_true)}`)
expect(windowProperties_true.isPrivacyMode).assertTrue();
function getProperties3() { await setPrivacyModeWin(tempWnd, false).catch(err => {
return new Promise(function (resolve, reject) { console.info(msgStr + `ohosWindow.setPrivacyMode failed error: ${JSON.stringify(err)}`)
mainWnd.getProperties((err, data) => { expect().assertFail();
if (err.code != 0) { done();
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err)); })
try { let windowProperties_false;
expect().assertFail(); windowProperties_false = await getWinProperties(tempWnd).catch(err => {
} catch (error) { console.info(msgStr + `ohosWindow.getProperties failed error: ${JSON.stringify(err)}`)
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) expect().assertFail();
} done();
done(); })
} else { console.info(msgStr + `ohosWindow.windowProperties_false : ${JSON.stringify(windowProperties_false)}`)
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data)); expect(!windowProperties_false.isPrivacyMode).assertTrue();
try { await tempWnd.destroy();
expect(!data.isPrivacyMode).assertTrue(); done();
} catch (error) { })
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) /**
} * @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_003
} * @tc.name Test setPrivacyModeTest3
resolve(data) * @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 tempWnd = null;
function find() { function createSubWindowFun() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.find('setPrivacyModeTest3', (err, data) => { windowStage.createSubWindow('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) { if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done); console.log(msgStr + 'windowStage.createSubWindow fail err:' + JSON.stringify(err));
reject(null)
} else { } else {
try { resolve(data)
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} }
resolve(data)
}) })
}) })
} }
function destroy(params) { function getPropertiesFun(win) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
mainWnd.destroy((err, data) => { win.getProperties((err, data) => {
console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err)); if (err.code != 0) {
console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data)); reject(null)
console.log(msgStr + 'tempWnd.destroy !!data' + !!data);
if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.destroy', done);
} else { } else {
try { resolve(data)
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} }
resolve(data)
}) })
}) })
} }
function findAgain(params) { function setPrivacyModeFun(win, boolean) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.find('setPrivacyModeTest2', (err, data) => { win.setPrivacyMode(boolean, (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) { if (err && err.code) {
try { reject(null)
expect(true).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} else { } else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done); resolve(true)
} }
resolve(data)
done();
}) })
}) })
} }
await createSubWindow() tempWnd = await createSubWindowFun().catch(err => {
.then(function (params) { console.info(msgStr + `ohosWindow.create failed error: ${JSON.stringify(err)}`)
console.log(msgStr + 'create then: ' + JSON.stringify(params)) expect().assertFail();
return getProperties() done();
}) })
.then(function (params) { expect(!!tempWnd).assertTrue();
console.log(msgStr + 'getProperties then: ' + JSON.stringify(params)) await setPrivacyModeFun(tempWnd, true).catch(err => {
return setPrivacyModeTrue() console.info(msgStr + `ohosWindow.setPrivacyMode failed error: ${JSON.stringify(err)}`)
}) expect().assertFail();
.then(function (params) { done();
console.log(msgStr + 'setPrivacyModeTrue then: ' + JSON.stringify(params)) })
return getProperties2() let windowProperties_true;
}) windowProperties_true = await getPropertiesFun(tempWnd).catch(err => {
.then(function (params) { console.info(msgStr + `ohosWindow.getProperties failed error: ${JSON.stringify(err)}`)
console.log(msgStr + 'getProperties2 then: ' + JSON.stringify(params)) expect().assertFail();
return setPrivacyModeFalse() done();
}) })
.then(function (params) { console.info(msgStr + `ohosWindow.windowProperties_true : ${JSON.stringify(windowProperties_true)}`)
console.log(msgStr + 'setPrivacyModeFalse then: ' + JSON.stringify(params)) expect(windowProperties_true.isPrivacyMode).assertTrue();
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)
})
})
/** await setPrivacyModeFun(tempWnd, false).catch(err => {
* @tc.number SUB_WINDOW_SETDENSITTYDPI_JSAPI_002 console.info(msgStr + `ohosWindow.setPrivacyMode failed error: ${JSON.stringify(err)}`)
* @tc.name Test setDensityDpiTest2 expect().assertFail();
* @tc.desc Verify Sets the screen pixel done();
*/
it('setDensityDpiTest2', 0, async function (done) {
let caseName = 'setDensityDpiTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let screens = await screenManager.getAllScreens().catch(errScreen => {
unexpectedError(errScreen, caseName, 'screenManager.getAllScreen', done);
}) })
console.log(msgStr + 'screenManager.getAllScreen' + JSON.stringify(screens)); let windowProperties_false;
try { windowProperties_false = await getPropertiesFun(tempWnd).catch(err => {
expect(!!screens).assertTrue(); console.info(msgStr + `ohosWindow.getProperties failed error: ${JSON.stringify(err)}`)
} catch (error) { expect().assertFail();
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) done();
} })
let currentDeviceDefaultDpi; console.info(msgStr + `ohosWindow.windowProperties_false : ${JSON.stringify(windowProperties_false)}`)
let currentDeviceDefault = null; expect(!windowProperties_false.isPrivacyMode).assertTrue();
display.getDefaultDisplay(async (err, data) => { await tempWnd.destroy();
if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
currentDeviceDefault = data;
currentDeviceDefaultDpi = parseInt(currentDeviceDefault.densityDPI)
let dpiItem = [-80, 80, 1000, 160, 0, 320, 188.88, 0, 640, 300, currentDeviceDefaultDpi];
for (let i = 0; i < dpiItem.length; i++) {
screens[0].setDensityDpi(dpiItem[i], (errDpi, dataDpi) => {
if (errDpi.code) {
console.error('Failed to set DensityDpi. Cause: ' + JSON.stringify(err) + dpiItem[i]);
return;
}
console.log(msgStr + 'screen.setDensityDpi success set DPI ' + dpiItem[i]);
display.getDefaultDisplay((error, result) => {
if (error.code) {
console.error(msgStr + 'screen.setDensityDpi display.getDefaultDisplay failed');
return;
console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay' + JSON.stringify(result));
let isEqual = Number(result.densityDPI) == parseInt(dpiItem[i])
console.log(msgStr + 'same ? ' + isEqual)
try {
expect(isEqual).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
})
})
}
});
console.log(msgStr + 'done ');
done(); done();
}) })
/** /**
* @tc.number SUB_WINDOW_SETPREFERREDORIENTATION_JSAPI_002 * @tc.number SUB_WINDOW_SETPREFERREDORIENTATION_JSAPI_002
* @tc.name Test setPreferredOrientationTest2 * @tc.name Test setPreferredOrientationTest2
* @tc.desc Sets the display direction property of the window * @tc.desc Sets the display direction property of the window
*/ */
it('setPreferredOrientationTest2', 0, async function (done) { it('setPreferredOrientationTest2', 0, async function (done) {
let caseName = 'setPreferredOrientationTest2'; let caseName = 'setPreferredOrientationTest2';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let mainWin = null; 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 num = 0
let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED', let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED',
'LANDSCAPE_INVERTED', 'AUTO_ROTATION', 'AUTO_ROTATION_PORTRAIT', 'AUTO_ROTATION_LANDSCAPE', 'LANDSCAPE_INVERTED', 'AUTO_ROTATION', 'AUTO_ROTATION_PORTRAIT', 'AUTO_ROTATION_LANDSCAPE',
'AUTO_ROTATION_RESTRICTED', 'AUTO_ROTATION_PORTRAIT_RESTRICTED', 'AUTO_ROTATION_LANDSCAPE_RESTRICTED', 'LOCKED', 'UNSPECIFIED']; 'AUTO_ROTATION_RESTRICTED', 'AUTO_ROTATION_PORTRAIT_RESTRICTED', 'AUTO_ROTATION_LANDSCAPE_RESTRICTED', 'LOCKED', 'UNSPECIFIED'];
function setPreferredOrientation(i) { function setPreferredOrientationFun(win, orientation) {
return new Promise(function (resolve, reject) { return new Promise((resolve, reject) => {
let orientation = ohosWindow.Orientation[orientationItem[i]] try {
mainWin.setPreferredOrientation(orientation, (err, data) => { win.setPreferredOrientation(orientation, (err) => {
if (err && err.code) { if (err.code) {
console.log(msgStr + 'window.setPreferredOrientation failed set error' + orientation); console.error(msgStr + 'Failed to set window orientation. Cause: ' + JSON.stringify(err));
} reject(null)
num++ } else {
if (++i < orientationItem.length) { console.info(msgStr + 'Succeeded in setting window orientation.');
setPreferredOrientation(i) resolve(true)
console.log(msgStr + 'jixuzhixing i: ' + i); }
} else { });
console.log(msgStr + 'i++<orientationItem.length i: ' + i + ' ,orientationItem.length:' + orientationItem.length); } catch (exception) {
} console.error(msgStr + 'Failed to set window orientation. Cause: ' + JSON.stringify(exception));
if (num == orientationItem.length) done(); reject(null)
console.log(msgStr + 'success set window.setPreferredOrientation ' + orientation + JSON.stringify(data)); }
resolve(data)
})
}) })
} }
await getMainWindow() mainWin = await windowStage.getMainWindow().catch((err) => {
.then(function (params) { console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
console.log(msgStr + 'setPreferredOrientation then: ' + JSON.stringify(params)) expect().assertFail();
return setPreferredOrientation(0) done();
}) });
expect(!!mainWin).assertTrue();
for (let i = 0;i < orientationItem.length; i++) {
let orientation = ohosWindow.Orientation[orientationItem[i]]
await setPreferredOrientationFun(mainWin, orientation).catch((err) => {
console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
expect().assertFail();
done();
});
console.info(msgStr + 'Succeeded in setting window orientation. orientation: ' + orientation + "step: " + i);
}
done()
}) })
/** /**
* @tc.number SUB_WINDOW_SETFORBIDSPLITMOVE_JSAPI_002 * @tc.number SUB_WINDOW_SETFORBIDSPLITMOVE_JSAPI_002
* @tc.name Test setForbidSplitMoveTest2 * @tc.name Test setForbidSplitMoveTest2
* @tc.desc Sets whether Windows are forbidden to move in split screen mode * @tc.desc Sets whether Windows are forbidden to move in split screen mode
*/ */
it('setForbidSplitMoveTest2', 0, async function (done) { it('setForbidSplitMoveTest2', 0, async function (done) {
let caseName = 'setForbidSplitMoveTest2'; let caseName = 'setForbidSplitMoveTest2';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let mainWin = await windowStage.getMainWindow().catch(err => {
function setForbidSplitMoveFun(win, boolean) {
return new Promise((resolve, reject) => {
win.setForbidSplitMove(boolean, (err, data) => {
if (err.code) {
reject(null)
} else {
console.log(msgStr + 'success set window.setForbidSplitMove drag is prohibited' + JSON.stringify(data));
resolve(true)
}
})
})
}
let mainWin;
mainWin = await windowStage.getMainWindow().catch(err => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done); unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
expect().assertFail();
done();
}); });
console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin));
try { expect(!!mainWin).assertTrue();
expect(!!mainWin).assertTrue();
} catch (error) { await setForbidSplitMoveFun(mainWin, true).catch(err => {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`) console.log(msgStr + 'failed set window.setForbidSplitMove drag is prohibited, error: ' + JSON.stringify(err));
} expect().assertFail();
await mainWin.setForbidSplitMove(true, (err, data) => { done();
if (err.code) {
console.log(msgStr + 'failed set window.setForbidSplitMove drag is prohibited');
return;
}
console.log(msgStr + 'success set window.setForbidSplitMove drag is prohibited' + JSON.stringify(data));
}) })
await mainWin.setForbidSplitMove(false, (err, data) => { await setForbidSplitMoveFun(mainWin, false).catch(err => {
if (err.code) { console.log(msgStr + 'failed set window.setForbidSplitMove drag is prohibited, error: ' + JSON.stringify(err));
console.log(msgStr + 'failed set window.setForbidSplitMove you can drag it now'); expect().assertFail();
return; done();
}
console.log(msgStr + 'success set window.setForbidSplitMove you can drag it now' + JSON.stringify(data));
}) })
console.log(msgStr + 'done '); console.log(msgStr + 'done ');
done(); done();
}) })
/** /**
* @tc.number SUB_WINDOW_SNAPSHOT_JSAPI_002 * @tc.number SUB_WINDOW_SNAPSHOT_JSAPI_002
* @tc.name Test snapshotTest2 * @tc.name Test snapshotTest2
* @tc.desc Scenario of screenshot of verification window * @tc.desc Scenario of screenshot of verification window
*/ */
it('snapshotTest2', 0, async function (done) { it('snapshotTest2', 0, async function (done) {
let caseName = 'snapshotTest2'; let caseName = 'snapshotTest2';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let mainWin = await windowStage.getMainWindow().catch(err => { let mainWin = null
mainWin = await windowStage.getMainWindow().catch(err => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done); unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
}); });
console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin));
try {
expect(!!mainWin).assertTrue(); expect(!!mainWin).assertTrue();
} catch (error) { mainWin.snapshot((err, data) => {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
await mainWin.snapshot((err, data) => {
if (err && err.code) { if (err && err.code) {
console.log(msgStr + 'snapshot err.code:' + JSON.stringify(err.code)); console.log(msgStr + 'snapshot err.code:' + JSON.stringify(err.code));
expect().assertFail();
done();
return; return;
} }
done();
console.log(msgStr + 'snapshot success data:' + JSON.stringify(data)); console.log(msgStr + 'snapshot success data:' + JSON.stringify(data));
}) })
done();
}) })
/** /**
* @tc.number SUB_WINDOW_DIALOGTARGETTOUCH_JSAPI_002 * @tc.number SUB_WINDOW_DIALOGTARGETTOUCH_JSAPI_002
* @tc.name Test dialogTargetTouchTest2 * @tc.name Test dialogTargetTouchTest2
* @tc.desc Verify the scenario of opening modal window * @tc.desc Verify the scenario of opening modal window
*/ */
it('dialogTargetTouchTest2', 0, async done => { it('dialogTargetTouchTest2', 0, async done => {
let caseName = 'dialogTargetTouchTest2'; let caseName = 'dialogTargetTouchTest2';
...@@ -3250,44 +2119,25 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -3250,44 +2119,25 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let tempType = ohosWindow.WindowType.TYPE_DIALOG let tempType = ohosWindow.WindowType.TYPE_DIALOG
let dialogTargetTouchTest2Win = null let dialogTargetTouchTest2Win = null
function create() { ohosWindow.create(context, 'dialogTargetTouchTest2', tempType, async (err, data) => {
return new Promise(function (resolve, reject) { if (err && err.code) {
ohosWindow.create(context, 'dialogTargetTouchTest2', tempType, (err, data) => { unexpectedError(err, caseName, 'ohosWindow.create', done);
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err)); } else {
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data)); dialogTargetTouchTest2Win = data
if (err && err.code) { try {
unexpectedError(err, caseName, 'ohosWindow.create', done); expect(!!dialogTargetTouchTest2Win).assertTrue();
} else { } catch (error) {
dialogTargetTouchTest2Win = data console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
try { }
expect(!!dialogTargetTouchTest2Win).assertTrue(); await dialogTargetTouchTest2Win.destroy()
} 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(); done();
}) }
} })
await create()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return destroy()
})
}) })
/** /**
* @tc.number SUB_WINDOW_ANIMATIONFORSHOWN_JSAPI_002 * @tc.number SUB_WINDOW_ANIMATIONFORSHOWN_JSAPI_002
* @tc.name Test animationForShownTest2 * @tc.name Test animationForShownTest2
* @tc.desc Verify window custom animation configuration of the scene * @tc.desc Verify window custom animation configuration of the scene
*/ */
it('animationForShownTest2', 0, async function (done) { it('animationForShownTest2', 0, async function (done) {
let caseName = 'animationForShownTest2'; let caseName = 'animationForShownTest2';
...@@ -3297,7 +2147,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -3297,7 +2147,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let wndId = 'animationForShownTest2'; let wndId = 'animationForShownTest2';
let baseType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT; let baseType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT;
let tempWnd = null; let tempWnd = null;
ohosWindow.create(context, wndId, baseType, (err, data) => { ohosWindow.create(context, wndId, baseType, async (err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done);
} else { } else {
...@@ -3330,27 +2180,23 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -3330,27 +2180,23 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
context.completeTransition(true) context.completeTransition(true)
console.info(msgStr + 'complete transition end'); console.info(msgStr + 'complete transition end');
} }
tempWnd.destroy(); await tempWnd.destroy();
done(); done();
} }
}); });
}) })
/** /**
* @tc.number SUB_WINDOW_GETCUTOUTINFO_JSAPI_002 * @tc.number SUB_WINDOW_GETCUTOUTINFO_JSAPI_002
* @tc.name Test getCutoutInfoTest2 * @tc.name Test getCutoutInfoTest2
* @tc.desc Obtain information about unavailable screen areas such as the hole screen, fringe screen, and waterfall screen * @tc.desc Obtain information about unavailable screen areas such as the hole screen, fringe screen, and waterfall screen
*/ */
it('getCutoutInfoTest2', 0, async function (done) { it('getCutoutInfoTest2', 0, async function (done) {
let caseName = 'getCutoutInfoTest2'; let caseName = 'getCutoutInfoTest2';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin context==' + JSON.stringify(context)); console.log(msgStr + 'begin context==' + JSON.stringify(context));
let dpClass = display.getDefaultDisplaySync(); let dpClass = display.getDefaultDisplaySync();
try { expect(!!dpClass).assertTrue();
expect(!!dpClass).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
dpClass.getCutoutInfo((err, data) => { dpClass.getCutoutInfo((err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'displayClass.getCutoutInfo', done); unexpectedError(err, caseName, 'displayClass.getCutoutInfo', done);
...@@ -3361,9 +2207,9 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -3361,9 +2207,9 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}) })
}) })
/** /**
* @tc.number SUB_WINDOW_SHOWWITHANIMATION_JSAPI_002 * @tc.number SUB_WINDOW_SHOWWITHANIMATION_JSAPI_002
* @tc.name Test showWithAnimationTest2 * @tc.name Test showWithAnimationTest2
* @tc.desc Displays the current window, playing an animation in the process * @tc.desc Displays the current window, playing an animation in the process
*/ */
it('showWithAnimationTest2', 0, async function (done) { it('showWithAnimationTest2', 0, async function (done) {
let caseName = 'showWithAnimationTest2'; let caseName = 'showWithAnimationTest2';
...@@ -3373,60 +2219,38 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -3373,60 +2219,38 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let baseType = ohosWindow.WindowType.TYPE_FLOAT; let baseType = ohosWindow.WindowType.TYPE_FLOAT;
let tempWnd = null; let tempWnd = null;
function create() { function createWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.create(context, wndId, baseType, (err, data) => { ohosWindow.create(context, wndId, baseType, (err, data) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); reject(null)
} 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 { } else {
console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(animationData)); resolve(data)
resolve(animationData)
} }
}) })
}) })
} }
function destroy() { tempWnd = await createWin().catch(err => {
return new Promise(function (resolve, reject) { console.info(msgStr + `ohosWindow.create failed error: ${JSON.stringify(err)}`)
tempWnd.destroy(); expect().assertFail();
resolve(true) done();
done(); })
}) expect(!!tempWnd).assertTrue();
} tempWnd.showWithAnimation(async (error, animationData) => {
if (error && error.code) {
await create() unexpectedError(error, caseName, 'Failed to show the window with animation', done);
.then(function (params) { } else {
console.log(msgStr + 'create then: ' + JSON.stringify(params)) console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(animationData));
return showWithAnimation() await tempWnd.destroy()
}).then(function (params) { done()
console.log(msgStr + 'showWithAnimation then: ' + JSON.stringify(params)) }
return destroy() })
})
}) })
/** /**
* @tc.number SUB_WINDOW_HIDEWITHANIMATION_JSAPI_002 * @tc.number SUB_WINDOW_HIDEWITHANIMATION_JSAPI_002
* @tc.name Test hideWithAnimationTest2 * @tc.name Test hideWithAnimationTest2
* @tc.desc Hide the current window and play an animation in the process * @tc.desc Hide the current window and play an animation in the process
*/ */
it('hideWithAnimationTest2', 0, async function (done) { it('hideWithAnimationTest2', 0, async function (done) {
let caseName = 'hideWithAnimationTest2'; let caseName = 'hideWithAnimationTest2';
...@@ -3436,65 +2260,58 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -3436,65 +2260,58 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let baseType = ohosWindow.WindowType.TYPE_FLOAT; let baseType = ohosWindow.WindowType.TYPE_FLOAT;
let tempWnd = null let tempWnd = null
function create() { function createWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.create(context, wndId, baseType, (creare_err, data) => { ohosWindow.create(context, wndId, baseType, (creare_err, data) => {
if (creare_err && creare_err.code) { if (creare_err && creare_err.code) {
unexpectedError(creare_err, caseName, 'ohosWindow.create ' + baseType, done); reject(null)
} } else {
try { resolve(data)
tempWnd = data
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
} }
resolve(data)
}) })
}) })
} }
function find() { function findWin() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
ohosWindow.find(wndId, (findErr, findWnd) => { ohosWindow.find(wndId, (findErr, findWnd) => {
if (findErr && findErr.code) { if (findErr && findErr.code) {
unexpectedError(findErr, caseName, 'Failed to hide the window with animation', done); reject(null)
} else { } else {
findWnd.hideWithAnimation((err, data) => { resolve(findWnd)
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() { tempWnd = await createWin().catch(err => {
return new Promise(function (resolve, reject) { console.info(msgStr + `ohosWindow.create failed error: ${JSON.stringify(err)}`)
tempWnd.destroy(); expect().assertFail();
resolve(true) done();
})
expect(!!tempWnd).assertTrue();
let findWnd;
findWnd = await findWin().catch(err => {
console.info(msgStr + `ohosWindow.find failed error: ${JSON.stringify(err)}`)
expect().assertFail();
done();
})
expect(!!findWnd).assertTrue();
findWnd.hideWithAnimation(async (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));
await tempWnd.destroy();
done(); 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_SETASPECTRATIO_JSAPI_001 * @tc.number SUB_WINDOW_SETASPECTRATIO_JSAPI_001
* @tc.name Test setAspectRatioTest1 * @tc.name Test setAspectRatioTest1
* @tc.desc Validate the scenario cancelled after setting the proportion of the content layout of the main window * @tc.desc Validate the scenario cancelled after setting the proportion of the content layout of the main window
*/ */
it('setAspectRatioTest1', 0, async function (done) { it('setAspectRatioTest1', 0, async function (done) {
let caseName = 'setAspectRatioTest1'; let caseName = 'setAspectRatioTest1';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
...@@ -3577,8 +2394,5 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) ...@@ -3577,8 +2394,5 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
await setAspectRatio() await setAspectRatio()
}) })
})
}
)
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册