windowPromise.test.ets 71.3 KB
Newer Older
Y
update  
yaocui 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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 "@ohos/hypium"
import ohosWindow from '@ohos.window';
import screenManager from '@ohos.screen';
import display from '@ohos.display';
Z
zhurong 已提交
19

Y
update  
yaocui 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
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 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_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);
      console.log('jsunittest beforeall systemWindowTypeDicArr=' + JSON.stringify(systemWindowTypeDicArr) + '   ,length=' + systemWindowTypeDicArr.length);
      systemWindowValueArr = Object.keys(systemWindowTypeDic);
      systemWindowTypeArr = Object.keys(systemWindowTypeDic);
    })
    beforeEach(function () {
    })
    afterEach(async function (done) {
      windowCount++;
      console.log('promise jsunittest afterEach listenerData:' + JSON.stringify(listenerData));
      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);
Z
zhurong 已提交
79
        }
Y
update  
yaocui 已提交
80 81 82 83 84 85
        await sleep(3000);
      }
      done();
    })
    afterAll(function () {
    })
Z
zhurong 已提交
86

Y
update  
yaocui 已提交
87 88 89 90 91 92 93 94
    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();
    }
95

Y
update  
yaocui 已提交
96 97 98 99 100 101
    function unexpectedError(error, caseName, apiName, done) {
      let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: ';
      console.log(msgStr + JSON.stringify(error));
      expect(TRUE_FLAG).assertFail();
      done();
    }
Z
zhurong 已提交
102

