API10用例优化

Signed-off-by: anyueling <anyueling@huawei.com>
This commit is contained in:
anyueling 2023-06-15 14:45:14 +08:00
parent 38155c0262
commit 2bd32c6c2e
48 changed files with 3879 additions and 3352 deletions

View File

@ -23,6 +23,8 @@ group("request_packages") {
"services/sa_profile:download_sa_profiles",
"services/service/rust:download_server",
"test/unittest/common/napi/requestTest:unittest",
"test/unittest/js_test/requestCreateTaskTest:unittest",
"test/unittest/js_test/requestOperateTaskTest:unittest",
]
}
}

View File

@ -71,7 +71,9 @@
],
"test": [
"//base/request/request/test/fuzztest:fuzztest",
"//base/request/request/test/unittest/common/napi/requestTest:unittest"
"//base/request/request/test/unittest/common/napi/requestTest:unittest",
"//base/request/request/test/unittest/js_test/requestCreateTaskTest:unittest",
"//base/request/request/test/unittest/js_test/requestOperateTaskTest:unittest"
]
}
}

View File

@ -0,0 +1,21 @@
{
"app":{
"bundleName":"com.acts.request",
"vendor":"huawei",
"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
}
}
}

View File

@ -0,0 +1,8 @@
{
"string":[
{
"name":"app_name",
"value":"ohosProject"
}
]
}

View File

@ -1,4 +1,4 @@
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Copyright (c) 2023 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
@ -13,17 +13,35 @@
import("//build/test.gni")
module_output_path = "request/request"
want_output_path = "request/requestCreateTaskTest"
ohos_js_unittest("RequestCreateTaskTest") {
module_out_path = module_output_path
hap_profile = "./config.json"
certificate_profile = "./signature/openharmony_sx.p7b"
ohos_js_stage_unittest("RequestCreateTaskTest") {
hap_profile = "entry/src/main/module.json"
deps = [
":actbmsstageetstest_js_assets",
":actbmsstageetstest_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "RequestCreateTaskTest"
subsystem_name = "request"
part_name = "request"
module_out_path = want_output_path
}
ohos_app_scope("actbmsstageetstest_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actbmsstageetstest_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actbmsstageetstest_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actbmsstageetstest_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
group("unittest") {
testonly = true
deps = [ ":RequestCreateTaskTest" ]
deps = []
deps += [ ":RequestCreateTaskTest" ]
}

View File

@ -0,0 +1,26 @@
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.acts.request",
"module-name": "testModule",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [
{
"test-file-name": [
"RequestCreateTaskTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"teardown-command":[
"bm uninstall -n com.acts.request"
]
}
]
}

View File

@ -1,66 +0,0 @@
{
"app": {
"bundleName": "com.acts.request",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 8,
"target": 9
}
},
"deviceConfig": {},
"module": {
"package": "com.acts.request",
"name": ".MainAbility",
"deviceType": [
"default",
"tablet"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"reqPermissions": [
{
"name": "ohos.permission.INTERNET"
}
],
"abilities": [
{
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.acts.request.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}

View File

@ -0,0 +1,9 @@
import AbilityStage from "@ohos.app.ability.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log('[Demo] MyAbilityStage onCreate');
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}

View File

@ -0,0 +1,37 @@
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.log('[Demo] MainAbility onCreate');
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log('[Demo] MainAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log('[Demo] MainAbility onWindowStageCreate');
globalThis.abilityContext = this.context;
globalThis.cacheDir = this.context.cacheDir;
windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null);
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log('[Demo] MainAbility onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('[Demo] MainAbility onForeground');
}
onBackground() {
// Ability has back to background
console.log('[Demo] MainAbility onBackground');
}
};

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2023 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 router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../../test/List.test'
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
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%')
}
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 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 router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}

View File

@ -0,0 +1,30 @@
import Ability from '@ohos.app.ability.UIAbility'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate');
}
onDestroy() {
console.log('TestAbility onDestroy');
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate');
windowStage.setUIContent(this.context, 'TestAbility/pages/index', null);
globalThis.abilityContext = this.context;
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy');
}
onForeground() {
console.log('TestAbility onForeground');
}
onBackground() {
console.log('TestAbility onBackground');
}
};

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2023 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 router from '@ohos.router';
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}

