diff --git a/account/BUILD.gn b/account/BUILD.gn index e244466fd18fcc310c045ed1e40965d59c662b83..0dce1ac124acd595eca87d4d9e91f332cb2e08b8 100755 --- a/account/BUILD.gn +++ b/account/BUILD.gn @@ -18,6 +18,7 @@ group("account") { deps = [ "OsAccountTest_js:ActsOsAccountJSApiTest", "appaccount:appaccount_hap", + "osaccount:osaccount_hap", ] } else { deps = [] diff --git a/account/osaccount/BUILD.gn b/account/osaccount/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..efe2642a611faf77b4fb516bcf94bc9b8f84f7f7 --- /dev/null +++ b/account/osaccount/BUILD.gn @@ -0,0 +1,24 @@ +# 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. + +import("//test/xts/tools/build/suite.gni") + +group("osaccount_hap") { + testonly = true + if (is_standard_system) { + deps = [ + "actsosaccountsystemtest:ActsOsAccountSystemTest", + "actsosaccountthirdpartytest:ActsOsAccountThirdPartyTest", + ] + } +} diff --git a/account/osaccount/actsosaccountsystemtest/BUILD.gn b/account/osaccount/actsosaccountsystemtest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..a3a3ced33babf0087703d52173e213e1d49438f4 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/BUILD.gn @@ -0,0 +1,31 @@ +# 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. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsOsAccountSystemTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsOsAccountSystemTest" +} +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "./entry/src/main/js/default" +} +ohos_resources("hjs_demo_resources") { + sources = [ "./entry/src/main/js/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/account/osaccount/actsosaccountsystemtest/Test.json b/account/osaccount/actsosaccountsystemtest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..e3b0d3326f7e038c6db1a25b86b9911eab5b2e56 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "com.example.actsosaccountsystemtest", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "ActsOsAccountSystemTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/config.json b/account/osaccount/actsosaccountsystemtest/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..6005e7b0648f4348eddfbb5fcba7255c88b81f26 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/config.json @@ -0,0 +1,83 @@ +{ + "app": { + "bundleName": "com.example.actsosaccountsystemtest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.actsosaccountsystemtest", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "defPermissions": [ + { + "availableScope": [], + "grantMode": "system_grant", + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS" + }, + { + "availableScope": [], + "grantMode": "system_grant", + "name": "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS", + "reason": "ceshi" + }, + { + "name": "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION", + "reason": "ceshi" + } + ], + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.actsosaccountsystemtest.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/app.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..2a68c1992145a976957d7dcdd69a7e9c2e8e9877 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/app.js @@ -0,0 +1,22 @@ +/* + * 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. + */ +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/i18n/en-US.json b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/i18n/zh-CN.json b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.css b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6724ec055a554cf3f9c7be83780c30df2274875b --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,12 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} +.titleST { + font-size: 32px; +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.hml b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..065ebc54d126c98094cc1f7bdbac19e3bec7d5c1 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,8 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + + + STActsOsAccountSystemTest + +
diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..bf4a20cd6664116e2f57f1808a8ed6aac570c301 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,46 @@ +/* + * 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. + */ +import file from '@system.file' +import {Core, ExpectExtend} from 'deccjsunit/index' + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + this.timeout = 8000; + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/resources/base/element/string.json b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..9880a82c2e4b26d9522b66fbafa9ea3aaafb06bf --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsOsAccountSystemTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/resources/base/media/icon.png b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/resources/base/media/icon.png differ diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Activate.test.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Activate.test.js new file mode 100755 index 0000000000000000000000000000000000000000..0ab2d5fec2c5d87d406c1be84cb83f1c6e443d5a --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Activate.test.js @@ -0,0 +1,405 @@ +/* + * 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. + */ +import osaccount from '@ohos.account.osAccount' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('ActsOsAccountSystemTest', function () { + + /* + * @tc.number : ActsOsAccountActivate_0100 + * @tc.name : activateOsAccount callback + * @tc.desc : Verify repeat switch 100 local user + */ + it('ActsOsAccountActivate_0100', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.isOsAccountActived(100, (err, data)=>{ + console.debug("====>isOsAccountActived err:" + JSON.stringify(err)); + console.debug("====>isOsAccountActived data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertTrue(); + osAccountManager.activateOsAccount(100, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_0100 end===="); + done(); + }) + }) + }); + + /* + * @tc.number : ActsOsAccountActivate_0200 + * @tc.name : activateOsAccount promise + * @tc.desc : Verify repeat switch 100 local user + */ + it('ActsOsAccountActivate_0200', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + var isActived = await osAccountManager.isOsAccountActived(100); + }catch(err){ + console.error("====>catch isOsAccountActived 0200 err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>isOsAccountActived err:" + JSON.stringify(isActived)); + expect(isActived).assertTrue(); + try{ + await osAccountManager.activateOsAccount(100); + }catch(err){ + console.debug("====>catch activateOsAccount 0200 err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_0200 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountActivate_0300 + * @tc.name : activateOsAccount callback + * @tc.desc : Authenticate switch to newly created local user + */ + it('ActsOsAccountActivate_0300', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0300 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var osLocalId; + osAccountManager.createOsAccount("osAccountNameTestActivate", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + osLocalId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + osAccountManager.isOsAccountActived(osLocalId, (err, data)=>{ + console.debug("====>localId: " + osLocalId + " isOsAccountActived err:" + JSON.stringify(err)); + console.debug("====>localId: " + osLocalId + " isOsAccountActived data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertFalse(); + osAccountManager.activateOsAccount(osLocalId, (err)=>{ + console.debug("====>activateOsAccount localId: " + osLocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.isOsAccountActived(osLocalId, (err, data)=>{ + console.debug("====>localId: " + osLocalId + " isOsAccountActived err:" + JSON.stringify(err)); + console.debug("====>localId: " + osLocalId + " isOsAccountActived data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertTrue(); + osAccountManager.isOsAccountActived(100, (err, data)=>{ + console.debug("====>localId: 100 isOsAccountActived err:" + JSON.stringify(err)); + console.debug("====>localId: 100 isOsAccountActived data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertFalse(); + osAccountManager.activateOsAccount(100, (err)=>{ + console.debug("====>activateOsAccount localId: 100 err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.removeOsAccount(osLocalId, (err)=>{ + console.debug("====>remove localId: " + osLocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountActivate_0300 end===="); + done(); + }) + }) + }) + }) + }) + }) + }) + }); + + /* + * @tc.number : ActsOsAccountActivate_0400 + * @tc.name : activateOsAccount promise + * @tc.desc : Authenticate switch to newly created local user + */ + it('ActsOsAccountActivate_0400', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0400 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var osLocalId; + var osAccountInfo = await osAccountManager.createOsAccount("osAccountNameTestActivate", 1); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + osLocalId = osAccountInfo.localId; + var isActived = await osAccountManager.isOsAccountActived(osLocalId); + console.debug("====>localId: " + osLocalId + " isOsAccountActived:" + isActived); + expect(isActived).assertFalse(); + await osAccountManager.activateOsAccount(osLocalId); + var isActivedTwice = await osAccountManager.isOsAccountActived(osLocalId); + console.debug("====>after activing localId: " + osLocalId + " isOsAccountActived:" + isActivedTwice); + expect(isActivedTwice).assertTrue(); + var isActiveHandred = await osAccountManager.isOsAccountActived(100); + console.debug("====>localId: 100 isOsAccountActived:" + isActiveHandred); + expect(isActiveHandred).assertFalse(); + await osAccountManager.activateOsAccount(100); + await osAccountManager.removeOsAccount(osLocalId); + console.debug("====>ActsOsAccountActivate_0400 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountActivate_0500 + * @tc.name : activateOsAccount callback + * @tc.desc : Authenticate failed to switch to 0 user + */ + it('ActsOsAccountActivate_0500', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.activateOsAccount(0, (err)=>{ + console.debug("====>activateOsAccount to 0 user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_0500 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountActivate_0600 + * @tc.name : activateOsAccount promise + * @tc.desc : Authenticate failed to switch to 0 user + */ + it('ActsOsAccountActivate_0600', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.activateOsAccount(0); + }catch(err){ + console.debug("====>activateOsAccount to 0 user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_0600 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountActivate_0700 + * @tc.name : activateOsAccount callback + * @tc.desc : Authenticate failed to switch to -1 user + */ + it('ActsOsAccountActivate_0700', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0700 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.activateOsAccount(-1, (err)=>{ + console.debug("====>activateOsAccount to -1 user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_0700 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountActivate_0800 + * @tc.name : activateOsAccount promise + * @tc.desc : Authenticate failed to switch to -1 user + */ + it('ActsOsAccountActivate_0800', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0800 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.activateOsAccount(-1); + }catch(err){ + console.debug("====>activateOsAccount to -1 user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_0800 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountActivate_0900 + * @tc.name : activateOsAccount callback + * @tc.desc : Authenticate failed to switch to "Abc" user + */ + it('ActsOsAccountActivate_0900', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_0900 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.activateOsAccount("Abc", (err)=>{ + console.debug("====>activateOsAccount to 'Abc' user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_0900 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountActivate_1000 + * @tc.name : activateOsAccount promise + * @tc.desc : Authenticate failed to switch to "Abc" user + */ + it('ActsOsAccountActivate_1000', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_1000 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.activateOsAccount("Abc"); + }catch(err){ + console.debug("====>activateOsAccount to 'Abc' user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_1000 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountActivate_1100 + * @tc.name : activateOsAccount callback + * @tc.desc : Authenticate failed to switch to undefined user + */ + it('ActsOsAccountActivate_1100', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_1100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.activateOsAccount(undefined, (err)=>{ + console.debug("====>activateOsAccount to undefined user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_1100 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountActivate_1200 + * @tc.name : activateOsAccount promise + * @tc.desc : Authenticate failed to switch to undefined user + */ + it('ActsOsAccountActivate_1200', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_1200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.activateOsAccount(undefined); + }catch(err){ + console.debug("====>activateOsAccount to undefined user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_1200 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountActivate_1300 + * @tc.name : activateOsAccount callback + * @tc.desc : Authenticate failed to switch to non-existent user + */ + it('ActsOsAccountActivate_1300', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_1300 start===="); + var osAccountManager = osaccount.getAccountManager(); + var nonExistentLocalId = 1000; + console.debug("====>get AccountManager finish===="); + osAccountManager.activateOsAccount(nonExistentLocalId, (err)=>{ + console.debug("====>activateOsAccount to nonexist user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_1300 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountActivate_1400 + * @tc.name : activateOsAccount promise + * @tc.desc : Authenticate failed to switch to non-existent user + */ + it('ActsOsAccountActivate_1400', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_1400 start===="); + var osAccountManager = osaccount.getAccountManager(); + var nonExistentLocalId = 1000; + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.activateOsAccount(nonExistentLocalId); + }catch(err){ + console.debug("====>activateOsAccount to nonexist user err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountActivate_1400 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountActivate_1500 + * @tc.name : activateOsAccount callback + * @tc.desc : Authenticate delete newly created active user + */ + it('ActsOsAccountActivate_1500', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_1500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + osAccountManager.createOsAccount("osAccountNameTestDelete", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + osAccountManager.isOsAccountActived(localId, (err, data)=>{ + console.debug("====>localId: " + localId + " isOsAccountActived err:" + JSON.stringify(err)); + console.debug("====>localId: " + localId + " isOsAccountActived data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertFalse(); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.isOsAccountActived(localId, (err, data)=>{ + console.debug("====>localId: " + localId + " isOsAccountActived err:" + JSON.stringify(err)); + console.debug("====>localId: " + localId + " isOsAccountActived data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertTrue(); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.isOsAccountActived(100, (err, data)=>{ + console.debug("====>localId: 100 isOsAccountActived err:" + JSON.stringify(err)); + console.debug("====>localId: 100 isOsAccountActived data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertTrue(); + console.debug("====>ActsOsAccountActivate_1500 end===="); + done(); + }) + }) + }) + }) + }) + }) + }); + + /* + * @tc.number : ActsOsAccountActivate_1600 + * @tc.name : activateOsAccount promise + * @tc.desc : Authenticate delete newly created active user + */ + it('ActsOsAccountActivate_1600', 0, async function (done) { + console.debug("====>ActsOsAccountActivate_1600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var osAccountInfo = await osAccountManager.createOsAccount("osAccountNameTestActivate", 1); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + var isActived = await osAccountManager.isOsAccountActived(localId); + console.debug("====>localId: " + localId + " isOsAccountActived:" + isActived); + expect(isActived).assertFalse(); + await osAccountManager.activateOsAccount(localId); + var isActivedTwice = await osAccountManager.isOsAccountActived(localId); + console.debug("====>after activing localId: " + localId + " isOsAccountActived:" + isActivedTwice); + expect(isActivedTwice).assertTrue(); + await osAccountManager.removeOsAccount(localId); + var isActiveHandred = await osAccountManager.isOsAccountActived(100); + console.debug("====>localId: 100 isOsAccountActived:" + isActiveHandred); + expect(isActiveHandred).assertTrue(); + console.debug("====>ActsOsAccountActivate_1600 end===="); + done(); + }); +}) \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/List.test.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..faef68495df494bb27a3efa7b4c2097ae1bc7ca2 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/List.test.js @@ -0,0 +1,17 @@ +/* + * 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. + */ +require('./Query.test.js') +require('./Activate.test.js') +require('./OnOff.test.js') \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/OnOff.test.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/OnOff.test.js new file mode 100755 index 0000000000000000000000000000000000000000..c05fbce83f7c6c33448834c8ef851eb6ac72a66f --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/OnOff.test.js @@ -0,0 +1,762 @@ +/* + * 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. + */ +import osaccount from '@ohos.account.osAccount' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +const TIMEOUTHALF = 500; +const TIMEOUT = 1000; +describe('ActsOsAccountSystemTest', function () { + function sleep(delay) { + var start = (new Date()).getTime(); + while((new Date()).getTime() - start < delay) { + continue; + } + } + + /* + * @tc.number : ActsOsAccountOnOff_0100 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verify that the activating type subscription can receive user switching + */ + it('ActsOsAccountOnOff_0100', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + osAccountManager.off("activating", "osAccountOnOffNameA", offCallback); + } + } + function removeCallback(err){ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_0100 end===="); + done(); + } + function offCallback(){ + console.debug("====>off enter") + osAccountManager.removeOsAccount(localId, removeCallback); + } + osAccountManager.on("activating", "osAccountOnOffNameA", onCallback); + sleep(TIMEOUT); + osAccountManager.createOsAccount("osAccountNameA", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameA"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_0200 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verify that the activate type subscription can receive user switching + */ + it('ActsOsAccountOnOff_0200', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + osAccountManager.off("activate", "osAccountOnOffNameB", offCallback); + } + } + function offCallback(){ + console.debug("====>off enter") + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_0200 end===="); + done(); + }) + } + osAccountManager.on("activate", "osAccountOnOffNameB", onCallback); + sleep(TIMEOUT); + osAccountManager.createOsAccount("osAccountNameB", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameB"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + }); + }); + }) + + /* + * @tc.number : ActsOsAccountOnOff_0300 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verify that the activating type unsubscribes successfully + */ + it('ActsOsAccountOnOff_0300', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0300 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + function offCallback(){ + console.debug("====>off enter") + } + osAccountManager.on("activating", "osAccountOnOffNameC", onCallback); + sleep(TIMEOUTHALF); + osAccountManager.off("activating", "osAccountOnOffNameC", offCallback); + sleep(TIMEOUTHALF); + osAccountManager.createOsAccount("osAccountNameC", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameC"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_0300 end===="); + done(); + }) + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_0400 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verify that the activate type unsubscribes successfully + */ + it('ActsOsAccountOnOff_0400', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0400 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + function offCallback(){ + console.debug("====>off enter") + } + osAccountManager.on("activate", "osAccountOnOffNameD", onCallback); + sleep(TIMEOUTHALF); + osAccountManager.off("activate", "osAccountOnOffNameD", offCallback); + sleep(TIMEOUTHALF); + osAccountManager.createOsAccount("osAccountNameD", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameD"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_0400 end===="); + done(); + }) + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_0500 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verification cannot cancel activating type not subscribed + */ + it('ActsOsAccountOnOff_0500', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0500 start===="); + var osAccountManager = osaccount.getAccountManager(); + var notOnName = "nameNotSubscribeActivatingTest"; + console.debug("====>get AccountManager finish===="); + function offCallback(){ + console.debug("====>wrongly enter off callback===="); + expect().assertFail(); + done(); + } + osAccountManager.off("activating", notOnName, offCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountOnOff_0500 end===="); + done(); + }, TIMEOUT); + }); + + /* + * @tc.number : ActsOsAccountOnOff_0600 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verification cannot cancel activate type not subscribed + */ + it('ActsOsAccountOnOff_0600', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0600 start===="); + var osAccountManager = osaccount.getAccountManager(); + var notOnName = "nameNotSubscribeActivateTest"; + console.debug("====>get AccountManager finish===="); + function offCallback(){ + console.debug("====>wrongly enter off callback===="); + expect().assertFail(); + done(); + } + osAccountManager.off("activate", notOnName, offCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountOnOff_0600 end===="); + done(); + }, TIMEOUT); + }); + + /* + * @tc.number : ActsOsAccountOnOff_0700 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verification cannot cancel activating type not subscribed + */ + it('ActsOsAccountOnOff_0700', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0700 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + osAccountManager.on("activating", "", onCallback); + sleep(TIMEOUTHALF); + osAccountManager.createOsAccount("osAccountNameE", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameE"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_0700 end===="); + done(); + }) + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_0800 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verification cannot cancel activating type not subscribed + */ + it('ActsOsAccountOnOff_0800', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0800 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + osAccountManager.on("activate", "", onCallback); + sleep(TIMEOUTHALF); + osAccountManager.createOsAccount("osAccountNameF", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameF"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_0800 end===="); + done(); + }) + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_0900 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verification does not trigger callbacks for activating type subscriptions when switching fails + */ + it('ActsOsAccountOnOff_0900', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_0900 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + function offCallback(){ + console.debug("====>off enter"); + console.debug("====>ActsOsAccountOnOff_0900 end===="); + done(); + } + osAccountManager.on("activating", "osAccountOnOffNameG", onCallback); + sleep(TIMEOUTHALF); + osAccountManager.queryAllCreatedOsAccounts((err, data)=>{ + console.debug("====>queryAllCreatedOsAccounts err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + for (var i = 0;i< data.length;i++){ + if(data[i].isActived == true){ + localId = data[i].localId; + } + } + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code !=0).assertEqual(true); + setTimeout(()=>{ + osAccountManager.off("activating", "osAccountOnOffNameG", offCallback); + }, TIMEOUT); + }); + }) + }); + + /* + * @tc.number : ActsOsAccountOnOff_1000 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verification does not trigger callbacks for activate type subscriptions when switching fails + */ + it('ActsOsAccountOnOff_1000', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1000 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + function offCallback(){ + console.debug("====>off enter"); + console.debug("====>ActsOsAccountOnOff_1000 end===="); + done(); + } + osAccountManager.on("activate", "osAccountOnOffNameH", onCallback); + sleep(TIMEOUTHALF); + osAccountManager.queryAllCreatedOsAccounts((err, data)=>{ + console.debug("====>queryAllCreatedOsAccounts err:" + JSON.stringify(err)); + for (var i = 0;i< data.length;i++){ + if(data[i].isActived == true){ + localId = data[i].localId; + } + } + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + setTimeout(()=>{ + expect(err.code !=0).assertEqual(true); + osAccountManager.off("activate", "osAccountOnOffNameH", offCallback); + }, 2000); + }); + }) + }) + + /* + * @tc.number : ActsOsAccountOnOff_1100 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verify that an instance repeatedly subscribes to local users + */ + it('ActsOsAccountOnOff_1100', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1100 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + var countNum = 0; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + countNum++; + } + } + function onCallbackTwice(receiveLocalId){ + console.debug("====>receive twice localId:" + receiveLocalId); + if(receiveLocalId == localId){ + countNum++; + } + } + function offCallback(){ + console.debug("====>off enter===="); + expect(countNum).assertEqual(2); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_1100 end===="); + done(); + }) + } + osAccountManager.on("activate", "osAccountOnOffNameI", onCallback); + osAccountManager.on("activate", "osAccountOnOffNameI", onCallbackTwice); + sleep(TIMEOUT); + osAccountManager.createOsAccount("osAccountNameI", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameI"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + osAccountManager.off("activate", "osAccountOnOffNameI", offCallback); + }, 2000); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_1200 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verify that an instance unsubscribes local users afer resubscribing + */ + it('ActsOsAccountOnOff_1200', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1200 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + var countNum = 0; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + countNum++; + } + } + function onCallbackTwice(receiveLocalId){ + console.debug("====>receive twice localId:" + receiveLocalId); + if(receiveLocalId == localId){ + countNum++; + } + } + function offCallback(){ + console.debug("====>off enter===="); + } + osAccountManager.on("activate", "osAccountOnOffNameJ", onCallback); + osAccountManager.on("activate", "osAccountOnOffNameJ", onCallbackTwice); + sleep(TIMEOUTHALF); + osAccountManager.off("activate", "osAccountOnOffNameJ", offCallback); + sleep(TIMEOUTHALF); + osAccountManager.createOsAccount("osAccountNameJ", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameJ"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + expect(countNum).assertEqual(0); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_1200 end===="); + done(); + }) + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_1300 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Verify that an instance unsubscribes local users afer resubscribing + */ + it('ActsOsAccountOnOff_1300', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1300 start===="); + var osAccountManager = osaccount.getAccountManager(); + var osAccountManagerTwice = osaccount.getAccountManager(); + var localId; + var countFirstNum = 0; + var countSecondNum = 0; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + countFirstNum++; + } + } + function onCallbackTwice(receiveLocalId){ + console.debug("====>receive twice localId:" + receiveLocalId); + if(receiveLocalId == localId){ + countSecondNum++; + } + } + function offCallback(){ + console.debug("====>off enter===="); + } + function offCallbackTwice(){ + console.debug("====>off twice enter===="); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_1300 end===="); + done(); + }) + } + osAccountManager.on("activate", "osAccountOnOffNameJ", onCallback); + osAccountManagerTwice.on("activate", "osAccountOnOffNameJ", onCallbackTwice); + sleep(TIMEOUTHALF); + osAccountManager.off("activate", "osAccountOnOffNameJ", offCallback); + sleep(TIMEOUTHALF); + osAccountManager.createOsAccount("osAccountNameK", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameK"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + expect(countFirstNum).assertEqual(0); + expect(countSecondNum).assertEqual(1); + osAccountManagerTwice.off("activate", "osAccountOnOffNameJ", offCallbackTwice); + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_1400 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Validate subscription with parameter type as empty string + */ + it('ActsOsAccountOnOff_1400', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1400 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + osAccountManager.on("", "osAccountOnOffNameL", onCallback); + sleep(TIMEOUTHALF); + osAccountManager.createOsAccount("osAccountNameL", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameL"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_1400 end===="); + done(); + }) + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_1500 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Validate subscription with parameter type as other string + */ + it('ActsOsAccountOnOff_1500', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1500 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + osAccountManager.on("Abc", "osAccountOnOffNameM", onCallback); + sleep(TIMEOUTHALF); + osAccountManager.createOsAccount("osAccountNameM", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameM"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_1500 end===="); + done(); + }) + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_1600 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Validate subscription with parameter type as undefined + */ + it('ActsOsAccountOnOff_1600', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1600 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + console.debug("====>wrongly received localId: " + localId + " after unsubscribing"); + expect().assertFail(); + done(); + } + } + osAccountManager.on(undefined, "osAccountOnOffNameM", onCallback); + osAccountManager.createOsAccount("osAccountNameM", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameM"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + setTimeout(()=>{ + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountOnOff_1600 end===="); + done(); + }) + }, TIMEOUT); + }); + }); + }); + + /* + * @tc.number : ActsOsAccountOnOff_1700 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Validate unsubscribe with parameter type as empty string + */ + it('ActsOsAccountOnOff_1700', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1700 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + function offCallback(){ + console.debug("====>wrongly enter off callback===="); + expect().assertFail(); + done(); + } + osAccountManager.off("", "osAccountOnOffNameN", offCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountOnOff_1700 end===="); + done(); + }, TIMEOUT); + }); + + /* + * @tc.number : ActsOsAccountOnOff_1800 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Validate unsubscribe with parameter type as other string + */ + it('ActsOsAccountOnOff_1800', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1800 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + function offCallback(){ + console.debug("====>wrongly enter off callback===="); + expect().assertFail(); + done(); + } + osAccountManager.off("Abc", "osAccountOnOffNameO", offCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountOnOff_1800 end===="); + done(); + }, TIMEOUT); + }); + + /* + * @tc.number : ActsOsAccountOnOff_1900 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Validate unsubscribe with parameter type as undefined + */ + it('ActsOsAccountOnOff_1900', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_1900 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + function offCallback(){ + console.debug("====>wrongly enter off callback===="); + expect().assertFail(); + done(); + } + osAccountManager.off(undefined, "osAccountOnOffNameP", offCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountOnOff_1900 end===="); + done(); + }, TIMEOUT); + }); + +}) \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Query.test.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Query.test.js new file mode 100755 index 0000000000000000000000000000000000000000..7834b26eb9cba5eb8b79e09cddbdbc793ee51d35 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Query.test.js @@ -0,0 +1,422 @@ +/* + * 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. + */ +import osaccount from '@ohos.account.osAccount' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +const OSACCOUNTMAXNUMBER = 999; +describe('ActsOsAccountSystemTest', function () { + + /* + * @tc.number : ActsOsAccountQuery_0100 + * @tc.name : queryOsAccountById callback + * @tc.desc : Authenticate to get local user 100 information and compare + */ + it('ActsOsAccountQuery_0100', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.queryOsAccountById(100, (err, data)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + console.debug("====>queryOsAccountById data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localId).assertEqual(100); + expect(data.type.ADMIN).assertEqual(0); + var serialNumberStr = data.serialNumber.toString(); + var serialIntercept = serialNumberStr.substring(8); + console.debug("====>truncate the last eight characters: " + serialIntercept); + expect(serialIntercept).assertEqual("00000001"); + expect(data.isCreateCompleted).assertTrue(); + console.debug("====>ActsOsAccountQuery_0100 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountQuery_0200 + * @tc.name : queryOsAccountById promise + * @tc.desc : Authenticate to get local user 100 information and compare + */ + it('ActsOsAccountQuery_0200', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var osAccountInfo = await osAccountManager.queryOsAccountById(100); + console.debug("====>queryOsAccountById osAccountInfo:" + JSON.stringify(osAccountInfo)); + expect(osAccountInfo.localId).assertEqual(100); + expect(osAccountInfo.type.ADMIN).assertEqual(0); + var serialNumberStr = osAccountInfo.serialNumber.toString(); + var serialIntercept = serialNumberStr.substring(8); + console.debug("====>truncate the last eight characters: " + serialIntercept); + expect(serialIntercept).assertEqual("00000001"); + expect(osAccountInfo.isCreateCompleted).assertTrue(); + console.debug("====>ActsOsAccountQuery_0200 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountQuery_0300 + * @tc.name : queryOsAccountById callback + * @tc.desc : Authenticate failed to obtain local user 0 information + */ + it('ActsOsAccountQuery_0300', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0300 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.queryOsAccountById(0, (err)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + expect(err.code != 0).assertEqual(true); + console.debug("====>ActsOsAccountQuery_0300 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountQuery_0400 + * @tc.name : queryOsAccountById promise + * @tc.desc : Authenticate failed to obtain local user 0 information + */ + it('ActsOsAccountQuery_0400', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0400 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.queryOsAccountById(0); + }catch(err){ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + expect(err.code != 0).assertEqual(true); + console.debug("====>ActsOsAccountQuery_0400 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountQuery_0500 + * @tc.name : queryOsAccountById callback + * @tc.desc : Authenticate failed to obtain local user -1 information + */ + it('ActsOsAccountQuery_0500', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.queryOsAccountById(-1, (err)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + expect(err.code != 0).assertEqual(true); + console.debug("====>ActsOsAccountQuery_0500 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountQuery_0600 + * @tc.name : queryOsAccountById promise + * @tc.desc : Authenticate failed to obtain local user 0 information + */ + it('ActsOsAccountQuery_0600', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.queryOsAccountById(-1); + }catch(err){ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + expect(err.code != 0).assertEqual(true); + console.debug("====>ActsOsAccountQuery_0600 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountQuery_0700 + * @tc.name : queryOsAccountById callback + * @tc.desc : Authenticate failed to obtain local user "100" information + */ + it('ActsOsAccountQuery_0700', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0700 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.queryOsAccountById("100", (err)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + expect(err.code != 0).assertEqual(true); + console.debug("====>ActsOsAccountQuery_0700 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountQuery_0800 + * @tc.name : queryOsAccountById promise + * @tc.desc : Authenticate failed to obtain local user "100" information + */ + it('ActsOsAccountQuery_0800', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0800 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.queryOsAccountById("100"); + }catch(err){ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + expect(err.code != 0).assertEqual(true); + console.debug("====>ActsOsAccountQuery_0800 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountQuery_0900 + * @tc.name : queryOsAccountById callback + * @tc.desc : Authenticate failed to obtain local user undefined information + */ + it('ActsOsAccountQuery_0900', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_0900 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.queryOsAccountById(undefined, (err)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + expect(err.code != 0).assertEqual(true); + console.debug("====>ActsOsAccountQuery_0900 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountQuery_1000 + * @tc.name : queryOsAccountById promise + * @tc.desc : Authenticate failed to obtain local user undefined information + */ + it('ActsOsAccountQuery_1000', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_1000 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.queryOsAccountById(undefined); + }catch(err){ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + expect(err.code != 0).assertEqual(true); + console.debug("====>ActsOsAccountQuery_1000 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountQuery_1100 + * @tc.name : queryAllCreatedOsAccounts callback + * @tc.desc : Verify that all local users contain 100 user + */ + it('ActsOsAccountQuery_1100', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_1100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + let dataMap = new Map(); + osAccountManager.queryAllCreatedOsAccounts((err, data)=>{ + console.debug("====>queryAllCreatedOsAccounts err:" + JSON.stringify(err)); + console.debug("====>queryAllCreatedOsAccounts data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + for (let i = 0, len = data.length; i < len; i++) { + dataMap.set(data[i].localId, data[i].localName) + } + expect(dataMap.has(100)).assertTrue(); + console.debug("====>ActsOsAccountQuery_1100 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountQuery_1200 + * @tc.name : queryAllCreatedOsAccounts promise + * @tc.desc : Verify that all local users contain 100 user + */ + it('ActsOsAccountQuery_1200', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_1200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + let dataMap = new Map(); + var osAccountCreated = await osAccountManager.queryAllCreatedOsAccounts(); + console.debug("====>queryAllCreatedOsAccounts:" + JSON.stringify(osAccountCreated)); + for (let i = 0, len = osAccountCreated.length; i < len; i++) { + dataMap.set(osAccountCreated[i].localId, osAccountCreated[i].localName) + } + expect(dataMap.has(100)).assertTrue(); + console.debug("====>ActsOsAccountQuery_1200 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountQuery_1300 + * @tc.name : queryAllCreatedOsAccounts callback + * @tc.desc : Verify that all local users contain 100 user and created users + */ + it('ActsOsAccountQuery_1300', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_1300 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + let dataMap = new Map(); + osAccountManager.createOsAccount("osAccountNameQueryA", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + createIocalId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameQueryA"); + osAccountManager.queryAllCreatedOsAccounts((err, data)=>{ + console.debug("====>queryAllCreatedOsAccounts err:" + JSON.stringify(err)); + console.debug("====>queryAllCreatedOsAccounts data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + for (let i = 0, len = data.length; i < len; i++) { + dataMap.set(data[i].localId, data[i].localName) + } + expect(dataMap.has(100)).assertTrue(); + expect(dataMap.has(createIocalId)).assertTrue(); + if (dataMap.has(createIocalId)) { + let createdlocalName = dataMap.get(createIocalId); + console.debug("====>query all local users containing localId: " + createIocalId); + console.debug("====>created localName" + createdlocalName); + expect(createdlocalName).assertEqual("osAccountNameQueryA"); + osAccountManager.removeOsAccount(createIocalId, (err)=>{ + console.debug("====>remove localId: " + createIocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountQuery_1300 end===="); + done(); + }) + } + }) + }); + }); + + /* + * @tc.number : ActsOsAccountQuery_1400 + * @tc.name : queryAllCreatedOsAccounts promise + * @tc.desc : Verify that all local users contain 100 user and created users + */ + it('ActsOsAccountQuery_1400', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_1400 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + let dataMap = new Map(); + var osAccountInfo = await osAccountManager.createOsAccount("osAccountNameQueryB", 1); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + createIocalId = osAccountInfo.localId; + expect(osAccountInfo.localName).assertEqual("osAccountNameQueryB"); + var data = await osAccountManager.queryAllCreatedOsAccounts(); + console.debug("====>queryAllCreatedOsAccounts data:" + JSON.stringify(data)); + for (let i = 0, len = data.length; i < len; i++) { + dataMap.set(data[i].localId, data[i].localName) + } + expect(dataMap.has(100)).assertTrue(); + expect(dataMap.has(createIocalId)).assertTrue(); + if (dataMap.has(createIocalId)) { + let createdlocalName = dataMap.get(createIocalId); + console.debug("====>query all local users containing localId: " + createIocalId); + expect(createdlocalName).assertEqual("osAccountNameQueryB"); + } + await osAccountManager.removeOsAccount(createIocalId); + console.debug("====>ActsOsAccountQuery_1400 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountQuery_1500 + * @tc.name : queryMaxOsAccountNumber callback + * @tc.desc : Query the maximum number of users that can be created on the device + */ + it('ActsOsAccountQuery_1500', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_1500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.queryMaxOsAccountNumber((err, data)=>{ + console.debug("====>queryMaxOsAccountNumber err:" + JSON.stringify(err)); + console.debug("====>queryMaxOsAccountNumber data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertEqual(OSACCOUNTMAXNUMBER); + console.debug("====>ActsOsAccountQuery_1500 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountQuery_1600 + * @tc.name : queryMaxOsAccountNumber callback + * @tc.desc : Query the maximum number of users that can be created on the device + */ + it('ActsOsAccountQuery_1600', 0, async function (done) { + console.debug("====>ActsOsAccountQuery_1600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var maxOsAccount = await osAccountManager.queryMaxOsAccountNumber(); + console.debug("====>queryMaxOsAccountNumber:" + maxOsAccount); + expect(maxOsAccount).assertEqual(OSACCOUNTMAXNUMBER); + console.debug("====>ActsOsAccountQuery_1600 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountIsVerified_0100 + * @tc.name : isOsAccountVerified callback + * @tc.desc : create a os account and check whether the initial state of the os account is verified + */ + it('ActsOsAccountIsVerified_0100', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0100 start===="); + var AccountManager = osaccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + var osLocalId; + AccountManager.createOsAccount("OsAccountNameVerfiedA", 1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" +JSON.stringify(err)); + console.debug("====>createOsAccount data:" +JSON.stringify(osAccountInfo)); + osLocalId = osAccountInfo.localId; + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("OsAccountNameVerfiedA"); + AccountManager.isOsAccountVerified(osLocalId, (err, data)=>{ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + console.debug("====>isOsAccountVerified data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data).assertEqual(false); + AccountManager.removeOsAccount(osLocalId, (err)=>{ + console.debug("====>removeOsAccount err:" +JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountIsVerified_0100 end===="); + done(); + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountIsVerified_0200 + * @tc.name : isOsAccountVerified promise + * @tc.desc : create a os account and check whether the initial state of the os account is verified + */ + it('ActsOsAccountIsVerified_0200', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0200 start===="); + var AccountManager = osaccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + var data = await AccountManager.createOsAccount("OsAccountNameVerfiedB", 1); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(data.localName).assertEqual("OsAccountNameVerfiedB"); + var osAccountLocalId = data.localId; + try{ + var data = await AccountManager.isOsAccountVerified(osAccountLocalId); + } + catch(err){ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>isOsAccountVerified data:" + data); + expect(data).assertEqual(false); + await AccountManager.removeOsAccount(osAccountLocalId); + console.debug("====>ActsOsAccountIsVerified_0200 end===="); + done(); + }) +}) \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/signature/openharmony_sx.p7b b/account/osaccount/actsosaccountsystemtest/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/account/osaccount/actsosaccountsystemtest/signature/openharmony_sx.p7b differ diff --git a/account/osaccount/actsosaccountthirdpartytest/BUILD.gn b/account/osaccount/actsosaccountthirdpartytest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..3a9095a448d2f961217e03eee65088ac5f04822c --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/BUILD.gn @@ -0,0 +1,31 @@ +# 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. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsOsAccountThirdPartyTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsOsAccountThirdPartyTest" +} +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "./entry/src/main/js/default" +} +ohos_resources("hjs_demo_resources") { + sources = [ "./entry/src/main/js/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/account/osaccount/actsosaccountthirdpartytest/Test.json b/account/osaccount/actsosaccountthirdpartytest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..888804d48285e74d5ac3f4f9aa17fb3f5311a7bc --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "100000", + "package": "com.example.actsosaccountthirdpartytest", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "ActsOsAccountThirdPartyTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/config.json b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..eadb59a2523d4dff7e17936983b2767312db3977 --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/config.json @@ -0,0 +1,83 @@ +{ + "app": { + "bundleName": "com.example.actsosaccountthirdpartytest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.actsosaccountthirdpartytest", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "defPermissions": [ + { + "availableScope": [], + "grantMode": "system_grant", + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS" + }, + { + "availableScope": [], + "grantMode": "system_grant", + "name": "ohos.permission.DISTRIBUTED_DATASYNC" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS", + "reason": "ceshi" + }, + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC", + "reason": "ceshi" + } + ], + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.actsosaccountthirdpartytest.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/app.js b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..2a68c1992145a976957d7dcdd69a7e9c2e8e9877 --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/app.js @@ -0,0 +1,22 @@ +/* + * 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. + */ +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/i18n/en-US.json b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/i18n/zh-CN.json b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.css b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6724ec055a554cf3f9c7be83780c30df2274875b --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,12 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} +.titleST { + font-size: 32px; +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.hml b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..718ac61d26ea06296527a29ad23d4e6f761865a6 --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,8 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + + + STActsOsAccountThirdPartyTest + +
diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.js b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..ff89334405379439f410d17e635542fecd8be44a --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,45 @@ +/* + * 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. + */ +import file from '@system.file' +import {Core, ExpectExtend} from 'deccjsunit/index' + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/resources/base/element/string.json b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..33e22aa3af86be72867076efc4c950899185b180 --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsAccountTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/resources/base/media/icon.png b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/resources/base/media/icon.png differ diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/List.test.js b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..02ac0b9d860b04bacf2d44b6fe5d8ee1360dcc87 --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/List.test.js @@ -0,0 +1,15 @@ +/* + * 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. + */ +require('./OsAccountIs.test.js') \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountIs.test.js b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountIs.test.js new file mode 100755 index 0000000000000000000000000000000000000000..9991b93521a7f8d22a0f44438ed9cb0854a6822a --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountIs.test.js @@ -0,0 +1,405 @@ +/* + * 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. + */ +import osAccount from '@ohos.account.osAccount' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + + +describe('ActsOsAccountThirdPartyTest', function () { + + /* + * @tc.number : ActsOsAccountDeviceId_0100 + * @tc.name : getDistributedVirtualDeviceId callback + * @tc.desc : get distributed virtual device ID + */ + it('ActsOsAccountDeviceId_0100', 0, async function(done){ + console.debug("====>ActsOsAccountDeviceId_0100 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + AccountManager.getDistributedVirtualDeviceId((err, deviceId)=>{ + console.debug("====>getDistributedVirtualDeviceId err:" + JSON.stringify(err)); + console.debug("====>getDistributedVirtualDeviceId deviceId:" + deviceId); + expect(err.code).assertEqual(0); + expect(deviceId).assertEqual("0"); + console.debug("====>ActsOsAccountDeviceId_0100 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountDeviceId_0200 + * @tc.name : getDistributedVirtualDeviceId promise + * @tc.desc : get distributed virtual device ID + */ + it('ActsOsAccountDeviceId_0200', 0, async function(done){ + console.debug("====>ActsOsAccountDeviceId_0200 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + try{ + var deviceId = await AccountManager.getDistributedVirtualDeviceId(); + } + catch(err){ + console.error("====>catch getDistributedVirtualDeviceId err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>getDistributedVirtualDeviceId:" + deviceId); + expect(deviceId).assertEqual("0"); + console.debug("====>ActsOsAccountDeviceId_0200 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountIsActived_0100 + * @tc.name : isOsAccountActived callback + * @tc.desc : Verify that users are not switched and query 100 users as active + */ + it('ActsOsAccountIsActived_0100', 0, async function(done){ + console.debug("====>ActsOsAccountIsActived_0100 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + AccountManager.isOsAccountActived(100, (err, isActived)=>{ + console.debug("====>isOsAccountActived err:" + JSON.stringify(err)); + console.debug("====>isOsAccountActived isActived:" + isActived); + expect(err.code).assertEqual(0); + expect(isActived).assertEqual(true); + console.debug("====>ActsOsAccountIsActived_0100 end"); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsActived_0200 + * @tc.name : isOsAccountActived promise + * @tc.desc : Verify that users are not switched and query 100 users as active + */ + it('ActsOsAccountIsActived_0200', 0, async function(done){ + console.debug("====>ActsOsAccountIsActived_0200 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + try{ + var isActived = await AccountManager.isOsAccountActived(100); + } + catch(err){ + console.debug("====>catch isOsAccountActived err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>isOsAccountActived:" + isActived); + expect(isActived).assertEqual(true); + console.debug("====>ActsOsAccountIsActived_0200 end"); + done(); + }) + + /* + * @tc.number : ActsOsAccountIsActived_0300 + * @tc.name : isOsAccountActived callback + * @tc.desc : Authentication query 0 user active status failed + */ + it('ActsOsAccountIsActived_0300', 0, async function(done){ + console.debug("====>ActsOsAccountIsActived_0300 start"); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + AccountManager.isOsAccountActived(0, (err)=>{ + console.debug("====>isOsAccountActived err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertEqual(true); + console.debug("====>ActsOsAccountIsActived_0300 end"); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsActived_0400 + * @tc.name : isOsAccountActived promise + * @tc.desc : Authentication query 0 user active status failed + */ + it('ActsOsAccountIsActived_0400', 0, async function(done){ + console.debug("====>isOsAccountActived_0400 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + try{ + await AccountManager.isOsAccountActived(0); + } + catch(err){ + console.debug("====>isOsAccountActived err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertTrue(); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountIsActived_0500 + * @tc.name : isOsAccountActived callback + * @tc.desc : Authentication failed to query the active status of the user that does not exist + */ + it('ActsOsAccountIsActived_0500', 0, async function(done){ + console.debug("====>ActsOsAccountIsActived_0500 start"); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + var nonExistLocalId = 1000; + AccountManager.isOsAccountActived(nonExistLocalId, (err)=>{ + console.debug("====>isOsAccountActived err:" + JSON.stringify(err)); + expect(err.code !=0).assertEqual(true); + console.debug("====>ActsOsAccountIsActived_0500 end"); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsActived_0600 + * @tc.name : isOsAccountActived promise + * @tc.desc : Authentication failed to query the active status of the user that does not exist + */ + it('ActsOsAccountIsActived_0600', 0, async function(done){ + console.debug("====>ActsOsAccountIsActived_0600 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + var nonExistLocalId = 1000; + try{ + await AccountManager.isOsAccountActived(nonExistLocalId); + } + catch(err){ + console.debug("====>isOsAccountActived err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertTrue(); + console.debug("====>ActsOsAccountIsActived_0600 end"); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountIsMulty_0100 + * @tc.name : isMultiOsAccountEnable callback + * @tc.desc : Check whether the function of supporting multiple os account is enabled + */ + it('ActsOsAccountIsMulty_0100', 0, async function(done){ + console.debug("====>ActsOsAccountIsMulty_0100 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + AccountManager.isMultiOsAccountEnable((err, data)=>{ + console.debug("====>isMultiOsAccountEnable err:" + JSON.stringify(err)); + console.debug("====>isMultiOsAccountEnable data:" + data); + expect(err.code).assertEqual(0); + expect(data).assertEqual(true); + console.debug("====>ActsOsAccountIsMulty_0100 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsMulty_0200 + * @tc.name : isMultiOsAccountEnable promise + * @tc.desc : Check whether the function of supporting multiple os account is enabled + */ + it('ActsOsAccountIsMulty_0200', 0, async function(done){ + console.debug("====>ActsOsAccountIsMulty_0200 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + try{ + var data = await AccountManager.isMultiOsAccountEnable(); + } + catch(err){ + console.debug("====>catch isMultiOsAccountEnable err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>isMultiOsAccountEnable data:" + JSON.stringify(data)); + expect(data).assertEqual(true); + console.debug("====>ActsOsAccountIsMulty_0200 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountIsVerified_0300 + * @tc.name : isOsAccountVerified callback + * @tc.desc : Verify query 0 user is unlocked failed + */ + it('ActsOsAccountIsVerified_0300', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0300 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + AccountManager.isOsAccountVerified(0, (err)=>{ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertEqual(true); + console.debug("====>ActsOsAccountIsVerified_0300 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsVerified_0400 + * @tc.name : isOsAccountVerified promise + * @tc.desc : Verify query 0 user is unlocked failed + */ + it('ActsOsAccountIsVerified_0400', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0400 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + try{ + await AccountManager.isOsAccountVerified(0); + } + catch(err){ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertTrue(); + console.debug("====>ActsOsAccountIsVerified_0400 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountIsVerified_0500 + * @tc.name : isOsAccountVerified callback + * @tc.desc : Verify query "100" user is unlocked failed + */ + it('ActsOsAccountIsVerified_0500', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0500 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + AccountManager.isOsAccountVerified("100", (err)=>{ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertEqual(true); + console.debug("====>ActsOsAccountIsVerified_0500 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsVerified_0600 + * @tc.name : isOsAccountVerified promise + * @tc.desc : Verify query "100" user is unlocked failed + */ + it('ActsOsAccountIsVerified_0600', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0600 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + try{ + await AccountManager.isOsAccountVerified("100"); + } + catch(err){ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertTrue(); + console.debug("====>ActsOsAccountIsVerified_0600 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountIsVerified_0700 + * @tc.name : isOsAccountVerified callback + * @tc.desc : Verify query undefined user is unlocked failed + */ + it('ActsOsAccountIsVerified_0700', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0700 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + AccountManager.isOsAccountVerified(undefined, (err)=>{ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertEqual(true); + console.debug("====>ActsOsAccountIsVerified_0700 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsVerified_0800 + * @tc.name : isOsAccountVerified promise + * @tc.desc : Verify query undefined user is unlocked failed + */ + it('ActsOsAccountIsVerified_0800', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0800 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + try{ + await AccountManager.isOsAccountVerified(undefined); + } + catch(err){ + console.debug("====>ActsOsAccountIsVerified_0800 err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertTrue(); + console.debug("====>ActsOsAccountIsVerified_0800 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountIsVerified_0900 + * @tc.name : isOsAccountVerified callback + * @tc.desc : Verify query does not exist user unlock failed + */ + it('ActsOsAccountIsVerified_0900', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_0900 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + var osAccountLocalId = 1000; + AccountManager.isOsAccountVerified(osAccountLocalId, (err)=>{ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertEqual(true); + console.debug("====>ActsOsAccountIsVerified_0900 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsVerified_1000 + * @tc.name : isOsAccountVerified promise + * @tc.desc : Verify query does not exist user unlock failed + */ + it('ActsOsAccountIsVerified_1000', 0, async function(done){ + console.debug("====>ActsOsAccountIsVerified_1000 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + var osAccountLocalId = 1000; + try{ + await AccountManager.isOsAccountVerified(osAccountLocalId); + } + catch(err){ + console.debug("====>isOsAccountVerified err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertTrue(); + console.debug("====>ActsOsAccountIsVerified_1000 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountIsTest_0100 + * @tc.name : isTestOsAccount callback + * @tc.desc : check whether this OS account is a test OS account + */ + it('ActsOsAccountIsTest_0100', 0, async function(done){ + console.debug("====>ActsOsAccountIsTest_0100 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + AccountManager.isTestOsAccount((err, data)=>{ + console.debug("====>isTestOsAccount err:" + JSON.stringify(err)); + console.debug("====>isTestOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data).assertEqual(false); + console.debug("====>ActsOsAccountIsTest_0100 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountIsTest_0200 + * @tc.name : isTestOsAccount promise + * @tc.desc : check whether this OS account is a test OS account + */ + it('ActsOsAccountIsTest_0200', 0, async function(done){ + console.debug("====>ActsOsAccountIsTest_0200 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get os AccountManager finish===="); + var isTest = await AccountManager.isTestOsAccount(); + expect(isTest).assertFalse(); + console.debug("====>ActsOsAccountIsTest_0200 end===="); + done(); + }) +}) \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/signature/openharmony_sx.p7b b/account/osaccount/actsosaccountthirdpartytest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..f06e218defa7f707e22a3890903c574e1c498217 Binary files /dev/null and b/account/osaccount/actsosaccountthirdpartytest/signature/openharmony_sx.p7b differ