Y
update  
yaocui 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    async function sleep(time) {
      let timeoutId = null;
      let promise = new Promise(resolve => {
        timeoutId = setTimeout(() => {
          resolve('sleep finished');
        }, time);
      })
      let result = await promise;
      clearTimeout(timeoutId)
    }
    /**
	 * @tc.number     SUB_WINDOW_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 = false;
      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, avoidAreaData : ' + JSON.stringify(avoidAreaData));
        console.log(msgStr + 'tempWnd.on systemAvoidAreaChange, listenerOnFlag : ' + JSON.stringify(listenerOnFlag));
        if (listenerOnFlag) {
          expect(!!avoidAreaData).assertTrue();
          tempWnd.off('systemAvoidAreaChange');
Y
update  
yaocui 已提交
136
          done();
Z
zhurong 已提交
137
        }
Y
update  
yaocui 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
      })
      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');
      listenerOnFlag = true;
      await sleep(1000);
      await tempWnd.setSystemBarEnable(['status', 'navigation']).catch((err) => {
        unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([status, navigation])', done);
      });
      console.log(msgStr + 'tempWnd.setSystemBarEnable([status, navigation]) success');
    })
159

Y
update  
yaocui 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
    /**
	 * @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 = ohosWindow.WindowType.TYPE_SYSTEM_ALERT;
      let changedModel = 102;
      let baseValue = 100;
      let resizeValue = 200;
      let listenerOnFlag = listenerStatus.ready;
      console.log(msgStr + 'begin');
      let tempWnd = null;
      listenerData.on = true;
      listenerData.typeStr = 'windowSizeChange';
      try {
        await ohosWindow.create(context, wndId, baseType).then((data) => {
          tempWnd = data
          newWindowObj = tempWnd
          console.log(msgStr + 'ohosWindow.create data:' + JSON.stringify(data));
        }).catch((err) => {
          unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done);
        });
        console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + tempWnd);
        expect(!!tempWnd).assertTrue();
        listenerData.on = true;
        listenerData.typeStr = 'windowSizeChange';
      } catch (err) {
        console.log(msgStr + 'ohosWindow.create catch err:' + JSON.stringify(err));
      }
      await 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();
200
        }
Y
update  
yaocui 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
      })
      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);
      });
      await tempWnd.destroy();
      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(10010);
      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 = ohosWindow.WindowType.TYPE_SYSTEM_ALERT;
      let changedModel = 102;
      let listenerOffFlag = false;
      listenerData.on = true;
      listenerData.typeStr = 'windowSizeChange';
      console.log(msgStr + 'begin');
      let createWindowObj = {
        name: wndId, windowType: baseType, ctx: context
      }
      console.log(msgStr + 'ohosWindow.create createWindowObj:' + JSON.stringify(createWindowObj));
      let tempWnd = null;
      await ohosWindow.create(context, wndId, baseType).then((data) => {
        console.log(msgStr + 'ohosWindow.create data:' + JSON.stringify(data));
        tempWnd = data
        newWindowObj = data
        console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + tempWnd);
        expect(!!tempWnd).assertTrue();
      }).catch((err) => {
        unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done);
      });
298

Y
update  
yaocui 已提交
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
      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 sleep(1000);
      await tempWnd.on('windowSizeChange', (sizeData) => {
        console.log(msgStr + 'tempWnd.on windowSizeChange, sizeData : ' + JSON.stringify(sizeData));
        if (listenerOffFlag) {
          listenerOffFlag = false;
          console.log(msgStr + 'tempWnd.on windowSizeChange  sizeData: ' + JSON.stringify(sizeData));
          expect(sizeData.width === 100).assertTrue();
          expect(sizeData.height === 100).assertTrue();
          done();
        } else {
          console.log(msgStr + 'tempWnd.on windowSizeChange,else listenerOffFlag : ' + listenerOffFlag);
          console.log(msgStr + 'tempWnd.on windowSizeChange,else sizeData : ' + JSON.stringify(sizeData));
          if(sizeData.width === 100&&sizeData.height === 100){
            console.log(msgStr + 'tempWnd.on windowSizeChange,else sizeData.width === 100&&sizeData.height === 100');
Y
yaocui 已提交
321
            done();
Y
update  
yaocui 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
          }
        }
      })
      console.log(msgStr + 'tempWnd.on windowSizeChange finished');
      await tempWnd.resetSize(100, 100).then(() => {
        listenerOffFlag = true;
        console.log(msgStr + 'listenerOffFlag:' + listenerOffFlag);
      }).catch((err) => {
        unexpectedError(err, caseName, 'tempWnd.resetSize(100, 100)', done);
      });
      console.log(msgStr + 'tempWnd.resetSize(100, 100) success');
      console.log(msgStr + 'tempWnd.off windowSizeChange finished');
      await tempWnd.destroy();
      done();
      console.log(msgStr + 'finished');
    })
    /**
    * @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));
Y
yaocui 已提交
365
        })
Y
update  
yaocui 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
        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);
              await tempWnd.destroy();
              done();
Z
zhurong 已提交
387
            }
Y
update  
yaocui 已提交
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
          }
        }
      }
    })
    /**
    * @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
      await ohosWindow.create(context, windowId, baseWndType).then(
        (data) => {
          tempWnd = data
        }
      ).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();
        await tempWnd.setWindowType(changedWndType).then(() => {
        }).catch((err) => {
          console.log(msgStr + 'tempWnd.setWindowType err.code: ' + JSON.stringify(err.code));
          tempWnd.destroy();
          let flag = (err.code == 1003)
          console.log(msgStr + 'tempWnd.setWindowType flag: ' + flag);
          if (flag) {
            expect(true).assertTrue();
          }
          done();
Y
yaocui 已提交
426
        })
Y
update  
yaocui 已提交
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
      }
    })
    /**
	  * @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', async (systemBarData) => {
        console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
        if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
          console.log(msgStr + 'systemBarTintChange compare start!');
          expect(!!systemBarData).assertTrue();
          expect(!!systemBarData.regionTint).assertTrue();
          let arrLength = systemBarData.regionTint.length;
          for (let i = 0; i < arrLength; i++) {
            let tempData = systemBarData.regionTint[i];
            console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable);
            if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) {
              statusFlag = listenerStatus.finished;
              expect(tempData.isEnable).assertTrue();
            } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) {
              navigationFlag = listenerStatus.finished;
              expect(!tempData.isEnable).assertTrue();
Z
zhurong 已提交
458
            }
Y
update  
yaocui 已提交
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
          }
        }
        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');
Z
zhurong 已提交
477

Y
update  
yaocui 已提交
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
      await tempWnd.setSystemBarEnable(['navigation']).catch((err) => {
        unexpectedError(err, caseName, 'tempWnd.setSystemBarEnable([navigation])', done);
      });
      console.log(msgStr + 'tempWnd.setSystemBarEnable([status]) 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([navigation]) success');
    })
    /**
	  * @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', async (systemBarData) => {
        console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
        if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
          console.log(msgStr + 'systemBarTintChange compare start!');
          expect(!!systemBarData).assertTrue();
          expect(!!systemBarData.regionTint).assertTrue();
          let arrLength = systemBarData.regionTint.length;
          for (let i = 0; i < arrLength; i++) {
            let tempData = systemBarData.regionTint[i];
            console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable);
            if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) {
              statusFlag = listenerStatus.finished;
              expect(!tempData.isEnable).assertTrue();
            } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) {
              navigationFlag = listenerStatus.finished;
              expect(tempData.isEnable).assertTrue();
            }
          }
        }
        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');
    })
Z
zhurong 已提交
550

Y
update  
yaocui 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
    /**
	  * @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', async (systemBarData) => {
        console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
        if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
          console.log(msgStr + 'systemBarTintChange compare start!');
          expect(!!systemBarData).assertTrue();
          expect(!!systemBarData.regionTint).assertTrue();
          let arrLength = systemBarData.regionTint.length;
          for (let i = 0; i < arrLength; i++) {
            let tempData = systemBarData.regionTint[i];
            console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable);
            if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) {
              statusFlag = listenerStatus.finished;
              expect(tempData.isEnable).assertTrue();
            } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) {
              navigationFlag = listenerStatus.finished;
              expect(tempData.isEnable).assertTrue();
            }
          }
        }
        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 .');
    })
Z
zhurong 已提交
611

Y
update  
yaocui 已提交
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
    /**
	  * @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', async (systemBarData) => {
        console.log(msgStr + 'tempWnd.on systemBarTintChange, systemBatData : ' + JSON.stringify(systemBarData));
        if (statusFlag === listenerStatus.pending || navigationFlag === listenerStatus.pending) {
          console.log(msgStr + 'systemBarTintChange compare start!');
          expect(!!systemBarData).assertTrue();
          expect(!!systemBarData.regionTint).assertTrue();
          let arrLength = systemBarData.regionTint.length;
          for (let i = 0; i < arrLength; i++) {
            let tempData = systemBarData.regionTint[i];
            console.log(msgStr + 'compare, type: ' + tempData.type + ';isEnable: ' + tempData.isEnable);
            if (tempData.type === ohosWindow.WindowType.TYPE_STATUS_BAR && statusFlag === listenerStatus.pending) {
              statusFlag = listenerStatus.finished;
              expect(!tempData.isEnable).assertTrue();
            } else if (tempData.type === ohosWindow.WindowType.TYPE_NAVIGATION_BAR && navigationFlag === listenerStatus.pending) {
              navigationFlag = listenerStatus.finished;
              expect(!tempData.isEnable).assertTrue();
            }
          }
        }
        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');
    })
Y
yaocui 已提交
672

Y
update  
yaocui 已提交
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
    /**
	  * @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 === 1003).assertTrue();
        done();
      });
      console.log(msgStr + 'tempWnd.setSystemBarEnable([null, 123]) finished');
    })
Y
yaocui 已提交
707

Y
update  
yaocui 已提交
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
    /**
	  * @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', async (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();
Z
zhurong 已提交
737
            }
Y
update  
yaocui 已提交
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
          }
        }
        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,
        };
        await 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();
Z
zhurong 已提交
778
        })
Y
update  
yaocui 已提交
779 780
      }
    })
Z
zhurong 已提交
781

Y
update  
yaocui 已提交
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
    /**
	  * @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', async (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();
Z
zhurong 已提交
835
            }
Y
update  
yaocui 已提交
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
          }
        }
        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,
        };
        await 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();
Z
zhurong 已提交
876
        })
Y
update  
yaocui 已提交
877 878
      }
    })
Z
zhurong 已提交
879

Y
update  
yaocui 已提交
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
    /**
	  * @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', async (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();
Z
zhurong 已提交
910
            }
Y
update  
yaocui 已提交
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
          }
        }
        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,
        };
        await 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();
Z
zhurong 已提交
952
        })
Y
update  
yaocui 已提交
953 954
      }
    })
Z
zhurong 已提交
955

Y
update  
yaocui 已提交
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
    /**
	 * @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 = systemWindowTypeDicArr.length;
      console.log(msgStr + '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 = null
        await ohosWindow.create(context, windId, tempType).then(
          (data) => {
            tempWnd = data;
          }
        ).catch((err) => {
          console.log(msgStr + 'ohosWindow.create ' + tempType + 'catched, err: ' + JSON.stringify(err));
          unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done);
        });
        console.log(msgStr + 'ohosWindow.create ' + tempType + 'finished, wnd: ' + tempWnd);
        expect(!!tempWnd).assertTrue();
        await tempWnd.destroy();
      }
      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 = null;
        try {
          await ohosWindow.create(context, windId, tempType).then((data) => {
            createData = data
            expect(!!createData).assertTrue();
          }).catch((err) => {
            console.log(msgStr + 'ohosWindow.create err' + JSON.stringify(err));
            unexpectedError(err, caseName, 'ohosWindow.create ' + tempType, done);
            return;
          })
        }
        catch (err) {
          console.log(msgStr + 'ohosWindow.create catch err' + JSON.stringify(err));
        }
        let tempWnd = createData
        console.log(msgStr + 'ohosWindow.create ' + tempType + ' wnd: ' + tempWnd);
        let proData = await tempWnd.getProperties().catch((err) => {
          console.log(msgStr + 'tempWnd.getProperties err' + JSON.stringify(err));
          unexpectedError(err, caseName, 'tempWnd.getProperties', done);
          console.log(msgStr + 'tempWnd.getProperties err&&err.code' + JSON.stringify(err));
Z
zhurong 已提交
1023
        })
Y
update  
yaocui 已提交
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
        expect(!!proData).assertTrue();
        expect(proData.type == tempType).assertTrue();
        await createData.destroy();
        console.log(msgStr + 'n:' + n);
        if (proData.type == tempType) n++
        console.log(msgStr + 'n++:' + n);
        console.log(msgStr + 'i:' + i);
        if (i + 1 == loopCount) {
          if (n === loopCount) {
            expect(true).assertTrue();
          } else {
            expect(true).assertFail();
          }
        }
      }
      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 === 1003).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 = null;
      await ohosWindow.create(context, windowId, 1).then(
        (data) => {
          ohosData = data;
        }).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(1001)
        done();
      })
      await ohosData.destroy();
      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 createWindowObj = {
        name: windowId, windowType: baseWndType, ctx: context
      }
      let tempWnd = null;
      try {
        await ohosWindow.createWindow(createWindowObj).then((data) => {
          tempWnd = data
          console.log(msgStr + 'ohosWindow.create ' + baseWndType + '  , wnd: ' + tempWnd);
        }).catch((err) => {
          unexpectedError(err, caseName, 'ohosWindow.create', done);
        });
      } catch (err) {
        console.log(msgStr + 'ohosWindow.create catch err:' + JSON.stringify(err));
      }
      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();
      await tempWnd.destroy();
      done();
    })
Z
zhurong 已提交
1122

Y
update  
yaocui 已提交
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
    /**
    * @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 createWindowObj = {
        name: windowId, windowType: baseWndType, ctx: context
      }
      let tempWnd = null;
      try {
        await ohosWindow.createWindow(createWindowObj).then((data) => {
          tempWnd = data
          console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd);
          expect(!!tempWnd).assertTrue();
        }).catch((err) => {
          unexpectedError(err, caseName, 'ohosWindow.create', done);
        });
      }
      catch (err) {
        console.log(msgStr + 'ohosWindow.createWindow catch err:' + JSON.stringify(err));
      }
      console.log(msgStr + 'tempWnd.loadContent start');
      await tempWnd.destroy();
      let errFlag = false;
      let loadContentData = null;
      try {
        await tempWnd.loadContent(null).then((data) => {
          loadContentData = data;
        }).catch((err) => {
          errFlag = true;
          expectedError(err, caseName, 'tempWnd.loadContent', done, 1003);
          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();
        }
      } catch (err) {
        console.log(msgStr + 'tempWnd.loadContent(null) catch err:' + JSON.stringify(err));
      }
    })
Z
zhurong 已提交
1172

Y
update  
yaocui 已提交
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
    /**
    * @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('MainAbility/pages/second/second').catch((err) => {
        unexpectedError(err, caseName, 'windowStage loadContent', done);
        console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + 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');
      try {
        let load4 = await windowStage.loadContent(null).catch((err) => {
          expect(false).assertTrue();
          console.log(msgStr + 'windowStage loadContent(null)' + JSON.stringify(err));
        });
        console.log(msgStr + 'windowStage loadContent end load5=' + JSON.stringify(load4));
      }
      catch (err) {
        console.log(msgStr + 'tempWnd.loadContent catch err=' + JSON.stringify(err));
        expectedError(err.code, caseName, 'tempWnd.loadContent', done, 401);
      }
      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');
      try {
        let load5 = await windowStage.loadContent(null, abilityStorage).catch((err) => {
          expect(false).assertTrue();
          console.log(msgStr + 'windowStage loadContent(null)' + JSON.stringify(err));
        });
        console.log(msgStr + 'windowStage loadContent end load5=' + JSON.stringify(load5));
      }
      catch (err) {
        console.log(msgStr + 'tempWnd.loadContent catch err=' + JSON.stringify(err));
        expectedError(err.code, caseName, 'tempWnd.loadContent', done, 401);
      }
      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('MainAbility/pages/second/second', null).catch((err) => {
        unexpectedError(err, caseName, 'windowStage loadContent', done);
        console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + JSON.stringify(err));
      });
      expect(!load6).assertTrue();
      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();
      await subWindow.destroy();
      console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow));
      console.log(msgStr + 'windowStage.createSubWindow end !!subWindow=' + !!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');
      try {
        let subWindow = await windowStage.createSubWindow(null).catch((err) => {
          expect(false).assertTrue();
          console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err));
        });
        console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow));
      }
      catch (err) {
        expectedError(err.code, caseName, 'windowStage.createSubWindow', done, 401);
        console.log(msgStr + 'windowStage.createSubWindow catch err=' + JSON.stringify(err));
      }
      done();
    })
    /**
    * @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 = null
      await ohosWindow.create(context, 'setPrivacyModeTest1', ohosWindow.WindowType.TYPE_SYSTEM_ALERT)
        .then((data) => {
          windowData = data;
        }).catch((err) => {
          unexpectedError(err, caseName, 'ohosWindow.create', done);
Y
yaocui 已提交
1324
        })
Y
update  
yaocui 已提交
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
      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();
      await windowData.destroy();
      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 createWindowObj = {
        name: windowId, windowType: baseWndType, ctx: context
      }
      let tempWnd = null;
      try {
        await ohosWindow.createWindow(createWindowObj).then((data) => {
          tempWnd = data
          console.log(msgStr + 'ohosWindow.create ' + baseWndType + ' wnd: ' + tempWnd);
          expect(!!tempWnd).assertTrue();
          console.log(msgStr + 'tempWnd.destroy start');
        }).catch((err) => {
          unexpectedError(err, caseName, 'ohosWindow.create', done);
        });
      } catch (err) {
        console.log(msgStr + 'destroy catch err : ' + JSON.stringify(err));
      }
      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, 1001);
      });
      console.log(msgStr + 'find findWnd: ' + JSON.stringify(findWnd));
      expect(!findWnd).assertTrue();
      done();
    })
    /**
    * @tc.number     SUB_WINDOW_SETPREFERREDORIENTATION_JSAPI_001
    * @tc.name       Test setPreferredOrientationTest1
    * @tc.desc       Sets the display direction property of the window
    */
    it('setPreferredOrientationTest1', 0, async function (done) {
      let caseName = 'setPreferredOrientationTest1';
      let msgStr = 'jsunittest ' + caseName + ' ';
      console.log(msgStr + 'begin');
      let mainWin = await windowStage.getMainWindow().catch(err => {
        unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
      });
      console.log(msgStr + 'windowStage.getMainWindow :' + JSON.stringify(mainWin));
      expect(!!mainWin).assertTrue();
      let num = 0
      let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED',
      'LANDSCAPE_INVERTED', 'AUTO_ROTATION', 'AUTO_ROTATION_PORTRAIT', 'AUTO_ROTATION_LANDSCAPE',
      'AUTO_ROTATION_RESTRICTED', 'AUTO_ROTATION_PORTRAIT_RESTRICTED', 'AUTO_ROTATION_LANDSCAPE_RESTRICTED', 'LOCKED', 'UNSPECIFIED'];
      for (let i = 0; i < orientationItem.length; i++) {
        let orientation = ohosWindow.Orientation[orientationItem[i]]
        console.log(msgStr + 'i : ' + i + ' ,orientation : ' + orientation);
        console.log(msgStr + 'i : ' + i + ' ,ohosWindow.Orientation : ' + JSON.stringify(ohosWindow.Orientation));
        await mainWin.setPreferredOrientation(orientation).then(() => {
          console.log(msgStr + 'success set window.setPreferredOrientation : ' + orientation);
          num++
          if (num == orientationItem.length) done();
        }).catch(err => {
          console.log(msgStr + 'window.setPreferredOrientation failed set error:' + orientation);
        });
        await sleep(3000)
      }
    })
    /**
    * @tc.number     SUB_WINDOW_SETFORBIDSPLITMOVE_JSAPI_001
    * @tc.name       Test setForbidSplitMoveTest1
    * @tc.desc       Sets whether Windows are forbidden to move in split screen mode
    */
    it('setForbidSplitMoveTest1', 0, async function (done) {
      let caseName = 'setForbidSplitMoveTest1';
      let msgStr = 'jsunittest ' + caseName + ' ';
      console.log(msgStr + 'begin');
      let mainWin = await windowStage.getMainWindow().catch(err => {
        unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
      });
      console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin));
      expect(!!mainWin).assertTrue();
      await mainWin.setForbidSplitMove(true).then(() => {
        console.log(msgStr + 'success set window.setForbidSplitMove drag is prohibited');
      }).catch(err => {
        console.log(msgStr + 'failed set window.setForbidSplitMove drag is prohibited');
      });
      await mainWin.setForbidSplitMove(false).then(() => {
        console.log(msgStr + 'success set window.setForbidSplitMove you can drag it now');
      }).catch(err => {
        console.log(msgStr + 'failed set window.setForbidSplitMove you can drag it now');
      });
      console.log(msgStr + 'done ');
      done();
    })
    /**
    * @tc.number     SUB_WINDOW_SNAPSHOT_JSAPI_001
    * @tc.name       Test snapshotTest1
    * @tc.desc       Scenario of screenshot of verification window
    */
    it('snapshotTest1', 0, async function (done) {
      let caseName = 'snapshotTest1';
      let msgStr = 'jsunittest ' + caseName + ' ';
      console.log(msgStr + 'begin');
      let mainWin = await windowStage.getMainWindow().catch((err) => {
        unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
      });
      console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin));
      expect(!!mainWin).assertTrue();
      await sleep(2000)
      let snapshotData = await mainWin.snapshot().catch((err) => {
        unexpectedError(err, caseName, 'mainWin.snapshot', done);
        console.log(msgStr + 'snapshot err.code:' + JSON.stringify(err.code));
      })
      expect(!!snapshotData).assertTrue();
      done();
    })
    /**
    * @tc.number     SUB_WINDOW_DIALOGTARGETTOUCH_JSAPI_001
    * @tc.name       Test dialogTargetTouchTest1
    * @tc.desc       Verify the scenario of opening modal window
    */
    it('dialogTargetTouchTest1', 0, async function (done) {
      let caseName = 'dialogTargetTouchTest1';
      let msgStr = 'jsunittest ' + caseName + ' ';
      console.log(msgStr + 'begin context==' + JSON.stringify(context));
      let tempType = ohosWindow.WindowType.TYPE_DIALOG
      let dialogTargetTouchTest1Win = null;
      let createWindowObj = {
        name: 'dialogTargetTouchTest1', windowType: tempType, ctx: context
      }
      try {
        await ohosWindow.createWindow(createWindowObj).then((data) => {
          dialogTargetTouchTest1Win = data
Y
yaocui 已提交
1495
        })
Y
update  
yaocui 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
          .catch((err) => {
            unexpectedError(err, caseName, 'ohosWindow.create', done);
          })
      }
      catch (err) {
        console.log(msgStr + 'ohosWindow.createWindow catch err' + JSON.stringify(err));
      }
      expect(!!dialogTargetTouchTest1Win).assertTrue();
      dialogTargetTouchTest1Win.destroy();
      done();
    })
    /**
    * @tc.number     SUB_WINDOW_ANIMATIONFORSHOWN_JSAPI_001
    * @tc.name       Test animationForShownTest1
    * @tc.desc       Verify window custom animation configuration of the scene
    */
    it('animationForShownTest1', 0, async function (done) {
      let caseName = 'animationForShownTest1';
      let msgStr = 'jsunittest ' + caseName + ' ';
      console.log(msgStr + 'begin context==' + JSON.stringify(context));
      console.log(msgStr + 'begin ohosWindow==' + JSON.stringify(ohosWindow));
      let wndId = 'animationForShownTest1';
      let baseType = ohosWindow.WindowType.TYPE_SYSTEM_ALERT;
      let tempWnd = null;
      let createWindowObj = {
        name: wndId, windowType: baseType, ctx: context
      }
      try {
        await ohosWindow.createWindow(createWindowObj).then((data) => {
          tempWnd = data
          console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + tempWnd);
          expect(!!tempWnd).assertTrue();
        }).catch((err) => {
          unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done);
        });
      } catch (err) {
        console.log(msgStr + 'ohosWindow.createWindow catch err:' + JSON.stringify(err));
      }
      let controller = tempWnd.getTransitionController();
      controller.animationForShown = (context: ohosWindow.TransitionContext) => {
        let toWindow = context.toWindow
        animateTo({
          duration: 1000,
          tempo: 0.5,
          curve: Curve.EaseInOut,
          delay: 0,
          iterations: 1,
          playMode: PlayMode.Normal,
        }, () => {
          var obj: ohosWindow.TranslateOptions;
          obj.x = 100.0;
          obj.y = 0.0;
          obj.z = 0.0;
          toWindow.translate(obj);
          console.info(msgStr + 'toWindow translate end');
        }
        )
        context.completeTransition(true)
        console.info(msgStr + 'complete transition end');
      }
      await tempWnd.destroy();
      done();
    })
    /**
    * @tc.number     SUB_WINDOW_GETCUTOUTINFO_JSAPI_001
    * @tc.name       Test getCutoutInfoTest1
    * @tc.desc       Obtain information about unavailable screen areas such as the hole screen, fringe screen, and waterfall screen
    */
    it('getCutoutInfoTest1', 0, async function (done) {
      let caseName = 'getCutoutInfoTest1';
      let msgStr = 'jsunittest ' + caseName + ' ';
      console.log(msgStr + 'begin context==' + JSON.stringify(context));
      let dpClass = display.getDefaultDisplaySync();
      expect(!!dpClass).assertTrue();
      dpClass.getCutoutInfo().then((data) => {
        console.info('Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data));
        done();
      }).catch(err => {
        unexpectedError(err, caseName, 'displayClass.getCutoutInfo', done);
      });
    })
  })
Y
update  
yaocui 已提交
1578
}