diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/InputMethodDrawnControl/InputMethodControlService.ts b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/InputMethodDrawnControl/InputMethodControlService.ts new file mode 100755 index 0000000000000000000000000000000000000000..343cd12a2bb28feb9648681e3bbe1cbe8dc3ca8a --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/InputMethodDrawnControl/InputMethodControlService.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; +import { KeyboardDelegate } from './KeyboardDelegate'; + +export default class InputMethodControlService extends InputMethodExtensionAbility { + private keyboardDelegate: KeyboardDelegate; + + onCreate(want) { + this.keyboardDelegate = new KeyboardDelegate(this.context); + this.keyboardDelegate.onCreate(); // 初始化窗口 + } + + onDestroy() { + console.log("onDestroy inputStageService**"); + } +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/InputMethodDrawnControl/KeyboardDelegate.ts b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/InputMethodDrawnControl/KeyboardDelegate.ts new file mode 100755 index 0000000000000000000000000000000000000000..0d19e826e465b40633b07dbbcf47ac05ff78c3ff --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/InputMethodDrawnControl/KeyboardDelegate.ts @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import inputMethodEngine from '@ohos.inputMethodEngine'; +import display from '@ohos.display'; +import windowManager from '@ohos.window'; +import promptAction from '@ohos.promptAction'; +import commoneventmanager from '@ohos.commonEventManager'; + +let inputMethodAbility = inputMethodEngine.getInputMethodAbility(); +let inputKeyboardDelegate = inputMethodEngine.getKeyboardDelegate(); + +const TAG = 'KeyboardDelegate'; + +export class KeyboardDelegate { + mContext; + WINDOW_TYPE_INPUT_METHOD_FLOAT = 2105; + windowName = 'inputApp'; + private windowHeight: number = 0; + private windowWidth: number = 0; + private nonBarPosition: number = 0; + + constructor(context) { + this.mContext = context; + } + + private sleep(timeout): Promise { + return new Promise(resolve => { + let t = setTimeout(() => { + clearTimeout(t); + resolve(null); + }, timeout); + }); + }; + + public onCreate(): void { + this.initWindow(); + let that = this; + inputMethodAbility.on("inputStop", () => { + inputMethodAbility.off("inputStop", () => { + console.log('====>inputMethodEngine delete inputStop notification.'); + }); + try{ + that.mContext.destroy((err) => { + console.info(TAG + '====>inputMethodAbility destroy err:' + JSON.stringify(err)); + }); + }catch(err){ + console.info(TAG + '====>inputMethodAbility destroy catch err:' + JSON.stringify(err)); + console.info(TAG + '====>inputMethodAbility destroy catch err:' + err); + } + }) + + function subscriberCallback(err, data) { + console.debug(TAG + '====>receive event err:' + JSON.stringify(err)); + console.debug(TAG + '====>receive event data:' + JSON.stringify(data)); + switch (data.code) { + case 10: + console.debug(TAG + '====>SUB_Misc_inputMethod_onHandleExtendAction_0010 event:' + data.event); + that.SUB_Misc_inputMethod_onHandleExtendAction_0010(); + break; + case 20: + console.debug(TAG + '====>SUB_Misc_inputMethod_offHandleExtendAction_0020 event:' + data.event); + that.SUB_Misc_inputMethod_offHandleExtendAction_0020(); + break; + case 30: + console.debug(TAG + '====>SUB_Misc_inputMethod_onSendFunctionKey_0030 event:' + data.event); + that.SUB_Misc_inputMethod_onSendFunctionKey_0030(); + break; + case 40: + console.debug(TAG + '====>SUB_Misc_inputMethod_offSendFunctionKey_0040 event:' + data.event); + that.SUB_Misc_inputMethod_offSendFunctionKey_0040(); + break; + } + } + + var commonEventSubscribeInfo = { + events: ["test"] + }; + + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then(function (data) { + subscriber = data; + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.debug(TAG + '====>scene subscribe finish===='); + }); + } + + public initWindow(): void { + let dis = display.getDefaultDisplaySync(); + var dWidth = dis.width; + var dHeight = dis.height; + var keyHeightRate = 0.47; + var keyHeight = dHeight * keyHeightRate; + this.windowWidth = dWidth; + this.windowHeight = keyHeight; + this.nonBarPosition = dHeight - keyHeight; + + var config = { + name: this.windowName, + windowType: this.WINDOW_TYPE_INPUT_METHOD_FLOAT, + cts: this.mContext + }; + + windowManager.createWindow(config).then((win) => { + win.resize(dWidth, keyHeight).then(() => { + win.moveWindowTo(0, this.nonBarPosition).then(() => { + win.setUIContent('page/service/index').then(() => { + }); + }); + }); + }); + } + + public onDestroy(): void { + console.debug(TAG + '====>onDestroy'); + globalThis.textInputClient.getTextIndexAtCursor().then((index) => { + console.debug(TAG + '====>getTextIndexAtCursor index:' + index); + promptAction.showToast({ message: 'getTextIndexAtCursor success' + index, duration: 200, bottom: 500 }); + var win = windowManager.findWindow(this.windowName); + win.destroyWindow(); + this.mContext.terminateSelf(); + return true; + }).catch((err) => { + promptAction.showToast({ message: 'getTextIndexAtCursor failed', duration: 200, bottom: 500 }); + }); + } + + private publishCallback(err): void { + if (err) { + console.error(TAG + '====>publish failed:' + JSON.stringify(err)); + } else { + console.debug(TAG + '====>publish'); + } + } + + private SUB_Misc_inputMethod_onHandleExtendAction_0010(): void { + console.info(TAG + '====>SUB_Misc_inputMethod_onHandleExtendAction_0010 start'); + inputMethodAbility.on("inputStart", async (KeyboardDelegate, InputClient) => { + let t = setTimeout(async () => { + clearTimeout(t); + console.info(TAG + '====>SUB_Misc_inputMethod_onHandleExtendAction_0010 sendExtendAction start'); + await InputClient.sendExtendAction(0); + console.info(TAG + '====>SUB_Misc_inputMethod_onHandleExtendAction_0010 sendExtendAction end'); + }, 500); + }); + } + + private SUB_Misc_inputMethod_offHandleExtendAction_0020(): void { + console.info(TAG + '====>SUB_Misc_inputMethod_offHandleExtendAction_0020 start'); + inputMethodAbility.on("inputStart", async (KeyboardDelegate, InputClient) => { + let t = setTimeout(async () => { + clearTimeout(t); + console.info(TAG + '====>SUB_Misc_inputMethod_offHandleExtendAction_0020 sendExtendAction start'); + await InputClient.sendExtendAction(0); + await this.sleep(100); + await InputClient.sendExtendAction(0); + console.info(TAG + '====>SUB_Misc_inputMethod_offHandleExtendAction_0020 sendExtendAction end'); + }, 500); + }); + } + + private SUB_Misc_inputMethod_onSendFunctionKey_0030(): void { + console.info(TAG + '====>SUB_Misc_inputMethod_onSendFunctionKey_0030 start'); + inputMethodAbility.on("inputStart", async (KeyboardDelegate, InputClient) => { + let t = setTimeout(async () => { + clearTimeout(t); + console.info(TAG + '====>SUB_Misc_inputMethod_onSendFunctionKey_0030 sendExtendAction start'); + await InputClient.sendKeyFunction(0); + console.info(TAG + '====>SUB_Misc_inputMethod_onSendFunctionKey_0030 sendExtendAction end'); + }, 500); + }); + } + + private SUB_Misc_inputMethod_offSendFunctionKey_0040(): void { + console.info(TAG + '====>SUB_Misc_inputMethod_offSendFunctionKey_0040 start'); + inputMethodAbility.on("inputStart", async (KeyboardDelegate, InputClient) => { + let t = setTimeout(async () => { + clearTimeout(t); + console.info(TAG + '====>SUB_Misc_inputMethod_offSendFunctionKey_0040 sendExtendAction start'); + await InputClient.sendKeyFunction(0); + await this.sleep(100); + await InputClient.sendKeyFunction(0); + console.info(TAG + '====>SUB_Misc_inputMethod_offSendFunctionKey_0040 sendExtendAction end'); + }, 500); + }); + } + + +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/List.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/List.test.ets index 75096b934ad8596d9ba5c9776e589326883e6164..41f8ac59919c1b02960cf902ef668be2a26088d7 100644 --- a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/List.test.ets +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/List.test.ets @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import inputMethodDrawnControl from './inputMethod_drawnControl.test' import inputMethod_attach from './inputMethod_attach.test' import inputMethod_showTextInput_hideTextInput_detach from './inputMethod_showTextInput_hideTextInput_detach.test' import inputMethod_updateAttribute from './inputMethod_updateAttribute.test' @@ -20,6 +21,7 @@ import inputMethod_updateCursor from './inputMethod_updateCursor.test' import inputMethod_setCallingWindow from './inputMethod_setCallingWindow.test' export default function testsuite() { + inputMethodDrawnControl(); inputMethod_attach(); inputMethod_showTextInput_hideTextInput_detach(); inputMethod_updateAttribute(); diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_drawnControl.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_drawnControl.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..132810bdf83de02f90d0a4154bb51d4e31ba1a6a --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_drawnControl.test.ets @@ -0,0 +1,230 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import commoneventmanager from '@ohos.commonEventManager'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import subtype from '@ohos.InputMethodSubtype'; +import inputMethod from '@ohos.inputMethod'; +import display from '@ohos.display'; + + +export default function inputMethodDrawnControlJSUnit() { + describe('inputMethodDrawnControlTest', function () { + var inputSever = { + packageName: '', + methodId: '', + name: '', + id: '', + extra: {} + } + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeAll(async (done) => { + let inputM = inputMethod.getCurrentInputMethod(); + console.info("====>beforeAll: getCurrentInputMethod inputMethodEngineJSUnit to: " + JSON.stringify(inputM)); + inputSever.packageName = inputM.packageName; + inputSever.methodId = inputM.methodId; + inputSever.name = inputM.packageName; + inputSever.id = inputM.methodId; + + let inputDemoService: subtype = { + id: "inputMethodWindService", + label: "", + name: "com.acts.inputmethoddrawncontrol.test", + mode: "lower", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + } + try { + console.info("====>beforeAll: inputMethodEngineJSUnit switchCurrentInputMethodSubtype success" + JSON.stringify(inputDemoService)); + await inputMethod.switchCurrentInputMethodSubtype(inputDemoService); + setTimeout(() => { + console.info("====>beforeAll: inputMethodEngineJSUnit switchCurrentInputMethodSubtype success"); + done(); + }, 2000) + } catch (err) { + console.info("====>beforeAll: inputMethodEngineJSUnit fail" + JSON.stringify(err)); + } + }) + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterAll(async (done) => { + try { + await inputMethod.switchInputMethod(inputSever); + setTimeout(() => { + console.info("====>afterAll: inputMethodEngineJSUnit switchInputMethod success"); + done(); + }, 2000) + } catch (err) { + console.info("====>afterAll: inputMethodEngineJSUnit fail" + JSON.stringify(err)); + } + }) + + it('SUB_Misc_inputMethod_onHandleExtendAction_0010',0, async function (done) { + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + async function publishCallback(err){ + console.info("====>SUB_Misc_inputMethod_onHandleExtendAction_0010 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_inputMethod_onHandleExtendAction_0010 publishCallback failed:" + JSON.stringify(err)); + } else { + try { + await inputMethod.getController().attach(true, ATTRIBUTE); + console.info("====>SUB_Misc_inputMethod_onHandleExtendAction_0010 onHandleExtendAction start"); + inputMethod.getController().on("handleExtendAction",async (action) => { + console.info("====>SUB_Misc_inputMethod_onHandleExtendAction_0010 onHandleExtendAction success: " + action); + inputMethod.getController().off("handleExtendAction"); + await inputMethod.getController().detach(); + expect(action).assertEqual(0); + done(); + }); + } catch (err) { + console.info("====>SUB_Misc_inputMethod_onHandleExtendAction_0010 onHandleExtendAction catch err: " + JSON.stringify(err)); + } + } + } + + var commonEventPublishData = { + code:10 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }); + + it('SUB_Misc_inputMethod_offHandleExtendAction_0020',0, async function (done) { + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + let flag = true; + async function publishCallback(err){ + console.info("====>SUB_Misc_inputMethod_offHandleExtendAction_0020 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_inputMethod_offHandleExtendAction_0020 publishCallback failed:" + JSON.stringify(err)); + } else { + try { + await inputMethod.getController().attach(true, ATTRIBUTE); + console.info("====>SUB_Misc_inputMethod_offHandleExtendAction_0020 offHandleExtendAction start"); + inputMethod.getController().on("handleExtendAction",async (action) => { + flag = false; + console.info("====>SUB_Misc_inputMethod_offHandleExtendAction_0020 flag: " + flag); + }); + inputMethod.getController().off("handleExtendAction"); + let t = setTimeout(async () => { + try { + clearTimeout(t); + await inputMethod.getController().detach(); + if (flag){ + expect(true).assertEqual(true); + console.info("====>SUB_Misc_inputMethod_offHandleExtendAction_0020 offHandleExtendAction success"); + }else{ + console.info("====>SUB_Misc_inputMethod_offHandleExtendAction_0020 offHandleExtendAction fail"); + expect().assertFail(); + } + } catch (err) { + console.info("====>SUB_Misc_inputMethod_offHandleExtendAction_0020 offHandleExtendAction catch err: " + JSON.stringify(err)); + } + done(); + }, 1000) + } catch (err) { + console.info("====>SUB_Misc_inputMethod_offHandleExtendAction_0020 offHandleExtendAction catch err: " + JSON.stringify(err)); + } + } + } + + var commonEventPublishData = { + code:20 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }); + + it('SUB_Misc_inputMethod_onSendFunctionKey_0030',0, async function (done) { + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + async function publishCallback(err){ + console.info("====>SUB_Misc_inputMethod_onSendFunctionKey_0030 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_inputMethod_onSendFunctionKey_0030 publishCallback failed:" + JSON.stringify(err)); + } else { + try { + await inputMethod.getController().attach(true, ATTRIBUTE); + console.info("====>SUB_Misc_inputMethod_onSendFunctionKey_0030 onSendFunctionKey start"); + inputMethod.getController().on("sendFunctionKey",async (FunctionKey) => { + console.info("====>SUB_Misc_inputMethod_onSendFunctionKey_0030 onSendFunctionKey success: " + FunctionKey.enterKeyType); + inputMethod.getController().off("sendFunctionKey"); + await inputMethod.getController().detach(); + expect(FunctionKey.enterKeyType).assertEqual(0); + done(); + }); + } catch (err) { + console.info("====>SUB_Misc_inputMethod_onSendFunctionKey_0030 onSendFunctionKey catch err: " + JSON.stringify(err)); + } + } + } + + var commonEventPublishData = { + code:30 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }); + + it('SUB_Misc_inputMethod_offSendFunctionKey_0040',0, async function (done) { + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + let flag = true; + async function publishCallback(err){ + console.info("====>SUB_Misc_inputMethod_offSendFunctionKey_0040 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_inputMethod_offSendFunctionKey_0040 publishCallback failed:" + JSON.stringify(err)); + } else { + try { + await inputMethod.getController().attach(true, ATTRIBUTE); + console.info("====>SUB_Misc_inputMethod_offSendFunctionKey_0040 offSendFunctionKey start"); + inputMethod.getController().on("sendFunctionKey",async (FunctionKey) => { + flag = false; + console.info("====>SUB_Misc_inputMethod_offSendFunctionKey_0040 flag: " + flag); + }); + inputMethod.getController().off("sendFunctionKey"); + let t = setTimeout(async () => { + try { + clearTimeout(t); + await inputMethod.getController().detach(); + if (flag){ + expect(true).assertEqual(true); + console.info("====>SUB_Misc_inputMethod_offSendFunctionKey_0040 offSendFunctionKey success"); + }else{ + console.info("====>SUB_Misc_inputMethod_offSendFunctionKey_0040 offSendFunctionKey fail"); + expect().assertFail(); + } + } catch (err) { + console.info("====>SUB_Misc_inputMethod_offSendFunctionKey_0040 offSendFunctionKey catch err: " + JSON.stringify(err)); + } + done(); + }, 1000) + } catch (err) { + console.info("====>SUB_Misc_inputMethod_offSendFunctionKey_0040 offSendFunctionKey catch err: " + JSON.stringify(err)); + } + } + } + + var commonEventPublishData = { + code:40 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }); + + + }) +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/module.json b/inputmethod/InputMethodDrawnControl/entry/src/main/module.json index ef30ac2abc527579ad5574353e39151a67782b30..4d2c86b0ff029fc874a699457f25cfccb3705980 100644 --- a/inputmethod/InputMethodDrawnControl/entry/src/main/module.json +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/module.json @@ -36,6 +36,16 @@ ] } ], + "extensionAbilities": [ + { + "description": "inputPanelTest", + "icon": "$media:icon", + "name": "inputMethodWindService", + "srcEntrance": "./ets/InputMethodDrawnControl/InputMethodControlService.ts", + "type": "inputMethod", + "visible":true + } + ], "requestPermissions": [ { "name":"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", diff --git a/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodAbility/KeyboardDelegate.ts b/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodAbility/KeyboardDelegate.ts index fe3f4c1348c477d215e0cadf13c0ccf95fe752b7..613bdcd71224034a811de35462a721a804b83082 100644 --- a/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodAbility/KeyboardDelegate.ts +++ b/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodAbility/KeyboardDelegate.ts @@ -215,6 +215,14 @@ export class KeyboardDelegate { console.debug(TAG + '====>Sub_Misc_inputMethod_offSelectByMovement_0140 event:' + data.event); that.Sub_Misc_inputMethod_offSelectByMovement_0140(); break; + case 170: + console.debug(TAG + '====>Sub_Misc_inputMethod_sendExtendAction_0170 event:' + data.event); + that.Sub_Misc_inputMethod_sendExtendAction_0170(); + break; + case 180: + console.debug(TAG + '====>Sub_Misc_inputMethod_sendExtendAction_0180 event:' + data.event); + that.Sub_Misc_inputMethod_sendExtendAction_0180(); + break; } } @@ -1502,5 +1510,70 @@ export class KeyboardDelegate { } } + private Sub_Misc_inputMethod_sendExtendAction_0170(): void{ + console.debug(TAG + '====>receive Sub_Misc_inputMethod_sendExtendAction_0170 data'); + inputMethodAbility.on('inputStart', async (KeyboardDelegate, InputClient) => { + inputMethodAbility.off('inputStart'); + let commonEventPublishData; + if (InputClient == null) { + commonEventPublishData = { + data: "FAILED" + }; + commoneventmanager.publish("Sub_Misc_inputMethod_sendExtendAction_0170", commonEventPublishData, this.publishCallback); + } else { + try { + InputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err,) => { + if (err) { + console.debug(TAG + '====>Sub_Misc_inputMethod_sendExtendAction_0170 sendExtendAction err:' + JSON.stringify(err)); + commonEventPublishData = { + data: "FAILED" + }; + } else { + console.debug(TAG + '====>Sub_Misc_inputMethod_sendExtendAction_0170 sendExtendAction success' ); + commonEventPublishData = { + data: "SUCCESS" + }; + } + commoneventmanager.publish("Sub_Misc_inputMethod_sendExtendAction_0170", commonEventPublishData, this.publishCallback); + }); + } catch (err) { + commonEventPublishData = { + data: "FAILED" + }; + console.debug(TAG + '====>Sub_Misc_inputMethod_sendExtendAction_0170 getTextIndexAtCursor throw_err:'); + commoneventmanager.publish("Sub_Misc_inputMethod_sendExtendAction_0170", commonEventPublishData, this.publishCallback); + } + } + }); + } + + private Sub_Misc_inputMethod_sendExtendAction_0180(): void{ + console.debug(TAG + '====>receive Sub_Misc_inputMethod_sendExtendAction_0180 data'); + inputMethodAbility.on('inputStart', async (KeyboardDelegate, InputClient) => { + inputMethodAbility.off('inputStart'); + let commonEventPublishData; + if (InputClient == null) { + commonEventPublishData = { + data: "FAILED" + }; + commoneventmanager.publish("Sub_Misc_inputMethod_sendExtendAction_0180", commonEventPublishData, this.publishCallback); + } else { + try { + await InputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY); + console.debug(TAG + '====>Sub_Misc_inputMethod_sendExtendAction_0180 sendExtendAction success:'); + commonEventPublishData = { + data: "SUCCESS" + }; + } catch (err) { + commonEventPublishData = { + data: "FAILED" + }; + console.debug(TAG + '====>Sub_Misc_inputMethod_sendExtendAction_0180 sendExtendAction catch err:'); + } + commoneventmanager.publish("Sub_Misc_inputMethod_sendExtendAction_0180", commonEventPublishData, this.publishCallback); + } + }); + } + } \ No newline at end of file diff --git a/inputmethod/InputMethodEngine/entry/src/main/ets/test/inputMethodAbility.test.ets b/inputmethod/InputMethodEngine/entry/src/main/ets/test/inputMethodAbility.test.ets index 06a57c6805f6fa2fc5261168912069ace66f498f..d335776574274c44e4200034f151e1e4b0144ceb 100644 --- a/inputmethod/InputMethodEngine/entry/src/main/ets/test/inputMethodAbility.test.ets +++ b/inputmethod/InputMethodEngine/entry/src/main/ets/test/inputMethodAbility.test.ets @@ -57,7 +57,7 @@ export default function inputMethodAbility() { inputServer.name = inputM.packageName; inputServer.id = inputM.methodId; console.info("====>beforeAll inputMethodStageJSUnit start"); - let inputDemoService: subtype ={ + inputDemoService = { id: 'inputStageService', label: '', name: 'com.acts.inputmethodengine.test', @@ -2560,13 +2560,17 @@ export default function inputMethodAbility() { } else { let t = setTimeout(async () => { await inputMethod.switchInputMethod(inputServer); - console.info("====>inputMethodAbility_test_091 setTimeout first"); + console.info("====>inputMethodAbility_test_091 setTimeout first: " + JSON.stringify(inputServer)); let t1 = setTimeout(async () => { - done(); console.info("====>inputMethodAbility_test_091 setTimeout second: " + flag); expect(flag).assertTrue(); clearTimeout(t1); await inputMethod.switchCurrentInputMethodSubtype(inputDemoService); + console.info("====>inputMethodAbility_test_091 switchInputMethod second" + JSON.stringify(inputDemoService)); + let t2 = setTimeout(() => { + clearTimeout(t2) + done(); + }, 500) },1000) clearTimeout(t); }, 1000) @@ -2590,5 +2594,115 @@ export default function inputMethodAbility() { commonEventManager.publish('test', commonEventPublishData, publishCallback); }); + it('Sub_Misc_inputMethod_sendExtendAction_0170', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 unSubscriberCallback start"); + if (err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 subscriberCallback data:" + + JSON.stringify(data)); + commonEventManager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500) + } + + function publishCallback(err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 publishCallback start"); + if (err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 publishCallback failed:" + JSON.stringify(err)); + } else { + runCmd(getFocusCmd); + } + } + + var commonEventSubscribeInfo = { + events: ["Sub_Misc_inputMethod_sendExtendAction_0170"] + } + var subscriber; + commonEventManager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 subscriber data:" + JSON.stringify(data)); + commonEventManager.subscribe(subscriber, subscriberCallback); + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0170 subscriber finish"); + }) + + var commonEventPublishData = { + code: 170 + } + commonEventManager.publish('test', commonEventPublishData, publishCallback); + }); + + it('Sub_Misc_inputMethod_sendExtendAction_0180', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 unSubscriberCallback start"); + if (err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 subscriberCallback data:" + + JSON.stringify(data)); + commonEventManager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500) + } + + function publishCallback(err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 publishCallback start"); + if (err){ + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 publishCallback failed:" + JSON.stringify(err)); + } else { + runCmd(getFocusCmd); + } + } + + var commonEventSubscribeInfo = { + events: ["Sub_Misc_inputMethod_sendExtendAction_0180"] + } + var subscriber; + commonEventManager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 subscriber data:" + JSON.stringify(data)); + commonEventManager.subscribe(subscriber, subscriberCallback); + console.info("====>Sub_Misc_inputMethod_sendExtendAction_0180 subscriber finish"); + }) + + var commonEventPublishData = { + code: 180 + } + commonEventManager.publish('test', commonEventPublishData, publishCallback); + }); + }); };