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 expect(subProps.length).assertEqual(NEW_IME_SUBTYPE_NUM); 72 for (let i = 0; i < subProps.length; i++) { 73 expect(subProps[i].name).assertEqual(bundleName); 74 expect(subProps[i].id).assertEqual(subName[i]); 75 expect(subProps[i].locale).assertEqual(locale[i]); 76 expect(subProps[i].language).assertEqual(language[i]); 77 } 78 } 79 80 function checkImeCurrentProp(property, index) { 81 expect(property.name).assertEqual(bundleName1); 82 expect(property.id).assertEqual(extName1[index]); 83 expect(property.packageName).assertEqual(bundleName1); 84 expect(property.methodId).assertEqual(extName1[index]); 85 } 86 87 function checkImeCurrentSubProp(subProp, index) { 88 expect(subProp.name).assertEqual(bundleName1); 89 expect(subProp.id).assertEqual(extName1[index]); 90 expect(subProp.locale).assertEqual(locale1[index]); 91 expect(subProp.language).assertEqual(language1[index]); 92 } 93 94 function checkImeSubProps(subProps) { 95 expect(subProps.length).assertEqual(OLD_IME_SUBTYPE_NUM); 96 for (let i = 0; i < subProps.length; i++) { 97 expect(subProps[i].name).assertEqual(bundleName1); 98 expect(subProps[i].id).assertEqual(extName1[i]); 99 expect(subProps[i].locale).assertEqual(locale1[i]); 100 expect(subProps[i].language).assertEqual(language1[i]); 101 } 102 } 103 104 function wait(delay) { 105 let start = new Date().getTime(); 106 while (new Date().getTime() - start < delay) { 107 } 108 } 109 110 /* 111 * @tc.number inputmethod_test_MAX_TYPE_NUM_001 112 * @tc.name Test MAX_TYPE_NUM. 113 * @tc.desc Function test 114 * @tc.level 2 115 */ 116 it('inputmethod_test_MAX_TYPE_NUM_001', 0, async function (done) { 117 console.info('************* inputmethod_test_MAX_TYPE_NUM_001 Test start*************'); 118 let MAX_NUM = 128; 119 let num = inputMethod.MAX_TYPE_NUM; 120 console.info(`inputmethod_test_001 result: ${ num }`); 121 expect(num).assertEqual(MAX_NUM); 122 done(); 123 }); 124 125 /* 126 * @tc.number inputmethod_test_getInputMethodController_001 127 * @tc.name Test to get an InputMethodController instance. 128 * @tc.desc Function test 129 * @tc.level 0 130 */ 131 it('inputmethod_test_getInputMethodController_001', 0, async function (done) { 132 console.info('************* inputmethod_test_getInputMethodController_001 Test start*************'); 133 let controller = inputMethod.getInputMethodController(); 134 expect(controller !== undefined).assertTrue(); 135 console.info('************* inputmethod_test_getInputMethodController_001 Test end*************'); 136 done(); 137 }); 138 139 /* 140 * @tc.number inputmethod_test_getController_001 141 * @tc.name Test to get an InputMethodController instance. 142 * @tc.desc Function test 143 * @tc.level 0 144 */ 145 it('inputmethod_test_getController_001', 0, async function (done) { 146 console.info('************* inputmethod_test_getController_001 Test start*************'); 147 let controller = inputMethod.getController(); 148 expect(controller !== undefined).assertTrue(); 149 console.info('************* inputmethod_test_getController_001 Test end*************'); 150 done(); 151 }); 152 153 /* 154 * @tc.number inputmethod_test_getInputMethodSetting_001 155 * @tc.name Test to get an InputMethodSetting instance. 156 * @tc.desc Function test 157 * @tc.level 0 158 */ 159 it('inputmethod_test_getInputMethodSetting_001', 0, async function (done) { 160 console.info('************* inputmethod_test_getInputMethodSetting_001 Test start*************'); 161 let setting = inputMethod.getInputMethodSetting(); 162 expect(setting !== undefined).assertTrue(); 163 console.info('************* inputmethod_test_getInputMethodSetting_001 Test end*************'); 164 done(); 165 }); 166 167 /* 168 * @tc.number inputmethod_test_getInputMethodSetting_001 169 * @tc.name Test to get an InputMethodSetting instance. 170 * @tc.desc Function test 171 * @tc.level 0 172 */ 173 it('inputmethod_test_getSetting_001', 0, async function (done) { 174 console.info('************* inputmethod_test_getSetting_001 Test start*************'); 175 let setting = inputMethod.getSetting(); 176 expect(setting !== undefined).assertTrue(); 177 console.info('************* inputmethod_test_getSetting_001 Test end*************'); 178 done(); 179 }); 180 181 /* 182 * @tc.number inputmethod_test_switchInputMethod_001 183 * @tc.name Test Indicates the input method which will replace the current one. 184 * @tc.desc Function test 185 * @tc.level 0 186 */ 187 it('inputmethod_test_switchInputMethod_001', 0, async function (done) { 188 console.info('************* inputmethod_test_switchInputMethod_001 Test start*************'); 189 let inputMethodProperty = { 190 name:bundleName, 191 id:extName 192 }; 193 inputMethod.getSetting().enableInputMethod(inputMethodProperty.name, inputMethodProperty.id, 194 inputMethod.EnabledState.FULL_EXPERIENCE_MODE); 195 setTimeout(() => { 196 inputMethod.switchInputMethod(inputMethodProperty).then(ret => { 197 expect(ret).assertTrue(); 198 let property = inputMethod.getCurrentInputMethod(); 199 checkNewImeCurrentProp(property); 200 console.info('************* inputmethod_test_switchInputMethod_001 Test end*************'); 201 expect(true).assertTrue(); 202 done(); 203 }).catch( err=> { 204 console.info(`inputmethod_test_switchInputMethod_001 err: ${JSON.stringify(err.message)}`); 205 expect().assertFail(); 206 }) 207 }, WAIT_DEAL_OK); 208 }); 209 210 /* 211 * @tc.number inputmethod_test_listCurrentInputMethodSubtype_001 212 * @tc.name Test list current input method subtypes. 213 * @tc.desc Function test 214 * @tc.level 2 215 */ 216 it('inputmethod_test_listCurrentInputMethodSubtype_001', 0, async function (done) { 217 console.info('************* inputmethod_test_listCurrentInputMethodSubtype_001 Test start*************'); 218 wait(WAIT_DEAL_OK); 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 wait(WAIT_DEAL_OK); 243 let inputMethodSetting = inputMethod.getSetting(); 244 inputMethodSetting.listCurrentInputMethodSubtype().then((subProps)=>{ 245 checkNewImeSubProps(subProps); 246 console.info('************* inputmethod_test_listCurrentInputMethodSubtype_002 Test end*************'); 247 expect(true).assertTrue(); 248 done(); 249 }).catch((err) => { 250 console.info(`inputmethod_test_listCurrentInputMethodSubtype_002 err: ${JSON.stringify(err.message)}`); 251 expect().assertFail(); 252 done(); 253 }); 254 }); 255 256 /* 257 * @tc.number inputmethod_test_listInputMethod_001 258 * @tc.name Test list input methods. 259 * @tc.desc Function test 260 * @tc.level 2 261 */ 262 it('inputmethod_test_listInputMethod_001', 0, async function (done) { 263 console.info('************* inputmethod_test_listInputMethod_001 Test start*************'); 264 let inputMethodSetting = inputMethod.getInputMethodSetting(); 265 inputMethodSetting.listInputMethod((err, props) => { 266 if (err) { 267 console.error(`inputmethod_test_listInputMethod_001 err: ${ JSON.stringify(err.message) }`); 268 expect().assertFail(); 269 done(); 270 return; 271 } 272 expect(props.length >= LEAST_ALL_IME_NUM).assertTrue(); 273 let imeProp = props.find(function (prop) {return prop.name === bundleName && prop.id === extName;}); 274 expect(imeProp != undefined).assertTrue(); 275 let imeProp1 = props.find(function (prop) {return prop.name === bundleName1;}); 276 expect(imeProp1 != undefined).assertTrue(); 277 console.info('************* inputmethod_test_listInputMethod_001 Test end*************'); 278 done(); 279 }); 280 }); 281 282 /* 283 * @tc.number inputmethod_test_listInputMethod_002 284 * @tc.name Test list input methods. 285 * @tc.desc Function test 286 * @tc.level 2 287 */ 288 it('inputmethod_test_listInputMethod_002', 0, async function (done) { 289 console.info('************* inputmethod_test_listInputMethod_002 Test start*************'); 290 let inputMethodSetting = inputMethod.getInputMethodSetting(); 291 await inputMethodSetting.listInputMethod().then((props) => { 292 expect(props.length >= LEAST_ALL_IME_NUM).assertTrue(); 293 let imeProp = props.find(function (prop) {return prop.name === bundleName && prop.id === extName;}); 294 expect(imeProp != undefined).assertTrue(); 295 let imeProp1 = props.find(function (prop) {return prop.name === bundleName1;}); 296 expect(imeProp1 != undefined).assertTrue(); 297 console.info('************* inputmethod_test_listInputMethod_002 Test end*************'); 298 done(); 299 }).catch((err) => { 300 console.info(`inputmethod_test_listInputMethod_002 err, ${JSON.stringify(err.message)} `); 301 expect().assertFail(); 302 done(); 303 }); 304 }); 305 306 /* 307 * @tc.number inputmethod_test_getInputMethods_001 308 * @tc.name Test get enable input methods. 309 * @tc.desc Function test 310 * @tc.level 2 311 */ 312 it('inputmethod_test_getInputMethods_001', 0, async function (done) { 313 console.info('************* inputmethod_test_getInputMethods_001 Test start*************'); 314 let inputMethodSetting = inputMethod.getInputMethodSetting(); 315 await inputMethodSetting.getInputMethods(true).then((props)=>{ 316 expect(props.length).assertEqual(ENABLE_IME_NUM); 317 let imeProp = props.find(function (prop) {return prop.name === bundleName;}); 318 expect(imeProp != undefined).assertTrue(); 319 console.info('************* inputmethod_test_getInputMethods_001 Test end*************'); 320 done(); 321 }).catch((err) => { 322 console.info(`inputmethod_test_getInputMethods_001 err, ${JSON.stringify(err.message)} `); 323 expect().assertFail(); 324 done(); 325 }); 326 }); 327 328 /* 329 * @tc.number inputmethod_test_getInputMethods_002 330 * @tc.name Test get enable input methods. 331 * @tc.desc Function test 332 * @tc.level 2 333 */ 334 it('inputmethod_test_getInputMethods_002', 0, async function (done) { 335 console.info('************* inputmethod_test_getInputMethods_002 Test start*************'); 336 let inputMethodSetting = inputMethod.getInputMethodSetting(); 337 inputMethodSetting.getInputMethods(true, (err, props) => { 338 if (err) { 339 console.error(`inputmethod_test_getInputMethods_002 err: ${JSON.stringify(err.message)}`); 340 expect().assertFail(); 341 done(); 342 return; 343 } 344 let imeProp = props.find(function (prop) {return prop.name === bundleName;}); 345 expect(imeProp != undefined).assertTrue(); 346 console.info('************* inputmethod_test_getInputMethods_002 Test end*************'); 347 done(); 348 }); 349 }); 350 351 /* 352 * @tc.number inputmethod_test_getInputMethods_003 353 * @tc.name Test get disable input methods. 354 * @tc.desc Function test 355 * @tc.level 2 356 */ 357 it('inputmethod_test_getInputMethods_003', 0, async function (done) { 358 console.info('************* inputmethod_test_getInputMethods_003 Test start*************'); 359 let inputMethodSetting = inputMethod.getInputMethodSetting(); 360 await inputMethodSetting.getInputMethods(false).then((props)=>{ 361 expect(props.length >= DISABLED_IME_COUNT).assertTrue(); 362 let imeProp = props.find(function (prop) {return prop.name === bundleName1;}); 363 expect(imeProp == undefined).assertTrue(); 364 console.info('************* inputmethod_test_getInputMethods_003 Test end*************'); 365 done(); 366 }).catch((err) => { 367 console.info(`inputmethod_test_getInputMethods_003 err, ${JSON.stringify(err.message)}`); 368 expect().assertFail(); 369 done(); 370 }); 371 }); 372 373 /* 374 * @tc.number inputmethod_test_getInputMethods_004 375 * @tc.name Test get disable input methods. 376 * @tc.desc Function test 377 * @tc.level 2 378 */ 379 it('inputmethod_test_getInputMethods_004', 0, async function (done) { 380 console.info('************* inputmethod_test_getInputMethods_004 Test start*************'); 381 let inputMethodSetting = inputMethod.getInputMethodSetting(); 382 inputMethodSetting.getInputMethods(false, (err, props) => { 383 if (err) { 384 console.error(`inputmethod_test_getInputMethods_004 err, ${JSON.stringify(err.message)}`); 385 expect().assertFail(); 386 done(); 387 return; 388 } 389 expect(props.length >= DISABLED_IME_COUNT).assertTrue(); 390 let imeProp = props.find(function (prop) {return prop.name === bundleName1;}); 391 expect(imeProp == undefined).assertTrue(); 392 console.info('************* inputmethod_test_getInputMethods_004 Test end*************'); 393 done(); 394 }); 395 }); 396 397 /* 398 * @tc.number inputmethod_test_switchCurrentInputMethodSubtype_001 399 * @tc.name Test Indicates the input method subtype which will replace the current one. 400 * @tc.desc Function test 401 * @tc.level 2 402 */ 403 it('inputmethod_test_switchCurrentInputMethodSubtype_001', 0, async function (done) { 404 console.info('************* inputmethod_test_switchCurrentInputMethodSubtype_001 Test start*************'); 405 let InputMethodSubtype = { 406 name: bundleName, 407 id: subName[1], 408 locale:'en_US.ISO-8859-1', 409 language:'en', 410 extra:{}, 411 }; 412 inputMethod.switchCurrentInputMethodSubtype(InputMethodSubtype).then(ret => { 413 expect(ret).assertTrue(); 414 let subProp = inputMethod.getCurrentInputMethodSubtype(); 415 checkNewImeCurrentSubProp(subProp, 1); 416 console.info('************* inputmethod_test_switchCurrentInputMethodSubtype_001 Test end*************'); 417 wait(WAIT_DEAL_OK); 418 done(); 419 }).catch( err=> { 420 console.info(`inputmethod_test_switchCurrentInputMethodSubtype_001 err, ${JSON.stringify(err.message)}`); 421 expect().assertFail(); 422 done(); 423 }) 424 }); 425 426 /* 427 * @tc.number inputmethod_test_imeChange_001 428 * @tc.name Test to subscribe 'imeChange'. 429 * @tc.desc Function test 430 * @tc.level 2 431 */ 432 it('inputmethod_test_imeChange_001', 0, async function (done) { 433 console.info('************* inputmethod_test_imeChange_001 Test start*************'); 434 let timeout = setTimeout(() => { 435 console.info(`inputmethod_test_imeChange_001 timeout`); 436 expect().assertFail(); 437 inputMethod.getSetting().off('imeChange'); 438 done(); 439 }, 1500); 440 inputMethod.getSetting().on('imeChange', (prop, subProp)=>{ 441 inputMethod.getSetting().off('imeChange'); 442 timeout && clearTimeout(timeout); 443 let currentSubProp = inputMethod.getCurrentInputMethodSubtype(); 444 let currentProp = inputMethod.getCurrentInputMethod(); 445 expect(currentSubProp.name).assertEqual(subProp.name); 446 expect(currentSubProp.id).assertEqual(subProp.id); 447 expect(currentProp.name).assertEqual(prop.name); 448 expect(currentProp.id).assertEqual(prop.id); 449 expect(bundleName).assertEqual(prop.name); 450 expect(subName[0]).assertEqual(subProp.id); 451 console.info('************* inputmethod_test_imeChange_001 Test end*************'); 452 done();}); 453 454 let InputMethodSubtype = { 455 name:bundleName, 456 id:subName[0], 457 locale:'en_US.ISO-8859-1', 458 language:'en', 459 extra:{}, 460 }; 461 inputMethod.switchCurrentInputMethodSubtype(InputMethodSubtype, (err, ret)=>{ 462 if(err){ 463 console.info(`inputmethod_test_imeChange_001 switchCurrentInputMethodSubtype err, ${JSON.stringify(err.message)}`); 464 expect().assertFail(); 465 done(); 466 return; 467 } 468 expect(ret).assertTrue(); 469 }); 470 }); 471 472 /* 473 * @tc.number inputmethod_test_switchCurrentInputMethodAndSubtype_001 474 * @tc.name Test Indicates the input method subtype which will replace the current one. 475 * @tc.desc Function test 476 * @tc.level 2 477 */ 478 it('inputmethod_test_switchCurrentInputMethodAndSubtype_001', 0, async function (done) { 479 console.info('************* inputmethod_test_switchCurrentInputMethodAndSubtype_001 Test start*************'); 480 let InputMethodSubtype = { 481 name:bundleName1, 482 id:extName1[0], 483 locale:locale1[0], 484 language:language1[0], 485 extra:{}, 486 }; 487 let inputMethodProperty = { 488 name:bundleName1, 489 id:extName1[0], 490 }; 491 inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, InputMethodSubtype).then(ret => { 492 expect(ret).assertTrue(); 493 let subProp = inputMethod.getCurrentInputMethodSubtype(); 494 checkImeCurrentSubProp(subProp, 0); 495 let property = inputMethod.getCurrentInputMethod(); 496 checkImeCurrentProp(property, 0); 497 console.info('************* inputmethod_test_switchCurrentInputMethodAndSubtype_001 Test end*************'); 498 wait(WAIT_DEAL_OK); 499 done(); 500 }).catch( err=> { 501 console.info(`inputmethod_test_switchCurrentInputMethodAndSubtype_001 err, ${JSON.stringify(err.message)}`); 502 expect().assertFail(); 503 done(); 504 }) 505 }); 506 507 /* 508 * @tc.number inputmethod_test_listInputMethodSubtype_001 509 * @tc.name Test list input method subtypes. 510 * @tc.desc Function test 511 * @tc.level 2 512 */ 513 it('inputmethod_test_listInputMethodSubtype_001', 0, async function (done) { 514 console.info('************* inputmethod_test_listInputMethodSubtype_001 Test start*************'); 515 let inputMethodProperty = { 516 name:bundleName, 517 id:extName 518 }; 519 let inputMethodSetting = inputMethod.getSetting(); 520 inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, subProps) => { 521 if (err) { 522 console.error(`inputmethod_test_listInputMethodSubtype_001 err, ${JSON.stringify(err.message)}`); 523 expect().assertFail(); 524 done(); 525 return; 526 } 527 checkNewImeSubProps(subProps); 528 console.info('************* inputmethod_test_listInputMethodSubtype_001 Test end*************'); 529 done(); 530 }); 531 }); 532 533 /* 534 * @tc.number inputmethod_test_listInputMethodSubtype_002 535 * @tc.name Test list input method subtypes. 536 * @tc.desc Function test 537 * @tc.level 2 538 */ 539 it('inputmethod_test_listInputMethodSubtype_002', 0, async function (done) { 540 console.info('************* inputmethod_test_listInputMethodSubtype_002 Test start*************'); 541 let inputMethodProperty = { 542 name:bundleName1, 543 id:extName1[0] 544 }; 545 let inputMethodSetting = inputMethod.getSetting(); 546 inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((subProps)=>{ 547 checkImeSubProps(subProps); 548 console.info('************* inputmethod_test_listInputMethodSubtype_002 Test end*************'); 549 done(); 550 }).catch((err) => { 551 console.info(`inputmethod_test_listInputMethodSubtype_002 err, ${JSON.stringify(err.message)}`); 552 expect().assertFail(); 553 done(); 554 }); 555 }); 556 557 /* 558 * @tc.number inputmethod_test_showSoftKeyboard_001 559 * @tc.name Test Indicates the input method which will show softboard with callback. 560 * @tc.desc Function test 561 * @tc.level 2 562 */ 563 it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) { 564 console.info('************* inputmethod_test_showSoftKeyboard_001 Test start*************'); 565 let inputMethodCtrl = inputMethod.getInputMethodController(); 566 inputMethodCtrl.showSoftKeyboard((err) => { 567 if (err) { 568 console.info(`inputmethod_test_showSoftKeyboard_001 err, ${JSON.stringify(err.message)}`); 569 expect(err.code === 12800003).assertTrue(); 570 done(); 571 return; 572 } 573 console.info('************* inputmethod_test_showSoftKeyboard_001 Test end*************'); 574 expect().assertFail(); 575 done(); 576 }); 577 }); 578 579 /* 580 * @tc.number inputmethod_test_hideSoftKeyboard_001 581 * @tc.name Test Indicates the input method which will hide softboard with callback. 582 * @tc.desc Function test 583 * @tc.level 2 584 */ 585 it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) { 586 console.info('************* inputmethod_test_hideSoftKeyboard_001 Test start*************'); 587 let inputMethodCtrl = inputMethod.getInputMethodController(); 588 inputMethodCtrl.hideSoftKeyboard((err)=>{ 589 if(err){ 590 console.info(`inputmethod_test_hideSoftKeyboard_001 err, ${JSON.stringify(err)}`); 591 expect(err.code === 12800003).assertTrue(); 592 done(); 593 return; 594 } 595 console.info('************* inputmethod_test_hideSoftKeyboard_001 Test end*************'); 596 expect().assertFail(); 597 done(); 598 }); 599 }); 600 601 /* 602 * @tc.number inputmethod_test_stopInputSession_001 603 * @tc.name Test Indicates the input method which will hides the keyboard. 604 * @tc.desc Function test 605 * @tc.level 2 606 */ 607 it('inputmethod_test_stopInputSession_001', 0, function (done) { 608 console.info('************* inputmethod_test_stopInputSession_001 Test start*************'); 609 let inputMethodCtrl = inputMethod.getController(); 610 inputMethodCtrl.stopInputSession((err, ret) => { 611 if (err) { 612 console.info(`inputmethod_test_stopInputSession_001 err, ${JSON.stringify(err.message)}`); 613 expect(err.code === 12800003).assertTrue(); 614 done(); 615 return; 616 } 617 expect().assertFalse(); 618 console.info('************* inputmethod_test_stopInputSession_001 Test end*************'); 619 done(); 620 }); 621 }); 622 623 624 /* 625 * @tc.number inputmethod_test_showSoftKeyboard_002 626 * @tc.name Test Indicates the input method which will show softboard with Promise. 627 * @tc.desc Function test 628 * @tc.level 2 629 */ 630 it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) { 631 console.info('************* inputmethod_test_showSoftKeyboard_002 Test start*************'); 632 let inputMethodCtrl = inputMethod.getInputMethodController(); 633 inputMethodCtrl.showSoftKeyboard().then(() =>{ 634 console.info('************* inputmethod_test_showSoftKeyboard_002 Test end*************' ); 635 expect().assertFail(); 636 done(); 637 }).catch((err) => { 638 console.info(`inputmethod_test_showSoftKeyboard_002 err, ${JSON.stringify(err.message)}`); 639 expect(err.code === 12800003).assertTrue(); 640 done(); 641 }) 642 }); 643 644 /* 645 * @tc.number inputmethod_test_hideSoftKeyboard_002 646 * @tc.name Test Indicates the input method which will hide softboard with Promise. 647 * @tc.desc Function test 648 * @tc.level 2 649 */ 650 it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) { 651 console.info('************* inputmethod_test_hideSoftKeyboard_002 Test start*************'); 652 let inputMethodCtrl = inputMethod.getInputMethodController(); 653 inputMethodCtrl.hideSoftKeyboard().then(() =>{ 654 console.info('************* inputmethod_test_hideSoftKeyboard_002 Test end*************' ); 655 expect().assertFail(); 656 done(); 657 }).catch((err) => { 658 console.info(`inputmethod_test_hideSoftKeyboard_002 err, ${JSON.stringify(err.message)}`); 659 expect(err.code === 12800003).assertTrue(); 660 done(); 661 }) 662 }); 663 664 /* 665 * @tc.number inputmethod_test_stopInputSession_002 666 * @tc.name Test Indicates the input method which will hides the keyboard. 667 * @tc.desc Function test 668 * @tc.level 2 669 */ 670 it('inputmethod_test_stopInputSession_002', 0, function (done) { 671 console.info('************* inputmethod_test_stopInputSession_002 Test start*************'); 672 let inputMethodCtrl = inputMethod.getController(); 673 inputMethodCtrl.stopInputSession().then((ret) => { 674 expect().assertFail(); 675 console.info('************* inputmethod_test_stopInputSession_002 Test end*************' ); 676 done(); 677 }).catch((err) => { 678 console.info(`inputmethod_test_stopInputSession_002 err, ${JSON.stringify(err.message)}`); 679 expect(err.code === 12800003).assertTrue(); 680 done(); 681 }) 682 }); 683 684 /* 685 * @tc.number inputmethod_test_switchInputMethod_002 686 * @tc.name Switch to ime before testcases run. 687 * @tc.desc Function test 688 * @tc.level 2 689 */ 690 it('inputmethod_test_switchInputMethod_002', 0, async function (done) { 691 console.info('************* inputmethod_test_switchInputMethod_002 Test start*************'); 692 inputMethod.switchInputMethod(propertyBeforeSwitch).then(ret => { 693 expect(ret).assertTrue(); 694 let property = inputMethod.getCurrentInputMethod(); 695 expect(property.name).assertEqual(propertyBeforeSwitch.name); 696 expect(property.id).assertEqual(propertyBeforeSwitch.id); 697 console.info('************* inputmethod_test_switchInputMethod_001 Test end*************'); 698 done(); 699 }).catch( err=> { 700 console.info(`inputmethod_test_switchInputMethod_001 err: ${JSON.stringify(err.message)}`); 701 expect().assertFail(); 702 }) 703 }); 704 705 /* 706 * @tc.number inputmethod_test_attach_001 707 * @tc.name Test whether the current application can be bound with the default input method. 708 * @tc.desc Function test 709 * @tc.level 0 710 */ 711 it('inputmethod_test_attach_001', 0, async function (done) { 712 console.info('************* inputmethod_test_attach_001 Test start*************'); 713 let inputMethodCtrl = inputMethod.getInputMethodController(); 714 let attribute = { 715 textInputType: inputMethod.TextInputType.TEXT, 716 enterKeyType: inputMethod.EnterKeyType.NONE 717 }; 718 let textConfig = { 719 inputAttribute: attribute 720 }; 721 try { 722 inputMethodCtrl.attach(false, textConfig, (err)=>{ 723 if (err) { 724 console.info(`inputmethod_test_attach_001 result: ${JSON.stringify(err)}`); 725 expect().assertFail(); 726 done(); 727 } 728 console.info('************* inputmethod_test_attach_001 Test end*************'); 729 expect(true).assertTrue(); 730 done(); 731 }); 732 } catch (error) { 733 console.info(`inputmethod_test_attach_001 error, result: ${JSON.stringify(error)}`); 734 expect().assertFail(); 735 done(); 736 } 737 }); 738 739 /* 740 * @tc.number inputmethod_test_attach_002 741 * @tc.name Test whether the current application can be bound with the default input method. 742 * @tc.desc Function test 743 * @tc.level 0 744 */ 745 it('inputmethod_test_attach_002', 0, async function (done) { 746 console.info('************* inputmethod_test_attach_002 Test start*************'); 747 let inputMethodCtrl = inputMethod.getInputMethodController(); 748 let attribute = { 749 textInputType: inputMethod.TextInputType.TEXT, 750 enterKeyType: inputMethod.EnterKeyType.NONE 751 }; 752 let textConfig = { 753 inputAttribute: attribute 754 }; 755 try { 756 inputMethodCtrl.attach(false, textConfig).then(()=>{ 757 console.info('************* inputmethod_test_attach_002 Test end*************'); 758 expect(true).assertTrue(); 759 done(); 760 }).catch((err) => { 761 console.info(`inputmethod_test_attach_002 err result: ${JSON.stringify(err)}`); 762 expect().assertFail(); 763 done(); 764 }) 765 } catch (error) { 766 console.info(`inputmethod_test_attach_002 error result: ${JSON.stringify(error)}`); 767 expect().assertFail(); 768 done(); 769 } 770 }); 771 772 /* 773 * @tc.number inputmethod_test_detach_001 774 * @tc.name Test whether it can successfully unbind with input method. 775 * @tc.desc Function test 776 * @tc.level 0 777 */ 778 it('inputmethod_test_detach_001', 0, async function (done) { 779 console.info('************* inputmethod_test_detach_001 Test start*************'); 780 let inputMethodCtrl = inputMethod.getController(); 781 inputMethodCtrl.detach((err) => { 782 if (err) { 783 console.info(`inputmethod_test_detach_001 result: ${JSON.stringify(err)}`); 784 expect().assertFail(); 785 done(); 786 } 787 console.info('inputmethod_test_detach_001 callback success'); 788 expect(true).assertTrue(); 789 done(); 790 }); 791 }); 792 793 /* 794 * @tc.number inputmethod_test_detach_002 795 * @tc.name Test whether the keyboard is hide successfully. 796 * @tc.desc Function test 797 * @tc.level 0 798 */ 799 it('inputmethod_test_detach_002', 0, async function (done) { 800 console.info('************* inputmethod_test_detach_002 Test start*************'); 801 let inputMethodCtrl = inputMethod.getController(); 802 console.info(`inputmethod_test_detach_002 result: ${JSON.stringify(inputMethodCtrl)}`); 803 inputMethodCtrl.detach().then(() => { 804 console.info('inputmethod_test_detach_002 promise success.'); 805 expect(true).assertTrue(); 806 done(); 807 }).catch((err) => { 808 console.info(`inputmethod_test_detach_002 result: ${JSON.stringify(err)}`); 809 expect().assertFail(); 810 done(); 811 }); 812 }); 813 814 /* 815 * @tc.number inputmethod_test_showTextInput_001 816 * @tc.name Test whether the keyboard is displayed successfully. 817 * @tc.desc Function test 818 * @tc.level 0 819 */ 820 it('inputmethod_test_showTextInput_001', 0, async function (done) { 821 console.info('************* inputmethod_test_showTextInput_001 Test start*************'); 822 let inputMethodCtrl = inputMethod.getController(); 823 inputMethodCtrl.showTextInput((err) => { 824 console.info(`inputmethod_test_detach_002 result: ${JSON.stringify(err)}`); 825 if (err.code === 12800009) { 826 console.info(`inputmethod_test_detach_002 err.code === 12800009.`); 827 expect(true).assertTrue(); 828 } else { 829 expect().assertFail(); 830 } 831 done(); 832 }) 833 }); 834 835 /* 836 * @tc.number inputmethod_test_hideTextInput_001 837 * @tc.name Test whether the keyboard is hidden successfully. 838 * @tc.desc Function test 839 * @tc.level 0 840 */ 841 it('inputmethod_test_hideTextInput_001', 0, async function (done) { 842 console.info('************* inputmethod_test_hideTextInput_001 Test start*************'); 843 let inputMethodCtrl = inputMethod.getController(); 844 inputMethodCtrl.hideTextInput((err) => { 845 console.info(`inputmethod_test_hideTextInput_001 err: ${JSON.stringify(err)}`); 846 if (err.code === 12800009) { 847 expect(true).assertTrue(); 848 } else { 849 expect().assertFail(); 850 } 851 done(); 852 }) 853 }); 854 855 /* 856 * @tc.number inputmethod_test_setCallingWindow_001 857 * @tc.name Test whether set calling window successfully. 858 * @tc.desc Function test 859 * @tc.level 0 860 */ 861 it('inputmethod_test_setCallingWindow_001', 0, async function (done) { 862 console.info('************* inputmethod_test_setCallingWindow_001 Test start*************'); 863 let inputMethodCtrl = inputMethod.getController(); 864 let windowId = 100; 865 try { 866 inputMethodCtrl.setCallingWindow(windowId, (err) => { 867 console.info(`inputmethod_test_setCallingWindow_001 err: ${JSON.stringify(err)}`); 868 if (err.code === 12800009) { 869 expect(true).assertTrue(); 870 } else { 871 expect().assertFail(); 872 } 873 done(); 874 }) 875 } catch (error) { 876 console.info(`inputmethod_test_setCallingWindow_001 result: ${JSON.stringify(error)}`); 877 expect().assertFail(); 878 done(); 879 } 880 }); 881 882 /* 883 * @tc.number inputmethod_test_setCallingWindow_002 884 * @tc.name Test whether set calling window successfully when type of param is wrong. 885 * @tc.desc Function test 886 * @tc.level 2 887 */ 888 it('inputmethod_test_setCallingWindow_002', 0, async function (done) { 889 console.info('************* inputmethod_test_setCallingWindow_002 Test start*************'); 890 let inputMethodCtrl = inputMethod.getController(); 891 let windowId = '100'; 892 try { 893 inputMethodCtrl.setCallingWindow(windowId, (err) => { 894 expect().assertFail(); 895 done(); 896 }) 897 } catch (error) { 898 console.info(`inputmethod_test_setCallingWindow_002 result: ${JSON.stringify(error)}`); 899 expect(true).assertTrue(); 900 done(); 901 } 902 }); 903 904 /* 905 * @tc.number inputmethod_test_updateCursor_001 906 * @tc.name Test whether update cursor successfully. 907 * @tc.desc Function test 908 * @tc.level 2 909 */ 910 it('inputmethod_test_updateCursor_001', 0, async function (done) { 911 console.info('************* inputmethod_test_updateCursor_001 Test start*************'); 912 let inputMethodCtrl = inputMethod.getController(); 913 let cursorInfo = { left: 100, top: 110, width: 600, height: 800 }; 914 try { 915 inputMethodCtrl.updateCursor(cursorInfo, (err) => { 916 if (err.code === 12800009) { 917 expect(true).assertTrue(); 918 } else { 919 expect().assertFail(); 920 } 921 done(); 922 }) 923 } catch (error) { 924 console.info(`inputmethod_test_updateCursor_001 result: ${JSON.stringify(error)}`); 925 expect().assertFail(); 926 done(); 927 } 928 }); 929 930 /* 931 * @tc.number inputmethod_test_changeSelection_001 932 * @tc.name Test whether change selection successfully. 933 * @tc.desc Function test 934 * @tc.level 2 935 */ 936 it('inputmethod_test_changeSelection_001', 0, async function (done) { 937 console.info('************* inputmethod_test_changeSelection_001 Test start*************'); 938 let inputMethodCtrl = inputMethod.getController(); 939 let text = 'test'; 940 let start = 0; 941 let end = 5; 942 try { 943 inputMethodCtrl.changeSelection(text, start, end, (err) => { 944 if (err.code === 12800009) { 945 expect(true).assertTrue(); 946 } else { 947 expect().assertFail(); 948 } 949 done(); 950 }); 951 } catch (error) { 952 console.info(`inputmethod_test_changeSelection_001 result: ${JSON.stringify(error)}`); 953 expect().assertFail(); 954 done(); 955 } 956 }); 957 958 /* 959 * @tc.number inputmethod_test_updateAttribute 960 * @tc.name Test whether update attribute successfully. 961 * @tc.desc Function test 962 * @tc.level 2 963 */ 964 it('inputmethod_test_updateAttribute', 0, async function (done) { 965 console.info('************* inputmethod_test_updateAttribute Test start*************'); 966 let inputMethodCtrl = inputMethod.getController(); 967 let attribute = {textInputType: inputMethod.TextInputType.TEXT, enterKeyType: inputMethod.EnterKeyType.NONE}; 968 try { 969 inputMethodCtrl.updateAttribute(attribute, (err) => { 970 if (err.code === 12800009) { 971 expect(true).assertTrue(); 972 } else { 973 expect().assertFail(); 974 } 975 done(); 976 }); 977 } catch (error) { 978 console.info(`inputmethod_test_updateAttribute result: ${JSON.stringify(error)}`); 979 expect().assertFail(); 980 done(); 981 } 982 }); 983 984 /* 985 * @tc.number inputmethod_test_on_insertText_001 986 * @tc.name Test whether the register the callback of the input method is valid. 987 * @tc.desc Function test 988 * @tc.level 2 989 */ 990 it('inputmethod_test_on_insertText_001', 0, async function (done) { 991 let inputMethodCtrl = inputMethod.getController(); 992 try { 993 inputMethodCtrl.on('insertText', (text) => { 994 }); 995 expect().assertFail(); 996 done(); 997 } catch (error) { 998 console.info(`inputmethod_test_on_insertText_001 result: ${JSON.stringify(error)}`); 999 expect(error.code === 12800009).assertTrue(); 1000 done(); 1001 } 1002 }); 1003 1004 /* 1005 * @tc.number inputmethod_test_on_deleteLeft_001 1006 * @tc.name Test whether the register the callback of the input method is valid. 1007 * @tc.desc Function test 1008 * @tc.level 2 1009 */ 1010 it('inputmethod_test_on_deleteLeft_001', 0, async function (done) { 1011 let inputMethodCtrl = inputMethod.getController(); 1012 try { 1013 inputMethodCtrl.on('deleteLeft', (length) => {}); 1014 expect().assertFail(); 1015 done(); 1016 } catch (error) { 1017 console.info(`inputmethod_test_on_deleteLeft_001 result: ${JSON.stringify(error)}`); 1018 expect(error.code === 12800009).assertTrue(); 1019 done(); 1020 } 1021 }); 1022 1023 /* 1024 * @tc.number inputmethod_test_on_deleteRight_001 1025 * @tc.name Test whether the register the callback of the input method is valid. 1026 * @tc.desc Function test 1027 * @tc.level 2 1028 */ 1029 it('inputmethod_test_on_deleteRight_001', 0, async function (done) { 1030 let inputMethodCtrl = inputMethod.getController(); 1031 try { 1032 inputMethodCtrl.on('deleteRight', (length) => {}); 1033 expect().assertFail(); 1034 done(); 1035 } catch (error) { 1036 console.info(`inputmethod_test_on_deleteRight_001 result: ${JSON.stringify(error)}`); 1037 expect(error.code === 12800009).assertTrue(); 1038 done(); 1039 } 1040 }); 1041 1042 /* 1043 * @tc.number inputmethod_test_on_sendKeyboardStatus_001 1044 * @tc.name Test whether the register the callback of the input method is valid. 1045 * @tc.desc Function test 1046 * @tc.level 2 1047 */ 1048 it('inputmethod_test_on_sendKeyboardStatus_001', 0, async function (done) { 1049 let inputMethodCtrl = inputMethod.getController(); 1050 try { 1051 inputMethodCtrl.on('sendKeyboardStatus', (status) => {}); 1052 expect().assertFail(); 1053 done(); 1054 } catch (error) { 1055 console.info(`inputmethod_test_on_sendKeyboardStatus_001 result: ${JSON.stringify(error)}`); 1056 expect(error.code === 12800009).assertTrue(); 1057 done(); 1058 } 1059 }); 1060 1061 /* 1062 * @tc.number inputmethod_test_on_sendKeyboardStatus_001 1063 * @tc.name Test whether the register the callback of the input method is valid. 1064 * @tc.desc Function test 1065 * @tc.level 2 1066 */ 1067 it('inputmethod_test_on_sendFunctionKey_001', 0, async function (done) { 1068 let inputMethodCtrl = inputMethod.getController(); 1069 try { 1070 inputMethodCtrl.on('sendFunctionKey', (functionKey) => {}); 1071 expect().assertFail(); 1072 done(); 1073 } catch (error) { 1074 console.info(`inputmethod_test_on_sendFunctionKey_001 result: ${JSON.stringify(error)}`); 1075 expect(error.code === 12800009).assertTrue(); 1076 done(); 1077 } 1078 }); 1079 1080 /* 1081 * @tc.number inputmethod_test_on_moveCursor_001 1082 * @tc.name Test whether the register the callback of the input method is valid. 1083 * @tc.desc Function test 1084 * @tc.level 2 1085 */ 1086 it('inputmethod_test_on_moveCursor_001', 0, async function (done) { 1087 let inputMethodCtrl = inputMethod.getController(); 1088 try { 1089 inputMethodCtrl.on('moveCursor', (direction) => {}); 1090 expect().assertFail(); 1091 done(); 1092 } catch (error) { 1093 console.info(`inputmethod_test_on_moveCursor_001 result: ${JSON.stringify(error)}`); 1094 expect(error.code === 12800009).assertTrue(); 1095 done(); 1096 } 1097 }); 1098 1099 /* 1100 * @tc.number inputmethod_test_on_handleExtendAction_001 1101 * @tc.name Test whether the register the callback of the input method is valid. 1102 * @tc.desc Function test 1103 * @tc.level 2 1104 */ 1105 it('inputmethod_test_on_handleExtendAction_001', 0, async function (done) { 1106 let inputMethodCtrl = inputMethod.getController(); 1107 try { 1108 inputMethodCtrl.on('handleExtendAction', (action) => {}); 1109 expect().assertFail(); 1110 done(); 1111 } catch (error) { 1112 console.info(`inputmethod_test_on_handleExtendAction_001 result: ${JSON.stringify(error)}`); 1113 expect(error.code === 12800009).assertTrue(); 1114 done(); 1115 } 1116 }); 1117 1118 /* 1119 * @tc.number inputmethod_test_off_001 1120 * @tc.name Test whether the unregister the callback of the input method is valid. 1121 * @tc.desc Function test 1122 * @tc.level 2 1123 */ 1124 it('inputmethod_test_off_001', 0, async function (done) { 1125 let inputMethodCtrl = inputMethod.getController(); 1126 try { 1127 inputMethodCtrl.off('insertText'); 1128 inputMethodCtrl.off('deleteLeft'); 1129 inputMethodCtrl.off('deleteRight'); 1130 inputMethodCtrl.off('sendKeyboardStatus'); 1131 inputMethodCtrl.off('sendFunctionKey'); 1132 inputMethodCtrl.off('moveCursor'); 1133 inputMethodCtrl.off('handleExtendAction'); 1134 expect(true).assertTrue(); 1135 done(); 1136 } catch(error) { 1137 console.info(`inputmethod_test_off_001 result: ${JSON.stringify(error)}`); 1138 expect().assertFail(); 1139 done(); 1140 } 1141 }); 1142 1143 /* 1144 * @tc.number inputmethod_settings_test_on_imeShow_001 1145 * @tc.name Test whether the register the callback of the input method is valid. 1146 * @tc.desc Function test 1147 * @tc.level 2 1148 */ 1149 it('inputmethod_setting_test_on_imeShow_001', 0, async function (done) { 1150 let inputMethodSetting = inputMethod.getSetting(); 1151 try { 1152 inputMethodSetting.on('imeShow', (info) => {}); 1153 expect(true).assertTrue(); 1154 done(); 1155 } catch (error) { 1156 console.info(`inputmethod_setting_test_on_imeShow_001 result: ${JSON.stringify(error)}`); 1157 expect().assertFail(); 1158 done(); 1159 } 1160 }); 1161 1162 /* 1163 * @tc.number inputmethod_settings_test_on_imeHide_001 1164 * @tc.name Test whether the register the callback of the input method is valid. 1165 * @tc.desc Function test 1166 * @tc.level 2 1167 */ 1168 it('inputmethod_setting_test_on_imeHide_001', 0, async function (done) { 1169 let inputMethodSetting = inputMethod.getSetting(); 1170 try { 1171 inputMethodSetting.on('imeHide', (info) => {}); 1172 expect(true).assertTrue(); 1173 done(); 1174 } catch (error) { 1175 console.info(`inputmethod_setting_test_on_imeHide_001 result: ${JSON.stringify(error)}`); 1176 expect().assertFail(); 1177 done(); 1178 } 1179 }); 1180 1181 /* 1182 * @tc.number inputmethod_test_getDefaultInputMethod_001 1183 * @tc.name Test Indicates the getDefaultInputMethod. 1184 * @tc.desc Function test 1185 * @tc.level 1 1186 */ 1187 it('inputmethod_test_getDefaultInputMethod_001', 0, async function (done) { 1188 console.info('************* inputmethod_test_getDefaultInputMethod_001 Test start*************'); 1189 try { 1190 let property = inputMethod.getDefaultInputMethod(); 1191 if (property.name.length > 0) { 1192 expect(true).assertTrue(); 1193 } 1194 console.info('************* inputmethod_test_getDefaultInputMethod_001 Test end*************'); 1195 } catch (error) { 1196 if(error) { 1197 console.info(`inputmethod_test_getDefaultInputMethod_001 error, result: ${JSON.stringify(error)}`); 1198 expect().assertFail(); 1199 } 1200 } finally { 1201 done(); 1202 } 1203 }); 1204 1205 /* 1206 * @tc.number inputmethod_test_getSystemInputMethodConfigAbility_001 1207 * @tc.name Test Indicates the getSystemInputMethodConfigAbility. 1208 * @tc.desc Function test 1209 * @tc.level 1 1210 */ 1211 it('inputmethod_test_getSystemInputMethodConfigAbility_001', 0, async function (done) { 1212 console.info('************* inputmethod_test_getSystemInputMethodConfigAbility_001 Test start*************'); 1213 try { 1214 let systemInputMethodConfigAbility = inputMethod.getSystemInputMethodConfigAbility(); 1215 console.info('************* inputmethod_test_getSystemInputMethodConfigAbility_001 Test end*************'); 1216 expect(true).assertTrue(); 1217 done(); 1218 } catch (error) { 1219 if(error) { 1220 console.info(`inputmethod_test_getSystemInputMethodConfigAbility_001 error, result: ${JSON.stringify(error)}`); 1221 expect().assertFail(); 1222 } 1223 } finally { 1224 done(); 1225 } 1226 }); 1227 1228 /* 1229 * @tc.number inputmethod_test_enableInputMethod_001 1230 * @tc.name Test param num abnormal 1231 * @tc.desc Function test 1232 * @tc.level 2 1233 */ 1234 it('inputmethod_test_enableInputMethod_001', 0, async function (done) { 1235 console.info('************* inputmethod_test_enableInputMethod_001 Test start*************'); 1236 try { 1237 inputMethod.getSetting().enableInputMethod("bundleName", "extName").then(() => { 1238 console.info('Succeeded in enable inputmethod.'); 1239 expect().assertFail(); 1240 done(); 1241 }).catch((err) => { 1242 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1243 expect().assertFail(); 1244 done(); 1245 }) 1246 } catch (err) { 1247 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1248 expect(err.code === 401).assertTrue(); 1249 expect(err.message === "the parameters check fails. at least three parameters is required!").assertTrue(); 1250 done(); 1251 } 1252 }); 1253 1254 /* 1255 * @tc.number inputmethod_test_enableInputMethod_002 1256 * @tc.name Test first param type abnormal 1257 * @tc.desc Function test 1258 * @tc.level 2 1259 */ 1260 it('inputmethod_test_enableInputMethod_002', 0, async function (done) { 1261 console.info('************* inputmethod_test_enableInputMethod_002 Test start*************'); 1262 try { 1263 inputMethod.getSetting().enableInputMethod(undefined, "extName", inputMethod.EnabledState.BASIC_MODE).then(() => { 1264 console.info('Succeeded in enable inputmethod.'); 1265 expect().assertFail(); 1266 done(); 1267 }).catch((err) => { 1268 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1269 expect().assertFail(); 1270 done(); 1271 }) 1272 } catch (err) { 1273 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1274 expect(err.code === 401).assertTrue(); 1275 expect(err.message === "the parameters check fails. bundleName type must be string!").assertTrue(); 1276 done(); 1277 } 1278 }); 1279 1280 /* 1281 * @tc.number inputmethod_test_enableInputMethod_003 1282 * @tc.name Test second param type abnormal 1283 * @tc.desc Function test 1284 * @tc.level 2 1285 */ 1286 it('inputmethod_test_enableInputMethod_003', 0, async function (done) { 1287 console.info('************* inputmethod_test_enableInputMethod_003 Test start*************'); 1288 try { 1289 inputMethod.getSetting().enableInputMethod("bundleName", undefined, inputMethod.EnabledState.BASIC_MODE).then(() => { 1290 console.info('Succeeded in enable inputmethod.'); 1291 expect().assertFail(); 1292 done(); 1293 }).catch((err) => { 1294 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1295 expect().assertFail(); 1296 done(); 1297 }) 1298 } catch (err) { 1299 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1300 expect(err.code === 401).assertTrue(); 1301 expect(err.message === "the parameters check fails. extensionName type must be string!").assertTrue(); 1302 done(); 1303 } 1304 }); 1305 1306 /* 1307 * @tc.number inputmethod_test_enableInputMethod_004 1308 * @tc.name Test third param type abnormal 1309 * @tc.desc Function test 1310 * @tc.level 2 1311 */ 1312 it('inputmethod_test_enableInputMethod_004', 0, async function (done) { 1313 console.info('************* inputmethod_test_enableInputMethod_004 Test start*************'); 1314 try { 1315 inputMethod.getSetting().enableInputMethod("bundleName", "extName", 5).then(() => { 1316 console.info('Succeeded in enable inputmethod.'); 1317 expect().assertFail(); 1318 done(); 1319 }).catch((err) => { 1320 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1321 expect().assertFail(); 1322 done(); 1323 }) 1324 } catch (err) { 1325 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1326 expect(err.code === 401).assertTrue(); 1327 expect(err.message === "the parameters check fails. enabledState type must be EnabledState!").assertTrue(); 1328 done(); 1329 } 1330 }); 1331 1332 /* 1333 * @tc.number inputmethod_test_enableInputMethod_005 1334 * @tc.name Test the ime not found 1335 * @tc.desc Function test 1336 * @tc.level 2 1337 */ 1338 it('inputmethod_test_enableInputMethod_005', 0, async function (done) { 1339 console.info('************* inputmethod_test_enableInputMethod_005 Test start*************'); 1340 try { 1341 inputMethod.getSetting().enableInputMethod("", "", inputMethod.EnabledState.BASIC_MODE).then(() => { 1342 console.info('Succeeded in enable inputmethod.'); 1343 expect().assertFail(); 1344 done(); 1345 }).catch((err) => { 1346 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1347 expect(err.code === 12800018).assertTrue(); 1348 done(); 1349 }) 1350 } catch (err) { 1351 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1352 expect().assertFail(); 1353 done(); 1354 } 1355 }); 1356 1357 /* 1358 * @tc.number inputmethod_test_enableInputMethod_006 1359 * @tc.name Test the ime not found 1360 * @tc.desc Function test 1361 * @tc.level 2 1362 */ 1363 it('inputmethod_test_enableInputMethod_006', 0, async function (done) { 1364 console.info('************* inputmethod_test_enableInputMethod_006 Test start*************'); 1365 try { 1366 inputMethod.getSetting().enableInputMethod("bundleName", "", inputMethod.EnabledState.BASIC_MODE).then(() => { 1367 console.info('Succeeded in enable inputmethod.'); 1368 expect().assertFail(); 1369 done(); 1370 }).catch((err) => { 1371 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1372 expect(err.code === 12800018).assertTrue(); 1373 done(); 1374 }) 1375 } catch (err) { 1376 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1377 expect().assertFail(); 1378 done(); 1379 } 1380 }); 1381 1382 /* 1383 * @tc.number inputmethod_test_enableInputMethod_007 1384 * @tc.name Test the ime not found 1385 * @tc.desc Function test 1386 * @tc.level 2 1387 */ 1388 it('inputmethod_test_enableInputMethod_007', 0, async function (done) { 1389 console.info('************* inputmethod_test_enableInputMethod_007 Test start*************'); 1390 try { 1391 inputMethod.getSetting().enableInputMethod("", "extName", inputMethod.EnabledState.BASIC_MODE).then(() => { 1392 console.info('Succeeded in enable inputmethod.'); 1393 expect().assertFail(); 1394 done(); 1395 }).catch((err) => { 1396 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1397 expect(err.code === 12800018).assertTrue(); 1398 done(); 1399 }) 1400 } catch (err) { 1401 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1402 expect().assertFail(); 1403 done(); 1404 } 1405 }); 1406 1407 /* 1408 * @tc.number inputmethod_test_enableInputMethod_008 1409 * @tc.name Test the ime not found 1410 * @tc.desc Function test 1411 * @tc.level 2 1412 */ 1413 it('inputmethod_test_enableInputMethod_008', 0, async function (done) { 1414 console.info('************* inputmethod_test_enableInputMethod_008 Test start*************'); 1415 try { 1416 let currentIme = inputMethod.getCurrentInputMethod(); 1417 inputMethod.getSetting().enableInputMethod("bundleName", currentIme.id, inputMethod.EnabledState.BASIC_MODE).then(() => { 1418 console.info('Succeeded in enable inputmethod.'); 1419 expect().assertFail(); 1420 done(); 1421 }).catch((err) => { 1422 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1423 expect(err.code === 12800018).assertTrue(); 1424 done(); 1425 }) 1426 } catch (err) { 1427 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1428 expect().assertFail(); 1429 done(); 1430 } 1431 }); 1432 1433 /* 1434 * @tc.number inputmethod_test_enableInputMethod_009 1435 * @tc.name Test the ime not found 1436 * @tc.desc Function test 1437 * @tc.level 2 1438 */ 1439 it('inputmethod_test_enableInputMethod_009', 0, async function (done) { 1440 console.info('************* inputmethod_test_enableInputMethod_009 Test start*************'); 1441 try { 1442 let currentIme = inputMethod.getCurrentInputMethod(); 1443 inputMethod.getSetting().enableInputMethod(currentIme.name, "extName", inputMethod.EnabledState.BASIC_MODE).then(() => { 1444 console.info('Succeeded in enable inputmethod.'); 1445 expect().assertFail(); 1446 done(); 1447 }).catch((err) => { 1448 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1449 expect(err.code === 12800018).assertTrue(); 1450 done(); 1451 }) 1452 } catch (err) { 1453 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1454 expect().assertFail(); 1455 done(); 1456 } 1457 }); 1458 1459 /* 1460 * @tc.number inputmethod_test_enableInputMethod_010 1461 * @tc.name enable success 1462 * @tc.desc Function test 1463 * @tc.level 1 1464 */ 1465 it('inputmethod_test_enableInputMethod_010', 0, async function (done) { 1466 console.info('************* inputmethod_test_enableInputMethod_010 Test start*************'); 1467 try { 1468 let inputMethodProperty = { 1469 name: bundleName1, 1470 id: extName1[0] 1471 }; 1472 let currentIme = inputMethod.getCurrentInputMethod(); 1473 console.info(`currentIme: ${JSON.stringify(currentIme)}`); 1474 inputMethod.getSetting().enableInputMethod(inputMethodProperty.name, inputMethodProperty.id, currentIme.enabledState).then(() => { 1475 console.info('Succeeded in enable inputmethod.'); 1476 expect(true).assertTrue(); 1477 done(); 1478 }).catch((err) => { 1479 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1480 expect().assertFail(); 1481 done(); 1482 }) 1483 } catch (err) { 1484 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1485 expect().assertFail(); 1486 done(); 1487 } 1488 }); 1489 1490 /* 1491 * @tc.number inputmethod_test_enableInputMethod_011 1492 * @tc.name preconfigured default input method cannot be disabled 1493 * @tc.desc Function test 1494 * @tc.level 1 1495 */ 1496 it('inputmethod_test_enableInputMethod_011', 0, async function (done) { 1497 console.info('************* inputmethod_test_enableInputMethod_011 Test start*************'); 1498 try { 1499 let defaultIme = inputMethod.getDefaultInputMethod(); 1500 inputMethod.getSetting().enableInputMethod(defaultIme.name, defaultIme.id, inputMethod.EnabledState.DISABLED).then(() => { 1501 console.info('Succeeded in enable inputmethod.'); 1502 expect().assertFail(); 1503 done(); 1504 }).catch((err) => { 1505 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1506 expect(err.code === 12800019).assertTrue(); 1507 done(); 1508 }) 1509 } catch (err) { 1510 console.error(`Failed to enableInputMethod. Code: ${err.code}, message: ${err.message}`); 1511 expect().assertFail(); 1512 done(); 1513 } 1514 }); 1515 1516 /* 1517 * @tc.number inputmethod_test_setSimpleKeyboardEnabled_001 1518 * @tc.name Set simple keyboard mode. 1519 * @tc.desc Function test 1520 * @tc.level 1 1521 */ 1522 it('inputmethod_test_setSimpleKeyboardEnabled_001', 0, async function (done) { 1523 console.info('************* inputmethod_test_setSimpleKeyboardEnabled_001 Test start*************'); 1524 inputMethod.setSimpleKeyboardEnabled(true); 1525 expect(true).assertTrue(); 1526 done(); 1527 inputMethod.setSimpleKeyboardEnabled(false); 1528 expect(true).assertTrue(); 1529 done(); 1530 inputMethod.setSimpleKeyboardEnabled(null); 1531 expect(true).assertTrue(); 1532 done(); 1533 console.info('************* inputmethod_test_setSimpleKeyboardEnabled_001 Test end*************'); 1534 1535 }); 1536});