提交 088ca50c 编写于 作者: X xialiangwei

增加UIExtensi

Signed-off-by: Nxialiangwei <xialiangwei1@huawei.com>
Change-Id: Ibc950073a87b75e93ba8e3fab077b99dda5ad934
上级 91412330
......@@ -19,7 +19,7 @@ group("actsuiextensiontest") {
deps = [
"uiextensionprovider:UIExtensionProvider",
"uiextensiontest:UIExtensionTest",
"actsabilityusertest:ActsAmsStartAbilityUser",
"actsabilityusertest:StartAbilityByUIContentSession",
]
}
}
......@@ -13,32 +13,32 @@
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsAmsStartAbilityUser") {
ohos_js_hap_suite("StartAbilityByUIContentSession") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":actsamsstartabilityuser_js_assets",
":actsamsstartabilityuser_resources",
":startabilitybyuicontentsession_js_assets",
":startabilitybyuicontentsession_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsAmsStartAbilityUser"
hap_name = "StartAbilityByUIContentSession"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("actsamsstartabilityuser_app_profile") {
ohos_app_scope("startabilitybyuicontentsession_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actsamsstartabilityuser_js_assets") {
ohos_js_assets("startabilitybyuicontentsession_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actsamsstartabilityuser_resources") {
ohos_resources("startabilitybyuicontentsession_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actsamsstartabilityuser_app_profile" ]
deps = [ ":startabilitybyuicontentsession_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
......@@ -10,7 +10,7 @@
"kits": [
{
"test-file-name": [
"ActsAmsStartAbilityUser.hap"
"StartAbilityByUIContentSession.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
import Ability from '@ohos.app.ability.UIAbility'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
......@@ -23,13 +20,6 @@ export default class MainAbility extends Ability {
onForeground() {
console.log('MainAbility onForeground')
setTimeout(()=>{
this.context.terminateSelf().then((data) => {
console.info("com.example.actsabilityusertest MainAbility terminateSelf data = " + JSON.stringify(data));
}).catch((err) => {
console.info("com.example.actsabilityusertest MainAbility terminateSelf err = " + JSON.stringify(err));
});
}, 2000)
}
onBackground() {
......
......@@ -16,13 +16,23 @@ import Ability from '@ohos.app.ability.UIAbility'
import commonEventManager from '@ohos.commonEventManager'
function PublishCallBackOne() {
console.debug("====>Publish CallBack ACTS_StartAbility_0100_CommonEvent====>");
console.log("====>Publish CallBack ACTS_StartAbility_0100_CommonEvent====>");
globalThis.ability2Context.terminateSelf().then(()=>{
console.debug("====>publish ACTS_TerminateSelf_CommonEvent finish====>")
console.log("====>terminateSelf success====>");
});
console.debug("====>terminateSelf succese====>")
}
function timeout() {
globalThis.ability2Context.startAbility(
{
bundleName: 'com.example.uiextensiontest',
abilityName: 'TestAbility',
}
).then(()=>{
console.log("====>start com.example.uiextensiontest.TestAbility finish====>")
});
}
export default class MainAbility2 extends Ability {
onCreate(want, launchParam) {
......@@ -38,9 +48,6 @@ export default class MainAbility2 extends Ability {
// Main window is created, set main page for this ability
console.log("MainAbility2 onWindowStageCreate");
windowStage.setUIContent(this.context, "pages/index2", null);
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
globalThis.ability2Context = this.context;
commonEventManager.publish(onResultEvent, PublishCallBackOne);
}
onWindowStageDestroy() {
......@@ -51,10 +58,14 @@ export default class MainAbility2 extends Ability {
onForeground() {
// Ability has brought to foreground
console.log("MainAbility2 onForeground");
globalThis.ability2Context = this.context;
setTimeout(timeout, 1000);
}
onBackground() {
// Ability has back to background
console.log("MainAbility2 onBackground");
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
commonEventManager.publish(onResultEvent, PublishCallBackOne);
}
};
......@@ -14,6 +14,17 @@
*/
import Ability from '@ohos.app.ability.UIAbility'
function timeout() {
globalThis.ability3Context.startAbility(
{
bundleName: 'com.example.uiextensiontest',
abilityName: 'TestAbility',
}
).then(()=>{
console.log("====>start com.example.uiextensiontest.TestAbility finish====>")
});
}
export default class MainAbility3 extends Ability {
onCreate(want, launchParam) {
......@@ -29,17 +40,6 @@ export default class MainAbility3 extends Ability {
// Main window is created, set main page for this ability
console.log("MainAbility3 onWindowStageCreate");
windowStage.setUIContent(this.context, "pages/index3", null);
globalThis.abilityContext3 = this.context;
globalThis.abilityContext3.terminateSelfWithResult(
{
resultCode:1,
want:{
action:'ACTION'
}
},()=>{
console.debug("====>terminateSelfWithResult succese====>")
});
console.debug("====>terminateSelf end====>")
}
onWindowStageDestroy() {
......@@ -50,10 +50,22 @@ export default class MainAbility3 extends Ability {
onForeground() {
// Ability has brought to foreground
console.log("MainAbility3 onForeground");
globalThis.ability3Context = this.context;
setTimeout(timeout, 1000);
}
onBackground() {
// Ability has back to background
console.log("MainAbility3 onBackground");
globalThis.ability3Context.terminateSelfWithResult(
{
resultCode:1,
want:{
action:'ACTION'
}
},()=>{
console.debug("====>terminateSelfWithResult success====>")
});
}
};
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 MainAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'
let lMonitor = {
abilityName: MainAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a 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')
}
};
\ No newline at end of file
......@@ -16,7 +16,7 @@
@Entry
@Component
struct Index {
@State message: string = 'Hello World3'
@State message: string = 'Hello World2'
build() {
Row() {
......
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import commonEvent from '@ohos.commonEvent'
var subscriberInfo_MainAbility = {
events: ["ACTS_StartAbility_CommonEvent"]
};
const START_ABILITY_TIMEOUT = 4000;
export default function abilityTest() {
describe('ACTS_StartAbility_Test', function () {
/*
* @tc.number : ACTS_StartAbility_Callback_Successfully_0100
* @tc.name : start new ability
* @tc.desc : Starting mainability2 with startability succeeded.(callback)
*/
it('ACTS_StartAbility_Callback_Successfully_0100', 0, async function (done) {
var Subscriber
var flag = true
var startresult = false
function SubscribeCallBack(err, data) {
expect(data.event == "ACTS_StartAbility_CommonEvent").assertTrue();
console.log("====>0100 Subscribe CallBack data:====>" + JSON.stringify(data));
if (data.event == "ACTS_StartAbility_CommonEvent") {
startresult = true
}
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback);
}
function UnSubscribeCallback() {
console.log("====>UnSubscribeCallback====>");
flag = false
expect(startresult).assertEqual(true);
done();
}
await commonEvent.createSubscriber(subscriberInfo_MainAbility).then((data) => {
console.log("====>Create Subscriber====>");
data.getSubscribeInfo().then(async (SubscribeInfo) => {
console.log("====>SubscribeInfo is====>" + JSON.stringify(SubscribeInfo));
Subscriber = data;
commonEvent.subscribe(Subscriber, SubscribeCallBack);
console.log("====>start startAbility====>");
globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2'
}, () => {
console.log("====>startAbility end====>");
})
})
})
function timeout() {
if (flag == true) {
expect().assertFail();
console.log('ACTS_StartAbility_Callback_Successfully_0100 - timeout')
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback)
}
}
setTimeout(timeout, START_ABILITY_TIMEOUT);
})
/*
* @tc.number : ACTS_StartAbility_Callback_Error_0200
* @tc.name : start new ability
* @tc.desc : Starting mainability2 with startability failed.(callback)
*/
it('ACTS_StartAbility_Callback_Error_0200', 0, async function (done) {
var AbilityDelegatorArgs = AbilityDelegatorRegistry.getArguments()
console.log("====>getArguments is====>" + JSON.stringify(AbilityDelegatorArgs));
var Subscriber
function SubscribeCallBack(err, data) {
expect().assertFail();
console.log("====>0200 Subscribe CallBack data:====>" + JSON.stringify(data));
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback);
}
function UnSubscribeCallback() {
console.log("====>UnSubscribeCallback====>");
done();
}
await commonEvent.createSubscriber(subscriberInfo_MainAbility).then((data) => {
console.log("====>Create Subscriber====>");
data.getSubscribeInfo().then(async (SubscribeInfo) => {
console.log("====>SubscribeInfo is====>" + JSON.stringify(SubscribeInfo));
Subscriber = data;
commonEvent.subscribe(Subscriber, SubscribeCallBack);
console.log("====>start startAbility====>");
await globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.error',
abilityName: 'com.example.error.MainAbility2'
}, () => {
console.log("====>startAbility end====>");
})
})
})
function timeout() {
console.log('ACTS_StartAbility_Callback_Error_0200 - timeout');
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback)
}
setTimeout(timeout, START_ABILITY_TIMEOUT);
})
/*
* @tc.number : ACTS_StartAbility_Promise_Successfully_0100
* @tc.name : start new ability
* @tc.desc : Starting mainability2 with startability succeeded.(callback)
*/
it('ACTS_StartAbility_Promise_Successfully_0100', 0, async function (done) {
var Subscriber
var flag = true
var startresult = false
function SubscribeCallBack(err, data) {
expect(data.event == "ACTS_StartAbility_CommonEvent").assertTrue();
console.log("====>0100 Subscribe CallBack data:====>" + JSON.stringify(data));
if (data.event == "ACTS_StartAbility_CommonEvent") {
startresult = true
}
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback);
}
function UnSubscribeCallback() {
console.log("====>UnSubscribeCallback====>");
flag = false
expect(startresult).assertEqual(true);
done();
}
commonEvent.createSubscriber(subscriberInfo_MainAbility).then((data) => {
console.log("====>Create Subscriber====>");
data.getSubscribeInfo().then(async (SubscribeInfo) => {
console.log("====>SubscribeInfo is====>" + JSON.stringify(SubscribeInfo));
Subscriber = data;
commonEvent.subscribe(Subscriber, SubscribeCallBack);
console.log("====>start startAbility====>");
await globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3'
}).then(() => {
console.log("====>startAbility end====>");
})
})
})
function timeout() {
if (flag == true) {
expect().assertFail();
console.log('ACTS_StartAbility_Promise_Successfully_0100 - timeout');
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback)
}
}
setTimeout(timeout, START_ABILITY_TIMEOUT);
})
/*
* @tc.number : ACTS_StartAbility_Promise_Error_0200
* @tc.name : start new ability
* @tc.desc : Starting mainability2 with startability failed.(callback)
*/
it('ACTS_StartAbility_Promise_Error_0200', 0, async function (done) {
var AbilityDelegatorArgs = AbilityDelegatorRegistry.getArguments()
console.log("====>getArguments is====>" + JSON.stringify(AbilityDelegatorArgs));
var Subscriber
function SubscribeCallBack(err, data) {
expect().assertFail();
console.log("====>0200 Subscribe CallBack data:====>" + JSON.stringify(data));
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback);
}
function UnSubscribeCallback() {
console.log("====>UnSubscribeCallback====>");
done();
}
commonEvent.createSubscriber(subscriberInfo_MainAbility).then((data) => {
console.log("====>Create Subscriber====>");
data.getSubscribeInfo().then(async (SubscribeInfo) => {
console.log("====>SubscribeInfo is====>" + JSON.stringify(SubscribeInfo));
Subscriber = data;
commonEvent.subscribe(Subscriber, SubscribeCallBack);
console.log("====>start startAbility====>");
globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.error',
abilityName: 'com.example.error.MainAbility2'
}).then(() => {
console.log("====>startAbility end====>");
})
})
})
function timeout() {
console.log('ACTS_StartAbility_Promise_Error_0200 - timeout');
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback)
}
setTimeout(timeout, START_ABILITY_TIMEOUT);
})
})
}
\ 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 abilityTest from './Ability.test'
export default function testsuite() {
abilityTest()
}
\ No newline at end of file
......@@ -53,23 +53,23 @@ struct Index {
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let terminateSelfWithResultEvent = 'ACTS_UIExtension_TerminateSelfWithResult';
let sendDataEvent = 'ACTS_UIExtension_SendData';
let startAbilityEvent = 'ACTS_UIExtension_StartAbility';
let startAbilityOpsEvent = 'ACTS_UIExtension_StartAbility_Options';
let startAbilityEventPromise = 'ACTS_UIExtension_StartAbility_Promise';
let startAbilityOpsEventPromise = 'ACTS_UIExtension_StartAbility_Options_Promise';
let startAbilityEvent1 = 'ACTS_UIExtension_StartAbility_001';
let startAbilityEvent2 = 'ACTS_UIExtension_StartAbility_002';
let startAbilityEvent3 = 'ACTS_UIExtension_StartAbility_003';
let startAbilityEvent4 = 'ACTS_UIExtension_StartAbility_004';
let startAbilityForResultEvent = 'ACTS_UIExtension_StartAbilityForResult';
let startAbilityForResultOpsEvent = 'ACTS_UIExtension_StartAbilityForResult_Options';
let startAbilityForResultEventPromise = 'ACTS_UIExtension_StartAbilityForResult_Promise';
let startAbilityForResultOpsEventPromise = 'ACTS_UIExtension_StartAbilityForResult_Options_Promise';
let startAbilityForResultEvent1 = 'ACTS_UIExtension_StartAbilityForResult_001';
let startAbilityForResultEvent2 = 'ACTS_UIExtension_StartAbilityForResult_002';
let startAbilityForResultEvent3 = 'ACTS_UIExtension_StartAbilityForResult_003';
let startAbilityForResultEvent4 = 'ACTS_UIExtension_StartAbilityForResult_004';
var subscriber;
var startresult = false;
var subscribeInfo = {
events: [startAbilityEvent, startAbilityOpsEvent, startAbilityEventPromise,
startAbilityOpsEventPromise, startAbilityForResultEvent,
startAbilityForResultOpsEvent, startAbilityForResultEventPromise,
startAbilityForResultOpsEventPromise,
events: [startAbilityEvent1, startAbilityEvent2, startAbilityEvent3,
startAbilityEvent4, startAbilityForResultEvent1,
startAbilityForResultEvent2, startAbilityForResultEvent3,
startAbilityForResultEvent4,
terminateSelfWithResultEvent, sendDataEvent]
}
commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
......@@ -117,89 +117,73 @@ struct Index {
}).catch((err)=>{
console.log(TAG + "setWindowPrivacyModeFalsePromise : " + JSON.stringify(err));
})
} else if(data.event == startAbilityEvent) {
} else if(data.event == startAbilityEvent1) {
this.session.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
}, () => {
console.log(TAG + "====>startAbilityEvent end====>" );
console.log(TAG + "====>startAbilityEvent1 end====>" );
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityOpsEvent) {
} else if(data.event == startAbilityEvent2) {
this.session.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
},
{
windowMode: 0,
displayId: 15
windowMode: 0
}, () => {
console.log(TAG + "====>startAbilityOpsEvent end====>" );
console.log(TAG + "====>startAbilityEvent2 end====>" );
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityEventPromise) {
} else if(data.event == startAbilityEvent3) {
this.session.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
}).then((data)=>{
console.log(TAG + "====>startAbilityEventPromise end====>");
console.log(TAG + "====>startAbilityEvent3 end====>");
console.log(TAG + "====>data is====>" + JSON.stringify(data));
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityOpsEventPromise) {
} else if(data.event == startAbilityEvent4) {
this.session.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
},
{
windowMode: 0,
displayId: 15
windowMode: 0
}).then((data)=>{
console.log(TAG + "====>startAbilityOpsEventPromise end====>");
console.log(TAG + "====>startAbilityEvent4 end====>");
console.log(TAG + "====>data is====>" + JSON.stringify(data));
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityForResultEvent) {
} else if(data.event == startAbilityForResultEvent1) {
var flag = true
this.session.startAbilityForResult(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
abilityName: 'MainAbility3'
}, (err,data) => {
console.log(TAG + "====>startAbilityForResultEvent end====>" + JSON.stringify(data));
console.log(TAG + "====>startAbilityForResultEvent1 end====>" + JSON.stringify(data));
if(data.resultCode == 1 && data.want.action=='ACTION') {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_OnResult', (err) => {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_001_OnResult', (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_OnResult failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_001_OnResult failed,
code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_OnResult success');
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_001_OnResult success');
}
});
}
......@@ -207,27 +191,24 @@ struct Index {
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityForResultOpsEvent) {
} else if(data.event == startAbilityForResultEvent2) {
var flag = true
this.session.startAbilityForResult(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
abilityName: 'MainAbility3'
},
{
windowMode: 0,
displayId: 15
windowMode: 0
}, (err,data) => {
console.log(TAG + "====>startAbilityForResultOpsEvent end====>" + JSON.stringify(data));
console.log(TAG + "====>startAbilityForResultEvent2 end====>" + JSON.stringify(data));
if(data.resultCode == 1 && data.want.action=='ACTION') {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_Options_OnResult', (err) => {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_002_OnResult', (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Options_OnResult failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_002_OnResult failed,
code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_Options_OnResult success');
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_002_OnResult success');
}
});
}
......@@ -235,23 +216,21 @@ struct Index {
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityForResultEventPromise) {
} else if(data.event == startAbilityForResultEvent3) {
var flag = true
this.session.startAbilityForResult(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
abilityName: 'MainAbility3'
}).then((data) => {
console.log(TAG + "====>startAbilityForResultEventPromise end====>" + JSON.stringify(data));
console.log(TAG + "====>startAbilityForResultEvent3 end====>" + JSON.stringify(data));
if(data.resultCode == 1 && data.want.action=='ACTION') {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_Promise_OnResult', (err) => {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_003_OnResult', (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Promise_OnResult failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_003_OnResult failed,
code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_Promise_OnResult success');
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_003_OnResult success');
}
});
}
......@@ -259,27 +238,24 @@ struct Index {
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityForResultOpsEventPromise) {
} else if(data.event == startAbilityForResultEvent4) {
var flag = true
this.session.startAbilityForResult(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
abilityName: 'MainAbility3'
},
{
windowMode: 0,
displayId: 15
windowMode: 0
}).then((data) => {
console.log(TAG + "====>startAbilityForResultOpsEventPromise end====>" + JSON.stringify(data));
console.log(TAG + "====>startAbilityForResultEvent4 end====>" + JSON.stringify(data));
if(data.resultCode == 1 && data.want.action=='ACTION') {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_Options_Promise_OnResult', (err) => {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_004_OnResult', (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Options_Promise_OnResult failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_004_OnResult failed,
code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_Options_Promise_OnResult success');
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_004_OnResult success');
}
});
}
......
......@@ -13,10 +13,17 @@
"test-file-name": [
"UIExtensionTest.hap",
"UIextensionProvider.hap",
"ActsAmsStartAbilityUser.hap"
"StartAbilityByUIContentSession.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": [
"power-shell wakeup",
"power-shell setmode 602"
]
}
]
}
......
......@@ -61,4 +61,9 @@ export default class TestAbility extends Ability {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
onNewWant(want, launchParam) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onNewWant');
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ export default function abilityTest() {
describe('ACTS_UIExtension', function () {
let TAG = "";
let sleepTimeOne = 1000;
let abilityContext = globalThis.abilityContext;
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () {
// Presets an action, which is performed only once before all test cases of the test suite start.
......@@ -144,13 +145,19 @@ export default function abilityTest() {
done();
})
})
/*
* @tc.number : ACTS_UIExtension_StartAbility_001
* @tc.name : start new ability by UIContentSession
* @tc.desc : Starting mainability2 by UIContentSession with startability succeeded.(callback)
*/
it('ACTS_UIExtension_StartAbility_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
let startAbilityEvent = 'ACTS_UIExtension_StartAbility';
let startAbilityEvent = 'ACTS_UIExtension_StartAbility_001';
var flag = true
function UnSubscribeCallback() {
......@@ -162,7 +169,7 @@ export default function abilityTest() {
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbility - timeout');
console.debug(TAG + 'StartAbility_001 - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
......@@ -198,17 +205,21 @@ export default function abilityTest() {
done();
})
setTimeout(timeout, 10000);
setTimeout(timeout, 5000);
})
it('ACTS_UIExtension_StartAbility_Options_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_Options_001 == ';
/*
* @tc.number : ACTS_UIExtension_StartAbility_002
* @tc.name : start new ability by UIContentSession
* @tc.desc : Starting mainability2 by UIContentSession with the parameter startability with options succeeded.(callback)
*/
it('ACTS_UIExtension_StartAbility_002',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_002 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
let startAbilityOpsEvent = 'ACTS_UIExtension_StartAbility_Options';
let startAbilityOpsEvent = 'ACTS_UIExtension_StartAbility_002';
var flag = true
......@@ -221,7 +232,7 @@ export default function abilityTest() {
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbility_Options - timeout');
console.debug(TAG + 'StartAbility_002 - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
......@@ -240,9 +251,9 @@ export default function abilityTest() {
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityOpsEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbility_Options_001 failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbility_002 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_Options_001 success');
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_002 success');
}
});
} else if (data.event == onResultEvent) {
......@@ -256,17 +267,21 @@ export default function abilityTest() {
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
setTimeout(timeout, 5000);
})
it('ACTS_UIExtension_StartAbility_Promise_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_Promise_001 == ';
/*
* @tc.number : ACTS_UIExtension_StartAbility_003
* @tc.name : start new ability by UIContentSession
* @tc.desc : Starting mainability2 by UIContentSession with startability succeeded.(promise)
*/
it('ACTS_UIExtension_StartAbility_003',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_003 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
let startAbilityEventPromise = 'ACTS_UIExtension_StartAbility_Promise';
let startAbilityEventPromise = 'ACTS_UIExtension_StartAbility_003';
var flag = true
......@@ -279,7 +294,7 @@ export default function abilityTest() {
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbility_Promise - timeout');
console.debug(TAG + 'StartAbility_003 - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
......@@ -298,9 +313,9 @@ export default function abilityTest() {
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityEventPromise, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbility_Promise_001 failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbility_003 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_Promise_001 success');
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_003 success');
}
});
} else if (data.event == onResultEvent) {
......@@ -315,15 +330,21 @@ export default function abilityTest() {
done();
})
setTimeout(timeout, 10000);
setTimeout(timeout, 5000);
})
it('ACTS_UIExtension_StartAbility_Options_Promise_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_Options_Promise_001 == ';
/*
* @tc.number : ACTS_UIExtension_StartAbility_004
* @tc.name : start new ability by UIContentSession
* @tc.desc : Starting mainability2 by UIContentSession with the parameter startability with options succeeded.(promise)
*/
it('ACTS_UIExtension_StartAbility_004',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_004 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
let startAbilityOpsEventPromise = 'ACTS_UIExtension_StartAbility_Options_Promise';
let startAbilityOpsEventPromise = 'ACTS_UIExtension_StartAbility_004';
var flag = true
......@@ -336,7 +357,7 @@ export default function abilityTest() {
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbility_Options_Promise - timeout');
console.debug(TAG + 'StartAbility_004 - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
......@@ -355,9 +376,9 @@ export default function abilityTest() {
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityOpsEventPromise, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbility_Options_Promise_001 failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbility_004 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_Options_Promise_001 success');
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_004 success');
}
});
} else if (data.event == onResultEvent) {
......@@ -371,16 +392,21 @@ export default function abilityTest() {
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
setTimeout(timeout, 5000);
})
/*
* @tc.number : ACTS_UIExtension_StartAbilityForResult_001
* @tc.name : start new ability for result by UIContentSession
* @tc.desc : Starting mainability3 by UIContentSession with startAbilityforresult succeeded.(callback)
*/
it('ACTS_UIExtension_StartAbilityForResult_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_OnResult';
let startAbilityForResultEvent = 'ACTS_UIExtension_StartAbilityForResult';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_001_OnResult';
let startAbilityForResultEvent = 'ACTS_UIExtension_StartAbilityForResult_001';
var flag = true
......@@ -393,7 +419,7 @@ export default function abilityTest() {
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbilityForResult - timeout');
console.debug(TAG + 'StartAbilityForResult_001 - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
......@@ -412,9 +438,9 @@ export default function abilityTest() {
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityForResultEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResultEvent failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_001 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResultEvent success');
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_001 success');
}
});
}
......@@ -429,16 +455,22 @@ export default function abilityTest() {
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
setTimeout(timeout, 5000);
})
it('ACTS_UIExtension_StartAbilityForResult_Options_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_Options_001 == ';
/*
* @tc.number : ACTS_UIExtension_StartAbilityForResult_002
* @tc.name : start new ability for result by UIContentSession
* @tc.desc : Starting mainability3 by UIContentSession with the parameter startabilityforresult with options succeeded.(callback)
*/
it('ACTS_UIExtension_StartAbilityForResult_002',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_002 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_Options_OnResult';
let startAbilityForResultOpsEvent = 'ACTS_UIExtension_StartAbilityForResult_Options';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_002_OnResult';
let startAbilityForResultOpsEvent = 'ACTS_UIExtension_StartAbilityForResult_002';
var flag = true
......@@ -451,7 +483,7 @@ export default function abilityTest() {
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbilityForResult_Options - timeout');
console.debug(TAG + 'StartAbilityForResult_002 - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
......@@ -470,9 +502,9 @@ export default function abilityTest() {
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityForResultOpsEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Options_001 failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_002 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_Options_001 success');
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_002 success');
}
});
}
......@@ -487,15 +519,21 @@ export default function abilityTest() {
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
setTimeout(timeout, 5000);
})
it('ACTS_UIExtension_StartAbilityForResult_Promise_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_Promise_001 == ';
/*
* @tc.number : ACTS_UIExtension_StartAbilityForResult_003
* @tc.name : start new ability for result by UIContentSession
* @tc.desc : Starting mainability3 by UIContentSession with startabilityforresult succeeded.(promise)
*/
it('ACTS_UIExtension_StartAbilityForResult_003',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_003 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_Promise_OnResult';
let startAbilityForResultEventPromise = 'ACTS_UIExtension_StartAbilityForResult_Promise';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_003_OnResult';
let startAbilityForResultEventPromise = 'ACTS_UIExtension_StartAbilityForResult_003';
var flag = true
......@@ -508,7 +546,7 @@ export default function abilityTest() {
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbilityForResult_Promise - timeout');
console.debug(TAG + 'StartAbilityForResult_003 - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
......@@ -527,9 +565,9 @@ export default function abilityTest() {
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityForResultEventPromise, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Promise_001 failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_003 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_Promise_001 success');
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_003 success');
}
});
}
......@@ -544,17 +582,21 @@ export default function abilityTest() {
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
setTimeout(timeout, 5000);
})
it('ACTS_UIExtension_StartAbilityForResult_Options_Promise_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_Options_Promise_001 == ';
/*
* @tc.number : ACTS_UIExtension_StartAbilityForResult_004
* @tc.name : start new ability for result by UIContentSession
* @tc.desc : Starting mainability2 by UIContentSession with the parameter startabilityforresult with options succeeded.(promise)
*/
it('ACTS_UIExtension_StartAbilityForResult_004',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_004 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_Options_Promise_OnResult';
let startAbilityForResultOpsEventPromise = 'ACTS_UIExtension_StartAbilityForResult_Options_Promise';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_004_OnResult';
let startAbilityForResultOpsEventPromise = 'ACTS_UIExtension_StartAbilityForResult_004';
var flag = true
......@@ -567,7 +609,7 @@ export default function abilityTest() {
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbilityForResult_Options_Promise - timeout');
console.debug(TAG + 'StartAbilityForResult_004 - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
......@@ -586,9 +628,9 @@ export default function abilityTest() {
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityForResultOpsEventPromise, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Options_Promise_001 failed, code is ${err.code}, message is ${err.message}`);
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_004 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_Options_Promise_001 success');
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_004 success');
}
});
}
......@@ -603,7 +645,7 @@ export default function abilityTest() {
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
setTimeout(timeout, 5000);
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册