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