From 10b2b6a523f0e4bc971df283d4ae8e90789e512e Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Mon, 7 Mar 2022 18:15:38 +0800 Subject: [PATCH] js api test Signed-off-by: wyuanchao --- bundle.json | 3 +- .../BUILD.gn | 26 ++ .../config.json | 74 ++++ .../device_usage_statistics_jsunit.test.js | 332 ++++++++++++++++++ .../ohos_device_usage_statistics.p7b | Bin 0 -> 3451 bytes 5 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn create mode 100644 interfaces/test/unittest/device_usage_statistics_jsunittest/config.json create mode 100644 interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js create mode 100644 interfaces/test/unittest/device_usage_statistics_jsunittest/ohos_device_usage_statistics.p7b diff --git a/bundle.json b/bundle.json index 014b937..374597e 100644 --- a/bundle.json +++ b/bundle.json @@ -67,7 +67,8 @@ } ], "test": [ - "//foundation/resourceschedule/device_usage_statistics/test/unittest:unittest" + "//foundation/resourceschedule/device_usage_statistics/test/unittest:unittest", + "//foundation/resourceschedule/device_usage_statistics/interfaces/test/unittest/device_usage_statistics_jsunittest:js_unittest" ] } } diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn b/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn new file mode 100644 index 0000000..c505e9a --- /dev/null +++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn @@ -0,0 +1,26 @@ +# 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("//build/test.gni") +module_output_path = "device_usage_statistics/interfaces" + +ohos_js_unittest("DeviceUsageStatisticsJsTest") { + module_out_path = module_output_path + hap_profile = "./config.json" + certificate_profile = "./ohos_device_usage_statistics.p7b" +} + +group("js_unittest") { + testonly = true + deps = [ ":DeviceUsageStatisticsJsTest" ] +} diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json b/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json new file mode 100644 index 0000000..88bddc0 --- /dev/null +++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json @@ -0,0 +1,74 @@ +{ + "app": { + "bundleName": "com.example.deviceUsageStatistics", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 7, + "target": 8 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.deviceUsageStatistics", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "backgroundModes": [ + "dataTransfer" + ], + "name": "com.example.deviceUsageStatistics.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "defPermissions": [ + { + "name": "ohos.permission.BUNDLE_ACTIVE_INFO" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.BUNDLE_ACTIVE_INFO" + } + ] + } + } + \ No newline at end of file diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js b/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js new file mode 100644 index 0000000..2b3c15c --- /dev/null +++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js @@ -0,0 +1,332 @@ +/* + * 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 bundleState from '@ohos.bundleState' + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe("DeviceUsageStatisticsJsTest", function () { + beforeAll(function() { + /* + * @tc.setup: setup invoked before all testcases + */ + console.info('beforeAll called') + }) + + afterAll(function() { + /* + * @tc.teardown: teardown invoked after all testcases + */ + console.info('afterAll called') + }) + + beforeEach(function() { + /* + * @tc.setup: setup invoked before each testcases + */ + console.info('beforeEach called') + }) + + afterEach(function() { + /* + * @tc.teardown: teardown invoked after each testcases + */ + console.info('afterEach caled') + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest001 + * @tc.desc: test isIdleState promise. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899 + */ + it("DeviceUsageStatisticsJsTest001", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest001---------------------------'); + let bundleName = 'com.example.deviceUsageStatistics'; + bundleState.isIdleState(bundleName).then((res) => { + console.info('BUNDLE_ACTIVE isIdleState promise success.'); + expect(true).assertEqual(true); + }).catch((err) => { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE isIdleState promise failure.'); + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest002 + * @tc.desc: test isIdleState callback. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G + */ + it("DeviceUsageStatisticsJsTest002", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest002---------------------------'); + let bundleName = 'com.example.deviceUsageStatistics'; + bundleState.isIdleState(bundleName, (err, res) => { + if(err.code === 0) { + console.info('BUNDLE_ACTIVE isIdleState callback success.'); + expect(true).assertEqual(true); + } else { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE isIdleState callback failure.'); + } + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest003 + * @tc.desc: test queryAppUsagePriorityGroup promise. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899 + */ + it("DeviceUsageStatisticsJsTest003", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest003---------------------------'); + bundleState.queryAppUsagePriorityGroup().then( res => { + console.info('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise success.'); + expect(true).assertEqual(true) + }).catch( err => { + expect(false).assertEqual(true) + console.info('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failure.'); + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest004 + * @tc.desc: test queryAppUsagePriorityGroup callback. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G + */ + it("DeviceUsageStatisticsJsTest004", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest004---------------------------'); + bundleState.queryAppUsagePriorityGroup((err, res) => { + if(err.code === 0) { + console.info('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback success.'); + expect(true).assertEqual(true) + } else { + expect(false).assertEqual(true) + console.info('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failure.'); + } + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest005 + * @tc.desc: test queryBundleActiveStates promise. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899 + */ + it("DeviceUsageStatisticsJsTest005", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest005---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + bundleState.queryBundleActiveStates(beginTime, endTime).then((res) => { + console.info('BUNDLE_ACTIVE queryBundleActiveStates promise success.'); + expect(true).assertEqual(true); + }).catch((err) => { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE queryBundleActiveStates promise failure.'); + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest006 + * @tc.desc: test queryBundleActiveStates callback. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G + */ + it("DeviceUsageStatisticsJsTest006", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest006---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + bundleState.queryBundleActiveStates(beginTime, endTime, (err, res) => { + if(err.code === 0) { + console.info('BUNDLE_ACTIVE queryBundleActiveStates callback success.'); + expect(true).assertEqual(true); + } else { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE queryBundleActiveStates callback failure.'); + } + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest007 + * @tc.desc: test queryBundleStateInfos promise. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899 + */ + it("DeviceUsageStatisticsJsTest007", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest007---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + bundleState.queryBundleStateInfos(beginTime, endTime).then((res) => { + console.info('BUNDLE_ACTIVE queryBundleStateInfos promise success.'); + expect(true).assertEqual(true); + }).catch((err) => { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE queryBundleStateInfos promise failure.'); + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest008 + * @tc.desc: test queryBundleStateInfos callback. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G + */ + it("DeviceUsageStatisticsJsTest008", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest008---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + bundleState.queryBundleStateInfos(beginTime, endTime, (err, res) => { + if(err.code === 0) { + console.info('BUNDLE_ACTIVE queryBundleStateInfos callback success.'); + expect(true).assertEqual(true); + } else { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE queryBundleStateInfos callback failure.'); + } + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest009 + * @tc.desc: test queryCurrentBundleActiveStates promise. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899 + */ + it("DeviceUsageStatisticsJsTest009", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest009---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + bundleState.queryCurrentBundleActiveStates(beginTime, endTime).then((res) => { + console.info('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.'); + expect(true).assertEqual(true); + }).catch((err) => { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failure.'); + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest010 + * @tc.desc: test queryCurrentBundleActiveStates callback. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G + */ + it("DeviceUsageStatisticsJsTest010", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest010---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => { + if(err.code === 0) { + console.info('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.'); + expect(true).assertEqual(true); + } else { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failure.'); + } + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest011 + * @tc.desc: test queryBundleStateInfoByInterval promise. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899 + */ + it("DeviceUsageStatisticsJsTest011", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest011---------------------------'); + let intervalType = 0; + let beginTime = 0; + let endTime = 20000000000000; + bundleState.queryBundleStateInfoByInterval(intervalType, beginTime, endTime).then((res) => { + console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'); + expect(true).assertEqual(true); + }).catch((err) => { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failure.'); + }); + + setTimeout(()=>{ + done(); + }, 500); + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest012 + * @tc.desc: test queryBundleStateInfoByInterval callback. + * @tc.type: FUNC + * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G + */ + it("DeviceUsageStatisticsJsTest012", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest012---------------------------'); + let intervalType = 0; + let beginTime = 0; + let endTime = 20000000000000; + bundleState.queryBundleStateInfoByInterval(intervalType, beginTime, endTime, (err, res) => { + if(err.code === 0) { + console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.'); + expect(true).assertEqual(true); + } else { + expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failure.'); + } + }); + + setTimeout(()=>{ + done(); + }, 500); + }) +}) \ No newline at end of file diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/ohos_device_usage_statistics.p7b b/interfaces/test/unittest/device_usage_statistics_jsunittest/ohos_device_usage_statistics.p7b new file mode 100644 index 0000000000000000000000000000000000000000..6d38035da96bab2ca3e7cdb4cc9d76c1d8cdd32f GIT binary patch literal 3451 zcmcgvYj6|S8MPjkF-Blwz(4^T;n)O_eOH!j$sq~5(&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