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