1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" 16import window from '@ohos.window'; 17import { UiDriver, BY, ON, PointerMatrix, UiComponent } from '@ohos.UiTest' 18import { BusinessError, Callback } from '@ohos.base'; 19import common from '@ohos.app.ability.common'; 20 21async function sleep(time: number) { 22 let timeoutId: number = 0; 23 let promise = new Promise<string>(resolve => { 24 timeoutId = setTimeout(() => { 25 resolve('sleep finished'); 26 }, time); 27 }) 28 await promise; 29 clearTimeout(timeoutId) 30} 31 32 33function buttonClick(buttonText: string, msgStr: string) { 34 console.info(msgStr + `case come in buttonClick fun`) 35 return new Promise<string>(async (resolve, reject) => { 36 let driver = await UiDriver.create() 37 console.info(msgStr + `case come in buttonClick fun`) 38 console.info(msgStr + `driver is ${JSON.stringify(driver)}`) 39 await sleep(900) 40 console.info(msgStr + `UiDriver start`) 41 let button: UiComponent = await driver.findComponent(BY.text(buttonText)) 42 console.info(msgStr + `button is ${JSON.stringify(button)}`) 43 await sleep(900) 44 if (button) { 45 console.info(msgStr + `button click begin`) 46 await button.click() 47 console.info(msgStr + `button click end`) 48 resolve(msgStr + 'get button successed') 49 } else { 50 console.info(msgStr + `inter else: button is null`) 51 reject(msgStr + 'get button failed') 52 } 53 }) 54} 55export default function windowEventTest(context: common.UIAbilityContext, windowStage: window.WindowStage) { 56 describe('window_event_test', () => { 57 console.log('describe window_event_test start!!!') 58 let tempWnd: window.Window | void; 59 let subWin: window.Window | void; 60 61 afterEach(async ()=>{ 62 if(tempWnd !== null && tempWnd !== undefined){ 63 await (tempWnd as window.Window).destroyWindow(); 64 } 65 if(subWin !== null && subWin !== undefined){ 66 await (subWin as window.Window).destroyWindow(); 67 } 68 }) 69 /** 70 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4820 71 * @tc.name : testTouchOutside_OnDialogWindow_ClickMainWindow 72 * @tc.desc : Enable listening for click events outside this window area. 73 * @tc.size : MediumTest 74 * @tc.type : Function 75 * @tc.level : Level2 76 */ 77 it('testTouchOutside_OnDialogWindow_ClickMainWindow', 0, async (done: Function) => { 78 let caseName = 'testTouchOutside_OnDialogWindow_ClickMainWindow'; 79 let msgStr = 'jsunittest ' + caseName + ' '; 80 console.log(msgStr + 'begin'); 81 let windowConfig: window.Configuration = { 82 name: "testTouchOutside_OnDialogWindow_ClickMainWindow", 83 windowType: window.WindowType.TYPE_DIALOG, 84 ctx: context, 85 }; 86 tempWnd = await window.createWindow(windowConfig).catch((err: BusinessError) => { 87 console.log(msgStr + 'window.createWindow ' + 'catched, err: ' + JSON.stringify(err)); 88 expect().assertFail(); 89 done(); 90 }); 91 expect(!!tempWnd).assertTrue(); 92 await (tempWnd as window.Window).resize(500, 500); 93 await (tempWnd as window.Window).setUIContent("testability/pages/second/pageOne"); 94 await (tempWnd as window.Window).showWindow(); 95 await (tempWnd as window.Window).moveWindowTo(1000, 1000); 96 97 let mainWin = windowStage.getMainWindowSync(); 98 try { 99 // 模态窗口覆盖的主窗口点击不到,所以不会触发监听 100 (tempWnd as window.Window).on('touchOutside', async () => { 101 console.info(msgStr + 'touch outside'); 102 (tempWnd as window.Window).off('touchOutside'); 103 await (tempWnd as window.Window).destroyWindow(); 104 expect().assertFail(); 105 done(); 106 }); 107 console.info(msgStr + 'register touch outside listener successed'); 108 } catch (exception) { 109 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 110 expect().assertFail(); 111 done(); 112 } 113 await buttonClick('MainPageButton', msgStr).catch(async (err: BusinessError) => { 114 console.info(msgStr + err); 115 await (tempWnd as window.Window).destroyWindow(); 116 expect().assertFail(); 117 done(); 118 }) 119 await sleep(800); 120 (tempWnd as window.Window).off('touchOutside'); 121 await (tempWnd as window.Window).destroyWindow(); 122 done(); 123 }) 124 /** 125 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4830 126 * @tc.name : testTouchOutside_OnMainWindow_ClickDialog 127 * @tc.desc : Enable listening for click events outside this window area. 128 * @tc.size : MediumTest 129 * @tc.type : Function 130 * @tc.level : Level2 131 */ 132 it('testTouchOutside_OnMainWindow_ClickDialog', 0, async (done: Function) => { 133 let caseName = 'testTouchOutside_OnMainWindow_ClickDialog'; 134 let msgStr = 'jsunittest ' + caseName + ' '; 135 console.log(msgStr + 'begin'); 136 let windowConfig: window.Configuration = { 137 name: "testTouchOutside_OnMainWindow_ClickDialog", 138 windowType: window.WindowType.TYPE_DIALOG, 139 ctx: context, 140 }; 141 tempWnd = await window.createWindow(windowConfig).catch((err: BusinessError) => { 142 console.log(msgStr + 'window.createWindow ' + 'catched, err: ' + JSON.stringify(err)); 143 expect().assertFail(); 144 done(); 145 }); 146 expect(!!tempWnd).assertTrue(); 147 await (tempWnd as window.Window).resize(500, 500); 148 await (tempWnd as window.Window).setUIContent("testability/pages/second/second"); 149 await (tempWnd as window.Window).showWindow(); 150 await (tempWnd as window.Window).moveWindowTo(10, 10); 151 152 let mainWin = windowStage.getMainWindowSync(); 153 try { 154 mainWin.on('touchOutside', async () => { 155 console.info(msgStr + 'touch outside'); 156 mainWin.off('touchOutside'); 157 await (tempWnd as window.Window).destroyWindow(); 158 await sleep(800) 159 done(); 160 }); 161 console.info(msgStr + 'register touch outside listener successed'); 162 } catch (exception) { 163 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 164 expect().assertFail(); 165 done(); 166 } 167 await buttonClick('secondPage_BackToIndex', msgStr).catch(async (err: BusinessError) => { 168 console.info(msgStr + err); 169 await (tempWnd as window.Window).destroyWindow(); 170 expect().assertFail(); 171 done(); 172 }) 173 }) 174 /** 175 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4840 176 * @tc.name : testTouchOutside_OnSubWindow_ClickMainWindow 177 * @tc.desc : Enable listening for click events outside this window area. 178 * @tc.size : MediumTest 179 * @tc.type : Function 180 * @tc.level : Level2 181 */ 182 it('testTouchOutside_OnSubWindow_ClickMainWindow', 0, async (done: Function) => { 183 let caseName = 'testTouchOutside_OnSubWindow_ClickMainWindow'; 184 let msgStr = 'jsunittest ' + caseName + ' '; 185 console.log(msgStr + 'begin'); 186 subWin = await windowStage.createSubWindow('testTouchOutside_OnSubWindow_ClickMainWindow') 187 .catch((err: BusinessError) => { 188 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 189 expect().assertFail(); 190 }); 191 expect(!!subWin).assertTrue(); 192 await (subWin as window.Window).resize(500, 500); 193 await (subWin as window.Window).setUIContent("testability/pages/second/pageOne"); 194 await (subWin as window.Window).showWindow(); 195 await (subWin as window.Window).moveWindowTo(1000, 1000); 196 let mainWin = windowStage.getMainWindowSync(); 197 try { 198 (subWin as window.Window).on('touchOutside', async () => { 199 console.info(msgStr + 'touch outside'); 200 (subWin as window.Window).off('touchOutside'); 201 await (subWin as window.Window).destroyWindow(); 202 await sleep(800) 203 done(); 204 }); 205 console.info(msgStr + 'register touch outside listener successed'); 206 } catch (exception) { 207 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 208 expect().assertFail(); 209 done(); 210 } 211 await buttonClick('MainPageButton', msgStr).catch(async (err: BusinessError) => { 212 console.info(msgStr + err); 213 await (subWin as window.Window).destroyWindow(); 214 expect().assertFail(); 215 done(); 216 }) 217 }) 218 /** 219 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4850 220 * @tc.name : testTouchOutside_OnMainWindow_ClickSubWindow 221 * @tc.desc : Enable listening for click events outside this window area. 222 * @tc.size : MediumTest 223 * @tc.type : Function 224 * @tc.level : Level2 225 */ 226 it('testTouchOutside_OnMainWindow_ClickSubWindow', 0, async (done: Function) => { 227 let caseName = 'testTouchOutside_OnMainWindow_ClickSubWindow'; 228 let msgStr = 'jsunittest ' + caseName + ' '; 229 console.log(msgStr + 'begin'); 230 subWin = await windowStage.createSubWindow('testTouchOutside_OnMainWindow_ClickSubWindow') 231 .catch((err: BusinessError) => { 232 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 233 expect().assertFail(); 234 }); 235 expect(!!subWin).assertTrue(); 236 await (subWin as window.Window).resize(500, 500); 237 await (subWin as window.Window).setUIContent("testability/pages/second/second"); 238 await (subWin as window.Window).showWindow(); 239 await (subWin as window.Window).moveWindowTo(10, 10); 240 let mainWin = windowStage.getMainWindowSync(); 241 try { 242 mainWin.on('touchOutside', async () => { 243 console.info(msgStr + 'touch outside'); 244 mainWin.off('touchOutside'); 245 await (subWin as window.Window).destroyWindow(); 246 await sleep(800) 247 done(); 248 }); 249 console.info(msgStr + 'register touch outside listener successed'); 250 } catch (exception) { 251 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 252 expect().assertFail(); 253 done(); 254 } 255 await buttonClick('secondPage_BackToIndex', msgStr).catch(async (err: BusinessError) => { 256 console.info(msgStr + err); 257 await (subWin as window.Window).destroyWindow(); 258 expect().assertFail(); 259 done(); 260 }) 261 }) 262 263 264 /** 265 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4860 266 * @tc.name : testDialogTargetTouch_OnMainWindow_ClickMainWindow 267 * @tc.desc : Enables listening for click or touch events for Windows covered by modal Windows 268 * @tc.size : MediumTest 269 * @tc.type : Function 270 * @tc.level : Level2 271 */ 272 it('testDialogTargetTouch_OnMainWindow_ClickMainWindow', 0, async (done: Function) => { 273 let caseName = 'testDialogTargetTouch_OnMainWindow_ClickMainWindow'; 274 let msgStr = 'jsunittest ' + caseName + ' '; 275 console.log(msgStr + 'begin'); 276 let windowConfig: window.Configuration = { 277 name: "testDialogTargetTouch_OnMainWindow_ClickMainWindow", 278 windowType: window.WindowType.TYPE_DIALOG, 279 ctx: context, 280 }; 281 tempWnd = await window.createWindow(windowConfig).catch((err: BusinessError) => { 282 console.log(msgStr + 'window.createWindow ' + 'catched, err: ' + JSON.stringify(err)); 283 expect().assertFail(); 284 done(); 285 }); 286 expect(!!tempWnd).assertTrue(); 287 await (tempWnd as window.Window).resize(500, 500); 288 await (tempWnd as window.Window).setUIContent("testability/pages/second/second"); 289 await (tempWnd as window.Window).showWindow(); 290 await (tempWnd as window.Window).moveWindowTo(1000, 1000); 291 let mainWin = windowStage.getMainWindowSync(); 292 // The listener must be registered on the modal window or it is invalid 293 try { 294 mainWin.on('dialogTargetTouch', async () => { 295 console.info(msgStr + 'touch dialog target'); 296 mainWin.off('dialogTargetTouch'); 297 await (tempWnd as window.Window).destroyWindow(); 298 expect().assertFail(); 299 done(); 300 }); 301 console.info(msgStr + 'register dialogTargetTouch listener successed'); 302 } catch (exception) { 303 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 304 expect().assertFail(); 305 done(); 306 } 307 await buttonClick('MainPageButton', msgStr).catch(async (err: BusinessError) => { 308 console.info(msgStr + err); 309 await (tempWnd as window.Window).destroyWindow(); 310 expect().assertFail(); 311 done(); 312 }) 313 await sleep(800) 314 mainWin.off('dialogTargetTouch'); 315 await (tempWnd as window.Window).destroyWindow(); 316 done(); 317 }) 318 /** 319 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4870 320 * @tc.name : testDialogTargetTouch_OnDialogWindow_ClickMainWindow 321 * @tc.desc : Enables listening for click or touch events for Windows covered by modal Windows 322 * @tc.size : MediumTest 323 * @tc.type : Function 324 * @tc.level : Level2 325 */ 326 it('testDialogTargetTouch_OnDialogWindow_ClickMainWindow', 0, async (done: Function) => { 327 let caseName = 'testDialogTargetTouch_OnDialogWindow_ClickMainWindow'; 328 let msgStr = 'jsunittest ' + caseName + ' '; 329 console.log(msgStr + 'begin'); 330 let windowConfig: window.Configuration = { 331 name: "testDialogTargetTouch_OnDialogWindow_ClickMainWindow", 332 windowType: window.WindowType.TYPE_DIALOG, 333 ctx: context, 334 }; 335 tempWnd = await window.createWindow(windowConfig).catch((err: BusinessError) => { 336 console.log(msgStr + 'window.createWindow ' + 'catched, err: ' + JSON.stringify(err)); 337 expect().assertFail(); 338 done(); 339 }); 340 expect(!!tempWnd).assertTrue(); 341 await (tempWnd as window.Window).resize(500, 500); 342 await (tempWnd as window.Window).setUIContent("testability/pages/second/second"); 343 await (tempWnd as window.Window).showWindow(); 344 await (tempWnd as window.Window).moveWindowTo(1000, 1000); 345 try { 346 (tempWnd as window.Window).on('dialogTargetTouch', async () => { 347 console.info(msgStr + 'touch dialog target'); 348 (tempWnd as window.Window).off('dialogTargetTouch'); 349 await (tempWnd as window.Window).destroyWindow(); 350 await sleep(800) 351 done(); 352 }); 353 console.info(msgStr + 'register dialogTargetTouch listener successed'); 354 } catch (exception) { 355 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 356 expect().assertFail(); 357 done(); 358 } 359 await buttonClick('MainPageButton', msgStr).catch(async (err: BusinessError) => { 360 console.info(msgStr + err); 361 await (tempWnd as window.Window).destroyWindow(); 362 expect().assertFail(); 363 done(); 364 }) 365 }) 366 /** 367 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4880 368 * @tc.name : testDialogTargetTouch_OnSubWindow_ClickSubWindow 369 * @tc.desc : Enables listening for click or touch events for Windows covered by modal Windows 370 * @tc.size : MediumTest 371 * @tc.type : Function 372 * @tc.level : Level2 373 */ 374 it('testDialogTargetTouch_OnSubWindow_ClickSubWindow', 0, async (done: Function) => { 375 let caseName = 'testDialogTargetTouch_OnSubWindow_ClickSubWindow'; 376 let msgStr = 'jsunittest ' + caseName + ' '; 377 console.log(msgStr + 'begin'); 378 subWin = await windowStage.createSubWindow('testDialogTargetTouch_OnSubWindow_Sub') 379 .catch((err: BusinessError) => { 380 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 381 expect().assertFail(); 382 }); 383 expect(!!subWin).assertTrue(); 384 await (subWin as window.Window).resize(500, 500); 385 await (subWin as window.Window).setUIContent("testability/pages/second/pageOne"); 386 await (subWin as window.Window).showWindow(); 387 await (subWin as window.Window).moveWindowTo(10, 10); 388 let windowConfig: window.Configuration = { 389 name: "testDialogTargetTouch_OnSubWindow_Dialog", 390 windowType: window.WindowType.TYPE_DIALOG, 391 ctx: context, 392 }; 393 tempWnd = await window.createWindow(windowConfig).catch((err: BusinessError) => { 394 console.log(msgStr + 'window.createWindow ' + 'catched, err: ' + JSON.stringify(err)); 395 expect().assertFail(); 396 done(); 397 }); 398 expect(!!tempWnd).assertTrue(); 399 await (tempWnd as window.Window).resize(500, 500); 400 await (tempWnd as window.Window).setUIContent("testability/pages/second/second"); 401 await (tempWnd as window.Window).showWindow(); 402 await (tempWnd as window.Window).moveWindowTo(900, 900); 403 // The listener must be registered on the modal window or it is invalid 404 try { 405 (subWin as window.Window).on('dialogTargetTouch', async () => { 406 console.info(msgStr + 'touch dialog target'); 407 (subWin as window.Window).off('dialogTargetTouch'); 408 await (subWin as window.Window).destroyWindow(); 409 await (tempWnd as window.Window).destroyWindow(); 410 expect().assertFail(); 411 done(); 412 }); 413 console.info(msgStr + 'register dialogTargetTouch listener successed'); 414 } catch (exception) { 415 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 416 expect().assertFail(); 417 done(); 418 } 419 await buttonClick('点击pageOne', msgStr).catch(async (err: BusinessError) => { 420 console.info(msgStr + err); 421 await (tempWnd as window.Window).destroyWindow(); 422 await (subWin as window.Window).destroyWindow(); 423 expect().assertFail(); 424 done(); 425 }) 426 await sleep(800); 427 (subWin as window.Window).off('dialogTargetTouch'); 428 await (subWin as window.Window).destroyWindow(); 429 await (tempWnd as window.Window).destroyWindow(); 430 done(); 431 }) 432 /** 433 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4890 434 * @tc.name : testDialogTargetTouch_OnDialogWindow_ClickSubWindow 435 * @tc.desc : Enables listening for click or touch events for Windows covered by modal Windows 436 * @tc.size : MediumTest 437 * @tc.type : Function 438 * @tc.level : Level2 439 */ 440 it('testDialogTargetTouch_OnDialogWindow_ClickSubWindow', 0, async (done: Function) => { 441 let caseName = 'testDialogTargetTouch_OnDialogWindow_ClickSubWindow'; 442 let msgStr = 'jsunittest ' + caseName + ' '; 443 console.log(msgStr + 'begin'); 444 subWin = await windowStage.createSubWindow('testDialogTargetTouch_OnDialogWindow_ClickSubWindow_Sub') 445 .catch((err: BusinessError) => { 446 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 447 expect().assertFail(); 448 }); 449 expect(!!subWin).assertTrue(); 450 await (subWin as window.Window).resize(500, 500); 451 await (subWin as window.Window).setUIContent("testability/pages/second/pageOne"); 452 await (subWin as window.Window).showWindow(); 453 await (subWin as window.Window).moveWindowTo(10, 10); 454 let windowConfig: window.Configuration = { 455 name: "testDialogTargetTouch_OnDialogWindow_ClickSubWindow_Dialog", 456 windowType: window.WindowType.TYPE_DIALOG, 457 ctx: context, 458 }; 459 tempWnd = await window.createWindow(windowConfig).catch((err: BusinessError) => { 460 console.log(msgStr + 'window.createWindow ' + 'catched, err: ' + JSON.stringify(err)); 461 expect().assertFail(); 462 done(); 463 }); 464 expect(!!tempWnd).assertTrue(); 465 await (tempWnd as window.Window).resize(500, 500); 466 await (tempWnd as window.Window).setUIContent("testability/pages/second/second"); 467 await (tempWnd as window.Window).showWindow(); 468 await (tempWnd as window.Window).moveWindowTo(900, 900); 469 try { 470 (tempWnd as window.Window).on('dialogTargetTouch', async () => { 471 console.info(msgStr + 'touch dialog target'); 472 (tempWnd as window.Window).off('dialogTargetTouch'); 473 await (subWin as window.Window).destroyWindow(); 474 await (tempWnd as window.Window).destroyWindow(); 475 await sleep(800) 476 done(); 477 }); 478 console.info(msgStr + 'register dialogTargetTouch listener successed'); 479 } catch (exception) { 480 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 481 expect().assertFail(); 482 done(); 483 } 484 await buttonClick('点击pageOne', msgStr).catch(async (err: BusinessError) => { 485 console.info(msgStr + err); 486 await (tempWnd as window.Window).destroyWindow(); 487 await (subWin as window.Window).destroyWindow(); 488 expect().assertFail(); 489 done(); 490 }) 491 }) 492 493 /** 494 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4900 495 * @tc.name : testNoInteractionDetected_OnMainWindow 496 * @tc.desc : Enables this window to not listen for interactive events within a specified timeout period 497 * @tc.size : MediumTest 498 * @tc.type : Function 499 * @tc.level : Level2 500 */ 501 it('testNoInteractionDetected_OnMainWindow', 0, async (done: Function) => { 502 let caseName = 'testNoInteractionDetected_OnMainWindow'; 503 let msgStr = 'jsunittest ' + caseName + ' '; 504 console.log(msgStr + 'begin'); 505 let mainWin = windowStage.getMainWindowSync(); 506 expect(!!mainWin).assertTrue(); 507 try { 508 mainWin.on('noInteractionDetected', 1, () => { 509 console.info(msgStr + 'no interaction in 10s'); 510 mainWin.off('noInteractionDetected'); 511 done(); 512 }); 513 console.info(msgStr + ' register noInteractionDetected successed'); 514 } catch (exception) { 515 if (exception.code != 801) { 516 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 517 expect().assertFail(); 518 done(); 519 } else { 520 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 521 console.log(msgStr + JSON.stringify(exception)) 522 expect(exception.code).assertEqual(801); 523 done(); 524 } 525 } 526 await sleep(800) 527 await sleep(800) 528 }) 529 /** 530 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4910 531 * @tc.name : testNoInteractionDetected_OnSubWindow 532 * @tc.desc : Enables this window to not listen for interactive events within a specified timeout period 533 * @tc.size : MediumTest 534 * @tc.type : Function 535 * @tc.level : Level2 536 */ 537 it('testNoInteractionDetected_OnSubWindow', 0, async (done: Function) => { 538 let caseName = 'testNoInteractionDetected_OnSubWindow'; 539 let msgStr = 'jsunittest ' + caseName + ' '; 540 console.log(msgStr + 'begin'); 541 subWin = await windowStage.createSubWindow('testNoInteractionDetected_OnSubWindow') 542 .catch((err: BusinessError) => { 543 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 544 expect().assertFail(); 545 }); 546 expect(!!subWin).assertTrue(); 547 await (subWin as window.Window).resize(500, 500); 548 await (subWin as window.Window).setUIContent("testability/pages/second/pageOne"); 549 await (subWin as window.Window).showWindow(); 550 await (subWin as window.Window).moveWindowTo(10, 10); 551 try { 552 (subWin as window.Window).on('noInteractionDetected', 1, async () => { 553 console.info(msgStr + 'no interaction in 10s'); 554 (subWin as window.Window).off('noInteractionDetected'); 555 await (subWin as window.Window).destroyWindow(); 556 done(); 557 }); 558 console.info(msgStr + ' register noInteractionDetected successed'); 559 } catch (exception) { 560 if (exception.code != 801) { 561 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 562 await (subWin as window.Window).destroyWindow(); 563 expect().assertFail(); 564 done(); 565 } else { 566 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 567 console.log(msgStr + JSON.stringify(exception)) 568 await (subWin as window.Window).destroyWindow(); 569 expect(exception.code).assertEqual(801); 570 done(); 571 } 572 } 573 await sleep(800) 574 await sleep(800) 575 }) 576 577 /** 578 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4920 579 * @tc.name : testSetWindowTouchable_MainWindow_Promise 580 * @tc.desc : Sets whether the window is touchable 581 * @tc.size : MediumTest 582 * @tc.type : Function 583 * @tc.level : Level2 584 */ 585 it('testSetWindowTouchable_MainWindow_Promise', 0, async (done: Function) => { 586 let caseName = 'testSetWindowTouchable_MainWindow_Promise'; 587 let msgStr = 'jsunittest ' + caseName + ' '; 588 console.log(msgStr + 'begin'); 589 let mainWin = windowStage.getMainWindowSync(); 590 expect(!!mainWin).assertTrue(); 591 let isTouchable: boolean = true; 592 try { 593 await mainWin.setWindowTouchable(isTouchable).then(() => { 594 console.info(msgStr + 'Succeeded in setting the window to be touchable.'); 595 let properties = mainWin.getWindowProperties(); 596 console.info(msgStr + 'getWindowProperties: ' + JSON.stringify(properties)); 597 expect(properties.touchable).assertEqual(isTouchable); 598 done(); 599 }).catch((err: BusinessError) => { 600 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 601 expect().assertFail(); 602 done(); 603 }); 604 } catch (exception) { 605 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 606 expect().assertFail(); 607 done(); 608 } 609 }) 610 /** 611 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4930 612 * @tc.name : testSetWindowTouchable_MainWindow_Callback 613 * @tc.desc : Sets whether the window is touchable 614 * @tc.size : MediumTest 615 * @tc.type : Function 616 * @tc.level : Level2 617 */ 618 it('testSetWindowTouchable_MainWindow_Callback', 0, async (done: Function) => { 619 let caseName = 'testSetWindowTouchable_MainWindow_Callback'; 620 let msgStr = 'jsunittest ' + caseName + ' '; 621 console.log(msgStr + 'begin'); 622 let mainWin = windowStage.getMainWindowSync(); 623 expect(!!mainWin).assertTrue(); 624 let isTouchable = true; 625 try { 626 mainWin.setWindowTouchable(isTouchable, (err: BusinessError) => { 627 const errCode: number = err.code; 628 if (errCode) { 629 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 630 expect().assertFail(); 631 done(); 632 return; 633 } 634 console.info(msgStr + 'Succeeded in setting the window to be touchable.'); 635 let properties = mainWin.getWindowProperties(); 636 console.info(msgStr + 'getWindowProperties: ' + JSON.stringify(properties)); 637 expect(properties.touchable).assertEqual(isTouchable); 638 done(); 639 }); 640 } catch (exception) { 641 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 642 expect().assertFail(); 643 done(); 644 } 645 }) 646 /** 647 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4940 648 * @tc.name : testSetWindowTouchable_SubWindow_Promise 649 * @tc.desc : Sets whether the window is touchable 650 * @tc.size : MediumTest 651 * @tc.type : Function 652 * @tc.level : Level2 653 */ 654 it('testSetWindowTouchable_SubWindow_Promise', 0, async (done: Function) => { 655 let caseName = 'testSetWindowTouchable_SubWindow_Promise'; 656 let msgStr = 'jsunittest ' + caseName + ' '; 657 console.log(msgStr + 'begin'); 658 subWin = await windowStage.createSubWindow('testSetWindowTouchable_SubWindow_Promise') 659 .catch((err: BusinessError) => { 660 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 661 expect().assertFail(); 662 done(); 663 }); 664 expect(!!subWin).assertTrue(); 665 await (subWin as window.Window).resize(500, 500); 666 await (subWin as window.Window).setUIContent("testability/pages/second/second"); 667 await (subWin as window.Window).showWindow(); 668 await (subWin as window.Window).moveWindowTo(10, 10); 669 let isTouchable: boolean = true; 670 try { 671 await (subWin as window.Window).setWindowTouchable(isTouchable).then(() => { 672 console.info(msgStr + 'Succeeded in setting the window to be touchable.'); 673 let properties = (subWin as window.Window).getWindowProperties(); 674 console.info(msgStr + 'getWindowProperties: ' + JSON.stringify(properties)); 675 expect(properties.touchable).assertEqual(isTouchable); 676 }).catch((err: BusinessError) => { 677 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 678 expect().assertFail(); 679 }); 680 } catch (exception) { 681 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 682 expect().assertFail(); 683 } 684 await (subWin as window.Window).destroyWindow(); 685 done(); 686 }) 687 /** 688 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_4950 689 * @tc.name : testSetWindowTouchable_SubWindow_Callback 690 * @tc.desc : Sets whether the window is touchable 691 * @tc.size : MediumTest 692 * @tc.type : Function 693 * @tc.level : Level2 694 */ 695 it('testSetWindowTouchable_SubWindow_Callback', 0, async (done: Function) => { 696 let caseName = 'testSetWindowTouchable_SubWindow_Callback'; 697 let msgStr = 'jsunittest ' + caseName + ' '; 698 console.log(msgStr + 'begin'); 699 subWin = await windowStage.createSubWindow('testSetWindowTouchable_SubWindow_Callback') 700 .catch((err: BusinessError) => { 701 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 702 expect().assertFail(); 703 done(); 704 }); 705 expect(!!subWin).assertTrue(); 706 await (subWin as window.Window).resize(500, 500); 707 await (subWin as window.Window).setUIContent("testability/pages/second/second"); 708 await (subWin as window.Window).showWindow(); 709 await (subWin as window.Window).moveWindowTo(10, 10); 710 let isTouchable: boolean = true; 711 try { 712 (subWin as window.Window).setWindowTouchable(isTouchable, async (err: BusinessError) => { 713 const errCode: number = err.code; 714 if (errCode) { 715 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 716 await (subWin as window.Window).destroyWindow(); 717 expect().assertFail(); 718 done(); 719 return; 720 } 721 console.info(msgStr + 'Succeeded in setting the window to be touchable.'); 722 let properties = (subWin as window.Window).getWindowProperties(); 723 console.info(msgStr + 'getWindowProperties: ' + JSON.stringify(properties)); 724 expect(properties.touchable).assertEqual(isTouchable); 725 await (subWin as window.Window).destroyWindow(); 726 done(); 727 }); 728 } catch (exception) { 729 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 730 await (subWin as window.Window).destroyWindow(); 731 expect().assertFail(); 732 done(); 733 } 734 }) 735 /** 736 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_5480 737 * @tc.name : testTouchOutside_OnSubWindowWithOps_ClickMainWindow 738 * @tc.desc : Enable listening for click events outside this window area. 739 * @tc.size : MediumTest 740 * @tc.type : Function 741 * @tc.level : Level2 742 */ 743 it('testTouchOutside_OnSubWindowWithOps_ClickMainWindow', 0, async (done: Function) => { 744 let caseName = 'testTouchOutside_OnSubWindowWithOps_ClickMainWindow'; 745 let msgStr = 'jsunittest ' + caseName + ' '; 746 console.log(msgStr + 'begin'); 747 let options: window.SubWindowOptions = { 748 title: 'testTouchOutside_OnSubWindowWithOps_ClickMainWindow', 749 decorEnabled: true 750 }; 751 await windowStage.createSubWindowWithOptions('testTouchOutside_OnSubWindowWithOps_ClickMainWindow', options) 752 .then(async (data) => { 753 subWin = data; 754 expect(!!subWin).assertTrue(); 755 await (subWin as window.Window).resize(500, 500); 756 await (subWin as window.Window).setUIContent("testability/pages/second/pageOne"); 757 await (subWin as window.Window).showWindow(); 758 await (subWin as window.Window).moveWindowTo(1000, 1000); 759 let mainWin = windowStage.getMainWindowSync(); 760 try { 761 (subWin as window.Window).on('touchOutside', async () => { 762 console.info(msgStr + 'touch outside'); 763 (subWin as window.Window).off('touchOutside'); 764 await (subWin as window.Window).destroyWindow(); 765 await sleep(800) 766 done(); 767 }); 768 console.info(msgStr + 'register touch outside listener successed'); 769 } catch (exception) { 770 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 771 expect().assertFail(); 772 done(); 773 } 774 await sleep(800) 775 await buttonClick('MainPageButton', msgStr).catch(async (err: BusinessError) => { 776 console.info(msgStr + err); 777 await (subWin as window.Window).destroyWindow(); 778 expect().assertFail(); 779 done(); 780 }) 781 }) 782 .catch(async(err: BusinessError) => { 783 if (err.code != 1300002) { 784 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 785 expect().assertFail(); 786 done(); 787 } else { 788 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 789 console.log(msgStr + JSON.stringify(err)) 790 expect(err.code).assertEqual(1300002); 791 done(); 792 } 793 }); 794 }) 795 /** 796 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_5490 797 * @tc.name : testTouchOutside_OnMainWindow_ClickSubWindowWithOps 798 * @tc.desc : Enable listening for click events outside this window area. 799 * @tc.size : MediumTest 800 * @tc.type : Function 801 * @tc.level : Level2 802 */ 803 it('testTouchOutside_OnMainWindow_ClickSubWindowWithOps', 0, async (done: Function) => { 804 let caseName = 'testTouchOutside_OnMainWindow_ClickSubWindowWithOps'; 805 let msgStr = 'jsunittest ' + caseName + ' '; 806 console.log(msgStr + 'begin'); 807 let options: window.SubWindowOptions = { 808 title: 'testTouchOutside_OnMainWindow_ClickSubWindowWithOps', 809 decorEnabled: true 810 }; 811 await windowStage.createSubWindowWithOptions('testTouchOutside_OnMainWindow_ClickSubWindowWithOps', options) 812 .then(async (data) => { 813 subWin = data; 814 expect(!!subWin).assertTrue(); 815 await (subWin as window.Window).resize(500, 500); 816 await (subWin as window.Window).setUIContent("testability/pages/second/second"); 817 await (subWin as window.Window).showWindow(); 818 await (subWin as window.Window).moveWindowTo(10, 10); 819 let mainWin = windowStage.getMainWindowSync(); 820 try { 821 mainWin.on('touchOutside', async () => { 822 console.info(msgStr + 'touch outside'); 823 mainWin.off('touchOutside'); 824 await (subWin as window.Window).destroyWindow(); 825 await sleep(800) 826 done(); 827 }); 828 console.info(msgStr + 'register touch outside listener successed'); 829 } catch (exception) { 830 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 831 expect().assertFail(); 832 done(); 833 } 834 await sleep(800) 835 await buttonClick('secondPage_BackToIndex', msgStr).catch(async (err: BusinessError) => { 836 console.info(msgStr + err); 837 await (subWin as window.Window).destroyWindow(); 838 expect().assertFail(); 839 done(); 840 }) 841 }) 842 .catch((err: BusinessError) => { 843 if (err.code != 1300002) { 844 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 845 expect().assertFail(); 846 done(); 847 } else { 848 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 849 console.log(msgStr + JSON.stringify(err)) 850 expect(err.code).assertEqual(1300002); 851 done(); 852 } 853 }); 854 }) 855 856 /** 857 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_5500 858 * @tc.name : testDialogTargetTouch_OnSubWindowWithOps_ClickSubWinOps 859 * @tc.desc : Enables listening for click or touch events for Windows covered by modal Windows 860 * @tc.size : MediumTest 861 * @tc.type : Function 862 * @tc.level : Level2 863 */ 864 it('testDialogTargetTouch_OnSubWindowWithOps_ClickSubWinOps', 0, async (done: Function) => { 865 let caseName = 'testDialogTargetTouch_OnSubWindowWithOps_ClickSubWinOps'; 866 let msgStr = 'jsunittest ' + caseName + ' '; 867 console.log(msgStr + 'begin'); 868 let windowConfig: window.Configuration = { 869 name: "testDialogTargetTouch_OnSubWindowWithOps_ClickSubWinOps", 870 windowType: window.WindowType.TYPE_DIALOG, 871 ctx: context, 872 }; 873 tempWnd = await window.createWindow(windowConfig).catch((err: BusinessError) => { 874 console.log(msgStr + 'window.createWindow ' + 'catched, err: ' + JSON.stringify(err)); 875 expect().assertFail(); 876 done(); 877 }); 878 expect(!!tempWnd).assertTrue(); 879 await (tempWnd as window.Window).resize(500, 500); 880 await (tempWnd as window.Window).setUIContent("testability/pages/second/second"); 881 await (tempWnd as window.Window).showWindow(); 882 await (tempWnd as window.Window).moveWindowTo(900, 900); 883 let options: window.SubWindowOptions = { 884 title: 'testDialogTargetTouch_OnSubWindowWithOps', 885 decorEnabled: true 886 }; 887 await windowStage.createSubWindowWithOptions('testDialogTargetTouch_OnSubWindowWithOps_Sub', options) 888 .then(async (data) => { 889 subWin = data; 890 expect(!!subWin).assertTrue(); 891 await (subWin as window.Window).resize(500, 500); 892 await (subWin as window.Window).setUIContent("testability/pages/second/pageOne"); 893 await (subWin as window.Window).showWindow(); 894 await (subWin as window.Window).moveWindowTo(10, 10); 895 // The listener must be registered on the modal window or it is invalid 896 try { 897 (subWin as window.Window).on('dialogTargetTouch', async () => { 898 console.info(msgStr + 'touch dialog target'); 899 (subWin as window.Window).off('dialogTargetTouch'); 900 await (subWin as window.Window).destroyWindow(); 901 await (tempWnd as window.Window).destroyWindow(); 902 expect().assertFail(); 903 done(); 904 }); 905 console.info(msgStr + 'register dialogTargetTouch listener successed'); 906 } catch (exception) { 907 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 908 expect().assertFail(); 909 done(); 910 } 911 await buttonClick('点击pageOne', msgStr).catch(async (err: BusinessError) => { 912 console.info(msgStr + err); 913 await (tempWnd as window.Window).destroyWindow(); 914 await (subWin as window.Window).destroyWindow(); 915 expect().assertFail(); 916 done(); 917 }) 918 await sleep(800) 919 await (subWin as window.Window).destroyWindow(); 920 await (tempWnd as window.Window).destroyWindow(); 921 done(); 922 }) 923 .catch(async(err: BusinessError) => { 924 await (tempWnd as window.Window).destroyWindow(); 925 if (err.code != 1300002) { 926 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 927 expect().assertFail(); 928 done(); 929 } else { 930 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 931 console.log(msgStr + JSON.stringify(err)) 932 expect(err.code).assertEqual(1300002); 933 done(); 934 } 935 }); 936 }) 937 938 /** 939 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_5510 940 * @tc.name : testDialogTargetTouch_OnDialogWindow_ClickSubWinOps 941 * @tc.desc : Enables listening for click or touch events for Windows covered by modal Windows 942 * @tc.size : MediumTest 943 * @tc.type : Function 944 * @tc.level : Level2 945 */ 946 it('testDialogTargetTouch_OnDialogWindow_ClickSubWinOps', 0, async (done: Function) => { 947 let caseName = 'testDialogTargetTouch_OnDialogWindow_ClickSubWinOps'; 948 let msgStr = 'jsunittest ' + caseName + ' '; 949 console.log(msgStr + 'begin'); 950 let options: window.SubWindowOptions = { 951 title: 'testDialogTargetTouch_OnDialogWindow_ClickSubWinOps', 952 decorEnabled: true 953 }; 954 await windowStage.createSubWindowWithOptions('testDialogTargetTouch_OnDialogWindow_ClickSubWinOps_Sub', options) 955 .then(async (data) => { 956 subWin = data; 957 expect(!!subWin).assertTrue(); 958 await (subWin as window.Window).resize(500, 500); 959 await (subWin as window.Window).setUIContent("testability/pages/second/pageOne"); 960 await (subWin as window.Window).showWindow(); 961 await (subWin as window.Window).moveWindowTo(10, 10); 962 let windowConfig: window.Configuration = { 963 name: "testDialogTargetTouch_OnDialogWindow_ClickSubWinOps_WithOps", 964 windowType: window.WindowType.TYPE_DIALOG, 965 ctx: context, 966 }; 967 tempWnd = await window.createWindow(windowConfig).catch((err: BusinessError) => { 968 console.log(msgStr + 'window.createWindow ' + 'catched, err: ' + JSON.stringify(err)); 969 expect().assertFail(); 970 done(); 971 }); 972 expect(!!tempWnd).assertTrue(); 973 await (tempWnd as window.Window).resize(500, 500); 974 await (tempWnd as window.Window).setUIContent("testability/pages/second/second"); 975 await (tempWnd as window.Window).showWindow(); 976 await (tempWnd as window.Window).moveWindowTo(900, 900); 977 try { 978 (tempWnd as window.Window).on('dialogTargetTouch', async () => { 979 console.info(msgStr + 'touch dialog target'); 980 (tempWnd as window.Window).off('dialogTargetTouch'); 981 await (subWin as window.Window).destroyWindow(); 982 await (tempWnd as window.Window).destroyWindow(); 983 await sleep(800) 984 done(); 985 }); 986 console.info(msgStr + 'register dialogTargetTouch listener successed'); 987 } catch (exception) { 988 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 989 expect().assertFail(); 990 done(); 991 } 992 await buttonClick('点击pageOne', msgStr).catch(async (err: BusinessError) => { 993 console.info(msgStr + err); 994 await (tempWnd as window.Window).destroyWindow(); 995 await (subWin as window.Window).destroyWindow(); 996 expect().assertFail(); 997 done(); 998 }) 999 await sleep(800) 1000 }) 1001 .catch((err: BusinessError) => { 1002 if (err.code != 1300002) { 1003 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 1004 expect().assertFail(); 1005 done(); 1006 } else { 1007 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 1008 console.log(msgStr + JSON.stringify(err)) 1009 expect(err.code).assertEqual(1300002); 1010 done(); 1011 } 1012 }); 1013 }) 1014 /** 1015 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_5520 1016 * @tc.name : testNoInteractionDetected_OnSubWindowWithOps 1017 * @tc.desc : Enables this window to not listen for interactive events within a specified timeout period 1018 * @tc.size : MediumTest 1019 * @tc.type : Function 1020 * @tc.level : Level2 1021 */ 1022 it('testNoInteractionDetected_OnSubWindowWithOps', 0, async (done: Function) => { 1023 let caseName = 'testNoInteractionDetected_OnSubWindowWithOps'; 1024 let msgStr = 'jsunittest ' + caseName + ' '; 1025 console.log(msgStr + 'begin'); 1026 let options: window.SubWindowOptions = { 1027 title: 'testNoInteractionDetected_OnSubWindowWithOps', 1028 decorEnabled: true 1029 }; 1030 await windowStage.createSubWindowWithOptions('testNoInteractionDetected_OnSubWindowWithOps', options) 1031 .then(async (data) => { 1032 subWin = data; 1033 expect(!!subWin).assertTrue(); 1034 await (subWin as window.Window).resize(500, 500); 1035 await (subWin as window.Window).setUIContent("testability/pages/second/pageOne"); 1036 await (subWin as window.Window).showWindow(); 1037 await (subWin as window.Window).moveWindowTo(10, 10); 1038 try { 1039 (subWin as window.Window).on('noInteractionDetected', 1, async () => { 1040 console.info(msgStr + 'no interaction in 10s'); 1041 (subWin as window.Window).off('noInteractionDetected'); 1042 await (subWin as window.Window).destroyWindow(); 1043 done(); 1044 }); 1045 console.info(msgStr + ' register noInteractionDetected successed'); 1046 } catch (exception) { 1047 if (exception.code != 801) { 1048 console.error(msgStr + `Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 1049 expect().assertFail(); 1050 done(); 1051 } else { 1052 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 1053 console.log(msgStr + JSON.stringify(exception)) 1054 expect(exception.code).assertEqual(801); 1055 done(); 1056 } 1057 } 1058 await sleep(500) 1059 await sleep(500) 1060 await sleep(500) 1061 }) 1062 .catch((err: BusinessError) => { 1063 if (err.code != 1300002) { 1064 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 1065 expect().assertFail(); 1066 done(); 1067 } else { 1068 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 1069 console.log(msgStr + JSON.stringify(err)) 1070 expect(err.code).assertEqual(1300002); 1071 done(); 1072 } 1073 }); 1074 }) 1075 /** 1076 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_5530 1077 * @tc.name : testSetWindowTouchable_SubWindowWithOps_Promise 1078 * @tc.desc : Sets whether the window is touchable 1079 * @tc.size : MediumTest 1080 * @tc.type : Function 1081 * @tc.level : Level2 1082 */ 1083 it('testSetWindowTouchable_SubWindowWithOps_Promise', 0, async (done: Function) => { 1084 let caseName = 'testSetWindowTouchable_SubWindowWithOps_Promise'; 1085 let msgStr = 'jsunittest ' + caseName + ' '; 1086 console.log(msgStr + 'begin'); 1087 let options: window.SubWindowOptions = { 1088 title: 'testSetWindowTouchable_SubWindowWithOps_Promise', 1089 decorEnabled: true 1090 }; 1091 await windowStage.createSubWindowWithOptions('testSetWindowTouchable_SubWindowWithOps_Promise', options) 1092 .then(async (data) => { 1093 subWin = data; 1094 expect(!!subWin).assertTrue(); 1095 await (subWin as window.Window).resize(500, 500); 1096 await (subWin as window.Window).setUIContent("testability/pages/second/second"); 1097 await (subWin as window.Window).showWindow(); 1098 await (subWin as window.Window).moveWindowTo(10, 10); 1099 let isTouchable: boolean = true; 1100 try { 1101 await (subWin as window.Window).setWindowTouchable(isTouchable).then(() => { 1102 console.info(msgStr + 'Succeeded in setting the window to be touchable.'); 1103 let properties: window.WindowProperties = (subWin as window.Window).getWindowProperties(); 1104 console.info(msgStr + 'getWindowProperties: ' + JSON.stringify(properties)); 1105 expect(properties.touchable).assertEqual(isTouchable); 1106 }).catch((err: BusinessError) => { 1107 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 1108 expect().assertFail(); 1109 }); 1110 } catch (exception) { 1111 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 1112 expect().assertFail(); 1113 } 1114 await (subWin as window.Window).destroyWindow(); 1115 done(); 1116 }) 1117 .catch((err: BusinessError) => { 1118 if (err.code != 1300002) { 1119 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 1120 expect().assertFail(); 1121 done(); 1122 } else { 1123 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 1124 console.log(msgStr + JSON.stringify(err)) 1125 expect(err.code).assertEqual(1300002); 1126 done(); 1127 } 1128 }); 1129 }) 1130 1131 /** 1132 * @tc.number : SUB_BASIC_WMS_SPCIAL_XTS_STAGE_JS_API_5540 1133 * @tc.name : testSetWindowTouchable_SubWindowWithOps_Callback 1134 * @tc.desc : Sets whether the window is touchable 1135 * @tc.size : MediumTest 1136 * @tc.type : Function 1137 * @tc.level : Level2 1138 */ 1139 it('testSetWindowTouchable_SubWindowWithOps_Callback', 0, async (done: Function) => { 1140 let caseName = 'testSetWindowTouchable_SubWindowWithOps_Callback'; 1141 let msgStr = 'jsunittest ' + caseName + ' '; 1142 console.log(msgStr + 'begin'); 1143 let options: window.SubWindowOptions = { 1144 title: 'testSetWindowTouchable_SubWindowWithOps_Callback', 1145 decorEnabled: true 1146 }; 1147 await windowStage.createSubWindowWithOptions('testSetWindowTouchable_SubWindowWithOps_Callback', options) 1148 .then(async (data) => { 1149 subWin = data; 1150 expect(!!subWin).assertTrue(); 1151 await (subWin as window.Window).resize(500, 500); 1152 await (subWin as window.Window).setUIContent("testability/pages/second/second"); 1153 await (subWin as window.Window).showWindow(); 1154 await (subWin as window.Window).moveWindowTo(10, 10); 1155 let isTouchable: boolean = true; 1156 try { 1157 (subWin as window.Window).setWindowTouchable(isTouchable, async (err: BusinessError) => { 1158 const errCode: number = err.code; 1159 if (errCode) { 1160 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 1161 await (subWin as window.Window).destroyWindow(); 1162 expect().assertFail(); 1163 done(); 1164 return; 1165 } 1166 console.info(msgStr + 'Succeeded in setting the window to be touchable.'); 1167 let properties: window.WindowProperties = (subWin as window.Window).getWindowProperties(); 1168 console.info(msgStr + 'getWindowProperties: ' + JSON.stringify(properties)); 1169 expect(properties.touchable).assertEqual(isTouchable); 1170 await (subWin as window.Window).destroyWindow(); 1171 done(); 1172 }); 1173 } catch (exception) { 1174 console.error(msgStr + `Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 1175 await (subWin as window.Window).destroyWindow(); 1176 expect().assertFail(); 1177 done(); 1178 } 1179 }) 1180 .catch((err: BusinessError) => { 1181 if (err.code != 1300002) { 1182 console.error(msgStr + `Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 1183 expect().assertFail(); 1184 done(); 1185 } else { 1186 console.log(msgStr + '当前设备类型不支持系统能力SystemCapability.Window.SessionManager') 1187 console.log(msgStr + JSON.stringify(err)) 1188 expect(err.code).assertEqual(1300002); 1189 done(); 1190 } 1191 }); 1192 }) 1193 }) 1194} 1195