提交 2efa0128 编写于 作者: Z zhurong

add xts Modify remaining problems

Signed-off-by: Nzhurong <zhurong18@h-partners.com>
上级 26293ccb
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index"
import ohosWindow from '@ohos.window';
import display from '@ohos.display';
export default function windowCallbackTest(context, windowStage, abilityStorage) {
console.log('testets context: ' + JSON.stringify(context))
console.log('testets context windowStage: ' + JSON.stringify(windowStage));
console.log('testets context abilityStorage: ' + JSON.stringify(abilityStorage));
describe('windowCallback_test', function () {
console.log('describe testets start!!')
const TRUE_FLAG = true;
console.log('describe window_api_test start!!!');
var commonRGBColorArr = ['rgb(255,0,0)', 'rgb(0,255,0)', 'rgb(0,0,255)', 'rgb(255,255,255)', 'rgb(0,0,0)', 'rgb(249,0,230)', 'rgb(102,102,102)', 'rgb(255,247,0)'];
var commonNUMBERColorArr = ['#00FF0000', '#0000FF00', '#000000FF', '#00FFFFFF', '#00000000', '#00F900E6', '#00666666', '#00FFF700'];
var commonKEYColorArr = ['red', 'green', 'blue', 'white', 'black', 'pink', 'grey', 'yellow'];
var appWindowTypeArr = [];
var windowTypeArr = [];
var appWindowTypeDic = {
'TYPE_BASE': 0,
'TYPE_APP': 0,
'TYPE_APP_SUB_WINDOW': 1,
};
var systemWindowTypeArr = [];
var systemWindowTypeDic = {
'TYPE_SYSTEM_ALERT': 1,
'TYPE_INPUT_METHOD': 2,
'TYPE_STATUS_BAR': 3,
'TYPE_PANEL': 4,
'TYPE_KEYGUARD': 5,
'TYPE_VOLUME_OVERLAY': 6,
'TYPE_NAVIGATION_BAR': 7,
'TYPE_FLOAT': 8
}
var windowLayoutModeArr = [];
var windowLayoutModeDic = {
'WINDOW_LAYOUT_MODE_TILE': 1,
'WINDOW_LAYOUT_MODE_CASCADE': 0
};
var windowCount = 2022;
var listenerStatus = {
ready: 'ready',
pending: 'pending',
finished: 'finished'
};
var listenerData = {
on: false,
typeStr: '',
};
beforeAll(function () {
appWindowTypeArr = Object.keys(appWindowTypeDic);
systemWindowTypeArr = Object.keys(systemWindowTypeDic);
for (i in ohosWindow.WindowType) {
windowTypeArr.push(ohosWindow.WindowType[i]);
}
console.log('jsunittest beforeall');
console.log(msgStr + 'beforeall ohosWindow.windowType' + JSON.stringify(ohosWindow.windowType))
})
beforeEach(function () {
})
afterEach(async function (done) {
windowCount++;
console.log('jsunittest afterEach listenerData:' + JSON.stringify(listenerData));
if (listenerData.on) {
listenerData.on = false;
if (listenerData.typeStr === 'systemBarTintChange') {
console.log('jsunittest systemBarTintChange start on');
console.log('jsunittest systemBarTintChange end off listenerData.typeStr==' + JSON.stringify(listenerData.typeStr));
ohosWindow.off(listenerData.typeStr);
console.log('jsunittest systemBarTintChange end off');
} else if (newWindowObj) {
newWindowObj.off(listenerData.typeStr);
}
await sleep(3000);
}
done();
})
afterAll(function () {
})
function expectedError(error, caseName, apiName, done, code) {
let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: ';
console.log(msgStr + JSON.stringify(error));
expect(TRUE_FLAG).assertTrue();
expect(error.code === code).assertTrue();
done();
}
function unexpectedError(error, caseName, apiName, done) {
let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: ';
console.log(msgStr + JSON.stringify(error));
expect(TRUE_FLAG).assertFail();
done();
}
function sleep(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('sleep finished');
}, time);
})
}
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_006
* @tc.name Test setSystemBarEnableTest6
* @tc.desc Test ohosWindow.setSystemBarEnable API function test1.
*/
it('setSystemBarEnableTest6', 0, function (done) {
let caseName = 'setSystemBarEnableTest6';
let msgStr = 'jsunittest ' + caseName + ' ';
let [flagStatus, flagNav] = [false, false];
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', systembartintstate => {
console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint));
if (flagStatus || flagNav) {
expect(!!systembartintstate).assertTrue();
expect(!!systembartintstate.regionTint).assertTrue();
console.log(msgStr + 'flagStatus || flagNav' + msgStr + 'ohosWindow.on systemBarTintChange regionTint:' + JSON.stringify(systembartintstate.regionTint));
done();
}
})
let mainWnd = null;
console.log(msgStr + 'mainWnd = null');
console.log(msgStr + 'windowStage = ' + JSON.stringify(windowStage));
windowStage.getMainWindow((err, data) => {
console.log(msgStr + 'getMainWindow data2' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
expect(!!data).assertTrue();
mainWnd = data;
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
mainWnd.show((err, data) => {
console.log(msgStr + 'mainWnd.show err' + JSON.stringify(err));
console.log(msgStr + 'mainWnd.show data' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'mainWnd.show success');
mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen data:' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'mainWnd.setFullScreen success');
flagNav = true;
mainWnd.setSystemBarEnable(['navigation'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable navigation JSON.stringify(data)==' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navigation]', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'mainWnd.setSystemBarEnable success flagNav==' + flagNav);
})
flagStatus = true;
mainWnd.setSystemBarEnable(['status'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)===' + JSON.stringify(data));
if (err && err.code) {
console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(err)===' + JSON.stringify(err));
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done);
}
expect(!data).assertTrue();
})
})
})
})
console.log(msgStr + 'finished!!');
});
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_007
* @tc.name Test setSystemBarEnableTest7
* @tc.desc Verify that the scene hides the status bar and displays the navigation bar.
*/
it('setSystemBarEnableTest7', 0, function (done) {
let caseName = 'setSystemBarEnableTest7';
let msgStr = 'jsunittest ' + caseName + ' ';
let [flagStatus, flagNav] = [false, false];
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', systembartintstate => {
console.log(msgStr + 'ohosWindow.on systembartintstate :' + JSON.stringify(systembartintstate));
console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint));
if (flagStatus || flagNav) {
console.log(msgStr + 'ohosWindow.on flagStatus || flagNav:');
expect(!!systembartintstate).assertTrue();
done();
}
})
let mainWnd = null;
console.log(msgStr + 'mainWnd = null')
windowStage.getMainWindow((err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
expect(!!data).assertTrue();
mainWnd = data;
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
mainWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done);
}
console.log(msgStr + 'mainWnd.show success');
expect(!data).assertTrue();
mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done);
}
expect(!data).assertTrue();
mainWnd.setSystemBarEnable(['status'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable status JSON.stringify(data)==' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status]', done);
}
flagStatus = true;
expect(!data).assertTrue();
mainWnd.setSystemBarEnable(['navigation'], (err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [navitgation]', done);
}
flagNav = true;
expect(!data).assertTrue();
})
})
})
})
})
console.log(msgStr + 'finished!!');
});
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_008
* @tc.name Test setSystemBarEnableTest8
* @tc.desc Verify that the scene displays both the status bar and the navigation bar.
*/
it('setSystemBarEnableTest8', 0, function (done) {
let caseName = 'setSystemBarEnableTest8';
let msgStr = 'jsunittest ' + caseName + ' ';
let [flagStatus, flagNav] = [false, false];
console.log(msgStr + 'begin');
let mainWnd = null;
console.log(msgStr + 'mainWnd = null');
windowStage.getMainWindow((err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
expect(!!data).assertTrue();
mainWnd = data;
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
mainWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done);
}
console.log(msgStr + 'mainWnd.show success');
expect(!data).assertTrue();
mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done);
}
expect(!data).assertTrue();
mainWnd.setSystemBarEnable([], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done);
}
expect(!data).assertTrue();
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
setTimeout(() => {
ohosWindow.on('systemBarTintChange', systembartintstate => {
console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate));
console.log(msgStr + 'ohosWindow.on systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint));
setTimeout(() => {
if (flagStatus || flagNav) {
let enable = systembartintstate.regionTint[0].isEnable
let numType = systembartintstate.regionTint[0].type
console.log(msgStr + 'ohosWindow.on isEnable : ' + JSON.stringify(enable));
console.log(msgStr + 'ohosWindow.on numType : ' + JSON.stringify(numType));
expect(numType === ohosWindow.WindowType.TYPE_NAVIGATION_BAR || enable).assertTrue();
}
done();
}, 3000)
})
}, 2300)
mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done);
}
flagStatus = true;
flagNav = true;
expect(!data).assertTrue();
})
})
})
})
})
});
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_009
* @tc.name Test setSystemBarEnableTest9
* @tc.desc Verify that the scene hides both the status bar and the navigation bar.
*/
it('setSystemBarEnableTest9', 0, function (done) {
let caseName = 'setSystemBarEnableTest9';
let msgStr = 'jsunittest ' + caseName + ' ';
let [flagStatus, flagNav] = [false, false];
console.log(msgStr + 'begin');
let mainWnd = null;
console.log(msgStr + 'mainWnd = null');
windowStage.getMainWindow((err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
expect(!!data).assertTrue();
mainWnd = data;
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
mainWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done);
}
console.log(msgStr + 'mainWnd.show success');
expect(!data).assertTrue();
mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen', done);
}
expect(!data).assertTrue();
mainWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable status,navigation JSON.stringify(data)==' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [status,navigation]', done);
}
flagStatus = true;
flagNav = true;
expect(!data).assertTrue();
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systembartintstate) => {
console.log(msgStr + 'ohosWindow.on systemBarTintChange :' + JSON.stringify(systembartintstate));
console.log(msgStr + 'ohosWindow.on systemBarTintChange systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint));
if (flagStatus || flagNav) {
expect(!!systembartintstate).assertTrue();
done();
}
})
mainWnd.setSystemBarEnable([], (err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done);
}
expect(!data).assertTrue();
})
})
})
})
})
});
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_010
* @tc.name Test setSystemBarEnableTest10
* @tc.desc Verify the scene where illegal values are entered when the navigation bar and status bar are displayed or hidden
*/
it('setSystemBarEnableTest10', 0, function (done) {
let caseName = 'setSystemBarEnableTest10';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let mainWnd = null;
console.log(msgStr + 'mainWnd = null');
windowStage.getMainWindow((err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'windowStage.getMainWindow', done);
}
expect(!!data).assertTrue();
mainWnd = data;
console.log(msgStr + 'await windowStage JSON.stringify(mainWnd)===' + JSON.stringify(mainWnd));
mainWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.show', done);
}
console.log(msgStr + 'mainWnd.show success');
expect(!data).assertTrue();
mainWnd.setFullScreen(true, (err, data) => {
console.log(msgStr + 'mainWnd.setFullScreen: ' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setFullScreen true', done);
}
expect(!data).assertTrue();
mainWnd.setSystemBarEnable([], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringify(data)==' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done);
}
expect(!data).assertTrue();
mainWnd.setSystemBarEnable([null, '123'], (err, data) => {
console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(data)==' + JSON.stringify(data));
console.log(msgStr + 'mainWnd.setSystemBarEnable [null,123] JSON.stringify(err)==' + JSON.stringify(err));
if (err && err.code) {
expect(err.code === 130).assertTrue();
done();
} else {
unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable [null,123]', done);
}
})
})
})
})
})
});
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_004
* @tc.name Test setSystemBarPropertiesTest1
* @tc.desc TVerify the scene where the colors of the status bar and navigation bar are set in RGB
*/
it('setSystemBarPropertiesTest4', 0, done => {
let caseName = 'setSystemBarPropertiesTest4';
let msgStr = 'jsunittest ' + caseName + ' ';
let cloneColorArr = JSON.parse(JSON.stringify(commonRGBColorArr));
let compareCount = 0;
let listenerFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (listenerFlag === listenerStatus.pending) {
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) {
console.log(msgStr + 'systemBarTintChange compare start!');
compareCount++;
let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor);
let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor);
expect(backgroundIndex === -1).assertTrue();
expect(contentColorIndex === -1).assertTrue();
}
}
}
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
windowStage.getMainWindow((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
}
let tempWnd = data
expect(!!tempWnd).assertTrue();
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
tempWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.show', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.show success');
tempWnd.setFullScreen(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
listenerFlag = listenerStatus.pending;
let loopCount = commonRGBColorArr.length
for (let i = 0; i < loopCount; i++) {
let tempColor = commonRGBColorArr[i];
let systemBarProperties = {
statusBarColor: tempColor,
isStatusBarLightIcon: true,
statusBarContentColor: tempColor,
navigationBarColor: tempColor,
isNavigationBarLightIcon: false,
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');
})
}
setTimeout(() => {
console.log(msgStr + 'time wait finished. compareCount: ' + compareCount);
listenerFlag = listenerStatus.finished;
done();
}, 10000)
})
})
})
})
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_005
* @tc.name Test setSystemBarPropertiesTest5
* @tc.desc Verify the scene where the status bar and navigation bar colors are set in hexadecimal form
*/
it('setSystemBarPropertiesTest5', 0, done => {
let caseName = 'setSystemBarPropertiesTest5';
let msgStr = 'jsunittest ' + caseName + ' ';
let cloneColorArr = {
SBC: JSON.parse(JSON.stringify(commonNUMBERColorArr)),
SCC: JSON.parse(JSON.stringify(commonNUMBERColorArr)),
NBC: JSON.parse(JSON.stringify(commonNUMBERColorArr)),
NCC: JSON.parse(JSON.stringify(commonNUMBERColorArr))
};
let compareCount = 0;
let listenerFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (listenerFlag === listenerStatus.pending) {
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR) {
console.log(msgStr + 'systemBarTintChange compare start! arrLength= '+ arrLength);
compareCount++;
let backgroundIndex = cloneColorArr.SBC.indexOf(tempData.backgroundColor);
let contentColorIndex = cloneColorArr.SCC.indexOf(tempData.contentColor);
if (backgroundIndex >= 0) {
cloneColorArr.SBC.splice(backgroundIndex, 1);
}
if (contentColorIndex >= 0) {
cloneColorArr.SCC.splice(contentColorIndex, 1);
}
console.log(msgStr+'compareCount: '+compareCount +' ,length: '+JSON.stringify(cloneColorArr.SCC.length)+ ' ,cloneColorArr.SBC:'+JSON.stringify(cloneColorArr.SBC));
console.log(msgStr+'compareCount: '+compareCount +' ,length: '+JSON.stringify(cloneColorArr.SCC.length)+' ,cloneColorArr.SCC'+JSON.stringify(cloneColorArr.SCC));
} else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) {
console.log(msgStr + 'systemBarTintChange compare start!');
compareCount++;
let backgroundIndex = cloneColorArr.NBC.indexOf(tempData.backgroundColor);
let contentColorIndex = cloneColorArr.NCC.indexOf(tempData.contentColor);
if (backgroundIndex >= 0) {
cloneColorArr.NBC.splice(backgroundIndex, 1);
}
if (contentColorIndex >= 0) {
cloneColorArr.NCC.splice(contentColorIndex, 1);
}
let ca = cloneColorArr;
let flag = ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length
if(compareCount===18&&!flag){
console.log(msgStr + 'compareCount: '+compareCount +' ,true flag:'+flag);
expect(true).assertTrue();
done();
}else{
console.log(msgStr + 'compareCount: '+compareCount +' ,flag:'+flag);
}
console.log(msgStr+'compareCount: '+compareCount +' ,length: '+JSON.stringify(cloneColorArr.NBC.length)+ ' ,cloneColorArr.SBC:'+JSON.stringify(cloneColorArr.NBC));
console.log(msgStr+'compareCount: '+compareCount +' ,length: '+JSON.stringify(cloneColorArr.NCC.length)+' ,cloneColorArr.SCC'+JSON.stringify(cloneColorArr.NCC));
}
}
}
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
windowStage.getMainWindow((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
}
let tempWnd = data
expect(!!tempWnd).assertTrue();
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
tempWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.show', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.show success');
tempWnd.setFullScreen(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
listenerFlag = listenerStatus.pending;
let loopCount = commonNUMBERColorArr.length
for (let i = 0; i < loopCount; i++) {
let tempColor = commonNUMBERColorArr[i];
let systemBarProperties = {
statusBarColor: tempColor,
isStatusBarLightIcon: true,
statusBarContentColor: tempColor,
navigationBarColor: tempColor,
isNavigationBarLightIcon: true,
navigationBarContentColor: tempColor,
};
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) {
expect(TRUE_FLAG).assertFail();
done();
}
})
}
})
})
})
})
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_006
* @tc.name Test setSystemBarPropertiesTest6
* @tc.desc TVerify the scene where the status bar and navigation bar colors are set as keywords
*/
it('setSystemBarPropertiesTest6', 0, done => {
let caseName = 'setSystemBarPropertiesTest6';
let msgStr = 'jsunittest ' + caseName + ' ';
let cloneColorArr = JSON.parse(JSON.stringify(commonKEYColorArr));
let compareCount = 0;
let listenerFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (listenerFlag === listenerStatus.pending) {
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) {
console.log(msgStr + 'systemBarTintChange compare start!');
compareCount++;
let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor);
let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor);
expect(backgroundIndex === -1).assertTrue();
expect(contentColorIndex === -1).assertTrue();
}
}
}
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
windowStage.getMainWindow((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
}
let tempWnd = data
expect(!!tempWnd).assertTrue();
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
tempWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.show', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.show success');
tempWnd.setFullScreen(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
listenerFlag = listenerStatus.pending;
let loopCount = commonRGBColorArr.length
for (let i = 0; i < loopCount; i++) {
let tempColor = commonKEYColorArr[i];
let systemBarProperties = {
statusBarColor: tempColor,
isStatusBarLightIcon: true,
statusBarContentColor: tempColor,
navigationBarColor: tempColor,
isNavigationBarLightIcon: false,
navigationBarContentColor: tempColor,
};
tempWnd.setSystemBarProperties(systemBarProperties, (err, data) => {
console.log(msgStr + 'tempWnd.setSystemBarProperties err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.setSystemBarProperties data' + JSON.stringify(data));
if (err && err.code) {
expect(TRUE_FLAG).assertFail();
done();
}
})
}
setTimeout(() => {
console.log(msgStr + 'time wait finished. compareCount: ' + compareCount);
listenerFlag = listenerStatus.finished;
done();
}, 10000)
})
})
})
})
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_005
* @tc.name Test create5
* @tc.desc Verify the scenario of creating the application type window
*/
it('createTest5', 0, done => {
let caseName = 'createTest5';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin context==' + JSON.stringify(context));
let loopCount = appWindowTypeArr.length;
console.log(msgStr + 'loopCount: ' + loopCount);
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) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
if (err && err.code) {
expect(err.code === 130).assertTrue();
console.log(msgStr + 'ohosWindow.create err.code==' + JSON.stringify(err.code))
if (i === loopCount - 1) {
done();
}
} else {
expectedError(err, caseName, 'ohosWindow.create ' + tempType, done);
}
})
}
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_006
* @tc.name Test createTest6
* @tc.desc Verify the scenario of creating the system type window
*/
it('createTest6', 0, done => {
let caseName = 'createTest6';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let loopCount = systemWindowTypeArr.length;
console.log('jsunittest loopCount: ' + loopCount);
for (let i = 0; i < loopCount; i++) {
let tempType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT;
let windId = 'createTest6' + i;
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
ohosWindow.create(context, windId, tempType, (err, data) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done);
return;
}
expect(!!data).assertTrue();
let tempWnd = data
console.log(msgStr + 'ohosWindow.create ' + tempType + ' wnd: ' + tempWnd);
tempWnd.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);
expect(!!data).assertTrue();
expect(data.type == tempType).assertTrue();
})
})
}
done();
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_007
* @tc.name Test createTest7
* @tc.desc Verify the scenario of creating a window of a type that does not exist
*/
it('createTest7', 0, done => {
let caseName = 'createTest7';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let tempType = 5000;
let windId = 'createTest7';
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
ohosWindow.create(context, windId, tempType, (err, data) => {
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
if (err && err.code) {
expect(err.code === 130).assertTrue();
done();
return;
}
expectedError(err, caseName, 'ohosWindow.create', done);
})
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_008
* @tc.name Test createTest8
* @tc.desc Verify the scenario of creating a window with duplicate IDs
*/
it('createTest8', 0, done => {
let caseName = 'createTest8';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let windowId = 'sameid'
ohosWindow.create(context, windowId, 1, (err, data) => {
console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err));
if (err && err.code) {
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
expect(!!data).assertTrue();
ohosWindow.create(context, windowId, 1, (err, data) => {
console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err));
if (err && err.code) {
console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data));
expect(err.code).assertEqual(120)
done();
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
console.log(msgStr + 'ohosWindow.create 1 twice data: ' + JSON.stringify(data));
}
})
})
})
/**
* @tc.number SUB_WINDOW_ON_OFF_JSAPI_005
* @tc.name Test listenerTest5
* @tc.desc Verify whether the change of avoidance area and change monitoring can be turned on normally
*/
it('listenerTest5', 0, function (done) {
let caseName = 'listenerTest5';
let msgStr = 'jsunittest ' + caseName + ' ';
let listenerOnFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
let tempWnd = null;
windowStage.getMainWindow((err, data) => {
console.log(msgStr + 'windowStage.getMainWindow err: ' + JSON.stringify(err));
console.log(msgStr + 'windowStage.getMainWindow data: ' + JSON.stringify(data));
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.show', done);
}
tempWnd = data
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
tempWnd.show((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.show', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.show success');
tempWnd.setFullScreen(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
tempWnd.on('systemAvoidAreaChange', avoidAreaData => {
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, avoidAreaData : ' + JSON.stringify(avoidAreaData));
if (listenerOnFlag === listenerStatus.pending) {
listenerOnFlag = listenerStatus.finished;
expect(!!avoidAreaData).assertTrue();
}
done();
})
tempWnd.setSystemBarEnable([], (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done);
}
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
listenerOnFlag = listenerStatus.pending;
})
tempWnd.setSystemBarEnable(['status', 'navigation'], (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
}
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
})
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished');
})
})
})
})
/**
* @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_003
* @tc.name Test setWindowTypeTest3
* @tc.desc Verify the scenario where the normal window type is set
*/
it('setWindowTypeTest3', 0, function (done) {
let caseName = 'setWindowTypeTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let windowId = 'setWindowTypeTest3';
console.log(msgStr + 'begin');
let tempWnd = null
let tempTypeArr = [];
ohosWindow.create(context, windowId, baseWndType, (err, data) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if (!!data) {
tempWnd = data
console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
let loopCount1 = systemWindowTypeArr;
console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount1))
for (let i = 0; i < loopCount1.length; i++) {
let tempType = ohosWindow.WindowType[loopCount1[i]];
console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' start');
tempTypeArr.push(tempType);
tempWnd.setWindowType(tempType, (err, data) => {
console.log(msgStr + 'tempWnd.setWindowType i: ' + i);
console.log(msgStr + 'tempWnd.setWindowType err: ' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.setWindowType data: ' + JSON.stringify(data));
console.log(msgStr + 'tempWnd.setWindowType !data: ' + !data);
if (!data) {
expect(!data).assertTrue();
console.log(msgStr + 'tempWnd.getProperties start');
tempWnd.getProperties((err, dataProper) => {
console.log(msgStr + 'tempWnd.getProperties err: ' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.getProperties dataProper: ' + JSON.stringify(dataProper));
console.log(msgStr + 'tempWnd.getProperties !!dataProper: ' + !!dataProper);
expect(!!dataProper).assertTrue();
if (!!dataProper) {
console.log(msgStr + 'tempWnd.getProperties true tempTypeArr: ' + JSON.stringify(tempTypeArr));
console.log(msgStr + 'tempWnd.getProperties true i: ' + i);
tempTypeArr.splice(tempTypeArr.findIndex(item => item === dataProper.type), 1);
console.log(msgStr + 'tempWnd.getProperties true tempTypeArr.length: ' + tempTypeArr.length);
console.log(msgStr + 'tempWnd.getProperties true loopCount1.length: ' + loopCount1.length);
console.log(msgStr + 'tempWnd.getProperties true tempTypeArr.length + 1: ' + tempTypeArr.length + 1);
expect((loopCount1.length - i) == (tempTypeArr.length + 1)).assertTrue();
if (i == loopCount1.length - 1) {
console.log(msgStr + 'tempWnd.getProperties i=' + i + ' , loopCount1.length-1==' + loopCount1.length);
done();
}
} else {
unexpectedError(err, caseName, 'tempWnd.getProperties aa', done);
}
})
} else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
}
console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' end');
})
}
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
})
})
/**
* @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_004
* @tc.name Test setWindowTypeTest4
* @tc.desc Verify the scene of setting illegal window type
*/
it('setWindowTypeTest4', 0, function (done) {
let caseName = 'setWindowTypeTest4';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let changedWndType = null;
let windowId = 'setWindowTypeTest4';
console.log(msgStr + 'begin');
let tempWnd = null
ohosWindow.create(context, windowId, baseWndType, (err, data) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if (!!data) {
tempWnd = data
expect(!!tempWnd).assertTrue();
tempWnd.setWindowType(changedWndType, (err, data) => {
console.log(msgStr + 'tempWnd.setWindowType err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.setWindowType data' + JSON.stringify(data));
console.log(msgStr + 'tempWnd.setWindowType !!data' + !!data);
if (!!data) {
expectedError(err, caseName, 'tempWnd.setWindowType', done);
} else {
expect(err.code == 130).assertTrue();
done();
}
})
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
})
})
/**
* @tc.number SUB_WINDOW_DESTROY_JSAPI_002
* @tc.name Test destroyTest2
* @tc.desc Verification window destruction scenario
*/
it('destroyTest2', 0, function (done) {
let caseName = 'destroyTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let windowId = 'destroyTest2';
console.log(msgStr + 'begin');
let tempWnd = null
ohosWindow.create(context, windowId, baseWndType, (err, data) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if (!!data) {
tempWnd = data
expect(!!tempWnd).assertTrue();
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 {
expect(!data).assertTrue();
ohosWindow.find(windowId, (err, data) => {
console.log(msgStr + 'ohosWindow.find err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.find data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.find !!data' + !!data);
if (err && err.code) {
expect(err.code == 120).assertTrue();
done();
} else {
expectedError(err, caseName, 'tempWnd.setWindowType', done);
}
})
}
})
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
})
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_007
* @tc.name Test loadContentTest7
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest7', 0, function (done) {
let caseName = 'loadContentTest7';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let windowId = 'loadContentTest7';
console.log(msgStr + 'begin');
let tempWnd = null
ohosWindow.create(context, windowId, baseWndType, (err, data) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if (!!data) {
tempWnd = data
expect(!!tempWnd).assertTrue();
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) {
expectedError(err, caseName, 'tempWnd.loadContent', done);
} else {
expect(!data).assertTrue();
done();
}
})
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
})
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_008
* @tc.name Test loadContentTest8
* @tc.desc Verify the scenario of loading a page that does not exist
*/
it('loadContentTest8', 0, function (done) {
let caseName = 'loadContentTest8';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let windowId = 'loadContentTest8';
console.log(msgStr + 'begin');
let tempWnd = null
ohosWindow.create(context, windowId, baseWndType, (err, data) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
console.log(msgStr + 'ohosWindow.create data' + JSON.stringify(data));
console.log(msgStr + 'ohosWindow.create !!data' + !!data);
if (!!data) {
tempWnd = data
expect(!!tempWnd).assertTrue();
tempWnd.loadContent(null, (err, data) => {
console.log(msgStr + 'tempWnd.loadContent err' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.loadContent data' + JSON.stringify(data));
console.log(msgStr + 'tempWnd.loadContent !!data' + !!data);
if (err && err.code) {
expect(err.code === 130).assertTrue();
done();
} else {
expectedError(err, caseName, 'tempWnd.loadContent', done);
}
})
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
})
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_009
* @tc.name Test loadContentTest9
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest9', 0, function (done) {
let caseName = 'loadContentTest9';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
windowStage.loadContent('pages/index/index.ets', (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.loadContent', done);
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err));
} else {
expect(!data).assertTrue();
console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data));
}
done();
});
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_010
* @tc.name Test loadContentTest10
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest10', 0, function (done) {
let caseName = 'loadContentTest10';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
windowStage.loadContent(null, (err, data) => {
if (err && err.code) {
expectedError(err, caseName, 'windowStage.loadContent', done, 130);
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err));
}
done();
});
console.log(msgStr + 'end');
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_011
* @tc.name Test loadContentTest11
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest11', 0, async function (done) {
let caseName = 'loadContentTest11';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
windowStage.loadContent('pages/index/index.ets', abilityStorage, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.loadContent', done);
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err));
} else {
expect(!data).assertTrue();
console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data));
}
done();
});
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_012
* @tc.name Test loadContentTest12
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest12', 0, function (done) {
let caseName = 'loadContentTest12';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
windowStage.loadContent(null, abilityStorage, (err, data) => {
if (err && err.code) {
expectedError(err, caseName, 'windowStage.loadContent', done, 130);
console.log(msgStr + 'windowStage.loadContent(pages/index/index.ets)' + JSON.stringify(err));
}
done();
});
})
/**
* @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_003
* @tc.name Test createSubWindowTest3
* @tc.desc Verify the scenario of creating an auxiliary window
*/
it('createSubWindowTest3', 0, function (done) {
let caseName = 'createSubWindowTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
windowStage.createSubWindow('createSubWindowTest3', (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.createSubWindow', done);
console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest3) err=' + JSON.stringify(err));
} else {
expect(!!data).assertTrue();
console.log(msgStr + 'windowStage.createSubWindow end data=' + JSON.stringify(data));
}
done();
});
})
/**
* @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_004
* @tc.name Test createSubWindowTest4
* @tc.desc Verify the scene of entering illegal values to create an auxiliary window
*/
it('createSubWindowTest4', 0, function (done) {
let caseName = 'createSubWindowTest4';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
windowStage.createSubWindow(null, (err, data) => {
if (err && err.code) {
expectedError(err, caseName, 'windowStage.createSubWindow', done, 130);
console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err));
} else {
expect(false).assertTrue();
console.log(msgStr + 'windowStage.createSubWindow end data=' + JSON.stringify(data));
}
done();
});
})
/**
* @tc.number SUB_WINDOW_GETSUBWINDOW_JSAPI_002
* @tc.name Test getSubWindowTest2
* @tc.desc Verify the scene of obtaining all auxiliary sub windows
*/
it('getSubWindowTest2', 0, async function (done) {
let caseName = 'getSubWindowTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
windowStage.getSubWindow((err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.getSubWindow', done);
console.log(msgStr + 'windowStage.getSubWindow(null) err=' + JSON.stringify(err));
} else {
expect(!!data).assertTrue();
console.log(msgStr + 'windowStage.getSubWindow end data=' + JSON.stringify(data));
}
done();
});
})
/**
* @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_002
* @tc.name Test setPrivacyModeTest2
* @tc.desc Verify the scene where the application sub window is set as a security layer
*/
it('setPrivacyModeTest2', 0, async function (done) {
let caseName = 'setPrivacyModeTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow));
let mainWnd = null;
ohosWindow.create(context, 'setPrivacyModeTest2', ohosWindow.WindowType.TYPE_SYSTEM_ALERT, (err, data) => {
if (err && err.code) {
console.log(msgStr + 'ohosWindow.create fail err:' + JSON.stringify(err));
expect().assertFail();
done();
} else {
expect(data != null).assertTrue();
console.log(msgStr + 'ohosWindow.create success data' + data);
mainWnd = data;
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err));
expect().assertFail();
done();
} else {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data));
expect(!data.isPrivacyMode).assertTrue();
mainWnd.setPrivacyMode(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err));
} else {
expect(!data).assertTrue();
console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data));
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err));
expect().assertFail();
done();
} else {
console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data));
expect(data.isPrivacyMode).assertTrue();
mainWnd.setPrivacyMode(false, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err));
} else {
expect(!data).assertTrue();
console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data));
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err));
expect().assertFail();
done();
} else {
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data));
expect(!data.isPrivacyMode).assertTrue();
}
done();
})
}
});
}
})
}
});
}
})
}
})
})
/**
* @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_003
* @tc.name Test setPrivacyModeTest3
* @tc.desc Verify that the auxiliary window is set as the security layer
*/
it('setPrivacyModeTest3', 0, async function (done) {
let caseName = 'setPrivacyModeTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin ohosWindow =' + JSON.stringify(ohosWindow));
let mainWnd = null;
windowStage.createSubWindow('setPrivacyModeTest3', (err, data) => {
if (err && err.code) {
console.log(msgStr + 'windowStage.createSubWindow fail err:' + JSON.stringify(err));
expect().assertFail();
done();
} else {
expect(data != null).assertTrue();
console.log(msgStr + 'windowStage.createSubWindow success data' + data);
mainWnd = data;
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=false err: ' + JSON.stringify(err));
expect().assertFail();
done();
} else {
console.log(msgStr + 'mainWnd.getProperties first data.isPrivacyMode=fasle data:' + JSON.stringify(data));
expect(!data.isPrivacyMode).assertTrue();
mainWnd.setPrivacyMode(true, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err));
} else {
expect(!data).assertTrue();
console.log(msgStr + 'mainWnd.setPrivacyMode true data=' + JSON.stringify(data));
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true fail err: ' + JSON.stringify(err));
expect().assertFail();
done();
} else {
console.log(msgStr + 'mainWnd.getProperties second isPrivacyMode=true callback data:' + JSON.stringify(data));
expect(data.isPrivacyMode).assertTrue();
mainWnd.setPrivacyMode(false, (err, data) => {
if (err && err.code) {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err));
} else {
expect(!data).assertTrue();
console.log(msgStr + 'mainWnd.setPrivacyMode(false) end data=' + JSON.stringify(data));
mainWnd.getProperties((err, data) => {
if (err.code != 0) {
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback fail err: ' + JSON.stringify(err));
expect().assertFail();
done();
} else {
console.log(msgStr + 'mainWnd.getProperties data.isPrivacyMode=fasle callback data:' + JSON.stringify(data));
expect(!data.isPrivacyMode).assertTrue();
}
done();
})
}
});
}
})
}
});
}
})
}
})
})
})
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-nocheck
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index"
import ohosWindow from '@ohos.window';
import screenManager from '@ohos.screen';
import display from '@ohos.display';
export default function windowPromiseTest(context, windowStage, abilityStorage) {
console.log('windowTest context: ' + JSON.stringify(context))
console.log('windowTest abilityStorage: ' + JSON.stringify(abilityStorage))
describe('windowPromise_test', function () {
console.log('describe window_api_test start!!!')
const TRUE_FLAG = true;
var commonRGBColorArr = ['rgb(255,0,0)', 'rgb(0,255,0)', 'rgb(0,0,255)', 'rgb(255,255,255)', 'rgb(0,0,0)', 'rgb(249,0,230)', 'rgb(102,102,102)', 'rgb(255,247,0)'];
var commonNUMBERColorArr = ['#00FF0000', '#0000FF00', '#000000FF', '#00FFFFFF', '#00000000', '#00F900E6', '#00666666', '#00FFF700'];
var commonKEYColorArr = ['red', 'green', 'blue', 'white', 'black', 'pink', 'grey', 'yellow'];
var appWindowTypeArr = [];
var windowTypeArr = [];
var appWindowTypeDic = {
'TYPE_BASE': 0,
'TYPE_APP': 0,
'TYPE_APP_SUB_WINDOW': 1,
};
var systemWindowValueArr = [];
var systemWindowTypeArr = [];
var systemWindowTypeDicArr = [];
var systemWindowTypeDic = {
'TYPE_SYSTEM_ALERT': 1,
'TYPE_INPUT_METHOD': 2,
'TYPE_STATUS_BAR': 3,
'TYPE_PANEL': 4,
'TYPE_KEYGUARD': 5,
'TYPE_VOLUME_OVERLAY': 6,
'TYPE_NAVIGATION_BAR': 7,
'TYPE_FLOAT': 8
}
var windowLayoutModeArr = [];
var windowLayoutModeDic = {
'WINDOW_LAYOUT_MODE_TILE': 1,
'WINDOW_LAYOUT_MODE_CASCADE': 0
};
var windowCount = 2022;
var listenerStatus = {
ready: 'ready',
pending: 'pending',
finished: 'finished'
};
var listenerData = {
on: false,
typeStr: '',
};
var newWindowObj = null;
const WINDOW_NAME = 'windowName';
beforeAll(function () {
console.log('jsunittest beforeall ohosWindow.WindowType=' + JSON.stringify(ohosWindow.WindowType));
systemWindowTypeDicArr = Object.keys(systemWindowTypeDic);
systemWindowValueArr = Object.keys(systemWindowTypeDic);
systemWindowTypeArr = Object.keys(systemWindowTypeDic);
for (i in ohosWindow.WindowType) {
windowTypeArr.push(ohosWindow.WindowType[i])
}
})
beforeEach(function () {
})
afterEach(async function (done) {
windowCount++;
if (listenerData.on) {
listenerData.on = false;
console.log('jsunittest afterEach listener off, listenerData:' + JSON.stringify(listenerData));
if (listenerData.typeStr === 'systemBarTintChange') {
ohosWindow.off(listenerData.typeStr);
} else if (newWindowObj) {
newWindowObj.off(listenerData.typeStr);
}
await sleep(3000);
}
done();
})
afterAll(function () {
})
function expectedError(error, caseName, apiName, done, code) {
let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: ';
console.log(msgStr + JSON.stringify(error));
if (error.code === code) {
expect(TRUE_FLAG).assertTrue();
}
done();
}
function unexpectedError(error, caseName, apiName, done) {
let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: ';
console.log(msgStr + JSON.stringify(error));
expect(TRUE_FLAG).assertFail();
done();
}
function sleep(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('sleep finished');
}, time);
})
}
/**
* @tc.number SUB_WINDOW_ON_OFF_JSAPI_001
* @tc.name Test listenerTest1
* @tc.desc Verify whether the change monitoring of avoidance area can be started normally.
*/
it('listenerTest1', 0, async function (done) {
let caseName = 'listenerTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
let listenerOnFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
listenerData.on = true;
listenerData.typeStr = 'systemAvoidAreaChange';
tempWnd.on('systemAvoidAreaChange', (avoidAreaData) => {
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, systemBatData : ' + JSON.stringify(avoidAreaData));
if (listenerOnFlag === listenerStatus.pending) {
listenerOnFlag = listenerStatus.finished;
expect(!!avoidAreaData).assertTrue();
done();
}
})
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable([]).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished');
await sleep(1000);
listenerOnFlag = listenerStatus.pending;
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
})
/**
* @tc.number SUB_WINDOW_ON_OFF_JSAPI_002
* @tc.name Test listenerTest2
* @tc.desc Verify that the window size avoidance area changes and monitor whether it can be opened normally.
*/
it('listenerTest2', 0, async function (done) {
let caseName = 'listenerTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
let wndId = 'listenerTest2';
let baseType = 2;
let changedModel = 102;
let baseValue = 100;
let resizeValue = 200;
let listenerOnFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
let tempWnd = await ohosWindow.create(context, wndId, baseType).catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done);
});
console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
listenerData.on = true;
listenerData.typeStr = 'windowSizeChange';
tempWnd.on('windowSizeChange', (sizeData) => {
console.log(msgStr + 'tempWnd.on windowSizeChange, systemBatData : ' + JSON.stringify(sizeData));
if (listenerOnFlag === listenerStatus.pending) {
listenerOnFlag = listenerStatus.finished;
expect(!!sizeData).assertTrue();
expect(sizeData.width === resizeValue).assertTrue();
expect(sizeData.height === resizeValue).assertTrue();
done();
}
})
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setWindowMode(changedModel).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setWindowMode ' + changedModel, done);
});
console.log(msgStr + 'tempWnd.setWindowMode ' + changedModel + ' success');
await tempWnd.resetSize(baseValue, baseValue).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.resetSize(' + baseValue + ', ' + baseValue + ')', done);
});
console.log(msgStr + 'tempWnd.resetSize(' + baseValue + ', ' + baseValue + ') success');
console.log(msgStr + 'tempWnd.on windowSizeChange finished');
await sleep(1000);
listenerOnFlag = listenerStatus.pending;
await tempWnd.resetSize(resizeValue, resizeValue).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.resetSize(' + resizeValue + ', ' + resizeValue + ')', done);
});
console.log(msgStr + 'tempWnd.resetSize(' + resizeValue + ', ' + resizeValue + ') success');
})
/**
* @tc.number SUB_WINDOW_ON_OFF_JSAPI_003
* @tc.name Test listenerTest3
* @tc.desc Verify whether the change monitoring of avoidance area can be started normally.
*/
it('listenerTest3', 0, async function (done) {
let caseName = 'listenerTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
let listenerOffFlag = listenerStatus.ready;
console.log(msgStr + 'begin 1');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
listenerData.on = true;
listenerData.typeStr = 'systemAvoidAreaChange';
tempWnd.on('systemAvoidAreaChange', (avoidAreaData) => {
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, systemBatData : ' + JSON.stringify(avoidAreaData));
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, systemBatData 1100 : ' + JSON.stringify(avoidAreaData));
done();
})
console.log(msgStr + 'tempWnd.on systemAvoidAreaChange finished');
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable([]).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
await sleep(1000);
tempWnd.off('systemAvoidAreaChange');
console.log(msgStr + 'tempWnd.off systemAvoidAreaChange finished');
await sleep(1200);
listenerOffFlag = listenerStatus.pending;
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
})
/**
* @tc.number SUB_WINDOW_ON_OFF_JSAPI_004
* @tc.name Test listenerTest4
* @tc.desc Verify whether the window size change monitoring can be closed normally.
*/
it('listenerTest4', 0, async function (done) {
let caseName = 'listenerTest4';
let msgStr = 'jsunittest ' + caseName + ' ';
let wndId = 'listenerTest4';
let baseType = 2;
let changedModel = 102;
let listenerOffFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
let tempWnd = await ohosWindow.create(context, wndId, baseType).catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done);
});
console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
listenerData.on = true;
listenerData.typeStr = 'windowSizeChange';
tempWnd.on('windowSizeChange', (sizeData) => {
console.log(msgStr + 'tempWnd.on windowSizeChange, sizeData : ' + JSON.stringify(sizeData));
if (listenerOffFlag === listenerStatus.pending) {
listenerOffFlag = listenerStatus.finished;
console.log(msgStr + 'tempWnd.on windowSizeChange, listenerOffFlag === listenerStatus.pending : ' + JSON.stringify(sizeData));
expect(sizeData.width === 100).assertTrue();
expect(sizeData.height === 100).assertTrue();
done();
}
})
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setWindowMode(changedModel).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setWindowMode ' + changedModel, done);
});
console.log(msgStr + 'tempWnd.setWindowMode ' + changedModel + ' success');
await tempWnd.resetSize(100, 100).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.resetSize(100, 100)', done);
});
console.log(msgStr + 'tempWnd.resetSize(100, 100) success');
console.log(msgStr + 'tempWnd.on windowSizeChange finished');
listenerOffFlag = listenerStatus.pending;
await sleep(1000);
tempWnd.off('windowSizeChange');
console.log(msgStr + 'tempWnd.off windowSizeChange finished');
sleep(1000);
await tempWnd.resetSize(200, 200).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.resetSize(200, 200)', done);
console.log(msgStr + 'tempWnd.resetSize(200, 200) err: ' + JSON.stringify(err));
});
console.log(msgStr + 'tempWnd.resetSize(200, 200) success');
})
/**
* @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_001
* @tc.name Test setWindowTypeTest1
* @tc.desc Test window.setWindowType API function test.
*/
it('setWindowTypeTest1', 0, async function (done) {
let caseName = 'setWindowTypeTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let windowId = 'setWindowTypeTest1';
console.log(msgStr + 'begin');
let tempWnd = null
let tempTypeArr = [];
tempWnd = await ohosWindow.create(context, windowId, baseWndType).catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.create', done);
})
console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' ,tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
let loopCount1 = systemWindowTypeArr;
console.log(msgStr + 'ohosWindow.windowType' + JSON.stringify(loopCount1))
for (let i = 1; i < loopCount1.length; i++) {
let tempType = ohosWindow.WindowType[loopCount1[i]];
console.log(msgStr + 'tempWnd.setWindowType: ' + tempType + ' ,start');
tempTypeArr.push(tempType);
console.log(msgStr + 'tempTypeArr: ' + JSON.stringify(tempTypeArr));
let windowTypeData = await tempWnd.setWindowType(tempType).catch((err) => {
console.log(msgStr + 'tempWnd.setWindowType err' + JSON.stringify(err));
})
console.log(msgStr + 'tempWnd.setWindowType windowTypeData' + JSON.stringify(windowTypeData));
console.log(msgStr + 'tempWnd.setWindowType !windowTypeData' + !windowTypeData);
console.log(msgStr + 'tempWnd.setWindowType ' + tempType + ' end');
if (!windowTypeData) {
expect(!windowTypeData).assertTrue();
let prodata = await tempWnd.getProperties().catch((err) => {
console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err));
unexpectedError(err, caseName, 'tempWnd.getProperties', done);
})
console.log(msgStr + 'tempWnd.getProperties prodata' + JSON.stringify(prodata));
console.log(msgStr + 'tempWnd.getProperties !!prodata' + !!prodata);
expect(!!prodata).assertTrue();
if (!!prodata) {
tempTypeArr.splice(tempTypeArr.findIndex(item => item === prodata.type), 1);
console.log(msgStr + '(loopCount1.length - i): ' + (loopCount1.length - i));
console.log(msgStr + '(tempTypeArr.length + 1): ' + (tempTypeArr.length + 1));
if (i == loopCount1.length - 1) {
expect((loopCount1.length - i) == (tempTypeArr.length + 1)).assertTrue();
console.log(msgStr + 'tempWnd.getProperties i=' + i + ' , loopCount1.length-1==' + loopCount1.length);
done();
}
} else {
unexpectedError(err, caseName, 'tempWnd.getProperties', done);
}
} else {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
}
}
})
/**
* @tc.number SUB_WINDOW_SETWINDOWTYPE_JSAPI_002
* @tc.name Test setWindowTypeTest2
* @tc.desc Test window.setWindowType API function test.
*/
it('setWindowTypeTest2', 0, async function (done) {
let caseName = 'setWindowTypeTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let changedWndType = null;
let windowId = 'setWindowTypeTest2';
console.log(msgStr + 'begin');
let tempWnd = null
tempWnd = await ohosWindow.create(context, windowId, baseWndType).catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.create', done);
})
console.log(msgStr + 'ohosWindow.create tempWnd' + JSON.stringify(tempWnd));
console.log(msgStr + 'ohosWindow.create !!tempWnd' + !!tempWnd);
if (!!tempWnd) {
expect(!!tempWnd).assertTrue();
let windowTypeData = await tempWnd.setWindowType(changedWndType).catch((err) => {
console.log(msgStr + 'tempWnd.setWindowType err: ' + JSON.stringify(err));
expectedError(err, caseName, 'tempWnd.setWindowType', done, 130);
})
console.log(msgStr + 'tempWnd.setWindowType windowTypeData' + JSON.stringify(windowTypeData));
console.log(msgStr + 'tempWnd.setWindowType !windowTypeData' + !windowTypeData);
if (!!windowTypeData) {
unexpectedError(err, caseName, 'tempWnd.setWindowType', done);
} else {
expect(err.code == 130).assertTrue();
done();
}
} else {
unexpectedError(err, caseName, 'ohosWindow.create', done);
}
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_001
* @tc.name Test setSystemBarEnableTest1
* @tc.desc Verify that the scene shows the status bar and hides the navigation bar
*/
it('setSystemBarEnableTest1', 0, async function (done) {
let caseName = 'setSystemBarEnableTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
let statusFlag = listenerStatus.ready;
let navigationFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable(['navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([navigation]) success');
await sleep(1000);
statusFlag = listenerStatus.pending;
navigationFlag = listenerStatus.pending;
if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
console.log(msgStr + 'start on !!!!');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
console.log(msgStr + 'tempWnd.on , statusFlag : ' + JSON.stringify(statusFlag));
console.log(msgStr + 'tempWnd.on , listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending));
console.log(msgStr + 'tempWnd.on , navigationFlag : ' + JSON.stringify(navigationFlag));
console.log(msgStr + 'tempWnd.on , listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending));
setTimeout(() => {
console.log(msgStr + 'tempWnd.on , 3 statusFlag : ' + JSON.stringify(statusFlag));
console.log(msgStr + 'tempWnd.on , 3 listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending));
console.log(msgStr + 'tempWnd.on , 3 navigationFlag : ' + JSON.stringify(navigationFlag));
console.log(msgStr + 'tempWnd.on , 3 listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending));
if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
console.log(msgStr + 'systemBarTintChange compare start!');
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable);
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) {
statusFlag = listenerStatus.finished;
expect(!tempData.isEnable).assertTrue();
} else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) {
navigationFlag = listenerStatus.finished;
expect(tempData.isEnable).assertTrue();
}
}
ohosWindow.off('systemBarTintChange');
}
done();
}, 3000)
})
}
await tempWnd.setSystemBarEnable(['status']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success');
console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success, statusFlag : ' + JSON.stringify(statusFlag));
console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success, listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending));
console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success, navigationFlag : ' + JSON.stringify(navigationFlag));
console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success, listenerStatus.pending : ' + JSON.stringify(listenerStatus.pending));
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_002
* @tc.name Test setSystemBarEnableTest2
* @tc.desc Verify that the scene hides the status bar and displays the navigation bar
*/
it('setSystemBarEnableTest2', 0, async function (done) {
let caseName = 'setSystemBarEnableTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
let statusFlag = listenerStatus.ready;
let navigationFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
console.log(msgStr + 'systemBarTintChange compare start!');
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable);
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) {
statusFlag = listenerStatus.finished;
expect(!tempData.isEnable).assertTrue();
} else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) {
navigationFlag = listenerStatus.finished;
expect(tempData.isEnable).assertTrue();
}
}
}
done();
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable(['status']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success');
await sleep(1000);
statusFlag = listenerStatus.pending;
navigationFlag = listenerStatus.pending;
await tempWnd.setSystemBarEnable(['navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([navigation]) success');
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_003
* @tc.name Test setSystemBarEnableTest3
* @tc.desc Verify that the scene displays both the status bar and the navigation bar
*/
it('setSystemBarEnableTest3', 0, async function (done) {
let caseName = 'setSystemBarEnableTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
let statusFlag = listenerStatus.ready;
let navigationFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
console.log(msgStr + 'systemBarTintChange compare start!');
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable);
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) {
statusFlag = listenerStatus.finished;
expect(tempData.isEnable).assertTrue();
} else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) {
navigationFlag = listenerStatus.finished;
expect(tempData.isEnable).assertTrue();
}
}
}
done();
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable([]).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
await sleep(1000);
statusFlag = listenerStatus.pending;
navigationFlag = listenerStatus.pending;
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success .');
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_004
* @tc.name Test setSystemBarEnableTest4
* @tc.desc Verify that the scene hides both the status bar and the navigation bar
*/
it('setSystemBarEnableTest4', 0, async function (done) {
let caseName = 'setSystemBarEnableTest4';
let msgStr = 'jsunittest ' + caseName + ' ';
let statusFlag = listenerStatus.ready;
let navigationFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
console.log(msgStr + 'systemBarTintChange compare start!');
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable);
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) {
statusFlag = listenerStatus.finished;
expect(!tempData.isEnable).assertTrue();
} else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) {
navigationFlag = listenerStatus.finished;
expect(!tempData.isEnable).assertTrue();
}
}
}
done();
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
await sleep(1000);
statusFlag = listenerStatus.pending;
navigationFlag = listenerStatus.pending;
await tempWnd.setSystemBarEnable([]).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARENABLE_JSAPI_005
* @tc.name Test setSystemBarEnableTest5
* @tc.desc Verify the scene where illegal values are entered when the status bar and navigation bar are displayed
*/
it('setSystemBarEnableTest5', 0, async function (done) {
let caseName = 'setSystemBarEnableTest5';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + JSON.stringify(tempWnd));
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
console.log(msgStr + 'tempWnd.setFullScreen(true) err' + JSON.stringify(err));
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable([]).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([]) success');
await tempWnd.setSystemBarEnable([null, '123']).catch((err) => {
console.log(msgStr + 'tempWnd.setSystemBarEnable([null, 123]) err=' + JSON.stringify(err));
expect(err.code === 130).assertTrue();
done();
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([null, 123]) finished');
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_001
* @tc.name Test setSystemBarPropertiesTest1
* @tc.desc Verify the scene where the colors of the status bar and navigation bar are set in RGB
*/
it('setSystemBarPropertiesTest1', 0, async function (done) {
let caseName = 'setSystemBarPropertiesTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
let cloneColorArr = JSON.parse(JSON.stringify(commonRGBColorArr));
let compareCount = 0;
let listenerFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (listenerFlag === listenerStatus.pending) {
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR || tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) {
console.log(msgStr + 'systemBarTintChange compare start!');
compareCount++;
let backgroundIndex = cloneColorArr.indexOf(tempData.backgroundColor);
let contentColorIndex = cloneColorArr.indexOf(tempData.contentColor);
expect(backgroundIndex === -1).assertTrue();
expect(contentColorIndex === -1).assertTrue();
}
}
}
done();
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
await sleep(1000);
listenerFlag = listenerStatus.pending;
let loopCount = commonRGBColorArr.length;
for (let i = 0; i < loopCount; i++) {
let tempColor = commonRGBColorArr[i];
let systemBarProperties = {
statusBarColor: tempColor,
isStatusBarLightIcon: true,
statusBarContentColor: tempColor,
navigationBarColor: tempColor,
isNavigationBarLightIcon: false,
navigationContentColor: tempColor,
};
tempWnd.setSystemBarProperties(systemBarProperties).then(() => {
console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success');
}, (err) => {
console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err));
expect(TRUE_FLAG).assertFail();
})
}
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_002
* @tc.name Test setSystemBarPropertiesTest2
* @tc.desc Verify the scene where the status bar and navigation bar colors are set in hexadecimal form
*/
it('setSystemBarPropertiesTest2', 0, async function (done) {
let caseName = 'setSystemBarPropertiesTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
let cloneColorArr = {
SBC: JSON.parse(JSON.stringify(commonNUMBERColorArr)),
SCC: JSON.parse(JSON.stringify(commonNUMBERColorArr)),
NBC: JSON.parse(JSON.stringify(commonNUMBERColorArr)),
NCC: JSON.parse(JSON.stringify(commonNUMBERColorArr))
};
let compareCount = 0;
let listenerFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (listenerFlag === listenerStatus.pending) {
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR) {
console.log(msgStr + 'systemBarTintChange compare start!');
compareCount++;
let backgroundIndex = cloneColorArr.SBC.indexOf(tempData.backgroundColor);
let contentColorIndex = cloneColorArr.SCC.indexOf(tempData.contentColor);
if (backgroundIndex >= 0) {
cloneColorArr.SBC.splice(backgroundIndex, 1);
}
if (contentColorIndex >= 0) {
cloneColorArr.SCC.splice(contentColorIndex, 1);
}
expect(backgroundIndex !== -1).assertTrue();
expect(contentColorIndex !== -1).assertTrue();
} else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR) {
console.log(msgStr + 'systemBarTintChange compare start!');
compareCount++;
let backgroundIndex = cloneColorArr.NBC.indexOf(tempData.backgroundColor);
let contentColorIndex = cloneColorArr.NCC.indexOf(tempData.contentColor);
if (backgroundIndex >= 0) {
cloneColorArr.NBC.splice(backgroundIndex, 1);
}
if (contentColorIndex >= 0) {
cloneColorArr.NCC.splice(contentColorIndex, 1);
}
expect(backgroundIndex !== -1).assertTrue();
expect(contentColorIndex !== -1).assertTrue();
}
}
}
done();
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
await sleep(1000);
listenerFlag = listenerStatus.pending;
let loopCount = commonNUMBERColorArr.length;
for (let i = 0; i < loopCount; i++) {
let tempColor = commonNUMBERColorArr[i];
let systemBarProperties = {
statusBarColor: tempColor,
isStatusBarLightIcon: true,
statusBarContentColor: tempColor,
navigationBarColor: tempColor,
isNavigationBarLightIcon: true,
navigationBarContentColor: tempColor,
};
tempWnd.setSystemBarProperties(systemBarProperties).then(() => {
console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success');
}, (err) => {
console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err));
expect(TRUE_FLAG).assertFail();
})
}
})
/**
* @tc.number SUB_WINDOW_SETSYSTEMBARPROPERTIES_JSAPI_003
* @tc.name Test setSystemBarPropertiesTest3
* @tc.desc Verify the scene where the status bar and navigation bar colors are set as keywords
*/
it('setSystemBarPropertiesTest3', 0, async function (done) {
let caseName = 'setSystemBarPropertiesTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
let cloneColorArr = JSON.parse(JSON.stringify(commonKEYColorArr));
let compareCount = 0;
let listenerFlag = listenerStatus.ready;
console.log(msgStr + 'begin');
listenerData.on = true;
listenerData.typeStr = 'systemBarTintChange';
ohosWindow.on('systemBarTintChange', (systemBarData) => {
console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
if (listenerFlag === listenerStatus.pending) {
expect(!!systemBarData).assertTrue();
expect(!!systemBarData.regionTint).assertTrue();
let arrLength = systemBarData.regionTint.length;
for (let i = 0; i < arrLength; i++) {
let tempData = systemBarData.regionTint[i];
console.log(msgStr + 'i=' + i + ' , ohosWindow.on for=' + JSON.stringify(tempData));
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);
expect(backgroundIndex === -1).assertTrue();
expect(contentColorIndex === -1).assertTrue();
}
}
}
done();
})
console.log(msgStr + 'tempWnd.on systemBarTintChange finished');
let tempWnd = await windowStage.getMainWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
});
console.log(msgStr + 'windowStage.getMainWindow, tempWnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
await tempWnd.show().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.show', done);
});
console.log(msgStr + 'tempWnd.show success');
await tempWnd.setFullScreen(true).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setFullScreen(true)', done);
});
console.log(msgStr + 'tempWnd.setFullScreen(true) success');
await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
});
console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
await sleep(1000);
listenerFlag = listenerStatus.pending;
let loopCount = commonKEYColorArr.length;
for (let i = 0; i < loopCount; i++) {
let tempColor = commonKEYColorArr[i];
let systemBarProperties = {
statusBarColor: tempColor,
isStatusBarLightIcon: true,
statusBarContentColor: tempColor,
navigationBarColor: tempColor,
isNavigationBarLightIcon: false,
navigationContentColor: tempColor,
};
tempWnd.setSystemBarProperties(systemBarProperties).then(() => {
console.log(msgStr + 'tempWnd.setSystemBarProperties ' + tempColor + ' success');
}, (err) => {
console.log(msgStr + 'tempWnd.setSystemBarProperties failed, err : ' + JSON.stringify(err));
expect(TRUE_FLAG).assertFail();
done();
})
}
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_001
* @tc.name Test create
* @tc.desc Verify the scenario of creating the application type window
*/
it('createTest1', 0, async function (done) {
let caseName = 'createTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let loopCount = appWindowTypeArr.length;
console.log('jsunittest loopCount: ' + loopCount);
for (let i = 0; i < loopCount; i++) {
let tempType = systemWindowTypeDic[systemWindowTypeDicArr[i]];
let windId = 'createTest1' + i;
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
let tempWnd = await ohosWindow.create(context, windId, tempType).catch((err) => {
console.log(msgStr + 'ohosWindow.create ' + tempType + 'catched, err: ' + JSON.stringify(err));
unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done);
});
console.log(msgStr + 'ohosWindow.create ' + tempType + 'finished, wnd: ' + tempWnd);
expect(!tempWnd).assertTrue();
}
console.log(msgStr + 'done ');
done();
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_002
* @tc.name Test createTest2
* @tc.desc Verify the scenario of creating the system type window
*/
it('createTest2', 0, async function (done) {
let caseName = 'createTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let loopCount = systemWindowTypeArr.length;
console.log(msgStr + ' loopCount: ' + loopCount);
let n = 0
for (let i = 0; i < loopCount; i++) {
let tempType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT;
let windId = 'createTest2' + i;
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
let createData = await ohosWindow.create(context, windId, tempType).catch((err) => {
console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done);
return;
})
expect(!!createData).assertTrue();
let tempWnd = createData
console.log(msgStr + 'ohosWindow.create ' + tempType + ' wnd: ' + tempWnd);
let proData = await tempWnd.getProperties().catch((err) => {
console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err));
unexpectedError(err, caseName, 'tempWnd.getProperties', done);
console.log(msgStr + 'tempWnd.getProperties err&&err.code' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.getProperties success, !!data : ' + !!data);
})
expect(!!proData).assertTrue();
expect(proData.type == tempType).assertTrue();
console.log(msgStr + 'n:' + n);
if (proData.type == tempType) n++
console.log(msgStr + 'n++:' + n);
console.log(msgStr + 'i:' + i);
if (i + 1 == loopCount) {
if (n === loopCount) {
expect(true).assertTrue();
} else {
unexpectedError(err, caseName, 'tempWnd.getProperties', done);
}
}
}
done();
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_003
* @tc.name Test createTest3
* @tc.desc Verify the scenario of creating a window of a type that does not exist
*/
it('createTest3', 0, async function (done) {
let caseName = 'createTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let tempType = 5000;
let windId = 'nonExistWindowType';
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
let nonExistWnd = await ohosWindow.create(context, windId, tempType).catch((err) => {
console.log(msgStr + 'ohosWindow.create err: ' + JSON.stringify(err));
expect(err.code === 130).assertTrue();
done();
});
})
/**
* @tc.number SUB_WINDOW_CREATE_JSAPI_004
* @tc.name Test createTest4
* @tc.desc Verify the scenario of creating a window with duplicate IDs
*/
it('createTest4', 0, async function (done) {
let caseName = 'createTest4';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let windowId = 'sameids'
let ohosData = await ohosWindow.create(context, windowId, 1).catch((err) => {
console.log(msgStr + 'ohosWindow.create 1 once err: ' + JSON.stringify(err));
unexpectedError(err, caseName, 'ohosWindow.create', done);
})
expect(!!ohosData).assertTrue();
let ohosDataError = await ohosWindow.create(context, windowId, 1).catch((err) => {
console.log(msgStr + 'ohosWindow.create 1 twice err: ' + JSON.stringify(err));
expect(err.code).assertEqual(120)
done();
})
console.log(msgStr + 'ohosWindow.create 1 twice ohosDataError: ' + JSON.stringify(ohosDataError));
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_001
* @tc.name Test loadContentTest1
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest1', 0, async function (done) {
let caseName = 'loadContentTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let windowId = 'loadContentTest1';
console.log(msgStr + 'begin');
let tempWnd = await ohosWindow.create(context, windowId, baseWndType).catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.create', done);
});
console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' , wnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
console.log(msgStr + 'tempWnd.loadContent start');
let load = await tempWnd.loadContent('pages/second/second').catch((err) => {
unexpectedError(err, caseName, 'tempWnd.loadContent', done);
console.log(msgStr + 'tempWnd.loadContent(pages/second/second) err=' + JSON.stringify(err));
});
console.log(msgStr + 'tempWnd.loadContent(pages/second/second) load=' + JSON.stringify(load));
expect(!load).assertTrue();
done();
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_002
* @tc.name Test loadContentTest2
* @tc.desc Verify the scene of loading the page with illegal values
*/
it('loadContentTest2', 0, async function (done) {
let caseName = 'loadContentTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let windowId = 'loadContentTest2';
console.log(msgStr + 'begin');
let tempWnd = await ohosWindow.create(context, windowId, baseWndType).catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.create', done);
});
console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
console.log(msgStr + 'tempWnd.loadContent start');
let errFlag = false;
let loadContentData = await tempWnd.loadContent(null).catch((err) => {
errFlag = true;
expectedError(err, caseName, 'tempWnd.loadContent', done, 130);
console.log(msgStr + 'tempWnd.loadContent(null)' + JSON.stringify(err));
});
console.log(msgStr + 'tempWnd.loadContent loadContentData:' + JSON.stringify(loadContentData));
if (!errFlag) {
console.log(msgStr + 'should report err');
expect(TRUE_FLAG).assertFail();
done();
}
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_003
* @tc.name Test loadContentTest3
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest3', 0, async function (done) {
let caseName = 'loadContentTest3';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let load3 = await windowStage.loadContent('pages/index/index.ets').catch((err) => {
unexpectedError(err, caseName, 'tempWnd.loadContent', done);
console.log(msgStr + 'tempWnd.loadContent(pages/index/index.ets)' + JSON.stringify(err));
});
expect(!load3).assertTrue();
console.log(msgStr + 'tempWnd.loadContent end load=' + JSON.stringify(load3));
done();
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_004
* @tc.name Test loadContentTest4
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest4', 0, async function (done) {
let caseName = 'loadContentTest4';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let load4 = await windowStage.loadContent(null).catch((err) => {
expectedError(err, caseName, 'tempWnd.loadContent', done, 130);
console.log(msgStr + 'tempWnd.loadContent(pages/index/index.ets)' + JSON.stringify(err));
});
console.log(msgStr + 'tempWnd.loadContent end load5=' + JSON.stringify(load4));
done();
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_005
* @tc.name Test loadContentTest5
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest5', 0, async function (done) {
let caseName = 'loadContentTest5';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let load5 = await windowStage.loadContent(null, abilityStorage).catch((err) => {
expectedError(err, caseName, 'tempWnd.loadContent', done, 130);
console.log(msgStr + 'tempWnd.loadContent(pages/index/index.ets)' + JSON.stringify(err));
});
console.log(msgStr + 'tempWnd.loadContent end load5=' + JSON.stringify(load5));
done();
})
/**
* @tc.number SUB_WINDOW_LOADCONTENT_JSAPI_006
* @tc.name Test loadContentTest6
* @tc.desc Verify the scenario of loading an existing page
*/
it('loadContentTest6', 0, async function (done) {
let caseName = 'loadContentTest6';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let load6 = await windowStage.loadContent('pages/index/index.ets', null).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.loadContent', done);
console.log(msgStr + 'tempWnd.loadContent(pages/index/index.ets)' + JSON.stringify(err));
});
expect(!load6).assertTrue();
console.log(msgStr + 'tempWnd.loadContent end load=' + JSON.stringify(load6));
done();
})
/**
* @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_001
* @tc.name Test createSubWindowTest1
* @tc.desc Verify the scenario of creating an auxiliary window
*/
it('createSubWindowTest1', 0, async function (done) {
let caseName = 'createSubWindowTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let subWindow = await windowStage.createSubWindow('createSubWindowTest1').catch((err) => {
unexpectedError(err, caseName, 'windowStage.createSubWindow', done);
console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest1)=' + JSON.stringify(err));
});
expect(!!subWindow).assertTrue();
console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow));
done();
})
/**
* @tc.number SUB_WINDOW_CREATESUBWINDOW_JSAPI_002
* @tc.name Test createSubWindowTest2
* @tc.desc Verify the scene of entering illegal values to create an auxiliary window
*/
it('createSubWindowTest2', 0, async function (done) {
let caseName = 'createSubWindowTest2';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let subWindow = await windowStage.createSubWindow(null).catch((err) => {
expectedError(err, caseName, 'windowStage.createSubWindow', done, 130);
console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err));
});
console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow));
})
/**
* @tc.number SUB_WINDOW_GETSUBWINDOW_JSAPI_001
* @tc.name Test getSubWindowTest1
* @tc.desc Verify the scene of obtaining all auxiliary sub windows
*/
it('getSubWindowTest1', 0, async function (done) {
let caseName = 'getSubWindowTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let subWindow = await windowStage.getSubWindow().catch((err) => {
unexpectedError(err, caseName, 'windowStage.getSubWindow', done);
console.log(msgStr + 'windowStage.getSubWindow(null) err=' + JSON.stringify(err));
});
expect(!!subWindow).assertTrue();
console.log(msgStr + 'windowStage.getSubWindow end subWindow=' + JSON.stringify(subWindow));
done();
})
/**
* @tc.number SUB_WINDOW_SETPRIVACYMODE_JSAPI_001
* @tc.name Test setPrivacyModeTest1
* @tc.desc Verify the scene where the application sub window is set as a security layer
*/
it('setPrivacyModeTest1', 0, async function (done) {
let caseName = 'setPrivacyModeTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin ');
let mainWnd = null;
let windowData = await ohosWindow.create(context, 'setPrivacyModeTest1', ohosWindow.WindowType.TYPE_SYSTEM_ALERT)
.catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.create', done);
})
expect(!!windowData).assertTrue();
console.log(msgStr + 'window.create success windowData' + windowData);
mainWnd = windowData;
let firstPro = await mainWnd.getProperties().catch((err, data) => {
unexpectedError(err, caseName, 'mainWnd.getProperties', done);
})
console.log(msgStr + 'mainWnd.getProperties firstPro=' + JSON.stringify(firstPro));
expect(!firstPro.isPrivacyMode).assertTrue();
let firstPrivacyMode = await mainWnd.setPrivacyMode(true).catch((err, data) => {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(true) err=' + JSON.stringify(err));
})
expect(!firstPrivacyMode).assertTrue();
console.log(msgStr + 'mainWnd.setPrivacyMode true firstPrivacyMode=' + JSON.stringify(firstPrivacyMode));
let secondPro = await mainWnd.getProperties().catch((err, data) => {
unexpectedError(err, caseName, 'mainWnd.getProperties', done);
})
console.log(msgStr + 'mainWnd.getProperties secondPro:' + JSON.stringify(secondPro.isPrivacyMode));
expect(secondPro.isPrivacyMode).assertTrue();
let secondPrivacyMode = await mainWnd.setPrivacyMode(false).catch((err, data) => {
unexpectedError(err, caseName, 'mainWnd.setPrivacyMode', done);
console.log(msgStr + 'mainWnd.setPrivacyMode(false) err=' + JSON.stringify(err));
})
expect(!secondPrivacyMode).assertTrue();
console.log(msgStr + 'mainWnd.setPrivacyMode(false) secondPrivacyMode=' + JSON.stringify(secondPrivacyMode));
let lastPro = await mainWnd.getProperties().catch((err, data) => {
unexpectedError(err, caseName, 'mainWnd.getProperties', done);
})
console.log(msgStr + 'mainWnd.getProperties lastPro:' + JSON.stringify(lastPro.isPrivacyMode));
expect(!lastPro.isPrivacyMode).assertTrue();
done();
})
/**
* @tc.number SUB_WINDOW_DESTROY_JSAPI_001
* @tc.name Test destroyTest1
* @tc.desc Verification window destruction scenario.
*/
it('destroyTest1', 0, async function (done) {
let caseName = 'destroyTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
let baseWndType = 1;
let windowId = 'destroyTest1';
console.log(msgStr + 'begin');
let tempWnd = await ohosWindow.create(context, windowId, baseWndType).catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.create', done);
});
console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd);
expect(!!tempWnd).assertTrue();
console.log(msgStr + 'tempWnd.destroy start');
await tempWnd.destroy().catch((err) => {
unexpectedError(err, caseName, 'tempWnd.destroy', done);
console.log(msgStr + 'destroy err : ' + JSON.stringify(err));
});
console.log(msgStr + 'tempWnd.destroy end');
let findWnd = await ohosWindow.find(windowId).catch((err) => {
expectedError(err, caseName, 'ohosWindow.find', done, 120);
});
console.log(msgStr + 'find findWnd: ' + JSON.stringify(findWnd));
expect(!findWnd).assertTrue();
done();
})
/**
* @tc.number SUB_WINDOW_SETDENSITTYDPI_JSAPI_001
* @tc.name Test setDensityDpiTest1
* @tc.desc Verify Sets the screen pixel
*/
it('setDensityDpiTest1', 0, async function (done) {
let caseName = 'setDensityDpiTest1';
let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin');
let screens = await screenManager.getAllScreens().catch(err => {
unexpectedError(err, caseName, 'screenManager.getAllScreen', done);
})
console.log(msgStr + 'screenManager.getAllScreen' + JSON.stringify(screens));
expect(!!screens).assertTrue();
let dpiItem = [-80, 80, 1000, 160, 0, 320, 188.88, 0, 640, 300];
for (let i = 0;i < dpiItem.length; i++) {
await sleep(1000);
await screens[0].setDensityDpi(dpiItem[i]).then(async () => {
console.log(msgStr + 'screen.setDensityDpi success set DPI ' + dpiItem[i]);
let defaultDpi = await display.getDefaultDisplay().catch(err => {
console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay failed');
});
console.log(msgStr + 'screen.setDensityDpi display.getDefaultDisplay' + JSON.stringify(defaultDpi));
let isEqual = defaultDpi.densityDPI == parseInt(dpiItem[i])
console.log(msgStr + 'same ? ' + isEqual)
expect(isEqual).assertTrue()
}).catch(err => {
console.log(msgStr + 'screen.setDensityDpi failed set DPI error' + dpiItem[i]);
});
}
console.log(msgStr + 'done ');
done();
})
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册