• 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 
16 #include <gtest/gtest.h>
17 #include <string_ex.h>
18 
19 #include "global.h"
20 #include "input_attribute.h"
21 #include "input_method_ability.h"
22 #include "input_method_controller.h"
23 #include "input_method_engine_listener_impl.h"
24 #include "tdd_util.h"
25 #include "text_listener.h"
26 
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace MiscServices {
30 using WindowMgr = TddUtil::WindowManager;
31 class InputMethodAttachTest : public testing::Test {
32 public:
33     static sptr<InputMethodController> inputMethodController_;
34     static sptr<InputMethodAbility> inputMethodAbility_;
35 
SetUpTestCase(void)36     static void SetUpTestCase(void)
37     {
38         IMSA_HILOGI("InputMethodAttachTest::SetUpTestCase");
39         // Set the tokenID to the tokenID of the current ime
40         TddUtil::StorageSelfTokenID();
41         std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
42         std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
43         TddUtil::SetTestTokenID(TddUtil::GetTestTokenID(bundleName));
44         inputMethodAbility_ = InputMethodAbility::GetInstance();
45         inputMethodAbility_->OnImeReady();
46         inputMethodAbility_->SetCoreAndAgent();
47         inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
48         TddUtil::RestoreSelfTokenID();
49 
50         TddUtil::WindowManager::RegisterFocusChangeListener();
51         WindowMgr::CreateWindow();
52         WindowMgr::ShowWindow();
53         bool isFocused = FocusChangedListenerTestImpl::isFocused_->GetValue();
54         IMSA_HILOGI("getFocus end, isFocused = %{public}d", isFocused);
55         inputMethodController_ = InputMethodController::GetInstance();
56     }
TearDownTestCase(void)57     static void TearDownTestCase(void)
58     {
59         IMSA_HILOGI("InputMethodAttachTest::TearDownTestCase");
60         WindowMgr::HideWindow();
61         WindowMgr::DestroyWindow();
62     }
SetUp()63     void SetUp()
64     {
65         IMSA_HILOGI("InputMethodAttachTest::SetUp");
66     }
TearDown()67     void TearDown()
68     {
69         IMSA_HILOGI("InputMethodAttachTest::TearDown");
70         inputMethodController_->Close();
71     }
72 };
73 sptr<InputMethodController> InputMethodAttachTest::inputMethodController_;
74 sptr<InputMethodAbility> InputMethodAttachTest::inputMethodAbility_;
75 
76 /**
77  * @tc.name: testAttach001
78  * @tc.desc: test Attach
79  * @tc.type: FUNC
80  */
81 HWTEST_F(InputMethodAttachTest, testAttach001, TestSize.Level0)
82 {
83     IMSA_HILOGI("test testAttach001 after attach.");
84     sptr<OnTextChangedListener> textListener = new TextListener();
85     auto ret = inputMethodController_->Attach(textListener);
86     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
87 
88     int32_t keyType = -1;
89     ret = inputMethodAbility_->GetEnterKeyType(keyType);
90     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
91     EXPECT_EQ(keyType, 0);
92     int32_t inputPattern = -1;
93     ret = inputMethodAbility_->GetInputPattern(inputPattern);
94     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
95     auto pattern = InputAttribute::PATTERN_TEXT;
96     EXPECT_EQ(inputPattern, pattern);
97 }
98 
99 /**
100  * @tc.name: testAttach002
101  * @tc.desc: test Attach
102  * @tc.type: FUNC
103  */
104 HWTEST_F(InputMethodAttachTest, testAttach002, TestSize.Level0)
105 {
106     IMSA_HILOGI("test testAttach002 after attach.");
107     sptr<OnTextChangedListener> textListener = new TextListener();
108     auto ret = inputMethodController_->Attach(textListener, false);
109     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
110 
111     int32_t keyType = -1;
112     ret = inputMethodAbility_->GetEnterKeyType(keyType);
113     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
114     EXPECT_EQ(keyType, 0);
115     int32_t inputPattern = -1;
116     ret = inputMethodAbility_->GetInputPattern(inputPattern);
117     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
118     auto pattern = InputAttribute::PATTERN_TEXT;
119     EXPECT_EQ(inputPattern, pattern);
120 }
121 
122 /**
123  * @tc.name: testAttach003
124  * @tc.desc: test Attach
125  * @tc.type: FUNC
126  */
127 HWTEST_F(InputMethodAttachTest, testAttach003, TestSize.Level0)
128 {
129     IMSA_HILOGI("test testAttach003 after attach.");
130     sptr<OnTextChangedListener> textListener = new TextListener();
131     InputAttribute attribute;
132     attribute.inputPattern = 2;
133     attribute.enterKeyType = 1;
134     auto ret = inputMethodController_->Attach(textListener, true, attribute);
135     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
136 
137     int32_t keyType = -1;
138     ret = inputMethodAbility_->GetEnterKeyType(keyType);
139     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
140     EXPECT_EQ(keyType, attribute.enterKeyType);
141     int32_t inputPattern = -1;
142     ret = inputMethodAbility_->GetInputPattern(inputPattern);
143     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
144     EXPECT_EQ(inputPattern, attribute.inputPattern);
145 }
146 
147 /**
148  * @tc.name: testAttach004
149  * @tc.desc: test Attach
150  * @tc.type: FUNC
151  */
152 HWTEST_F(InputMethodAttachTest, testAttach004, TestSize.Level0)
153 {
154     IMSA_HILOGI("test testAttach004 after attach.");
155     sptr<OnTextChangedListener> textListener = new TextListener();
156     InputAttribute attribute;
157     attribute.inputPattern = 3;
158     attribute.enterKeyType = 2;
159     TextConfig config;
160     config.inputAttribute = attribute;
161     auto ret = inputMethodController_->Attach(textListener, false, config);
162     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
163 
164     int32_t keyType = -1;
165     ret = inputMethodAbility_->GetEnterKeyType(keyType);
166     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
167     EXPECT_EQ(keyType, config.inputAttribute.enterKeyType);
168     int32_t inputPattern = -1;
169     ret = inputMethodAbility_->GetInputPattern(inputPattern);
170     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
171     EXPECT_EQ(inputPattern, config.inputAttribute.inputPattern);
172 }
173 
174 /**
175  * @tc.name: testAttach005
176  * @tc.desc: test Attach, test optional param in TextConfig
177  * @tc.type: FUNC
178  */
179 HWTEST_F(InputMethodAttachTest, testAttach005, TestSize.Level0)
180 {
181     IMSA_HILOGI("test testAttach005 after attach.");
182     sptr<OnTextChangedListener> textListener = new TextListener();
183     InputAttribute attribute;
184     attribute.inputPattern = 3;
185     attribute.enterKeyType = 2;
186     TextConfig config;
187     config.inputAttribute = attribute;
188     CursorInfo cursorInfo;
189     cursorInfo.left = 0;
190     cursorInfo.top = 1;
191     cursorInfo.width = 0.5;
192     cursorInfo.height = 1.2;
193     config.cursorInfo = cursorInfo;
194     SelectionRange selectionRange;
195     selectionRange.start = 0;
196     selectionRange.end = 2;
197     config.range = selectionRange;
198     config.windowId = 10;
199     auto ret = inputMethodController_->Attach(textListener, true, config);
200     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
201 
202     int32_t keyType = -1;
203     ret = inputMethodAbility_->GetEnterKeyType(keyType);
204     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
205     EXPECT_EQ(keyType, config.inputAttribute.enterKeyType);
206     int32_t inputPattern = -1;
207     ret = inputMethodAbility_->GetInputPattern(inputPattern);
208     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
209     EXPECT_EQ(inputPattern, config.inputAttribute.inputPattern);
210 
211     TextTotalConfig textConfig;
212     ret = inputMethodAbility_->GetTextConfig(textConfig);
213     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
214     EXPECT_EQ(textConfig.inputAttribute, config.inputAttribute);
215     EXPECT_EQ(textConfig.windowId, config.windowId);
216     EXPECT_EQ(textConfig.cursorInfo, config.cursorInfo);
217     EXPECT_EQ(textConfig.textSelection.newBegin, config.range.start);
218     EXPECT_EQ(textConfig.textSelection.newEnd, config.range.end);
219     EXPECT_EQ(textConfig.textSelection.oldBegin, 0);
220     EXPECT_EQ(textConfig.textSelection.oldEnd, 0);
221 }
222 
223 /**
224  * @tc.name: testOnConfigurationChangeWithOutAttach
225  * @tc.desc: test OnConfigurationChange without attach
226  * @tc.type: FUNC
227  */
228 HWTEST_F(InputMethodAttachTest, testOnConfigurationChangeWithOutAttach, TestSize.Level0)
229 {
230     IMSA_HILOGI("InputMethodAttachTest testOnConfigurationChangeWithOutAttach in.");
231     Configuration config;
232     EnterKeyType keyType = EnterKeyType::NEXT;
233     config.SetEnterKeyType(keyType);
234     TextInputType textInputType = TextInputType::DATETIME;
235     config.SetTextInputType(textInputType);
236     auto ret = inputMethodController_->OnConfigurationChange(config);
237     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_BOUND);
238 }
239 
240 /**
241  * @tc.name: testOnConfigurationChange
242  * @tc.desc: test OnConfigurationChange after attach
243  * @tc.type: FUNC
244  */
245 HWTEST_F(InputMethodAttachTest, testOnConfigurationChange, TestSize.Level0)
246 {
247     IMSA_HILOGI("test OnConfigurationChange after attach.");
248     sptr<OnTextChangedListener> textListener = new TextListener();
249     auto ret = inputMethodController_->Attach(textListener);
250     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
251 
252     Configuration config;
253     EnterKeyType keyType = EnterKeyType::NEXT;
254     config.SetEnterKeyType(keyType);
255     TextInputType textInputType = TextInputType::DATETIME;
256     config.SetTextInputType(textInputType);
257     ret = inputMethodController_->OnConfigurationChange(config);
258     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
259     int32_t keyType2;
260     ret = inputMethodAbility_->GetEnterKeyType(keyType2);
261     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
262     EXPECT_EQ(keyType2, (int)keyType);
263     int32_t inputPattern;
264     ret = inputMethodAbility_->GetInputPattern(inputPattern);
265     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
266     EXPECT_EQ(inputPattern, (int)textInputType);
267 }
268 
269 /**
270  * @tc.name: testGetTextConfig
271  * @tc.desc: test GetTextConfig of InputMethodAbility
272  * @tc.type: FUNC
273  */
274 HWTEST_F(InputMethodAttachTest, testGetTextConfig, TestSize.Level0)
275 {
276     IMSA_HILOGI("test OnConfigurationChange001 after attach.");
277     sptr<OnTextChangedListener> textListener = new TextListener();
278     InputAttribute attribute;
279     attribute.inputPattern = 3;
280     attribute.enterKeyType = 2;
281     TextConfig config;
282     config.inputAttribute = attribute;
283     CursorInfo cursorInfo;
284     cursorInfo.left = 0;
285     cursorInfo.top = 1;
286     cursorInfo.width = 0.5;
287     cursorInfo.height = 1.2;
288     config.cursorInfo = cursorInfo;
289     SelectionRange selectionRange;
290     selectionRange.start = 0;
291     selectionRange.end = 2;
292     config.range = selectionRange;
293     config.windowId = 10;
294     auto ret = inputMethodController_->Attach(textListener, false, config);
295     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
296     TextTotalConfig totalConfig;
297     ret = inputMethodAbility_->GetTextConfig(totalConfig);
298     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
299 
300     EXPECT_EQ(totalConfig.inputAttribute, attribute);
301     EXPECT_EQ(totalConfig.cursorInfo, cursorInfo);
302     EXPECT_EQ(totalConfig.textSelection.newBegin, selectionRange.start);
303     EXPECT_EQ(totalConfig.textSelection.newEnd, selectionRange.end);
304     EXPECT_EQ(totalConfig.textSelection.oldBegin, 0);
305     EXPECT_EQ(totalConfig.textSelection.oldEnd, 0);
306     EXPECT_EQ(totalConfig.windowId, config.windowId);
307 }
308 
309 /**
310  * @tc.name: testOnCursorUpdateAfterAttach001
311  * @tc.desc: test OnCursorUpdate after attach
312  * @tc.type: FUNC
313  */
314 HWTEST_F(InputMethodAttachTest, testOnCursorUpdateAfterAttach001, TestSize.Level0)
315 {
316     IMSA_HILOGI("test testOnCursorUpdateAfterAttach001.");
317     sptr<OnTextChangedListener> textListener = new TextListener();
318     auto ret = inputMethodController_->Attach(textListener);
319     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
320     CursorInfo cursorInfo = { .top = 5, .left = 5, .height = 5, .width = 0.8 };
321     ret = inputMethodController_->OnCursorUpdate(cursorInfo);
322     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
323     TextTotalConfig totalConfig;
324     ret = inputMethodAbility_->GetTextConfig(totalConfig);
325     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
326     EXPECT_EQ(totalConfig.cursorInfo.height, -1);
327     EXPECT_EQ(totalConfig.cursorInfo.width, -1);
328     EXPECT_EQ(totalConfig.cursorInfo.left, -1);
329     EXPECT_EQ(totalConfig.cursorInfo.top, -1);
330 }
331 
332 /**
333  * @tc.name: testOnCursorUpdateAfterAttach002
334  * @tc.desc: test OnCursorUpdate after attach
335  * @tc.type: FUNC
336  */
337 HWTEST_F(InputMethodAttachTest, testOnCursorUpdateAfterAttach002, TestSize.Level0)
338 {
339     IMSA_HILOGI("test testOnCursorUpdateAfterAttach002.");
340     sptr<OnTextChangedListener> textListener = new TextListener();
341     InputAttribute attribute;
342     attribute.inputPattern = 3;
343     attribute.enterKeyType = 2;
344     TextConfig config;
345     config.inputAttribute = attribute;
346     config.cursorInfo = { .top = 1, .left = 1, .height = 1, .width = 0.4 };
347     auto ret = inputMethodController_->Attach(textListener, true, config);
348     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
349     CursorInfo cursorInfo = { .top = 5, .left = 5, .height = 5, .width = 0.8 };
350     ret = inputMethodController_->OnCursorUpdate(cursorInfo);
351     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
352     TextTotalConfig totalConfig;
353     ret = inputMethodAbility_->GetTextConfig(totalConfig);
354     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
355     EXPECT_EQ(totalConfig.cursorInfo, config.cursorInfo);
356 }
357 
358 /**
359  * @tc.name: testOnSelectionChangeAfterAttach002
360  * @tc.desc: test OnSelectionChange after attach
361  * @tc.type: FUNC
362  */
363 HWTEST_F(InputMethodAttachTest, testOnSelectionChangeAfterAttach002, TestSize.Level0)
364 {
365     IMSA_HILOGI("test testOnSelectionChangeAfterAttach002.");
366     sptr<OnTextChangedListener> textListener = new TextListener();
367     InputAttribute attribute;
368     attribute.inputPattern = 3;
369     attribute.enterKeyType = 2;
370     TextConfig config;
371     config.inputAttribute = attribute;
372     config.range = { .start = 1, .end = 2 };
373     auto ret = inputMethodController_->Attach(textListener, false, config);
374     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
375     int start = 0;
376     int end = 1;
377     ret = inputMethodController_->OnSelectionChange(Str8ToStr16("aaa"), start, end);
378     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
379 
380     TextTotalConfig totalConfig;
381     ret = inputMethodAbility_->GetTextConfig(totalConfig);
382     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
383     EXPECT_EQ(totalConfig.textSelection.newBegin, config.range.start);
384     EXPECT_EQ(totalConfig.textSelection.newEnd, config.range.end);
385     EXPECT_EQ(totalConfig.textSelection.oldBegin, 0);
386     EXPECT_EQ(totalConfig.textSelection.oldEnd, 0);
387 }
388 
389 /**
390  * @tc.name: testOnConfigurationChangeAfterAttach001
391  * @tc.desc: test OnConfigurationChange after attach
392  * @tc.type: FUNC
393  */
394 HWTEST_F(InputMethodAttachTest, testOnConfigurationChangeAfterAttach001, TestSize.Level0)
395 {
396     IMSA_HILOGI("test testOnConfigurationChangeAfterAttach001.");
397     sptr<OnTextChangedListener> textListener = new TextListener();
398     auto ret = inputMethodController_->Attach(textListener);
399     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
400 
401     Configuration config;
402     config.SetTextInputType(TextInputType::DATETIME);
403     config.SetEnterKeyType(EnterKeyType::NEXT);
404     ret = inputMethodController_->OnConfigurationChange(config);
405     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
406 
407     TextTotalConfig totalConfig;
408     ret = inputMethodAbility_->GetTextConfig(totalConfig);
409     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
410     EXPECT_EQ(totalConfig.inputAttribute.inputPattern, static_cast<int32_t>(TextInputType::DATETIME));
411     EXPECT_EQ(totalConfig.inputAttribute.enterKeyType, static_cast<int32_t>(EnterKeyType::NEXT));
412 }
413 
414 /**
415  * @tc.name: testOnConfigurationChangeAfterAttach002
416  * @tc.desc: test OnConfigurationChange after attach
417  * @tc.type: FUNC
418  */
419 HWTEST_F(InputMethodAttachTest, testOnConfigurationChangeAfterAttach002, TestSize.Level0)
420 {
421     IMSA_HILOGI("test testOnConfigurationChangeAfterAttach002.");
422     sptr<OnTextChangedListener> textListener = new TextListener();
423     InputAttribute attribute;
424     attribute.inputPattern = 3;
425     attribute.enterKeyType = 2;
426     TextConfig config;
427     config.inputAttribute = attribute;
428     auto ret = inputMethodController_->Attach(textListener, false, config);
429     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
430 
431     Configuration configuration;
432     configuration.SetTextInputType(TextInputType::DATETIME);
433     configuration.SetEnterKeyType(EnterKeyType::NEXT);
434     ret = inputMethodController_->OnConfigurationChange(configuration);
435     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
436 
437     TextTotalConfig totalConfig;
438     ret = inputMethodAbility_->GetTextConfig(totalConfig);
439     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
440     EXPECT_EQ(totalConfig.inputAttribute.inputPattern, static_cast<int32_t>(configuration.GetTextInputType()));
441     EXPECT_EQ(totalConfig.inputAttribute.enterKeyType, static_cast<int32_t>(configuration.GetEnterKeyType()));
442 }
443 
444 /**
445  * @tc.name: testSetCallingWindowAfterAttach002
446  * @tc.desc: test SetCallingWindow after attach
447  * @tc.type: FUNC
448  */
449 HWTEST_F(InputMethodAttachTest, testSetCallingWindowAfterAttach002, TestSize.Level0)
450 {
451     IMSA_HILOGI("test testSetCallingWindowAfterAttach002.");
452     sptr<OnTextChangedListener> textListener = new TextListener();
453     InputAttribute attribute;
454     attribute.inputPattern = 3;
455     attribute.enterKeyType = 2;
456     TextConfig config;
457     config.inputAttribute = attribute;
458     config.windowId = 88;
459     auto ret = inputMethodController_->Attach(textListener, false, config);
460     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
461 
462     uint32_t windowId = 99;
463     ret = inputMethodController_->SetCallingWindow(windowId);
464     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
465 
466     TextTotalConfig totalConfig;
467     ret = inputMethodAbility_->GetTextConfig(totalConfig);
468     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
469     EXPECT_EQ(totalConfig.windowId, config.windowId);
470 }
471 
472 /**
473  * @tc.name: testOnCursorUpdate001
474  * @tc.desc: test OnCursorUpdate after attach
475  * @tc.type: FUNC
476  */
477 HWTEST_F(InputMethodAttachTest, testOnCursorUpdate001, TestSize.Level0)
478 {
479     IMSA_HILOGI("test testOnCursorUpdate001.");
480     sptr<OnTextChangedListener> textListener = new TextListener();
481     auto ret = inputMethodController_->Attach(textListener);
482     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
483     CursorInfo cursorInfo = { .top = 5, .left = 5, .height = 5, .width = 0.8 };
484     ret = inputMethodController_->OnCursorUpdate(cursorInfo);
485     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
486 
487     InputAttribute attribute;
488     attribute.inputPattern = 3;
489     attribute.enterKeyType = 2;
490     TextConfig config;
491     config.inputAttribute = attribute;
492     CursorInfo cursorInfo2 = { .top = 10, .left = 9, .width = 8, .height = 7 };
493     config.cursorInfo = cursorInfo2;
494     ret = inputMethodController_->Attach(textListener, false, config);
495     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
496 
497     TextTotalConfig totalConfig;
498     ret = inputMethodAbility_->GetTextConfig(totalConfig);
499     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
500     EXPECT_EQ(totalConfig.cursorInfo, cursorInfo2);
501 }
502 
503 /**
504  * @tc.name: testOnSelectionChange
505  * @tc.desc: test OnSelectionChange after attach
506  * @tc.type: FUNC
507  */
508 HWTEST_F(InputMethodAttachTest, testOnSelectionChange, TestSize.Level0)
509 {
510     IMSA_HILOGI("test testOnSelectionChange.");
511     sptr<OnTextChangedListener> textListener = new TextListener();
512     auto ret = inputMethodController_->Attach(textListener);
513     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
514     int start = 0;
515     int end = 1;
516     ret = inputMethodController_->OnSelectionChange(Str8ToStr16("bbb"), start, end);
517     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
518 
519     InputAttribute attribute;
520     attribute.inputPattern = 3;
521     attribute.enterKeyType = 2;
522     TextConfig config;
523     config.inputAttribute = attribute;
524     config.range.start = 10;
525     config.range.end = 20;
526     ret = inputMethodController_->Attach(textListener, false, config);
527     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
528 
529     TextTotalConfig totalConfig;
530     ret = inputMethodAbility_->GetTextConfig(totalConfig);
531     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
532     EXPECT_EQ(totalConfig.textSelection.newBegin, config.range.start);
533     EXPECT_EQ(totalConfig.textSelection.newEnd, config.range.end);
534     EXPECT_EQ(totalConfig.textSelection.oldBegin, 0);
535     EXPECT_EQ(totalConfig.textSelection.oldEnd, 0);
536 }
537 
538 /**
539  * @tc.name: testOnConfigurationChange002
540  * @tc.desc: test OnConfigurationChange after attach
541  * @tc.type: FUNC
542  */
543 HWTEST_F(InputMethodAttachTest, testOnConfigurationChange002, TestSize.Level0)
544 {
545     IMSA_HILOGI("test testOnConfigurationChange002.");
546     sptr<OnTextChangedListener> textListener = new TextListener();
547     auto ret = inputMethodController_->Attach(textListener);
548     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
549 
550     Configuration configuration;
551     configuration.SetTextInputType(TextInputType::DATETIME);
552     configuration.SetEnterKeyType(EnterKeyType::NEXT);
553     ret = inputMethodController_->OnConfigurationChange(configuration);
554     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
555 
556     InputAttribute attribute;
557     attribute.inputPattern = 3;
558     attribute.enterKeyType = 2;
559     TextConfig config;
560     config.inputAttribute = attribute;
561     config.inputAttribute.enterKeyType = 5;
562     config.inputAttribute.inputPattern = 5;
563     ret = inputMethodController_->Attach(textListener, false, config);
564     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
565 
566     TextTotalConfig totalConfig;
567     ret = inputMethodAbility_->GetTextConfig(totalConfig);
568     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
569 
570     EXPECT_EQ(totalConfig.inputAttribute, config.inputAttribute);
571 }
572 
573 /**
574  * @tc.name: testSetCallingWindow
575  * @tc.desc: test SetCallingWindow after attach
576  * @tc.type: FUNC
577  */
578 HWTEST_F(InputMethodAttachTest, testSetCallingWindow, TestSize.Level0)
579 {
580     IMSA_HILOGI("test testSetCallingWindow.");
581     sptr<OnTextChangedListener> textListener = new TextListener();
582     auto ret = inputMethodController_->Attach(textListener);
583     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
584 
585     uint32_t windowId = 88;
586     ret = inputMethodController_->SetCallingWindow(windowId);
587     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
588 
589     InputAttribute attribute;
590     attribute.inputPattern = 3;
591     attribute.enterKeyType = 2;
592     TextConfig config;
593     config.windowId = 77;
594     ret = inputMethodController_->Attach(textListener, false, config);
595     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
596 
597     TextTotalConfig totalConfig;
598     ret = inputMethodAbility_->GetTextConfig(totalConfig);
599     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
600 
601     EXPECT_EQ(totalConfig.windowId, config.windowId);
602 }
603 } // namespace MiscServices
604 } // namespace OHOS
605