Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
3c0a6354
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3c0a6354
编写于
2月 15, 2023
作者:
华
华华小仙女
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
解决冲突
Signed-off-by:
N
华华小仙女
<
zhurong18@h-partners.com
>
上级
fddba063
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
1332 addition
and
2518 deletion
+1332
-2518
graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets
...ndowStage/entry/src/main/ets/test/windowCallback.test.ets
+1332
-2518
未找到文件。
graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets
浏览文件 @
3c0a6354
...
...
@@ -101,7 +101,8 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
+
apiName
+
' failed, err: '
;
console
.
log
(
msgStr
+
JSON
.
stringify
(
error
));
try
{
expect(error.code == code).assertTrue();
expect
(
TRUE_FLAG
)
.
assertTrue
();
expect
(
error
.
code
===
code
)
.
assertTrue
();
}
catch
(
error
)
{
console
.
info
(
`ohosWindow.on ${JSON.stringify(error)}`
)
}
...
...
@@ -119,126 +120,150 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
done
();
}
function sleep(time) {
return new Promise(resolve => {
setTimeout(() => {
async
function
sleep
(
time
)
{
let
timeoutId
=
null
;
let
promise
=
new
Promise
(
resolve
=>
{
timeoutId
=
setTimeout
(()
=>
{
resolve
(
'sleep finished'
);
},
time
);
})
let
result
=
await
promise
;
clearTimeout
(
timeoutId
)
}
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_006
* @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
)
{
let
caseName
=
'setSystemBarEnableTest6'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
let
flagStatus = false
;
let
[
flagStatus
,
flagNav
]
=
[
false
,
false
]
;
console
.
log
(
msgStr
+
'begin'
);
listenerData
.
on
=
true
;
listenerData
.
typeStr
=
'systemBarTintChange'
;
function ohosWindowOn() {
ohosWindow
.
on
(
'systemBarTintChange'
,
systembartintstate
=>
{
console
.
log
(
msgStr
+
'ohosWindow.on systembartintstate.regionTint : '
+
JSON
.
stringify
(
systembartintstate
.
regionTint
));
if (flagStatus) {
console.log(msgStr + 'systembartintstate.regionTint[0].type : ' + JSON.stringify(systembartintstate.regionTint[0].type));
console.log(msgStr + 'systembartintstate.regionTint[0].isEnable : ' + JSON.stringify(systembartintstate.regionTint[0].isEnable));
console
.
log
(
msgStr
+
'ohosWindow.on flagNav : '
+
JSON
.
stringify
(
flagNav
));
console
.
log
(
msgStr
+
'ohosWindow.on flagStatus : '
+
JSON
.
stringify
(
flagStatus
));
console
.
log
(
msgStr
+
'ohosWindow.on flagStatus && flagNav : '
+
(
flagStatus
&&
flagNav
));
if
(
flagStatus
||
flagNav
)
{
try
{
expect
(
!!
systembartintstate
)
.
assertTrue
();
expect(systembartintstate.regionTint[0].type == 3 && systembartintstate.regionTint[0].isEnable
).assertTrue();
expect
(
!!
systembartintstate
.
regionTint
)
.
assertTrue
();
}
catch
(
error
)
{
console.info(msgStr +
`ohosWindow.on ${JSON.stringify(error)}`)
console
.
info
(
`ohosWindow.on ${JSON.stringify(error)}`
)
}
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
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
windowStage
.
getMainWindow
((
err
,
data
)
=>
{
console.log(msgStr + 'getMainWindow data
:
' + JSON.stringify(data));
console
.
log
(
msgStr
+
'getMainWindow data'
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
try {
mainWnd = data;
expect(!!data).assertTrue();
} catch (error) {
console.info(msgStr + `getMainWindow ${JSON.stringify(error)}`)
}
console
.
log
(
msgStr
+
'windowStage getMainWindow failed'
);
reject
(
null
)
}
else
{
resolve
(
data
);
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
console
.
log
(
msgStr
+
'windowStage getMainWindow successed'
);
}
})
})
}
function show() {
function
show
(
win
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd.show((err, data) => {
console.log(msgStr + 'mainWnd.show err' + JSON.stringify(err));
console.log(msgStr + 'mainWnd.show data' + JSON.stringify(data));
win
.
show
((
err
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.show', done);
}
try {
expect(!data).assertTrue();
} catch (err) {
console.info(msgStr + `mainWnd.show err: ${JSON.stringify(err)}`)
}
console
.
log
(
msgStr
+
'mainWnd.show failed'
);
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.show success'
);
resolve(data)
resolve
(
true
)
}
})
})
}
function setFullScreen() {
function
setFullScreen
(
win
)
{
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
));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done);
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(msgStr + `setFullScreen ${JSON.stringify(error)}`)
}
console
.
log
(
msgStr
+
'mainWnd.setFullScreen failed'
);
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.setFullScreen success'
);
resolve(data)
flagNav
=
true
;
resolve
(
true
)
}
})
})
}
function setSystemBarEnable
Status(
) {
function
setSystemBarEnable
Navigation
(
win
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd.setSystemBarEnable(['status
'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable
status data=
==' + JSON.stringify(data));
win
.
setSystemBarEnable
([
'navigation
'
],
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setSystemBarEnable
navigation JSON.stringify(data)
=='
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
console.log(msgStr + 'mainWnd.setSystemBarEnable status err===' + JSON.stringify(err));
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done);
console
.
log
(
msgStr
+
'mainWnd.setSystemBarEnable failed'
);
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()
await show()
await setFullScreen()
await setSystemBarEnableStatus()
ohosWindowOn()
let
mainWnd
=
null
;
mainWnd
=
await
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
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
...
...
@@ -250,10 +275,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
let
[
flagStatus
,
flagNav
]
=
[
false
,
false
];
console
.
log
(
msgStr
+
'begin'
);
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
function ohosWindowOn() {
ohosWindow
.
on
(
'systemBarTintChange'
,
systembartintstate
=>
{
console
.
log
(
msgStr
+
'ohosWindow.on systembartintstate :'
+
JSON
.
stringify
(
systembartintstate
));
console
.
log
(
msgStr
+
'ohosWindow.on systembartintstate.regionTint : '
+
JSON
.
stringify
(
systembartintstate
.
regionTint
));
...
...
@@ -264,108 +286,108 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`ohosWindow.on catch err: ${JSON.stringify(error)}`
)
}
ohosWindow
.
off
(
'systemBarTintChange'
)
done
();
}
})
}
let mainWnd = null;
console.log(msgStr + 'mainWnd = 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 {
mainWnd = data;
expect(!!data).assertTrue();
} catch (error) {
console.info(`ohosWindow.on ${JSON.stringify(error)}`)
}
console
.
log
(
msgStr
+
'mainWnd getMainWindow success'
);
reject
(
null
)
}
else
{
resolve
(
data
);
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
console
.
log
(
msgStr
+
'windowStage JSON.stringify(mainWnd)==='
+
JSON
.
stringify
(
mainWnd
));
}
})
})
}
function show() {
function
show
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd.show((err
, data
) => {
mainWnd
.
show
((
err
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.show', done);
}
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.show success'
);
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`)
resolve
(
true
)
}
resolve(data)
})
})
}
function setFullScreen() {
function
setFullScreen
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd
.
setFullScreen
(
true
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setFullScreen'
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done);
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`)
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.setFullScreen successed'
);
resolve
(
true
)
}
resolve(data)
})
})
}
function setSystemBarEnableStatus() {
function
setSystemBarEnableStatus
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd
.
setSystemBarEnable
([
'status'
],
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setSystemBarEnable status JSON.stringify(data)=='
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done);
}
reject
(
null
)
}
else
{
flagStatus
=
true
;
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
resolve
(
true
)
}
resolve(data)
})
})
}
function setSystemBarEnableNavigation() {
function
setSystemBarEnableNavigation
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd
.
setSystemBarEnable
([
'navigation'
],
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setSystemBarEnable status JSON.stringify(data)=='
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navitgation]', done);
}
reject
(
null
)
}
else
{
flagNav
=
true
;
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
resolve
(
true
)
}
resolve(data)
})
})
}
await getMainWindow()
await show()
await setFullScreen()
ohosWindowOn()
await setSystemBarEnableStatus()
await setSystemBarEnableNavigation()
let
mainWnd
=
null
;
mainWnd
=
await
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
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
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
...
...
@@ -377,128 +399,121 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
let
[
flagStatus
,
flagNav
]
=
[
false
,
false
];
console
.
log
(
msgStr
+
'begin'
);
let mainWnd = null;
console.log(msgStr + 'mainWnd = null');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow
.
on
(
'systemBarTintChange'
,
systembartintstate
=>
{
console
.
log
(
msgStr
+
'ohosWindow.on systemBarTintChange :'
+
JSON
.
stringify
(
systembartintstate
));
console
.
log
(
msgStr
+
'ohosWindow.on systembartintstate.regionTint : '
+
JSON
.
stringify
(
systembartintstate
.
regionTint
));
if
(
flagStatus
||
flagNav
)
{
let
enable
=
systembartintstate
.
regionTint
[
0
]
.
isEnable
let
numType
=
systembartintstate
.
regionTint
[
0
]
.
type
console
.
log
(
msgStr
+
'ohosWindow.on isEnable : '
+
JSON
.
stringify
(
enable
));
console
.
log
(
msgStr
+
'ohosWindow.on numType : '
+
JSON
.
stringify
(
numType
));
try
{
expect
(
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
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
windowStage
.
getMainWindow
((
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`mainWnd.getMainWindow catch err: ${JSON.stringify(error)}`)
}
mainWnd = data;
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'windowStage JSON.stringify(mainWnd)==='
+
JSON
.
stringify
(
data
));
resolve
(
data
)
}
})
})
}
function show() {
function
show
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd.show((err
, data
) => {
mainWnd
.
show
((
err
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.show', done);
}
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.show success'
);
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`)
resolve
(
true
)
}
resolve(data)
})
})
}
function setFullScreen() {
function
setFullScreen
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd
.
setFullScreen
(
true
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setFullScreen'
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done);
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`)
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.setFullScreen successed'
);
resolve
(
true
)
}
resolve(data)
})
})
}
function setSystemBarEnable() {
function
setSystemBarEnable
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd.setSystemBarEnable([], (err
, data
) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(
data
));
mainWnd
.
setSystemBarEnable
([],
(
err
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setSystemBarEnable [] JSON.stringify(data)=='
+
JSON
.
stringify
(
err
));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done);
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
reject
(
null
)
}
else
{
resolve
(
true
)
}
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
resolve(data)
})
})
}
function ohosWindowOn() {
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() {
function
setSystemBarEnableT
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd
.
setSystemBarEnable
([
'status'
,
'navigation'
],
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done);
}
reject
(
null
)
}
else
{
flagStatus
=
true
;
flagNav
=
true
;
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
resolve
(
true
)
console
.
log
(
msgStr
+
'mainWnd.setSystemBarEnable [status, navigation] JSON.stringify(data)=='
+
JSON
.
stringify
(
data
));
}
resolve(data)
})
})
}
await getMainWindow()
await show()
await setFullScreen()
await setSystemBarEnable()
await setSystemBarEnableT()
ohosWindowOn()
let
mainWnd
=
null
;
mainWnd
=
await
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
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
();
});
await
setSystemBarEnableT
(
mainWnd
)
.
catch
((
err
)
=>
{
console
.
info
(
msgStr
+
'setWindowSystemBarEnable error : '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
done
();
});
});
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_009
...
...
@@ -510,119 +525,115 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
let
[
flagStatus
,
flagNav
]
=
[
false
,
false
];
console
.
log
(
msgStr
+
'begin'
);
let mainWnd = null;
console.log(msgStr + 'mainWnd = null');
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)}`
)
}
ohosWindow
.
off
(
'systemBarTintChange'
)
done
();
}
})
function
getMainWindow
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
windowStage
.
getMainWindow
((
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`windowStage.getMainWindow catch err: ${JSON.stringify(error)}`)
}
mainWnd = data;
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'windowStage JSON.stringify(mainWnd)==='
+
JSON
.
stringify
(
data
));
resolve
(
data
)
}
})
})
}
function show() {
function
show
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd.show((err
, data
) => {
mainWnd
.
show
((
err
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.show', done);
}
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.show success'
);
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.show catch err: ${JSON.stringify(error)}`)
resolve
(
true
)
}
resolve(data)
})
})
}
function setFullScreen() {
function
setFullScreen
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd
.
setFullScreen
(
true
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setFullScreen'
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setFullScreen', done);
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.setFullScreen successed'
);
resolve
(
true
)
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setFullScreen catch err: ${JSON.stringify(error)}`)
})
})
}
function
setSystemBarEnable
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd
.
setSystemBarEnable
([],
(
err
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setSystemBarEnable [] JSON.stringify(data)=='
+
JSON
.
stringify
(
err
));
if
(
err
&&
err
.
code
)
{
reject
(
null
)
}
else
{
resolve
(
true
)
}
resolve(data)
})
})
}
function setSystemBarEnableT() {
function
setSystemBarEnableT
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd
.
setSystemBarEnable
([
'status'
,
'navigation'
],
(
err
,
data
)
=>
{
console.log(msgStr + 'mainWnd.setSystemBarEnable status,navigation JSON.stringify(data)==' + JSON.stringify(data));
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done);
}
reject
(
null
)
}
else
{
flagStatus
=
true
;
flagNav
=
true
;
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
resolve
(
true
)
}
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
resolve(data)
})
})
}
function ohosWindowOn() {
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)}`)
}
let
mainWnd
=
null
;
mainWnd
=
await
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
done
();
}
})
}
function setSystemBarEnable() {
return new Promise(function (resolve, reject) {
mainWnd.setSystemBarEnable([], (err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done);
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setSystemBarEnable catch err: ${JSON.stringify(error)}`)
}
resolve(data)
})
})
}
});
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 getMainWindow()
await show()
await setFullScreen()
await setSystemBarEnableT()
ohosWindowOn()
await setSystemBarEnable()
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
...
...
@@ -633,84 +644,84 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
caseName
=
'setSystemBarEnableTest10'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
let mainWnd = null;
console.log(msgStr + 'mainWnd = 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 {
console.log(msgStr + 'windowStage.getMainWindow JSON.stringify(!!data)===' + JSON.stringify(!!data));
expect(!!data).assertTrue();
} catch (error) {
console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`)
reject
(
null
)
}
else
{
resolve
(
data
);
console
.
log
(
msgStr
+
'windowStage JSON.stringify(mainWnd)==='
+
JSON
.
stringify
(
mainWnd
));
}
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
)
{
mainWnd.show((err
, data
) => {
mainWnd
.
show
((
err
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(data, caseName, 'mainWnd.show', done);
}
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.show success'
);
try {
console.log(msgStr + 'mainWnd.show JSON.stringify(!data)===' + JSON.stringify(!data));
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.show catch error: ${JSON.stringify(error)}`)
resolve
(
true
)
}
resolve(data)
})
})
}
function setFullScreen() {
function
setFullScreen
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
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
)
{
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done);
}
try {
console.log(msgStr + 'mainWnd.setFullScreen JSON.stringify(!data)===' + JSON.stringify(!data));
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setFullScreen catch error: ${JSON.stringify(error)}`)
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'mainWnd.setFullScreen successed'
);
resolve
(
true
)
}
resolve(data)
})
})
}
function setSystemBarEnable() {
function
setSystemBarEnable
(
mainWnd
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
mainWnd.setSystemBarEnable([], (err
, data
) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(
data
));
mainWnd
.
setSystemBarEnable
([],
(
err
)
=>
{
console
.
log
(
msgStr
+
'mainWnd.setSystemBarEnable [] JSON.stringify(data)=='
+
JSON
.
stringify
(
err
));
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)}`)
reject
(
null
)
}
else
{
resolve
(
true
)
}
resolve(data)
})
})
}
function setSystemBarEnableError() {
return new Promise(function (resolve, reject) {
let
mainWnd
=
null
;
mainWnd
=
await
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
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
));
...
...
@@ -725,16 +736,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
else
{
unexpectedError
(
data
,
caseName
,
'mainWnd.setSystemBarEnable [null,123]'
,
done
);
}
resolve(data)
})
})
}
await getMainWindow()
await show()
await setFullScreen()
await setSystemBarEnable()
await setSystemBarEnableError()
});
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_004
...
...
@@ -746,119 +748,29 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
let
cloneColorArr
=
JSON
.
parse
(
JSON
.
stringify
(
commonRGBColorArr
));
let
compareCount
=
0
;
let listenerFlag = false;
console
.
log
(
msgStr
+
'begin'
);
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
function ohosWindowOn() {
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (listenerFlag) {
try {
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
} catch (error) {
console.info(`ohosWindow.on catch error: ${JSON.stringify(error)}`)
}
let 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 set
FullScreen(
) {
return new Promise(
function (resolve, reject)
{
tempWnd.set
FullScreen(true
, (err, data) => {
function
set
SystemBarPropertiesFun
(
tempWnd
,
systemBarProperties
)
{
return
new
Promise
(
(
resolve
,
reject
)
=>
{
tempWnd
.
set
SystemBarProperties
(
systemBarProperties
,
(
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)
})
})
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'tempWnd.setSystemBarProperties '
+
JSON
.
stringify
(
systemBarProperties
)
+
' success'
);
resolve
(
true
)
}
function setSystemBarEnableNavigationT() {
return new Promise(function (resolve, reject) {
tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
listenerFlag = true;
resolve(data)
})
})
}
function setSystemBarProperties() {
return new Promise(function (resolve, reject) {
let
tempWnd
;
tempWnd
=
await
windowStage
.
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
done
();
});
expect
(
!!
tempWnd
)
.
assertTrue
();
let
loopCount
=
commonRGBColorArr
.
length
for
(
let
i
=
0
;
i
<
loopCount
;
i
++
)
{
let
tempColor
=
commonRGBColorArr
[
i
];
...
...
@@ -870,25 +782,13 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
isNavigationBarLightIcon
:
false
,
navigationBarContentColor
:
tempColor
,
};
tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => {
console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarProperties' + tempColor + ' ', done);
}
console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success');
resolve(data)
})
}
})
await
setSystemBarPropertiesFun
(
tempWnd
,
systemBarProperties
)
.
catch
((
err
)
=>
{
console
.
info
(
msgStr
+
'setSystemBarProperties error : '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
done
();
});
}
await getMainWindow()
await show()
await setFullScreen()
ohosWindowOn()
await setSystemBarEnableNavigationT()
await setSystemBarProperties()
done
();
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_005
...
...
@@ -910,8 +810,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
log
(
msgStr
+
'begin'
);
listenerData
.
on
=
true
;
listenerData
.
typeStr
=
'systemBarTintChange'
;
function ohosWindowOn() {
ohosWindow
.
on
(
'systemBarTintChange'
,
(
systemBarData
)
=>
{
console
.
log
(
msgStr
+
'tempWnd.on systemBarTintChange, systemBatData : '
+
JSON
.
stringify
(
systemBarData
));
if
(
listenerFlag
)
{
...
...
@@ -991,116 +889,61 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
console
.
log
(
msgStr
+
'tempWnd.on systemBarTintChange finished'
);
})
}
let tempWnd = null
function getMainWindow() {
return new Promise(function (resolve, reject) {
windowStage.getMainWindow((err, data) => {
let
tempWnd
;
tempWnd
=
await
windowStage
.
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
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
)
{
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
}
tempWnd = data
try
{
expect(
!!data).assertTrue
();
expect
(
TRUE_FLAG
)
.
assertFail
();
}
catch
(
error
)
{
console.info(`windowStage.getMainWindow catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
resolve(data)
})
})
console
.
info
(
`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`
)
}
function show() {
return new Promise(function (resolve, reject) {
tempWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.show', done);
done
();
return
;
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
if
(
i
==
commonNUMBERColorArr
.
length
-
1
)
{
console
.
info
(
msgStr
+
'setSystemBarPropertiesTest5 finished step:'
+
i
);
done
();
}
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.setSystemBatEnable catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
listenerFlag = true;
resolve(data)
})
})
}
function setSystemBarProperties() {
return new Promise(function (resolve, reject) {
let loopCount = commonNUMBERColorArr.length
for (let i = 0; i < loopCount; i++) {
console.log(msgStr + 'tempWnd.setSystemBarEnable i:' + i);
let tempColor = commonNUMBERColorArr[i];
let systemBarProperties = {
statusBarColor: tempColor,
isStatusBarLightIcon: true,
statusBarContentColor: tempColor,
navigationBarColor: tempColor,
isNavigationBarLightIcon: true,
navigationBarContentColor: tempColor,
};
tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => {
console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data));
if (err && err.code) {
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
...
...
@@ -1116,8 +959,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
log
(
msgStr
+
'begin'
);
listenerData
.
on
=
true
;
listenerData
.
typeStr
=
'systemBarTintChange'
;
function ohosWindowOn() {
ohosWindow
.
on
(
'systemBarTintChange'
,
(
systemBarData
)
=>
{
console
.
log
(
msgStr
+
'tempWnd.on systemBarTintChange, systemBatData : '
+
JSON
.
stringify
(
systemBarData
));
if
(
listenerFlag
)
{
...
...
@@ -1146,82 +987,30 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
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(`winsowStage.getMainWindow catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
resolve(data)
})
})
}
function show() {
return new Promise(function (resolve, reject) {
tempWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.show', done);
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'tempWnd.show success');
resolve(data)
})
})
}
function setFullScreen() {
return new Promise(function (resolve, reject) {
tempWnd.setFullScreen(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
}
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() {
return new Promise(function (resolve, reject) {
let
tempWnd
;
tempWnd
=
await
windowStage
.
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
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
=
commonRGBColorArr
.
length
for
(
let
i
=
0
;
i
<
loopCount
;
i
++
)
{
let
tempColor
=
commonKEYColorArr
[
i
];
...
...
@@ -1242,22 +1031,14 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`tempWnd.setSystemBarProperties catch error: ${JSON.stringify(error)}`
)
}
resolve(data)
done
();
}
})
}
listenerFlag = false;
if
(
i
==
commonRGBColorArr
.
length
-
1
)
{
console
.
info
(
msgStr
+
'setSystemBarPropertiesTest5 finished step:'
+
i
);
done
();
}
})
}
await getMainWindow()
await show()
await setFullScreen()
ohosWindowOn()
await setSystemBarEnableNavigationT()
await setSystemBarProperties()
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_005
...
...
@@ -1270,28 +1051,32 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
log
(
msgStr
+
'begin context=='
+
JSON
.
stringify
(
context
));
let
loopCount
=
appWindowTypeArr
.
length
;
console
.
log
(
msgStr
+
'loopCount: '
+
loopCount
);
for (let i = 0; i < loopCount; i++) {
let tempType = ohosWindow.WindowType.TYPE_APP;
let windId = 'createTest5' + i;
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
ohosWindow.create(context, windId, tempType, (err, data) => {
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
)
{
try {
expect(err.code === 1003).assertTrue();
} catch (error) {
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
resolve
(
err
)
}
else
{
reject
(
null
)
}
})
})
}
for
(
let
i
=
0
;
i
<
loopCount
;
i
++
)
{
let
tempType
=
ohosWindow
.
WindowType
.
TYPE_APP
;
let
windId
=
'createTest5'
+
i
;
console
.
log
(
msgStr
+
'ohosWindow.create '
+
tempType
+
' step: '
+
i
);
let
errCode
;
errCode
=
await
createWin
(
windId
,
tempType
)
expect
(
errCode
.
code
===
1003
)
.
assertTrue
();
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);
}
})
}
})
/**
...
...
@@ -1308,121 +1093,55 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
tempWnd
=
null
let
tempType
=
ohosWindow
.
WindowType
.
TYPE_SYSTEM_ALERT
;
function create
(i
) {
function
create
Win
(
windId
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
let windId = 'createTest6' + i;
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
console.log(msgStr + 'ohosWindow.create windId: ' + windId + ' start');
ohosWindow
.
create
(
context
,
windId
,
tempType
,
(
err
,
data
)
=>
{
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done);
return;
}
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
}
tempWnd = data
reject
(
null
)
}
else
{
console
.
log
(
msgStr
+
'ohosWindow.create '
+
tempType
+
' wnd: '
+
tempWnd
);
resolve(i)
resolve
(
data
)
}
})
})
}
function getProperties(
i
) {
function
getProperties
(
win
)
{
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 data'
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'tempWnd.getProperties', done);
console
.
log
(
msgStr
+
'tempWnd.getProperties err&&err.code'
+
JSON
.
stringify
(
err
));
return;
}
console.log(msgStr + 'tempWnd.getProperties success, !!data : ' + !!data);
try {
expect(!!data).assertTrue();
expect(data.type == tempType).assertTrue();
} catch (error) {
console.info(`tempWnd.getProperties catch error: ${JSON.stringify(error)}`)
}
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);
reject
(
null
)
}
else
{
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
console
.
log
(
msgStr
+
'tempWnd.getProperties success, !!data : '
+
!!
data
);
resolve
(
data
)
}
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)
for
(
let
i
=
0
;
i
<
loopCount
;
i
++
)
{
let
windId
=
'createTest6'
+
i
;
let
tempWnd
;
tempWnd
=
await
createWin
(
windId
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.create catch error: ${JSON.stringify(err)}`
)
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
()
}
for (let i = 0; i < loopCount; i++) {
await create(i)
await getProperties(i)
await find(i)
await destroy(i)
await findAgain(i)
}
})
/**
...
...
@@ -1437,9 +1156,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
tempType
=
5000
;
let
windId
=
'createTest7'
;
console
.
log
(
msgStr
+
'ohosWindow.create '
+
tempType
+
' start'
);
function create() {
return new Promise(function (resolve, reject) {
ohosWindow
.
create
(
context
,
windId
,
tempType
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'ohosWindow.create data'
+
JSON
.
stringify
(
data
));
if
(
err
&&
err
.
code
)
{
...
...
@@ -1452,12 +1168,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
return
;
}
unexpectedError
(
err
,
caseName
,
'ohosWindow.create'
,
done
);
resolve(data)
})
})
}
await create()
})
/**
...
...
@@ -1472,23 +1183,27 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
windowId
=
'sameid'
let
tempWnd
=
null
;
function create() {
function
create
FirstWin
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
windowId
,
1
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'ohosWindow.create 1 once err: '
+
JSON
.
stringify
(
err
));
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
expect(!!data).assertTrue();
tempWnd = data;
reject
(
null
)
}
else
{
resolve
(
data
)
}
})
})
}
function createAgain() {
return new Promise(function (resolve, reject) {
ohosWindow.create(context, windowId, 1, (err, data) => {
let
dataOne
;
dataOne
=
await
createFirstWin
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to create window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
done
();
});
expect
(
!!
dataOne
)
.
assertTrue
();
ohosWindow
.
create
(
context
,
windowId
,
1
,
async
(
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
));
...
...
@@ -1497,212 +1212,101 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
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
));
}
resolve(data)
})
})
}
function find() {
/**
* @tc.number SUB_WINDOW_ON_OFF_JSAPI_005
* @tc.name Test listenerTest5
* @tc.desc Verify whether the change of avoidance area and change monitoring can be turned on normally
*/
it
(
'listenerTest5'
,
0
,
async
function
(
done
)
{
let
caseName
=
'listenerTest5'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
let
listenerOnFlag
=
false
;
console
.
log
(
msgStr
+
'begin'
);
listenerData
.
on
=
true
;
listenerData
.
typeStr
=
'systemAvoidAreaChange'
;
function
setSystemBarEnable
(
tempWnd
)
{
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);
tempWnd
.
setSystemBarEnable
([],
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
reject
(
false
)
}
else
{
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
console
.
log
(
msgStr
+
'tempWnd.setSystemBarEnable([]) success'
);
listenerOnFlag
=
true
;
resolve
(
true
)
}
resolve(data)
})
})
}
function
destroy(params
) {
function
setSystemBarEnableT
(
tempWnd
)
{
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);
tempWnd
.
setSystemBarEnable
([
'status'
,
'navigation'
],
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'ohosWindow.destroy', done);
reject
(
false
)
}
else
{
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
console
.
log
(
msgStr
+
'tempWnd.setSystemBarEnable([status, navigation]) success'
);
console
.
log
(
msgStr
+
'tempWnd.on systemAvoidAreaChange finished'
);
resolve
(
true
)
}
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 {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
try {
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
let
tempWnd
;
tempWnd
=
await
windowStage
.
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
done
();
})
})
}
await create()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return createAgain()
}).then(function (params) {
return find()
}).then(function (params) {
return destroy(params)
}).then(function (params) {
return findAgain(params)
})
})
/**
* @tc.number SUB_WINDOW_ON_OFF_JSAPI_005
* @tc.name Test listenerTest5
* @tc.desc Verify whether the change of avoidance area and change monitoring can be turned on normally
*/
it('listenerTest5', 0, async function (done) {
let caseName = 'listenerTest5';
let msgStr = 'jsunittest ' + caseName + ' ';
let listenerOnFlag = false;
console.log(msgStr + 'begin');
let tempWnd = null;
listenerData.on = true;
listenerData.typeStr = 'systemAvoidAreaChange';
function getMainWindow() {
return new Promise(function (resolve, reject) {
windowStage.getMainWindow((err, data) => {
console.log(msgStr + 'windowStage.getMainWindow err: ' + JSON.stringify(err));
console.log(msgStr + 'windowStage.getMainWindow data: ' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.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)
})
})
}
});
expect
(
!!
tempWnd
)
.
assertTrue
();
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)}`
)
}
tempWnd
.
off
(
'systemAvoidAreaChange'
)
done
()
}
})
}
function setSystemBarEnable() {
return new Promise(function (resolve, reject) {
tempWnd.setSystemBarEnable([], (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done);
}
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.setSystemBarEnable catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
listenerOnFlag = true;
resolve(data)
})
})
}
function setSystemBarEnableT() {
return new Promise(function (resolve, reject) {
tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
}
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished');
resolve(data)
tempWnd.off('systemAvoidAreaChange')
await
tempWnd
.
show
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to show the window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
()
done
();
})
})
}
await getMainWindow()
await show()
await setFullScreen()
tempWndOn()
await setSystemBarEnable()
await setSystemBarEnableT()
});
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
...
...
@@ -1717,78 +1321,65 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
log
(
msgStr
+
'begin'
);
console
.
log
(
msgStr
+
'newWindowObj 2: '
+
JSON
.
stringify
(
newWindowObj
));
let
tempWnd
=
null
let tempTypeArr = [];
let
loopCount1
=
systemWindowTypeArr
;
console
.
log
(
msgStr
+
'ohosWindow.windowType'
+
JSON
.
stringify
(
loopCount1
))
function create() {
function
create
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
windowId
,
baseWndType
,
(
err
,
data
)
=>
{
try
{
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if
(
!!
data
)
{
tempWnd = data
console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd);
try {
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`ohosWindwo.create catch error: ${JSON.stringify(error)}`)
}
resolve
(
data
)
}
else
{
reject
(
null
)
}
}
catch
(
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
)
{
tempWnd
.setWindowType(tempType, (err, data) => {
win
.
setWindowType
(
tempType
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'tempWnd.setWindowType i: '
+
i
);
console.log(msgStr + 'tempWnd.setWindowType err: ' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.setWindowType data: ' + JSON.stringify(data));
console.log(msgStr + 'tempWnd.setWindowType !data: ' + !data);
if (!data) {
expect(!data).assertTrue();
if
(
err
&&
err
.
code
)
{
reject
(
null
)
}
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) {
console.log(msgStr + 'getProperties start tempTypeArr:' + JSON.stringify(tempTypeArr) + ',i:' + i);
return new Promise(function (resolve, reject) {
tempWnd.getProperties((err, dataProper) => {
console.log(msgStr + 'tempWnd.getProperties err: ' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.getProperties dataProper: ' + JSON.stringify(dataProper));
console.log(msgStr + 'tempWnd.getProperties !!dataProper: ' + !!dataProper);
expect(!!dataProper).assertTrue();
expect(dataProper.type === tempType).assertTrue();
resolve(dataProper)
})
tempWnd
=
await
createWin
()
.
catch
(
err
=>
{
console
.
log
(
msgStr
+
'ohosWindow.create failed'
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
done
();
})
}
expect
(
!!
tempWnd
)
.
assertTrue
();
await create()
for
(
let
i
=
0
;
i
<
loopCount1
.
length
;
i
++
)
{
let
tempType
=
ohosWindow
.
WindowType
[
loopCount1
[
i
]];
console.log(msgStr + 'tempWnd.setWindowType :' + tempType + ' start');
tempTypeArr.push(tempType);
console.log(msgStr + 'for tempTypeArr:' + JSON.stringify(tempTypeArr) + ',i:' + i);
await setWindowType(tempType, i)
console
.
log
(
msgStr
+
"step: "
+
i
);
await
setWindowType
(
tempWnd
,
tempType
,
i
)
.
catch
(
err
=>
{
console
.
log
(
msgStr
+
'setWindowType failed'
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
done
();
})
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
)
{
console.log(msgStr + 'tempWnd.getProperties i=' + i + ' , loopCount1.length-1==' + loopCount1.length);
tempWnd.destroy();
await
tempWnd
.
destroy
();
done
();
}
}
...
...
@@ -1807,35 +1398,28 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
log
(
msgStr
+
'begin'
);
let
tempWnd
=
null
function create() {
function
create
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
windowId
,
baseWndType
,
(
err
,
data
)
=>
{
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if
(
!!
data
)
{
tempWnd = data
try {
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
}
resolve
(
data
)
}
else
{
unexpectedError(err, caseName, 'ohosWindow.create', done);
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);
tempWnd
=
await
createWin
()
.
catch
(
err
=>
{
console
.
info
(
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
expect
(
!!
tempWnd
)
.
assertTrue
();
tempWnd
.
setWindowType
(
changedWndType
,
async
(
err
,
data
)
=>
{
if
(
!!
data
)
{
await
tempWnd
.
destroy
();
unexpectedError
(
err
,
caseName
,
'tempWnd.setWindowType'
,
done
);
}
else
{
try
{
...
...
@@ -1843,84 +1427,11 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`tempWnd.setWindowType catch error: ${JSON.stringify(error)}`
)
}
}
resolve(data)
})
})
}
function find() {
return new Promise(function (resolve, reject) {
ohosWindow.find(windowId, (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
} else {
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function destroy(params) {
return new Promise(function (resolve, reject) {
tempWnd.destroy((err, data) => {
console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data));
console.log(msgStr + 'tempWnd.destroy !!data' + !!data);
if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.destroy', done);
} else {
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function findAgain(params) {
return new Promise(function (resolve, reject) {
ohosWindow.find(windowId, (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
try {
expect(true).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
}
resolve(data)
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
...
...
@@ -1935,33 +1446,25 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
log
(
msgStr
+
'begin'
);
let
tempWnd
=
null
function create() {
function
create
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
windowId
,
baseWndType
,
(
err
,
data
)
=>
{
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if
(
!!
data
)
{
tempWnd = data
try {
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
resolve
(
data
)
}
else
{
unexpectedError(err, caseName, 'ohosWindow.create', done);
reject
(
null
)
}
})
})
}
function destroy() {
return new Promise(function (resolve, reject) {
tempWnd.destroy((err, data) => {
console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data));
console.log(msgStr + 'tempWnd.destroy !!data' + !!data);
tempWnd
=
await
createWin
()
.
catch
(
err
=>
{
console
.
info
(
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
expect
(
!!
tempWnd
)
.
assertTrue
();
tempWnd
.
destroy
(
async
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError
(
err
,
caseName
,
'ohosWindow.destroy'
,
done
);
}
else
{
...
...
@@ -1970,31 +1473,14 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`tempWnd.show catch error: ${JSON.stringify(error)}`
)
}
ohosWindow.find(windowId, (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
try {
await
ohosWindow
.
find
(
windowId
)
.
then
((
data
)
=>
{
console
.
info
(
'Succeeded in finding the window. Data: '
+
JSON
.
stringify
(
data
));
})
.
catch
((
err
)
=>
{
console
.
error
(
'Failed to find the Window. Cause: '
+
JSON
.
stringify
(
err
));
expect
(
err
.
code
==
1001
)
.
assertTrue
();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
done
();
} else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
}
})
}
resolve(data)
})
})
});
}
await create()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return destroy()
})
})
/**
...
...
@@ -2010,118 +1496,37 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
log
(
msgStr
+
'begin'
);
let
tempWnd
=
null
function create() {
function
create
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
windowId
,
baseWndType
,
(
err
,
data
)
=>
{
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if
(
!!
data
)
{
tempWnd = data
try {
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
resolve
(
data
)
})
})
}
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)}`)
reject
(
null
)
}
}
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)
})
tempWnd
=
await
createWin
()
.
catch
(
err
=>
{
console
.
info
(
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
}
expect
(
!!
tempWnd
)
.
assertTrue
();
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);
tempWnd
.
loadContent
(
'pages/index'
,
async
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'ohosWindow.destroy
', done);
unexpectedError
(
err
,
caseName
,
'tempWnd.loadContent
'
,
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);
console
.
info
(
`tempWnd.loadContent 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 loadContent()
}).then(function (params) {
return find()
}).then(function (params) {
return destroy(params)
}).then(function (params) {
return findAgain(params)
})
})
/**
...
...
@@ -2137,118 +1542,37 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
log
(
msgStr
+
'begin'
);
let
tempWnd
=
null
function create() {
function
create
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
windowId
,
baseWndType
,
(
err
,
data
)
=>
{
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if
(
!!
data
)
{
tempWnd = data
try {
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
}
resolve
(
data
)
}
else
{
unexpectedError(err, caseName, 'ohosWindow.create', done);
reject
(
null
)
}
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);
tempWnd
=
await
createWin
()
.
catch
(
err
=>
{
console
.
info
(
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
expect
(
!!
tempWnd
)
.
assertTrue
();
tempWnd
.
loadContent
(
null
,
async
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
try
{
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
);
}
resolve(data)
})
})
}
function find() {
return new Promise(function (resolve, reject) {
ohosWindow.find(windowId, (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
} else {
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function destroy(params) {
return new Promise(function (resolve, reject) {
tempWnd.destroy((err, data) => {
console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data));
console.log(msgStr + 'tempWnd.destroy !!data' + !!data);
if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.destroy', done);
} else {
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function findAgain(params) {
return new Promise(function (resolve, reject) {
ohosWindow.find(windowId, (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
try {
expect(true).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
}
resolve(data)
done();
})
})
}
await create()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return loadContent()
}).then(function (params) {
return find()
}).then(function (params) {
return destroy(params)
}).then(function (params) {
return findAgain(params)
})
})
/**
...
...
@@ -2260,9 +1584,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
caseName
=
'loadContentTest9'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
function loadContent() {
return new Promise(function (resolve, reject) {
windowStage
.
loadContent
(
'pages/index/index.ets'
,
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError
(
err
,
caseName
,
'windowStage.loadContent'
,
done
);
...
...
@@ -2274,16 +1595,8 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
console
.
info
(
`windowStage.loadContent catch error: ${JSON.stringify(error)}`
)
}
console
.
log
(
msgStr
+
'windowStage.loadContent end data='
+
JSON
.
stringify
(
data
));
}
resolve(data)
done
();
})
})
}
await loadContent()
.then(function (params) {
console.log(msgStr + 'loadContent then: ' + JSON.stringify(params))
})
})
/**
...
...
@@ -2296,8 +1609,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
function loadContent() {
return new Promise(function (resolve, reject) {
try
{
windowStage
.
loadContent
(
null
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'windowStage.loadContent(pages/index/index.ets)'
+
JSON
.
stringify
(
err
));
...
...
@@ -2306,7 +1617,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`windowStage.loadContent catch error: ${JSON.stringify(error)}`
)
}
resolve(data)
done
();
});
}
catch
(
err
)
{
console
.
log
(
msgStr
+
'windowStage.loadContent(pages/index/index.ets) catch err'
+
JSON
.
stringify
(
err
));
...
...
@@ -2315,16 +1626,9 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`windowStage.loadContent catch error: ${JSON.stringify(error)}`
)
}
}
console.log(msgStr + 'end');
done
();
})
}
await loadContent()
.then(function (params) {
console.log(msgStr + 'loadContent then: ' + JSON.stringify(params))
})
console
.
log
(
msgStr
+
'end'
);
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_011
...
...
@@ -2336,8 +1640,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
function loadContent() {
return new Promise(function (resolve, reject) {
windowStage
.
loadContent
(
'pages/index/index.ets'
,
abilityStorage
,
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError
(
err
,
caseName
,
'windowStage.loadContent'
,
done
);
...
...
@@ -2348,17 +1650,9 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`windowStage.loadContent catch error: ${JSON.stringify(error)}`
)
}
console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data));
}
resolve(data)
done
();
})
})
console
.
log
(
msgStr
+
'windowStage.loadContent end data='
+
JSON
.
stringify
(
data
));
}
await loadContent()
.then(function (params) {
console.log(msgStr + 'loadContent then: ' + JSON.stringify(params))
})
})
/**
...
...
@@ -2371,8 +1665,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
function loadContent() {
return new Promise(function (resolve, reject) {
try
{
windowStage
.
loadContent
(
null
,
abilityStorage
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'windowStage.loadContent(pages/index/index.ets)'
+
JSON
.
stringify
(
err
));
...
...
@@ -2381,7 +1673,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`windowStage.loadContent catch error: ${JSON.stringify(error)}`
)
}
resolve(data)
done
();
});
}
catch
(
err
)
{
console
.
log
(
msgStr
+
'windowStage.loadContent(pages/index/index.ets) catch err '
+
JSON
.
stringify
(
err
));
...
...
@@ -2390,15 +1682,8 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
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
...
...
@@ -2409,97 +1694,70 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
caseName
=
'createSubWindowTest3'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
let
temp
Wnd = null
let
sub
Wnd
=
null
function
createSubWindow
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
windowStage
.
createSubWindow
(
'createSubWindowTest3'
,
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'windowStage.createSubWindow', done);
reject
(
null
)
console
.
log
(
msgStr
+
'windowStage.createSubWindow(createSubWindowTest3) err='
+
JSON
.
stringify
(
err
));
}
else
{
try {
tempWnd = data
expect(!!data).assertTrue();
} catch (error) {
console.info(`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'windowStage.createSubWindow end data=' + JSON.stringify(data));
}
resolve
(
data
)
}
})
})
}
function find() {
function
find
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
find
(
'createSubWindowTest3'
,
(
err
,
data
)
=>
{
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
reject
(
false
)
}
else
{
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve
(
data
)
}
})
})
}
function destroy
(params
) {
function
destroy
Win
(
win
)
{
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);
win
.
destroy
((
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError(err, caseName, 'ohosWindow.destroy', done);
reject
(
null
)
}
else
{
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
resolve
(
true
)
}
resolve(data)
})
})
}
function findAgain(params) {
return new Promise(function (resolve, reject) {
ohosWindow.find('createSubWindowTest3', (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
try {
expect(true).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
}
resolve(data)
subWnd
=
await
createSubWindow
()
.
catch
(
err
=>
{
console
.
info
(
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
expect
(
!!
subWnd
)
.
assertTrue
();
let
subWindow
;
subWindow
=
await
findWin
()
.
catch
(
err
=>
{
console
.
info
(
`ohosWindow.find failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
}
await createSubWindow()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return find()
}).then(function (params) {
return destroy(params)
}).then(function (params) {
return findAgain(params)
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
()
})
})
/**
...
...
@@ -2511,9 +1769,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
caseName
=
'createSubWindowTest4'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
function createSubWindow() {
return new Promise(function (resolve, reject) {
try
{
windowStage
.
createSubWindow
(
null
,
(
err
,
data
)
=>
{
console
.
log
(
msgStr
+
'windowStage.createSubWindow(null) err='
+
JSON
.
stringify
(
err
));
...
...
@@ -2522,7 +1777,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`windowStage.createSubWindow catch error: ${JSON.stringify(error)}`
)
}
resolve(data)
done
();
});
}
catch
(
err
)
{
try
{
...
...
@@ -2530,16 +1785,9 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`tempWnd.show catch error: ${JSON.stringify(error)}`
)
}
console.log(msgStr + 'windowStage.createSubWindow(null) catch err=' + JSON.stringify(err));
}
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
...
...
@@ -2551,8 +1799,6 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
function getSubWindow() {
return new Promise(function (resolve, reject) {
windowStage
.
getSubWindow
((
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError
(
err
,
caseName
,
'windowStage.getSubWindow'
,
done
);
...
...
@@ -2563,17 +1809,9 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
catch
(
error
)
{
console
.
info
(
`windowStage.getSubWindow catch error: ${JSON.stringify(error)}`
)
}
console.log(msgStr + 'windowStage.getSubWindow end data=' + JSON.stringify(data));
}
resolve(data)
done
();
})
})
console
.
log
(
msgStr
+
'windowStage.getSubWindow end data='
+
JSON
.
stringify
(
data
));
}
await getSubWindow()
.then(function (params) {
console.log(msgStr + 'getMainWindow then: ' + JSON.stringify(params))
})
})
/**
...
...
@@ -2585,533 +1823,164 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
caseName
=
'setPrivacyModeTest2'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin ohosWindow ='
+
JSON
.
stringify
(
ohosWindow
));
let
main
Wnd = null;
let
temp
Wnd
=
null
;
function create() {
function
create
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
'setPrivacyModeTest2'
,
ohosWindow
.
WindowType
.
TYPE_SYSTEM_ALERT
,
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
console
.
log
(
msgStr
+
'ohosWindow.create fail err:'
+
JSON
.
stringify
(
err
));
try {
expect().assertFail();
} catch (error) {
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
}
} else {
try {
expect(data != null).assertTrue();
} catch (error) {
console.info(`ohosWindow.create catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'ohosWindow.create success data' + data);
mainWnd = data;
resolve(data)
}
})
})
}
function getProperties() {
return new Promise(function (resolve, reject) {
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err));
try {
expect().assertFail();
} catch (error) {
console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`)
}
done();
} else {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data));
try {
expect(!data.isPrivacyMode).assertTrue();
} catch (error) {
console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function setPrivacyModeTrue() {
return new Promise(function (resolve, reject) {
mainWnd.setPrivacyMode(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err));
} else {
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setPrivacyMode catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data));
}
resolve(data)
})
})
}
function getProperties2() {
return new Promise(function (resolve, reject) {
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err));
try {
expect().assertFail();
} catch (error) {
console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`)
}
done();
} else {
console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data));
try {
expect(data.isPrivacyMode).assertTrue();
} catch (error) {
console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function setPrivacyModeFalse() {
return new Promise(function (resolve, reject) {
mainWnd.setPrivacyMode(false, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err));
} else {
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`mainWnd.setPrivacyMode catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data));
}
resolve(data)
})
})
}
function getProperties3() {
return new Promise(function (resolve, reject) {
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err));
try {
expect().assertFail();
} catch (error) {
console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`)
}
done();
} else {
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data));
try {
expect(!data.isPrivacyMode).assertTrue();
} catch (error) {
console.info(`mainWnd.getProperties catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function find() {
return new Promise(function (resolve, reject) {
ohosWindow.find('setPrivacyModeTest2', (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
} else {
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function destroy(params) {
return new Promise(function (resolve, reject) {
mainWnd.destroy((err, data) => {
console.log(msgStr + 'tempWnd.destroy err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.destroy data' + JSON.stringify(data));
console.log(msgStr + 'tempWnd.destroy !!data' + !!data);
if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.destroy', done);
} else {
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function findAgain(params) {
return new Promise(function (resolve, reject) {
ohosWindow.find('setPrivacyModeTest2', (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
try {
expect(true).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
} else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
}
resolve(data)
done();
})
})
}
await create()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return getProperties()
})
.then(function (params) {
console.log(msgStr + 'getProperties then: ' + JSON.stringify(params))
return setPrivacyModeTrue()
})
.then(function (params) {
console.log(msgStr + 'setPrivacyModeTrue then: ' + JSON.stringify(params))
return getProperties2()
})
.then(function (params) {
console.log(msgStr + 'getProperties2 then: ' + JSON.stringify(params))
return setPrivacyModeFalse()
})
.then(function (params) {
console.log(msgStr + 'setPrivacyModeFalse then: ' + JSON.stringify(params))
return getProperties3()
})
.then(function (params) {
console.log(msgStr + 'getProperties3 then: ' + JSON.stringify(params))
return find()
})
.then(function (params) {
console.log(msgStr + 'find then: ' + JSON.stringify(params))
return destroy(params)
})
.then(function (params) {
console.log(msgStr + 'destroy then: ' + JSON.stringify(params))
return findAgain(params)
})
})
/**
* @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_003
* @tc.name Test setPrivacyModeTest3
* @tc.desc Verify that the auxiliary window is set as the security layer
*/
it('setPrivacyModeTest3', 0, async function (done) {
let caseName = 'setPrivacyModeTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow));
let mainWnd = null;
function createSubWindow() {
return new Promise(function (resolve, reject) {
windowStage.createSubWindow('setPrivacyModeTest3', (err, data) => {
if (err && err.code) {
console.log(msgStr + 'windowStage.createSubWindow fail err:' + JSON.stringify(err));
try {
expect().assertFail();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
done();
} else {
try {
expect(data != null).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'windowStage.createSubWindow success data' + data);
mainWnd = data;
}
resolve(data)
})
})
}
function getProperties() {
return new Promise(function (resolve, reject) {
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err));
try {
expect().assertFail();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
done();
} else {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data));
try {
expect(!data.isPrivacyMode).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function setPrivacyModeTrue() {
return new Promise(function (resolve, reject) {
mainWnd.setPrivacyMode(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err));
reject
(
null
)
}
else
{
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data));
}
resolve(data)
})
})
}
function getProperties2() {
return new Promise(function (resolve, reject) {
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err));
try {
expect().assertFail();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
done();
} else {
console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data));
try {
expect(data.isPrivacyMode).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function setPrivacyModeFalse() {
return new Promise(function (resolve, reject) {
mainWnd.setPrivacyMode(false, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err));
} else {
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data));
}
resolve(data)
})
})
}
function getProperties3() {
return new Promise(function (resolve, reject) {
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err));
try {
expect().assertFail();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
done();
} else {
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data));
try {
expect(!data.isPrivacyMode).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve(data)
})
})
}
function find() {
return new Promise(function (resolve, reject) {
ohosWindow.find('setPrivacyModeTest3', (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
} else {
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve
(
data
)
}
})
})
}
function
destroy(params
) {
function
getWinProperties
(
win
)
{
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);
win
.
getProperties
((
err
,
data
)
=>
{
if
(
err
.
code
!=
0
)
{
reject
(
null
)
}
else
{
try {
expect(!data).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
}
resolve
(
data
)
}
})
})
}
function
findAgain(params
) {
function
setPrivacyModeWin
(
win
,
boolean
)
{
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);
win
.
setPrivacyMode
(
boolean
,
(
err
)
=>
{
if
(
err
&&
err
.
code
)
{
try {
expect(true).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
console
.
log
(
msgStr
+
'mainWnd.setPrivacyMode(true) err='
+
JSON
.
stringify
(
err
));
reject
(
null
)
}
else
{
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
resolve
(
true
)
}
resolve(data)
done();
})
})
}
await createSubWindow()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return getProperties()
})
.then(function (params) {
console.log(msgStr + 'getProperties then: ' + JSON.stringify(params))
return setPrivacyModeTrue()
})
.then(function (params) {
console.log(msgStr + 'setPrivacyModeTrue then: ' + JSON.stringify(params))
return getProperties2()
})
.then(function (params) {
console.log(msgStr + 'getProperties2 then: ' + JSON.stringify(params))
return setPrivacyModeFalse()
tempWnd
=
await
createWin
()
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
.then(function (params) {
console.log(msgStr + 'setPrivacyModeFalse then: ' + JSON.stringify(params))
return getProperties3()
expect
(
!!
tempWnd
)
.
assertTrue
();
await
setPrivacyModeWin
(
tempWnd
,
true
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.setPrivacyMode failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
.then(function (params) {
console.log(msgStr + 'getProperties3 then: ' + JSON.stringify(params))
return find()
let
windowProperties_true
;
windowProperties_true
=
await
getWinProperties
(
tempWnd
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.getProperties failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
.then(function (params) {
console.log(msgStr + 'find then: ' + JSON.stringify(params))
return destroy(params)
console
.
info
(
msgStr
+
`ohosWindow.windowProperties_true : ${JSON.stringify(windowProperties_true)}`
)
expect
(
windowProperties_true
.
isPrivacyMode
)
.
assertTrue
();
await
setPrivacyModeWin
(
tempWnd
,
false
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.setPrivacyMode failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
.then(function (params) {
console.log(msgStr + 'destroy then: ' + JSON.stringify(params))
return findAgain(params)
let
windowProperties_false
;
windowProperties_false
=
await
getWinProperties
(
tempWnd
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.getProperties failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
console
.
info
(
msgStr
+
`ohosWindow.windowProperties_false : ${JSON.stringify(windowProperties_false)}`
)
expect
(
!
windowProperties_false
.
isPrivacyMode
)
.
assertTrue
();
await
tempWnd
.
destroy
();
done
();
})
/**
* @tc.number
SUB_WINDOW_SETDENSITTYDPI_JSAPI_002
* @tc.name
Test setDensityDpiTest2
* @tc.desc
Verify Sets the screen pixel
* @tc.number
SUB_WINDOW_SETPRIVACYMODE_JSAPI_003
* @tc.name
Test setPrivacyModeTest3
* @tc.desc
Verify that the auxiliary window is set as the security layer
*/
it('set
DensityDpiTest2
', 0, async function (done) {
let caseName = 'set
DensityDpiTest2
';
it
(
'set
PrivacyModeTest3
'
,
0
,
async
function
(
done
)
{
let
caseName
=
'set
PrivacyModeTest3
'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console.log(msgStr + 'begin');
let screens = await screenManager.getAllScreens().catch(errScreen => {
unexpectedError(errScreen, caseName, 'screenManager.getAllScreen', done);
})
console.log(msgStr + 'screenManager.getAllScreen' + JSON.stringify(screens));
try {
expect(!!screens).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
console
.
log
(
msgStr
+
'begin ohosWindow ='
+
JSON
.
stringify
(
ohosWindow
));
let
tempWnd
=
null
;
function
createSubWindowFun
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
windowStage
.
createSubWindow
(
'setPrivacyModeTest3'
,
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
console
.
log
(
msgStr
+
'windowStage.createSubWindow fail err:'
+
JSON
.
stringify
(
err
));
reject
(
null
)
}
else
{
resolve
(
data
)
}
let currentDeviceDefaultDpi;
let currentDeviceDefault = null;
display.getDefaultDisplay(async (err, data) => {
if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
return;
})
})
}
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
currentDeviceDefault = data;
currentDeviceDefaultDpi = parseInt(currentDeviceDefault.densityDPI)
let dpiItem = [-80, 80, 1000, 160, 0, 320, 188.88, 0, 640, 300, currentDeviceDefaultDpi];
for (let i = 0; i < dpiItem.length; i++) {
screens[0].setDensityDpi(dpiItem[i], (errDpi, dataDpi) => {
if (errDpi.code) {
console.error('Failed to set DensityDpi. Cause: ' + JSON.stringify(err) + dpiItem[i]);
return;
function
getPropertiesFun
(
win
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
win
.
getProperties
((
err
,
data
)
=>
{
if
(
err
.
code
!=
0
)
{
reject
(
null
)
}
else
{
resolve
(
data
)
}
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)}`)
})
})
}
function
setPrivacyModeFun
(
win
,
boolean
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
win
.
setPrivacyMode
(
boolean
,
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
reject
(
null
)
}
else
{
resolve
(
true
)
}
})
})
}
});
console.log(msgStr + 'done ');
tempWnd
=
await
createSubWindowFun
()
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
expect
(
!!
tempWnd
)
.
assertTrue
();
await
setPrivacyModeFun
(
tempWnd
,
true
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.setPrivacyMode failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
let
windowProperties_true
;
windowProperties_true
=
await
getPropertiesFun
(
tempWnd
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.getProperties failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
console
.
info
(
msgStr
+
`ohosWindow.windowProperties_true : ${JSON.stringify(windowProperties_true)}`
)
expect
(
windowProperties_true
.
isPrivacyMode
)
.
assertTrue
();
await
setPrivacyModeFun
(
tempWnd
,
false
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.setPrivacyMode failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
let
windowProperties_false
;
windowProperties_false
=
await
getPropertiesFun
(
tempWnd
)
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.getProperties failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
console
.
info
(
msgStr
+
`ohosWindow.windowProperties_false : ${JSON.stringify(windowProperties_false)}`
)
expect
(
!
windowProperties_false
.
isPrivacyMode
)
.
assertTrue
();
await
tempWnd
.
destroy
();
done
();
})
/**
...
...
@@ -3124,57 +1993,46 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin'
);
let
mainWin
=
null
;
function getMainWindow() {
return new Promise(function (resolve, reject) {
windowStage.getMainWindow((err, data) => {
console.log(msgStr + 'getMainWindow data:' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
try {
expect(!!data).assertTrue();
} catch (error) {
console.info(`ohosWindow.on ${JSON.stringify(error)}`)
}
mainWin = data
resolve(data);
console.log(msgStr + 'await windowStage JSON.stringify(mainWin)===' + JSON.stringify(mainWin));
})
})
}
let
num
=
0
let
orientationItem
=
[
'UNSPECIFIED'
,
'PORTRAIT'
,
'LANDSCAPE'
,
'PORTRAIT_INVERTED'
,
'LANDSCAPE_INVERTED'
,
'AUTO_ROTATION'
,
'AUTO_ROTATION_PORTRAIT'
,
'AUTO_ROTATION_LANDSCAPE'
,
'AUTO_ROTATION_RESTRICTED'
,
'AUTO_ROTATION_PORTRAIT_RESTRICTED'
,
'AUTO_ROTATION_LANDSCAPE_RESTRICTED'
,
'LOCKED'
,
'UNSPECIFIED'
];
function setPreferredOrientation(i) {
return new Promise(function (resolve, reject) {
let orientation = ohosWindow.Orientation[orientationItem[i]]
mainWin.setPreferredOrientation(orientation, (err, data) => {
if (err && err.code) {
console.log(msgStr + 'window.setPreferredOrientation failed set error' + orientation);
}
num++
if (++i < orientationItem.length) {
setPreferredOrientation(i)
console.log(msgStr + 'jixuzhixing i: ' + i);
function
setPreferredOrientationFun
(
win
,
orientation
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
win
.
setPreferredOrientation
(
orientation
,
(
err
)
=>
{
if
(
err
.
code
)
{
console
.
error
(
msgStr
+
'Failed to set window orientation. Cause: '
+
JSON
.
stringify
(
err
));
reject
(
null
)
}
else
{
console.log(msgStr + 'i++<orientationItem.length i: ' + i + ' ,orientationItem.length:' + orientationItem.length);
console
.
info
(
msgStr
+
'Succeeded in setting window orientation.'
);
resolve
(
true
)
}
});
}
catch
(
exception
)
{
console
.
error
(
msgStr
+
'Failed to set window orientation. Cause: '
+
JSON
.
stringify
(
exception
));
reject
(
null
)
}
if (num == orientationItem.length) done();
console.log(msgStr + 'success set window.setPreferredOrientation ' + orientation + JSON.stringify(data));
resolve(data)
})
})
}
await getMainWindow()
.then(function (params) {
console.log(msgStr + 'setPreferredOrientation then: ' + JSON.stringify(params))
return setPreferredOrientation(0)
})
mainWin
=
await
windowStage
.
getMainWindow
()
.
catch
((
err
)
=>
{
console
.
error
(
msgStr
+
'Failed to obtain the main window. Cause: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
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
...
...
@@ -3185,28 +2043,38 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
caseName
=
'setForbidSplitMoveTest2'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
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
);
expect
()
.
assertFail
();
done
();
});
console
.
log
(
msgStr
+
'windowStage.getMainWindow'
+
JSON
.
stringify
(
mainWin
));
try {
expect
(
!!
mainWin
)
.
assertTrue
();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
await mainWin.setForbidSplitMove(true, (err, data) => {
if (err.code) {
console.log(msgStr + 'failed set window.setForbidSplitMove drag is prohibited');
return;
}
console.log(msgStr + 'success set window.setForbidSplitMove drag is prohibited' + JSON.stringify(data));
await
setForbidSplitMoveFun
(
mainWin
,
true
)
.
catch
(
err
=>
{
console
.
log
(
msgStr
+
'failed set window.setForbidSplitMove drag is prohibited, error: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
done
();
})
await mainWin.setForbidSplitMove(false, (err, data) => {
if (err.code) {
console.log(msgStr + 'failed set window.setForbidSplitMove you can drag it now');
return;
}
console.log(msgStr + 'success set window.setForbidSplitMove you can drag it now' + JSON.stringify(data));
await
setForbidSplitMoveFun
(
mainWin
,
false
)
.
catch
(
err
=>
{
console
.
log
(
msgStr
+
'failed set window.setForbidSplitMove drag is prohibited, error: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
done
();
})
console
.
log
(
msgStr
+
'done '
);
done
();
...
...
@@ -3220,23 +2088,24 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
caseName
=
'snapshotTest2'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
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
);
});
console
.
log
(
msgStr
+
'windowStage.getMainWindow'
+
JSON
.
stringify
(
mainWin
));
try {
expect
(
!!
mainWin
)
.
assertTrue
();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
await mainWin.snapshot((err, data) => {
mainWin
.
snapshot
((
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
console
.
log
(
msgStr
+
'snapshot err.code:'
+
JSON
.
stringify
(
err
.
code
));
expect
()
.
assertFail
();
done
();
return
;
}
done
();
console
.
log
(
msgStr
+
'snapshot success data:'
+
JSON
.
stringify
(
data
));
})
done();
})
/**
* @tc.number SUB_WINDOW_DIALOGTARGETTOUCH_JSAPI_002
...
...
@@ -3250,11 +2119,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
tempType
=
ohosWindow
.
WindowType
.
TYPE_DIALOG
let
dialogTargetTouchTest2Win
=
null
function create() {
return new Promise(function (resolve, reject) {
ohosWindow.create(context, 'dialogTargetTouchTest2', tempType, (err, data) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
ohosWindow
.
create
(
context
,
'dialogTargetTouchTest2'
,
tempType
,
async
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError
(
err
,
caseName
,
'ohosWindow.create'
,
done
);
}
else
{
...
...
@@ -3264,24 +2129,9 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
}
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)
await
dialogTargetTouchTest2Win
.
destroy
()
done
();
})
}
await create()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return destroy()
})
})
/**
...
...
@@ -3297,7 +2147,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
wndId
=
'animationForShownTest2'
;
let
baseType
=
ohosWindow
.
WindowType
.
TYPE_SYSTEM_ALERT
;
let
tempWnd
=
null
;
ohosWindow.create(context, wndId, baseType, (err, data) => {
ohosWindow
.
create
(
context
,
wndId
,
baseType
,
async
(
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError
(
err
,
caseName
,
'ohosWindow.create '
+
baseType
,
done
);
}
else
{
...
...
@@ -3330,7 +2180,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
context
.
completeTransition
(
true
)
console
.
info
(
msgStr
+
'complete transition end'
);
}
tempWnd.destroy();
await
tempWnd
.
destroy
();
done
();
}
});
...
...
@@ -3346,11 +2196,7 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
console
.
log
(
msgStr
+
'begin context=='
+
JSON
.
stringify
(
context
));
let
dpClass
=
display
.
getDefaultDisplaySync
();
try {
expect
(
!!
dpClass
)
.
assertTrue
();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
dpClass
.
getCutoutInfo
((
err
,
data
)
=>
{
if
(
err
&&
err
.
code
)
{
unexpectedError
(
err
,
caseName
,
'displayClass.getCutoutInfo'
,
done
);
...
...
@@ -3373,54 +2219,32 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
baseType
=
ohosWindow
.
WindowType
.
TYPE_FLOAT
;
let
tempWnd
=
null
;
function create() {
function
create
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
wndId
,
baseType
,
(
err
,
data
)
=>
{
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) => {
tempWnd
=
await
createWin
()
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
done
();
})
expect
(
!!
tempWnd
)
.
assertTrue
();
tempWnd
.
showWithAnimation
(
async
(
error
,
animationData
)
=>
{
if
(
error
&&
error
.
code
)
{
unexpectedError
(
error
,
caseName
,
'Failed to show the window with animation'
,
done
);
}
else
{
console
.
info
(
'Succeeded in showing the window with animation. Data: '
+
JSON
.
stringify
(
animationData
));
resolve(animationData)
}
})
})
}
function destroy() {
return new Promise(function (resolve, reject) {
tempWnd.destroy();
resolve(true)
done();
})
await
tempWnd
.
destroy
()
done
()
}
await create()
.then(function (params) {
console.log(msgStr + 'create then: ' + JSON.stringify(params))
return showWithAnimation()
}).then(function (params) {
console.log(msgStr + 'showWithAnimation then: ' + JSON.stringify(params))
return destroy()
})
})
/**
...
...
@@ -3436,65 +2260,58 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
let
baseType
=
ohosWindow
.
WindowType
.
TYPE_FLOAT
;
let
tempWnd
=
null
function create() {
function
create
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
create
(
context
,
wndId
,
baseType
,
(
creare_err
,
data
)
=>
{
if
(
creare_err
&&
creare_err
.
code
)
{
unexpectedError(creare_err, caseName, 'ohosWindow.create ' + baseType, done);
}
try {
tempWnd = data
expect(!!tempWnd).assertTrue();
} catch (error) {
console.info(`tempWnd.show catch error: ${JSON.stringify(error)}`)
}
reject
(
null
)
}
else
{
resolve
(
data
)
}
})
})
}
function find() {
function
find
Win
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
ohosWindow
.
find
(
wndId
,
(
findErr
,
findWnd
)
=>
{
if
(
findErr
&&
findErr
.
code
)
{
unexpectedError(findErr, caseName, 'Failed to hide the window with animation', done);
reject
(
null
)
}
else
{
findWnd.hideWithAnimation((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'Failed to hide the window with animation', done);
} else {
console.info('Succeeded in hiding the window with animation. Data: ' + JSON.stringify(data));
done();
}
})
}
resolve
(
findWnd
)
}
})
})
}
function destroy() {
return new Promise(function (resolve, reject) {
tempWnd.destroy();
resolve(true)
tempWnd
=
await
createWin
()
.
catch
(
err
=>
{
console
.
info
(
msgStr
+
`ohosWindow.create failed error: ${JSON.stringify(err)}`
)
expect
()
.
assertFail
();
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
();
}
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.name Test setAspectRatioTest1
* @tc.desc Validate the scenario cancelled after setting the proportion of the content layout of the main window
*/
* @tc.number SUB_WINDOW_SETASPECTRATIO_JSAPI_001
* @tc.name Test setAspectRatioTest1
* @tc.desc Validate the scenario cancelled after setting the proportion of the content layout of the main window
*/
it
(
'setAspectRatioTest1'
,
0
,
async
function
(
done
)
{
let
caseName
=
'setAspectRatioTest1'
;
let
msgStr
=
'jsunittest '
+
caseName
+
' '
;
...
...
@@ -3577,8 +2394,5 @@ export default function windowCallbackTest(context, windowStage, abilityStorage)
await
setAspectRatio
()
})
}
)
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录