1/* 2 * Copyright (C) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 18 19describe('InputMethodTest', function () { 20 beforeAll(function () { 21 console.info('beforeAll called'); 22 propertyBeforeSwitch = inputMethod.getCurrentInputMethod(); 23 }); 24 25 afterAll(function () { 26 console.info('afterAll called'); 27 }); 28 29 beforeEach(function () { 30 console.info('beforeEach called'); 31 }); 32 33 afterEach(function () { 34 console.info('afterEach called'); 35 }); 36 let propertyBeforeSwitch = undefined; 37 let bundleName = 'com.example.newTestIme'; 38 let extName = 'InputMethodExtAbility'; 39 let subName = ['lowerInput', 'upperInput', 'chineseInput']; 40 let locale = ['en-US', 'en-US', 'zh-CN']; 41 let language = ['english', 'english', 'chinese']; 42 let bundleName1 = 'com.example.testIme'; 43 let extName1 = ['InputMethodExtAbility', 'InputMethodExtAbility2']; 44 let locale1 = ['zh-CN', 'en-US']; 45 let language1 = ['chinese', 'english']; 46 const LEAST_ALL_IME_NUM = 2; 47 const ENABLE_IME_NUM = 3; 48 const LEAST_DISABLE_IME_NUM = 1; 49 const NEW_IME_SUBTYPE_NUM = 3; 50 const OLD_IME_SUBTYPE_NUM = 2; 51 const WAIT_DEAL_OK = 500; 52 const DISABLED_IME_COUNT = 0; 53 54 function checkNewImeCurrentProp(property) 55 { 56 expect(property.name).assertEqual(bundleName); 57 expect(property.id).assertEqual(extName); 58 expect(property.packageName).assertEqual(bundleName); 59 expect(property.methodId).assertEqual(extName); 60 } 61 62 function checkNewImeCurrentSubProp(subProp, index) 63 { 64 expect(subProp.name).assertEqual(bundleName); 65 expect(subProp.id).assertEqual(subName[index]); 66 expect(subProp.locale).assertEqual(locale[index]); 67 expect(subProp.language).assertEqual(language[index]); 68 } 69 70 function checkNewImeSubProps(subProps) 71 { 72 expect(subProps.length).assertEqual(NEW_IME_SUBTYPE_NUM); 73 for (let i = 0; i < subProps.length; i++) { 74 expect(subProps[i].name).assertEqual(bundleName); 75 expect(subProps[i].id).assertEqual(subName[i]); 76 expect(subProps[i].locale).assertEqual(locale[i]); 77 expect(subProps[i].language).assertEqual(language[i]); 78 } 79 } 80 81 function checkImeCurrentProp(property, index) 82 { 83 expect(property.name).assertEqual(bundleName1); 84 expect(property.id).assertEqual(extName1[index]); 85 expect(property.packageName).assertEqual(bundleName1); 86 expect(property.methodId).assertEqual(extName1[index]); 87 } 88 89 function checkImeCurrentSubProp(subProp, index) 90 { 91 expect(subProp.name).assertEqual(bundleName1); 92 expect(subProp.id).assertEqual(extName1[index]); 93 expect(subProp.locale).assertEqual(locale1[index]); 94 expect(subProp.language).assertEqual(language1[index]); 95 } 96 97 function checkImeSubProps(subProps) 98 { 99 expect(subProps.length).assertEqual(OLD_IME_SUBTYPE_NUM); 100 for (let i = 0; i < subProps.length; i++) { 101 expect(subProps[i].name).assertEqual(bundleName1); 102 expect(subProps[i].id).assertEqual(extName1[i]); 103 expect(subProps[i].locale).assertEqual(locale1[i]); 104 expect(subProps[i].language).assertEqual(language1[i]); 105 } 106 } 107 108 function wait(delay) { 109 let start = new Date().getTime(); 110 while (new Date().getTime() - start < delay){ 111 } 112 } 113 114 /* 115 * @tc.number inputmethod_test_MAX_TYPE_NUM_001 116 * @tc.name Test MAX_TYPE_NUM. 117 * @tc.desc Function test 118 * @tc.level 2 119 */ 120 it('inputmethod_test_MAX_TYPE_NUM_001', 0, async function (done) { 121 console.info('************* inputmethod_test_MAX_TYPE_NUM_001 Test start*************'); 122 let MAX_NUM = 128; 123 let num = inputMethod.MAX_TYPE_NUM; 124 console.info(`inputmethod_test_001 result: ${ num }`); 125 expect(num).assertEqual(MAX_NUM); 126 done(); 127 }); 128 129 /* 130 * @tc.number inputmethod_test_getInputMethodController_001 131 * @tc.name Test to get an InputMethodController instance. 132 * @tc.desc Function test 133 * @tc.level 2 134 */ 135 it('inputmethod_test_getInputMethodController_001', 0, async function (done) { 136 console.info('************* inputmethod_test_getInputMethodController_001 Test start*************'); 137 let controller = inputMethod.getInputMethodController(); 138 expect(controller !== undefined).assertTrue(); 139 console.info('************* inputmethod_test_getInputMethodController_001 Test end*************'); 140 done(); 141 }); 142 143 /* 144 * @tc.number inputmethod_test_getController_001 145 * @tc.name Test to get an InputMethodController instance. 146 * @tc.desc Function test 147 * @tc.level 2 148 */ 149 it('inputmethod_test_getController_001', 0, async function (done) { 150 console.info('************* inputmethod_test_getController_001 Test start*************'); 151 let controller = inputMethod.getController(); 152 expect(controller !== undefined).assertTrue(); 153 console.info('************* inputmethod_test_getController_001 Test end*************'); 154 done(); 155 }); 156 157 /* 158 * @tc.number inputmethod_test_getInputMethodSetting_001 159 * @tc.name Test to get an InputMethodSetting instance. 160 * @tc.desc Function test 161 * @tc.level 2 162 */ 163 it('inputmethod_test_getInputMethodSetting_001', 0, async function (done) { 164 console.info('************* inputmethod_test_getInputMethodSetting_001 Test start*************'); 165 let setting = inputMethod.getInputMethodSetting(); 166 expect(setting !== undefined).assertTrue(); 167 console.info('************* inputmethod_test_getInputMethodSetting_001 Test end*************'); 168 done(); 169 }); 170 171 /* 172 * @tc.number inputmethod_test_getInputMethodSetting_001 173 * @tc.name Test to get an InputMethodSetting instance. 174 * @tc.desc Function test 175 * @tc.level 2 176 */ 177 it('inputmethod_test_getSetting_001', 0, async function (done) { 178 console.info('************* inputmethod_test_getSetting_001 Test start*************'); 179 let setting = inputMethod.getSetting(); 180 expect(setting !== undefined).assertTrue(); 181 console.info('************* inputmethod_test_getSetting_001 Test end*************'); 182 done(); 183 }); 184 185 /* 186 * @tc.number inputmethod_test_switchInputMethod_001 187 * @tc.name Test Indicates the input method which will replace the current one. 188 * @tc.desc Function test 189 * @tc.level 2 190 */ 191 it('inputmethod_test_switchInputMethod_001', 0, async function (done) { 192 console.info('************* inputmethod_test_switchInputMethod_001 Test start*************'); 193 let inputMethodProperty = { 194 name:bundleName, 195 id:extName 196 }; 197 inputMethod.switchInputMethod(inputMethodProperty).then(ret => { 198 expect(ret).assertTrue(); 199 let property = inputMethod.getCurrentInputMethod(); 200 checkNewImeCurrentProp(property); 201 console.info('************* inputmethod_test_switchInputMethod_001 Test end*************'); 202 wait(WAIT_DEAL_OK); 203 expect(true).assertTrue(); 204 done(); 205 }).catch( err=> { 206 console.info(`inputmethod_test_switchInputMethod_001 err: ${JSON.stringify(err.message)}`); 207 expect().assertFail(); 208 }) 209 }); 210 211 /* 212 * @tc.number inputmethod_test_listCurrentInputMethodSubtype_001 213 * @tc.name Test list current input method subtypes. 214 * @tc.desc Function test 215 * @tc.level 2 216 */ 217 it('inputmethod_test_listCurrentInputMethodSubtype_001', 0, async function (done) { 218 console.info('************* inputmethod_test_listCurrentInputMethodSubtype_001 Test start*************'); 219 let inputMethodSetting = inputMethod.getSetting(); 220 inputMethodSetting.listCurrentInputMethodSubtype((err, subProps) => { 221 if (err) { 222 console.error(`inputmethod_test_listCurrentInputMethodSubtype_001 err: ${ err }`); 223 expect().assertFail(); 224 done(); 225 return; 226 } 227 checkNewImeSubProps(subProps); 228 console.info('************* inputmethod_test_listCurrentInputMethodSubtype_001 Test end*************'); 229 expect(true).assertTrue(); 230 done(); 231 }); 232 }); 233 234 /* 235 * @tc.number inputmethod_test_listCurrentInputMethodSubtype_002 236 * @tc.name Test list current input method subtypes. 237 * @tc.desc Function test 238 * @tc.level 2 239 */ 240 it('inputmethod_test_listCurrentInputMethodSubtype_002', 0, async function (done) { 241 console.info('************* inputmethod_test_listCurrentInputMethodSubtype_002 Test start*************'); 242 let inputMethodSetting = inputMethod.getSetting(); 243 inputMethodSetting.listCurrentInputMethodSubtype().then((subProps)=>{ 244 checkNewImeSubProps(subProps); 245 console.info('************* inputmethod_test_listCurrentInputMethodSubtype_002 Test end*************'); 246 expect(true).assertTrue(); 247 done(); 248 }).catch((err) => { 249 console.info(`inputmethod_test_listCurrentInputMethodSubtype_002 err: ${JSON.stringify(err.message)}`); 250 expect().assertFail(); 251 done(); 252 }); 253 }); 254 255 /* 256 * @tc.number inputmethod_test_listInputMethod_001 257 * @tc.name Test list input methods. 258 * @tc.desc Function test 259 * @tc.level 2 260 */ 261 it('inputmethod_test_listInputMethod_001', 0, async function (done) { 262 console.info('************* inputmethod_test_listInputMethod_001 Test start*************'); 263 let inputMethodSetting = inputMethod.getInputMethodSetting(); 264 inputMethodSetting.listInputMethod((err, props) => { 265 if (err) { 266 console.error(`inputmethod_test_listInputMethod_001 err: ${ JSON.stringify(err.message) }`); 267 expect().assertFail(); 268 done(); 269 return; 270 } 271 expect(props.length >= LEAST_ALL_IME_NUM).assertTrue(); 272 let imeProp = props.find(function (prop) {return prop.name === bundleName && prop.id === extName;}); 273 expect(imeProp != undefined).assertTrue(); 274 let imeProp1 = props.find(function (prop) {return prop.name === bundleName1;}); 275 expect(imeProp1 != undefined).assertTrue(); 276 console.info('************* inputmethod_test_listInputMethod_001 Test end*************'); 277 done(); 278 }); 279 }); 280 281 /* 282 * @tc.number inputmethod_test_listInputMethod_002 283 * @tc.name Test list input methods. 284 * @tc.desc Function test 285 * @tc.level 2 286 */ 287 it('inputmethod_test_listInputMethod_002', 0, async function (done) { 288 console.info('************* inputmethod_test_listInputMethod_002 Test start*************'); 289 let inputMethodSetting = inputMethod.getInputMethodSetting(); 290 await inputMethodSetting.listInputMethod().then((props) => { 291 expect(props.length >= LEAST_ALL_IME_NUM).assertTrue(); 292 let imeProp = props.find(function (prop) {return prop.name === bundleName && prop.id === extName;}); 293 expect(imeProp != undefined).assertTrue(); 294 let imeProp1 = props.find(function (prop) {return prop.name === bundleName1;}); 295 expect(imeProp1 != undefined).assertTrue(); 296 console.info('************* inputmethod_test_listInputMethod_002 Test end*************'); 297 done(); 298 }).catch((err) => { 299 console.info(`inputmethod_test_listInputMethod_002 err, ${JSON.stringify(err.message)} `); 300 expect().assertFail(); 301 done(); 302 }); 303 }); 304 305 /* 306 * @tc.number inputmethod_test_getInputMethods_001 307 * @tc.name Test get enable input methods. 308 * @tc.desc Function test 309 * @tc.level 2 310 */ 311 it('inputmethod_test_getInputMethods_001', 0, async function (done) { 312 console.info('************* inputmethod_test_getInputMethods_001 Test start*************'); 313 let inputMethodSetting = inputMethod.getInputMethodSetting(); 314 await inputMethodSetting.getInputMethods(true).then((props)=>{ 315 expect(props.length).assertEqual(ENABLE_IME_NUM); 316 let imeProp = props.find(function (prop) {return prop.name === bundleName;}); 317 expect(imeProp != undefined).assertTrue(); 318 console.info('************* inputmethod_test_getInputMethods_001 Test end*************'); 319 done(); 320 }).catch((err) => { 321 console.info(`inputmethod_test_getInputMethods_001 err, ${JSON.stringify(err.message)} `); 322 expect().assertFail(); 323 done(); 324 }); 325 }); 326 327 /* 328 * @tc.number inputmethod_test_getInputMethods_002 329 * @tc.name Test get enable input methods. 330 * @tc.desc Function test 331 * @tc.level 2 332 */ 333 it('inputmethod_test_getInputMethods_002', 0, async function (done) { 334 console.info('************* inputmethod_test_getInputMethods_002 Test start*************'); 335 let inputMethodSetting = inputMethod.getInputMethodSetting(); 336 inputMethodSetting.getInputMethods(true, (err, props) => { 337 if (err) { 338 console.error(`inputmethod_test_getInputMethods_002 err: ${JSON.stringify(err.message)}`); 339 expect().assertFail(); 340 done(); 341 return; 342 } 343 let imeProp = props.find(function (prop) {return prop.name === bundleName;}); 344 expect(imeProp != undefined).assertTrue(); 345 console.info('************* inputmethod_test_getInputMethods_002 Test end*************'); 346 done(); 347 }); 348 }); 349 350 /* 351 * @tc.number inputmethod_test_getInputMethods_003 352 * @tc.name Test get disable input methods. 353 * @tc.desc Function test 354 * @tc.level 2 355 */ 356 it('inputmethod_test_getInputMethods_003', 0, async function (done) { 357 console.info('************* inputmethod_test_getInputMethods_003 Test start*************'); 358 let inputMethodSetting = inputMethod.getInputMethodSetting(); 359 await inputMethodSetting.getInputMethods(false).then((props)=>{ 360 expect(props.length >= DISABLED_IME_COUNT).assertTrue(); 361 let imeProp = props.find(function (prop) {return prop.name === bundleName1;}); 362 expect(imeProp == undefined).assertTrue(); 363 console.info('************* inputmethod_test_getInputMethods_003 Test end*************'); 364 done(); 365 }).catch((err) => { 366 console.info(`inputmethod_test_getInputMethods_003 err, ${JSON.stringify(err.message)}`); 367 expect().assertFail(); 368 done(); 369 }); 370 }); 371 372 /* 373 * @tc.number inputmethod_test_getInputMethods_004 374 * @tc.name Test get disable input methods. 375 * @tc.desc Function test 376 * @tc.level 2 377 */ 378 it('inputmethod_test_getInputMethods_004', 0, async function (done) { 379 console.info('************* inputmethod_test_getInputMethods_004 Test start*************'); 380 let inputMethodSetting = inputMethod.getInputMethodSetting(); 381 inputMethodSetting.getInputMethods(false, (err, props) => { 382 if (err) { 383 console.error(`inputmethod_test_getInputMethods_004 err, ${JSON.stringify(err.message)}`); 384 expect().assertFail(); 385 done(); 386 return; 387 } 388 expect(props.length >= DISABLED_IME_COUNT).assertTrue(); 389 let imeProp = props.find(function (prop) {return prop.name === bundleName1;}); 390 expect(imeProp == undefined).assertTrue(); 391 console.info('************* inputmethod_test_getInputMethods_004 Test end*************'); 392 done(); 393 }); 394 }); 395 396 /* 397 * @tc.number inputmethod_test_switchCurrentInputMethodSubtype_001 398 * @tc.name Test Indicates the input method subtype which will replace the current one. 399 * @tc.desc Function test 400 * @tc.level 2 401 */ 402 it('inputmethod_test_switchCurrentInputMethodSubtype_001', 0, async function (done) { 403 console.info('************* inputmethod_test_switchCurrentInputMethodSubtype_001 Test start*************'); 404 let InputMethodSubtype = { 405 name: bundleName, 406 id: subName[1], 407 locale:'en_US.ISO-8859-1', 408 language:'en', 409 extra:{}, 410 }; 411 inputMethod.switchCurrentInputMethodSubtype(InputMethodSubtype).then(ret => { 412 expect(ret).assertTrue(); 413 let subProp = inputMethod.getCurrentInputMethodSubtype(); 414 checkNewImeCurrentSubProp(subProp, 1); 415 console.info('************* inputmethod_test_switchCurrentInputMethodSubtype_001 Test end*************'); 416 wait(WAIT_DEAL_OK); 417 done(); 418 }).catch( err=> { 419 console.info(`inputmethod_test_switchCurrentInputMethodSubtype_001 err, ${JSON.stringify(err.message)}`); 420 expect().assertFail(); 421 done(); 422 }) 423 }); 424 425 /* 426 * @tc.number inputmethod_test_imeChange_001 427 * @tc.name Test to subscribe 'imeChange'. 428 * @tc.desc Function test 429 * @tc.level 2 430 */ 431 it('inputmethod_test_imeChange_001', 0, async function (done) { 432 console.info('************* inputmethod_test_imeChange_001 Test start*************'); 433 let timeout = setTimeout(() => { 434 console.info(`inputmethod_test_imeChange_001 timeout`); 435 expect().assertFail(); 436 inputMethod.getSetting().off('imeChange'); 437 done(); 438 }, 1500); 439 inputMethod.getSetting().on('imeChange', (prop, subProp)=>{ 440 inputMethod.getSetting().off('imeChange'); 441 timeout && clearTimeout(timeout); 442 let currentSubProp = inputMethod.getCurrentInputMethodSubtype(); 443 let currentProp = inputMethod.getCurrentInputMethod(); 444 expect(currentSubProp.name).assertEqual(subProp.name); 445 expect(currentSubProp.id).assertEqual(subProp.id); 446 expect(currentProp.name).assertEqual(prop.name); 447 expect(currentProp.id).assertEqual(prop.id); 448 expect(bundleName).assertEqual(prop.name); 449 expect(subName[0]).assertEqual(subProp.id); 450 console.info('************* inputmethod_test_imeChange_001 Test end*************'); 451 done();}); 452 453 let InputMethodSubtype = { 454 name:bundleName, 455 id:subName[0], 456 locale:'en_US.ISO-8859-1', 457 language:'en', 458 extra:{}, 459 }; 460 inputMethod.switchCurrentInputMethodSubtype(InputMethodSubtype, (err, ret)=>{ 461 if(err){ 462 console.info(`inputmethod_test_imeChange_001 switchCurrentInputMethodSubtype err, ${JSON.stringify(err.message)}`); 463 expect().assertFail(); 464 done(); 465 return; 466 } 467 expect(ret).assertTrue(); 468 }); 469 }); 470 471 /* 472 * @tc.number inputmethod_test_switchCurrentInputMethodAndSubtype_001 473 * @tc.name Test Indicates the input method subtype which will replace the current one. 474 * @tc.desc Function test 475 * @tc.level 2 476 */ 477 it('inputmethod_test_switchCurrentInputMethodAndSubtype_001', 0, async function (done) { 478 console.info('************* inputmethod_test_switchCurrentInputMethodAndSubtype_001 Test start*************'); 479 let InputMethodSubtype = { 480 name:bundleName1, 481 id:extName1[0], 482 locale:locale1[0], 483 language:language1[0], 484 extra:{}, 485 }; 486 let inputMethodProperty = { 487 name:bundleName1, 488 id:extName1[0], 489 }; 490 inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, InputMethodSubtype).then(ret => { 491 expect(ret).assertTrue(); 492 let subProp = inputMethod.getCurrentInputMethodSubtype(); 493 checkImeCurrentSubProp(subProp, 0); 494 let property = inputMethod.getCurrentInputMethod(); 495 checkImeCurrentProp(property, 0); 496 console.info('************* inputmethod_test_switchCurrentInputMethodAndSubtype_001 Test end*************'); 497 wait(WAIT_DEAL_OK); 498 done(); 499 }).catch( err=> { 500 console.info(`inputmethod_test_switchCurrentInputMethodAndSubtype_001 err, ${JSON.stringify(err.message)}`); 501 expect().assertFail(); 502 done(); 503 }) 504 }); 505 506 /* 507 * @tc.number inputmethod_test_listInputMethodSubtype_001 508 * @tc.name Test list input method subtypes. 509 * @tc.desc Function test 510 * @tc.level 2 511 */ 512 it('inputmethod_test_listInputMethodSubtype_001', 0, async function (done) { 513 console.info('************* inputmethod_test_listInputMethodSubtype_001 Test start*************'); 514 let inputMethodProperty = { 515 name:bundleName, 516 id:extName 517 }; 518 let inputMethodSetting = inputMethod.getSetting(); 519 inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, subProps) => { 520 if (err) { 521 console.error(`inputmethod_test_listInputMethodSubtype_001 err, ${JSON.stringify(err.message)}`); 522 expect().assertFail(); 523 done(); 524 return; 525 } 526 checkNewImeSubProps(subProps); 527 console.info('************* inputmethod_test_listInputMethodSubtype_001 Test end*************'); 528 done(); 529 }); 530 }); 531 532 /* 533 * @tc.number inputmethod_test_listInputMethodSubtype_002 534 * @tc.name Test list input method subtypes. 535 * @tc.desc Function test 536 * @tc.level 2 537 */ 538 it('inputmethod_test_listInputMethodSubtype_002', 0, async function (done) { 539 console.info('************* inputmethod_test_listInputMethodSubtype_002 Test start*************'); 540 let inputMethodProperty = { 541 name:bundleName1, 542 id:extName1[0] 543 }; 544 let inputMethodSetting = inputMethod.getSetting(); 545 inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((subProps)=>{ 546 checkImeSubProps(subProps); 547 console.info('************* inputmethod_test_listInputMethodSubtype_002 Test end*************'); 548 done(); 549 }).catch((err) => { 550 console.info(`inputmethod_test_listInputMethodSubtype_002 err, ${JSON.stringify(err.message)}`); 551 expect().assertFail(); 552 done(); 553 }); 554 }); 555 556 /* 557 * @tc.number inputmethod_test_showSoftKeyboard_001 558 * @tc.name Test Indicates the input method which will show softboard with callback. 559 * @tc.desc Function test 560 * @tc.level 2 561 */ 562 it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) { 563 console.info('************* inputmethod_test_showSoftKeyboard_001 Test start*************'); 564 let inputMethodCtrl = inputMethod.getInputMethodController(); 565 inputMethodCtrl.showSoftKeyboard((err) => { 566 if (err) { 567 console.info(`inputmethod_test_showSoftKeyboard_001 err, ${JSON.stringify(err.message)}`); 568 expect(err.code === 12800003).assertTrue(); 569 done(); 570 return; 571 } 572 console.info('************* inputmethod_test_showSoftKeyboard_001 Test end*************'); 573 expect().assertFail(); 574 done(); 575 }); 576 }); 577 578 /* 579 * @tc.number inputmethod_test_hideSoftKeyboard_001 580 * @tc.name Test Indicates the input method which will hide softboard with callback. 581 * @tc.desc Function test 582 * @tc.level 2 583 */ 584 it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) { 585 console.info('************* inputmethod_test_hideSoftKeyboard_001 Test start*************'); 586 let inputMethodCtrl = inputMethod.getInputMethodController(); 587 inputMethodCtrl.hideSoftKeyboard((err)=>{ 588 if(err){ 589 console.info(`inputmethod_test_hideSoftKeyboard_001 err, ${JSON.stringify(err)}`); 590 expect(err.code === 12800003).assertTrue(); 591 done(); 592 return; 593 } 594 console.info('************* inputmethod_test_hideSoftKeyboard_001 Test end*************'); 595 expect().assertFail(); 596 done(); 597 }); 598 }); 599 600 /* 601 * @tc.number inputmethod_test_stopInputSession_001 602 * @tc.name Test Indicates the input method which will hides the keyboard. 603 * @tc.desc Function test 604 * @tc.level 2 605 */ 606 it('inputmethod_test_stopInputSession_001', 0, function (done) { 607 console.info('************* inputmethod_test_stopInputSession_001 Test start*************'); 608 let inputMethodCtrl = inputMethod.getController(); 609 inputMethodCtrl.stopInputSession((err, ret) => { 610 if (err) { 611 console.info(`inputmethod_test_stopInputSession_001 err, ${JSON.stringify(err.message)}`); 612 expect(err.code === 12800003).assertTrue(); 613 done(); 614 return; 615 } 616 expect().assertFalse(); 617 console.info('************* inputmethod_test_stopInputSession_001 Test end*************'); 618 done(); 619 }); 620 }); 621 622 623 /* 624 * @tc.number inputmethod_test_showSoftKeyboard_002 625 * @tc.name Test Indicates the input method which will show softboard with Promise. 626 * @tc.desc Function test 627 * @tc.level 2 628 */ 629 it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) { 630 console.info('************* inputmethod_test_showSoftKeyboard_002 Test start*************'); 631 let inputMethodCtrl = inputMethod.getInputMethodController(); 632 inputMethodCtrl.showSoftKeyboard().then(() =>{ 633 console.info('************* inputmethod_test_showSoftKeyboard_002 Test end*************' ); 634 expect().assertFail(); 635 done(); 636 }).catch((err) => { 637 console.info(`inputmethod_test_showSoftKeyboard_002 err, ${JSON.stringify(err.message)}`); 638 expect(err.code === 12800003).assertTrue(); 639 done(); 640 }) 641 }); 642 643 /* 644 * @tc.number inputmethod_test_hideSoftKeyboard_002 645 * @tc.name Test Indicates the input method which will hide softboard with Promise. 646 * @tc.desc Function test 647 * @tc.level 2 648 */ 649 it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) { 650 console.info('************* inputmethod_test_hideSoftKeyboard_002 Test start*************'); 651 let inputMethodCtrl = inputMethod.getInputMethodController(); 652 inputMethodCtrl.hideSoftKeyboard().then(() =>{ 653 console.info('************* inputmethod_test_hideSoftKeyboard_002 Test end*************' ); 654 expect().assertFail(); 655 done(); 656 }).catch((err) => { 657 console.info(`inputmethod_test_hideSoftKeyboard_002 err, ${JSON.stringify(err.message)}`); 658 expect(err.code === 12800003).assertTrue(); 659 done(); 660 }) 661 }); 662 663 /* 664 * @tc.number inputmethod_test_stopInputSession_002 665 * @tc.name Test Indicates the input method which will hides the keyboard. 666 * @tc.desc Function test 667 * @tc.level 2 668 */ 669 it('inputmethod_test_stopInputSession_002', 0, function (done) { 670 console.info('************* inputmethod_test_stopInputSession_002 Test start*************'); 671 let inputMethodCtrl = inputMethod.getController(); 672 inputMethodCtrl.stopInputSession().then((ret) => { 673 expect().assertFail(); 674 console.info('************* inputmethod_test_stopInputSession_002 Test end*************' ); 675 done(); 676 }).catch((err) => { 677 console.info(`inputmethod_test_stopInputSession_002 err, ${JSON.stringify(err.message)}`); 678 expect(err.code === 12800003).assertTrue(); 679 done(); 680 }) 681 }); 682 683 /* 684 * @tc.number inputmethod_test_switchInputMethod_002 685 * @tc.name Switch to ime before testcases run. 686 * @tc.desc Function test 687 * @tc.level 2 688 */ 689 it('inputmethod_test_switchInputMethod_002', 0, async function (done) { 690 console.info('************* inputmethod_test_switchInputMethod_002 Test start*************'); 691 inputMethod.switchInputMethod(propertyBeforeSwitch).then(ret => { 692 expect(ret).assertTrue(); 693 let property = inputMethod.getCurrentInputMethod(); 694 expect(property.name).assertEqual(propertyBeforeSwitch.name); 695 expect(property.id).assertEqual(propertyBeforeSwitch.id); 696 console.info('************* inputmethod_test_switchInputMethod_001 Test end*************'); 697 done(); 698 }).catch( err=> { 699 console.info(`inputmethod_test_switchInputMethod_001 err: ${JSON.stringify(err.message)}`); 700 expect().assertFail(); 701 }) 702 }); 703 704 /* 705 * @tc.number inputmethod_test_attach_001 706 * @tc.name Test whether the current application can be bound with the default input method. 707 * @tc.desc Function test 708 * @tc.level 2 709 */ 710 it('inputmethod_test_attach_001', 0, async function (done) { 711 console.info('************* inputmethod_test_attach_001 Test start*************'); 712 let inputMethodCtrl = inputMethod.getInputMethodController(); 713 let attribute = { 714 textInputType: inputMethod.TextInputType.TEXT, 715 enterKeyType: inputMethod.EnterKeyType.NONE 716 }; 717 let textConfig = { 718 inputAttribute: attribute 719 }; 720 try { 721 inputMethodCtrl.attach(false, textConfig, (err)=>{ 722 if (err) { 723 console.info(`inputmethod_test_attach_001 result: ${JSON.stringify(err)}`); 724 expect().assertFail(); 725 done(); 726 } 727 console.info('************* inputmethod_test_attach_001 Test end*************'); 728 expect(true).assertTrue(); 729 done(); 730 }); 731 } catch (error) { 732 console.info(`inputmethod_test_attach_001 error, result: ${JSON.stringify(error)}`); 733 expect().assertFail(); 734 done(); 735 } 736 }); 737 738 /* 739 * @tc.number inputmethod_test_attach_002 740 * @tc.name Test whether the current application can be bound with the default input method. 741 * @tc.desc Function test 742 * @tc.level 2 743 */ 744 it('inputmethod_test_attach_002', 0, async function (done) { 745 console.info('************* inputmethod_test_attach_002 Test start*************'); 746 let inputMethodCtrl = inputMethod.getInputMethodController(); 747 let attribute = { 748 textInputType: inputMethod.TextInputType.TEXT, 749 enterKeyType: inputMethod.EnterKeyType.NONE 750 }; 751 let textConfig = { 752 inputAttribute: attribute 753 }; 754 try { 755 inputMethodCtrl.attach(false, textConfig).then(()=>{ 756 console.info('************* inputmethod_test_attach_002 Test end*************'); 757 expect(true).assertTrue(); 758 done(); 759 }).catch((err) => { 760 console.info(`inputmethod_test_attach_002 err result: ${JSON.stringify(err)}`); 761 expect().assertFail(); 762 done(); 763 }) 764 } catch (error) { 765 console.info(`inputmethod_test_attach_002 error result: ${JSON.stringify(error)}`); 766 expect().assertFail(); 767 done(); 768 } 769 }); 770 771 /* 772 * @tc.number inputmethod_test_detach_001 773 * @tc.name Test whether it can successfully unbind with input method. 774 * @tc.desc Function test 775 * @tc.level 2 776 */ 777 it('inputmethod_test_detach_001', 0, async function (done) { 778 console.info('************* inputmethod_test_detach_001 Test start*************'); 779 let inputMethodCtrl = inputMethod.getController(); 780 inputMethodCtrl.detach((err) => { 781 if (err) { 782 console.info(`inputmethod_test_detach_001 result: ${JSON.stringify(err)}`); 783 expect().assertFail(); 784 done(); 785 } 786 console.info('inputmethod_test_detach_001 callback success'); 787 expect(true).assertTrue(); 788 done(); 789 }); 790 }); 791 792 /* 793 * @tc.number inputmethod_test_detach_002 794 * @tc.name Test whether the keyboard is hide successfully. 795 * @tc.desc Function test 796 * @tc.level 2 797 */ 798 it('inputmethod_test_detach_002', 0, async function (done) { 799 console.info('************* inputmethod_test_detach_002 Test start*************'); 800 let inputMethodCtrl = inputMethod.getController(); 801 console.info(`inputmethod_test_detach_002 result: ${JSON.stringify(inputMethodCtrl)}`); 802 inputMethodCtrl.detach().then(() => { 803 console.info('inputmethod_test_detach_002 promise success.'); 804 expect(true).assertTrue(); 805 done(); 806 }).catch((err) => { 807 console.info(`inputmethod_test_detach_002 result: ${JSON.stringify(err)}`); 808 expect().assertFail(); 809 done(); 810 }); 811 }); 812 813 /* 814 * @tc.number inputmethod_test_showTextInput_001 815 * @tc.name Test whether the keyboard is displayed successfully. 816 * @tc.desc Function test 817 * @tc.level 2 818 */ 819 it('inputmethod_test_showTextInput_001', 0, async function (done) { 820 console.info('************* inputmethod_test_showTextInput_001 Test start*************'); 821 let inputMethodCtrl = inputMethod.getController(); 822 inputMethodCtrl.showTextInput((err) => { 823 console.info(`inputmethod_test_detach_002 result: ${JSON.stringify(err)}`); 824 if (err.code === 12800009) { 825 console.info(`inputmethod_test_detach_002 err.code === 12800009.`); 826 expect(true).assertTrue(); 827 } else { 828 expect().assertFail(); 829 } 830 done(); 831 }) 832 }); 833 834 /* 835 * @tc.number inputmethod_test_hideTextInput_001 836 * @tc.name Test whether the keyboard is hidden successfully. 837 * @tc.desc Function test 838 * @tc.level 2 839 */ 840 it('inputmethod_test_hideTextInput_001', 0, async function (done) { 841 console.info('************* inputmethod_test_hideTextInput_001 Test start*************'); 842 let inputMethodCtrl = inputMethod.getController(); 843 inputMethodCtrl.hideTextInput((err) => { 844 console.info(`inputmethod_test_hideTextInput_001 err: ${JSON.stringify(err)}`); 845 if (err.code === 12800009) { 846 expect(true).assertTrue(); 847 } else { 848 expect().assertFail(); 849 } 850 done(); 851 }) 852 }); 853 854 /* 855 * @tc.number inputmethod_test_setCallingWindow_001 856 * @tc.name Test whether set calling window successfully. 857 * @tc.desc Function test 858 * @tc.level 2 859 */ 860 it('inputmethod_test_setCallingWindow_001', 0, async function (done) { 861 console.info('************* inputmethod_test_setCallingWindow_001 Test start*************'); 862 let inputMethodCtrl = inputMethod.getController(); 863 let windowId = 100; 864 try { 865 inputMethodCtrl.setCallingWindow(windowId, (err) => { 866 console.info(`inputmethod_test_setCallingWindow_001 err: ${JSON.stringify(err)}`); 867 if (err.code === 12800009) { 868 expect(true).assertTrue(); 869 } else { 870 expect().assertFail(); 871 } 872 done(); 873 }) 874 } catch (error) { 875 console.info(`inputmethod_test_setCallingWindow_001 result: ${JSON.stringify(error)}`); 876 expect().assertFail(); 877 done(); 878 } 879 }); 880 881 /* 882 * @tc.number inputmethod_test_setCallingWindow_002 883 * @tc.name Test whether set calling window successfully when type of param is wrong. 884 * @tc.desc Function test 885 * @tc.level 2 886 */ 887 it('inputmethod_test_setCallingWindow_002', 0, async function (done) { 888 console.info('************* inputmethod_test_setCallingWindow_002 Test start*************'); 889 let inputMethodCtrl = inputMethod.getController(); 890 let windowId = '100'; 891 try { 892 inputMethodCtrl.setCallingWindow(windowId, (err) => { 893 expect().assertFail(); 894 done(); 895 }) 896 } catch (error) { 897 console.info(`inputmethod_test_setCallingWindow_002 result: ${JSON.stringify(error)}`); 898 expect(true).assertTrue(); 899 done(); 900 } 901 }); 902 903 /* 904 * @tc.number inputmethod_test_updateCursor_001 905 * @tc.name Test whether update cursor successfully. 906 * @tc.desc Function test 907 * @tc.level 2 908 */ 909 it('inputmethod_test_updateCursor_001', 0, async function (done) { 910 console.info('************* inputmethod_test_updateCursor_001 Test start*************'); 911 let inputMethodCtrl = inputMethod.getController(); 912 let cursorInfo = { left: 100, top: 110, width: 600, height: 800 }; 913 try { 914 inputMethodCtrl.updateCursor(cursorInfo, (err) => { 915 if (err.code === 12800009) { 916 expect(true).assertTrue(); 917 } else { 918 expect().assertFail(); 919 } 920 done(); 921 }) 922 } catch (error) { 923 console.info(`inputmethod_test_updateCursor_001 result: ${JSON.stringify(error)}`); 924 expect().assertFail(); 925 done(); 926 } 927 }); 928 929 /* 930 * @tc.number inputmethod_test_changeSelection_001 931 * @tc.name Test whether change selection successfully. 932 * @tc.desc Function test 933 * @tc.level 2 934 */ 935 it('inputmethod_test_changeSelection_001', 0, async function (done) { 936 console.info('************* inputmethod_test_changeSelection_001 Test start*************'); 937 let inputMethodCtrl = inputMethod.getController(); 938 let text = 'test'; 939 let start = 0; 940 let end = 5; 941 try { 942 inputMethodCtrl.changeSelection(text, start, end, (err) => { 943 if (err.code === 12800009) { 944 expect(true).assertTrue(); 945 } else { 946 expect().assertFail(); 947 } 948 done(); 949 }); 950 } catch (error) { 951 console.info(`inputmethod_test_changeSelection_001 result: ${JSON.stringify(error)}`); 952 expect().assertFail(); 953 done(); 954 } 955 }); 956 957 /* 958 * @tc.number inputmethod_test_updateAttribute 959 * @tc.name Test whether update attribute successfully. 960 * @tc.desc Function test 961 * @tc.level 2 962 */ 963 it('inputmethod_test_updateAttribute', 0, async function (done) { 964 console.info('************* inputmethod_test_updateAttribute Test start*************'); 965 let inputMethodCtrl = inputMethod.getController(); 966 let attribute = {textInputType: inputMethod.TextInputType.TEXT, enterKeyType: inputMethod.EnterKeyType.NONE}; 967 try { 968 inputMethodCtrl.updateAttribute(attribute, (err) => { 969 if (err.code === 12800009) { 970 expect(true).assertTrue(); 971 } else { 972 expect().assertFail(); 973 } 974 done(); 975 }); 976 } catch (error) { 977 console.info(`inputmethod_test_updateAttribute result: ${JSON.stringify(error)}`); 978 expect().assertFail(); 979 done(); 980 } 981 }); 982 983 /* 984 * @tc.number inputmethod_test_on_insertText_001 985 * @tc.name Test whether the register the callback of the input method is valid. 986 * @tc.desc Function test 987 * @tc.level 2 988 */ 989 it('inputmethod_test_on_insertText_001', 0, async function (done) { 990 let inputMethodCtrl = inputMethod.getController(); 991 try { 992 inputMethodCtrl.on('insertText', (text) => { 993 }); 994 expect().assertFail(); 995 done(); 996 } catch (error) { 997 console.info(`inputmethod_test_on_insertText_001 result: ${JSON.stringify(error)}`); 998 expect(error.code === 12800009).assertTrue(); 999 done(); 1000 } 1001 }); 1002 1003 /* 1004 * @tc.number inputmethod_test_on_deleteLeft_001 1005 * @tc.name Test whether the register the callback of the input method is valid. 1006 * @tc.desc Function test 1007 * @tc.level 2 1008 */ 1009 it('inputmethod_test_on_deleteLeft_001', 0, async function (done) { 1010 let inputMethodCtrl = inputMethod.getController(); 1011 try { 1012 inputMethodCtrl.on('deleteLeft', (length) => {}); 1013 expect().assertFail(); 1014 done(); 1015 } catch (error) { 1016 console.info(`inputmethod_test_on_deleteLeft_001 result: ${JSON.stringify(error)}`); 1017 expect(error.code === 12800009).assertTrue(); 1018 done(); 1019 } 1020 }); 1021 1022 /* 1023 * @tc.number inputmethod_test_on_deleteRight_001 1024 * @tc.name Test whether the register the callback of the input method is valid. 1025 * @tc.desc Function test 1026 * @tc.level 2 1027 */ 1028 it('inputmethod_test_on_deleteRight_001', 0, async function (done) { 1029 let inputMethodCtrl = inputMethod.getController(); 1030 try { 1031 inputMethodCtrl.on('deleteRight', (length) => {}); 1032 expect().assertFail(); 1033 done(); 1034 } catch (error) { 1035 console.info(`inputmethod_test_on_deleteRight_001 result: ${JSON.stringify(error)}`); 1036 expect(error.code === 12800009).assertTrue(); 1037 done(); 1038 } 1039 }); 1040 1041 /* 1042 * @tc.number inputmethod_test_on_sendKeyboardStatus_001 1043 * @tc.name Test whether the register the callback of the input method is valid. 1044 * @tc.desc Function test 1045 * @tc.level 2 1046 */ 1047 it('inputmethod_test_on_sendKeyboardStatus_001', 0, async function (done) { 1048 let inputMethodCtrl = inputMethod.getController(); 1049 try { 1050 inputMethodCtrl.on('sendKeyboardStatus', (status) => {}); 1051 expect().assertFail(); 1052 done(); 1053 } catch (error) { 1054 console.info(`inputmethod_test_on_sendKeyboardStatus_001 result: ${JSON.stringify(error)}`); 1055 expect(error.code === 12800009).assertTrue(); 1056 done(); 1057 } 1058 }); 1059 1060 /* 1061 * @tc.number inputmethod_test_on_sendKeyboardStatus_001 1062 * @tc.name Test whether the register the callback of the input method is valid. 1063 * @tc.desc Function test 1064 * @tc.level 2 1065 */ 1066 it('inputmethod_test_on_sendFunctionKey_001', 0, async function (done) { 1067 let inputMethodCtrl = inputMethod.getController(); 1068 try { 1069 inputMethodCtrl.on('sendFunctionKey', (functionKey) => {}); 1070 expect().assertFail(); 1071 done(); 1072 } catch (error) { 1073 console.info(`inputmethod_test_on_sendFunctionKey_001 result: ${JSON.stringify(error)}`); 1074 expect(error.code === 12800009).assertTrue(); 1075 done(); 1076 } 1077 }); 1078 1079 /* 1080 * @tc.number inputmethod_test_on_moveCursor_001 1081 * @tc.name Test whether the register the callback of the input method is valid. 1082 * @tc.desc Function test 1083 * @tc.level 2 1084 */ 1085 it('inputmethod_test_on_moveCursor_001', 0, async function (done) { 1086 let inputMethodCtrl = inputMethod.getController(); 1087 try { 1088 inputMethodCtrl.on('moveCursor', (direction) => {}); 1089 expect().assertFail(); 1090 done(); 1091 } catch (error) { 1092 console.info(`inputmethod_test_on_moveCursor_001 result: ${JSON.stringify(error)}`); 1093 expect(error.code === 12800009).assertTrue(); 1094 done(); 1095 } 1096 }); 1097 1098 /* 1099 * @tc.number inputmethod_test_on_handleExtendAction_001 1100 * @tc.name Test whether the register the callback of the input method is valid. 1101 * @tc.desc Function test 1102 * @tc.level 2 1103 */ 1104 it('inputmethod_test_on_handleExtendAction_001', 0, async function (done) { 1105 let inputMethodCtrl = inputMethod.getController(); 1106 try { 1107 inputMethodCtrl.on('handleExtendAction', (action) => {}); 1108 expect().assertFail(); 1109 done(); 1110 } catch (error) { 1111 console.info(`inputmethod_test_on_handleExtendAction_001 result: ${JSON.stringify(error)}`); 1112 expect(error.code === 12800009).assertTrue(); 1113 done(); 1114 } 1115 }); 1116 1117 /* 1118 * @tc.number inputmethod_test_off_001 1119 * @tc.name Test whether the unregister the callback of the input method is valid. 1120 * @tc.desc Function test 1121 * @tc.level 2 1122 */ 1123 it('inputmethod_test_off_001', 0, async function (done) { 1124 let inputMethodCtrl = inputMethod.getController(); 1125 try { 1126 inputMethodCtrl.off('insertText'); 1127 inputMethodCtrl.off('deleteLeft'); 1128 inputMethodCtrl.off('deleteRight'); 1129 inputMethodCtrl.off('sendKeyboardStatus'); 1130 inputMethodCtrl.off('sendFunctionKey'); 1131 inputMethodCtrl.off('moveCursor'); 1132 inputMethodCtrl.off('handleExtendAction'); 1133 expect(true).assertTrue(); 1134 done(); 1135 } catch(error) { 1136 console.info(`inputmethod_test_off_001 result: ${JSON.stringify(error)}`); 1137 expect().assertFail(); 1138 done(); 1139 } 1140 }); 1141 1142 /* 1143 * @tc.number inputmethod_settings_test_on_imeShow_001 1144 * @tc.name Test whether the register the callback of the input method is valid. 1145 * @tc.desc Function test 1146 * @tc.level 2 1147 */ 1148 it('inputmethod_setting_test_on_imeShow_001', 0, async function (done) { 1149 let inputMethodSetting = inputMethod.getSetting(); 1150 try { 1151 inputMethodSetting.on('imeShow', (info) => {}); 1152 expect(true).assertTrue(); 1153 done(); 1154 } catch (error) { 1155 console.info(`inputmethod_setting_test_on_imeShow_001 result: ${JSON.stringify(error)}`); 1156 expect().assertFail(); 1157 done(); 1158 } 1159 }); 1160 1161 /* 1162 * @tc.number inputmethod_settings_test_on_imeHide_001 1163 * @tc.name Test whether the register the callback of the input method is valid. 1164 * @tc.desc Function test 1165 * @tc.level 2 1166 */ 1167 it('inputmethod_setting_test_on_imeHide_001', 0, async function (done) { 1168 let inputMethodSetting = inputMethod.getSetting(); 1169 try { 1170 inputMethodSetting.on('imeHide', (info) => {}); 1171 expect(true).assertTrue(); 1172 done(); 1173 } catch (error) { 1174 console.info(`inputmethod_setting_test_on_imeHide_001 result: ${JSON.stringify(error)}`); 1175 expect().assertFail(); 1176 done(); 1177 } 1178 }); 1179 1180 /* 1181 * @tc.number inputmethod_test_getDefaultInputMethod_001 1182 * @tc.name Test Indicates the getDefaultInputMethod. 1183 * @tc.desc Function test 1184 * @tc.level 1 1185 */ 1186 it('inputmethod_test_getDefaultInputMethod_001', 0, async function (done) { 1187 console.info('************* inputmethod_test_getDefaultInputMethod_001 Test start*************'); 1188 try { 1189 let property = inputMethod.getDefaultInputMethod(); 1190 if (property.name.length > 0) { 1191 expect(true).assertTrue(); 1192 } 1193 console.info('************* inputmethod_test_getDefaultInputMethod_001 Test end*************'); 1194 } catch (error) { 1195 if(error) { 1196 console.info(`inputmethod_test_getDefaultInputMethod_001 error, result: ${JSON.stringify(error)}`); 1197 expect().assertFail(); 1198 } 1199 } finally { 1200 done(); 1201 } 1202 }); 1203 1204 /* 1205 * @tc.number inputmethod_test_getSystemInputMethodConfigAbility_001 1206 * @tc.name Test Indicates the getSystemInputMethodConfigAbility. 1207 * @tc.desc Function test 1208 * @tc.level 1 1209 */ 1210 it('inputmethod_test_getSystemInputMethodConfigAbility_001', 0, async function (done) { 1211 console.info('************* inputmethod_test_getSystemInputMethodConfigAbility_001 Test start*************'); 1212 try { 1213 let systemInputMethodConfigAbility = inputMethod.getSystemInputMethodConfigAbility(); 1214 console.info('************* inputmethod_test_getSystemInputMethodConfigAbility_001 Test end*************'); 1215 expect(true).assertTrue(); 1216 done(); 1217 } catch (error) { 1218 if(error) { 1219 console.info(`inputmethod_test_getSystemInputMethodConfigAbility_001 error, result: ${JSON.stringify(error)}`); 1220 expect().assertFail(); 1221 } 1222 } finally { 1223 done(); 1224 } 1225 }); 1226});