• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import inputMethod from '@ohos.inputMethod';
17import commonEventManager from '@ohos.commonEventManager';
18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index';
19import { PanelInfo, PanelFlag, PanelType } from '@ohos.inputMethod.Panel';
20
21describe('InputMethodWithAttachTest', function () {
22  const WAIT_DEAL_OK = 500;
23  const TEST_RESULT_CODE = 0;
24  const TEST_FUNCTION = {
25    INSERT_TEXT_SYNC: 0,
26    MOVE_CURSOR_SYNC: 1,
27    GET_ATTRIBUTE_SYNC: 2,
28    SELECT_BY_RANGE_SYNC: 3,
29    SELECT_BY_MOVEMENT_SYNC: 4,
30    GET_INDEX_AT_CURSOR_SYNC: 5,
31    DELETE_FORWARD_SYNC: 6,
32    DELETE_BACKWARD_SYNC: 7,
33    GET_FORWARD_SYNC: 8,
34    GET_BACKWARD_SYNC: 9,
35    CHANGE_FLAG_TO_FIXED: 10,
36    CHANGE_FLAG_TO_FLOATING: 11,
37    SETPRIVACYMODE_WITHOUT_PERMISSION: 12,
38    SETPRIVACYMODE_ERROR_PARAM: 13,
39    ADJUST_WITH_INVALID_FLAG: 14,
40    ADJUST_WITH_NON_FULL_SCREEN_NO_PANEL_RECT: 15,
41    ADJUST_WITH_FULL_SCREEN_NO_AVOID_Y: 16,
42    ADJUST_WITH_INVALID_AVOID_Y:17,
43    ADJUST_WITH_INVALID_TYPE:18,
44    ADJUST_SUCCESS: 19,
45    SET_PREVIEW_TEXT: 20,
46    FINISH_TEXT_PREVIEW: 21,
47    SET_KEEP_SCREEN_ON: 22
48  }
49
50  beforeAll(async function (done) {
51    console.info('beforeAll called');
52    let inputMethodProperty = {
53      name: 'com.example.testIme',
54      id: 'InputMethodExtAbility'
55    };
56    await inputMethod.switchInputMethod(inputMethodProperty);
57    let inputMethodCtrl = inputMethod.getController();
58    inputMethodCtrl.on('finishTextPreview', () => {});
59    inputMethodCtrl.on('setPreviewText', () => {});
60    setTimeout(() => {
61      done();
62    }, WAIT_DEAL_OK);
63  });
64
65  afterAll(async function () {
66    console.info('afterAll called');
67    let inputMethodSetting = inputMethod.getInputMethodSetting();
68    let props = await inputMethodSetting.listInputMethod();
69    let bundleName = 'com.example.newTestIme';
70    let bundleName1 = 'com.example.testIme';
71    for (let i = 0; i < props.length; i++) {
72      let prop = props[i];
73      if (prop.name !== bundleName && prop.name !== bundleName1) {
74        await inputMethod.switchInputMethod(prop);
75      }
76    }
77    let inputMethodCtrl = inputMethod.getController();
78    inputMethodCtrl.off('finishTextPreview');
79    inputMethodCtrl.off('setPreviewText');
80  });
81
82  beforeEach(async function () {
83    console.info('beforeEach called');
84    let inputMethodCtrl = inputMethod.getController();
85    let cfg = {
86      inputAttribute:
87        {
88          textInputType: inputMethod.TextInputType.TEXT,
89          enterKeyType: inputMethod.EnterKeyType.NONE
90        }
91    };
92    await inputMethodCtrl.attach(false, cfg);
93  });
94
95  afterEach(async function () {
96    console.info('afterEach called');
97    let inputMethodCtrl = inputMethod.getController();
98    await inputMethodCtrl.detach();
99  });
100
101  function publishCommonEvent(codeNumber) {
102    console.info(`[publishCommonEvent] publish event, codeNumber = ${codeNumber}`);
103    commonEventManager.publish('syncTestFunction', { code: codeNumber }, (err)=>{
104      console.info(`inputMethod publish finish, err = ${JSON.stringify(err)}`);
105    })
106  }
107
108  function subscribe(subscribeInfo, functionCode, done) {
109    commonEventManager.createSubscriber(subscribeInfo).then((data) => {
110      let subscriber = data;
111      commonEventManager.subscribe(subscriber, (err, eventData) => {
112        console.info("inputMethod subscribe");
113        if (eventData.code === TEST_RESULT_CODE) {
114          expect(true).assertTrue();
115        } else {
116          expect().assertFail();
117        }
118        commonEventManager.unsubscribe(subscriber);
119        done();
120      })
121      publishCommonEvent(functionCode);
122    })
123  }
124  /*
125   * @tc.number  inputmethod_with_attach_test_showTextInput_001
126   * @tc.name    Test whether the keyboard is displayed successfully.
127   * @tc.desc    Function test
128   * @tc.level   0
129   */
130  it('inputmethod_with_attach_test_showTextInput_001', 0, async function (done) {
131    console.info('************* inputmethod_with_attach_test_showTextInput_001 Test start*************');
132    let inputMethodCtrl = inputMethod.getController();
133    inputMethodCtrl.showTextInput((err) => {
134      if (err) {
135        console.info(`inputmethod_with_attach_test_showTextInput_001 result: ${JSON.stringify(err)}`);
136        expect().assertFail();
137        done();
138      }
139      console.info('inputmethod_with_attach_test_showTextInput_001 callback success');
140      expect(true).assertTrue();
141      done();
142    });
143  });
144
145  /*
146  * @tc.number  inputmethod_with_attach_test_showTextInput_002
147  * @tc.name    Test whether the keyboard is displayed successfully.
148  * @tc.desc    Function test
149  * @tc.level   0
150  */
151  it('inputmethod_with_attach_test_showTextInput_002', 0, async function (done) {
152    console.info('************* inputmethod_with_attach_test_showTextInput_002 Test start*************');
153    let inputMethodCtrl = inputMethod.getController();
154    inputMethodCtrl.showTextInput().then(() => {
155      console.info('inputmethod_with_attach_test_showTextInput_002 promise success');
156      expect(true).assertTrue();
157      done();
158    }).catch((error) => {
159      console.info(`inputmethod_with_attach_test_showTextInput_002 result: ${JSON.stringify(error)}`);
160      expect().assertFail();
161      done();
162    });
163  });
164
165  /*
166  * @tc.number  inputmethod_with_attach_test_hideTextInput_001
167  * @tc.name    Test whether the keyboard is hide successfully.
168  * @tc.desc    Function test
169  * @tc.level   0
170  */
171  it('inputmethod_with_attach_test_hideTextInput_001', 0, async function (done) {
172    console.info('************* inputmethod_with_attach_test_hideTextInput_001 Test start*************');
173    let inputMethodCtrl = inputMethod.getController();
174    inputMethodCtrl.hideTextInput((err) => {
175      if (err) {
176        console.info(`inputmethod_with_attach_test_hideTextInput_001 result: ${JSON.stringify(err)}`);
177        expect().assertFail();
178        done();
179        return;
180      }
181      console.info('inputmethod_with_attach_test_hideTextInput_001 callback success');
182      expect(true).assertTrue();
183      done();
184    });
185  });
186
187  /*
188  * @tc.number  inputmethod_with_attach_test_hideTextInput_002
189  * @tc.name    Test whether the keyboard is hide successfully.
190  * @tc.desc    Function test
191  * @tc.level   0
192  */
193  it('inputmethod_with_attach_test_hideTextInput_002', 0, async function (done) {
194    console.info('************* inputmethod_with_attach_test_hideTextInput_002 Test start*************');
195    let inputMethodCtrl = inputMethod.getController();
196    inputMethodCtrl.hideTextInput().then(() => {
197      console.info('inputmethod_with_attach_test_hideTextInput_002 promise success');
198      expect(true).assertTrue();
199      done();
200    }).catch((error) => {
201      console.info(`inputmethod_with_attach_test_hideTextInput_002 result: ${JSON.stringify(error)}`);
202      expect().assertFail();
203      done();
204    });
205  });
206
207  /*
208   * @tc.number  inputmethod_with_attach_test_setCallingWindow_001
209   * @tc.name    Test the window ID of the application that the notification system is currently bound to
210   *     the input method. After setting correctly, whether the window where the client is located can avoid
211   *     the input method window.
212   * @tc.desc    Function test
213   * @tc.level   2
214   */
215  it('inputmethod_with_attach_test_setCallingWindow_001', 0, async function (done) {
216    console.info('************* inputmethod_with_attach_test_setCallingWindow_001 Test start*************');
217    try {
218      let inputMethodCtrl = inputMethod.getController();
219      let windId = 100;
220      inputMethodCtrl.setCallingWindow(windId, (err) => {
221      if (err) {
222        console.info(`inputmethod_with_attach_test_setCallingWindow_001 result: ${JSON.stringify(err)}`);
223        expect().assertFail();
224        done();
225      }
226      console.info('inputmethod_with_attach_test_setCallingWindow_001 callback success');
227      expect(true).assertTrue();
228      done();
229      })
230    } catch (error) {
231      console.info(`inputmethod_with_attach_test_setCallingWindow_001 result: ${JSON.stringify(error)}`);
232      expect().assertFail();
233      done();
234    }
235  });
236
237  /*
238   * @tc.number  inputmethod_with_attach_test_setCallingWindow_002
239   * @tc.name    Test the window ID of the application that the notification system is currently bound to
240   *     the input method. After setting correctly, whether the window where the client is located can avoid
241   *     the input method window.
242   * @tc.desc    Function test
243   * @tc.level   2
244   */
245  it('inputmethod_with_attach_test_setCallingWindow_002', 0, async function (done) {
246    console.info('************* inputmethod_with_attach_test_setCallingWindow_002 Test start*************');
247    try {
248      let inputMethodCtrl = inputMethod.getController();
249      let windId = 100;
250      inputMethodCtrl.setCallingWindow(windId).then(() => {
251        console.info('inputmethod_with_attach_test_setCallingWindow_002 promise success');
252        expect(true).assertTrue();
253        done();
254      }).catch((error) => {
255        console.info(`inputmethod_with_attach_test_setCallingWindow_002 result: ${JSON.stringify(error)}`);
256        expect().assertFail();
257        done();
258      })
259    } catch (error) {
260      console.info(`inputmethod_with_attach_test_setCallingWindow_002 result: ${JSON.stringify(error)}`);
261      expect().assertFail();
262      done();
263    }
264    console.info('************* inputmethod_with_attach_test_setCallingWindow_002 Test end*************');
265  });
266
267  /*
268   * @tc.number  inputmethod_with_attach_test_updateCursor_001
269   * @tc.name    Test whether the notification input method is valid when the current application cursor has changed.
270   * @tc.desc    Function test
271   * @tc.level   2
272   */
273  it('inputmethod_with_attach_test_updateCursor_001', 0, async function (done) {
274    console.info('************* inputmethod_with_attach_test_updateCursor_001 Test start*************');
275    try {
276      let inputMethodCtrl = inputMethod.getController();
277      let cursorInfo = { left: 100, top: 110, width: 600, height: 800 };
278      inputMethodCtrl.updateCursor(cursorInfo, (err) => {
279        if (err) {
280          console.info(`inputmethod_with_attach_test_updateCursor_001 result: ${JSON.stringify(err)}`);
281          expect().assertFail();
282          done();
283          return;
284        }
285        console.info('inputmethod_with_attach_test_updateCursor_001 callback success');
286        expect(true).assertTrue();
287        done();
288      })
289    } catch (error) {
290      console.info(`inputmethod_with_attach_test_updateCursor_001 result: ${JSON.stringify(error)}`);
291      expect().assertFail();
292      done();
293    }
294    console.info('************* inputmethod_with_attach_test_updateCursor_001 Test end*************');
295  });
296
297  /*
298   * @tc.number  inputmethod_with_attach_test_updateCursor_002
299   * @tc.name    Test whether the notification input method is valid when the current application cursor has changed.
300   * @tc.desc    Function test
301   * @tc.level   0
302   */
303  it('inputmethod_with_attach_test_updateCursor_002', 0, async function (done) {
304    console.info('************* inputmethod_with_attach_test_updateCursor_002 Test start*************');
305    try {
306      let inputMethodCtrl = inputMethod.getController();
307      let cursorInfo = { left: 100, top: 110, width: 600, height: 800 };
308      inputMethodCtrl.updateCursor(cursorInfo).then(() => {
309        console.info('inputmethod_with_attach_test_updateCursor_002 promise success');
310        expect(true).assertTrue();
311        done();
312      }).catch((error) => {
313        console.info(`inputmethod_with_attach_test_updateCursor_002 result: ${JSON.stringify(error)}`);
314        expect().assertFail();
315        done();
316      })
317    } catch (error) {
318      console.info(`inputmethod_with_attach_test_updateCursor_002 result: ${JSON.stringify(error)}`);
319      expect().assertFail();
320      done();
321    }
322    console.info('************* inputmethod_with_attach_test_updateCursor_002 Test end*************');
323  });
324
325  /*
326   * @tc.number  inputmethod_with_attach_test_changeSelection_001
327   * @tc.name    Test whether the selection range of the current application text of the notification input
328   *     method has changed.
329   * @tc.desc    Function test
330   * @tc.level   2
331   */
332  it('inputmethod_with_attach_test_changeSelection_001', 0, async function (done) {
333    console.info('************* inputmethod_with_attach_test_changeSelection_001 Test start*************');
334    try {
335      let inputMethodCtrl = inputMethod.getController();
336      let text = 'text';
337      let start = 0;
338      let end = 5;
339      inputMethodCtrl.changeSelection(text, start, end, (err) => {
340        if (err) {
341          console.info(`inputmethod_with_attach_test_changeSelection_001 result: ${JSON.stringify(err)}`);
342          expect().assertFail();
343          done();
344          return;
345        }
346        console.info('inputmethod_with_attach_test_changeSelection_001 callback success');
347        expect(true).assertTrue();
348        done();
349      })
350    } catch (error) {
351      console.info(`inputmethod_with_attach_test_changeSelection_001 result: ${JSON.stringify(error)}`);
352      expect().assertFail();
353      done();
354    }
355    console.info('************* inputmethod_with_attach_test_changeSelection_001 Test end*************');
356  });
357
358  /*
359   * @tc.number  inputmethod_with_attach_test_changeSelection_002
360   * @tc.name    Test whether the selection range of the current application text of the notification input
361   *     method has changed.
362   * @tc.desc    Function test
363   * @tc.level   2
364   */
365  it('inputmethod_with_attach_test_changeSelection_002', 0, async function (done) {
366    console.info('************* inputmethod_with_attach_test_changeSelection_002 Test start*************');
367    try {
368      let inputMethodCtrl = inputMethod.getController();
369      let text = 'text';
370      let start = 0;
371      let end = 5;
372      inputMethodCtrl.changeSelection(text, start, end).then(() => {
373        console.info('inputmethod_with_attach_test_changeSelection_002 promise success');
374        expect(true).assertTrue();
375        done();
376      }).catch((error) => {
377        console.info(`inputmethod_with_attach_test_changeSelection_002 result: ${JSON.stringify(error)}`);
378        expect().assertFail();
379        done();
380      })
381    } catch (error) {
382      console.info(`inputmethod_with_attach_test_changeSelection_002 result: ${JSON.stringify(error)}`);
383      expect().assertFail();
384      done();
385    }
386    console.info('************* inputmethod_with_attach_test_changeSelection_002 Test end*************');
387  });
388
389  /*
390   * @tc.number  inputmethod_with_attach_test_updateAttribute_001
391   * @tc.name    Test whether the InputAttribute information can be updated successfully.
392   * @tc.desc    Function test
393   * @tc.level   2
394   */
395  it('inputmethod_with_attach_test_updateAttribute_001', 0, async function (done) {
396    console.info('************* inputmethod_with_attach_test_updateAttribute_001 Test start*************');
397    try {
398      let inputMethodCtrl = inputMethod.getController();
399      let attribute = { textInputType: inputMethod.TextInputType.TEXT, enterKeyType: inputMethod.EnterKeyType.NONE };
400      inputMethodCtrl.updateAttribute(attribute, (err) => {
401        if (err) {
402          console.info(`inputmethod_with_attach_test_updateAttribute_001 result: ${JSON.stringify(err)}`);
403          expect().assertFail();
404          done();
405          return;
406        }
407        console.info('inputmethod_with_attach_test_updateAttribute_001 callback success');
408        expect(true).assertTrue();
409        done();
410      })
411    } catch (error) {
412      console.info(`inputmethod_with_attach_test_updateAttribute_001 result: ${JSON.stringify(error)}`);
413      expect().assertFail();
414      done();
415    }
416    console.info('************* inputmethod_with_attach_test_updateAttribute_001 Test end*************');
417  });
418
419  /*
420   * @tc.number  inputmethod_with_attach_test_updateAttribute_001
421   * @tc.name    Test whether the InputAttribute information can be updated successfully.
422   * @tc.desc    Function test
423   * @tc.level   2
424   */
425  it('inputmethod_with_attach_test_updateAttribute_001', 0, async function (done) {
426    console.info('************* inputmethod_with_attach_test_updateAttribute_001 Test start*************');
427    try {
428      let inputMethodCtrl = inputMethod.getController();
429      let attribute = { textInputType: 1, enterKeyType: 1 };
430      inputMethodCtrl.updateAttribute(attribute).then(() => {
431        console.info('inputmethod_with_attach_test_updateAttribute_001 promise success');
432        expect(true).assertTrue();
433        done();
434      }).catch((error) => {
435        console.info(`inputmethod_with_attach_test_updateAttribute_001 result: ${JSON.stringify(error)}`);
436        expect().assertFail();
437        done();
438      })
439    } catch (error) {
440      console.info(`inputmethod_with_attach_test_updateAttribute_001 result: ${JSON.stringify(error)}`);
441      expect().assertFail();
442      done();
443    }
444    console.info('************* inputmethod_with_attach_test_updateAttribute_001 Test end*************');
445  });
446
447  /*
448   * @tc.number  inputmethod_test_showSoftKeyboard_001
449   * @tc.name    Test Indicates the input method which will show softboard with callback.
450   * @tc.desc    Function test
451   * @tc.level   2
452   */
453  it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) {
454    console.info('************* inputmethod_test_showSoftKeyboard_001 Test start*************');
455    let inputMethodCtrl = inputMethod.getInputMethodController();
456    inputMethodCtrl.showSoftKeyboard((err)=>{
457      if (err) {
458        console.info(`inputmethod_test_showSoftKeyboard_001 err, ${JSON.stringify(err.message)}`);
459        expect().assertFail();
460        done();
461      }
462      console.info('************* inputmethod_test_showSoftKeyboard_001 Test end*************');
463      expect(true).assertTrue();
464      done();
465    });
466  });
467
468  /*
469   * @tc.number  inputmethod_test_showSoftKeyboard_002
470   * @tc.name    Test Indicates the input method which will show softboard with callback.
471   * @tc.desc    Function test
472   * @tc.level   2
473   */
474  it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) {
475    console.info('************* inputmethod_test_showSoftKeyboard_002 Test start*************');
476    let inputMethodCtrl = inputMethod.getInputMethodController();
477    inputMethodCtrl.showSoftKeyboard().then(()=>{
478      console.info('inputmethod_test_showSoftKeyboard_002 success.');
479      expect(true).assertTrue();
480      done();
481    }).catch((err) => {
482      console.info(`inputmethod_test_showSoftKeyboard_002 err, ${JSON.stringify(err.message)}`);
483      expect().assertFail();
484      done();
485    });
486  });
487
488  /*
489   * @tc.number  inputmethod_test_hideSoftKeyboard_001
490   * @tc.name    Test Indicates the input method which will hide softboard with callback.
491   * @tc.desc    Function test
492   * @tc.level   2
493   */
494  it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) {
495    console.info('************* inputmethod_test_hideSoftKeyboard_001 Test start*************');
496    let inputMethodCtrl = inputMethod.getInputMethodController();
497    inputMethodCtrl.hideSoftKeyboard((err)=>{
498      if(err){
499        console.info(`inputmethod_test_hideSoftKeyboard_001 err, ${JSON.stringify(err.message)}`);
500        expect().assertFail();
501        done();
502      }
503      console.info('************* inputmethod_test_hideSoftKeyboard_001  Test end*************');
504      expect(true).assertTrue();
505      done();
506    });
507  });
508
509  /*
510   * @tc.number  inputmethod_test_hideSoftKeyboard_001
511   * @tc.name    Test Indicates the input method which will hide softboard with callback.
512   * @tc.desc    Function test
513   * @tc.level   2
514   */
515  it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) {
516    console.info('************* inputmethod_test_hideSoftKeyboard_002 Test start*************');
517    let inputMethodCtrl = inputMethod.getInputMethodController();
518    inputMethodCtrl.hideSoftKeyboard().then(()=>{
519      console.info('inputmethod_test_hideSoftKeyboard_002 success.');
520      expect(true).assertTrue();
521      done();
522    }).catch((err) => {
523      console.info(`inputmethod_test_hideSoftKeyboard_002 err, ${JSON.stringify(err.message)}`);
524      expect().assertFail();
525      done();
526    });
527  });
528
529  /*
530   * @tc.number  inputmethod_test_stopInputSessionWithAttach_001
531   * @tc.name    Test Indicates the input method which will hides the keyboard.
532   * @tc.desc    Function test
533   * @tc.level   2
534   */
535  it('inputmethod_test_stopInputSessionWithAttach_001', 0, function (done) {
536    console.info('************* inputmethod_test_stopInputSessionWithAttach_001 Test start*************');
537    let inputMethodCtrl = inputMethod.getController();
538    inputMethodCtrl.stopInputSession((err, ret) => {
539      if (err) {
540        console.info(`inputmethod_test_stopInputSessionWithAttach_001 err, ${JSON.stringify(err.message)}`);
541        expect().assertFail();
542        done();
543        return;
544      }
545      expect(ret).assertTrue();
546      console.info('************* inputmethod_test_stopInputSessionWithAttach_001 Test end*************');
547      done();
548    });
549  });
550
551  /*
552 * @tc.number  inputmethod_test_stopInputSessionWithAttach_002
553 * @tc.name    Test Indicates the input method which will hides the keyboard.
554 * @tc.desc    Function test
555 * @tc.level   2
556 */
557  it('inputmethod_test_stopInputSessionWithAttach_002', 0, function (done) {
558    console.info('************* inputmethod_test_stopInputSessionWithAttach_002 Test start*************');
559    let inputMethodCtrl = inputMethod.getController();
560    inputMethodCtrl.hideSoftKeyboard().then((result)=>{
561      if (result) {
562        console.info('inputmethod_test_stopInputSessionWithAttach_002 failed.');
563        expect().assertFail();
564        done();
565      }
566      console.info('inputmethod_test_stopInputSessionWithAttach_002 success.');
567      expect(true).assertTrue();
568      done();
569    }).catch((err) => {
570      console.info(`inputmethod_test_stopInputSessionWithAttach_002 err, ${JSON.stringify(err.message)}`);
571      expect().assertFail();
572      done();
573    });
574  });
575
576  /*
577   * @tc.number  inputmethod_with_attach_test_on_000
578   * @tc.name    Test whether the register the callback of the input method is valid.
579   * @tc.desc    Function test
580   * @tc.level   2
581   */
582  it('inputmethod_with_attach_test_on_000', 0, async function (done) {
583    let inputMethodCtrl = inputMethod.getController();
584    try {
585      inputMethodCtrl.on('insertText', (text) => {
586        console.info(`inputMethod insertText success, text: ${JSON.stringify(text)}`);
587      });
588      inputMethodCtrl.on('deleteLeft', (length) => {
589        console.info(`inputMethod deleteLeft success, length: ${JSON.stringify(length)}`);
590      });
591      inputMethodCtrl.on('deleteRight', (length) => {
592        console.info(`inputMethod deleteRight success, length: ${JSON.stringify(length)}`);
593      });
594      inputMethodCtrl.on('sendKeyboardStatus', (keyBoardStatus) => {
595        console.info(`inputMethod sendKeyboardStatus success, keyBoardStatus: ${JSON.stringify(keyBoardStatus)}`);
596      });
597      inputMethodCtrl.on('sendFunctionKey', (functionKey) => {
598        console.info(`inputMethod sendFunctionKey success,
599          functionKey.enterKeyType: ${JSON.stringify(functionKey.enterKeyType)}`);
600      });
601      inputMethodCtrl.on('moveCursor', (direction) => {
602        console.info(`inputMethod moveCursor success, direction: ${JSON.stringify(direction)}`);
603      });
604      inputMethodCtrl.on('handleExtendAction', (action) => {
605        console.info(`inputMethod handleExtendAction success, action: ${JSON.stringify(action)}`);
606      });
607      expect(true).assertTrue();
608      done();
609    } catch(error) {
610      console.info(`inputmethod_with_attach_test_on_000 result: ${JSON.stringify(error)}`);
611      expect().assertFail();
612      done();
613    }
614  });
615
616  /*
617   * @tc.number  inputmethod_test_insertTextSync_001
618   * @tc.name    Test Indicates the input method which will replace the current one.
619   * @tc.desc    Function test
620   * @tc.level   2
621   */
622  it('inputmethod_test_insertTextSync_001', 0, async function (done) {
623    console.info('************* inputmethod_test_insertTextSync_001 Test start*************');
624    let inputMethodCtrl = inputMethod.getController();
625    await inputMethodCtrl.showSoftKeyboard();
626    try {
627      inputMethodCtrl.on('insertText', (text) => {
628        console.info(`inputMethod insertText success, text: ${JSON.stringify(text)}`);
629        expect(true).assertTrue();
630        done();
631      });
632      publishCommonEvent(TEST_FUNCTION.INSERT_TEXT_SYNC);
633    } catch(error) {
634      console.info(`inputmethod_test_insertTextSync result: ${JSON.stringify(error)}`);
635      expect().assertFail();
636      done();
637    }
638  });
639
640  /*
641   * @tc.number  inputmethod_test_moveCursorSync_001
642   * @tc.name    Test Indicates the input method which will replace the current one.
643   * @tc.desc    Function test
644   * @tc.level   2
645   */
646  it('inputmethod_test_moveCursorSync_001', 0, async function (done) {
647    console.info('************* inputmethod_test_moveCursorSync_001 Test start*************');
648    let inputMethodCtrl = inputMethod.getController();
649    await inputMethodCtrl.showSoftKeyboard();
650    try {
651      inputMethodCtrl.on('moveCursor', (direction) => {
652        console.info(`inputMethod moveCursor success, direction: ${direction}`);
653        expect(true).assertTrue();
654        done();
655      });
656      publishCommonEvent(TEST_FUNCTION.MOVE_CURSOR_SYNC);
657    } catch(error) {
658      console.info(`inputmethod_text_moveCursorSync result: ${JSON.stringify(error)}`);
659      expect().assertFail();
660      done();
661    }
662  });
663
664  /*
665   * @tc.number  inputmethod_test_getEditorAttributeSync_001
666   * @tc.name    Test Indicates the input method which will replace the current one.
667   * @tc.desc    Function test
668   * @tc.level   2
669   */
670  it('inputmethod_test_getEditorAttributeSync_001', 0, async function (done) {
671    console.info('************* inputmethod_test_getEditorAttributeSync_001 Test start*************');
672    let inputMethodCtrl = inputMethod.getController();
673    await inputMethodCtrl.showSoftKeyboard();
674    try {
675      let subscribeInfo = {
676        events: ['getEditorAttributeSyncResult']
677      };
678      subscribe(subscribeInfo, TEST_FUNCTION.GET_ATTRIBUTE_SYNC, done);
679    } catch(error) {
680      console.info(`inputmethod_test_getEditorAttributeSync_001 result: ${JSON.stringify(error)}`);
681      expect().assertFail();
682      done();
683    }
684  });
685
686  /*
687   * @tc.number  inputmethod_test_getSystemPanelInsets_001
688   * @tc.name    Test Indicates the input method which will replace the current one.
689   * @tc.desc    Function test
690   * @tc.level   2
691   */
692  it('inputmethod_test_setKeepScreenOn_001', 0, async function (done) {
693    console.info('************* inputmethod_test_setKeepScreenOn_001 Test start*************');
694    let inputMethodCtrl = inputMethod.getController();
695    await inputMethodCtrl.showSoftKeyboard();
696    try {
697      let subscribeInfo = {
698        events: ['setKeepScreenOn']
699      };
700      subscribe(subscribeInfo, TEST_FUNCTION.SET_KEEP_SCREEN_ON, done);
701    } catch(error) {
702      console.info(`inputmethod_test_setKeepScreenOn_001 result: ${JSON.stringify(error)}`);
703      expect().assertFail();
704      done();
705    }
706  });
707
708  /*
709   * @tc.number  inputmethod_test_SelectByRangeSync_001
710   * @tc.name    Test Indicates the input method which will replace the current one.
711   * @tc.desc    Function test
712   * @tc.level   2
713   */
714  it('inputmethod_test_selectByRangeSync_001', 0, async function (done) {
715    console.info('************* inputmethod_test_selectByRangeSync_001 Test start*************');
716    let inputMethodCtrl = inputMethod.getController();
717    await inputMethodCtrl.showSoftKeyboard();
718    try {
719      inputMethodCtrl.on('selectByRange', (range) => {
720        console.info(`inputMethod selectByRangeSync success, direction: ${range}`);
721        expect(true).assertTrue();
722        done();
723      });
724      publishCommonEvent(TEST_FUNCTION.SELECT_BY_RANGE_SYNC);
725    } catch(error) {
726      console.info(`inputmethod_text_selectByRangeSync result: ${JSON.stringify(error)}`);
727      expect().assertFail();
728       done();
729     }
730  });
731
732  /*
733   * @tc.number  inputmethod_test_selectByMovementSync_001
734   * @tc.name    Test Indicates the input method which will replace the current one.
735   * @tc.desc    Function test
736   * @tc.level   2
737   */
738  it('inputmethod_test_selectByMovementSync_001', 0, async function (done) {
739    console.info('************* inputmethod_test_selectByMovementSync_001 Test start*************');
740    let inputMethodCtrl = inputMethod.getController();
741    await inputMethodCtrl.showSoftKeyboard();
742    try {
743      inputMethodCtrl.on('selectByMovement', (movement) => {
744        console.info(`inputMethod selectByMovementSync success, movement: ${movement}`);
745        expect(true).assertTrue();
746        done();
747      });
748      publishCommonEvent(TEST_FUNCTION.SELECT_BY_MOVEMENT_SYNC);
749    } catch(error) {
750      console.info(`inputmethod_text_selectByMovementSync result: ${JSON.stringify(error)}`);
751      expect().assertFail();
752       done();
753     }
754  });
755
756  /*
757   * @tc.number  inputmethod_test_selectByMovementSync_001
758   * @tc.name    Test Indicates the input method which will replace the current one.
759   * @tc.desc    Function test
760   * @tc.level   2
761   */
762  it('inputmethod_test_getTextIndexAtCursorSync_001', 0, async function (done) {
763    console.info('************* inputmethod_test_getTextIndexAtCursorSync_001 Test start*************');
764    let inputMethodCtrl = inputMethod.getController();
765    await inputMethodCtrl.showSoftKeyboard();
766    try {
767      inputMethodCtrl.on('getTextIndexAtCursor', () => {
768        console.info(`inputMethod getTextIndexAtCursor success`);
769        return 2;
770      });
771      let subscribeInfo = {
772        events: ['getTextIndexAtCursorSyncResult']
773      };
774      subscribe(subscribeInfo, TEST_FUNCTION.GET_INDEX_AT_CURSOR_SYNC, done);
775    } catch(error) {
776      console.info(`inputmethod_test_getTextIndexAtCursorSync_001 result: ${JSON.stringify(error)}`);
777      expect().assertFail();
778      done();
779    }
780  });
781
782  /*
783   * @tc.number  inputmethod_test_deleteForwardSync_001
784   * @tc.name    Test Indicates the input method which will replace the current one.
785   * @tc.desc    Function test
786   * @tc.level   2
787   */
788  it('inputmethod_test_deleteForwardSync_001', 0, async function (done) {
789    console.info('************* inputmethod_test_deleteForwardSync_001 Test start*************');
790    let inputMethodCtrl = inputMethod.getController();
791    await inputMethodCtrl.showSoftKeyboard();
792    try {
793      inputMethodCtrl.on('deleteLeft', (length) => {
794        console.info(`inputMethod deleteForwardSync success, length: ${length}`);
795        expect(true).assertTrue();
796        done();
797      });
798      publishCommonEvent(TEST_FUNCTION.DELETE_FORWARD_SYNC);
799    } catch(error) {
800      console.info(`inputmethod_text_deleteForwardSync result: ${JSON.stringify(error)}`);
801      expect().assertFail();
802      done();
803    }
804  });
805
806  /*
807   * @tc.number  inputmethod_test_deleteBackwardSync_001
808   * @tc.name    Test Indicates the input method which will replace the current one.
809   * @tc.desc    Function test
810   * @tc.level   2
811   */
812  it('inputmethod_test_deleteBackwardSync_001', 0, async function (done) {
813    console.info('************* inputmethod_test_deleteBackwardSync_001 Test start*************');
814    let inputMethodCtrl = inputMethod.getController();
815    await inputMethodCtrl.showSoftKeyboard();
816    try {
817      inputMethodCtrl.on('deleteRight', (length) => {
818        console.info(`inputMethod deleteBackwardSync success, length: ${length}`);
819        expect(true).assertTrue();
820        done();
821      });
822      publishCommonEvent(TEST_FUNCTION.DELETE_BACKWARD_SYNC);
823    } catch(error) {
824      console.info(`inputmethod_text_deleteBackwardSync result: ${JSON.stringify(error)}`);
825      expect().assertFail();
826      done();
827    }
828  });
829
830  /*
831   * @tc.number  inputmethod_test_getForwardSync_001
832   * @tc.name    Test Indicates the input method which will replace the current one.
833   * @tc.desc    Function test
834   * @tc.level   0
835   */
836  it('inputmethod_test_getForwardSync_001', 0, async function (done) {
837    console.info('************* inputmethod_test_getForwardSync_001 Test start*************');
838    let inputMethodCtrl = inputMethod.getController();
839    await inputMethodCtrl.showSoftKeyboard();
840    try {
841      inputMethodCtrl.on('getLeftTextOfCursor', (length) => {
842        console.info(`inputMethod getForwardSync success, length: ${length}`);
843        return 'getLeftTextOfCursor';
844      });
845      let subscribeInfo = {
846        events: ['getForwardSyncResult']
847      };
848      subscribe(subscribeInfo, TEST_FUNCTION.GET_FORWARD_SYNC, done);
849    } catch(error) {
850      console.info(`inputmethod_text_getForwardSync result: ${JSON.stringify(error)}`);
851      expect().assertFail();
852      done();
853    }
854  });
855  /*
856   * @tc.number  inputmethod_test_getBackwardSync_001
857   * @tc.name    Test Indicates the input method which will replace the current one.
858   * @tc.desc    Function test
859   * @tc.level   0
860   */
861  it('inputmethod_test_getBackwardSync_001', 0, async function (done) {
862    console.info('************* inputmethod_test_getBackwardSync_001 Test start*************');
863    let inputMethodCtrl = inputMethod.getController();
864    await inputMethodCtrl.showSoftKeyboard();
865    try {
866      inputMethodCtrl.on('getRightTextOfCursor', (length) => {
867        console.info(`inputMethod getBackwardSync success, length: ${length}`);
868        return 'getRightTextOfCursor';
869      });
870      let subscribeInfo = {
871        events: ['getBackwardSyncResult']
872      };
873      subscribe(subscribeInfo, TEST_FUNCTION.GET_BACKWARD_SYNC, done);
874    } catch(error) {
875      console.info(`inputmethod_text_getBackwardSync result: ${JSON.stringify(error)}`);
876      expect().assertFail();
877      done();
878    }
879  });
880
881  /*
882   * @tc.number  inputmethod_test_isPanelShown_001
883   * @tc.name    Test Indicates querying by isPanelShown.
884   * @tc.desc    Function test
885   * @tc.level   0
886   */
887  it('inputmethod_test_isPanelShown_001', 0, async function (done) {
888    console.info('************* inputmethod_test_isPanelShown_001 Test start*************');
889    try {
890      let cfg = {
891        inputAttribute:
892            {
893              textInputType: inputMethod.TextInputType.TEXT,
894              enterKeyType: inputMethod.EnterKeyType.NONE
895            }
896      };
897      await inputMethod.getController().attach(true, cfg);
898      setTimeout(()=>{
899        let result = inputMethod.getSetting().isPanelShown({type: PanelType.SOFT_KEYBOARD});
900        if (result) {
901          expect(true).assertTrue();
902        } else {
903          expect().assertFail();
904        }
905        done();
906      }, WAIT_DEAL_OK);
907    } catch (error) {
908      console.info(`inputmethod_test_isPanelShown_001 result: ${JSON.stringify(error)}`);
909      expect().assertFail();
910      done();
911    }
912  });
913
914  /*
915   * @tc.number  inputmethod_test_isPanelShown_002
916   * @tc.name    Test Indicates querying by isPanelShown.
917   * @tc.desc    Function test
918   * @tc.level   2
919   */
920  it('inputmethod_test_isPanelShown_002', 0, async function (done) {
921    console.info('************* inputmethod_test_isPanelShown_002 Test start*************');
922    try {
923      let subscribeInfo = {
924        events: ['changeFlag']
925      };
926      subscribe(subscribeInfo, TEST_FUNCTION.CHANGE_FLAG_TO_FLOATING, () => {
927        let result = inputMethod.getSetting().isPanelShown({
928          type: PanelType.SOFT_KEYBOARD,
929          flag: PanelFlag.FLAG_FLOATING
930        });
931        if (result) {
932          expect(true).assertTrue();
933        } else {
934          expect().assertFail();
935        }
936        subscribe(subscribeInfo, TEST_FUNCTION.CHANGE_FLAG_TO_FIXED, done);
937      });
938    } catch (error) {
939      console.info(`inputmethod_test_isPanelShown_002 result: ${JSON.stringify(error)}`);
940      expect().assertFail();
941      done();
942    }
943  });
944
945  /*
946   * @tc.number  inputmethod_test_setPrivacyModeWithoutPermission_001
947   * @tc.name    Test Indicates set panel privacy mode without permission.
948   * @tc.desc    Function test
949   * @tc.level   2
950   */
951  it('inputmethod_test_setPrivacyModeWithoutPermission_001', 0, async function (done) {
952    console.info('************* inputmethod_test_setPrivacyModeWithoutPermission_001 Test start*************');
953    try {
954      let subscribeInfo = {
955        events: ['setPrivacyModeWithoutPermissionResult']
956      };
957      subscribe(subscribeInfo, TEST_FUNCTION.SETPRIVACYMODE_WITHOUT_PERMISSION, done);
958    } catch(error) {
959      console.info(`inputmethod_test_setPrivacyModeWithoutPermission_001 result: ${JSON.stringify(error)}`);
960      expect().assertFail();
961      done();
962    }
963  });
964
965  /*
966   * @tc.number  inputmethod_test_setPrivacyModeErrorParam_001
967   * @tc.name    Test Indicates set panel privacy mode with undefined param.
968   * @tc.desc    Function test
969   * @tc.level   2
970   */
971    it('inputmethod_test_setPrivacyModeErrorParam_001', 0, async function (done) {
972      console.info('************* inputmethod_test_setPrivacyModeErrorParam_001 Test start*************');
973      try {
974        let subscribeInfo = {
975          events: ['setPrivacyModeErrorParamResult']
976        };
977        subscribe(subscribeInfo, TEST_FUNCTION.SETPRIVACYMODE_ERROR_PARAM, done);
978      } catch(error) {
979        console.info(`inputmethod_test_setPrivacyModeErrorParam_001 result: ${JSON.stringify(error)}`);
980        expect().assertFail();
981        done();
982      }
983    });
984
985  /*
986   * @tc.number  inputmethod_test_adjustPanelRect_001
987   * @tc.name    Test Indicates adjustPanelRect with invalid panel flag.
988   * @tc.desc    Function test
989   * @tc.level   2
990   */
991  it('inputmethod_test_adjustPanelRect_001', 0, async function (done) {
992    console.info('************* inputmethod_test_adjustPanelRect_001 Test start*************');
993    try {
994      let subscribeInfo = {
995        events: ['adjustWithInvalidFlagResult']
996      };
997      subscribe(subscribeInfo, TEST_FUNCTION.ADJUST_WITH_INVALID_FLAG, done);
998    } catch(error) {
999      console.info(`inputmethod_test_adjustPanelRect_001 result: ${JSON.stringify(error)}`);
1000      expect().assertFail();
1001      done();
1002    }
1003  });
1004
1005  /*
1006   * @tc.number  inputmethod_test_adjustPanelRect_002
1007   * @tc.name    Test Indicates adjustPanelRect with non full screen mode but panel rect is not provided.
1008   * @tc.desc    Function test
1009   * @tc.level   2
1010   */
1011  it('inputmethod_test_adjustPanelRect_002', 0, async function (done) {
1012    console.info('************* inputmethod_test_adjustPanelRect_002 Test start*************');
1013    try {
1014      let subscribeInfo = {
1015        events: ['adjustWithNonFullScreenNoPanelRectResult']
1016      };
1017      subscribe(subscribeInfo, TEST_FUNCTION.ADJUST_WITH_NON_FULL_SCREEN_NO_PANEL_RECT, done);
1018    } catch(error) {
1019      console.info(`inputmethod_test_adjustPanelRect_002 result: ${JSON.stringify(error)}`);
1020      expect().assertFail();
1021      done();
1022    }
1023  });
1024
1025  /*
1026   * @tc.number  inputmethod_test_adjustPanelRect_003
1027   * @tc.name    Test Indicates adjustPanelRect with full screen mode but no avoid Y.
1028   * @tc.desc    Function test
1029   * @tc.level   2
1030   */
1031  it('inputmethod_test_adjustPanelRect_003', 0, async function (done) {
1032    console.info('************* inputmethod_test_adjustPanelRect_003 Test start*************');
1033    try {
1034      let subscribeInfo = {
1035        events: ['adjustWithFullScreenNoAvoidYResult']
1036      };
1037      subscribe(subscribeInfo, TEST_FUNCTION.ADJUST_WITH_FULL_SCREEN_NO_AVOID_Y, done);
1038    } catch(error) {
1039      console.info(`inputmethod_test_adjustPanelRect_003 result: ${JSON.stringify(error)}`);
1040      expect().assertFail();
1041      done();
1042    }
1043  });
1044
1045  /*
1046   * @tc.number  inputmethod_test_adjustPanelRect_004
1047   * @tc.name    Test Indicates adjustPanelRect with invalid avoid Y.
1048   * @tc.desc    Function test
1049   * @tc.level   2
1050   */
1051  it('inputmethod_test_adjustPanelRect_004', 0, async function (done) {
1052    console.info('************* inputmethod_test_adjustPanelRect_004 Test start*************');
1053    try {
1054      let subscribeInfo = {
1055        events: ['adjustWithInvalidAvoidYResult']
1056      };
1057      subscribe(subscribeInfo, TEST_FUNCTION.ADJUST_WITH_INVALID_AVOID_Y, done);
1058    } catch(error) {
1059      console.info(`inputmethod_test_adjustPanelRect_004 result: ${JSON.stringify(error)}`);
1060      expect().assertFail();
1061      done();
1062    }
1063  });
1064
1065  /*
1066   * @tc.number  inputmethod_test_adjustPanelRect_005
1067   * @tc.name    Test Indicates adjustPanelRect with invalid panel type.
1068   * @tc.desc    Function test
1069   * @tc.level   2
1070   */
1071  it('inputmethod_test_adjustPanelRect_005', 0, async function (done) {
1072    console.info('************* inputmethod_test_adjustPanelRect_005 Test start*************');
1073    try {
1074      let subscribeInfo = {
1075        events: ['adjustWithInvalidTypeResult']
1076      };
1077      subscribe(subscribeInfo, TEST_FUNCTION.ADJUST_WITH_INVALID_TYPE, done);
1078    } catch(error) {
1079      console.info(`inputmethod_test_adjustPanelRect_005 result: ${JSON.stringify(error)}`);
1080      expect().assertFail();
1081      done();
1082    }
1083  });
1084
1085  /*
1086   * @tc.number  inputmethod_test_adjustPanelRect_006
1087   * @tc.name    Test Indicates adjustPanelRect successfully.
1088   * @tc.desc    Function test
1089   * @tc.level   2
1090   */
1091  it('inputmethod_test_adjustPanelRect_006', 0, async function (done) {
1092    console.info('************* inputmethod_test_adjustPanelRect_006 Test start*************');
1093    try {
1094      let subscribeInfo = {
1095        events: ['adjustSuccessResult']
1096      };
1097      subscribe(subscribeInfo, TEST_FUNCTION.ADJUST_SUCCESS, done);
1098    } catch(error) {
1099      console.info(`inputmethod_test_adjustPanelRect_006 result: ${JSON.stringify(error)}`);
1100      expect().assertFail();
1101      done();
1102    }
1103  });
1104
1105  /*
1106   * @tc.number  inputmethod_test_setPreviewText_001
1107   * @tc.name    Test Indicates the input method which will replace the current one.
1108   * @tc.desc    Function test
1109   * @tc.level   2
1110   */
1111  it('inputmethod_test_setPreviewText_001', 0, async function (done) {
1112    console.info('************* inputmethod_test_setPreviewText_001 Test start*************');
1113    let inputMethodCtrl = inputMethod.getController();
1114    await inputMethodCtrl.showSoftKeyboard();
1115    try {
1116      inputMethodCtrl.on('setPreviewText', (text, range) => {
1117        console.info(`inputMethod setPreviewText success, text: ${JSON.stringify(text)}, start: ${range.start}, end: ${range.end}`);
1118        expect(true).assertTrue();
1119        done();
1120      });
1121      publishCommonEvent(TEST_FUNCTION.SET_PREVIEW_TEXT);
1122    } catch(error) {
1123      console.info(`inputmethod_test_setPreviewText_001 result: ${JSON.stringify(error)}`);
1124      expect().assertFail();
1125      done();
1126    }
1127  });
1128
1129  /*
1130   * @tc.number  inputmethod_test_setPreviewText_002
1131   * @tc.name    Test Indicates the input method which will replace the current one.
1132   * @tc.desc    Function test
1133   * @tc.level   2
1134   */
1135  it('inputmethod_test_setPreviewText_002', 0, async function (done) {
1136    console.info('************* inputmethod_test_setPreviewText_002 Test start*************');
1137    let inputMethodCtrl = inputMethod.getController();
1138    try {
1139      inputMethodCtrl.on('setPreviewText', 'test');
1140    } catch(error) {
1141      console.info(`inputmethod_test_setPreviewText_002 result: ${JSON.stringify(error)}`);
1142      expect(error.code === 401).assertTrue();
1143      done();
1144    }
1145  });
1146
1147   /*
1148   * @tc.number  inputmethod_test_setPreviewText_003
1149   * @tc.name    Test Indicates the input method which will replace the current one.
1150   * @tc.desc    Function test
1151   * @tc.level   2
1152   */
1153   it('inputmethod_test_setPreviewText_003', 0, async function (done) {
1154    console.info('************* inputmethod_test_setPreviewText_003 Test start*************');
1155    let inputMethodCtrl = inputMethod.getController();
1156    try {
1157      inputMethodCtrl.on('setPreviewText');
1158    } catch(error) {
1159      console.info(`inputmethod_test_setPreviewText_003 result: ${JSON.stringify(error)}`);
1160      expect(error.code === 401).assertTrue();
1161      done();
1162    }
1163  });
1164
1165  /*
1166   * @tc.number  inputmethod_test_setPreviewText_004
1167   * @tc.name    Test Indicates the input method which will replace the current one.
1168   * @tc.desc    Function test
1169   * @tc.level   2
1170   */
1171  it('inputmethod_test_setPreviewText_004', 0, async function (done) {
1172    console.info('************* inputmethod_test_setPreviewText_004 Test start*************');
1173    let inputMethodCtrl = inputMethod.getController();
1174    await inputMethodCtrl.showSoftKeyboard();
1175    let index = 0;
1176    let callback1 = (text, range) => {
1177      console.info(`inputMethod setPreviewText 1 success, text: ${JSON.stringify(text)}, start: ${range.start}, end: ${range.end}`);
1178      index += 1;
1179    };
1180    let callback2 = (text, range) => {
1181      console.info(`inputMethod setPreviewText 2 success, text: ${JSON.stringify(text)}, start: ${range.start}, end: ${range.end}`);
1182      index += 1;
1183    };
1184    try {
1185      inputMethodCtrl.on('setPreviewText', callback1);
1186      inputMethodCtrl.on('setPreviewText', callback2);
1187      publishCommonEvent(TEST_FUNCTION.SET_PREVIEW_TEXT);
1188      let timeOutCb = async () => {
1189        console.info(`inputMethod setPreviewText timeout`);
1190        clearTimeout(t);
1191        expect(index).assertEqual(2);
1192        done();
1193      };
1194      let t = setTimeout(timeOutCb, 500);
1195    } catch(error) {
1196      console.info(`inputmethod_test_setPreviewText_004 result: ${JSON.stringify(error)}`);
1197      expect().assertFail();
1198      done();
1199    }
1200  });
1201
1202  /*
1203   * @tc.number  inputmethod_test_setPreviewText_005
1204   * @tc.name    Test Indicates the input method which will replace the current one.
1205   * @tc.desc    Function test
1206   * @tc.level   2
1207   */
1208  it('inputmethod_test_setPreviewText_005', 0, async function (done) {
1209    console.info('************* inputmethod_test_setPreviewText_005 Test start*************');
1210    let inputMethodCtrl = inputMethod.getController();
1211    await inputMethodCtrl.showSoftKeyboard();
1212    let index = 0;
1213    let callback1 = (text, range) => {
1214      console.info(`inputMethod setPreviewText 1 success, text: ${JSON.stringify(text)}, start: ${range.start}, end: ${range.end}`);
1215      index += 1;
1216    };
1217    let callback2 = (text, range) => {
1218      console.info(`inputMethod setPreviewText 2 success, text: ${JSON.stringify(text)}, start: ${range.start}, end: ${range.end}`);
1219      index += 1;
1220    };
1221    try {
1222      inputMethodCtrl.on('setPreviewText', callback1);
1223      inputMethodCtrl.on('setPreviewText', callback2);
1224      publishCommonEvent(TEST_FUNCTION.SET_PREVIEW_TEXT);
1225      let timeOutCb = async () => {
1226        console.info(`inputMethod setPreviewText timeOutCb`);
1227        clearTimeout(t);
1228        expect(index).assertEqual(2);
1229        inputMethodCtrl.off('setPreviewText', callback2);
1230        publishCommonEvent(TEST_FUNCTION.SET_PREVIEW_TEXT);
1231        let timeOutCb1 = async () => {
1232          console.info(`inputMethod setPreviewText timeOutCb1`);
1233          clearTimeout(t1);
1234          expect(index).assertEqual(3);
1235          inputMethodCtrl.off('setPreviewText');
1236          publishCommonEvent(TEST_FUNCTION.SET_PREVIEW_TEXT);
1237          let timeOutCb2 = async () => {
1238            console.info(`inputMethod setPreviewText timeOutCb2`);
1239            clearTimeout(t2);
1240            expect(index).assertEqual(3);
1241            inputMethodCtrl.on('setPreviewText', () => {});
1242            done();
1243          };
1244          let t2 = setTimeout(timeOutCb2, 500);
1245        };
1246        let t1 = setTimeout(timeOutCb1, 500);
1247      };
1248      let t = setTimeout(timeOutCb, 500);
1249    } catch(error) {
1250      console.info(`inputmethod_test_setPreviewText_005 result: ${JSON.stringify(error)}`);
1251      expect().assertFail();
1252      done();
1253    }
1254  });
1255
1256  /*
1257   * @tc.number  inputmethod_test_finishTextPreview_001
1258   * @tc.name    Test Indicates the input method which will replace the current one.
1259   * @tc.desc    Function test
1260   * @tc.level   2
1261   */
1262  it('inputmethod_test_finishTextPreview_001', 0, async function (done) {
1263    console.info('************* inputmethod_test_finishTextPreview_001 Test start*************');
1264    let inputMethodCtrl = inputMethod.getController();
1265    await inputMethodCtrl.showSoftKeyboard();
1266    try {
1267      inputMethodCtrl.on('finishTextPreview', () => {
1268        console.info(`inputMethod finishTextPreview success`);
1269        expect(true).assertTrue();
1270        done();
1271      });
1272      publishCommonEvent(TEST_FUNCTION.FINISH_TEXT_PREVIEW);
1273    } catch(error) {
1274      console.info(`inputmethod_test_finishTextPreview_001 result: ${JSON.stringify(error)}`);
1275      expect().assertFail();
1276      done();
1277    }
1278  });
1279
1280  /*
1281   * @tc.number  inputmethod_test_finishTextPreview_002
1282   * @tc.name    Test Indicates the input method which will replace the current one.
1283   * @tc.desc    Function test
1284   * @tc.level   2
1285   */
1286  it('inputmethod_test_finishTextPreview_002', 0, async function (done) {
1287    console.info('************* inputmethod_test_finishTextPreview_002 Test start*************');
1288    let inputMethodCtrl = inputMethod.getController();
1289    try {
1290      inputMethodCtrl.on('finishTextPreview');
1291    } catch(error) {
1292      console.info(`inputmethod_test_finishTextPreview_002 result: ${JSON.stringify(error)}`);
1293      expect(error.code === 401).assertTrue();
1294      done();
1295    }
1296  });
1297
1298  /*
1299   * @tc.number  inputmethod_test_finishTextPreview_003
1300   * @tc.name    Test Indicates the input method which will replace the current one.
1301   * @tc.desc    Function test
1302   * @tc.level   2
1303   */
1304  it('inputmethod_test_finishTextPreview_003', 0, async function (done) {
1305    console.info('************* inputmethod_test_finishTextPreview_002 Test start*************');
1306    let inputMethodCtrl = inputMethod.getController();
1307    try {
1308      inputMethodCtrl.on('finishTextPreview', 0);
1309    } catch(error) {
1310      console.info(`inputmethod_test_finishTextPreview_003 result: ${JSON.stringify(error)}`);
1311      expect(error.code === 401).assertTrue();
1312      done();
1313    }
1314  });
1315
1316  /*
1317   * @tc.number  inputmethod_test_finishTextPreview_004
1318   * @tc.name    Test Indicates the input method which will replace the current one.
1319   * @tc.desc    Function test
1320   * @tc.level   2
1321   */
1322  it('inputmethod_test_finishTextPreview_004', 0, async function (done) {
1323    console.info('************* inputmethod_test_finishTextPreview_004 Test start*************');
1324    let inputMethodCtrl = inputMethod.getController();
1325    await inputMethodCtrl.showSoftKeyboard();
1326    let index = 0;
1327    let callback1 = () => {
1328      console.info(`inputMethod finishTextPreview 1 success`);
1329      index += 1;
1330    };
1331    let callback2 = () => {
1332      console.info(`inputMethod finishTextPreview 2 success`);
1333      index += 1;
1334    };
1335    try {
1336      inputMethodCtrl.on('finishTextPreview', callback1);
1337      inputMethodCtrl.on('finishTextPreview', callback2);
1338      publishCommonEvent(TEST_FUNCTION.FINISH_TEXT_PREVIEW);
1339      let timeOutCb = async () => {
1340        console.info(`inputMethod finishTextPreview timeout`);
1341        clearTimeout(t);
1342        expect(index).assertEqual(2);
1343        done();
1344      };
1345      let t = setTimeout(timeOutCb, 500);
1346    } catch(error) {
1347      console.info(`inputmethod_test_finishTextPreview_004 result: ${JSON.stringify(error)}`);
1348      expect().assertFail();
1349      done();
1350    }
1351  });
1352
1353  /*
1354   * @tc.number  inputmethod_test_finishTextPreview_005
1355   * @tc.name    Test Indicates the input method which will replace the current one.
1356   * @tc.desc    Function test
1357   * @tc.level   0
1358   */
1359  it('inputmethod_test_finishTextPreview_005', 0, async function (done) {
1360    console.info('************* inputmethod_test_finishTextPreview_005 Test start*************');
1361    let inputMethodCtrl = inputMethod.getController();
1362    await inputMethodCtrl.showSoftKeyboard();
1363    let index = 0;
1364    let callback1 = () => {
1365      console.info(`inputMethod finishTextPreview 1 success`);
1366      index += 1;
1367    };
1368    let callback2 = () => {
1369      console.info(`inputMethod finishTextPreview 2 success`);
1370      index += 1;
1371    };
1372    try {
1373      inputMethodCtrl.on('finishTextPreview', callback1);
1374      inputMethodCtrl.on('finishTextPreview', callback2);
1375      publishCommonEvent(TEST_FUNCTION.FINISH_TEXT_PREVIEW);
1376      let timeOutCb = async () => {
1377        console.info(`inputMethod finishTextPreview timeOutCb`);
1378        clearTimeout(t);
1379        expect(index).assertEqual(2);
1380
1381        inputMethodCtrl.off('finishTextPreview', callback2);
1382        publishCommonEvent(TEST_FUNCTION.FINISH_TEXT_PREVIEW);
1383        let timeOutCb1 = async () => {
1384          console.info(`inputMethod finishTextPreview timeOutCb1`);
1385          clearTimeout(t1);
1386          expect(index).assertEqual(3);
1387          inputMethodCtrl.off('finishTextPreview');
1388          publishCommonEvent(TEST_FUNCTION.FINISH_TEXT_PREVIEW);
1389          let timeOutCb2 = async () => {
1390            console.info(`inputMethod finishTextPreview timeOutCb2`);
1391            clearTimeout(t2);
1392            expect(index).assertEqual(3);
1393            done();
1394          };
1395          let t2 = setTimeout(timeOutCb2, 500);
1396        };
1397        let t1 = setTimeout(timeOutCb1, 500);
1398      };
1399      let t = setTimeout(timeOutCb, 500);
1400    } catch(error) {
1401      console.info(`inputmethod_test_finishTextPreview_005 result: ${JSON.stringify(error)}`);
1402      expect().assertFail();
1403      done();
1404    }
1405  });
1406
1407  /*
1408   * @tc.number  inputmethod_with_attach_test_discardTypingText
1409   * @tc.name    discard Typing Text
1410   * @tc.desc    Function test
1411   * @tc.level   2
1412   */
1413  it('inputmethod_with_attach_test_discardTypingText', 0, async function (done) {
1414    console.info('************* inputmethod_with_attach_test_discardTypingText Test start*************');
1415    let cfg = {
1416      inputAttribute:
1417      {
1418        textInputType: inputMethod.TextInputType.TEXT,
1419        enterKeyType: inputMethod.EnterKeyType.SEARCH
1420      }
1421    };
1422    await inputMethod.getController().attach(true, cfg);
1423    let inputMethodCtrl = inputMethod.getController();
1424    inputMethodCtrl.discardTypingText((err) => {
1425      if (err) {
1426        console.info(`inputmethod_with_attach_test_discardTypingText result: ${JSON.stringify(err)}`);
1427        expect().assertFail();
1428        done();
1429      }
1430      console.info('inputmethod_with_attach_test_discardTypingText callback success');
1431      expect(true).assertTrue();
1432      done();
1433    });
1434    console.info('************* inputmethod_with_attach_test_discardTypingText Test end*************');
1435  });
1436});