MangerAbilityJsunit.test.js 13.9 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.
 */
C
chensi10 已提交
15 16
import featureAbility from '@ohos.ability.featureability'
import abilitymanager from '@ohos.app.abilitymanager'
C
chensi10 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit'

var WeightReasonCode = {
    REASON_UNKNOWN: 0,
    WEIGHT_FOREGROUND: 100,
    WEIGHT_FOREGROUND_SERVICE: 125,
    WEIGHT_VISIBLE: 200,
    WEIGHT_PERCEPTIBLE: 230,
    WEIGHT_SERVICE: 300,
    WEIGHT_TOP_SLEEPING: 325,
    WEIGHT_CANT_SAVE_STATE: 350,
    WEIGHT_CACHED: 400,
    WEIGHT_GONE: 1000
C
chensi10 已提交
30
}
C
chensi10 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44

var abilityNameList = [
    "com.ohos.launcher.MainAbility",
    "com.example.SimulateFeatureAbilityFir",
    "com.example.actsamscallbackfirstscene.MainAbility"
]

var bundleNameList = [
    "com.ohos.launcher",
    "com.ohos.systemui",
    "com.ix.simulate.feature",
    "com.example.actsamscallbackfirstscene"
]

C
chensi10 已提交
45 46
describe('ActsAmsCallBackFirstScene', function () {
    console.info('----ActsAmsCallBackFirstScene----');
Z
zhaoyuan 已提交
47
    beforeAll(async function (done) {
C
chensi10 已提交
48
        featureAbility.startAbility(
C
chensi10 已提交
49 50 51 52 53 54 55 56
            {
                want:
                {
                    deviceId: "",
                    bundleName: "com.ohos.launcher",
                    abilityName: "com.ohos.launcher.MainAbility",
                    action: "action1",
                    parameters:
C
chensi10 已提交
57
                        {},
C
chensi10 已提交
58 59 60
                },
            },
        );
C
chensi10 已提交
61
        var maxnum = 10, flag = 1;
Z
zhaoyuan 已提交
62 63 64 65 66 67 68
        var data = await abilitymanager.queryRecentAbilityMissionInfos(maxnum, flag);
        console.log('queryRecentAbilityMissionInfos data  ' + JSON.stringify(data));
        for (var i = 0; i < data.length; i++) {
            if (data[i].baseAbility.bundleName != 'com.example.actsamscallbackfirstscene' &&
                data[i].topAbility.bundleName != 'com.example.actsamscallbackfirstscene') {
                var info = abilitymanager.removeMission(data[i].id);
                console.log(' removeMission data  [' + info + ']');
C
chensi10 已提交
69
            }
Z
zhaoyuan 已提交
70
        };
C
chensi10 已提交
71
        featureAbility.startAbility(
C
chensi10 已提交
72 73 74 75 76 77 78 79
            {
                want:
                {
                    deviceId: "",
                    bundleName: "com.ix.simulate.feature",
                    abilityName: "com.example.SimulateFeatureAbilityFir",
                    action: "action1",
                    parameters:
C
chensi10 已提交
80
                        {},
C
chensi10 已提交
81 82 83
                },
            },
        );
Z
zhaoyuan 已提交
84
        done();
C
chensi10 已提交
85
    });
C
chensi10 已提交
86

C
chensi10 已提交
87 88 89 90 91
    /*
     * @tc.number    : Acts_Ams_test_0200
     * @tc.name      : getAllRunningProcesses : Get All Running Processes Info
     * @tc.desc      : Get All Running Processes Info(by CallBack)
     */
C
chensi10 已提交
92
    it('Acts_Ams_test_0200', 0, async function (done) {
C
chensi10 已提交
93 94 95 96 97 98 99 100 101 102 103
        setTimeout(function () {
            abilitymanager.getAllRunningProcesses(
                (error, info) => {
                    console.info('getAllRunningProcesses error.code \
                    ' + error.code + ', data length [' + info.length + ']');
                    console.info('Acts_Ams_test_0200 getAllRunningProcesses data ' + JSON.stringify(info));
                    expect(Array.isArray(info)).assertEqual(true);
                    expect(info.length).assertEqual(4);
                    for (var i = 0; i < info.length; i++) {
                        expect(typeof (info[i].pid)).assertEqual("number");
                        expect(info[i].pid).assertLarger(0);
C
chensi10 已提交
104

C
chensi10 已提交
105 106 107
                        expect(typeof (info[i].processName)).assertEqual("string");
                        expect(info[i].processName.length).assertLarger(0);
                        expect(bundleNameList.indexOf(info[i].processName)).assertLarger(-1);
C
chensi10 已提交
108

C
chensi10 已提交
109 110
                        expect(Array.isArray(info[i].pkgList)).assertEqual(true);
                        expect(info[i].pkgList.length).assertEqual(0);
C
chensi10 已提交
111

C
chensi10 已提交
112 113
                        expect(typeof (info[i].uid)).assertEqual("number");
                        expect(info[i].uid).assertLarger(0);
C
chensi10 已提交
114

C
chensi10 已提交
115 116
                        expect(typeof (info[i].lastMemoryLevel)).assertEqual("number");
                        expect(info[i].lastMemoryLevel).assertEqual(-1);
C
chensi10 已提交
117

C
chensi10 已提交
118 119
                        expect(typeof (info[i].weight)).assertEqual("number");
                        expect(info[i].weight).assertEqual(-1);
C
chensi10 已提交
120

C
chensi10 已提交
121 122 123 124 125 126
                        expect(typeof (info[i].weightReasonCode)).assertEqual("number");
                        expect(info[i].weightReasonCode).assertEqual(WeightReasonCode.REASON_UNKNOWN);
                    }
                });
            done();
        }, 5000);
C
chensi10 已提交
127 128
    })

C
chensi10 已提交
129 130 131 132 133
    /*
    * @tc.number    : Acts_Ams_test_0400
    * @tc.name      : queryRunningAbilityMissionInfos : Query Running Ability Mission Infos
    * @tc.desc      : Query Running Ability Mission Infos(by CallBack)
    */
C
chensi10 已提交
134 135 136
    it('Acts_Ams_test_0400', 0, async function (done) {
        var maxnum = 10;
        abilitymanager.queryRunningAbilityMissionInfos(maxnum,
C
chensi10 已提交
137 138
            (error, info) => {
                console.info('queryRecentAbilityMissionInfos error.code : \
Z
zhaoyuan 已提交
139
                ' + error.code + ',data length [' + info.length + ']');
C
chensi10 已提交
140
                console.info('Acts_Ams_test_0400 queryRunningAbilityMissionInfos info ' + JSON.stringify(info));
C
chensi10 已提交
141
                expect(Array.isArray(info)).assertEqual(true);
C
chensi10 已提交
142
                expect(info.length).assertEqual(2);
C
chensi10 已提交
143 144 145 146 147 148
                for (var i = 0; i < info.length; i++) {
                    expect(typeof (info[i].id)).assertEqual("number");
                    expect(info[i].id).assertLarger(0);

                    expect(typeof (info[i].baseAbility)).assertEqual("object");
                    expect(typeof (info[i].baseAbility.deviceId)).assertEqual("string");
C
chensi10 已提交
149
                    expect(info[i].baseAbility.deviceId.length).assertEqual(0);
C
chensi10 已提交
150 151
                    expect(typeof (info[i].baseAbility.bundleName)).assertEqual("string");
                    expect(info[i].baseAbility.bundleName.length).assertLarger(0);
C
chensi10 已提交
152
                    expect(bundleNameList.indexOf(info[i].baseAbility.bundleName)).assertLarger(-1);
C
chensi10 已提交
153 154
                    expect(typeof (info[i].baseAbility.abilityName)).assertEqual("string");
                    expect(info[i].baseAbility.abilityName.length).assertLarger(0);
C
chensi10 已提交
155
                    expect(abilityNameList.indexOf(info[i].baseAbility.abilityName)).assertLarger(-1);
C
chensi10 已提交
156 157 158

                    expect(typeof (info[i].topAbility)).assertEqual("object");
                    expect(typeof (info[i].topAbility.deviceId)).assertEqual("string");
C
chensi10 已提交
159
                    expect(info[i].topAbility.deviceId.length).assertEqual(0);
C
chensi10 已提交
160 161
                    expect(typeof (info[i].topAbility.bundleName)).assertEqual("string");
                    expect(info[i].topAbility.bundleName.length).assertLarger(0);
C
chensi10 已提交
162
                    expect(bundleNameList.indexOf(info[i].topAbility.bundleName)).assertLarger(-1);
C
chensi10 已提交
163 164
                    expect(typeof (info[i].topAbility.abilityName)).assertEqual("string");
                    expect(info[i].topAbility.abilityName.length).assertLarger(0);
C
chensi10 已提交
165
                    expect(abilityNameList.indexOf(info[i].topAbility.abilityName)).assertLarger(-1);
C
chensi10 已提交
166 167 168 169 170 171 172 173 174

                    expect(typeof (info[i].missionDescription)).assertEqual("object");
                    expect(typeof (info[i].missionDescription.label)).assertEqual("string");
                    expect(typeof (info[i].missionDescription.iconPath)).assertEqual("string");
                }
            });
        done();
    })

C
chensi10 已提交
175 176 177 178 179
    /*
     * @tc.number    : Acts_Ams_test_0600
     * @tc.name      : queryRecentAbilityMissionInfos : Query Recent Ability Mission Infos
     * @tc.desc      : Query Recent Ability Mission Infos(by CallBack)
     */
C
chensi10 已提交
180
    it('Acts_Ams_test_0600', 0, async function (done) {
C
chensi10 已提交
181 182 183 184
        var maxnum = 10, flag = 1;
        abilitymanager.queryRecentAbilityMissionInfos(maxnum, flag,
            (error, info) => {
                console.info('queryRunningAbilityMissionInfos error.code : \
Z
zhaoyuan 已提交
185
                ' + error.code + ',data length [' + info.length + ']');
C
chensi10 已提交
186
                console.info('Acts_Ams_test_0600 queryRecentAbilityMissionInfos info ' + JSON.stringify(info));
C
chensi10 已提交
187
                expect(Array.isArray(info)).assertEqual(true);
C
chensi10 已提交
188
                expect(info.length).assertEqual(2);
C
chensi10 已提交
189 190 191 192 193 194
                for (var i = 0; i < info.length; i++) {
                    expect(typeof (info[i].id)).assertEqual("number");
                    expect(info[i].id).assertLarger(0);

                    expect(typeof (info[i].baseAbility)).assertEqual("object");
                    expect(typeof (info[i].baseAbility.deviceId)).assertEqual("string");
C
chensi10 已提交
195
                    expect(info[i].baseAbility.deviceId.length).assertEqual(0);
C
chensi10 已提交
196 197
                    expect(typeof (info[i].baseAbility.bundleName)).assertEqual("string");
                    expect(info[i].baseAbility.bundleName.length).assertLarger(0);
C
chensi10 已提交
198
                    expect(bundleNameList.indexOf(info[i].baseAbility.bundleName)).assertLarger(-1);
C
chensi10 已提交
199 200
                    expect(typeof (info[i].baseAbility.abilityName)).assertEqual("string");
                    expect(info[i].baseAbility.abilityName.length).assertLarger(0);
C
chensi10 已提交
201
                    expect(abilityNameList.indexOf(info[i].baseAbility.abilityName)).assertLarger(-1);
C
chensi10 已提交
202 203 204

                    expect(typeof (info[i].topAbility)).assertEqual("object");
                    expect(typeof (info[i].topAbility.deviceId)).assertEqual("string");
C
chensi10 已提交
205
                    expect(info[i].topAbility.deviceId.length).assertEqual(0);
C
chensi10 已提交
206 207
                    expect(typeof (info[i].topAbility.bundleName)).assertEqual("string");
                    expect(info[i].topAbility.bundleName.length).assertLarger(0);
C
chensi10 已提交
208
                    expect(bundleNameList.indexOf(info[i].topAbility.bundleName)).assertLarger(-1);
C
chensi10 已提交
209 210
                    expect(typeof (info[i].topAbility.abilityName)).assertEqual("string");
                    expect(info[i].topAbility.abilityName.length).assertLarger(0);
C
chensi10 已提交
211
                    expect(abilityNameList.indexOf(info[i].topAbility.abilityName)).assertLarger(-1);
C
chensi10 已提交
212 213 214 215 216 217 218 219

                    expect(typeof (info[i].missionDescription)).assertEqual("object");
                    expect(typeof (info[i].missionDescription.label)).assertEqual("string");
                    expect(typeof (info[i].missionDescription.iconPath)).assertEqual("string");
                }
            });
        done();
    })
C
chensi10 已提交
220 221 222 223 224 225

    /*
     * @tc.number    : Acts_Ams_test_0800
     * @tc.name      : removeMission : Remove Mission
     * @tc.desc      : Remove Mission(by CallBack)
     */
C
chensi10 已提交
226 227 228 229
    it('Acts_Ams_test_0800', 0, async function (done) {
        var maxnum = 10;
        var result = await abilitymanager.queryRunningAbilityMissionInfos(maxnum);
        abilitymanager.removeMission(result[0].id,
C
chensi10 已提交
230 231 232
            (error, info) => {
                console.info('Acts_Ams_test_0800 removeMission error.code \
                ' + error.code + ',data  [' + info + ']');
C
chensi10 已提交
233 234 235 236 237
                expect(info).assertLarger(0);
            });
        done();
    })

C
chensi10 已提交
238 239 240 241 242
    /*
     * @tc.number    : Acts_Ams_test_1200
     * @tc.name      : moveMissionToTop : Move Mission To Top
     * @tc.desc      : Move Mission To Top(by CallBack)
     */
C
chensi10 已提交
243 244 245 246
    it('Acts_Ams_test_1200', 0, async function (done) {
        var maxnum = 10;
        var result = await abilitymanager.queryRunningAbilityMissionInfos(maxnum);
        abilitymanager.moveMissionToTop(result[0].id,
C
chensi10 已提交
247 248 249
            (error, info) => {
                console.info('Acts_Ams_test_1200 moveMissionToTop error.code \
                ' + error.code + ',data  [' + info + ']');
C
chensi10 已提交
250 251 252 253
                expect(info).assertEqual(0);
            });
        done();
    })
C
chensi10 已提交
254 255 256 257 258 259

    /*
     * @tc.number    : Acts_Ams_test_1400
     * @tc.name      : removeMissions : Remove Missions
     * @tc.desc      : Remove Missions(by CallBack)
     */
C
chensi10 已提交
260 261 262 263
    it('Acts_Ams_test_1400', 0, async function (done) {
        var maxnum = 10;
        var result = await abilitymanager.queryRunningAbilityMissionInfos(maxnum);
        abilitymanager.removeMissions([result[0].id],
C
chensi10 已提交
264 265 266
            (error, info) => {
                console.info('Acts_Ams_test_1400 removeMissions error.code \
                ' + error.code + ',data  [' + info + ']');
C
chensi10 已提交
267 268 269 270 271
                expect(info).assertLarger(0);
            });
        done();
    })

C
chensi10 已提交
272 273 274 275 276
    /*
     * @tc.number    : Acts_Ams_test_1000
     * @tc.name      : clearMissions : Clear Missions
     * @tc.desc      : Clear Missions(by CallBack)
     */
C
chensi10 已提交
277 278
    it('Acts_Ams_test_1000', 0, async function (done) {
        abilitymanager.clearMissions(
C
chensi10 已提交
279 280 281
            (error, info) => {
                console.info('Acts_Ams_test_1000 clearMissions error.code \
                ' + error.code + ',data  [' + info + ']');
C
chensi10 已提交
282 283 284 285 286
                expect(info).assertLarger(0);
            });
        done();
    })

C
chensi10 已提交
287 288 289 290 291
    /*
     * @tc.number    : Acts_Ams_test_1600
     * @tc.name      : killProcessesByBundleName : Kill Processes By BundleName
     * @tc.desc      : Kill Processes By BundleName(by CallBack)
     */
C
chensi10 已提交
292 293
    it('Acts_Ams_test_1600', 0, async function (done) {
        abilitymanager.killProcessesByBundleName('com.ix.simulate.feature',
C
chensi10 已提交
294 295 296
            (error, info) => {
                console.info('Acts_Ams_test_1600 killProcessesByBundleName error.code: \
                ' + error.code + ',data  [' + info + ']');
C
chensi10 已提交
297 298 299 300 301 302 303 304
                expect(info).assertEqual(0);
            });
        done();

    })
})