View File

@ -0,0 +1,58 @@
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'
])
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.request.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
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');
}
};

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2023 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 requestCreateTaskTest from './RequestCreateTask.test.ets';
export default function testsuite() {
requestCreateTaskTest();
}

View File

@ -0,0 +1,92 @@
{
"module": {
"name": "testModule",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:testModule_entry_dsc",
"mainElement": "com.acts.request.MainAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"metadata": [
{
"name": "ArkTSPartialUpdate",
"value": "false"
}
],
"abilities": [
{
"name": "com.acts.request.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:testModule_entry_main",
"icon": "$media:icon",
"label": "$string:entry_label",
"visible": true,
"launchType": "singleton",
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "$string:permission_reason",
"usedScene": {
"abilities": ["MainAbility"],
"when": "always"
}
},
{
"name": "ohos.permission.READ_CALENDAR",
"reason": "$string:permission_reason",
"usedScene": {
"abilities": ["MainAbility"],
"when": "inuse"
}
},
{
"name":"ohos.permission.INTERNET",
"reason":"need use ohos.permission.INTERNET."
},
{"name": "ohos.permission.WRITE_MEDIA",
"reason": "need use ohos.permission.WRITE_MEDIA",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when":"always"
}
},
{"name": "ohos.permission.READ_MEDIA",
"reason": "need use ohos.permission.WRITE_MEDIA",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when":"always"
}
}
],
"metadata": [
{
"name": "MetaData1",
"value": "MetaDataValue",
"resource": "$profile:shortcuts_config"
}
]
}
}

View File

@ -0,0 +1,44 @@
{
"string": [
{
"name": "testModule_entry_dsc",
"value": "i am an entry for testModule"
},
{
"name": "testModule_entry_main",
"value": "the testModule entry ability"
},
{
"name": "entry_label",
"value": "ActsContextTest"
},
{
"name": "form_description",
"value": "my form"
},
{
"name": "serviceability_description",
"value": "my whether"
},
{
"name": "description_application",
"value": "demo for test"
},
{
"name": "app_name",
"value": "Demo"
},
{
"name": "form_FormAbility_desc",
"value": "form_description"
},
{
"name": "form_FormAbility_label",
"value": "form_label"
},
{
"name": "permission_reason",
"value": "Need permission"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,6 @@
{
"src": [
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
]
}

View File

@ -0,0 +1 @@
{"src": ["MainAbility/pages/index/index","MainAbility/pages/second/second"]}

View File

@ -0,0 +1,5 @@
{
"src": [
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
}

View File

@ -0,0 +1,6 @@
{
"src": [
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
]
}

View File

@ -0,0 +1,6 @@
{
"src": [
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
]
}

View File

@ -0,0 +1,21 @@
{
"app":{
"bundleName":"com.acts.request",
"vendor":"huawei",
"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
}
}
}

View File

@ -0,0 +1,8 @@
{
"string":[
{
"name":"app_name",
"value":"ohosProject"
}
]
}

View File

@ -1,4 +1,4 @@
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Copyright (c) 2023 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
@ -13,17 +13,35 @@
import("//build/test.gni")
module_output_path = "request/request"
want_output_path = "request/requestOperateTaskTest"
ohos_js_unittest("RequestOperateTaskTest") {
module_out_path = module_output_path
hap_profile = "./config.json"
certificate_profile = "./signature/openharmony_sx.p7b"
ohos_js_stage_unittest("RequestOperateTaskTest") {
hap_profile = "entry/src/main/module.json"
deps = [
":actbmsstageetstest_js_assets",
":actbmsstageetstest_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "RequestOperateTaskTest"
subsystem_name = "request"
part_name = "request"
module_out_path = want_output_path
}
ohos_app_scope("actbmsstageetstest_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actbmsstageetstest_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actbmsstageetstest_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actbmsstageetstest_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
group("unittest") {
testonly = true
deps = [ ":RequestOperateTaskTest" ]
deps = []
deps += [ ":RequestOperateTaskTest" ]
}

View File

@ -0,0 +1,26 @@
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.acts.request",
"module-name": "testModule",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [
{
"test-file-name": [
"RequestOperateTaskTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"teardown-command":[
"bm uninstall -n com.acts.request"
]
}
]
}

View File

@ -1,66 +0,0 @@
{
"app": {
"bundleName": "com.acts.request",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 8,
"target": 9
}
},
"deviceConfig": {},
"module": {
"package": "com.acts.request",
"name": ".MainAbility",
"deviceType": [
"default",
"tablet"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"reqPermissions": [
{
"name": "ohos.permission.INTERNET"
}
],
"abilities": [
{
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.acts.request.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}

View File

@ -0,0 +1,9 @@
import AbilityStage from "@ohos.app.ability.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log('[Demo] MyAbilityStage onCreate');
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}

View File

@ -0,0 +1,37 @@
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.log('[Demo] MainAbility onCreate');
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log('[Demo] MainAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log('[Demo] MainAbility onWindowStageCreate');
globalThis.abilityContext = this.context;
globalThis.cacheDir = this.context.cacheDir;
windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null);
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log('[Demo] MainAbility onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('[Demo] MainAbility onForeground');
}
onBackground() {
// Ability has back to background
console.log('[Demo] MainAbility onBackground');
}
};

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2023 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 router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../../test/List.test'
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
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%')
}
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 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 router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}

View File

@ -0,0 +1,30 @@
import Ability from '@ohos.app.ability.UIAbility'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate');
}
onDestroy() {
console.log('TestAbility onDestroy');
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate');
windowStage.setUIContent(this.context, 'TestAbility/pages/index', null);
globalThis.abilityContext = this.context;
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy');
}
onForeground() {
console.log('TestAbility onForeground');
}
onBackground() {
console.log('TestAbility onBackground');
}
};

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2023 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 router from '@ohos.router';
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}

View File

@ -0,0 +1,58 @@
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'
])
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.request.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
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');
}
};

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2023 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 requestOperateTaskTest from './RequestOperateTask.test.ets';
export default function testsuite() {
requestOperateTaskTest();
}

