未验证 提交 7eb26d1e 编写于 作者: O openharmony_ci 提交者: Gitee

!8386 【master】【杂散】【输入法框架】新增inputmethod无权限用用例

Merge pull request !8386 from 张育帅/master
......@@ -15,6 +15,7 @@ import("//build/ohos_var.gni")
group("inputmethod") {
testonly = true
deps = [
"InputMethodAuthorityTest:ActsInputMethodAuthorityTest",
"InputMethodEngine:ActsInputMethodEngineTest",
"InputMethodTest_Stage:ActsImeAbilityTest",
"InputMethodTest_ets:ActsInputMethodEtsTest",
......
{
"app":{
"bundleName":"com.acts.inputmethodauthority.test",
"vendor":"hw",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:app_name",
"description":"$string:description_application",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
}
}
}
{
"string":[
{
"name":"app_name",
"value":"ohosProject"
}
]
}
\ No newline at end of file
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsInputMethodAuthorityTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":IMExtAbility_ets_assets",
":IMExtAbility_resources",
]
ets2abc = true
certificate_profile = "signature/ActsInputMethodAuthorityTest.p7b"
hap_name = "ActsInputMethodAuthorityTest"
subsystem_name = "inputmethod"
part_name = "imf"
}
ohos_app_scope("IMExtAbility_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("IMExtAbility_ets_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("IMExtAbility_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":IMExtAbility_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.acts.inputmethodauthority.test",
"module-name": "entry_test",
"shell-timeout": "600000"
},
"kits": [{
"test-file-name": [
"ActsInputMethodAuthorityTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}]
}
/*
* 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 AbilityStage from "@ohos.app.ability.AbilityStage";
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage onCreate");
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
/*
* 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 Ability from '@ohos.app.ability.UIAbility';
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability
console.info("ImExtAbility onCreate");
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.info("ImExtAbility onDestroy");
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.info("ImExtAbility onWindowStageCreate");
globalThis.abilityContext = this.context;
windowStage.setUIContent(this.context, "pages/index/index", null);
console.info("ImExtAbility onWindowStageCreate finish");
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.info("ImExtAbility onWindowStageDestroy");
}
onForeground() {
// Ability has brought to foreground
console.info("ImExtAbility onForeground");
}
onBackground() {
// Ability has back to background
console.info("ImExtAbility onBackground");
}
};
\ No newline at end of file
/*
* 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 TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
var abilityDelegator = undefined;
var abilityDelegatorArguments = undefined;
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`;
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err));
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ");
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility';
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback);
var cmd = 'aa start -d 0 -a com.acts.inputmethodauthority.test.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName;
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters);
var debug = abilityDelegatorArguments.parameters["-D"];
if (debug == 'true')
{
cmd += ' -D';
}
console.info('cmd : ' + cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
});
console.info('OpenHarmonyTestRunner onRun end');
}
};
\ No newline at end of file
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../test/List.test'
@Entry
@Component
struct Index {
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {})
}
.width('100%')
.height('100%')
}
aboutToAppear(){
let abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
}
\ No newline at end of file
/*
* 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 inputMethodAuthorityJSUnit from './inputmethodauthority.test';
export default function testsuite() {
inputMethodAuthorityJSUnit();
}
\ No newline at end of file
/**
* 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 inputMethod from '@ohos.inputMethod';
import subtype from '@ohos.InputMethodSubtype';
export default function inputMethodAuthorityJSUnit() {
describe('inputMethodAuthorityJSUnit', function () {
console.info("====>************* inputMethodAuthorityJSUnit settings Test start*************");
/*
* @tc.number inputmethod_test_switchInputMethod_001
* @tc.name Test Indicates the input method which will replace the current one.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_switchInputMethod_001', 0, async function (done) {
console.info("====>************* inputmethod_test_switchInputMethod_001 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputmethod_test_switchInputMethod_001 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName: inputM.packageName,
methodId: inputM.methodId,
name: inputM.packageName,
id: inputM.methodId,
extra: {}
}
inputMethod.switchInputMethod(inputMethodProperty).then(data => {
console.info("====>inputmethod_test_switchInputMethod_001 data:" + data)
expect(data == true).assertTrue();
console.info("====>************* inputmethod_test_switchInputMethod_001 Test end*************");
done();
}).catch(err => {
console.info("====>inputmethod_test_switchInputMethod_001 err:" + err)
expect().assertFail();
done();
});
});
/*
* @tc.number inputmethod_test_switchInputMethod_002
* @tc.name Test Indicates the input method which will replace the current one.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_switchInputMethod_002', 0, async function (done) {
console.info("====>************* inputmethod_test_switchInputMethod_002 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputmethod_test_switchInputMethod_002 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName: inputM.packageName,
methodId: inputM.methodId,
name: inputM.packageName,
id: inputM.methodId,
extra: {}
}
inputMethod.switchInputMethod(inputMethodProperty, (err, data) => {
try {
if (err) {
console.info("====>inputmethod_test_switchInputMethod_002 error:" + err);
expect().assertFail();
done();
}
console.info("====>inputmethod_test_switchInputMethod_002 data:" + data)
console.info("====>************* inputmethod_test_switchInputMethod_002 Test end*************");
expect(data == true).assertTrue();
done();
} catch (err) {
console.info("====>inputmethod_test_switchInputMethod_002 catch error:" + err);
done();
}
});
});
/*
* @tc.number inputmethod_test_showSoftKeyboard_001
* @tc.name Test Indicates the input method which will show softboard with calback.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.showSoftKeyboard((err) => {
try {
if(err == undefined){
expect().assertFail()
done();
}else{
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_showSoftKeyboard_001 Test end*************");
done();
}
} catch (err) {
console.info("====>inputmethod_test_showSoftKeyboard_001 err tests fail" + JSON.stringify(err));
done();
}
});
});
/*
* @tc.number inputmethod_test_showSoftKeyboard_002
* @tc.name Test Indicates the input method which will show softboard with Promise.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.showSoftKeyboard().then(() => {
try {
expect().assertFail()
done();
} catch (err) {
console.info("====>inputmethod_test_showSoftKeyboard_002 err tests fail" + JSON.stringify(err));
done();
}
}).catch((err) => {
console.info('====>inputmethod_test_showSoftKeyboard_002 promise failed : ' + JSON.stringify(err))
console.info('====>inputmethod_test_showSoftKeyboard_002 typeof(err.code): ' + typeof(err.code))
console.info('====>inputmethod_test_showSoftKeyboard_002 typeof(err.code): ' + err.code)
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_showSoftKeyboard_002 Test end*************");
done();
})
});
/*
* @tc.number inputmethod_test_hideSoftKeyboard_001
* @tc.name Test Indicates the input method which will hide softboard with calback.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.hideSoftKeyboard((err) => {
try {
if(err == undefined){
expect().assertFail()
done();
}else{
console.info('====>inputmethod_test_hideSoftKeyboard_001 callbacek failed : ' + JSON.stringify(err))
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_hideSoftKeyboard_001 Test end*************");
done();
}
} catch (err) {
console.info('====>inputmethod_test_hideSoftKeyboard_001 callbacek failed : ' + JSON.stringify(err))
done();
}
})
});
/*
* @tc.number inputmethod_test_hideSoftKeyboard_002
* @tc.name Test Indicates the input method which will hide softboard with Promise.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.hideSoftKeyboard().then(() => {
try {
expect().assertFail()
done();
} catch (err) {
console.info("====>inputmethod_test_hideSoftKeyboard_002 err tests fail" + JSON.stringify(err));
done();
}
}).catch((err) => {
console.info('====>inputmethod_test_hideSoftKeyboard_002 promise failed : ' + JSON.stringify(err))
expect(err.code).assertEqual(12800003);
console.info("====>************* inputmethod_test_hideSoftKeyboard_002 Test end*************");
done();
})
});
/*
* @tc.number inputMethod_test_switchCurrentInputMethodAndSubtype_001
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethod_test_switchCurrentInputMethodAndSubtype_001', 0, async function (done) {
console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_001 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_001 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName:inputM.packageName,
methodId:inputM.methodId,
name:inputM.packageName,
id:inputM.methodId,
label: "",
icon: "",
iconId: 124,
extra:{}
}
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_001 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,data) => {
try {
if (err) {
console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_001 err: ' + JSON.stringify(err));
expect( err.code === 12800008 ).assertTrue();
done();
}
console.info("====>inputMethod_test_switchCurrentInputMethodAndSubtype_001 data: " + JSON.stringify(data));
expect(data != null).assertTrue();
done();
} catch (error) {
console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_001 catch error: ' + JSON.stringify(error));
done();
}
});
console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_001 Test end*************");
});
/*
* @tc.number inputMethod_test_switchCurrentInputMethodAndSubtype_002
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethod_test_switchCurrentInputMethodAndSubtype_002', 0, async function (done) {
console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_002 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_002 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName:inputM.packageName,
methodId:inputM.methodId,
name:inputM.packageName,
id:inputM.methodId,
label: "",
icon: "",
iconId: 124,
extra:{}
}
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_002 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
try {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((data) => {
console.info("====>inputMethod_test_switchCurrentInputMethodAndSubtype_002 data: " + JSON.stringify(data));
expect(data != null).assertTrue();
done();
}).catch(err => {
console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_002 err: ' + JSON.stringify(err));
expect().assertFail();
done();
});
}catch (error) {
console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_002 catch error: ' + JSON.stringify(error));
expect().assertFail();
done();
};
console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_002 Test end*************");
});
/*
* @tc.number inputMethod_test_switchCurrentInputMethodSubtype_001
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethod_test_switchCurrentInputMethodSubtype_001', 0, async function (done) {
console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_001 Test start*************");
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethod_test_switchCurrentInputMethodSubtype_001 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty, (err,data) => {
try {
if (err) {
console.error('inputMethod_test_switchCurrentInputMethodSubtype_001 err: ' + JSON.stringify(err));
expect().assertFail();
done();
};
console.info("====>inputMethod_test_switchCurrentInputMethodSubtype_001 data: " + JSON.stringify(data));
expect(data != null).assertTrue();
done();
} catch (error) {
console.error('inputMethod_test_switchCurrentInputMethodSubtype_001 catch error: ' + JSON.stringify(error));
done();
}
});
console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_001 Test end*************");
});
/*
* @tc.number inputMethod_test_switchCurrentInputMethodSubtype_002
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethod_test_switchCurrentInputMethodSubtype_002', 0, async function (done) {
console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_002 Test start*************");
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethod_test_switchCurrentInputMethodSubtype_002 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
try {
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty).then((data) => {
console.info("====>inputMethod_test_switchCurrentInputMethodSubtype_002 data: " + JSON.stringify(data));
expect(data != null).assertTrue();
done();
}).catch(err => {
console.error('inputMethod_test_switchCurrentInputMethodSubtype_002 err: ' + JSON.stringify(err));
expect().assertFail();
done();
});
}catch (error) {
console.error('inputMethod_test_switchCurrentInputMethodSubtype_002 catch error: ' + JSON.stringify(error));
expect().assertFail();
done();
};
console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_002 Test end*************");
});
});
};
{
"module": {
"name": "entry_test",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:phone_entry_dsc",
"mainElement": "MainAbility",
"deviceTypes": [
"tablet",
"default",
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"metadata": [
{
"name": "ArkTSPartialUpdate",
"value": "false"
}
],
"abilities": [
{
"name": "com.acts.inputmethodauthority.test.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:phone_entry_main",
"icon": "$media:icon",
"label": "$string:entry_label",
"visible": true,
"orientation": "portrait",
"launchType": "singleton",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name":"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"need use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.CONNECT_IME_ABILITY"
}
]
}
}
{
"string": [
{
"name": "phone_entry_dsc",
"value": "i am an entry for phone"
},
{
"name": "phone_entry_main",
"value": "the phone entry ability"
},
{
"name": "entry_label",
"value": "ActsInputMethodAuthorityTest"
},
{
"name": "ime_description",
"value": "input method extension ability."
},
{
"name": "ime_label",
"value": "inputMethod extension ability services."
},
{
"name": "ime_label_1",
"value": "inputMethod extension ability services_1."
},
{
"name": "description_application",
"value": "demo for test"
},
{
"name": "app_name",
"value": "Demo"
}
]
}
......@@ -14,9 +14,10 @@
*/
import imeAbilityTest from './imeAbilityTest.test'
import inputMethodStageJSUnit from './inputMethodStageJSUnit';
import inputMethodNormalStageJSUnit from './inputMethodNormalStageJSUnit';
export default function testsuite() {
imeAbilityTest(globalThis.abilityContext);
inputMethodStageJSUnit();
inputMethodNormalStageJSUnit();
}
\ No newline at end of file
/**
* 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 inputMethod from '@ohos.inputMethod';
import subtype from '@ohos.InputMethodSubtype';
export default function inputMethodNormalStageJSUnit() {
describe('inputMethodNormalStageJSUnit', function () {
console.info("====>************* inputMethodNormalStageJSUnit settings Test start*************");
/*
* @tc.number inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001', 0, async function (done) {
console.info("====>************* inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName:inputM.packageName,
methodId:inputM.methodId,
name:inputM.packageName,
id:inputM.methodId,
label: "",
icon: "",
iconId: 124,
extra:{}
}
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,data) => {
try{
if(err){
console.info("====>inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001 permission fail: " + JSON.stringify(err));
expect(err.code).assertEqual(201);
done();
}else{
console.info('====>inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001 success: ' + data);
expect().assertFail();
done();
}
}catch(err){
console.error("====>inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001 catch err: " + JSON.stringify(err));
done();
console.info("====>inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001 end");
}
});
console.info("====>************* inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_001 Test end*************");
});
/*
* @tc.number inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_002
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_002', 0, async function (done) {
console.info("====>************* inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_002 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_002 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName:inputM.packageName,
methodId:inputM.methodId,
name:inputM.packageName,
id:inputM.methodId,
label: "",
icon: "",
iconId: 124,
extra:{}
}
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_002 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
try{
console.info('====>inputMethodNormalStage_test_switchInputMethod_001 switchCurrentInputMethodAndSubtype permission fail');
await inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty);
expect().assertFail();
done();
}catch(err){
console.error('====>inputMethodNormalStage_test_switchInputMethod_001 switchCurrentInputMethodAndSubtype catch err' + JSON.stringify(err))
expect(err.code).assertEqual(201);
expect(err.message).assertContain("the permissions check fails");
done();
console.info("====>inputMethodNormalStage_test_switchInputMethod_001 end");
}
console.info("====>************* inputMethodNormalStage_test_switchCurrentInputMethodAndSubtype_002 Test end*************");
});
/*
* @tc.number inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001', 0, async function (done) {
console.info("====>************* inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001 Test start*************");
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty, (err,data) => {
try{
if(err){
console.info("====>inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001 permission fail: " + JSON.stringify(err));
expect(err.code).assertEqual(201);
done();
}else{
console.info('====>inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001 success: ' + data);
expect().assertFail();
done();
}
}catch(err){
console.error("====>inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001 catch err: " + JSON.stringify(err));
done();
console.info("====>inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001 end");
}
});
console.info("====>************* inputMethodNormalStage_test_switchCurrentInputMethodSubtype_001 Test end*************");
});
/*
* @tc.number inputMethodNormalStage_test_switchCurrentInputMethodSubtype_002
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethodNormalStage_test_switchCurrentInputMethodSubtype_002', 0, async function (done) {
console.info("====>************* inputMethodNormalStage_test_switchCurrentInputMethodSubtype_002 Test start*************");
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethodNormalStage_test_switchCurrentInputMethodSubtype_002 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
try{
console.info('====>inputMethodNormalStage_test_switchCurrentInputMethodSubtype_002 switchCurrentInputMethodSubtype permission fail');
await inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty);
expect().assertFail();
done();
}catch(err){
console.error('====>inputMethodNormalStage_test_switchCurrentInputMethodSubtype_002 switchCurrentInputMethodSubtype catch err' + JSON.stringify(err))
expect(err.code).assertEqual(201);
expect(err.message).assertContain("the permissions check fails");
done();
console.info("====>inputMethodNormalStage_test_switchCurrentInputMethodSubtype_002 end");
}
console.info("====>************* inputMethodNormalStage_test_switchCurrentInputMethodSubtype_002 Test end*************");
});
});
};
......@@ -311,189 +311,6 @@ export default function inputMethodStageJSUnit() {
done();
});
/*
* @tc.number inputMethod_test_switchCurrentInputMethodAndSubtype_001
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethod_test_switchCurrentInputMethodAndSubtype_001', 0, async function (done) {
console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_001 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_001 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName:inputM.packageName,
methodId:inputM.methodId,
name:inputM.packageName,
id:inputM.methodId,
label: "",
icon: "",
iconId: 124,
extra:{}
}
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_001 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,data) => {
try {
if (err) {
console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_001 err: ' + JSON.stringify(err));
expect( err.code === 12800008 ).assertTrue();
done();
}
console.info("====>inputMethod_test_switchCurrentInputMethodAndSubtype_001 data: " + JSON.stringify(data));
expect(data != null).assertTrue();
done();
} catch (error) {
console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_001 catch error: ' + JSON.stringify(error));
done();
}
});
console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_001 Test end*************");
});
/*
* @tc.number inputMethod_test_switchCurrentInputMethodAndSubtype_002
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethod_test_switchCurrentInputMethodAndSubtype_002', 0, async function (done) {
console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_002 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_002 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName:inputM.packageName,
methodId:inputM.methodId,
name:inputM.packageName,
id:inputM.methodId,
label: "",
icon: "",
iconId: 124,
extra:{}
}
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_002 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
try {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((data) => {
console.info("====>inputMethod_test_switchCurrentInputMethodAndSubtype_002 data: " + JSON.stringify(data));
expect(data != null).assertTrue();
done();
}).catch(err => {
console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_002 err: ' + JSON.stringify(err));
expect().assertFail();
done();
});
}catch (error) {
console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_002 catch error: ' + JSON.stringify(error));
expect().assertFail();
done();
};
console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_002 Test end*************");
});
/*
* @tc.number inputMethod_test_switchCurrentInputMethodSubtype_001
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethod_test_switchCurrentInputMethodSubtype_001', 0, async function (done) {
console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_001 Test start*************");
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethod_test_switchCurrentInputMethodSubtype_001 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty, (err,data) => {
try {
if (err) {
console.error('inputMethod_test_switchCurrentInputMethodSubtype_001 err: ' + JSON.stringify(err));
expect().assertFail();
done();
};
console.info("====>inputMethod_test_switchCurrentInputMethodSubtype_001 data: " + JSON.stringify(data));
expect(data != null).assertTrue();
done();
} catch (error) {
console.error('inputMethod_test_switchCurrentInputMethodSubtype_001 catch error: ' + JSON.stringify(error));
done();
}
});
console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_001 Test end*************");
});
/*
* @tc.number inputMethod_test_switchCurrentInputMethodSubtype_002
* @tc.name Switch current input method subtype.
* @tc.desc Function test
* @tc.level 2
*/
it('inputMethod_test_switchCurrentInputMethodSubtype_002', 0, async function (done) {
console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_002 Test start*************");
let inputMS = inputMethod.getCurrentInputMethodSubtype()
console.info("inputMethod_test_switchCurrentInputMethodSubtype_002 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS));
let inputMethodSubProperty : subtype = {
id: inputMS.id,
label: "",
name: inputMS.name,
mode: "lower",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
};
try {
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty).then((data) => {
console.info("====>inputMethod_test_switchCurrentInputMethodSubtype_002 data: " + JSON.stringify(data));
expect(data != null).assertTrue();
done();
}).catch(err => {
console.error('inputMethod_test_switchCurrentInputMethodSubtype_002 err: ' + JSON.stringify(err));
expect().assertFail();
done();
});
}catch (error) {
console.error('inputMethod_test_switchCurrentInputMethodSubtype_002 catch error: ' + JSON.stringify(error));
expect().assertFail();
done();
};
console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_002 Test end*************");
});
/*
* @tc.number inputMethod_test_showOptionalInputMethods_001
......
......@@ -50,15 +50,6 @@
"description": "$string:ime_description",
"type": "inputMethod"
}
],
"requestPermissions": [
{
"name":"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"need use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.CONNECT_IME_ABILITY"
}
]
}
}
......@@ -66,11 +66,6 @@
"launchType": "standard"
}
],
"reqPermissions": [
{
"name": "ohos.permission.CONNECT_IME_ABILITY"
}
],
"js": [
{
"mode": {
......
......@@ -14,8 +14,10 @@
*/
import inputMethodJSUnit from './inputMethodJSUnit';
import inputMethodEngineJSUnit from './inputMethodEngineJSUnit';
import inputMethodNormalJSUnit from './inputMethodNormalJSUnit';
export default function testsuite() {
inputMethodJSUnit();
inputMethodEngineJSUnit();
inputMethodNormalJSUnit();
}
\ No newline at end of file
......@@ -122,171 +122,6 @@ export default function inputMethodJSUnit() {
done();
});
/*
* @tc.number inputmethod_test_switchInputMethod_001
* @tc.name Test Indicates the input method which will replace the current one.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_switchInputMethod_001', 0, async function (done) {
console.info("====>************* inputmethod_test_switchInputMethod_001 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputmethod_test_switchInputMethod_001 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName: inputM.packageName,
methodId: inputM.methodId,
name: inputM.packageName,
id: inputM.methodId,
extra: {}
}
inputMethod.switchInputMethod(inputMethodProperty).then(data => {
console.info("====>inputmethod_test_switchInputMethod_001 data:" + data)
expect(data == true).assertTrue();
console.info("====>************* inputmethod_test_switchInputMethod_001 Test end*************");
done();
}).catch(err => {
console.info("====>inputmethod_test_switchInputMethod_001 err:" + err)
expect().assertFail();
done();
});
});
/*
* @tc.number inputmethod_test_switchInputMethod_002
* @tc.name Test Indicates the input method which will replace the current one.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_switchInputMethod_002', 0, async function (done) {
console.info("====>************* inputmethod_test_switchInputMethod_002 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputmethod_test_switchInputMethod_002 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName: inputM.packageName,
methodId: inputM.methodId,
name: inputM.packageName,
id: inputM.methodId,
extra: {}
}
inputMethod.switchInputMethod(inputMethodProperty, (err, data) => {
try {
if (err) {
console.info("====>inputmethod_test_switchInputMethod_002 error:" + err);
expect().assertFail();
done();
}
console.info("====>inputmethod_test_switchInputMethod_002 data:" + data)
console.info("====>************* inputmethod_test_switchInputMethod_002 Test end*************");
expect(data == true).assertTrue();
done();
} catch (err) {
console.info("====>inputmethod_test_switchInputMethod_002 catch error:" + err);
done();
}
});
});
/*
* @tc.number inputmethod_test_showSoftKeyboard_001
* @tc.name Test Indicates the input method which will show softboard with calback.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.showSoftKeyboard((err) => {
try {
if(err == undefined){
expect().assertFail()
done();
}else{
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_showSoftKeyboard_001 Test end*************");
done();
}
} catch (err) {
console.info("====>inputmethod_test_showSoftKeyboard_001 err tests fail" + JSON.stringify(err));
done();
}
});
});
/*
* @tc.number inputmethod_test_showSoftKeyboard_002
* @tc.name Test Indicates the input method which will show softboard with Promise.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.showSoftKeyboard().then(() => {
try {
expect().assertFail()
done();
} catch (err) {
console.info("====>inputmethod_test_showSoftKeyboard_002 err tests fail" + JSON.stringify(err));
done();
}
}).catch((err) => {
console.info('====>inputmethod_test_showSoftKeyboard_002 promise failed : ' + JSON.stringify(err))
console.info('====>inputmethod_test_showSoftKeyboard_002 typeof(err.code): ' + typeof(err.code))
console.info('====>inputmethod_test_showSoftKeyboard_002 typeof(err.code): ' + err.code)
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_showSoftKeyboard_002 Test end*************");
done();
})
});
/*
* @tc.number inputmethod_test_hideSoftKeyboard_001
* @tc.name Test Indicates the input method which will hide softboard with calback.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.hideSoftKeyboard((err) => {
try {
if(err == undefined){
expect().assertFail()
done();
}else{
console.info('====>inputmethod_test_hideSoftKeyboard_001 callbacek failed : ' + JSON.stringify(err))
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_hideSoftKeyboard_001 Test end*************");
done();
}
} catch (err) {
console.info('====>inputmethod_test_hideSoftKeyboard_001 callbacek failed : ' + JSON.stringify(err))
done();
}
})
});
/*
* @tc.number inputmethod_test_hideSoftKeyboard_002
* @tc.name Test Indicates the input method which will hide softboard with Promise.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.hideSoftKeyboard().then(() => {
try {
expect().assertFail()
done();
} catch (err) {
console.info("====>inputmethod_test_hideSoftKeyboard_002 err tests fail" + JSON.stringify(err));
done();
}
}).catch((err) => {
console.info('====>inputmethod_test_hideSoftKeyboard_002 promise failed : ' + JSON.stringify(err))
expect(err.code).assertEqual(12800003);
console.info("====>************* inputmethod_test_hideSoftKeyboard_002 Test end*************");
done();
})
});
/*
* @tc.number inputmethod_test_getCurrentInputMethod_001
* @tc.name return The InputMethodProperty object of the current input method.
......
/**
* 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 inputMethod from '@ohos.inputMethod';
export default function inputMethodNormalJSUnit() {
describe('inputMethodNormalJSUnit', function () {
console.info("====>************* inputMethodNormalJSUnit settings Test start*************");
/*
* @tc.number inputmethodNomal_test_switchInputMethod_001
* @tc.name Test Indicates the input method which will replace the current one.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethodNomal_test_switchInputMethod_001', 0, async function (done) {
console.info("====>************* inputmethodNomal_test_switchInputMethod_001 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputmethodNomal_test_switchInputMethod_001 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName: inputM.packageName,
methodId: inputM.methodId,
name: inputM.packageName,
id: inputM.methodId,
extra: {}
}
try{
console.info('====>inputmethodNomal_test_switchInputMethod_001 switchInputMethod permission fail')
await inputMethod.switchInputMethod(inputMethodProperty);
expect().assertFail();
done();
}catch(err){
console.error('====>inputmethodNomal_test_switchInputMethod_001 switchInputMethod catch err' + JSON.stringify(err))
expect(err.code).assertEqual(201);
expect(err.message).assertContain("the permissions check fails");
done();
console.info("====>inputmethodNomal_test_switchInputMethod_001 end");
}
});
/*
* @tc.number inputmethodNomal_test_switchInputMethod_002
* @tc.name Test Indicates the input method which will replace the current one.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethodNomal_test_switchInputMethod_002', 0, async function (done) {
console.info("====>************* inputmethodNomal_test_switchInputMethod_002 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputmethodNomal_test_switchInputMethod_002 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName: inputM.packageName,
methodId: inputM.methodId,
name: inputM.packageName,
id: inputM.methodId,
extra: {}
}
inputMethod.switchInputMethod(inputMethodProperty, (err, data) => {
try{
if(err){
console.info("====>inputmethodNomal_test_switchInputMethod_002 switchInputMethod permission fail: " + JSON.stringify(err));
expect(err.code).assertEqual(201);
done();
}else{
console.info('====>inputmethodNomal_test_switchInputMethod_002 success: ' + data);
expect().assertFail();
done();
}
}catch(err){
console.error("====>inputmethodNomal_test_switchInputMethod_002 catch err: " + JSON.stringify(err));
done();
console.info("====>inputmethodNomal_test_switchInputMethod_002 end");
}
});
});
/*
* @tc.number inputmethodNomal_test_showSoftKeyboard_001
* @tc.name Test Indicates the input method which will show softboard with calback.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethodNomal_test_showSoftKeyboard_001', 0, async function (done) {
console.info("====>*************inputmethodNomal_test_showSoftKeyboard_001 start******************");
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.showSoftKeyboard((err, data) => {
try{
if(err){
console.info("====>inputmethodNomal_test_showSoftKeyboard_001 showSoftKeyboard permission fail: " + JSON.stringify(err));
expect(err.code).assertEqual(201);
done();
}else{
console.info('====>inputmethodNomal_test_showSoftKeyboard_001 success: ' + data);
expect().assertFail();
done();
}
}catch(err){
console.error("====>inputmethodNomal_test_showSoftKeyboard_001 catch err: " + JSON.stringify(err));
done();
console.info("====>inputmethodNomal_test_showSoftKeyboard_001 end");
}
});
});
/*
* @tc.number inputmethodNomal_test_showSoftKeyboard_002
* @tc.name Test Indicates the input method which will show softboard with Promise.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethodNomal_test_showSoftKeyboard_002', 0, async function (done) {
console.info("====>*********inputmethodNomal_test_showSoftKeyboard_002 start************");
let inputMethodCtrl = inputMethod.getInputMethodController();
try{
console.info('====>inputmethodNomal_test_showSoftKeyboard_002 showSoftKeyboard permission fail')
await inputMethodCtrl.showSoftKeyboard();
expect().assertFail();
done();
}catch(err){
console.error('====>inputmethodNomal_test_showSoftKeyboard_002 showSoftKeyboard catch err' + JSON.stringify(err))
expect(err.code).assertEqual(201);
expect(err.message).assertContain("the permissions check fails");
done();
console.info("====>inputmethodNomal_test_showSoftKeyboard_002 end");
}
});
/*
* @tc.number inputmethodNomal_test_hideSoftKeyboard_001
* @tc.name Test Indicates the input method which will hide softboard with calback.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethodNomal_test_hideSoftKeyboard_001', 0, async function (done) {
console.info("====>*********inputmethodNomal_test_hideSoftKeyboard_001 start************");
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.hideSoftKeyboard((err, data) => {
try{
if(err){
console.info("====>inputmethodNomal_test_hideSoftKeyboard_001 hideSoftKeyboard permission fail: " + JSON.stringify(err));
expect(err.code).assertEqual(201);
done();
}else{
console.info('====>inputmethodNomal_test_hideSoftKeyboard_001 success: ' + data);
expect().assertFail();
done();
}
}catch(err){
console.error("====>inputmethodNomal_test_hideSoftKeyboard_001 catch err: " + JSON.stringify(err));
done();
console.info("====>inputmethodNomal_test_hideSoftKeyboard_001 end");
}
});
});
/*
* @tc.number inputmethodNomal_test_hideSoftKeyboard_002
* @tc.name Test Indicates the input method which will hide softboard with Promise.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethodNomal_test_hideSoftKeyboard_002', 0, async function (done) {
console.info("====>*********inputmethodNomal_test_hideSoftKeyboard_002 start************");
let inputMethodCtrl = inputMethod.getInputMethodController()
try{
console.info('====>inputmethodNomal_test_hideSoftKeyboard_002 hideSoftKeyboard permission fail')
await inputMethodCtrl.hideSoftKeyboard();
expect().assertFail();
done();
}catch(err){
console.error('====>inputmethodNomal_test_hideSoftKeyboard_002 hideSoftKeyboard catch err' + JSON.stringify(err))
expect(err.code).assertEqual(201);
expect(err.message).assertContain("the permissions check fails");
done();
console.info("====>inputmethodNomal_test_hideSoftKeyboard_002 end");
}
});
});
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册