• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import backgroundTaskManager from '@ohos.backgroundTaskManager';
17import featureAbility from '@ohos.ability.featureAbility';
18import commonEvent from '@ohos.commonEvent';
19
20import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium';
21
22const TAG = "ContinuousTaskJsTest ";
23let subscribe_;
24
25export default function ContinuousTaskJsTest() {
26describe("ContinuousTaskJsTest", function () {
27    beforeAll(function() {
28
29        /*
30         * @tc.setup: setup invoked before all testcases
31         */
32         console.info('beforeAll called');
33    })
34
35    afterAll(function() {
36
37        /*
38         * @tc.teardown: teardown invoked after all testcases
39         */
40         console.info('afterAll called');
41    })
42
43    beforeEach(function() {
44
45        /*
46         * @tc.setup: setup invoked before each testcases
47         */
48         console.info('beforeEach called');
49    })
50
51    afterEach(function() {
52
53        /*
54         * @tc.teardown: teardown invoked after each testcases
55         */
56         console.info('afterEach called');
57    })
58
59    async function startAbilityWithOption(subscribeInfo, option, event, done) {
60        commonEvent.createSubscriber(subscribeInfo, (err, subscriber) => {
61            if (subscriber !== null && subscriber !== undefined) {
62                console.info(TAG + "Subscribe begin");
63                subscribe_ = subscriber;
64                commonEvent.subscribe(subscribe_, (err, data) => {
65                    if (data !== null && data !== undefined) {
66                        console.info(TAG + "Get comment event: " + JSON.stringify(data));
67                        if (data.event === event) {
68                            expect(true).assertTrue();
69                        } else {
70                            expect(false).assertTrue();
71                        }
72                    } else {
73                        console.error(TAG + "SubscribeCallBack failed");
74                        expect(false).assertTrue();
75                    }
76                    done();
77                })
78            } else {
79                console.error(TAG + "createSubscriber failed");
80                expect(false).assertTrue();
81                done();
82            }
83        })
84
85        setTimeout(() => {
86            console.info(TAG + "Start ability with option:" + option + " begin");
87            featureAbility.startAbility(
88                {
89                want: {
90                    bundleName: "ohos.acts.resourceschedule.taskmgr.js.function",
91                    abilityName: "ohos.acts.resourceschedule.taskmgr.js.function.ServiceAbility",
92                    parameters: {
93                        option: option
94                    }
95                }
96                }
97            ).catch(() => {
98                console.error(TAG + "Start ability failed");
99                expect(false).assertTrue();
100                done();
101            });
102        }, 1000);
103    }
104
105    /*
106     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_001
107     * @tc.name:ContinuousTaskJsTest001
108     * @tc.desc:verify old startBackgroundrunning interface callback mode work properly
109     */
110    it("ContinuousTaskJsTest001", 0, async function (done) {
111        console.info(TAG + '-----------------ContinuousTaskJsTest001 begin--------------------');
112        startAbilityWithOption({ events: ["startTaskUseApi7Callback"] }, "testcase1", "startTaskUseApi7Callback", done);
113    })
114
115    /*
116     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_002
117     * @tc.name:ContinuousTaskJsTest002
118     * @tc.desc:verify cancelBackgroundrunning interface callback mode work properly
119     */
120    it("ContinuousTaskJsTest002", 0, async function (done) {
121        console.info(TAG + '-----------------ContinuousTaskJsTest002 begin--------------------');
122        startAbilityWithOption({ events: ["stopTaskUseApi7Callback"] }, "testcase2", "stopTaskUseApi7Callback", done);
123    })
124
125    /*
126     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_003
127     * @tc.name:ContinuousTaskJsTest003
128     * @tc.desc:verify new startBackgroundrunning interface callback mode work properly
129     */
130    it("ContinuousTaskJsTest003", 0, async function (done) {
131        console.info(TAG + '-----------------ContinuousTaskJsTest003 begin--------------------');
132        startAbilityWithOption({ events: ["startTaskUseApi8Callback"] }, "testcase3", "startTaskUseApi8Callback", done);
133    })
134
135    /*
136     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_004
137     * @tc.name:ContinuousTaskJsTest004
138     * @tc.desc:verify new stopBackgroundrunning interface callback mode work properly
139     */
140    it("ContinuousTaskJsTest004", 0, async function (done) {
141        console.info(TAG + '-----------------ContinuousTaskJsTest004 begin--------------------');
142        startAbilityWithOption({ events: ["stopTaskUseApi8Callback"] }, "testcase4", "stopTaskUseApi8Callback", done);
143    })
144
145    /*
146     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_005
147     * @tc.name:ContinuousTaskJsTest005
148     * @tc.desc:verify old startBackgroundrunning interface promise mode work properly
149     */
150    it("ContinuousTaskJsTest005", 0, async function (done) {
151        console.info(TAG + '-----------------ContinuousTaskJsTest005 begin--------------------');
152        startAbilityWithOption({ events: ["startTaskUseApi7Promise"] }, "testcase5", "startTaskUseApi7Promise", done);
153    })
154
155    /*
156     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_006
157     * @tc.name:ContinuousTaskJsTest006
158     * @tc.desc:verify cancelBackgroundrunning interface promise mode work properly
159     */
160    it("ContinuousTaskJsTest006", 0, async function (done) {
161        console.info(TAG + '-----------------ContinuousTaskJsTest006 begin--------------------');
162        startAbilityWithOption({ events: ["stopTaskUseApi7Promise"] }, "testcase6", "stopTaskUseApi7Promise", done);
163    })
164
165    /*
166     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_007
167     * @tc.name:ContinuousTaskJsTest007
168     * @tc.desc:verify new startBackgroundrunning interface promise mode work properly
169     */
170    it("ContinuousTaskJsTest007", 0, async function (done) {
171        console.info(TAG + '-----------------ContinuousTaskJsTest007 begin--------------------');
172        startAbilityWithOption({ events: ["startTaskUseApi8Promise"] }, "testcase7", "startTaskUseApi8Promise", done);
173    })
174
175    /*
176     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_008
177     * @tc.name:ContinuousTaskJsTest008
178     * @tc.desc:verify new stopBackgroundrunning interface promise mode work properly
179     */
180    it("ContinuousTaskJsTest008", 0, async function (done) {
181        console.info(TAG + '-----------------ContinuousTaskJsTest008 begin--------------------');
182        startAbilityWithOption({ events: ["stopTaskUseApi8Promise"] }, "testcase8", "stopTaskUseApi8Promise", done);
183    })
184
185    /*
186     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_009
187     * @tc.name:ContinuousTaskJsTest009
188     * @tc.desc:verify continuous task request failed with invalid background mode
189     */
190    it("ContinuousTaskJsTest009", 0, async function (done) {
191        console.info(TAG + '-----------------ContinuousTaskJsTest009 begin--------------------');
192        startAbilityWithOption({ events: ["startTaskInvalidBgmode"] }, "testcase9", "startTaskInvalidBgmode", done);
193    })
194
195    /*
196     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_0010
197     * @tc.name: ContinuousTaskJsTest010
198     * @tc.desc: test backgroudManager BackgroudMode constant
199     */
200    it("ContinuousTaskJsTest010", 0, async function (done) {
201        console.info(TAG + '-----------------ContinuousTaskJsTest010 begin--------------------');
202        let value1 = backgroundTaskManager.BackgroundMode.DATA_TRANSFER;
203        expect(value1).assertEqual(1);
204        done();
205    })
206
207    /*
208     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_0011
209     * @tc.name: ContinuousTaskJsTest011
210     * @tc.desc: test backgroudManager BackgroudMode constant
211     */
212    it("ContinuousTaskJsTest011", 0, async function (done) {
213        console.info(TAG + '-----------------ContinuousTaskJsTest011 begin--------------------');
214        let value1 = backgroundTaskManager.BackgroundMode.AUDIO_PLAYBACK;
215        expect(value1).assertEqual(2);
216        done();
217    })
218
219    /*
220     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_0012
221     * @tc.name: ContinuousTaskJsTest012
222     * @tc.desc: test backgroudManager BackgroudMode constant
223     */
224    it("ContinuousTaskJsTest012", 0, async function (done) {
225        console.info(TAG + '-----------------ContinuousTaskJsTest012 begin--------------------');
226        let value1 = backgroundTaskManager.BackgroundMode.AUDIO_RECORDING;
227        expect(value1).assertEqual(3);
228        done();
229    })
230
231    /*
232     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_0013
233     * @tc.name: ContinuousTaskJsTest013
234     * @tc.desc: test backgroudManager BackgroudMode constant
235     */
236    it("ContinuousTaskJsTest013", 0, async function (done) {
237        console.info(TAG + '-----------------ContinuousTaskJsTest013 begin--------------------');
238        let value1 = backgroundTaskManager.BackgroundMode.LOCATION;
239        expect(value1).assertEqual(4);
240        done();
241    })
242
243    /*
244     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_0014
245     * @tc.name: ContinuousTaskJsTest014
246     * @tc.desc: test backgroudManager BackgroudMode constant
247     */
248    it("ContinuousTaskJsTest014", 0, async function (done) {
249        console.info(TAG + '-----------------ContinuousTaskJsTest014 begin--------------------');
250        let value1 = backgroundTaskManager.BackgroundMode.BLUETOOTH_INTERACTION;
251        expect(value1).assertEqual(5);
252        done();
253    })
254
255    /*
256     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_0015
257     * @tc.name: ContinuousTaskJsTest015
258     * @tc.desc: test backgroudManager BackgroudMode constant
259     */
260    it("ContinuousTaskJsTest015", 0, async function (done) {
261        console.info(TAG + '-----------------ContinuousTaskJsTest015 begin--------------------');
262        let value1 = backgroundTaskManager.BackgroundMode.MULTI_DEVICE_CONNECTION;
263        expect(value1).assertEqual(6);
264        done();
265    })
266
267    /*
268     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_0016
269     * @tc.name: ContinuousTaskJsTest016
270     * @tc.desc: test backgroudManager BackgroudMode constant
271     */
272    it("ContinuousTaskJsTest016", 0, async function (done) {
273        console.info(TAG + '-----------------ContinuousTaskJsTest016 begin--------------------');
274        let value1 = backgroundTaskManager.BackgroundMode.TASK_KEEPING;
275        expect(value1).assertEqual(9);
276        done();
277    })
278
279    /*
280     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_017
281     * @tc.name:ContinuousTaskJsTest017
282     * @tc.desc:verify continuous task updateBackgroundRunning
283     */
284    it("ContinuousTaskJsTest017", 0, async function (done) {
285        console.info(TAG + '-----------------ContinuousTaskJsTest017 begin--------------------');
286        startAbilityWithOption({ events: ["updateTaskUseApi12Promise"] }, "testcase10", "updateTaskUseApi12Promise", done);
287    })
288
289    /*
290     * @tc.number:SUB_RESOURCESCHEDULE_LONG_TASK_XTS_0018
291     * @tc.name: ContinuousTaskJsTest018
292     * @tc.desc: test backgroudManager BackgroudMode constant
293     * @tc.size MEDIUM
294     * @tc.type Function
295     * @tc.level Level 3
296     * @tc.require
297     */
298    it("ContinuousTaskJsTest018", 0, async function (done) {
299        console.info(TAG + '-----------------ContinuousTaskJsTest018 begin--------------------');
300        let value1 = backgroundTaskManager.BackgroundMode.VOIP;
301        expect(value1).assertEqual(8);
302        done();
303    })
304})}
305