NoPermission.test.js 12.7 KB
Newer Older
J
jiyong_sd 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/*
 * 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 account from '@ohos.account.appAccount'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'

const TIMEOUT = 5000;
const ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED = 4521993;
export default function ActsAccountNoPermission() {
    describe('ActsAccountNoPermission', function () {
        function sleep(delay) {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve()
                }, delay)
            }).then(() => {
                console.info(`sleep #{time} over ...`)
            })
        }
        beforeAll(async function (done) {
            console.debug("====>beforeAll start====");
            await sleep(TIMEOUT);
            console.debug("====>beforeAll end====");
            done();
        });

        /*
        * @tc.number    : ActsAccountNoPermission_0100
        * @tc.name      : setAppAccountSyncEnable callback
        * @tc.desc      : Set the added account to allow synchronization without permission
        */
        it('ActsAccountNoPermission_0100', 0, async function (done) {
            console.debug("====>ActsAccountNoPermission_0100 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("syncenable_callback_setnopermission", (err)=>{
                console.debug("====>add account ActsAccountNoPermission_0100 err:" + JSON.stringify(err));
49
                expect(err).assertEqual(null);
J
jiyong_sd 已提交
50 51 52 53 54
                appAccountManager.setAppAccountSyncEnable("syncenable_callback_setnopermission", true, (err)=>{
                    console.debug("====>setAppAccountSyncEnable 0100 err:" + JSON.stringify(err));
                    expect(err.code).assertEqual(account.ResultCode.ERROR_PERMISSION_DENIED);
                    appAccountManager.deleteAccount("syncenable_callback_setnopermission", (err)=>{
                        console.debug("====>delete Account ActsAccountNoPermission_0100 err:" + JSON.stringify(err));
55
                        expect(err).assertEqual(null);
J
jiyong_sd 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
                        console.debug("====>ActsAccountNoPermission_0100 end====");
                        done();
                    }); 
                })
            });
        });

        /*
        * @tc.number    : ActsAccountNoPermission_0200
        * @tc.name      : setAppAccountSyncEnable promise
        * @tc.desc      : Set the added account to allow synchronization without permission
        */
        it('ActsAccountNoPermission_0200', 0, async function (done) {
            console.debug("====>ActsAccountNoPermission_0200 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountNoPermission_0200 start====");
            await appAccountManager.addAccount("syncenable_promise_setnopermission");
            console.debug("====>setAppAccountSyncEnable ActsAccountNoPermission_0200 start====");
            try{
                await appAccountManager.setAppAccountSyncEnable("syncenable_promise_setnopermission", true);
            }
            catch(err){
                console.debug("====>setAppAccountSyncEnable 0200 err:" + JSON.stringify(err));
                expect(err.code).assertEqual(account.ResultCode.ERROR_PERMISSION_DENIED);
                console.debug("====>delete account ActsAccountNoPermission_0200 start====");
                await appAccountManager.deleteAccount("syncenable_promise_setnopermission");
                console.debug("====>ActsAccountNoPermission_0200 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountNoPermission_0300
        * @tc.name      : Check sync flag callback form
        * @tc.desc      : Check the added account synchronization without permission
        */
        it('ActsAccountNoPermission_0300', 0, async function (done) {
            console.debug("====>ActsAccountNoPermission_0300 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("syncenable_callback_checknopermission", (err)=>{
                console.debug("====>add account ActsAccountNoPermission_0300 err:" + JSON.stringify(err));
99
                expect(err).assertEqual(null);
J
jiyong_sd 已提交
100 101 102 103 104
                appAccountManager.checkAppAccountSyncEnable("syncenable_callback_checknopermission", (err, data)=>{
                    console.debug("====>checkAppAccountSyncEnable 0300 err:" + JSON.stringify(err));
                    expect(err.code).assertEqual(account.ResultCode.ERROR_PERMISSION_DENIED);
                    appAccountManager.deleteAccount("syncenable_callback_checknopermission", (err)=>{
                        console.debug("====>delete Account ActsAccountNoPermission_0300 err:" + JSON.stringify(err));
105
                        expect(err).assertEqual(null);
J
jiyong_sd 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
                        console.debug("====>ActsAccountNoPermission_0300 end====");
                        done();
                    });
                })
            });
        });

        /*
        * @tc.number    : ActsAccountNoPermission_0400
        * @tc.name      : Check sync flag promise form
        * @tc.desc      : Check the added account synchronization without permission
        */
        it('ActsAccountNoPermission_0400', 0, async function (done) {
            console.debug("====>ActsAccountNoPermission_0400 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountNoPermission_0400 start====");
            await appAccountManager.addAccount("syncenable_promise_checknopermission");
            console.debug("====>checkAppAccountSyncEnable ActsAccountNoPermission_0400 start====");
            try{
                var data = await appAccountManager.checkAppAccountSyncEnable("syncenable_promise_checknopermission");
            }
            catch(err){
                console.debug("====>checkAppAccountSyncEnable 0400 err:" + JSON.stringify(err));
                expect(err.code).assertEqual(account.ResultCode.ERROR_PERMISSION_DENIED);
                await appAccountManager.deleteAccount("syncenable_promise_checknopermission");
                console.debug("====>ActsAccountNoPermission_0400 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountNoPermission_0500
        * @tc.name      : getAllAccessibleAccounts callback
        * @tc.desc      : This application gets authorization after adding a single account without permission
        */
        it('ActsAccountNoPermission_0500', 0, async function (done) {
            console.debug("====>ActsAccountNoPermission_0500 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("accessibleAccount_callback_nopermission", (err)=>{
                console.debug("====> add account ActsAccountNoPermission_0500 err:" + JSON.stringify(err));
148
                expect(err).assertEqual(null);
J
jiyong_sd 已提交
149 150 151 152 153
                appAccountManager.getAllAccessibleAccounts((err, data)=>{
                    console.debug("====>getAllAccessibleAccounts 0500 err:" + JSON.stringify(err));
                    expect(err.code).assertEqual(account.ResultCode.ERROR_PERMISSION_DENIED);
                    appAccountManager.deleteAccount("accessibleAccount_callback_nopermission", (err)=>{
                        console.debug("====>delete Account ActsAccountNoPermission_0500 err:" + JSON.stringify(err));
154
                        expect(err).assertEqual(null);
J
jiyong_sd 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
                        console.debug("====>ActsAccountNoPermission_0500 end====");
                        done();
                    })
                });
            });
        });

        /*
        * @tc.number    : ActsAccountNoPermission_0600
        * @tc.name      : getAllAccessibleAccounts promise
        * @tc.desc      : This application gets authorization after adding a single account without permission
        */
        it('ActsAccountNoPermission_0600', 0, async function (done) {
            console.debug("====>ActsAccountNoPermission_0600 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountNoPermission_0600 start====");
            await appAccountManager.addAccount("accessibleAccount_promise_nopermission");
            console.debug("====>getAllAccessibleAccounts 0600 start====");
            try{
                var data = await appAccountManager.getAllAccessibleAccounts();
            }
            catch(err){
                console.debug("====>getAllAccessibleAccounts 0600 err:" + JSON.stringify(err));
                expect(err.code).assertEqual(account.ResultCode.ERROR_PERMISSION_DENIED);
                await appAccountManager.deleteAccount("accessibleAccount_promise_nopermission");
                console.debug("====>ActsAccountNoPermission_0600 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountNoPermission_0700
        * @tc.name      : getAllAccounts callback
        * @tc.desc      : This application gets its own application information after adding an account without permission
        */
        it('ActsAccountNoPermission_0700', 0, async function (done) {
            console.debug("====>ActsAccountNoPermission_0700 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            var selfBundle = "com.example.actsaccounttest";
            appAccountManager.addAccount("getAll_callback_nopermission", (err)=>{
                console.debug("====>add account 0700 err:" + JSON.stringify(err));
198
                expect(err).assertEqual(null);
J
jiyong_sd 已提交
199 200
                appAccountManager.getAllAccounts(selfBundle, (err, data)=>{
                    console.debug("====>getAllAccounts 0700 err:" + JSON.stringify(err));
201 202
                    expect(err).assertEqual(null);
                    expect(data.length>0).assertEqual(true);
J
jiyong_sd 已提交
203 204
                    appAccountManager.deleteAccount("getAll_callback_nopermission", (err)=>{
                        console.debug("====>delete account 0700 err:" + JSON.stringify(err));
205
                        expect(err).assertEqual(null);
J
jiyong_sd 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
                        console.debug("====>ActsAccountNoPermission_0700 end====");
                        done();
                    });
                })
            });
        });

        /*
        * @tc.number    : ActsAccountNoPermission_0800
        * @tc.name      : getAllAccounts promise
        * @tc.desc      : This application gets its own application information after adding an account without permission
        */
        it('ActsAccountNoPermission_0800', 0, async function (done) {
            console.debug("====>ActsAccountNoPermission_0800 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            var selfBundle = "com.example.actsaccounttest";
            console.debug("====>add account 0800 start====");
            await appAccountManager.addAccount("getAll_promise_nopermission");
            console.debug("====>getAllAccounts 0800 start====");
            try{
                var data = await appAccountManager.getAllAccounts(selfBundle);
228
                console.debug("====>getAll_promise_nopermission data:" + JSON.stringify(data))
229 230
                expect(data.length>0).assertEqual(true);
                done();
J
jiyong_sd 已提交
231 232 233 234 235 236 237 238 239 240 241
            }
            catch(err){
                console.error("====>getAllAccounts 0800 err:" + JSON.stringify(err));
                expect(err.code).assertEqual(account.ResultCode.ERROR_PERMISSION_DENIED);
                await appAccountManager.deleteAccount("getAll_promise_nopermission");      
                console.debug("====>ActsAccountNoPermission_0800 end====");
                done();
            }          
        });
    })
}