MangerAbilityJsunit.test.js 7.5 KB
Newer Older
C
chensi10 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (c) 2021 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.
 */
15 16 17
import featureAbility from '@ohos.ability.featureability'
import missionManager from '@ohos.application.missionManager'
import appManager from "@ohos.application.appManager"
C
chensi10 已提交
18 19 20 21
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'

var abilityNameList = [
    "com.ohos.launcher.MainAbility",
Z
zhaoyuan17 已提交
22
    "com.ohos.callui.ServiceAbility",
C
chensi10 已提交
23 24 25 26 27 28 29
    "com.example.SimulateFeatureAbilityFir",
    "com.example.actsamstestfirstscene.MainAbility"
]

var bundleNameList = [
    "com.ohos.launcher",
    "com.ohos.systemui",
Z
zhaoyuan17 已提交
30
    "com.ohos.callui",
Z
zhaoyuan17 已提交
31 32 33 34
    "com.ohos.contacts",
    "com.ohos.mms",
    "com.ohos.telephonydataability",
    "com.ohos.contactsdataability",
C
chensi10 已提交
35 36 37 38
    "com.ix.simulate.feature",
    "com.example.actsamstestfirstscene"
]

C
chensi10 已提交
39 40
describe('ActsAmsTestFirstScene', function () {
    console.info('----ActsAmsTestFirstScene----');
Z
zhaoyuan 已提交
41
    beforeAll(async function (done) {
C
chengxingzhen 已提交
42
        var maxnum = 10;
43 44
        var data = await missionManager.getMissionInfos("", maxnum);
        console.log('ActsAmsTestFirstScene beforeAll getMissionInfos data: ' + JSON.stringify(data));
Z
zhaoyuan 已提交
45
        for (var i = 0; i < data.length; i++) {
46 47 48 49 50 51 52 53
            if (data[i].want.bundleName != 'com.example.actsamstestfirstscene') {
                console.log("ActsAmsTestFirstScene, missionId: " + data[i].missionId)
                missionManager.clearMission(data[i].missionId,
                    (error, info) => {
                        console.info('ActsAmsTestFirstScene beforeAll clearMission error.code \
                        ' + error.code + ', want.bundleName:' + data[i].want.bundleName);
                    }
                );
C
chensi10 已提交
54
            }
C
chengxingzhen 已提交
55
        }
Z
zhaoyuan17 已提交
56
        await featureAbility.startAbility(
C
chensi10 已提交
57 58 59 60 61 62 63 64 65 66 67
            {
                want:
                {
                    deviceId: "",
                    bundleName: "com.ix.simulate.feature",
                    abilityName: "com.example.SimulateFeatureAbilityFir",
                    action: "action1",
                    entities: ["entity1"],
                    type: "MIMETYPE",
                    uri: "key={true,true,false}",
                    options:
C
chensi10 已提交
68
                        {},
C
chensi10 已提交
69
                    parameters:
C
chensi10 已提交
70
                        {},
C
chensi10 已提交
71
                },
72 73 74 75
            }, (error, data) => {
                console.info('ActsAmsTestFirstScene SimulateFeatureAbilityFir start, error.code \
                ' + error.code + ', data length [' + data.length + ']');
            }
C
chensi10 已提交
76
        );
77
        done();
C
chensi10 已提交
78 79
    });

Z
zhaoyuan17 已提交
80 81 82 83 84 85
    function timeout(done) {
        expect().assertFail();
        console.debug('Acts_Ams_test=========timeout========');
        done();
    }

Z
zhaoyuan17 已提交
86
    function sleep(delay) {
87 88 89 90 91
        var start = new Date().getTime();
        while (true) {
            if (new Date().getTime() - start > delay) {
                break;
            }
Z
zhaoyuan17 已提交
92 93 94
        }
    }

C
chensi10 已提交
95 96
    /*
    * @tc.number    : Acts_Ams_test_0100
97
    * @tc.name      : getProcessRunningInfos : Get All Running Processes Info
C
chensi10 已提交
98 99
    * @tc.desc      : Get All Running Processes Info(by Promise)
    */
C
chensi10 已提交
100
    it('Acts_Ams_test_0100', 0, async function (done) {
Z
zhaoyuan17 已提交
101 102 103
        console.info("sleep begin");
        sleep(5000);
        console.info("sleep end");
104
        var info = await appManager.getProcessRunningInfos();
Z
zhaoyuan17 已提交
105
        expect(Array.isArray(info)).assertEqual(true);
C
chengxingzhen 已提交
106
        expect(info.length).assertLarger(0);
Z
zhaoyuan17 已提交
107
        for (var i = 0; i < info.length; i++) {
108
            console.info('Acts_Ams_test_0100 getProcessRunningInfo[' + i + "]: " + JSON.stringify(info[i]));
Z
zhaoyuan17 已提交
109 110
            expect(typeof (info[i].pid)).assertEqual("number");
            expect(info[i].pid).assertLarger(0);
C
chensi10 已提交
111

Z
zhaoyuan17 已提交
112 113
            expect(typeof (info[i].processName)).assertEqual("string");
            expect(info[i].processName.length).assertLarger(0);
114 115
            expect(Array.isArray(info[i].bundleNames)).assertEqual(true);
            expect(info[i].bundleNames.length).assertEqual(0);
C
chensi10 已提交
116

Z
zhaoyuan17 已提交
117 118 119 120
            expect(typeof (info[i].uid)).assertEqual("number");
            expect(info[i].uid).assertLarger(0);
        }
        done();
C
chensi10 已提交
121 122
    })

123
    
Z
zhaoyuan17 已提交
124 125
    /*
    * @tc.number    : Acts_Ams_test_1100
126
    * @tc.name      : moveMissionToFront : Move Mission To Top
Z
zhaoyuan17 已提交
127 128 129 130
    * @tc.desc      : Move Mission To Top(by Promise)
    */
    it('Acts_Ams_test_1100', 0, async function (done) {
        var maxnum = 10;
131 132 133 134
        var result = await missionManager.getMissionInfos("", maxnum);
        for (var i = 0; i < result.length; i++) {
            console.info('Acts_Ams_test_0100 getMissionInfos result[' + i + "]: " + JSON.stringify(result[i]));
        }
135 136 137 138
        var info = await missionManager.moveMissionToFront(result[0].missionId).catch(err => {
            console.log('Acts_Ams_test_1100 moveMissionToFront failed: ' + err);
            expect(err).assertEqual(0);
        });
139
        console.info('Acts_Ams_test_1100 moveMissionToFront data  [' + info + ']');
Z
zhaoyuan17 已提交
140 141 142
        done();
    })

C
chensi10 已提交
143 144
    /*
    * @tc.number    : Acts_Ams_test_0300
145
    * @tc.name      : getMissionInfos : Query Running Ability Mission Infos
C
chensi10 已提交
146 147
    * @tc.desc      : Query Running Ability Mission Infos(by Promise)
    */
C
chensi10 已提交
148 149
    it('Acts_Ams_test_0300', 0, async function (done) {
        var maxnum = 10;
150
        var data = await missionManager.getMissionInfos("", maxnum);
Z
zhaoyuan17 已提交
151
        expect(Array.isArray(data)).assertEqual(true);
Z
zhaoyuan17 已提交
152
        expect(data.length).assertEqual(2);
Z
zhaoyuan17 已提交
153
        for (var i = 0; i < data.length; i++) {
154
            console.info('Acts_Ams_test_0300 getMissionInfos data[' + i + "]: " + JSON.stringify(data[i]));
Z
zhaoyuan17 已提交
155 156 157
            expect(typeof (data[i].missionId)).assertEqual("number");
            expect(data[i].missionId).assertLarger(0);

158 159 160 161 162 163 164 165 166 167 168
            expect(typeof (data[i].want)).assertEqual("object");
            expect(typeof (data[i].want.deviceId)).assertEqual("string");
            expect(typeof (data[i].want.bundleName)).assertEqual("string");
            expect(data[i].want.bundleName.length).assertLarger(0);
            expect(bundleNameList.indexOf(data[i].want.bundleName)).assertLarger(-1);
            expect(typeof (data[i].want.abilityName)).assertEqual("string");
            expect(data[i].want.abilityName.length).assertLarger(0);
            expect(abilityNameList.indexOf(data[i].want.abilityName)).assertLarger(-1);

            expect(typeof (data[i].label)).assertEqual("string");
            expect(typeof (data[i].iconPath)).assertEqual("string");
Z
zhaoyuan17 已提交
169 170 171 172
        }
        done();
    })

Z
zhaoyuan17 已提交
173 174 175 176 177 178
    /*
    * @tc.number    : Acts_Ams_test_1500
    * @tc.name      : killProcessesByBundleName : Kill Processes By BundleName
    * @tc.desc      : Kill Processes By BundleName(by Promise)
    */
    it('Acts_Ams_test_1500', 0, async function (done) {
179
        var info = await appManager.killProcessesByBundleName('com.ix.simulate.feature');
Z
zhaoyuan17 已提交
180 181 182 183
        console.info('Acts_Ams_test_1500 killProcessesByBundleName data  [' + info + ']');
        expect(info).assertEqual(0);
        done();
    })
184
})