diff --git a/graphic/BUILD.gn b/graphic/BUILD.gn index 1f40d59efdde8def7ba0a4077293f69bcc8c43fa..2d44c3f376ef0998857ac5324a093651a4608bea 100755 --- a/graphic/BUILD.gn +++ b/graphic/BUILD.gn @@ -17,6 +17,7 @@ group("graphic") { if (is_standard_system) { deps = [ "webGL:webGL_hap_test", + "windowStage:window_stage_hap_test", "windowstandard:window_hap_test", ] } else { diff --git a/graphic/windowStage/AppScope/app.json b/graphic/windowStage/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..2c223fed485d736ab9906abf778f3d48eeb6c7cf --- /dev/null +++ b/graphic/windowStage/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "huawei", + "versionCode": 1000000, + "versionName": "1.0.0", + "debug": false, + "icon": "$media:icon", + "label": "$string:app_name", + "description": "$string:description_application", + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} \ No newline at end of file diff --git a/graphic/windowStage/AppScope/resources/base/element/string.json b/graphic/windowStage/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee69f9a861d9dc269ed6638735d52674583498e1 --- /dev/null +++ b/graphic/windowStage/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"ohosProject" + } + ] +} \ No newline at end of file diff --git a/graphic/windowStage/AppScope/resources/base/media/app_icon.png b/graphic/windowStage/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/graphic/windowStage/AppScope/resources/base/media/app_icon.png differ diff --git a/graphic/windowStage/BUILD.gn b/graphic/windowStage/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6638dde4d44c9e63cf7e14af39b47329a50eecff --- /dev/null +++ b/graphic/windowStage/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("window_stage_hap_test") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "window_stage_hap_test" +} + +ohos_app_scope("windowStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("windowStage_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("windowStage_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":windowStage_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/graphic/windowStage/Test.json b/graphic/windowStage/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..5f865c396b81cdea1554da9eed5aa127435aa9bd --- /dev/null +++ b/graphic/windowStage/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "180000", + "package": "com.example.myapplication", + "shell-timeout": "600000" + }, + "kits": [ + { + "test-file-name": [ + "window_stage_hap_test.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/graphic/windowStage/entry/src/main/ets/Application/AbilityStage.ts b/graphic/windowStage/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3fdadfebeeeb676df2ce8f78f4b59e26fae9cf0 --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/graphic/windowStage/entry/src/main/ets/MainAbility/MainAbility.ts b/graphic/windowStage/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..ed9de5ac32a0385ec7e83d2b09d806008314a5bb --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,38 @@ +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate windowStage="+ windowStage) + globalThis.windowStage = windowStage + globalThis.abilityStorage = this.storage + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; \ No newline at end of file diff --git a/graphic/windowStage/entry/src/main/ets/pages/index/index.ets b/graphic/windowStage/entry/src/main/ets/pages/index/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a35d714386252bb8b07ae887ecd88cb38b1a80fd --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021 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 file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets" +import testsuite from "../../test/List.test.ets" + + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + testsuite(globalThis.abilityContext,globalThis.windowStage,globalThis.abilityStorage) + core.execute() + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/graphic/windowStage/entry/src/main/ets/pages/second/second.ets b/graphic/windowStage/entry/src/main/ets/pages/second/second.ets new file mode 100644 index 0000000000000000000000000000000000000000..1c1c727ff11ecc97909f482c35268db87ae23bb4 --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 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 router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/graphic/windowStage/entry/src/main/ets/test/List.test.ets b/graphic/windowStage/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a12b8278ae479566c869493d0fda3edfb458d121 --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 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 windowPromiseTest from './windowPromise.test.ets' +import windoCallbackTest from './windowCallback.test.ets' + +export default function testsuite(context, windowStage, abilityStorage) { + windoCallbackTest(context, windowStage, abilityStorage) + windowPromiseTest(context, windowStage, abilityStorage) +} \ No newline at end of file diff --git a/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e1b51c11576bf3c513bc014e50c4b3a7e9b3f737 --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets @@ -0,0 +1,872 @@ +/* + * 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 display from '@ohos.display'; + +export default function windoCallbackTest(context, windowStage, abilityStorage) { + + console.log('testets context 1: ' + JSON.stringify(context)) + console.log('testets context 1 windowStage 2 : ' + JSON.stringify(windowStage)); + describe('windowApiCallback_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_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, done => { + let caseName = 'setSystemBarEnableTest10'; + 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 systemBarTintChange :' + JSON.stringify(systembartintstate)); + console.log(msgStr + 'ohosWindow.on systemBarTintChange systembartintstate.regionTint : ' + JSON.stringify(systembartintstate.regionTint)); + if (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([], (err, data) => { + console.log(msgStr + 'mainWnd.setSystemBarEnable [] JSON.stringfy(data)==' + JSON.stringify(data)); + if (err && err.code) { + unexpectedError(data, caseName, 'mainWnd.setSystemBarEnable []', done); + } + flagStatus = true; + flagNav = true; + expect(!data).assertTrue(); + mainWnd.setSystemBarEnable([null, '123'], (err, data) => { + 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 === 2108 || tempData.type === 2112) { + 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 === 2108) { + 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); + } + } else if (tempData.type === 2112) { + 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); + } + } + } + } + }) + 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(); + } + }) + } + setTimeout(() => { + console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); + listenerFlag = listenerStatus.finished; + let ca = cloneColorArr; + if (ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length) { + unexpectedError(null, caseName, ' something compaer failed', done); + } else { + done(); + } + }, 10000) + }) + }) + }) + }) + }) + /** + * @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 === 2108 || tempData.type === 2112) { + 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(); + if (i === loopCount - 1) { + 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, 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.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.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(['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, 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 = 1; 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 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(); + tempWnd.getProperties((err, data) => { + console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err)); + console.log(msgStr + 'tempWnd.getProperties data' + JSON.stringify(data)); + console.log(msgStr + 'tempWnd.getProperties !!data' + !!data); + expect(!!data).assertTrue(); + if (!!data) { + tempTypeArr.splice(tempTypeArr.findIndex(item => item === data.type), 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', 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, 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, 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_003 + * @tc.name Test loadContentTest3 + * @tc.desc Verify the scenario of loading an existing page + */ + it('loadContentTest3', 0, done => { + let caseName = 'loadContentTest3'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'loadContentTest3'; + 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_004 +* @tc.name Test loadContentTest4 +* @tc.desc Verify the scenario of loading a page that does not exist +*/ + it('loadContentTest4', 0, done => { + let caseName = 'loadContentTest4'; + let msgStr = 'jsunittest ' + caseName + ' '; + let baseWndType = 1; + let windowId = 'loadContentTest4'; + 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); + } + }) + }) + }) +} diff --git a/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets b/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5696f5cc2d16e363ad204fd97ed2d4cd43abe896 --- /dev/null +++ b/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets @@ -0,0 +1,735 @@ +/* + * 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'; + +export default function windowPromiseTest(context, windowStage) { + console.log('windowTest context: ' + JSON.stringify(context)) + describe('window_api_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 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)); + appWindowTypeArr = Object.keys(appWindowTypeDic); + 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) { + let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; + console.log(msgStr + JSON.stringify(error)); + 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_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'); + 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 === 2108 && statusFlag === listenerStatus.pending) { + statusFlag = listenerStatus.finished; + expect(tempData.isEnable).assertTrue(); + } else if (tempData.type === 2112 && navigationFlag === listenerStatus.pending) { + navigationFlag = listenerStatus.finished; + expect(!tempData.isEnable).assertTrue(); + } + if (statusFlag === listenerStatus.finished && navigationFlag === listenerStatus.finished) { + 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(['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; + await tempWnd.setSystemBarEnable(['status']).catch((err) => { + unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status])', done); + }); + console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) success'); + setTimeout(() => { + if (statusFlag !== listenerStatus.finished || navigationFlag !== listenerStatus.finished) { + let apiStr = 'tempWnd.on systemBarTintChange time wait'; + unexpectedError(null, caseName, apiStr, done); + } + }, 5000) + }) + + /** + * @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 === 2108 && statusFlag === listenerStatus.pending) { + statusFlag = listenerStatus.finished; + expect(!tempData.isEnable).assertTrue(); + } else if (tempData.type === 2112 && navigationFlag === listenerStatus.pending) { + navigationFlag = listenerStatus.finished; + expect(tempData.isEnable).assertTrue(); + } + if (statusFlag === listenerStatus.finished && navigationFlag === listenerStatus.finished) { + 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'); + setTimeout(() => { + if (statusFlag !== listenerStatus.finished || navigationFlag !== listenerStatus.finished) { + let apiStr = 'tempWnd.on systemBarTintChange time wait'; + unexpectedError(null, caseName, apiStr, done); + } + }, 5000) + }) + + /** + * @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 === 2108 && statusFlag === listenerStatus.pending) { + statusFlag = listenerStatus.finished; + expect(tempData.isEnable).assertTrue(); + } else if (tempData.type === 2112 && navigationFlag === listenerStatus.pending) { + navigationFlag = listenerStatus.finished; + expect(tempData.isEnable).assertTrue(); + } + if (statusFlag === listenerStatus.finished && navigationFlag === listenerStatus.finished) { + 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'); + setTimeout(() => { + if (statusFlag !== listenerStatus.finished || navigationFlag !== listenerStatus.finished) { + let apiStr = 'tempWnd.on systemBarTintChange time wait'; + unexpectedError(null, caseName, apiStr, done); + } + }, 5000) + }) + + /** + * @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 === 2108 && statusFlag === listenerStatus.pending) { + statusFlag = listenerStatus.finished; + expect(!tempData.isEnable).assertTrue(); + } else if (tempData.type === 2112 && navigationFlag === listenerStatus.pending) { + navigationFlag = listenerStatus.finished; + expect(!tempData.isEnable).assertTrue(); + } + if (statusFlag === listenerStatus.finished && navigationFlag === listenerStatus.finished) { + 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'); + setTimeout(() => { + if (statusFlag !== listenerStatus.finished || navigationFlag !== listenerStatus.finished) { + let apiStr = 'tempWnd.on systemBarTintChange time wait'; + unexpectedError(null, caseName, apiStr, done); + } + }, 5000) + }) + + /** + * @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: ' + 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 tempWnd.setSystemBarEnable([null, '123']).catch((err) => { + expectedError(err, caseName, 'tempWnd.setSystemBarEnable([null, 123])', 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 === 2108 || tempData.type === 2112) { + 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'); + 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(); + done(); + }) + } + setTimeout(() => { + console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); + listenerFlag = listenerStatus.finished; + done(); + }, 10000) + }) + + /** + * @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 === 2108) { + 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 === 2112) { + 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(); + } + } + } + }) + 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(); + done(); + }) + } + setTimeout(() => { + console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); + listenerFlag = listenerStatus.finished; + let ca = cloneColorArr; + if (ca.NCC.length || ca.NBC.length || ca.SBC.length || ca.SCC.length) { + unexpectedError(null, caseName, ' something compaer failed', done); + } else { + done(); + } + }, 10000) + }) + + /** + * @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]; + if (tempData.type === 2108 || tempData.type === 2112) { + 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'); + 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(); + }) + } + setTimeout(() => { + console.log(msgStr + 'time wait finished. compareCount: ' + compareCount); + listenerFlag = listenerStatus.finished; + done(); + }, 10000) + }) + + /** + * @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 = appWindowTypeDic[appWindowTypeArr[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)); + expectedError(err, caseName, 'ohosWindow.create ' + tempType, done); + }); + console.log(msgStr + 'ohosWindow.create ' + tempType + 'finished, wnd: ' + tempWnd); + expect(!tempWnd).assertTrue(); + if (i === loopCount - 1) { + } + } + console.log(msgStr + '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(); + }); + }) + }) +} diff --git a/graphic/windowStage/entry/src/main/module.json b/graphic/windowStage/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..2f75303710fc9915a694392337254ae6fdbc266d --- /dev/null +++ b/graphic/windowStage/entry/src/main/module.json @@ -0,0 +1,42 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:phone_entry_dsc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [{ + "name": "com.example.myapplication.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "visible": true, + "orientation": "portrait", + "skills": [{ + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + }] + }], + "requestPermissions": [{ + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW", + "reason": "need use ohos.permission.SYSTEM_FLOAT_WINDOW" + }, + { + "name": "ohos.permission.CAPTURE_SCREEN", + "reason": "need use ohos.permission.SYSTEM_FLOAT_WINDOW" + } + ] + } +} \ No newline at end of file diff --git a/graphic/windowStage/entry/src/main/resources/base/element/string.json b/graphic/windowStage/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2977b612ec4595b13eaaffe3e8fc578e83c42d48 --- /dev/null +++ b/graphic/windowStage/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsContextTest" + }, + { + "name": "form_description", + "value": "my form" + }, + { + "name": "serviceability_description", + "value": "my whether" + }, + { + "name": "description_application", + "value": "demo for test" + }, + { + "name": "app_name", + "value": "Demo" + } + ] +} diff --git a/graphic/windowStage/entry/src/main/resources/base/media/icon.png b/graphic/windowStage/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/graphic/windowStage/entry/src/main/resources/base/media/icon.png differ diff --git a/graphic/windowStage/entry/src/main/resources/base/profile/main_pages.json b/graphic/windowStage/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/graphic/windowStage/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/graphic/windowStage/signature/openharmony_sx.p7b b/graphic/windowStage/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..7ffcdc78527c5c1aa24520ab7e913c5f47c703f0 Binary files /dev/null and b/graphic/windowStage/signature/openharmony_sx.p7b differ