View File

@ -0,0 +1,92 @@
{
"module": {
"name": "testModule",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:testModule_entry_dsc",
"mainElement": "com.acts.request.MainAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"metadata": [
{
"name": "ArkTSPartialUpdate",
"value": "false"
}
],
"abilities": [
{
"name": "com.acts.request.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:testModule_entry_main",
"icon": "$media:icon",
"label": "$string:entry_label",
"visible": true,
"launchType": "singleton",
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "$string:permission_reason",
"usedScene": {
"abilities": ["MainAbility"],
"when": "always"
}
},
{
"name": "ohos.permission.READ_CALENDAR",
"reason": "$string:permission_reason",
"usedScene": {
"abilities": ["MainAbility"],
"when": "inuse"
}
},
{
"name":"ohos.permission.INTERNET",
"reason":"need use ohos.permission.INTERNET."
},
{"name": "ohos.permission.WRITE_MEDIA",
"reason": "need use ohos.permission.WRITE_MEDIA",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when":"always"
}
},
{"name": "ohos.permission.READ_MEDIA",
"reason": "need use ohos.permission.WRITE_MEDIA",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when":"always"
}
}
],
"metadata": [
{
"name": "MetaData1",
"value": "MetaDataValue",
"resource": "$profile:shortcuts_config"
}
]
}
}

View File

@ -0,0 +1,44 @@
{
"string": [
{
"name": "testModule_entry_dsc",
"value": "i am an entry for testModule"
},
{
"name": "testModule_entry_main",
"value": "the testModule entry ability"
},
{
"name": "entry_label",
"value": "ActsContextTest"
},
{
"name": "form_description",
"value": "my form"
},
{
"name": "serviceability_description",
"value": "my whether"
},
{
"name": "description_application",
"value": "demo for test"
},
{
"name": "app_name",
"value": "Demo"
},
{
"name": "form_FormAbility_desc",
"value": "form_description"
},
{
"name": "form_FormAbility_label",
"value": "form_label"
},
{
"name": "permission_reason",
"value": "Need permission"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,6 @@
{
"src": [
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
]
}

View File

@ -0,0 +1 @@
{"src": ["MainAbility/pages/index/index","MainAbility/pages/second/second"]}

View File

@ -0,0 +1,5 @@
{
"src": [
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
}

View File

@ -0,0 +1,6 @@
{
"src": [
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
]
}

View File

@ -0,0 +1,6 @@
{
"src": [
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
]
}