1/* 2 * Copyright (C) 2023 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 */ 15 16import inputMethod from '@ohos.inputMethod'; 17import commonEventManager from '@ohos.commonEventManager'; 18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'; 19import { PanelInfo, PanelFlag, PanelType } from '@ohos.inputMethod.Panel'; 20 21describe('InputMethodWithAttachTest', function () { 22 const WAIT_DEAL_OK = 500; 23 const TEST_RESULT_CODE = 0; 24 const TEST_FUNCTION = { 25 INSERT_TEXT_SYNC: 0, 26 MOVE_CURSOR_SYNC: 1, 27 GET_ATTRIBUTE_SYNC: 2, 28 SELECT_BY_RANGE_SYNC: 3, 29 SELECT_BY_MOVEMENT_SYNC: 4, 30 GET_INDEX_AT_CURSOR_SYNC: 5, 31 DELETE_FORWARD_SYNC: 6, 32 DELETE_BACKWARD_SYNC: 7, 33 GET_FORWARD_SYNC: 8, 34 GET_BACKWARD_SYNC: 9, 35 CHANGE_FLAG_TO_FIXED: 10, 36 CHANGE_FLAG_TO_FLOATING: 11, 37 SETPRIVACYMODE_WITHOUT_PERMISSION: 12, 38 SETPRIVACYMODE_ERROR_PARAM: 13 39 } 40 41 beforeAll(async function (done) { 42 console.info('beforeAll called'); 43 let inputMethodProperty = { 44 name:'com.example.testIme', 45 id:'InputMethodExtAbility' 46 }; 47 await inputMethod.switchInputMethod(inputMethodProperty); 48 setTimeout(()=>{ 49 done(); 50 }, WAIT_DEAL_OK); 51 }); 52 53 afterAll(async function () { 54 console.info('afterAll called'); 55 let inputMethodSetting = inputMethod.getInputMethodSetting(); 56 let props = await inputMethodSetting.listInputMethod(); 57 let bundleName = 'com.example.newTestIme'; 58 let bundleName1 = 'com.example.testIme'; 59 for(let i = 0;i< props.length; i++) { 60 let prop = props[i]; 61 if(prop.name !== bundleName && prop.name !== bundleName1){ 62 await inputMethod.switchInputMethod(prop); 63 } 64 } 65 }); 66 67 beforeEach(async function () { 68 console.info('beforeEach called'); 69 let inputMethodCtrl = inputMethod.getController(); 70 let cfg = { 71 inputAttribute: 72 { 73 textInputType: inputMethod.TextInputType.TEXT, 74 enterKeyType: inputMethod.EnterKeyType.NONE 75 } 76 }; 77 await inputMethodCtrl.attach(false, cfg); 78 }); 79 80 afterEach(async function () { 81 console.info('afterEach called'); 82 let inputMethodCtrl = inputMethod.getController(); 83 await inputMethodCtrl.detach(); 84 }); 85 86 function publishCommonEvent(codeNumber) { 87 console.info(`[publishCommonEvent] publish event, codeNumber = ${codeNumber}`); 88 commonEventManager.publish('syncTestFunction', { code: codeNumber }, (err)=>{ 89 console.info(`inputMethod publish finish, err = ${JSON.stringify(err)}`); 90 }) 91 } 92 93 function subscribe(subscribeInfo, functionCode, done) { 94 commonEventManager.createSubscriber(subscribeInfo).then((data)=>{ 95 let subscriber = data; 96 commonEventManager.subscribe(subscriber, (err, eventData)=>{ 97 console.info("inputMethod subscribe"); 98 if(eventData.code === TEST_RESULT_CODE) { 99 expect(true).assertTrue(); 100 }else{ 101 expect().assertFail(); 102 } 103 commonEventManager.unsubscribe(subscriber); 104 done(); 105 }) 106 publishCommonEvent(functionCode); 107 }) 108 } 109 /* 110 * @tc.number inputmethod_with_attach_test_showTextInput_001 111 * @tc.name Test whether the keyboard is displayed successfully. 112 * @tc.desc Function test 113 * @tc.level 2 114 */ 115 it('inputmethod_with_attach_test_showTextInput_001', 0, async function (done) { 116 console.info('************* inputmethod_with_attach_test_showTextInput_001 Test start*************'); 117 let inputMethodCtrl = inputMethod.getController(); 118 inputMethodCtrl.showTextInput((err) => { 119 if (err) { 120 console.info(`inputmethod_with_attach_test_showTextInput_001 result: ${JSON.stringify(err)}`); 121 expect().assertFail(); 122 done(); 123 } 124 console.info('inputmethod_with_attach_test_showTextInput_001 callback success'); 125 expect(true).assertTrue(); 126 done(); 127 }); 128 }); 129 130 /* 131 * @tc.number inputmethod_with_attach_test_showTextInput_002 132 * @tc.name Test whether the keyboard is displayed successfully. 133 * @tc.desc Function test 134 * @tc.level 2 135 */ 136 it('inputmethod_with_attach_test_showTextInput_002', 0, async function (done) { 137 console.info('************* inputmethod_with_attach_test_showTextInput_002 Test start*************'); 138 let inputMethodCtrl = inputMethod.getController(); 139 inputMethodCtrl.showTextInput().then(() => { 140 console.info('inputmethod_with_attach_test_showTextInput_002 promise success'); 141 expect(true).assertTrue(); 142 done(); 143 }).catch((error) => { 144 console.info(`inputmethod_with_attach_test_showTextInput_002 result: ${JSON.stringify(error)}`); 145 expect().assertFail(); 146 done(); 147 }); 148 }); 149 150 /* 151 * @tc.number inputmethod_with_attach_test_hideTextInput_001 152 * @tc.name Test whether the keyboard is hide successfully. 153 * @tc.desc Function test 154 * @tc.level 2 155 */ 156 it('inputmethod_with_attach_test_hideTextInput_001', 0, async function (done) { 157 console.info('************* inputmethod_with_attach_test_hideTextInput_001 Test start*************'); 158 let inputMethodCtrl = inputMethod.getController(); 159 inputMethodCtrl.hideTextInput((err) => { 160 if (err) { 161 console.info(`inputmethod_with_attach_test_hideTextInput_001 result: ${JSON.stringify(err)}`); 162 expect().assertFail(); 163 done(); 164 return; 165 } 166 console.info('inputmethod_with_attach_test_hideTextInput_001 callback success'); 167 expect(true).assertTrue(); 168 done(); 169 }); 170 }); 171 172 173 /* 174 * @tc.number inputmethod_with_attach_test_hideTextInput_002 175 * @tc.name Test whether the keyboard is hide successfully. 176 * @tc.desc Function test 177 * @tc.level 2 178 */ 179 it('inputmethod_with_attach_test_hideTextInput_002', 0, async function (done) { 180 console.info('************* inputmethod_with_attach_test_hideTextInput_002 Test start*************'); 181 let inputMethodCtrl = inputMethod.getController(); 182 inputMethodCtrl.hideTextInput().then(() => { 183 console.info('inputmethod_with_attach_test_hideTextInput_002 promise success'); 184 expect(true).assertTrue(); 185 done(); 186 }).catch((error) => { 187 console.info(`inputmethod_with_attach_test_hideTextInput_002 result: ${JSON.stringify(error)}`); 188 expect().assertFail(); 189 done(); 190 }); 191 }); 192 193 /* 194 * @tc.number inputmethod_with_attach_test_setCallingWindow_001 195 * @tc.name Test the window ID of the application that the notification system is currently bound to 196 * the input method. After setting correctly, whether the window where the client is located can avoid 197 * the input method window. 198 * @tc.desc Function test 199 * @tc.level 2 200 */ 201 it('inputmethod_with_attach_test_setCallingWindow_001', 0, async function (done) { 202 console.info('************* inputmethod_with_attach_test_setCallingWindow_001 Test start*************'); 203 try { 204 let inputMethodCtrl = inputMethod.getController(); 205 let windId = 100; 206 inputMethodCtrl.setCallingWindow(windId, (err) => { 207 if (err) { 208 console.info(`inputmethod_with_attach_test_setCallingWindow_001 result: ${JSON.stringify(err)}`); 209 expect().assertFail(); 210 done(); 211 } 212 console.info('inputmethod_with_attach_test_setCallingWindow_001 callback success'); 213 expect(true).assertTrue(); 214 done(); 215 }) 216 } catch (error) { 217 console.info(`inputmethod_with_attach_test_setCallingWindow_001 result: ${JSON.stringify(error)}`); 218 expect().assertFail(); 219 done(); 220 } 221 }); 222 223 /* 224 * @tc.number inputmethod_with_attach_test_setCallingWindow_002 225 * @tc.name Test the window ID of the application that the notification system is currently bound to 226 * the input method. After setting correctly, whether the window where the client is located can avoid 227 * the input method window. 228 * @tc.desc Function test 229 * @tc.level 2 230 */ 231 it('inputmethod_with_attach_test_setCallingWindow_002', 0, async function (done) { 232 console.info('************* inputmethod_with_attach_test_setCallingWindow_002 Test start*************'); 233 try { 234 let inputMethodCtrl = inputMethod.getController(); 235 let windId = 100; 236 inputMethodCtrl.setCallingWindow(windId).then(() => { 237 console.info('inputmethod_with_attach_test_setCallingWindow_002 promise success'); 238 expect(true).assertTrue(); 239 done(); 240 }).catch((error) => { 241 console.info(`inputmethod_with_attach_test_setCallingWindow_002 result: ${JSON.stringify(error)}`); 242 expect().assertFail(); 243 done(); 244 }) 245 } catch (error) { 246 console.info(`inputmethod_with_attach_test_setCallingWindow_002 result: ${JSON.stringify(error)}`); 247 expect().assertFail(); 248 done(); 249 } 250 console.info('************* inputmethod_with_attach_test_setCallingWindow_002 Test end*************'); 251 }); 252 253 /* 254 * @tc.number inputmethod_with_attach_test_updateCursor_001 255 * @tc.name Test whether the notification input method is valid when the current application cursor has changed. 256 * @tc.desc Function test 257 * @tc.level 2 258 */ 259 it('inputmethod_with_attach_test_updateCursor_001', 0, async function (done) { 260 console.info('************* inputmethod_with_attach_test_updateCursor_001 Test start*************'); 261 try { 262 let inputMethodCtrl = inputMethod.getController(); 263 let cursorInfo = { left: 100, top: 110, width: 600, height: 800 }; 264 inputMethodCtrl.updateCursor(cursorInfo, (err) => { 265 if (err) { 266 console.info(`inputmethod_with_attach_test_updateCursor_001 result: ${JSON.stringify(err)}`); 267 expect().assertFail(); 268 done(); 269 return; 270 } 271 console.info('inputmethod_with_attach_test_updateCursor_001 callback success'); 272 expect(true).assertTrue(); 273 done(); 274 }) 275 } catch (error) { 276 console.info(`inputmethod_with_attach_test_updateCursor_001 result: ${JSON.stringify(error)}`); 277 expect().assertFail(); 278 done(); 279 } 280 console.info('************* inputmethod_with_attach_test_updateCursor_001 Test end*************'); 281 }); 282 283 /* 284 * @tc.number inputmethod_with_attach_test_updateCursor_002 285 * @tc.name Test whether the notification input method is valid when the current application cursor has changed. 286 * @tc.desc Function test 287 * @tc.level 2 288 */ 289 it('inputmethod_with_attach_test_updateCursor_002', 0, async function (done) { 290 console.info('************* inputmethod_with_attach_test_updateCursor_002 Test start*************'); 291 try { 292 let inputMethodCtrl = inputMethod.getController(); 293 let cursorInfo = { left: 100, top: 110, width: 600, height: 800 }; 294 inputMethodCtrl.updateCursor(cursorInfo).then(() => { 295 console.info('inputmethod_with_attach_test_updateCursor_002 promise success'); 296 expect(true).assertTrue(); 297 done(); 298 }).catch((error) => { 299 console.info(`inputmethod_with_attach_test_updateCursor_002 result: ${JSON.stringify(error)}`); 300 expect().assertFail(); 301 done(); 302 }) 303 } catch (error) { 304 console.info(`inputmethod_with_attach_test_updateCursor_002 result: ${JSON.stringify(error)}`); 305 expect().assertFail(); 306 done(); 307 } 308 console.info('************* inputmethod_with_attach_test_updateCursor_002 Test end*************'); 309 }); 310 311 /* 312 * @tc.number inputmethod_with_attach_test_changeSelection_001 313 * @tc.name Test whether the selection range of the current application text of the notification input 314 * method has changed. 315 * @tc.desc Function test 316 * @tc.level 2 317 */ 318 it('inputmethod_with_attach_test_changeSelection_001', 0, async function (done) { 319 console.info('************* inputmethod_with_attach_test_changeSelection_001 Test start*************'); 320 try { 321 let inputMethodCtrl = inputMethod.getController(); 322 let text = 'text'; 323 let start = 0; 324 let end = 5; 325 inputMethodCtrl.changeSelection(text, start, end, (err) => { 326 if (err) { 327 console.info(`inputmethod_with_attach_test_changeSelection_001 result: ${JSON.stringify(err)}`); 328 expect().assertFail(); 329 done(); 330 return; 331 } 332 console.info('inputmethod_with_attach_test_changeSelection_001 callback success'); 333 expect(true).assertTrue(); 334 done(); 335 }) 336 } catch (error) { 337 console.info(`inputmethod_with_attach_test_changeSelection_001 result: ${JSON.stringify(error)}`); 338 expect().assertFail(); 339 done(); 340 } 341 console.info('************* inputmethod_with_attach_test_changeSelection_001 Test end*************'); 342 }); 343 344 /* 345 * @tc.number inputmethod_with_attach_test_changeSelection_002 346 * @tc.name Test whether the selection range of the current application text of the notification input 347 * method has changed. 348 * @tc.desc Function test 349 * @tc.level 2 350 */ 351 it('inputmethod_with_attach_test_changeSelection_002', 0, async function (done) { 352 console.info('************* inputmethod_with_attach_test_changeSelection_002 Test start*************'); 353 try { 354 let inputMethodCtrl = inputMethod.getController(); 355 let text = 'text'; 356 let start = 0; 357 let end = 5; 358 inputMethodCtrl.changeSelection(text, start, end).then(() => { 359 console.info('inputmethod_with_attach_test_changeSelection_002 promise success'); 360 expect(true).assertTrue(); 361 done(); 362 }).catch((error) => { 363 console.info(`inputmethod_with_attach_test_changeSelection_002 result: ${JSON.stringify(error)}`); 364 expect().assertFail(); 365 done(); 366 }) 367 } catch (error) { 368 console.info(`inputmethod_with_attach_test_changeSelection_002 result: ${JSON.stringify(error)}`); 369 expect().assertFail(); 370 done(); 371 } 372 console.info('************* inputmethod_with_attach_test_changeSelection_002 Test end*************'); 373 }); 374 375 /* 376 * @tc.number inputmethod_with_attach_test_updateAttribute_001 377 * @tc.name Test whether the InputAttribute information can be updated successfully. 378 * @tc.desc Function test 379 * @tc.level 2 380 */ 381 it('inputmethod_with_attach_test_updateAttribute_001', 0, async function (done) { 382 console.info('************* inputmethod_with_attach_test_updateAttribute_001 Test start*************'); 383 try { 384 let inputMethodCtrl = inputMethod.getController(); 385 let attribute = { textInputType: inputMethod.TextInputType.TEXT, enterKeyType: inputMethod.EnterKeyType.NONE }; 386 inputMethodCtrl.updateAttribute(attribute, (err) => { 387 if (err) { 388 console.info(`inputmethod_with_attach_test_updateAttribute_001 result: ${JSON.stringify(err)}`); 389 expect().assertFail(); 390 done(); 391 return; 392 } 393 console.info('inputmethod_with_attach_test_updateAttribute_001 callback success'); 394 expect(true).assertTrue(); 395 done(); 396 }) 397 } catch (error) { 398 console.info(`inputmethod_with_attach_test_updateAttribute_001 result: ${JSON.stringify(error)}`); 399 expect().assertFail(); 400 done(); 401 } 402 console.info('************* inputmethod_with_attach_test_updateAttribute_001 Test end*************'); 403 }); 404 405 /* 406 * @tc.number inputmethod_with_attach_test_updateAttribute_001 407 * @tc.name Test whether the InputAttribute information can be updated successfully. 408 * @tc.desc Function test 409 * @tc.level 2 410 */ 411 it('inputmethod_with_attach_test_updateAttribute_001', 0, async function (done) { 412 console.info('************* inputmethod_with_attach_test_updateAttribute_001 Test start*************'); 413 try { 414 let inputMethodCtrl = inputMethod.getController(); 415 let attribute = { textInputType: 1, enterKeyType: 1 }; 416 inputMethodCtrl.updateAttribute(attribute).then(() => { 417 console.info('inputmethod_with_attach_test_updateAttribute_001 promise success'); 418 expect(true).assertTrue(); 419 done(); 420 }).catch((error) => { 421 console.info(`inputmethod_with_attach_test_updateAttribute_001 result: ${JSON.stringify(error)}`); 422 expect().assertFail(); 423 done(); 424 }) 425 } catch (error) { 426 console.info(`inputmethod_with_attach_test_updateAttribute_001 result: ${JSON.stringify(error)}`); 427 expect().assertFail(); 428 done(); 429 } 430 console.info('************* inputmethod_with_attach_test_updateAttribute_001 Test end*************'); 431 }); 432 433 /* 434 * @tc.number inputmethod_test_showSoftKeyboard_001 435 * @tc.name Test Indicates the input method which will show softboard with callback. 436 * @tc.desc Function test 437 * @tc.level 2 438 */ 439 it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) { 440 console.info('************* inputmethod_test_showSoftKeyboard_001 Test start*************'); 441 let inputMethodCtrl = inputMethod.getInputMethodController(); 442 inputMethodCtrl.showSoftKeyboard((err)=>{ 443 if (err) { 444 console.info(`inputmethod_test_showSoftKeyboard_001 err, ${JSON.stringify(err.message)}`); 445 expect().assertFail(); 446 done(); 447 } 448 console.info('************* inputmethod_test_showSoftKeyboard_001 Test end*************'); 449 expect(true).assertTrue(); 450 done(); 451 }); 452 }); 453 454 /* 455 * @tc.number inputmethod_test_showSoftKeyboard_002 456 * @tc.name Test Indicates the input method which will show softboard with callback. 457 * @tc.desc Function test 458 * @tc.level 2 459 */ 460 it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) { 461 console.info('************* inputmethod_test_showSoftKeyboard_002 Test start*************'); 462 let inputMethodCtrl = inputMethod.getInputMethodController(); 463 inputMethodCtrl.showSoftKeyboard().then(()=>{ 464 console.info('inputmethod_test_showSoftKeyboard_002 success.'); 465 expect(true).assertTrue(); 466 done(); 467 }).catch((err) => { 468 console.info(`inputmethod_test_showSoftKeyboard_002 err, ${JSON.stringify(err.message)}`); 469 expect().assertFail(); 470 done(); 471 }); 472 }); 473 474 /* 475 * @tc.number inputmethod_test_hideSoftKeyboard_001 476 * @tc.name Test Indicates the input method which will hide softboard with callback. 477 * @tc.desc Function test 478 * @tc.level 2 479 */ 480 it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) { 481 console.info('************* inputmethod_test_hideSoftKeyboard_001 Test start*************'); 482 let inputMethodCtrl = inputMethod.getInputMethodController(); 483 inputMethodCtrl.hideSoftKeyboard((err)=>{ 484 if(err){ 485 console.info(`inputmethod_test_hideSoftKeyboard_001 err, ${JSON.stringify(err.message)}`); 486 expect().assertFail(); 487 done(); 488 } 489 console.info('************* inputmethod_test_hideSoftKeyboard_001 Test end*************'); 490 expect(true).assertTrue(); 491 done(); 492 }); 493 }); 494 495 /* 496 * @tc.number inputmethod_test_hideSoftKeyboard_001 497 * @tc.name Test Indicates the input method which will hide softboard with callback. 498 * @tc.desc Function test 499 * @tc.level 2 500 */ 501 it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) { 502 console.info('************* inputmethod_test_hideSoftKeyboard_002 Test start*************'); 503 let inputMethodCtrl = inputMethod.getInputMethodController(); 504 inputMethodCtrl.hideSoftKeyboard().then(()=>{ 505 console.info('inputmethod_test_hideSoftKeyboard_002 success.'); 506 expect(true).assertTrue(); 507 done(); 508 }).catch((err) => { 509 console.info(`inputmethod_test_hideSoftKeyboard_002 err, ${JSON.stringify(err.message)}`); 510 expect().assertFail(); 511 done(); 512 }); 513 }); 514 515 /* 516 * @tc.number inputmethod_test_stopInputSessionWithAttach_001 517 * @tc.name Test Indicates the input method which will hides the keyboard. 518 * @tc.desc Function test 519 * @tc.level 2 520 */ 521 it('inputmethod_test_stopInputSessionWithAttach_001', 0, function (done) { 522 console.info('************* inputmethod_test_stopInputSessionWithAttach_001 Test start*************'); 523 let inputMethodCtrl = inputMethod.getController(); 524 inputMethodCtrl.stopInputSession((err, ret) => { 525 if (err) { 526 console.info(`inputmethod_test_stopInputSessionWithAttach_001 err, ${JSON.stringify(err.message)}`); 527 expect().assertFail(); 528 done(); 529 return; 530 } 531 expect(ret).assertTrue(); 532 console.info('************* inputmethod_test_stopInputSessionWithAttach_001 Test end*************'); 533 done(); 534 }); 535 }); 536 537 /* 538 * @tc.number inputmethod_test_stopInputSessionWithAttach_002 539 * @tc.name Test Indicates the input method which will hides the keyboard. 540 * @tc.desc Function test 541 * @tc.level 2 542 */ 543 it('inputmethod_test_stopInputSessionWithAttach_002', 0, function (done) { 544 console.info('************* inputmethod_test_stopInputSessionWithAttach_002 Test start*************'); 545 let inputMethodCtrl = inputMethod.getController(); 546 inputMethodCtrl.hideSoftKeyboard().then((result)=>{ 547 if (result) { 548 console.info('inputmethod_test_stopInputSessionWithAttach_002 failed.'); 549 expect().assertFail(); 550 done(); 551 } 552 console.info('inputmethod_test_stopInputSessionWithAttach_002 success.'); 553 expect(true).assertTrue(); 554 done(); 555 }).catch((err) => { 556 console.info(`inputmethod_test_stopInputSessionWithAttach_002 err, ${JSON.stringify(err.message)}`); 557 expect().assertFail(); 558 done(); 559 }); 560 }); 561 562 /* 563 * @tc.number inputmethod_with_attach_test_on_000 564 * @tc.name Test whether the register the callback of the input method is valid. 565 * @tc.desc Function test 566 * @tc.level 2 567 */ 568 it('inputmethod_with_attach_test_on_000', 0, async function (done) { 569 let inputMethodCtrl = inputMethod.getController(); 570 try { 571 inputMethodCtrl.on('insertText', (text) => { 572 console.info(`inputMethod insertText success, text: ${JSON.stringify(text)}`); 573 }); 574 inputMethodCtrl.on('deleteLeft', (length) => { 575 console.info(`inputMethod deleteLeft success, length: ${JSON.stringify(length)}`); 576 }); 577 inputMethodCtrl.on('deleteRight', (length) => { 578 console.info(`inputMethod deleteRight success, length: ${JSON.stringify(length)}`); 579 }); 580 inputMethodCtrl.on('sendKeyboardStatus', (keyBoardStatus) => { 581 console.info(`inputMethod sendKeyboardStatus success, keyBoardStatus: ${JSON.stringify(keyBoardStatus)}`); 582 }); 583 inputMethodCtrl.on('sendFunctionKey', (functionKey) => { 584 console.info(`inputMethod sendFunctionKey success, 585 functionKey.enterKeyType: ${JSON.stringify(functionKey.enterKeyType)}`); 586 }); 587 inputMethodCtrl.on('moveCursor', (direction) => { 588 console.info(`inputMethod moveCursor success, direction: ${JSON.stringify(direction)}`); 589 }); 590 inputMethodCtrl.on('handleExtendAction', (action) => { 591 console.info(`inputMethod handleExtendAction success, action: ${JSON.stringify(action)}`); 592 }); 593 expect(true).assertTrue(); 594 done(); 595 } catch(error) { 596 console.info(`inputmethod_with_attach_test_on_000 result: ${JSON.stringify(error)}`); 597 expect().assertFail(); 598 done(); 599 } 600 }); 601 602 /* 603 * @tc.number inputmethod_test_insertTextSync_001 604 * @tc.name Test Indicates the input method which will replace the current one. 605 * @tc.desc Function test 606 * @tc.level 2 607 */ 608 it('inputmethod_test_insertTextSync_001', 0, async function (done) { 609 console.info('************* inputmethod_test_insertTextSync_001 Test start*************'); 610 let inputMethodCtrl = inputMethod.getController(); 611 await inputMethodCtrl.showSoftKeyboard(); 612 try { 613 inputMethodCtrl.on('insertText', (text) => { 614 console.info(`inputMethod insertText success, text: ${JSON.stringify(text)}`); 615 expect(true).assertTrue(); 616 done(); 617 }); 618 publishCommonEvent(TEST_FUNCTION.INSERT_TEXT_SYNC); 619 } catch(error) { 620 console.info(`inputmethod_test_insertTextSync result: ${JSON.stringify(error)}`); 621 expect().assertFail(); 622 done(); 623 } 624 }); 625 626 /* 627 * @tc.number inputmethod_test_moveCursorSync_001 628 * @tc.name Test Indicates the input method which will replace the current one. 629 * @tc.desc Function test 630 * @tc.level 2 631 */ 632 it('inputmethod_test_moveCursorSync_001', 0, async function (done) { 633 console.info('************* inputmethod_test_moveCursorSync_001 Test start*************'); 634 let inputMethodCtrl = inputMethod.getController(); 635 await inputMethodCtrl.showSoftKeyboard(); 636 try { 637 inputMethodCtrl.on('moveCursor', (direction) => { 638 console.info(`inputMethod moveCursor success, direction: ${direction}`); 639 expect(true).assertTrue(); 640 done(); 641 }); 642 publishCommonEvent(TEST_FUNCTION.MOVE_CURSOR_SYNC); 643 } catch(error) { 644 console.info(`inputmethod_text_moveCursorSync result: ${JSON.stringify(error)}`); 645 expect().assertFail(); 646 done(); 647 } 648 }); 649 650 /* 651 * @tc.number inputmethod_test_getEditorAttributeSync_001 652 * @tc.name Test Indicates the input method which will replace the current one. 653 * @tc.desc Function test 654 * @tc.level 2 655 */ 656 it('inputmethod_test_getEditorAttributeSync_001', 0, async function (done) { 657 console.info('************* inputmethod_test_getEditorAttributeSync_001 Test start*************'); 658 let inputMethodCtrl = inputMethod.getController(); 659 await inputMethodCtrl.showSoftKeyboard(); 660 try { 661 let subscribeInfo = { 662 events: ['getEditorAttributeSyncResult'] 663 }; 664 subscribe(subscribeInfo, TEST_FUNCTION.GET_ATTRIBUTE_SYNC, done); 665 } catch(error) { 666 console.info(`inputmethod_test_getEditorAttributeSync_001 result: ${JSON.stringify(error)}`); 667 expect().assertFail(); 668 done(); 669 } 670 }); 671 672 /* 673 * @tc.number inputmethod_test_SelectByRangeSync_001 674 * @tc.name Test Indicates the input method which will replace the current one. 675 * @tc.desc Function test 676 * @tc.level 2 677 */ 678 it('inputmethod_test_selectByRangeSync_001', 0, async function (done) { 679 console.info('************* inputmethod_test_selectByRangeSync_001 Test start*************'); 680 let inputMethodCtrl = inputMethod.getController(); 681 await inputMethodCtrl.showSoftKeyboard(); 682 try { 683 inputMethodCtrl.on('selectByRange', (range) => { 684 console.info(`inputMethod selectByRangeSync success, direction: ${range}`); 685 expect(true).assertTrue(); 686 done(); 687 }); 688 publishCommonEvent(TEST_FUNCTION.SELECT_BY_RANGE_SYNC); 689 } catch(error) { 690 console.info(`inputmethod_text_selectByRangeSync result: ${JSON.stringify(error)}`); 691 expect().assertFail(); 692 done(); 693 } 694 }); 695 696 /* 697 * @tc.number inputmethod_test_selectByMovementSync_001 698 * @tc.name Test Indicates the input method which will replace the current one. 699 * @tc.desc Function test 700 * @tc.level 2 701 */ 702 it('inputmethod_test_selectByMovementSync_001', 0, async function (done) { 703 console.info('************* inputmethod_test_selectByMovementSync_001 Test start*************'); 704 let inputMethodCtrl = inputMethod.getController(); 705 await inputMethodCtrl.showSoftKeyboard(); 706 try { 707 inputMethodCtrl.on('selectByMovement', (movement) => { 708 console.info(`inputMethod selectByMovementSync success, movement: ${movement}`); 709 expect(true).assertTrue(); 710 done(); 711 }); 712 publishCommonEvent(TEST_FUNCTION.SELECT_BY_MOVEMENT_SYNC); 713 } catch(error) { 714 console.info(`inputmethod_text_selectByMovementSync result: ${JSON.stringify(error)}`); 715 expect().assertFail(); 716 done(); 717 } 718 }); 719 720 /* 721 * @tc.number inputmethod_test_selectByMovementSync_001 722 * @tc.name Test Indicates the input method which will replace the current one. 723 * @tc.desc Function test 724 * @tc.level 2 725 */ 726 it('inputmethod_test_getTextIndexAtCursorSync_001', 0, async function (done) { 727 console.info('************* inputmethod_test_getTextIndexAtCursorSync_001 Test start*************'); 728 let inputMethodCtrl = inputMethod.getController(); 729 await inputMethodCtrl.showSoftKeyboard(); 730 try { 731 inputMethodCtrl.on('getTextIndexAtCursor', () => { 732 console.info(`inputMethod getTextIndexAtCursor success`); 733 return 2; 734 }); 735 let subscribeInfo = { 736 events: ['getTextIndexAtCursorSyncResult'] 737 }; 738 subscribe(subscribeInfo, TEST_FUNCTION.GET_INDEX_AT_CURSOR_SYNC, done); 739 } catch(error) { 740 console.info(`inputmethod_test_getTextIndexAtCursorSync_001 result: ${JSON.stringify(error)}`); 741 expect().assertFail(); 742 done(); 743 } 744 }); 745 746 /* 747 * @tc.number inputmethod_test_deleteForwardSync_001 748 * @tc.name Test Indicates the input method which will replace the current one. 749 * @tc.desc Function test 750 * @tc.level 2 751 */ 752 it('inputmethod_test_deleteForwardSync_001', 0, async function (done) { 753 console.info('************* inputmethod_test_deleteForwardSync_001 Test start*************'); 754 let inputMethodCtrl = inputMethod.getController(); 755 await inputMethodCtrl.showSoftKeyboard(); 756 try { 757 inputMethodCtrl.on('deleteLeft', (length) => { 758 console.info(`inputMethod deleteForwardSync success, length: ${length}`); 759 expect(true).assertTrue(); 760 done(); 761 }); 762 publishCommonEvent(TEST_FUNCTION.DELETE_FORWARD_SYNC); 763 } catch(error) { 764 console.info(`inputmethod_text_deleteForwardSync result: ${JSON.stringify(error)}`); 765 expect().assertFail(); 766 done(); 767 } 768 }); 769 770 /* 771 * @tc.number inputmethod_test_deleteBackwardSync_001 772 * @tc.name Test Indicates the input method which will replace the current one. 773 * @tc.desc Function test 774 * @tc.level 2 775 */ 776 it('inputmethod_test_deleteBackwardSync_001', 0, async function (done) { 777 console.info('************* inputmethod_test_deleteBackwardSync_001 Test start*************'); 778 let inputMethodCtrl = inputMethod.getController(); 779 await inputMethodCtrl.showSoftKeyboard(); 780 try { 781 inputMethodCtrl.on('deleteRight', (length) => { 782 console.info(`inputMethod deleteBackwardSync success, length: ${length}`); 783 expect(true).assertTrue(); 784 done(); 785 }); 786 publishCommonEvent(TEST_FUNCTION.DELETE_BACKWARD_SYNC); 787 } catch(error) { 788 console.info(`inputmethod_text_deleteBackwardSync result: ${JSON.stringify(error)}`); 789 expect().assertFail(); 790 done(); 791 } 792 }); 793 794 /* 795 * @tc.number inputmethod_test_getForwardSync_001 796 * @tc.name Test Indicates the input method which will replace the current one. 797 * @tc.desc Function test 798 * @tc.level 2 799 */ 800 it('inputmethod_test_getForwardSync_001', 0, async function (done) { 801 console.info('************* inputmethod_test_getForwardSync_001 Test start*************'); 802 let inputMethodCtrl = inputMethod.getController(); 803 await inputMethodCtrl.showSoftKeyboard(); 804 try { 805 inputMethodCtrl.on('getLeftTextOfCursor', (length) => { 806 console.info(`inputMethod getForwardSync success, length: ${length}`); 807 return 'getLeftTextOfCursor'; 808 }); 809 let subscribeInfo = { 810 events: ['getForwardSyncResult'] 811 }; 812 subscribe(subscribeInfo, TEST_FUNCTION.GET_FORWARD_SYNC, done); 813 } catch(error) { 814 console.info(`inputmethod_text_getForwardSync result: ${JSON.stringify(error)}`); 815 expect().assertFail(); 816 done(); 817 } 818 }); 819 /* 820 * @tc.number inputmethod_test_getBackwardSync_001 821 * @tc.name Test Indicates the input method which will replace the current one. 822 * @tc.desc Function test 823 * @tc.level 2 824 */ 825 it('inputmethod_test_getBackwardSync_001', 0, async function (done) { 826 console.info('************* inputmethod_test_getBackwardSync_001 Test start*************'); 827 let inputMethodCtrl = inputMethod.getController(); 828 await inputMethodCtrl.showSoftKeyboard(); 829 try { 830 inputMethodCtrl.on('getRightTextOfCursor', (length) => { 831 console.info(`inputMethod getBackwardSync success, length: ${length}`); 832 return 'getRightTextOfCursor'; 833 }); 834 let subscribeInfo = { 835 events: ['getBackwardSyncResult'] 836 }; 837 subscribe(subscribeInfo, TEST_FUNCTION.GET_BACKWARD_SYNC, done); 838 } catch(error) { 839 console.info(`inputmethod_text_getBackwardSync result: ${JSON.stringify(error)}`); 840 expect().assertFail(); 841 done(); 842 } 843 }); 844 845 /* 846 * @tc.number inputmethod_test_isPanelShown_001 847 * @tc.name Test Indicates querying by isPanelShown. 848 * @tc.desc Function test 849 * @tc.level 2 850 */ 851 it('inputmethod_test_isPanelShown_001', 0, async function (done) { 852 console.info('************* inputmethod_test_isPanelShown_001 Test start*************'); 853 try { 854 let cfg = { 855 inputAttribute: 856 { 857 textInputType: inputMethod.TextInputType.TEXT, 858 enterKeyType: inputMethod.EnterKeyType.NONE 859 } 860 }; 861 await inputMethod.getController().attach(true, cfg); 862 setTimeout(()=>{ 863 let result = inputMethod.getSetting().isPanelShown({type: PanelType.SOFT_KEYBOARD}); 864 if (result) { 865 expect(true).assertTrue(); 866 } else { 867 expect().assertFail(); 868 } 869 done(); 870 }, WAIT_DEAL_OK); 871 } catch (error) { 872 console.info(`inputmethod_test_isPanelShown_001 result: ${JSON.stringify(error)}`); 873 expect().assertFail(); 874 done(); 875 } 876 }); 877 878 /* 879 * @tc.number inputmethod_test_isPanelShown_002 880 * @tc.name Test Indicates querying by isPanelShown. 881 * @tc.desc Function test 882 * @tc.level 2 883 */ 884 it('inputmethod_test_isPanelShown_002', 0, async function (done) { 885 console.info('************* inputmethod_test_isPanelShown_002 Test start*************'); 886 try { 887 let subscribeInfo = { 888 events: ['changeFlag'] 889 }; 890 subscribe(subscribeInfo, TEST_FUNCTION.CHANGE_FLAG_TO_FLOATING, () => { 891 let result = inputMethod.getSetting().isPanelShown({ 892 type: PanelType.SOFT_KEYBOARD, 893 flag: PanelFlag.FLAG_FLOATING 894 }); 895 if (result) { 896 expect(true).assertTrue(); 897 } else { 898 expect().assertFail(); 899 } 900 subscribe(subscribeInfo, TEST_FUNCTION.CHANGE_FLAG_TO_FIXED, done); 901 }); 902 } catch (error) { 903 console.info(`inputmethod_test_isPanelShown_002 result: ${JSON.stringify(error)}`); 904 expect().assertFail(); 905 done(); 906 } 907 }); 908 909 /* 910 * @tc.number inputmethod_test_setPrivacyModeWithoutPermission_001 911 * @tc.name Test Indicates set panel privacy mode without permission. 912 * @tc.desc Function test 913 * @tc.level 2 914 */ 915 it('inputmethod_test_setPrivacyModeWithoutPermission_001', 0, async function (done) { 916 console.info('************* inputmethod_test_setPrivacyModeWithoutPermission_001 Test start*************'); 917 try { 918 let subscribeInfo = { 919 events: ['setPrivacyModeWithoutPermissionResult'] 920 }; 921 subscribe(subscribeInfo, TEST_FUNCTION.SETPRIVACYMODE_WITHOUT_PERMISSION, done); 922 } catch(error) { 923 console.info(`inputmethod_test_setPrivacyModeWithoutPermission_001 result: ${JSON.stringify(error)}`); 924 expect().assertFail(); 925 done(); 926 } 927 }); 928 929 /* 930 * @tc.number inputmethod_test_setPrivacyModeErrorParam_001 931 * @tc.name Test Indicates set panel privacy mode with undefined param. 932 * @tc.desc Function test 933 * @tc.level 2 934 */ 935 it('inputmethod_test_setPrivacyModeErrorParam_001', 0, async function (done) { 936 console.info('************* inputmethod_test_setPrivacyModeErrorParam_001 Test start*************'); 937 try { 938 let subscribeInfo = { 939 events: ['setPrivacyModeErrorParamResult'] 940 }; 941 subscribe(subscribeInfo, TEST_FUNCTION.SETPRIVACYMODE_ERROR_PARAM, done); 942 } catch(error) { 943 console.info(`inputmethod_test_setPrivacyModeErrorParam_001 result: ${JSON.stringify(error)}`); 944 expect().assertFail(); 945 done(); 946 } 947 }); 948});