From fd6169f7281c67a97e53cee91d8eadd805d92f7d Mon Sep 17 00:00:00 2001 From: gaoxi785 Date: Fri, 21 Jan 2022 17:05:26 +0800 Subject: [PATCH] Update account xts case and fix appaccount bug Signed-off-by: gaoxi785 --- .../appaccount/actsaccountpressure/Test.json | 2 +- .../src/main/js/test/NoPermission.test.js | 4 +- .../entry/src/main/js/test/OnOff.js | 21 +- .../actsosaccountsystemtest/Test.json | 2 +- .../entry/src/main/js/test/Activate.test.js | 2 +- .../src/main/js/test/Constraints.test.js | 1093 +++++++++++++++++ .../entry/src/main/js/test/Create.test.js | 616 ++++++++++ .../entry/src/main/js/test/List.test.js | 6 +- .../entry/src/main/js/test/OnOff.test.js | 102 +- .../entry/src/main/js/test/Photo.test.js | 189 +++ .../entry/src/main/js/test/Query.test.js | 2 +- .../entry/src/main/js/test/Set.test.js | 774 ++++++++++++ .../actsosaccountthirdpartytest/Test.json | 2 +- .../src/main/js/default/pages/index/index.js | 1 + .../entry/src/main/js/test/List.test.js | 3 +- .../src/main/js/test/OsAccountGet.test.js | 469 +++++++ .../src/main/js/test/OsAccountIs.test.js | 4 +- 17 files changed, 3227 insertions(+), 65 deletions(-) create mode 100755 account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Constraints.test.js create mode 100755 account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Create.test.js create mode 100755 account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Photo.test.js create mode 100755 account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Set.test.js create mode 100755 account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountGet.test.js diff --git a/account/appaccount/actsaccountpressure/Test.json b/account/appaccount/actsaccountpressure/Test.json index 479500b35..6a464d872 100755 --- a/account/appaccount/actsaccountpressure/Test.json +++ b/account/appaccount/actsaccountpressure/Test.json @@ -2,7 +2,7 @@ "description": "Configuration for hjunit demo Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "3000000", + "test-timeout": "1500000", "package": "com.example.actsaccountpressure", "shell-timeout": "60000" }, diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/NoPermission.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/NoPermission.test.js index 1cdcfe266..31e419a4c 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/NoPermission.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/NoPermission.test.js @@ -189,7 +189,7 @@ describe('ActsAccountNoPermission', function () { console.debug("====>ActsAccountNoPermission_0700 start===="); var appAccountManager = account.createAppAccountManager(); console.debug("====>creat finish===="); - var selfBundle = "com.example.actsaccountnopermission"; + var selfBundle = "com.example.actsaccounttest"; appAccountManager.addAccount("getAll_callback_nopermission", (err)=>{ console.debug("====>add account 0700 err:" + JSON.stringify(err)); expect(err.code).assertEqual(0); @@ -215,7 +215,7 @@ describe('ActsAccountNoPermission', function () { console.debug("====>ActsAccountNoPermission_0800 start===="); var appAccountManager = account.createAppAccountManager(); console.debug("====>creat finish===="); - var selfBundle = "com.example.actsaccountnopermission"; + var selfBundle = "com.example.actsaccounttest"; console.debug("====>add account 0800 start===="); await appAccountManager.addAccount("getAll_promise_nopermission"); console.debug("====>getAllAccounts 0800 start===="); diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js index 563310551..c2c32ab9d 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js @@ -655,16 +655,19 @@ describe('ActsAccountChangeOnOff', async function () { expect(data).assertEqual("com.example.actsaccounttest"); } twiceSign = twiceSign + 1; - appAccountManager.off('change', function (){ - console.debug("====>off ActsAccountChangeOnOff_1000 finish===="); - appAccountManager.deleteAccount("onoff_twice", (err)=>{ - console.debug("====>delete account ActsAccountChangeOnOff_1000 err:" + JSON.stringify(err)); - expect(err.code).assertEqual(0); - expect(twiceSign).assertEqual(2); - console.debug("====>ActsAccountChangeOnOff_1000 end===="); - done(); + setTimeout(async function (){ + console.debug("====>off start===="); + appAccountManager.off('change', function (){ + console.debug("====>off ActsAccountChangeOnOff_1000 finish===="); + appAccountManager.deleteAccount("onoff_twice", (err)=>{ + console.debug("====>delete account ActsAccountChangeOnOff_1000 err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + expect(twiceSign).assertEqual(2); + console.debug("====>ActsAccountChangeOnOff_1000 end===="); + done(); + }); }); - }); + }, 1000) } try{ appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnFirstCallback); diff --git a/account/osaccount/actsosaccountsystemtest/Test.json b/account/osaccount/actsosaccountsystemtest/Test.json index e3b0d3326..062835828 100755 --- a/account/osaccount/actsosaccountsystemtest/Test.json +++ b/account/osaccount/actsosaccountsystemtest/Test.json @@ -2,7 +2,7 @@ "description": "Configuration for hjunit demo Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "300000", + "test-timeout": "800000", "package": "com.example.actsosaccountsystemtest", "shell-timeout": "60000" }, 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 index fbd2adb23..a89585532 100755 --- a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Activate.test.js +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Activate.test.js @@ -16,7 +16,7 @@ import osaccount from '@ohos.account.osAccount' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' const TIMEOUT = 1000; -const ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR = 4587571; +const ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR = 4587574; describe('ActsOsAccountSystemTest', function () { /* diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Constraints.test.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Constraints.test.js new file mode 100755 index 000000000..5c7583351 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Constraints.test.js @@ -0,0 +1,1093 @@ +/* + * 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 : ActsOsAccountConstraints_0100 + * @tc.name : Constraints callback + * @tc.desc : get 100 local user all constraints + */ + it('ActsOsAccountConstraints_0100', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0100 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var adminConstraints = ["constraint.wifi","constraint.wifi.set","constraint.locale.set", + "constraint.app.accounts","constraint.apps.install","constraint.apps.uninstall","constraint.location.shared", + "constraint.unknown.sources.install","constraint.global.unknown.app.install","constraint.bluetooth.set", + "constraint.bluetooth"]; + AccountManager.getOsAccountAllConstraints(100, (err, constraints)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(constraints)); + expect(err.code).assertEqual(0); + expect(constraints.length).assertEqual(adminConstraints.length); + var succeed = 0, failed = 0; + for(var j = 0; jthe number of constraints obtained:" + succeed); + console.debug("====>number of constraints not fetched:" + failed); + if(failed == 0){ + console.debug("====>ActsOsAccountConstraints_0100 end===="); + done(); + } + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_0200 + * @tc.name : Constraints promise + * @tc.desc : get 100 local user all constraints + */ + it('ActsOsAccountConstraints_0200', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0200 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var adminConstraints = ["constraint.wifi","constraint.wifi.set","constraint.locale.set", + "constraint.app.accounts","constraint.apps.install","constraint.apps.uninstall","constraint.location.shared", + "constraint.unknown.sources.install","constraint.global.unknown.app.install","constraint.bluetooth.set", + "constraint.bluetooth"]; + var constraints = await AccountManager.getOsAccountAllConstraints(100); + console.debug("====>getAccountManager constraints:" + JSON.stringify(constraints)); + expect(constraints.length).assertEqual(adminConstraints.length); + var succeed = 0, failed = 0; + for(var j = 0; jthe number of constraints obtained:" + succeed); + console.debug("====>number of constraints not fetched:" + failed); + if(failed == 0){ + console.debug("====>ActsOsAccountConstraints_0100 end===="); + done(); + } + console.debug("====>ActsOsAccountConstraints_0200 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountConstraints_0300 + * @tc.name : Constraints callback + * @tc.desc : get 0 local user all constraints + */ + it('ActsOsAccountConstraints_0300', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0300 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + AccountManager.getOsAccountAllConstraints(0, (err, constraints)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(constraints)); + expect(err.code).assertEqual(0); + expect(constraints.length).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_0300 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_0400 + * @tc.name : Constraints promise + * @tc.desc : get 0 local user all constraints + */ + it('ActsOsAccountConstraints_0400', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0400 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var constraints = await AccountManager.getOsAccountAllConstraints(0); + console.debug("====>getAccountManager constraints:" +JSON.stringify(constraints)); + expect(constraints.length).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_0400 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountConstraints_0500 + * @tc.name : Constraints callback + * @tc.desc : create and add constraints + */ + it('ActsOsAccountConstraints_0500', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0500 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.isOsAccountConstraintEnable(localId, "constraint.location.set", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertFalse(); + AccountManager.setOsAccountConstraints(localId, ["constraint.location.set"], true, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + AccountManager.isOsAccountConstraintEnable(localId, "constraint.location.set", (err, constraint)=>{ + console.debug("====>twice isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>twice isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertTrue(); + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_0500 end===="); + done(); + }) + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_0600 + * @tc.name : Constraints promise + * @tc.desc : create and add constraints + */ + it('ActsOsAccountConstraints_0600', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0600 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + var constraint = await AccountManager.isOsAccountConstraintEnable(localId, "constraint.location.set"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertFalse(); + try{ + await AccountManager.setOsAccountConstraints(localId, ["constraint.location.set"], true); + } + catch(err){ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + var constraintTwice = await AccountManager.isOsAccountConstraintEnable(localId, "constraint.location.set"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraintTwice); + expect(constraintTwice).assertTrue(); + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_0600 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountConstraints_0700 + * @tc.name : Constraints callback + * @tc.desc : create and delete constraints + */ + it('ActsOsAccountConstraints_0700', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0700 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.isOsAccountConstraintEnable(localId, "constraint.bluetooth.set", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertTrue(); + AccountManager.setOsAccountConstraints(localId, ["constraint.bluetooth.set"], false, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + AccountManager.isOsAccountConstraintEnable(localId, "constraint.bluetooth.set", (err, constraint)=>{ + console.debug("====>twice isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>twice isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertFalse(); + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_0700 end===="); + done(); + }) + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_0800 + * @tc.name : Constraints promise + * @tc.desc : create and delete constraints + */ + it('ActsOsAccountConstraints_0800', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0800 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + var constraint = await AccountManager.isOsAccountConstraintEnable(localId, "constraint.bluetooth.set"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertTrue(); + await AccountManager.setOsAccountConstraints(localId, ["constraint.bluetooth.set"], false); + var constraintTwice = await AccountManager.isOsAccountConstraintEnable(localId, "constraint.bluetooth.set"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraintTwice); + expect(constraintTwice).assertFalse(); + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_0800 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountConstraints_0900 + * @tc.name : Constraints callback + * @tc.desc : add the same constraints consecutively + */ + it('ActsOsAccountConstraints_0900', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_0900 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.isOsAccountConstraintEnable(localId, "constraint.location.set", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertFalse(); + AccountManager.setOsAccountConstraints(localId, ["constraint.location.set"], true, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + AccountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>getOsAccountAllConstraints :" + JSON.stringify(constraints)); + expect(err.code).assertEqual(0); + let result = constraints.includes("constraint.location.set"); + expect(result).assertTrue(); + AccountManager.setOsAccountConstraints(localId, ["constraint.location.set"], true, (err)=>{ + console.debug("====>twice setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + AccountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{ + console.debug("====>twice getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>twice getOsAccountAllConstraints :" + JSON.stringify(constraints)); + expect(err.code).assertEqual(0); + let result = constraints.includes("constraint.location.set"); + expect(result).assertTrue(); + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_0900 end===="); + done(); + }) + }) + }) + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_1000 + * @tc.name : Constraints promise + * @tc.desc : add the same constraints consecutively + */ + it('ActsOsAccountConstraints_1000', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1000 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + var constraint = await AccountManager.isOsAccountConstraintEnable(localId, "constraint.location.set"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertFalse(); + await AccountManager.setOsAccountConstraints(localId, ["constraint.location.set"], true); + var constraints = await AccountManager.getOsAccountAllConstraints(localId); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(constraints)); + let result = constraints.includes("constraint.location.set"); + expect(result).assertTrue(); + await AccountManager.setOsAccountConstraints(localId, ["constraint.location.set"], true); + var constraints = await AccountManager.getOsAccountAllConstraints(localId); + console.debug("====>twice getOsAccountAllConstraints:" + JSON.stringify(constraints)); + let result1 = constraints.includes("constraint.location.set"); + expect(result1).assertTrue(); + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_1000 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountConstraints_1100 + * @tc.name : Constraints callback + * @tc.desc : delete the same constraints consecutively + */ + it('ActsOsAccountConstraints_1100', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1100 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.isOsAccountConstraintEnable(localId, "constraint.network.reset", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertTrue(); + AccountManager.setOsAccountConstraints(localId, ["constraint.network.reset"], false, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + AccountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>getOsAccountAllConstraints :" + JSON.stringify(constraints)); + expect(err.code).assertEqual(0); + var number = 0; + for(var i=0; i < constraints.length; i++){ + if(constraints[i] != "constraint.network.reset"){ + number++; + } + } + if(number == constraints.length-1){ + expect().assertTrue(); + } + AccountManager.setOsAccountConstraints(localId, ["constraint.network.reset"], false, (err)=>{ + console.debug("====>twice setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + AccountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{ + console.debug("====>twice getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>twice getOsAccountAllConstraints :" + JSON.stringify(constraints)); + expect(err.code).assertEqual(0); + var numberTwo = 0; + for(var i=0; i < constraints.length; i++){ + if(constraints[i] != "constraint.network.reset"){ + numberTwo++; + } + } + if(numberTwo == constraints.length-1){ + expect().assertTrue(); + } + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_1100 end===="); + done(); + }) + }) + }) + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_1200 + * @tc.name : Constraints promise + * @tc.desc : delete the same constraints consecutively + */ + it('ActsOsAccountConstraints_1200', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1200 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + var constraint = await AccountManager.isOsAccountConstraintEnable(localId, "constraint.network.reset"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertTrue(); + await AccountManager.setOsAccountConstraints(localId, ["constraint.network.reset"], false); + var constraints = await AccountManager.getOsAccountAllConstraints(localId); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(constraints)); + var number = 0; + for(var i=0; i < constraints.length; i++){ + if(constraints[i] != "constraint.network.reset"){ + number++; + } + } + if(number == constraints.length-1){ + expect().assertTrue(); + } + await AccountManager.setOsAccountConstraints(localId, ["constraint.network.reset"], false); + var constraints = await AccountManager.getOsAccountAllConstraints(localId); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(constraints)); + var numberTwo = 0; + for(var i=0; i < constraints.length; i++){ + if(constraints[i] != "constraint.network.reset"){ + numberTwo++; + } + } + if(numberTwo == constraints.length-1){ + expect().assertTrue(); + } + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_1200 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountConstraints_1300 + * @tc.name : Constraints callback + * @tc.desc : to add a constraint not in the constraint list + */ + it('ActsOsAccountConstraints_1300', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1300 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + AccountManager.isOsAccountConstraintEnable(100, "constraint.undefined", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertFalse(); + AccountManager.setOsAccountConstraints(100, ["constraint.undefined"], true, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code != 0 ).assertTrue(); + console.debug("====>ActsOsAccountConstraints_1300 end===="); + done(); + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_1400 + * @tc.name : Constraints promise + * @tc.desc : to add a constraint not in the constraint list + */ + it('ActsOsAccountConstraints_1400', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1400 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var constraint = await AccountManager.isOsAccountConstraintEnable(100, "constraint.undefined"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertFalse(); + try{ + await AccountManager.setOsAccountConstraints(100, ["constraint.undefined"], true); + } + catch(err){ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountConstraints_1400 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountConstraints_1500 + * @tc.name : Constraints callback + * @tc.desc : to add constraint is empty string and not in constraint list + */ + it('ActsOsAccountConstraints_1500', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1500 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + AccountManager.isOsAccountConstraintEnable(100, "", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertFalse(); + AccountManager.setOsAccountConstraints(100, [""], true, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code != 0 ).assertTrue(); + console.debug("====>ActsOsAccountConstraints_1500 end===="); + done(); + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_1600 + * @tc.name : Constraints promise + * @tc.desc : to add constraint is empty string and not in constraint list + */ + it('ActsOsAccountConstraints_1600', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1600 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var constraint = await AccountManager.isOsAccountConstraintEnable(100, ""); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertFalse(); + try{ + await AccountManager.setOsAccountConstraints(100, [""], true); + } + catch(err){ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountConstraints_1600 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountConstraints_1700 + * @tc.name : Constraints callback + * @tc.desc : to delete a constraint not in the constraint list + */ + it('ActsOsAccountConstraints_1700', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1700 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + AccountManager.isOsAccountConstraintEnable(100, "constraint.undefined", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertFalse(); + AccountManager.setOsAccountConstraints(100, ["constraint.undefined"], false, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code != 0 ).assertTrue(); + console.debug("====>ActsOsAccountConstraints_1700 end===="); + done(); + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_1800 + * @tc.name : Constraints promise + * @tc.desc : to delete a constraint not in the constraint list + */ + it('ActsOsAccountConstraints_1800', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1800 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var constraint = await AccountManager.isOsAccountConstraintEnable(100, "constraint.undefined"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertFalse(); + try{ + await AccountManager.setOsAccountConstraints(100, ["constraint.undefined"], false); + } + catch(err){ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountConstraints_1800 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountConstraints_1900 + * @tc.name : Constraints callback + * @tc.desc : add constraints, whether in the constraint list or not in the constraint list + */ + it('ActsOsAccountConstraints_1900', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_1900 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.isOsAccountConstraintEnable(localId, "constraint.device.unmute", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertFalse(); + AccountManager.setOsAccountConstraints(localId, ["constraint.device.unmute", + "constraint.undefined"], true, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_1900 end===="); + done(); + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_2000 + * @tc.name : Constraints promise + * @tc.desc : add constraints, whether in the constraint list or not in the constraint list + */ + it('ActsOsAccountConstraints_2000', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2000 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + var constraint = await AccountManager.isOsAccountConstraintEnable(localId, "constraint.device.unmute"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertFalse(); + try{ + await AccountManager.setOsAccountConstraints(localId, ["constraint.device.unmute", + "constraint.undefined"], true); + } + catch(err){ + console.debug("====>setOsAccountConstraints:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_2000 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountConstraints_2100 + * @tc.name : Constraints callback + * @tc.desc : delete constraints, whether in the constraint list or not in the constraint list + */ + it('ActsOsAccountConstraints_2100', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2100 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.isOsAccountConstraintEnable(localId, "constraint.cell.broadcasts.set", (err, constraint)=>{ + console.debug("====>isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.debug("====>isOsAccountConstraintEnable constraint:" + constraint); + expect(err.code).assertEqual(0); + expect(constraint).assertTrue(); + AccountManager.setOsAccountConstraints(localId, ["constraint.cell.broadcasts.set", + "constraint.undefined"], false, (err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_2100 end===="); + done(); + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_2200 + * @tc.name : Constraints promise + * @tc.desc : delete constraints, whether in the constraint list or not in the constraint list + */ + it('ActsOsAccountConstraints_2200', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2200 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + var constraint = await AccountManager.isOsAccountConstraintEnable(localId, "constraint.device.unmute"); + console.debug("====>isOsAccountConstraintEnable constraints:" + constraint); + expect(constraint).assertFalse(); + try{ + await AccountManager.setOsAccountConstraints(localId, ["constraint.device.unmute", + "constraint.undefined"], true); + } + catch(err){ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code !=0 ).assertTrue(); + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_2200 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountConstraints_2300 + * @tc.name : Constraints callback + * @tc.desc : create a local user of type normal and get all constraints + */ + it('ActsOsAccountConstraints_2300', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2300 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var normalConstraint = ["constraint.global.unknown.app.install","constraint.bluetooth.set", + "constraint.bluetooth","constraint.bluetooth.share","constraint.usb.file.transfer","constraint.credentials.set", + "constraint.os.account.remove","constraint.managed.profile.remove","constraint.debug.features.use", + "constraint.vpn.set","constraint.date.time.set","constraint.tethering.config","constraint.network.reset", + "constraint.factory.reset","constraint.os.account.create","constraint.add.managed.profile", + "constraint.apps.verify.disable","constraint.cell.broadcasts.set"]; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.getOsAccountAllConstraints(localId, (err, allConstraints)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(allConstraints)); + expect(err.code).assertEqual(0); + expect(allConstraints.length).assertEqual(normalConstraint.length); + var succeed = 0, failed = 0; + for(var j = 0; jthe number of constraints obtained:" + succeed); + console.debug("====>number of constraints not fetched:" + failed); + if(failed == 0){ + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_2300 end===="); + done(); + }) + }else{ + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + expect().assertFail(); + console.debug("====>ActsOsAccountConstraints_2300 end===="); + done(); + }) + } + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_2400 + * @tc.name : Constraints promise + * @tc.desc : create a local user of type normal and get all constraints + */ + it('ActsOsAccountConstraints_2400', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2400 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var normalConstraint = ["constraint.global.unknown.app.install","constraint.bluetooth.set", + "constraint.bluetooth","constraint.bluetooth.share","constraint.usb.file.transfer","constraint.credentials.set", + "constraint.os.account.remove","constraint.managed.profile.remove","constraint.debug.features.use", + "constraint.vpn.set","constraint.date.time.set","constraint.tethering.config","constraint.network.reset", + "constraint.factory.reset","constraint.os.account.create","constraint.add.managed.profile", + "constraint.apps.verify.disable","constraint.cell.broadcasts.set"]; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + var allConstraints = await AccountManager.getOsAccountAllConstraints(localId); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(allConstraints)); + expect(allConstraints.length).assertEqual(normalConstraint.length); + var succeed = 0, failed = 0; + for(var j = 0; jthe number of constraints obtained:" + succeed); + console.debug("====>number of constraints not fetched:" + failed); + if(failed == 0){ + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_2400 end===="); + done(); + }else{ + await AccountManager.removeOsAccount(localId); + expect().assertFail(); + console.debug("====>ActsOsAccountConstraints_2400 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountConstraints_2500 + * @tc.name : Constraints callback + * @tc.desc : create a local user of type guest and get all constraints + */ + it('ActsOsAccountConstraints_2500', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2500 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var guestConstraints = ["constraint.tethering.config","constraint.network.reset","constraint.factory.reset", + "constraint.os.account.create","constraint.add.managed.profile","constraint.apps.verify.disable", + "constraint.cell.broadcasts.set","constraint.mobile.networks.set","constraint.control.apps", + "constraint.physical.media","constraint.microphone","constraint.microphone.unmute","constraint.volume.adjust", + "constraint.calls.outgoing","constraint.sms.use"]; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.GUEST, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.getOsAccountAllConstraints(localId, (err, allConstraints)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(allConstraints)); + expect(err.code).assertEqual(0); + expect(allConstraints.length).assertEqual(guestConstraints.length); + var succeed = 0, failed = 0; + for(var j = 0; jthe number of constraints obtained:" + succeed); + console.debug("====>number of constraints not fetched:" + failed); + if(failed == 0){ + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_2500 end===="); + done(); + }) + }else{ + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + expect().assertFail(); + console.debug("====>ActsOsAccountConstraints_2500 end===="); + done(); + }) + } + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_2600 + * @tc.name : Constraints promise + * @tc.desc : create a local user of type guest and get all constraints + */ + it('ActsOsAccountConstraints_2600', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2600 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var guestConstraints = ["constraint.tethering.config","constraint.network.reset","constraint.factory.reset", + "constraint.os.account.create","constraint.add.managed.profile","constraint.apps.verify.disable", + "constraint.cell.broadcasts.set","constraint.mobile.networks.set","constraint.control.apps", + "constraint.physical.media","constraint.microphone","constraint.microphone.unmute","constraint.volume.adjust", + "constraint.calls.outgoing","constraint.sms.use"]; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.GUEST); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + var allConstraints = await AccountManager.getOsAccountAllConstraints(localId); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(allConstraints)); + expect(allConstraints.length).assertEqual(guestConstraints.length); + var succeed = 0, failed = 0; + for(var j = 0; jthe number of constraints obtained:" + succeed); + console.debug("====>number of constraints not fetched:" + failed); + if(failed == 0){ + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_2600 end===="); + done(); + }else{ + await AccountManager.removeOsAccount(localId); + expect().assertFail(); + console.debug("====>ActsOsAccountConstraints_2600 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountConstraints_2700 + * @tc.name : Constraints callback + * @tc.desc : get all constrain information of non-existing local users + */ + it('ActsOsAccountConstraints_2700', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2700 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var nonExistentLocalId = 1000; + AccountManager.getOsAccountAllConstraints(nonExistentLocalId, (err)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountConstraints_2700 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_2800 + * @tc.name : Constraints promise + * @tc.desc : get all constrain information of non-existing local users + */ + it('ActsOsAccountConstraints_2800', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2800 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var nonExistentLocalId = 1000; + try{ + await AccountManager.getOsAccountAllConstraints(nonExistentLocalId); + } + catch(err){ + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(err)); + expect(err.code != 0).assertTrue(); + console.debug("====>ActsOsAccountConstraints_2800 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountConstraints_2900 + * @tc.name : Constraints callback + * @tc.desc : create a normal type local user,add all constraints and delete two constraints + */ + it('ActsOsAccountConstraints_2900', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_2900 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var addallConstraints = ["constraint.wifi","constraint.wifi.set","constraint.locale.set", + "constraint.app.accounts","constraint.apps.install","constraint.apps.uninstall","constraint.location.shared", + "constraint.unknown.sources.install","constraint.global.unknown.app.install","constraint.bluetooth.set", + "constraint.bluetooth","constraint.bluetooth.share","constraint.usb.file.transfer","constraint.credentials.set", + "constraint.os.account.remove","constraint.managed.profile.remove","constraint.debug.features.use", + "constraint.vpn.set","constraint.date.time.set","constraint.tethering.config","constraint.network.reset", + "constraint.factory.reset","constraint.os.account.create","constraint.add.managed.profile", + "constraint.apps.verify.disable","constraint.cell.broadcasts.set","constraint.mobile.networks.set", + "constraint.control.apps","constraint.physical.media","constraint.microphone","constraint.microphone.unmute", + "constraint.volume.adjust","constraint.calls.outgoing","constraint.sms.use","constraint.fun", + "constraint.windows.create","constraint.system.error.dialogs","constraint.cross.profile.copy.paste", + "constraint.beam.outgoing","constraint.wallpaper","constraint.safe.boot", + "constraint.parent.profile.app.linking","constraint.audio.record","constraint.camera.use", + "constraint.os.account.background.run","constraint.data.roam","constraint.os.account.set.icon", + "constraint.wallpaper.set","constraint.oem.unlock","constraint.device.unmute","constraint.password.unified", + "constraint.autofill","constraint.content.capture","constraint.content.suggestions", + "constraint.os.account.start","constraint.location.set","constraint.airplane.mode.set", + "constraint.brightness.set","constraint.share.into.profile","constraint.ambient.display", + "constraint.screen.timeout.set","constraint.print","constraint.private.dns.set"]; + AccountManager.createOsAccount('NameConstraintsC', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("NameConstraintsC"); + localId = data.localId; + AccountManager.setOsAccountConstraints(localId, addallConstraints, true,(err)=>{ + console.debug("====>setOsAccountConstraints err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + AccountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(constraints)); + expect(err.code).assertEqual(0); + expect(constraints.length).assertEqual(63); + AccountManager.setOsAccountConstraints(localId, ["constraint.print", + "constraint.private.dns.set"], false, (err)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + AccountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{ + console.debug("====>getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.debug("====>getOsAccountAllConstraints:" + JSON.stringify(constraints)); + expect(err.code).assertEqual(0); + expect(constraints.length).assertEqual(61); + AccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountConstraints_2900 end===="); + done(); + }) + }) + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountConstraints_3000 + * @tc.name : Constraints promise + * @tc.desc : create a normal type local user,add all constraints and delete two constraints + */ + it('ActsOsAccountConstraints_3000', 0, async function(done){ + console.debug("====>ActsOsAccountConstraints_3000 start===="); + var AccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var addallConstraints = ["constraint.wifi","constraint.wifi.set","constraint.locale.set", + "constraint.app.accounts","constraint.apps.install","constraint.apps.uninstall","constraint.location.shared", + "constraint.unknown.sources.install","constraint.global.unknown.app.install","constraint.bluetooth.set", + "constraint.bluetooth","constraint.bluetooth.share","constraint.usb.file.transfer","constraint.credentials.set", + "constraint.os.account.remove","constraint.managed.profile.remove","constraint.debug.features.use", + "constraint.vpn.set","constraint.date.time.set","constraint.tethering.config","constraint.network.reset", + "constraint.factory.reset","constraint.os.account.create","constraint.add.managed.profile", + "constraint.apps.verify.disable","constraint.cell.broadcasts.set","constraint.mobile.networks.set", + "constraint.control.apps","constraint.physical.media","constraint.microphone","constraint.microphone.unmute", + "constraint.volume.adjust","constraint.calls.outgoing","constraint.sms.use","constraint.fun", + "constraint.windows.create","constraint.system.error.dialogs","constraint.cross.profile.copy.paste", + "constraint.beam.outgoing","constraint.wallpaper","constraint.safe.boot", + "constraint.parent.profile.app.linking","constraint.audio.record","constraint.camera.use", + "constraint.os.account.background.run","constraint.data.roam","constraint.os.account.set.icon", + "constraint.wallpaper.set","constraint.oem.unlock","constraint.device.unmute","constraint.password.unified", + "constraint.autofill","constraint.content.capture","constraint.content.suggestions", + "constraint.os.account.start","constraint.location.set","constraint.airplane.mode.set", + "constraint.brightness.set","constraint.share.into.profile","constraint.ambient.display", + "constraint.screen.timeout.set","constraint.print","constraint.private.dns.set"]; + var info = await AccountManager.createOsAccount("NameConstraintsP", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("NameConstraintsP"); + localId = info.localId; + await AccountManager.setOsAccountConstraints(localId, addallConstraints, true); + console.debug("====>add allConstraints finish===="); + var constraints = await AccountManager.getOsAccountAllConstraints(localId); + console.debug("====>getAccountManager constraints:" +JSON.stringify(constraints)); + expect(constraints.length).assertEqual(63); + await AccountManager.setOsAccountConstraints(localId, ["constraint.print", + "constraint.private.dns.set"], false); + var constraints = await AccountManager.getOsAccountAllConstraints(localId); + console.debug("====>getAccountManager constraints:" +JSON.stringify(constraints)); + expect(constraints.length).assertEqual(61); + await AccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountConstraints_3000 end===="); + done(); + }) + +}) \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Create.test.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Create.test.js new file mode 100755 index 000000000..8b3b44e92 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Create.test.js @@ -0,0 +1,616 @@ +/* + * 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 ERR_OS_ACCOUNT_KIT_CREATE_OS_ACCOUNT_ERROR = 4587526; +const ERR_OSACCOUNT_KIT_REMOVE_OSACCOUNT_ERROR = 4587532; +const ERR_OSACCOUNT_KIT_LOCAL_NAME_EMPTY_ERROR = 4587581; +const ERR_OSACCOUNT_KIT_CANNOT_DELETE_ID_ERROR = 4587584; +describe('ActsOsAccountSystemTest', function () { + + /* + * @tc.number : ActsOsAccountCreate_0100 + * @tc.name : createOsAccount callback + * @tc.desc : Authenticate to create a local user of type normal + */ + it('ActsOsAccountCreate_0100', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var createIdStr; + let dataMap = new Map(); + osAccountManager.createOsAccount("osAccountNameCreateA", osaccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + createIocalId = osAccountInfo.localId; + createIdStr = createIocalId.toString(); + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameCreateA"); + 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++) { + console.debug("====>contain localId:" + data[i].localId); + dataMap.set(data[i].localId.toString(), data[i]) + } + expect(dataMap.has("100")).assertTrue(); + expect(dataMap.has(createIdStr)).assertTrue(); + if (dataMap.has(createIdStr)) { + let OsAccountInfo = dataMap.get(createIdStr); + console.debug("====>query all local users containing: " + JSON.stringify(OsAccountInfo)); + expect(OsAccountInfo.localName).assertEqual("osAccountNameCreateA"); + expect(OsAccountInfo.type.NORMAL).assertEqual(1); + expect(OsAccountInfo.isActived).assertFalse(); + osAccountManager.removeOsAccount(createIocalId, (err)=>{ + console.debug("====>remove localId: " + createIocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountCreate_0100 end===="); + done(); + }) + } + }) + }); + }); + + /* + * @tc.number : ActsOsAccountCreate_0200 + * @tc.name : createOsAccount promise + * @tc.desc : Authenticate to create a local user of type normal + */ + it('ActsOsAccountCreate_0200', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var createIdStr; + let dataMap = new Map(); + var osAccount = await osAccountManager.createOsAccount("osAccountNameCreateB", osaccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccount)); + createIocalId = osAccount.localId; + createIdStr = createIocalId.toString(); + expect(osAccount.localName).assertEqual("osAccountNameCreateB"); + var data = await osAccountManager.queryAllCreatedOsAccounts(); + console.debug("====>queryAllCreatedOsAccounts data:" + JSON.stringify(data)); + for (let i = 0, len = data.length; i < len; i++) { + console.debug("====>contain localId:" + data[i].localId); + dataMap.set(data[i].localId.toString(), data[i]) + } + expect(dataMap.has("100")).assertTrue(); + expect(dataMap.has(createIdStr)).assertTrue(); + if (dataMap.has(createIdStr)) { + let OsAccountInfo = dataMap.get(createIdStr); + console.debug("====>query all local users containing: " + JSON.stringify(OsAccountInfo)); + expect(OsAccountInfo.localName).assertEqual("osAccountNameCreateB"); + expect(OsAccountInfo.type.NORMAL).assertEqual(1); + expect(OsAccountInfo.isActived).assertFalse(); + } + await osAccountManager.removeOsAccount(createIocalId); + console.debug("====>ActsOsAccountCreate_0200 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountCreate_0300 + * @tc.name : createOsAccount callback + * @tc.desc : Authenticate to create a local user of type guest + */ + it('ActsOsAccountCreate_0300', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0300 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var createIdStr; + let dataMap = new Map(); + osAccountManager.createOsAccount("osAccountNameCreateC", osaccount.OsAccountType.GUEST, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + createIocalId = osAccountInfo.localId; + createIdStr = createIocalId.toString(); + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameCreateC"); + 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++) { + console.debug("====>contain localId:" + data[i].localId); + dataMap.set(data[i].localId.toString(), data[i]) + } + expect(dataMap.has("100")).assertTrue(); + expect(dataMap.has(createIdStr)).assertTrue(); + if (dataMap.has(createIdStr)) { + let OsAccountInfo = dataMap.get(createIdStr); + console.debug("====>query all local users containing: " + JSON.stringify(OsAccountInfo)); + expect(OsAccountInfo.localName).assertEqual("osAccountNameCreateC"); + expect(OsAccountInfo.type.GUEST).assertEqual(2); + expect(OsAccountInfo.isActived).assertFalse(); + osAccountManager.removeOsAccount(createIocalId, (err)=>{ + console.debug("====>remove localId: " + createIocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountCreate_0300 end===="); + done(); + }) + } + }) + }); + }); + + /* + * @tc.number : ActsOsAccountCreate_0400 + * @tc.name : createOsAccount promise + * @tc.desc : Authenticate to create a local user of type guest + */ + it('ActsOsAccountCreate_0400', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0400 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var createIdStr; + let dataMap = new Map(); + var osAccount = await osAccountManager.createOsAccount("osAccountNameCreateD", osaccount.OsAccountType.GUEST); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccount)); + createIocalId = osAccount.localId; + createIdStr = createIocalId.toString(); + expect(osAccount.localName).assertEqual("osAccountNameCreateD"); + var data = await osAccountManager.queryAllCreatedOsAccounts(); + console.debug("====>queryAllCreatedOsAccounts data:" + JSON.stringify(data)); + for (let i = 0, len = data.length; i < len; i++) { + console.debug("====>contain localId:" + data[i].localId); + dataMap.set(data[i].localId.toString(), data[i]) + } + expect(dataMap.has("100")).assertTrue(); + expect(dataMap.has(createIdStr)).assertTrue(); + if (dataMap.has(createIdStr)) { + let OsAccountInfo = dataMap.get(createIdStr); + console.debug("====>query all local users containing: " + JSON.stringify(OsAccountInfo)); + expect(OsAccountInfo.localName).assertEqual("osAccountNameCreateD"); + expect(OsAccountInfo.type.GUEST).assertEqual(2); + expect(OsAccountInfo.isActived).assertFalse(); + } + await osAccountManager.removeOsAccount(createIocalId); + console.debug("====>ActsOsAccountCreate_0400 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountCreate_0500 + * @tc.name : createOsAccount callback + * @tc.desc : Authenticate to create a local user of type admin + */ + it('ActsOsAccountCreate_0500', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var createIdStr; + let dataMap = new Map(); + osAccountManager.createOsAccount("osAccountNameCreateE", osaccount.OsAccountType.ADMIN, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + createIocalId = osAccountInfo.localId; + createIdStr = createIocalId.toString(); + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameCreateE"); + 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++) { + console.debug("====>contain localId:" + data[i].localId); + dataMap.set(data[i].localId.toString(), data[i]) + } + expect(dataMap.has("100")).assertTrue(); + expect(dataMap.has(createIdStr)).assertTrue(); + if (dataMap.has(createIdStr)) { + let OsAccountInfo = dataMap.get(createIdStr); + console.debug("====>query all local users containing: " + JSON.stringify(OsAccountInfo)); + expect(OsAccountInfo.localName).assertEqual("osAccountNameCreateE"); + expect(OsAccountInfo.type.ADMIN).assertEqual(0); + expect(OsAccountInfo.isActived).assertFalse(); + osAccountManager.removeOsAccount(createIocalId, (err)=>{ + console.debug("====>remove localId: " + createIocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountCreate_0500 end===="); + done(); + }) + } + }) + }); + }); + + /* + * @tc.number : ActsOsAccountCreate_0600 + * @tc.name : createOsAccount promise + * @tc.desc : Authenticate to create a local user of type admin + */ + it('ActsOsAccountCreate_0600', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var createIdStr; + let dataMap = new Map(); + var osAccount = await osAccountManager.createOsAccount("osAccountNameCreateF", osaccount.OsAccountType.ADMIN); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccount)); + createIocalId = osAccount.localId; + createIdStr = createIocalId.toString(); + expect(osAccount.localName).assertEqual("osAccountNameCreateF"); + var data = await osAccountManager.queryAllCreatedOsAccounts(); + console.debug("====>queryAllCreatedOsAccounts data:" + JSON.stringify(data)); + for (let i = 0, len = data.length; i < len; i++) { + console.debug("====>contain localId:" + data[i].localId); + dataMap.set(data[i].localId.toString(), data[i]) + } + expect(dataMap.has("100")).assertTrue(); + expect(dataMap.has(createIdStr)).assertTrue(); + if (dataMap.has(createIdStr)) { + let OsAccountInfo = dataMap.get(createIdStr); + console.debug("====>query all local users containing: " + JSON.stringify(OsAccountInfo)); + expect(OsAccountInfo.localName).assertEqual("osAccountNameCreateF"); + expect(OsAccountInfo.type.ADMIN).assertEqual(0); + expect(OsAccountInfo.isActived).assertFalse(); + } + await osAccountManager.removeOsAccount(createIocalId); + console.debug("====>ActsOsAccountCreate_0600 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountCreate_0700 + * @tc.name : createOsAccount callback + * @tc.desc : Verify that the created user name is empty + */ + it('ActsOsAccountCreate_0700', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0700 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.createOsAccount("", osaccount.OsAccountType.ADMIN, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_LOCAL_NAME_EMPTY_ERROR); + console.debug("====>ActsOsAccountCreate_0700 end===="); + done(); + }); + }); + + /* + * @tc.number : ActsOsAccountCreate_0800 + * @tc.name : createOsAccount promise + * @tc.desc : Verify that the created user name is empty + */ + it('ActsOsAccountCreate_0800', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0800 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.createOsAccount("", osaccount.OsAccountType.ADMIN); + }catch(err){ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_LOCAL_NAME_EMPTY_ERROR); + console.debug("====>ActsOsAccountCreate_0800 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountCreate_0900 + * @tc.name : removeOsAccount callback + * @tc.desc : Authenticate to delete the specified local user + */ + it('ActsOsAccountCreate_0900', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_0900 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var createIdStr; + let dataMap = new Map(); + osAccountManager.createOsAccount("osAccountNameCreateG", osaccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + createIocalId = osAccountInfo.localId; + createIdStr = createIocalId.toString(); + expect(err.code).assertEqual(0); + expect(osAccountInfo.localName).assertEqual("osAccountNameCreateG"); + osAccountManager.removeOsAccount(createIocalId, (err)=>{ + console.debug("====>remove localId: " + createIocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + 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++) { + console.debug("====>contain localId:" + data[i].localId); + dataMap.set(data[i].localId.toString(), data[i]) + } + expect(dataMap.has("100")).assertTrue(); + expect(dataMap.has(createIdStr)).assertFalse(); + console.debug("====>ActsOsAccountCreate_0900 end===="); + done(); + }) + }) + }); + }); + + /* + * @tc.number : ActsOsAccountCreate_1000 + * @tc.name : removeOsAccount promise + * @tc.desc : Authenticate to delete the specified local user + */ + it('ActsOsAccountCreate_1000', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1000 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var createIdStr; + let dataMap = new Map(); + var osAccount = await osAccountManager.createOsAccount("osAccountNameCreateH", osaccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccount)); + createIocalId = osAccount.localId; + createIdStr = createIocalId.toString(); + expect(osAccount.localName).assertEqual("osAccountNameCreateH"); + await osAccountManager.removeOsAccount(createIocalId); + console.debug("====>remove localId: " + createIocalId); + var data = await osAccountManager.queryAllCreatedOsAccounts(); + console.debug("====>queryAllCreatedOsAccounts data:" + JSON.stringify(data)); + for (let i = 0, len = data.length; i < len; i++) { + console.debug("====>contain localId:" + data[i].localId); + dataMap.set(data[i].localId.toString(), data[i]) + } + expect(dataMap.has("100")).assertTrue(); + expect(dataMap.has(createIdStr)).assertFalse(); + console.debug("====>ActsOsAccountCreate_1000 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountCreate_1100 + * @tc.name : removeOsAccount callback + * @tc.desc : Verify duplicate removal of the same local user + */ + it('ActsOsAccountCreate_1100', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + osAccountManager.createOsAccount("osAccountNameCreateI", osaccount.OsAccountType.NORMAL, (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("osAccountNameCreateI"); + osAccountManager.removeOsAccount(createIocalId, (err)=>{ + console.debug("====>remove localId: " + createIocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.removeOsAccount(createIocalId, (err)=>{ + console.debug("====>remove localId: " + createIocalId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_REMOVE_OSACCOUNT_ERROR); + console.debug("====>ActsOsAccountCreate_1100 end===="); + done(); + }) + }) + }); + }); + + /* + * @tc.number : ActsOsAccountCreate_1200 + * @tc.name : removeOsAccount promise + * @tc.desc : Verify duplicate removal of the same local user + */ + it('ActsOsAccountCreate_1200', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var createIocalId; + var osAccount = await osAccountManager.createOsAccount("osAccountNameCreateA", osaccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccount)); + createIocalId = osAccount.localId; + expect(osAccount.localName).assertEqual("osAccountNameCreateA"); + await osAccountManager.removeOsAccount(createIocalId); + console.debug("====>remove localId: " + createIocalId); + try{ + await osAccountManager.removeOsAccount(createIocalId); + }catch(err){ + console.debug("====>remove localId: " + createIocalId + " err: " + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_REMOVE_OSACCOUNT_ERROR); + console.debug("====>ActsOsAccountCreate_1200 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountCreate_1300 + * @tc.name : removeOsAccount callback + * @tc.desc : Validation cannot delete 0 user + */ + it('ActsOsAccountCreate_1300', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1300 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId = 0; + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_CANNOT_DELETE_ID_ERROR); + console.debug("====>ActsOsAccountCreate_1300 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountCreate_1400 + * @tc.name : removeOsAccount promise + * @tc.desc : Validation cannot delete 0 user + */ + it('ActsOsAccountCreate_1400', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1400 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId = 0; + try{ + await osAccountManager.removeOsAccount(localId); + }catch(err){ + console.debug("====>remove localId: " + localId + " err: " + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_CANNOT_DELETE_ID_ERROR); + console.debug("====>ActsOsAccountCreate_1400 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountCreate_1500 + * @tc.name : removeOsAccount callback + * @tc.desc : Validation cannot delete 100 user + */ + it('ActsOsAccountCreate_1500', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId = 100; + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_CANNOT_DELETE_ID_ERROR); + console.debug("====>ActsOsAccountCreate_1500 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountCreate_1600 + * @tc.name : removeOsAccount promise + * @tc.desc : Validation cannot delete 100 user + */ + it('ActsOsAccountCreate_1600', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId = 100; + try{ + await osAccountManager.removeOsAccount(localId); + }catch(err){ + console.debug("====>remove localId: " + localId + " err: " + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_CANNOT_DELETE_ID_ERROR); + console.debug("====>ActsOsAccountCreate_1600 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountCreate_1700 + * @tc.name : createOsAccount callback + * @tc.desc : Authentication failed to create user with parameter type not matching + */ + it('ActsOsAccountCreate_1700', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1700 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.createOsAccount("osAccountNameCreateA", -1, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + expect(err.code).assertEqual(ERR_OS_ACCOUNT_KIT_CREATE_OS_ACCOUNT_ERROR); + console.debug("====>ActsOsAccountCreate_1700 end===="); + done(); + }); + }); + + /* + * @tc.number : ActsOsAccountCreate_1800 + * @tc.name : createOsAccount promise + * @tc.desc : Authentication failed to create user with parameter type not matching + */ + it('ActsOsAccountCreate_1800', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1800 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.createOsAccount("osAccountNameCreateA", -1); + }catch(err){ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OS_ACCOUNT_KIT_CREATE_OS_ACCOUNT_ERROR); + console.debug("====>ActsOsAccountCreate_1800 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountCreate_1900 + * @tc.name : createOsAccount callback + * @tc.desc : Authentication failed to create user with parameter type mismatch + */ + it('ActsOsAccountCreate_1900', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_1900 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.createOsAccount("osAccountNameCreateA", 3, (err, osAccountInfo)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + expect(err.code).assertEqual(ERR_OS_ACCOUNT_KIT_CREATE_OS_ACCOUNT_ERROR); + console.debug("====>ActsOsAccountCreate_1900 end===="); + done(); + }); + }); + + /* + * @tc.number : ActsOsAccountCreate_2000 + * @tc.name : createOsAccount promise + * @tc.desc : Authentication failed to create user with parameter type mismatch + */ + it('ActsOsAccountCreate_2000', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_2000 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.createOsAccount("osAccountNameCreateA", 3); + }catch(err){ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OS_ACCOUNT_KIT_CREATE_OS_ACCOUNT_ERROR); + console.debug("====>ActsOsAccountCreate_2000 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountCreate_2100 + * @tc.name : createOsAccount + * @tc.desc : Verify that the user localId can be reused and the user serialNumber is not + */ + it('ActsOsAccountCreate_2100', 0, async function (done) { + console.debug("====>ActsOsAccountCreate_2100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var OsAccountInfo = await osAccountManager.createOsAccount("nameCreateSerial", osaccount.OsAccountType.NORMAL); + console.debug("====>first createOsAccount OsAccountInfo:" + JSON.stringify(OsAccountInfo)); + console.debug("====>createTime: " + OsAccountInfo.createTime); + console.debug("====>lastLoginTime: " + OsAccountInfo.lastLoginTime); + console.debug("====>serialNumber: " + OsAccountInfo.serialNumber); + console.debug("====>domainInfo: " + OsAccountInfo.domainInfo); + var localIdFir = OsAccountInfo.localId; + var serialNumFir = OsAccountInfo.serialNumber; + expect(OsAccountInfo.localName).assertEqual("nameCreateSerial"); + console.debug("====>remove os account start===="); + await osAccountManager.removeOsAccount(localIdFir); + var accountInfoSec = await osAccountManager.createOsAccount("nameCreateSerial", osaccount.OsAccountType.NORMAL); + console.debug("====>second createOsAccount OsAccountInfo:" + JSON.stringify(accountInfoSec)); + var localIdSec = accountInfoSec.localId; + var serialNumSec = accountInfoSec.serialNumber; + console.debug("====>first create localId: " + localIdFir + " second create localId: " + localIdSec); + console.debug("====>first create serialNumber: " + serialNumFir + " second serialNumber: " + serialNumSec); + expect(localIdFir).assertEqual(localIdSec); + var serialNumAdd = serialNumFir + 1; + expect(serialNumAdd).assertEqual(serialNumSec); + console.debug("====>ActsOsAccountCreate_2100 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 index faef68495..79211bf27 100755 --- a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/List.test.js +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/List.test.js @@ -14,4 +14,8 @@ */ require('./Query.test.js') require('./Activate.test.js') -require('./OnOff.test.js') \ No newline at end of file +require('./OnOff.test.js') +require('./Set.test.js') +require('./Constraints.test.js') +require('./Photo.test.js') +require('./Create.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 index b4a853c71..65328de69 100755 --- a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/OnOff.test.js +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/OnOff.test.js @@ -25,47 +25,6 @@ describe('ActsOsAccountSystemTest', function () { } } - /* - * @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 @@ -217,7 +176,7 @@ describe('ActsOsAccountSystemTest', function () { setTimeout(()=>{ console.debug("====>ActsOsAccountOnOff_0500 end===="); done(); - }, TIMEOUT); + }, TIMEOUT); }); /* @@ -271,6 +230,7 @@ describe('ActsOsAccountSystemTest', function () { osAccountManager.activateOsAccount(localId, (err)=>{ console.debug("====>activateOsAccount errcode:" + JSON.stringify(err)); expect(err.code).assertEqual(0); + sleep(TIMEOUT); setTimeout(()=>{ osAccountManager.removeOsAccount(localId, (err)=>{ console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); @@ -714,7 +674,7 @@ describe('ActsOsAccountSystemTest', function () { setTimeout(()=>{ console.debug("====>ActsOsAccountOnOff_1700 end===="); done(); - }, TIMEOUT); + }, TIMEOUT); }); /* @@ -735,7 +695,7 @@ describe('ActsOsAccountSystemTest', function () { setTimeout(()=>{ console.debug("====>ActsOsAccountOnOff_1800 end===="); done(); - }, TIMEOUT); + }, TIMEOUT); }); /* @@ -756,7 +716,59 @@ describe('ActsOsAccountSystemTest', function () { setTimeout(()=>{ console.debug("====>ActsOsAccountOnOff_1900 end===="); done(); - }, TIMEOUT); + }, TIMEOUT); }); + /* + * @tc.number : ActsOsAccountOnOff_2000 + * @tc.name : Subscribe and unsubscribing local multi-user + * @tc.desc : Authenticate switch back after switching user subscription receives two callbacks + */ + it('ActsOsAccountOnOff_2000', 0, async function (done) { + console.debug("====>ActsOsAccountOnOff_2000 start===="); + var osAccountManager = osaccount.getAccountManager(); + var localId; + var enterSign = 0; + var localHundredId = 100; + console.debug("====>get AccountManager finish===="); + function onCallback(receiveLocalId){ + console.debug("====>receive localId:" + receiveLocalId); + if(receiveLocalId == localId){ + enterSign = enterSign + 1; + } + if(receiveLocalId == localHundredId){ + enterSign = enterSign + 1; + osAccountManager.off("activate", "osAccountOnOffNameQ", 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("====>the enterSign is: " + enterSign); + expect(enterSign).assertEqual(2); + console.debug("====>ActsOsAccountOnOff_2000 end===="); + done(); + }) + } + osAccountManager.on("activate", "osAccountOnOffNameQ", onCallback); + sleep(TIMEOUT); + osAccountManager.createOsAccount("osAccountNameQ", 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("osAccountNameQ"); + osAccountManager.activateOsAccount(localId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.activateOsAccount(localHundredId, (err)=>{ + console.debug("====>activateOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + }); + }); + }); + }) + }) \ No newline at end of file diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Photo.test.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Photo.test.js new file mode 100755 index 000000000..b241f2758 --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Photo.test.js @@ -0,0 +1,189 @@ +/* + * 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 TIMEOUT = 1000; +const ERR_OSACCOUNT_KIT_GET_OS_ACCOUNT_PROFILE_PHOTO_ERROR = 4587558; +describe('ActsOsAccountSystemTest', function () { + + /* + * @tc.number : ActsOsAccountProfilePhoto_0100 + * @tc.name : getOsAccountProfilePhoto callback + * @tc.desc : Verify that the newly created user photo is an empty string + */ + it('ActsOsAccountProfilePhoto_0100', 0, async function (done) { + console.debug("====>ActsOsAccountProfilePhoto_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + osAccountManager.createOsAccount("osAccountNameIdSerialC", osaccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>create os account err: " + JSON.stringify(err)); + console.debug("====>create os account OsAccountInfo: " + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("osAccountNameIdSerialC"); + localId = data.localId; + osAccountManager.getOsAccountProfilePhoto(localId, (err, photo)=>{ + console.debug("====>getOsAccountProfilePhoto err:" + JSON.stringify(err)); + console.debug("====>get photo:" + photo + " by localId: " + localId); + expect(err.code).assertEqual(0); + expect(photo).assertEqual(""); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountProfilePhoto_0100 end===="); + done(); + }) + + }) + }) + }); + + /* + * @tc.number : ActsOsAccountProfilePhoto_0200 + * @tc.name : getOsAccountProfilePhoto promise + * @tc.desc : Verify that the newly created user photo is an empty string + */ + it('ActsOsAccountProfilePhoto_0200', 0, async function (done) { + console.debug("====>ActsOsAccountProfilePhoto_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var data = await osAccountManager.createOsAccount("osAccountNameIdSerialD", osaccount.OsAccountType.NORMAL); + console.debug("====>create os account OsAccountInfo: " + JSON.stringify(data)); + expect(data.localName).assertEqual("osAccountNameIdSerialD"); + localId = data.localId; + var photo = await osAccountManager.getOsAccountProfilePhoto(localId); + console.debug("====>get photo:" + photo + " by localId: " + localId); + expect(photo).assertEqual(""); + await osAccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountProfilePhoto_0200 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountProfilePhoto_0300 + * @tc.name : getOsAccountProfilePhoto callback + * @tc.desc : Verify to ger the photo of the user that does not exist + */ + it('ActsOsAccountProfilePhoto_0300', 0, async function (done) { + console.debug("====>ActsOsAccountProfilePhoto_0300 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var nonExistentId = 1000; + osAccountManager.getOsAccountProfilePhoto(nonExistentId, (err)=>{ + console.debug("====>getOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_GET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountProfilePhoto_0300 end===="); + done(); + }) + }); + + /* + * @tc.number : ActsOsAccountProfilePhoto_0400 + * @tc.name : getOsAccountProfilePhoto promise + * @tc.desc : Verify to get the photo of the user that does not exist + */ + it('ActsOsAccountProfilePhoto_0400', 0, async function (done) { + console.debug("====>ActsOsAccountProfilePhoto_0400 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var nonExistentId = 1000; + try{ + await osAccountManager.getOsAccountProfilePhoto(nonExistentId); + }catch(err){ + console.debug("====>getOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_GET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountProfilePhoto_0400 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountProfilePhoto_0500 + * @tc.name : getOsAccountProfilePhoto callback + * @tc.desc : Verify to get photo with parameter type mismatch + */ + it('ActsOsAccountProfilePhoto_0500', 0, async function (done) { + console.debug("====>ActsOsAccountProfilePhoto_0500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localIdStr = "100"; + function gerPhotoCallback(err, data){ + console.debug("====>getOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + osAccountManager.getOsAccountProfilePhoto(localIdStr, gerPhotoCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountProfilePhoto_0500 end===="); + done(); + }, TIMEOUT); + }); + + /* + * @tc.number : ActsOsAccountProfilePhoto_0600 + * @tc.name : getOsAccountProfilePhoto promise + * @tc.desc : Verify to the get photo with parameter type mismatch + */ + it('ActsOsAccountProfilePhoto_0600', 0, async function (done) { + console.debug("====>ActsOsAccountProfilePhoto_0600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localIdStr = "100"; + var data = await osAccountManager.getOsAccountProfilePhoto(localIdStr); + expect(data).assertEqual(null); + console.debug("====>ActsOsAccountProfilePhoto_0600 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountProfilePhoto_0700 + * @tc.name : getOsAccountProfilePhoto callback + * @tc.desc : Verify to get photo with parameter undefined + */ + it('ActsOsAccountProfilePhoto_0700', 0, async function (done) { + console.debug("====>ActsOsAccountProfilePhoto_0700 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var undefinedId = undefined; + function gerPhotoCallback(err, data){ + console.debug("====>getOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + osAccountManager.getOsAccountProfilePhoto(undefinedId,gerPhotoCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountProfilePhoto_0700 end===="); + done(); + }, TIMEOUT); + }); + + /* + * @tc.number : ActsOsAccountProfilePhoto_0800 + * @tc.name : getOsAccountProfilePhoto promise + * @tc.desc : Verify to get photo with parameter undefined + */ + it('ActsOsAccountProfilePhoto_0800', 0, async function (done) { + console.debug("====>ActsOsAccountProfilePhoto_0800 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var undefinedId = undefined; + var data = await osAccountManager.getOsAccountProfilePhoto(undefinedId); + expect(data).assertEqual(null); + console.debug("====>ActsOsAccountProfilePhoto_0800 end===="); + done(); + }); +}) \ 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 index 5540a6895..7358ed1b3 100755 --- a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Query.test.js +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Query.test.js @@ -17,7 +17,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 1000; const OSACCOUNTMAXNUMBER = 999; -const ERR_OSACCOUNT_KIT_QUERY_OS_ACCOUNT_BY_ID_ERROR = 4587554; +const ERR_OSACCOUNT_KIT_QUERY_OS_ACCOUNT_BY_ID_ERROR = 4587556; describe('ActsOsAccountSystemTest', function () { /* diff --git a/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Set.test.js b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Set.test.js new file mode 100755 index 000000000..1ff3d827c --- /dev/null +++ b/account/osaccount/actsosaccountsystemtest/entry/src/main/js/test/Set.test.js @@ -0,0 +1,774 @@ +/* + * 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 TIMEOUT = 1000; +const ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_NAME_ERROR = 4587564; +const ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR = 4587566; +describe('ActsOsAccountSystemTest', function () { + + /* + * @tc.number : ActsOsAccountSet_0100 + * @tc.name : setOsAccountName callback + * @tc.desc : Set the local name of the os account based on the localId + */ + it('ActsOsAccountSet_0100', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0100 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + osAccountManager.createOsAccount("osAccountNameSetA", osAccount.OsAccountType.NORMAL, (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("osAccountNameSetA"); + osAccountManager.setOsAccountName(localId, "Abc", (err)=>{ + console.debug("====>setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.queryOsAccountById(localId, (err, info)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + console.debug("====>queryOsAccountById info:" + JSON.stringify(info)); + expect(err.code).assertEqual(0); + expect(info.localName).assertEqual("Abc"); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountSet_0100 end===="); + done(); + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountSet_0200 + * @tc.name : setOsAccountName promise + * @tc.desc : Set the local name of the os account based on the localId + */ + it('ActsOsAccountSet_0200', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0200 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var osAccountInfo = await osAccountManager.createOsAccount("osAccountNameSetB", osAccount.OsAccountType.NORMAL); + console.debug("====>createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + localId = osAccountInfo.localId; + expect(osAccountInfo.localName).assertEqual("osAccountNameSetB"); + await osAccountManager.setOsAccountName(localId, "Abc"); + var getInfo = await osAccountManager.queryOsAccountById(localId); + console.debug("====>queryOsAccountById info:" + JSON.stringify(getInfo)); + expect(getInfo.localName).assertEqual("Abc"); + await osAccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountSet_0200 end===="); + done(); + }) + + + /* + * @tc.number : ActsOsAccountSet_0300 + * @tc.name : setOsAccountName callback + * @tc.desc : Authentication failed to set local name for 0 user + */ + it('ActsOsAccountSet_0300', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0300 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.setOsAccountName(0, "Abc", (err)=>{ + console.debug("====>setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_NAME_ERROR); + console.debug("====>ActsOsAccountSet_0300 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountSet_0400 + * @tc.name : setOsAccountName promise + * @tc.desc : Authentication failed to set local name for 0 user + */ + it('ActsOsAccountSet_0400', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0400 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.setOsAccountName(0, "Abc"); + } + catch(err){ + console.debug("====>catch setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_NAME_ERROR); + console.debug("====>ActsOsAccountSet_0400 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountSet_0500 + * @tc.name : setOsAccountName callback + * @tc.desc : Authentication failed to set local name for -1 user + */ + it('ActsOsAccountSet_0500', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0500 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.setOsAccountName(-1, "Abc", (err)=>{ + console.debug("====>setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_NAME_ERROR); + console.debug("====>ActsOsAccountSet_0500 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountSet_0600 + * @tc.name : setOsAccountName promise + * @tc.desc : Authentication failed to set local name for -1 user + */ + it('ActsOsAccountSet_0600', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0600 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.setOsAccountName(-1, "Abc"); + } + catch(err){ + console.debug("====>catch setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_NAME_ERROR); + console.debug("====>ActsOsAccountSet_0600 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountSet_0700 + * @tc.name : setOsAccountName callback + * @tc.desc : Authentication failed to set local name for "100" user + */ + it('ActsOsAccountSet_0700', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0700 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + function funcSetNameCallback(err){ + console.debug("====>setOsAccountName err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + osAccountManager.setOsAccountName("100", "Abc", funcSetNameCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountSet_0700 end===="); + done(); + }, TIMEOUT); + }) + + /* + * @tc.number : ActsOsAccountSet_0800 + * @tc.name : setOsAccountName promise + * @tc.desc : Authentication failed to set local name for "100" user + */ + it('ActsOsAccountSet_0800', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0800 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var result = await osAccountManager.setOsAccountName("100", "Abc"); + console.debug("====>catch setOsAccountName err:" + JSON.stringify(result)); + expect(result).assertEqual(null); + console.debug("====>ActsOsAccountSet_0800 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountSet_0900 + * @tc.name : setOsAccountName callback + * @tc.desc : Authentication failed to set local name for undefined user + */ + it('ActsOsAccountSet_0900', 0, async function (done) { + console.debug("====>ActsOsAccountSet_0900 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + function funcSetNameCallback(err){ + console.debug("====>setOsAccountName err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + osAccountManager.setOsAccountName(undefined, "Abc", funcSetNameCallback); + setTimeout(()=>{ + console.debug("====>ActsOsAccountSet_0900 end===="); + done(); + }, TIMEOUT); + }) + + /* + * @tc.number : ActsOsAccountSet_1000 + * @tc.name : setOsAccountName promise + * @tc.desc : Authentication failed to set local name for undefined user + */ + it('ActsOsAccountSet_1000', 0, async function (done) { + console.debug("====>ActsOsAccountSet_1000 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var result = await osAccountManager.setOsAccountName(undefined, "Abc"); + console.debug("====>catch setOsAccountName err:" + JSON.stringify(result)); + expect(result).assertEqual(null); + console.debug("====>ActsOsAccountSet_1000 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountSet_1100 + * @tc.name : setOsAccountName callback + * @tc.desc : Verify that the same username is set repeatedly + */ + it('ActsOsAccountSet_1100', 0, async function(done){ + console.debug("====>ActsOsAccountSet_1100 start===="); + var osAccountManager = osAccount.getAccountManager(); + var localId; + osAccountManager.createOsAccount('localName_callback', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("localName_callback"); + localId = data.localId; + osAccountManager.setOsAccountName(localId, "localName_callback", (err)=>{ + console.debug("====>setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.setOsAccountName(localId, "localName_callback", (err)=>{ + console.debug("====>twice setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.queryOsAccountById(localId, (err,info)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + console.debug("====>queryOsAccountById data:" +JSON.stringify(info)); + expect(err.code).assertEqual(0); + expect(info.localName).assertEqual("localName_callback"); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountSet_1100 end===="); + done(); + }) + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountSet_1200 + * @tc.name : setOsAccountName promise + * @tc.desc : Verify that the same username is set repeatedly + */ + it('ActsOsAccountSet_1200', 0, async function (done) { + console.debug("====>ActsOsAccountSet_1200 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + try{ + var info = await osAccountManager.createOsAccount("localName_promise", osAccount.OsAccountType.NORMAL); + } + catch(err){ + console.debug("====>catch createOsAccount err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("localName_promise"); + localId = info.localId + try{ + await osAccountManager.setOsAccountName(localId, "localName_promise"); + } + catch(err){ + console.debug("====>catch setOsAccountName err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + try{ + await osAccountManager.setOsAccountName(localId, "localName_promise"); + } + catch(err){ + console.debug("====>catch twice setOsAccountName err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + try{ + var info = await osAccountManager.queryOsAccountById(localId); + } + catch(err){ + console.debug("====>catch queryOsAccountById err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>queryOsAccountById info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("localName_promise"); + await osAccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountSet_1200 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountSet_1300 + * @tc.name : setOsAccountName callback + * @tc.desc : Verify repeated settings with different username + */ + it('ActsOsAccountSet_1300', 0, async function(done){ + console.debug("====>ActsOsAccountSet_1300 start===="); + var osAccountManager = osAccount.getAccountManager(); + var localId; + osAccountManager.createOsAccount('localName_callback', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("localName_callback"); + localId = data.localId; + osAccountManager.setOsAccountName(localId, "localName_callback", (err)=>{ + console.debug("====>setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.setOsAccountName(localId, "localName_callbackTwice", (err)=>{ + console.debug("====>twice setOsAccountName err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.queryOsAccountById(localId, (err,info)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + console.debug("====>queryOsAccountById data:" +JSON.stringify(info)); + expect(err.code).assertEqual(0); + expect(info.localName).assertEqual("localName_callbackTwice"); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountSet_1300 end===="); + done(); + }) + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountSet_1400 + * @tc.name : setOsAccountName promise + * @tc.desc : Verify repeated settings with different username + */ + it('ActsOsAccountSet_1400', 0, async function (done) { + console.debug("====>ActsOsAccountSet_1400 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + try{ + var info = await osAccountManager.createOsAccount("localName_promise", osAccount.OsAccountType.NORMAL); + } + catch(err){ + console.debug("====>catch createOsAccount err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("localName_promise"); + localId = info.localId + try{ + await osAccountManager.setOsAccountName(localId, "localName_promise"); + } + catch(err){ + console.debug("====>catch setOsAccountName err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + try{ + await osAccountManager.setOsAccountName(localId, "localName_promiseTwice"); + } + catch(err){ + console.debug("====>catch setOsAccountName err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + try{ + var info = await osAccountManager.queryOsAccountById(localId); + } + catch(err){ + console.debug("====>catch twice queryOsAccountById err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>queryOsAccountById info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("localName_promiseTwice"); + await osAccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountSet_1400 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountSet_1500 + * @tc.name : setOsAccountName callback + * @tc.desc : create and set profile photo the base64 image converted from png image + */ + it('ActsOsAccountSet_1500', 0, async function(done){ + console.debug("====>ActsOsAccountSet_1500 start===="); + var osAccountManager = osAccount.getAccountManager(); + var localId; + var photo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA"+ + "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+ + "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+ + "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==" + osAccountManager.createOsAccount('localNamePhotoPng_callback', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("localNamePhotoPng_callback"); + localId = data.localId; + osAccountManager.setOsAccountProfilePhoto(localId, photo, (err)=>{ + console.debug("====>setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.queryOsAccountById(localId, (err,info)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + console.debug("====>queryOsAccountById data:" +JSON.stringify(info)); + expect(err.code).assertEqual(0); + expect(info.photo).assertEqual(photo); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountSet_1500 end===="); + done(); + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountSet_1600 + * @tc.name : setOsAccountName promise + * @tc.desc : create and set profile photo the base64 image converted from png image + */ + it('ActsOsAccountSet_1600', 0, async function (done) { + console.debug("====>ActsOsAccountSet_1600 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var photo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA"+ + "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+ + "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+ + "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==" + try{ + var info = await osAccountManager.createOsAccount("localPhotoPng_promise", osAccount.OsAccountType.NORMAL); + } + catch(err){ + console.debug("====>catch createOsAccount err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("localPhotoPng_promise"); + localId = info.localId + try{ + await osAccountManager.setOsAccountProfilePhoto(localId, photo); + } + catch(err){ + console.debug("====>catch setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + try{ + var info = await osAccountManager.queryOsAccountById(localId); + } + catch(err){ + console.debug("====>catch queryOsAccountById err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>queryOsAccountById info:" + JSON.stringify(info)); + expect(info.photo).assertEqual(photo); + await osAccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountSet_1600 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountSet_1700 + * @tc.name : setOsAccountName callback + * @tc.desc : create and set profile photo the base64 image converted from jpg image + */ + it('ActsOsAccountSet_1700', 0, async function(done){ + console.debug("====>ActsOsAccountSet_1700 start===="); + var osAccountManager = osAccount.getAccountManager(); + var localId; + var photo = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMD"+ + "AsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUF"+ + "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAALAAwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAA"+ + "gEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTV"+ + "FVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5"+ + "ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBU"+ + "QdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEh"+ + "YaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAP"+ + "wD2v4p+OPEXwz+LN3rvivwn4nh0bV9dsP7Oe51nRLOC7EF0kpEkL6psLRLDGsVwFhZkm8ucFljc/R1z8SPiZqBjl0n4SXljb7cPD4g1iwiuA"+ + "+TyBbTzoVxtwd+c5yBwT1/hv4W+F/CupalqVjpSy6rqQaO81PUJpL28niLFvJaednkMKljti3bEzhVArQ8H+CtE+H+iro/h7T49J0mORpIbC"+ + "3ZvIt9xyUiQnbFGO0aAIMnAGaxlTcqPsnJrrdb7Jfpv1vt1eilap7Syfk/n/nt09NF//9k=" + osAccountManager.createOsAccount('localNamePhotoJpg_callback', osAccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>createOsAccount err:" + JSON.stringify(err)); + console.debug("====>createOsAccount data:" + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("localNamePhotoJpg_callback"); + localId = data.localId; + osAccountManager.setOsAccountProfilePhoto(localId, photo, (err)=>{ + console.debug("====>setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.queryOsAccountById(localId, (err,info)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + console.debug("====>queryOsAccountById data:" +JSON.stringify(info)); + expect(err.code).assertEqual(0); + expect(info.photo).assertEqual(photo); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>removeOsAccount err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountSet_1700 end===="); + done(); + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountSet_1800 + * @tc.name : setOsAccountName promise + * @tc.desc : create and set profile photo the base64 image converted from jpg image + */ + it('ActsOsAccountSet_1800', 0, async function (done) { + console.debug("====>ActsOsAccountSet_1800 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var photo = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMD"+ + "AsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUF"+ + "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAALAAwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAA"+ + "gEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTV"+ + "FVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5"+ + "ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBU"+ + "QdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEh"+ + "YaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAP"+ + "wD2v4p+OPEXwz+LN3rvivwn4nh0bV9dsP7Oe51nRLOC7EF0kpEkL6psLRLDGsVwFhZkm8ucFljc/R1z8SPiZqBjl0n4SXljb7cPD4g1iwiuA"+ + "+TyBbTzoVxtwd+c5yBwT1/hv4W+F/CupalqVjpSy6rqQaO81PUJpL28niLFvJaednkMKljti3bEzhVArQ8H+CtE+H+iro/h7T49J0mORpIbC"+ + "3ZvIt9xyUiQnbFGO0aAIMnAGaxlTcqPsnJrrdb7Jfpv1vt1eilap7Syfk/n/nt09NF//9k=" + try{ + var info = await osAccountManager.createOsAccount("localPhotoJpg_promise", osAccount.OsAccountType.NORMAL); + } + catch(err){ + console.debug("====>catch createOsAccount err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>createOsAccount info:" + JSON.stringify(info)); + expect(info.localName).assertEqual("localPhotoJpg_promise"); + localId = info.localId + try{ + await osAccountManager.setOsAccountProfilePhoto(localId, photo); + } + catch(err){ + console.debug("====>catch setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + try{ + var info = await osAccountManager.queryOsAccountById(localId); + } + catch(err){ + console.debug("====>catch queryOsAccountById err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>queryOsAccountById info:" + JSON.stringify(info)); + expect(info.photo).assertEqual(photo); + await osAccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountSet_1800 end===="); + done(); + }) + + /* + * @tc.number : ActsOsAccountSet_1900 + * @tc.name : setOsAccountName callback + * @tc.desc : set 0 local user profile photo the base64 image converted from png image + */ + it('ActsOsAccountSet_1900', 0, async function (done) { + console.debug("====>ActsOsAccountSet_1900 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var photo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA"+ + "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+ + "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+ + "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==" + osAccountManager.setOsAccountProfilePhoto(0, photo, (err)=>{ + console.debug("====>setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountSet_1900 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountSet_2000 + * @tc.name : setOsAccountName promise + * @tc.desc : set 0 local user profile photo the base64 image converted from png image + */ + it('ActsOsAccountSet_2000', 0, async function (done) { + console.debug("====>ActsOsAccountSet_2000 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var photo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA"+ + "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+ + "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+ + "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==" + try{ + await osAccountManager.setOsAccountProfilePhoto(0, photo); + } + catch(err){ + console.debug("====>catch setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountSet_2000 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountSet_2100 + * @tc.name : setOsAccountName callback + * @tc.desc : set 0 local user profile photo the base64 image converted from jpg image + */ + it('ActsOsAccountSet_2100', 0, async function (done) { + console.debug("====>ActsOsAccountSet_2100 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var photo = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMD"+ + "AsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUF"+ + "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAALAAwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAA"+ + "gEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTV"+ + "FVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5"+ + "ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBU"+ + "QdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEh"+ + "YaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAP"+ + "wD2v4p+OPEXwz+LN3rvivwn4nh0bV9dsP7Oe51nRLOC7EF0kpEkL6psLRLDGsVwFhZkm8ucFljc/R1z8SPiZqBjl0n4SXljb7cPD4g1iwiuA"+ + "+TyBbTzoVxtwd+c5yBwT1/hv4W+F/CupalqVjpSy6rqQaO81PUJpL28niLFvJaednkMKljti3bEzhVArQ8H+CtE+H+iro/h7T49J0mORpIbC"+ + "3ZvIt9xyUiQnbFGO0aAIMnAGaxlTcqPsnJrrdb7Jfpv1vt1eilap7Syfk/n/nt09NF//9k=" + osAccountManager.setOsAccountProfilePhoto(0, photo, (err)=>{ + console.debug("====>setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountSet_2100 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountSet_2200 + * @tc.name : setOsAccountName promise + * @tc.desc : set 0 local user profile photo the base64 image converted from jpg image + */ + it('ActsOsAccountSet_2200', 0, async function (done) { + console.debug("====>ActsOsAccountSet_2200 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var photo = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMD"+ + "AsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUF"+ + "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAALAAwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAA"+ + "gEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTV"+ + "FVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5"+ + "ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBU"+ + "QdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEh"+ + "YaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAP"+ + "wD2v4p+OPEXwz+LN3rvivwn4nh0bV9dsP7Oe51nRLOC7EF0kpEkL6psLRLDGsVwFhZkm8ucFljc/R1z8SPiZqBjl0n4SXljb7cPD4g1iwiuA"+ + "+TyBbTzoVxtwd+c5yBwT1/hv4W+F/CupalqVjpSy6rqQaO81PUJpL28niLFvJaednkMKljti3bEzhVArQ8H+CtE+H+iro/h7T49J0mORpIbC"+ + "3ZvIt9xyUiQnbFGO0aAIMnAGaxlTcqPsnJrrdb7Jfpv1vt1eilap7Syfk/n/nt09NF//9k=" + try{ + await osAccountManager.setOsAccountProfilePhoto(0, photo); + } + catch(err){ + console.debug("====>catch setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountSet_2200 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountSet_2300 + * @tc.name : setOsAccountName callback + * @tc.desc : set the specified local profile photo to "bbb" + */ + it('ActsOsAccountSet_2300', 0, async function (done) { + console.debug("====>ActsOsAccountSet_2300 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.setOsAccountProfilePhoto(100, "bbb", (err)=>{ + console.debug("====>setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountSet_2300 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountSet_2400 + * @tc.name : setOsAccountName promise + * @tc.desc : set the specified local profile photo to "bbb" + */ + it('ActsOsAccountSet_2400', 0, async function (done) { + console.debug("====>ActsOsAccountSet_2400 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.setOsAccountProfilePhoto(100, "bbb"); + } + catch(err){ + console.debug("====>catch setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountSet_2400 end===="); + done(); + } + }) + + /* + * @tc.number : ActsOsAccountSet_2500 + * @tc.name : setOsAccountName callback + * @tc.desc : set the specified local profile photo to "" + */ + it('ActsOsAccountSet_2500', 0, async function (done) { + console.debug("====>ActsOsAccountSet_2500 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.setOsAccountProfilePhoto(100, "", (err)=>{ + console.debug("====>setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountSet_2500 end===="); + done(); + }) + }) + + /* + * @tc.number : ActsOsAccountSet_2600 + * @tc.name : setOsAccountName promise + * @tc.desc : set the specified local profile photo to "" + */ + it('ActsOsAccountSet_2600', 0, async function (done) { + console.debug("====>ActsOsAccountSet_2600 start===="); + var osAccountManager = osAccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + try{ + await osAccountManager.setOsAccountProfilePhoto(100, ""); + } + catch(err){ + console.debug("====>catch setOsAccountProfilePhoto err:" + JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_SET_OS_ACCOUNT_PROFILE_PHOTO_ERROR); + console.debug("====>ActsOsAccountSet_2600 end===="); + done(); + } + }) + +}) \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/Test.json b/account/osaccount/actsosaccountthirdpartytest/Test.json index 888804d48..4b309e4aa 100755 --- a/account/osaccount/actsosaccountthirdpartytest/Test.json +++ b/account/osaccount/actsosaccountthirdpartytest/Test.json @@ -2,7 +2,7 @@ "description": "Configuration for hjunit demo Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "100000", + "test-timeout": "200000", "package": "com.example.actsosaccountthirdpartytest", "shell-timeout": "60000" }, 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 index ff8933440..bf4a20cd6 100755 --- 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 @@ -35,6 +35,7 @@ export default { core.init() const configService = core.getDefaultService('config') + this.timeout = 8000; configService.setConfig(this) require('../../../test/List.test') 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 index 02ac0b9d8..0d2e50ff5 100755 --- a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/List.test.js +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/List.test.js @@ -12,4 +12,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./OsAccountIs.test.js') \ No newline at end of file +require('./OsAccountIs.test.js') +require('./OsAccountGet.test.js') \ No newline at end of file diff --git a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountGet.test.js b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountGet.test.js new file mode 100755 index 000000000..b25bc0a96 --- /dev/null +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountGet.test.js @@ -0,0 +1,469 @@ +/* + * 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 bundle from '@ohos.bundle' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +const ERR_OSACCOUNT_KIT_GET_OS_ACCOUNT_LOCAL_ID_FROM_UID_ERROR = 4587551; +describe('ActsOsAccountThirdPartyTest', function () { + + /* + * @tc.number : ActsOsAccountGetIdFormUid_0100 + * @tc.name : getOsAccountLocalIdFromUid callback + * @tc.desc : Verify that the user localId is obtained by uid + */ + it('ActsOsAccountGetIdFormUid_0100', 0, async function (done) { + console.debug("====>ActsOsAccountGetIdFormUid_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var bundleName = "com.example.actsosaccountthirdpartytest"; + var bundleInfo = await bundle.getBundleInfo(bundleName, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + var uid = bundleInfo.uid; + console.debug("====>obtained uid:" + uid); + osAccountManager.getOsAccountLocalIdFromUid(uid, (err, localId)=>{ + console.debug("====>get localId err: " + JSON.stringify(err)); + console.debug("====>localId obtained by uid:" + localId); + expect(err.code).assertEqual(0); + expect(localId).assertEqual(0); + console.debug("====>ActsOsAccountGetIdFormUid_0100 end===="); + done(); + }); + }); + + /* + * @tc.number : ActsOsAccountGetIdFormUid_0200 + * @tc.name : getOsAccountLocalIdFromUid promise + * @tc.desc : Verify that the user localId is obtained by uid + */ + it('ActsOsAccountGetIdFormUid_0200', 0, async function (done) { + console.debug("====>ActsOsAccountGetIdFormUid_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var bundleName = "com.example.actsosaccountthirdpartytest"; + var bundleInfo = await bundle.getBundleInfo(bundleName, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + var uid = bundleInfo.uid; + console.debug("====>obtained uid:" + uid); + var localId = await osAccountManager.getOsAccountLocalIdFromUid(uid); + console.debug("====>localId obtained by uid:" + localId); + expect(localId).assertEqual(0); + console.debug("====>ActsOsAccountGetIdFormUid_0200 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountGetIdFormUid_0300 + * @tc.name : getOsAccountLocalIdFromUid callback + * @tc.desc : Authentication failed to query user by uid -1 + */ + it('ActsOsAccountGetIdFormUid_0300', 0, async function (done) { + console.debug("====>ActsOsAccountGetIdFormUid_0300 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var incorrectUid = -1; + osAccountManager.getOsAccountLocalIdFromUid(incorrectUid, (err, localId)=>{ + console.debug("====>get localId err: " + JSON.stringify(err)); + console.debug("====>localId obtained by uid:" + localId); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_GET_OS_ACCOUNT_LOCAL_ID_FROM_UID_ERROR); + expect(localId).assertEqual(0); + console.debug("====>ActsOsAccountGetIdFormUid_0300 end===="); + done(); + }); + }); + + /* + * @tc.number : ActsOsAccountGetIdFormUid_0400 + * @tc.name : getOsAccountLocalIdFromUid promise + * @tc.desc : Authentication failed to query user by uid -1 + */ + it('ActsOsAccountGetIdFormUid_0400', 0, async function (done) { + console.debug("====>ActsOsAccountGetIdFormUid_0400 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var incorrectUid = -1; + try{ + await osAccountManager.getOsAccountLocalIdFromUid(incorrectUid); + }catch(err){ + console.debug("====>get localId by uid err:" +JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_GET_OS_ACCOUNT_LOCAL_ID_FROM_UID_ERROR); + console.debug("====>ActsOsAccountGetIdFormUid_0400 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountGetIdFormUid_0500 + * @tc.name : getOsAccountLocalIdFromUid callback + * @tc.desc : Authentication failed to query user by uid 2147483648 + */ + it('ActsOsAccountGetIdFormUid_0500', 0, async function (done) { + console.debug("====>ActsOsAccountGetIdFormUid_0500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var incorrectUid = 2147483648; + osAccountManager.getOsAccountLocalIdFromUid(incorrectUid, (err, localId)=>{ + console.debug("====>get localId err: " + JSON.stringify(err)); + console.debug("====>localId obtained by uid:" + localId); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_GET_OS_ACCOUNT_LOCAL_ID_FROM_UID_ERROR); + expect(localId).assertEqual(0); + console.debug("====>ActsOsAccountGetIdFormUid_0500 end===="); + done(); + }); + }); + + /* + * @tc.number : ActsOsAccountGetIdFormUid_0600 + * @tc.name : getOsAccountLocalIdFromUid promise + * @tc.desc : Authentication failed to query user by uid 2147483648 + */ + it('ActsOsAccountGetIdFormUid_0600', 0, async function (done) { + console.debug("====>ActsOsAccountGetIdFormUid_0600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var incorrectUid = 2147483648; + try{ + await osAccountManager.getOsAccountLocalIdFromUid(incorrectUid); + }catch(err){ + console.debug("====>get localId by uid err:" +JSON.stringify(err)); + expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_GET_OS_ACCOUNT_LOCAL_ID_FROM_UID_ERROR); + console.debug("====>ActsOsAccountGetIdFormUid_0600 end===="); + done(); + } + }); + + /* + * @tc.number : ActsOsAccountGetIdFormProcess_0100 + * @tc.name : getOsAccountLocalIdFromProcess callback + * @tc.desc : Verify that the user localId obtained from the current process uid + */ + it('ActsOsAccountGetIdFormProcess_0100', 0, async function (done) { + console.debug("====>ActsOsAccountGetIdFormProcess_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.getOsAccountLocalIdFromProcess((err, localId)=>{ + console.debug("====>get localId err: " + JSON.stringify(err)); + console.debug("====>localId obtained by process:" + localId); + expect(err.code).assertEqual(0); + expect(localId).assertEqual(0); + console.debug("====>ActsOsAccountGetIdFormProcess_0100 end===="); + done(); + }); + }); + + /* + * @tc.number : ActsOsAccountGetIdFormProcess_0200 + * @tc.name : getOsAccountLocalIdFromProcess promise + * @tc.desc : Verify that the user localId obtained from the current process uid + */ + it('ActsOsAccountGetIdFormProcess_0200', 0, async function (done) { + console.debug("====>ActsOsAccountGetIdFormProcess_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.debug("====>localId obtained by process:" + localId); + expect(localId).assertEqual(0); + console.debug("====>ActsOsAccountGetIdFormProcess_0200 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountGetTypeFormProcess_0100 + * @tc.name : getOsAccountTypeFromProcess callback + * @tc.desc : Verify that the user type obtained from the current process uid + */ + it('ActsOsAccountGetTypeFormProcess_0100', 0, async function (done) { + console.debug("====>ActsOsAccountGetTypeFormProcess_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.getOsAccountTypeFromProcess((err, accountType)=>{ + console.debug("====>get type err: " + JSON.stringify(err)); + console.debug("====>type obtained by process:" + JSON.stringify(accountType)); + expect(err.code).assertEqual(0); + expect(accountType.ADMIN).assertEqual(0); + console.debug("====>ActsOsAccountGetTypeFormProcess_0100 end===="); + done(); + }); + }); + + /* + * @tc.number : ActsOsAccountGetTypeFormProcess_0200 + * @tc.name : getOsAccountTypeFromProcess promise + * @tc.desc : Verify that the user type obtained from the current process uid + */ + it('ActsOsAccountGetTypeFormProcess_0200', 0, async function (done) { + console.debug("====>ActsOsAccountGetTypeFormProcess_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var accountType = await osAccountManager.getOsAccountTypeFromProcess(); + console.debug("====>type obtained by process:" + JSON.stringify(accountType)); + expect(accountType.ADMIN).assertEqual(0); + console.debug("====>ActsOsAccountGetTypeFormProcess_0200 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountLocalIdSerial_0100 + * @tc.name : getSerialNumberByOsAccountLocalId callback + * @tc.desc : Verify query serialNumber by 100 user and query 100 user by serialNumber + */ + it('ActsOsAccountLocalIdSerial_0100', 0, async function (done) { + console.debug("====>ActsOsAccountLocalIdSerial_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.getSerialNumberByOsAccountLocalId(100, (err, serialNumber)=>{ + console.debug("====>ger serialNumber err:" + JSON.stringify(err)); + console.debug("====>get serialNumber:" + serialNumber + " by localId: 100" ); + expect(err.code).assertEqual(0); + var serialNumberStr = serialNumber.toString(); + var serialIntercept = serialNumberStr.substring(8); + console.debug("====>truncate the last eight characters: " + serialIntercept); + expect(serialIntercept).assertEqual("00000001"); + osAccountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err, localId)=>{ + console.debug("====>ger localId err:" + JSON.stringify(err)); + console.debug("====>get localId:" + localId + " by serialNumber: " + serialNumber); + expect(err.code).assertEqual(0); + expect(localId).assertEqual(100); + console.debug("====>ActsOsAccountLocalIdSerial_0100 end===="); + done(); + }) + }) + }); + + /* + * @tc.number : ActsOsAccountLocalIdSerial_0200 + * @tc.name : getSerialNumberByOsAccountLocalId promise + * @tc.desc : Verify query serialNumber by 100 user and query 100 user by serialNumber + */ + it('ActsOsAccountLocalIdSerial_0200', 0, async function (done) { + console.debug("====>ActsOsAccountLocalIdSerial_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var serialNumber = await osAccountManager.getSerialNumberByOsAccountLocalId(100); + console.debug("====>get serialNumber:" + serialNumber + " by localId: 100" ); + var serialNumberStr = serialNumber.toString(); + var serialIntercept = serialNumberStr.substring(8); + console.debug("====>truncate the last eight characters: " + serialIntercept); + expect(serialIntercept).assertEqual("00000001"); + var localId = await osAccountManager.getOsAccountLocalIdBySerialNumber(serialNumber); + console.debug("====>get localId:" + localId + " by serialNumber: " + serialNumber); + expect(localId).assertEqual(100); + console.debug("====>ActsOsAccountLocalIdSerial_0200 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountLocalIdSerial_0300 + * @tc.name : getOsAccountLocalIdBySerialNumber callback + * @tc.desc : Verify query serialNumber by 0 user and query 0 user by serialNumber + */ + it('ActsOsAccountLocalIdSerial_0300', 0, async function (done) { + console.debug("====>ActsOsAccountLocalIdSerial_0300 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + osAccountManager.getSerialNumberByOsAccountLocalId(0, (err, serialNumber)=>{ + console.debug("====>ger serialNumber err:" + JSON.stringify(err)); + console.debug("====>get serialNumber:" + serialNumber + " by localId: 0" ); + expect(err.code).assertEqual(0); + var serialNumberStr = serialNumber.toString(); + var serialIntercept = serialNumberStr.substring(8); + console.debug("====>truncate the last eight characters: " + serialIntercept); + expect(serialIntercept).assertEqual("00000000"); + osAccountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err, localId)=>{ + console.debug("====>ger localId err:" + JSON.stringify(err)); + console.debug("====>get localId:" + localId + " by serialNumber: " + serialNumber); + expect(err.code).assertEqual(0); + expect(localId).assertEqual(0); + console.debug("====>ActsOsAccountLocalIdSerial_0300 end===="); + done(); + }) + }) + }); + + /* + * @tc.number : ActsOsAccountLocalIdSerial_0400 + * @tc.name : getOsAccountLocalIdBySerialNumber promise + * @tc.desc : Verify query serialNumber by 0 user and query 0 user by serialNumber + */ + it('ActsOsAccountLocalIdSerial_0400', 0, async function (done) { + console.debug("====>ActsOsAccountLocalIdSerial_0400 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var serialNumber = await osAccountManager.getSerialNumberByOsAccountLocalId(0); + console.debug("====>get serialNumber:" + serialNumber + " by localId: 0" ); + var serialNumberStr = serialNumber.toString(); + var serialIntercept = serialNumberStr.substring(8); + console.debug("====>truncate the last eight characters: " + serialIntercept); + expect(serialIntercept).assertEqual("00000000"); + var localId = await osAccountManager.getOsAccountLocalIdBySerialNumber(serialNumber); + console.debug("====>get localId:" + localId + " by serialNumber: " + serialNumber); + expect(localId).assertEqual(0); + console.debug("====>ActsOsAccountLocalIdSerial_0400 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountLocalIdSerial_0500 + * @tc.name : getSerialNumberByOsAccountLocalId callback + * @tc.desc : Verify the query for the newly created user serialNumber and query the owning user through the + * serialNumber + */ + it('ActsOsAccountLocalIdSerial_0500', 0, async function (done) { + console.debug("====>ActsOsAccountLocalIdSerial_0500 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + osAccountManager.createOsAccount("osAccountNameIdSerialA", osaccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>create os account err: " + JSON.stringify(err)); + console.debug("====>create os account OsAccountInfo: " + JSON.stringify(data)); + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("osAccountNameIdSerialA"); + localId = data.localId; + osAccountManager.getSerialNumberByOsAccountLocalId(localId, (err, serialNumber)=>{ + console.debug("====>queryOsAccountById err:" + JSON.stringify(err)); + console.debug("====>get serialNumber:" + serialNumber + " by localId: " + localId); + expect(err.code).assertEqual(0); + osAccountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err, getlocalId)=>{ + console.debug("====>ger localId err:" + JSON.stringify(err)); + console.debug("====>get localId:" + getlocalId + " by serialNumber: " + serialNumber); + expect(err.code).assertEqual(0); + expect(getlocalId).assertEqual(localId); + osAccountManager.removeOsAccount(localId, (err)=>{ + console.debug("====>remove localId: " + localId + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountLocalIdSerial_0500 end===="); + done(); + }) + }) + }) + }) + }); + + /* + * @tc.number : ActsOsAccountLocalIdSerial_0600 + * @tc.name : getOsAccountLocalIdBySerialNumber promise + * @tc.desc : Verify the query for the newly created user serialNumber and query the owning user through the + * serialNumber + */ + it('ActsOsAccountLocalIdSerial_0600', 0, async function (done) { + console.debug("====>ActsOsAccountLocalIdSerial_0600 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var localId; + var OsAccountInfo = await osAccountManager.createOsAccount("accountIdSerialB", osaccount.OsAccountType.NORMAL); + console.debug("====>create os account OsAccountInfo: " + JSON.stringify(OsAccountInfo)); + expect(OsAccountInfo.localName).assertEqual("accountIdSerialB"); + localId = OsAccountInfo.localId; + var serialNumber = await osAccountManager.getSerialNumberByOsAccountLocalId(localId); + console.debug("====>get serialNumber:" + serialNumber + " by localId: " + localId); + var getlocalId = await osAccountManager.getOsAccountLocalIdBySerialNumber(serialNumber); + console.debug("====>get localId:" + getlocalId + " by serialNumber: " + serialNumber); + expect(getlocalId).assertEqual(localId); + await osAccountManager.removeOsAccount(localId); + console.debug("====>ActsOsAccountLocalIdSerial_0600 end===="); + done(); + }); + + /* + * @tc.number : ActsOsAccountGetCount_0100 + * @tc.name : getCreatedOsAccountsCount callback + * @tc.desc : Verify to obtain the number os all os accounts created + */ + it('ActsOsAccountGetCount_0100', 0, async function (done) { + console.debug("====>ActsOsAccountGetCount_0100 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var obtainCount = 0; + var localIdFir; + var localIdSec; + osAccountManager.getCreatedOsAccountsCount((err, data)=>{ + console.debug("====>obtains the number of all os accounts created err:" + JSON.stringify(err)); + console.debug("====>obtains the number of all os accounts created data:" + data); + expect(err.code).assertEqual(0); + obtainCount = data; + osAccountManager.createOsAccount("osAccountNameIdSerialE", osaccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>create first os account err: " + JSON.stringify(err)); + console.debug("====>create first os account OsAccountInfo: " + JSON.stringify(data)); + localIdFir = data.localId; + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("osAccountNameIdSerialE"); + osAccountManager.createOsAccount("osAccountIdSerialF", osaccount.OsAccountType.NORMAL, (err, data)=>{ + console.debug("====>create second os account err: " + JSON.stringify(err)); + console.debug("====>create second os account OsAccountInfo: " + JSON.stringify(data)); + localIdSec = data.localId; + expect(err.code).assertEqual(0); + expect(data.localName).assertEqual("osAccountIdSerialF"); + osAccountManager.getCreatedOsAccountsCount((err, count)=>{ + console.debug("====>obtains the number of all os accounts created err:" + JSON.stringify(err)); + console.debug("====>obtains the number of all os accounts created count:" + count); + expect(err.code).assertEqual(0); + count = count - 2; + expect(count).assertEqual(obtainCount); + osAccountManager.removeOsAccount(localIdFir, (err)=>{ + console.debug("====>remove localId: " + localIdFir + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + osAccountManager.getCreatedOsAccountsCount((err, data)=>{ + console.debug("====>obtains the number accounts created err:" + JSON.stringify(err)); + console.debug("====>obtains the number accounts created data:" + data); + expect(err.code).assertEqual(0); + data = data - 1; + expect(data).assertEqual(obtainCount); + osAccountManager.removeOsAccount(localIdSec, (err)=>{ + console.debug("====>remove localId: " + localIdSec + " err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + console.debug("====>ActsOsAccountGetCount_0100 end===="); + done(); + }) + }) + }) + }) + }) + }) + }) + }) + + /* + * @tc.number : ActsOsAccountGetCount_0200 + * @tc.name : getCreatedOsAccountsCount promise + * @tc.desc : Verify to obtain the number os all os accounts created + */ + it('ActsOsAccountGetCount_0200', 0, async function (done) { + console.debug("====>ActsOsAccountGetCount_0200 start===="); + var osAccountManager = osaccount.getAccountManager(); + console.debug("====>get AccountManager finish===="); + var obtainCount = await osAccountManager.getCreatedOsAccountsCount(); + console.debug("====>obtains the number of all os accounts created:" + obtainCount); + var osAccountFir = await osAccountManager.createOsAccount("osAccountIdSerialG", osaccount.OsAccountType.NORMAL); + console.debug("====>create first os account OsAccountInfo: " + JSON.stringify(osAccountFir)); + var localIdFir = osAccountFir.localId; + expect(osAccountFir.localName).assertEqual("osAccountIdSerialG"); + var osAccountSec = await osAccountManager.createOsAccount("osAccountIdSerialH", osaccount.OsAccountType.NORMAL); + console.debug("====>create second os account OsAccountInfo: " + JSON.stringify(osAccountSec)); + var localIdSec = osAccountSec.localId; + expect(osAccountSec.localName).assertEqual("osAccountIdSerialH"); + var countFir = await osAccountManager.getCreatedOsAccountsCount(); + console.debug("====>obtains the number of all os accounts created count:" + countFir); + countFir = countFir - 2; + expect(countFir).assertEqual(obtainCount); + await osAccountManager.removeOsAccount(localIdFir); + console.debug("====>remove localId: " + localIdFir); + var countSec = await osAccountManager.getCreatedOsAccountsCount(); + console.debug("====>obtains the number accounts created count:" + countSec); + countSec = countSec - 1; + expect(countSec).assertEqual(obtainCount); + await osAccountManager.removeOsAccount(localIdSec); + console.debug("====>remove localId: " + localIdSec); + console.debug("====>ActsOsAccountGetCount_0200 end===="); + done(); + }) +}) \ 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 index ab542eeeb..59774d663 100755 --- a/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountIs.test.js +++ b/account/osaccount/actsosaccountthirdpartytest/entry/src/main/js/test/OsAccountIs.test.js @@ -16,8 +16,8 @@ import osAccount from '@ohos.account.osAccount' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' const TIMEOUT = 1000; -const ERR_OSACCOUNT_KIT_IS_OS_ACCOUNT_ACTIVED_ERROR = 4587543; -const ERR_OSACCOUNT_KIT_IS_OS_ACCOUNT_VERIFIED_ERROR = 4587546; +const ERR_OSACCOUNT_KIT_IS_OS_ACCOUNT_ACTIVED_ERROR = 4587545; +const ERR_OSACCOUNT_KIT_IS_OS_ACCOUNT_VERIFIED_ERROR = 4587548; describe('ActsOsAccountThirdPartyTest', function () { /* -- GitLab