• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import account from '@ohos.account.appAccount'
16import commonevent from '@ohos.commonEventManager'
17import featureAbility from '@ohos.ability.featureAbility'
18import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Size, Level } from '@ohos/hypium'
19
20export default function ActsAccountChangeOnOff() {
21    describe('ActsAccountChangeOnOff', async function () {
22        async function sleep(delay) {
23            let timeoutId = null;
24            let promise = new Promise((resolve, reject) => {
25                timeoutId = setTimeout(() => resolve("done!"), delay);
26            });
27            await promise
28            clearTimeout(timeoutId)
29        }
30
31        async function testInit(){
32            console.info("====>testInit startAbility start====");
33            featureAbility.startAbilityForResult(
34                {
35                    want:
36                    {
37                        deviceId: "",
38                        bundleName: "com.example.actsaccountsceneonoff",
39                        abilityName: "com.example.actsaccountsceneonoff.MainAbility",
40                        action: "action1",
41                        parameters:
42                        {},
43                    },
44                },
45            )
46        }
47
48        /*
49        * @tc.number    : ActsAccountChangeOnOff_0100
50        * @tc.name      : Subscribe/unsubscribe to the change event of application
51        * @tc.desc      : Received the account information change to the authorized account of the subscription to change
52        *                 the additional information
53        */
54        it('ActsAccountChangeOnOff_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
55            await testInit();
56            await sleep(500)
57            console.info("====>ActsAccountChangeOnOff_0100 start====");
58            var appAccountManager = account.createAppAccountManager();
59            console.info("====>creat appAccountManager finish");
60            console.info("====>add account ActsAccountChangeOnOff_0100 start");
61            await appAccountManager.addAccount("changeonoff_extra");
62            console.info("====>enableAppAccess ActsAccountChangeOnOff_0100 start");
63            await appAccountManager.enableAppAccess("changeonoff_extra", "com.example.actsaccountsceneonoff");
64            async function deleteAccountCallback(err){
65                console.info("====>delete account 0100 err:" + JSON.stringify(err));
66                try {
67                    expect(err).assertEqual(null);
68                } catch (err) {
69                    console.info('====>Assert err: ' + JSON.stringify(err));
70                }
71                await sleep(500);
72                done();
73            }
74            function disCallback(err){
75                console.info("====>delete account 0100 err:" + JSON.stringify(err));
76                try {
77                    expect(err).assertEqual(null);
78                } catch (err) {
79                    console.info('====>Assert err: ' + JSON.stringify(err));
80                }
81                appAccountManager.deleteAccount("changeonoff_extra", deleteAccountCallback);
82            }
83            function unSubscriberCallback(err){
84                console.info("====>unsubscribe 0100 err:" + JSON.stringify(err));
85                appAccountManager.disableAppAccess("changeonoff_extra", "com.example.actsaccountsceneonoff", disCallback);
86            }
87            async function subscriberCallback(err, data){
88                console.info("====>subscriberCallback 0100 data:" + JSON.stringify(data));
89                try {
90                    expect(data.event).assertEqual("account_on_change_extra");
91                    if (data.data == "ON_SUCCESS") {
92                        console.info("====>setAccountExtraInfo start====");
93                        await appAccountManager.setAccountExtraInfo("changeonoff_extra", "change_extra");
94                        console.info("====>setAccountExtraInfo finish====");
95                    } else {
96                        expect(data.data).assertEqual("SUCCESS");
97                        commonevent.unsubscribe(subscriber, unSubscriberCallback);
98                    }
99                } catch (err) {
100                    console.info('====>subscriberCallback err: ' + JSON.stringify(err));
101                }
102            }
103            async function publishCallback(err){
104                console.info("====>main publish call back err:" + JSON.stringify(err));
105            }
106            var commonEventSubscribeInfo = {
107                events: ["account_on_change_extra"]
108            }
109            await sleep(500)
110            var subscriber
111            await commonevent.createSubscriber(commonEventSubscribeInfo).then(function (data){
112                subscriber = data;
113                commonevent.subscribe(subscriber, subscriberCallback);
114                console.info("====>subscribe ActsAccountChangeOnOff_0100 finish====")
115            });
116
117            var commonEventPublishData = {
118                code: 1
119            }
120            await sleep(500);
121            console.info("====>publish event account_on_change 0100====");
122            commonevent.publish("account_on_change", commonEventPublishData, publishCallback);
123        });
124
125        /*
126        * @tc.number    : ActsAccountChangeOnOff_0200
127        * @tc.name      : Subscribe/unsubscribe to the change event of application
128        * @tc.desc      : Received the account information change to the authorized account of the subscription to change
129        *                 the associatal data
130        */
131        it('ActsAccountChangeOnOff_0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
132            await testInit();
133            await sleep(500)
134            console.info("====>ActsAccountChangeOnOff_0200 start====");
135            var appAccountManager = account.createAppAccountManager();
136            console.info("====>creat appAccountManager finish");
137            console.info("====>add account ActsAccountChangeOnOff_0200 start");
138            await appAccountManager.addAccount("onoff_associatedata");
139            console.info("====>enableAppAccess ActsAccountChangeOnOff_0200 start");
140            await appAccountManager.enableAppAccess("onoff_associatedata", "com.example.actsaccountsceneonoff");
141            async function deleteAccountCallback(err){
142                console.info("====>delete account 0200 err:" + JSON.stringify(err));
143                try {
144                    expect(err).assertEqual(null);
145                } catch (err) {
146                    console.info('====>Assert err: ' + JSON.stringify(err));
147                }
148                await sleep(500);
149                done();
150            }
151            function unSubscriberCallback(err){
152                console.info("====>unsubscribe 0200 err:" + JSON.stringify(err));
153                appAccountManager.deleteAccount("onoff_associatedata", deleteAccountCallback);
154            }
155            async function subscriberCallback(err, data){
156                console.info("====>subscriberCallback 0200 data:" + JSON.stringify(data));
157                try {
158                    expect(data.event).assertEqual("account_on_change_associatedata");
159                    if (data.data == "ON_SUCCESS") {
160                        console.info("====>setAssociatedData start====");
161                        await appAccountManager.setAssociatedData("onoff_associatedata", "change_key", "change_value");
162                        console.info("====>setAssociatedData finish====");
163                    } else {
164                        expect(data.data).assertEqual("SUCCESS");
165                        commonevent.unsubscribe(subscriber, unSubscriberCallback);
166                    }
167                } catch (err) {
168                    console.info('====>subscriberCallback err: ' + JSON.stringify(err));
169                }
170            }
171            async function publishCallback(err){
172                console.info("====>main publish call back err:" + JSON.stringify(err));
173            }
174            var commonEventSubscribeInfo = {
175                events: ["account_on_change_associatedata"]
176            }
177            await sleep(500)
178            var subscriber
179            await commonevent.createSubscriber(commonEventSubscribeInfo).then(function (data){
180                subscriber = data;
181                commonevent.subscribe(subscriber, subscriberCallback);
182                console.info("====>subscribe ActsAccountChangeOnOff_0200 finish====")
183            });
184
185            var commonEventPublishData = {
186                code: 2
187            }
188            await sleep(500);
189            console.info("====>publish event account_on_change 0200====");
190            commonevent.publish("account_on_change", commonEventPublishData, publishCallback);
191        });
192
193        /*
194        * @tc.number    : ActsAccountChangeOnOff_0300
195        * @tc.name      : Subscribe/unsubscribe to the change event of application
196        * @tc.desc      : Received the account information change to the authorized account of the subscription to change
197        *                 the credential
198        */
199        it('ActsAccountChangeOnOff_0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL4, async function (done) {
200            await testInit();
201            await sleep(500)
202            console.info("====>ActsAccountChangeOnOff_0300 start====");
203            var appAccountManager = account.createAppAccountManager();
204            console.info("====>creat appAccountManager finish");
205            console.info("====>add account ActsAccountChangeOnOff_0300 start");
206            await appAccountManager.addAccount("onoff_credential");
207            console.info("====>enableAppAccess ActsAccountChangeOnOff_0300 start");
208            await appAccountManager.enableAppAccess("onoff_credential", "com.example.actsaccountsceneonoff");
209            async function deleteAccountCallback(err){
210                console.info("====>delete account 0300 err:" + JSON.stringify(err));
211                try {
212                    expect(err).assertEqual(null);
213                } catch (err) {
214                    console.info('====>Assert err: ' + JSON.stringify(err));
215                }
216                await sleep(500);
217                done();
218            }
219            function unSubscriberCallback(err){
220                console.info("====>unsubscribe 0300 err:" + JSON.stringify(err));
221                appAccountManager.deleteAccount("onoff_credential", deleteAccountCallback);
222            }
223            async function subscriberCallback(err, data){
224                console.info("====>subscriberCallback 0300 data:" + JSON.stringify(data));
225                try {
226                    expect(data.event).assertEqual("account_on_change_credential");
227                    if (data.data == "ON_SUCCESS") {
228                        console.info("====>setAccountCredential start====");
229                        await appAccountManager.setAccountCredential("onoff_credential", "credentialType", "credential");
230                        console.info("====>setAccountCredential finish====");
231                    } else {
232                        expect(data.data).assertEqual("SUCCESS");
233                        commonevent.unsubscribe(subscriber, unSubscriberCallback);
234                    }
235                } catch (err) {
236                    console.info('====>subscriberCallback err: ' + JSON.stringify(err));
237                }
238            }
239            async function publishCallback(err){
240                console.info("====>main publish call back err:" + JSON.stringify(err));
241            }
242            var commonEventSubscribeInfo = {
243                events: ["account_on_change_credential"]
244            }
245            await sleep(500)
246            var subscriber
247            await commonevent.createSubscriber(commonEventSubscribeInfo).then(function (data){
248                subscriber = data;
249                commonevent.subscribe(subscriber, subscriberCallback);
250                console.info("====>subscribe ActsAccountChangeOnOff_0300 finish====")
251            });
252
253            var commonEventPublishData = {
254                code: 3
255            }
256            await sleep(500);
257            console.info("====>publish event account_on_change 0300====");
258            commonevent.publish("account_on_change", commonEventPublishData, publishCallback);
259        });
260
261        /*
262        * @tc.number    : ActsAccountChangeOnOff_0400
263        * @tc.name      : Subscribe/unsubscribe to the change event of application
264        * @tc.desc      : Received the account information change to the authorized account of the subscription to delete
265        *                 authorized account
266        */
267        it('ActsAccountChangeOnOff_0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL4, async function (done) {
268            await testInit();
269            await sleep(500)
270            console.info("====>ActsAccountChangeOnOff_0400 start====");
271            var appAccountManager = account.createAppAccountManager();
272            console.info("====>creat appAccountManager finish");
273            console.info("====>add first account ActsAccountChangeOnOff_0400 start");
274            await appAccountManager.addAccount("onoff_deleteFir");
275            console.info("====>add second account ActsAccountChangeOnOff_0400 start");
276            await appAccountManager.addAccount("onoff_deleteSec");
277            console.info("====>enableAppAccess first ActsAccountChangeOnOff_0400 start");
278            await appAccountManager.enableAppAccess("onoff_deleteFir", "com.example.actsaccountsceneonoff");
279            console.info("====>enableAppAccess second ActsAccountChangeOnOff_0400 start");
280            await appAccountManager.enableAppAccess("onoff_deleteSec", "com.example.actsaccountsceneonoff");
281            async function deleteAccountCallback(err){
282                console.info("====>delete account 0400 err:" + JSON.stringify(err));
283                try {
284                    expect(err).assertEqual(null);
285                } catch (err) {
286                    console.info('====>Assert err: ' + JSON.stringify(err));
287                }
288                await sleep(500);
289                done();
290            }
291            function unSubscriberCallback(err){
292                console.info("====>unsubscribe 0400 err:" + JSON.stringify(err));
293                appAccountManager.deleteAccount("onoff_deleteFir", deleteAccountCallback);
294            }
295            async function subscriberCallback(err, data){
296                console.info("====>subscriberCallback 0400 data:" + JSON.stringify(data));
297                try {
298                    expect(data.event).assertEqual("account_on_delete_another");
299                    if (data.data == "ON_SUCCESS") {
300                        console.info("====>deleteAccount start====");
301                        await appAccountManager.deleteAccount("onoff_deleteSec");
302                        console.info("====>deleteAccount finish====");
303                    } else {
304                        expect(data.data).assertEqual("SUCCESS");
305                        commonevent.unsubscribe(subscriber, unSubscriberCallback);
306                    }
307                } catch (err) {
308                    console.info('====>subscriberCallback err: ' + JSON.stringify(err));
309                }
310            }
311            async function publishCallback(err){
312                console.info("====>main publish call back err:" + JSON.stringify(err));
313            }
314            var commonEventSubscribeInfo = {
315                events: ["account_on_delete_another"]
316            }
317            await sleep(500)
318            var subscriber
319            await commonevent.createSubscriber(commonEventSubscribeInfo).then(function (data){
320                subscriber = data;
321                commonevent.subscribe(subscriber, subscriberCallback);
322                console.info("====>subscribe ActsAccountChangeOnOff_0400 finish====")
323            });
324
325            var commonEventPublishData = {
326                code: 4
327            }
328            await sleep(500);
329            console.info("====>publish event account_on_change 0400====");
330            commonevent.publish("account_on_change", commonEventPublishData, publishCallback);
331        });
332
333        /*
334        * @tc.number    : ActsAccountChangeOnOff_0500
335        * @tc.name      : Subscribe/unsubscribe to the change event of application
336        * @tc.desc      : Received the account information change to the authorized account of the subscription to delete
337        *                 the only authorized account
338        */
339        it('ActsAccountChangeOnOff_0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL4, async function (done) {
340            await testInit();
341            await sleep(500)
342            console.info("====>ActsAccountChangeOnOff_0500 start====");
343            var appAccountManager = account.createAppAccountManager();
344            console.info("====>creat appAccountManager finish");
345            console.info("====>add account ActsAccountChangeOnOff_0500 start");
346            await appAccountManager.addAccount("onoff_delete");
347            console.info("====>enableAppAccess ActsAccountChangeOnOff_0500 start");
348            await appAccountManager.enableAppAccess("onoff_delete", "com.example.actsaccountsceneonoff");
349            async function deleteAccountCallback(err){
350                console.info("====>delete account 0500 err:" + JSON.stringify(err));
351                await sleep(500);
352                done();
353            }
354            function unSubscriberCallback(err){
355                console.info("====>unsubscribe 0500 err:" + JSON.stringify(err));
356                appAccountManager.deleteAccount("onoff_delete", deleteAccountCallback);
357            }
358            async function subscriberCallback(err, data){
359                console.info("====>subscriberCallback 0500 data:" + JSON.stringify(data));
360                try {
361                    expect(data.event).assertEqual("account_on_change_delete");
362                    if (data.data == "ON_SUCCESS") {
363                        console.info("====>deleteAccount start====");
364                        await appAccountManager.deleteAccount("onoff_delete");
365                        console.info("====>deleteAccount finish====");
366                    } else {
367                        expect(data.data).assertEqual("SUCCESS");
368                        commonevent.unsubscribe(subscriber, unSubscriberCallback);
369                    }
370                } catch (err) {
371                    console.info('====>subscriberCallback err: ' + JSON.stringify(err));
372                }
373            }
374            async function publishCallback(err){
375                console.info("====>main publish call back err:" + JSON.stringify(err));
376            }
377            var commonEventSubscribeInfo = {
378                events: ["account_on_change_delete"]
379            }
380            await sleep(500)
381            var subscriber
382            await commonevent.createSubscriber(commonEventSubscribeInfo).then(function (data){
383                subscriber = data;
384                commonevent.subscribe(subscriber, subscriberCallback);
385                console.info("====>subscribe ActsAccountChangeOnOff_0500 finish====")
386            });
387
388            var commonEventPublishData = {
389                code: 5
390            }
391            await sleep(500);
392            console.info("====>publish event account_on_change 0500====");
393            commonevent.publish("account_on_change", commonEventPublishData, publishCallback);
394        });
395
396        /*
397        * @tc.number    : ActsAccountChangeOnOff_0600
398        * @tc.name      : Subscribe/unsubscribe to the change event of application
399        * @tc.desc      : Received the account information change to the authorized account of the subscription to cancel
400        *                 authorized account
401        */
402        it('ActsAccountChangeOnOff_0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL4, async function (done) {
403            await testInit();
404            await sleep(500)
405            console.info("====>ActsAccountChangeOnOff_0600 start====");
406            var appAccountManager = account.createAppAccountManager();
407            console.info("====>creat appAccountManager finish");
408            console.info("====>add first account ActsAccountChangeOnOff_0600 start");
409            await appAccountManager.addAccount("onoff_enableFir");
410            console.info("====>add second account ActsAccountChangeOnOff_0600 start");
411            await appAccountManager.addAccount("onoff_enableSec");
412            console.info("====>enableAppAccess first ActsAccountChangeOnOff_0600 start");
413            await appAccountManager.enableAppAccess("onoff_enableFir", "com.example.actsaccountsceneonoff");
414            console.info("====>enableAppAccess second ActsAccountChangeOnOff_0600 start");
415            await appAccountManager.enableAppAccess("onoff_enableSec", "com.example.actsaccountsceneonoff");
416            function deleteAccountCallback(err){
417                console.info("====>delete first account 0600 err:" + JSON.stringify(err));
418                try {
419                    expect(err).assertEqual(null);
420                } catch (err) {
421                    console.info('====>Assert err: ' + JSON.stringify(err));
422                }
423                appAccountManager.deleteAccount("onoff_enableSec", async (err)=>{
424                    console.info("====>delete second account 0600 err:" + JSON.stringify(err));
425                    try {
426                        expect(err).assertEqual(null);
427                    } catch (err) {
428                        console.info('====>Assert err: ' + JSON.stringify(err));
429                    }
430                    await sleep(500);
431                    done();
432                });
433            }
434            function unSubscriberCallback(err){
435                console.info("====>unsubscribe 0600 err:" + JSON.stringify(err));
436                appAccountManager.deleteAccount("onoff_enableFir", deleteAccountCallback);
437            }
438            async function subscriberCallback(err, data){
439                console.info("====>subscriberCallback 0600 data:" + JSON.stringify(data));
440                try {
441                    expect(data.event).assertEqual("account_on_disable_another");
442                    if (data.data == "ON_SUCCESS") {
443                        console.info("====>disableAppAccess start====");
444                        await appAccountManager.disableAppAccess("onoff_enableSec", "com.example.actsaccountsceneonoff");
445                        console.info("====>disableAppAccess finish====");
446                    } else {
447                        expect(data.data).assertEqual("SUCCESS");
448                        commonevent.unsubscribe(subscriber, unSubscriberCallback);
449                    }
450                } catch (err) {
451                    console.info('====>subscriberCallback err: ' + JSON.stringify(err));
452                }
453            }
454            async function publishCallback(err){
455                console.info("====>main publish call back err:" + JSON.stringify(err));
456            }
457            var commonEventSubscribeInfo = {
458                events: ["account_on_disable_another"]
459            }
460            await sleep(500)
461            var subscriber
462            await commonevent.createSubscriber(commonEventSubscribeInfo).then(function (data){
463                subscriber = data;
464                commonevent.subscribe(subscriber, subscriberCallback);
465                console.info("====>subscribe ActsAccountChangeOnOff_0600 finish====")
466            });
467
468            var commonEventPublishData = {
469                code: 6
470            }
471            await sleep(500);
472            console.info("====>publish event account_on_change 0600====");
473            commonevent.publish("account_on_change", commonEventPublishData, publishCallback);
474        });
475
476        /*
477        * @tc.number    : ActsAccountChangeOnOff_0700
478        * @tc.name      : Subscribe/unsubscribe to the change event of application
479        * @tc.desc      : Received the account information change to the authorized account of the subscription to cancel
480        *                 the only authorized account
481        */
482        it('ActsAccountChangeOnOff_0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL4, async function (done) {
483            await testInit();
484            await sleep(500)
485            console.info("====>ActsAccountChangeOnOff_0700 start====");
486            var appAccountManager = account.createAppAccountManager();
487            console.info("====>creat appAccountManager finish");
488            console.info("====>add account ActsAccountChangeOnOff_0700 start");
489            await appAccountManager.addAccount("onoff_disable");
490            console.info("====>enableAppAccess ActsAccountChangeOnOff_0700 start");
491            await appAccountManager.enableAppAccess("onoff_disable", "com.example.actsaccountsceneonoff");
492            async function deleteAccountCallback(err){
493                console.info("====>delete account 0700 err:" + JSON.stringify(err));
494                try {
495                    expect(err).assertEqual(null);
496                } catch (err) {
497                    console.info('====>Assert err: ' + JSON.stringify(err));
498                }
499                await sleep(500);
500                done();
501            }
502            function unSubscriberCallback(err){
503                console.info("====>unsubscribe 0700 err:" + JSON.stringify(err));
504                appAccountManager.deleteAccount("onoff_disable", deleteAccountCallback);
505            }
506            async function subscriberCallback(err, data){
507                console.info("====>subscriberCallback 0700 data:" + JSON.stringify(data));
508                try {
509                    expect(data.event).assertEqual("account_on_change_disable");
510                    if (data.data == "ON_SUCCESS") {
511                        console.info("====>disableAppAccess start====");
512                        await appAccountManager.disableAppAccess("onoff_disable", "com.example.actsaccountsceneonoff");
513                        console.info("====>disableAppAccess finish====");
514                    } else {
515                        expect(data.data).assertEqual("SUCCESS");
516                        commonevent.unsubscribe(subscriber, unSubscriberCallback);
517                    }
518                } catch (err) {
519                    console.info('====>subscriberCallback err: ' + JSON.stringify(err));
520                }
521            }
522            async function publishCallback(err){
523                console.info("====>main publish call back err:" + JSON.stringify(err));
524            }
525            var commonEventSubscribeInfo = {
526                events: ["account_on_change_disable"]
527            }
528            await sleep(500)
529            var subscriber
530            await commonevent.createSubscriber(commonEventSubscribeInfo).then(function (data){
531                subscriber = data;
532                commonevent.subscribe(subscriber, subscriberCallback);
533                console.info("====>subscribe ActsAccountChangeOnOff_0700 finish====")
534            });
535
536            var commonEventPublishData = {
537                code: 7
538            }
539            await sleep(500);
540            console.info("====>publish event account_on_change 0700====");
541            commonevent.publish("account_on_change", commonEventPublishData, publishCallback);
542        });
543
544        /*
545        * @tc.number    : ActsAccountChangeOnOff_0800
546        * @tc.name      : Subscribe/unsubscribe to the change event of application
547        * @tc.desc      : Receive account information after the app subscribes to itself and changes additional information
548        */
549        it('ActsAccountChangeOnOff_0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
550            console.info("====>ActsAccountChangeOnOff_0800 start====");
551            let dataMap = new Map();
552            var appAccountManager = account.createAppAccountManager();
553            console.info("====>creat appAccountManager finish");
554            console.info("====>add account ActsAccountChangeOnOff_0800 start");
555            await appAccountManager.addAccount("onoff_self");
556            console.info("====>on ActsAccountChangeOnOff_0800 start");
557            function changeOnCallback(data){
558                console.info("====>receive change 0800 data:" + JSON.stringify(data));
559                console.info("====>data.length:" + data.length);
560                for (let i = 0, len = data.length; i < len; i++) {
561                    dataMap.set(data[i].name, data[i].owner)
562                }
563                expect(dataMap.has("onoff_self")).assertTrue();
564                if (dataMap.has("onoff_self")) {
565                    let data = dataMap.get("onoff_self");
566                    console.info("====>the account owner is: " + data);
567                    expect(data).assertEqual("com.example.actsaccounttest");
568                }
569                appAccountManager.off('change', function (){
570                    console.info("====>off ActsAccountChangeOnOff_0800 finish====");
571                    appAccountManager.deleteAccount("onoff_self", async (err)=>{
572                        console.info("====>delete account ActsAccountChangeOnOff_0800 err:" + JSON.stringify(err));
573                        try {
574                            expect(err).assertEqual(null);
575                        } catch (err) {
576                            console.info('====>Assert err: ' + JSON.stringify(err));
577                        }
578                        console.info("====>ActsAccountChangeOnOff_0800 end====");
579                        await sleep(500);
580                        done();
581                    });
582                });
583            }
584            try{
585                appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
586            }
587            catch(err){
588                console.error("====>on ActsAccountChangeOnOff_0800 err:" + JSON.stringify(err));
589                expect().assertFail();
590                done();
591            }
592            console.info("====>setAccountExtraInfo start====");
593            try{
594                await appAccountManager.setAccountExtraInfo("onoff_self", "change_extra");
595            }
596            catch(err){
597                console.error("====>setAccountExtraInfo fail err:" + JSON.stringify(err));
598                expect().assertFail();
599                done();
600            }
601        });
602
603        /*
604        * @tc.number    : ActsAccountChangeOnOff_0900
605        * @tc.name      : Subscribe/unsubscribe to the change event of application
606        * @tc.desc      : Receiving account information after adding two accounts to the app, subscribing to itself,
607        *                 and changing one of the associatal data
608        */
609        it('ActsAccountChangeOnOff_0900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
610            console.info("====>ActsAccountChangeOnOff_0900 start====");
611            let dataMap = new Map();
612            var appAccountManager = account.createAppAccountManager();
613            console.info("====>creat appAccountManager finish");
614            console.info("====>add first account ActsAccountChangeOnOff_0900 start");
615            await appAccountManager.addAccount("onoff_self_first");
616            console.info("====>add second account ActsAccountChangeOnOff_0900 start");
617            await appAccountManager.addAccount("onoff_self_second");
618            console.info("====>on ActsAccountChangeOnOff_0900 start");
619            function changeOnCallback(data){
620                console.info("====>receive change 0900 data:" + JSON.stringify(data));
621                console.info("====>data.length:" + data.length);
622                for (let i = 0, len = data.length; i < len; i++) {
623                    dataMap.set(data[i].name, data[i].owner)
624                }
625                expect(dataMap.has("onoff_self_first")).assertTrue();
626                if (dataMap.has("onoff_self_first")) {
627                    let data = dataMap.get("onoff_self_first");
628                    console.info("====>the account owner is: " + data);
629                    expect(data).assertEqual("com.example.actsaccounttest");
630                }
631                expect(dataMap.has("onoff_self_second")).assertTrue();
632                if (dataMap.has("onoff_self_second")) {
633                    let data = dataMap.get("onoff_self_second");
634                    console.info("====>the account owner is: " + data);
635                    expect(data).assertEqual("com.example.actsaccounttest");
636                }
637                appAccountManager.off('change', function (){
638                    console.info("====>off ActsAccountChangeOnOff_0900 finish====");
639                    appAccountManager.deleteAccount("onoff_self_first", (err)=>{
640                        console.info("====>delete first account 0900 err:" + JSON.stringify(err));
641                        try {
642                            expect(err).assertEqual(null);
643                        } catch (err) {
644                            console.info('====>Assert err: ' + JSON.stringify(err));
645                        }
646                        appAccountManager.deleteAccount("onoff_self_second", async (err)=>{
647                            console.info("====>delete second account 0900 err:" + JSON.stringify(err));
648                            try {
649                                expect(err).assertEqual(null);
650                            } catch (err) {
651                                console.info('====>Assert err: ' + JSON.stringify(err));
652                            }
653                            console.info("====>ActsAccountChangeOnOff_0900 end====");
654                            await sleep(500);
655                            done();
656                        });
657                    });
658                });
659            }
660            try{
661                appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
662            }
663            catch(err){
664                console.error("====>on ActsAccountChangeOnOff_0900 err:" + JSON.stringify(err));
665                expect().assertFail();
666                done();
667            }
668            console.info("====>setAssociatedData start====");
669            try{
670                await appAccountManager.setAssociatedData("onoff_self_second", "change_key", "change_value");
671            }
672            catch(err){
673                console.error("====>setAssociatedData fail err:" + JSON.stringify(err));
674                expect().assertFail();
675                done();
676            }
677        });
678
679        /*
680        * @tc.number    : ActsAccountChangeOnOff_1000
681        * @tc.name      : Subscribe/unsubscribe to the change event of application
682        * @tc.desc      : Repeat subscription account information changes, the subscription behavior is independent
683        */
684        it('ActsAccountChangeOnOff_1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
685            console.info("====>ActsAccountChangeOnOff_1000 start====");
686            let dataMapFir = new Map();
687            let dataMapSec = new Map();
688            var appAccountManager = account.createAppAccountManager();
689            console.info("====>creat appAccountManager finish");
690            console.info("====>add account ActsAccountChangeOnOff_1000 start");
691            await appAccountManager.addAccount("onoff_twice");
692            console.info("====>on ActsAccountChangeOnOff_1000 start");
693            var twiceSign = 0;
694            function changeOnFirstCallback(data){
695                console.info("====>first receive change 1000 data:" + JSON.stringify(data));
696                console.info("====>data.length:" + data.length);
697                for (let i = 0, len = data.length; i < len; i++) {
698                    dataMapFir.set(data[i].name, data[i].owner)
699                }
700                expect(dataMapFir.has("onoff_twice")).assertTrue();
701                if (dataMapFir.has("onoff_twice")) {
702                    let data = dataMapFir.get("onoff_twice");
703                    console.info("====>the account owner is: " + data);
704                    expect(data).assertEqual("com.example.actsaccounttest");
705                }
706                twiceSign = twiceSign + 1;
707            }
708            function changeOnSecondCallback(data){
709                console.info("====>second receive change 1000 data:" + JSON.stringify(data));
710                console.info("====>data.length:" + data.length);
711                for (let i = 0, len = data.length; i < len; i++) {
712                    dataMapSec.set(data[i].name, data[i].owner)
713                }
714                expect(dataMapSec.has("onoff_twice")).assertTrue();
715                if (dataMapSec.has("onoff_twice")) {
716                    let data = dataMapSec.get("onoff_twice");
717                    console.info("====>the account owner is: " + data);
718                    expect(data).assertEqual("com.example.actsaccounttest");
719                }
720                twiceSign = twiceSign + 1;
721            }
722            try{
723                appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnFirstCallback);
724                appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnSecondCallback);
725            } catch(err){
726                console.error("====>on ActsAccountChangeOnOff_1000 err:" + JSON.stringify(err));
727                expect().assertFail();
728                done();
729            }
730            console.info("====>setAccountExtraInfo start====");
731            try{
732                await appAccountManager.setAccountExtraInfo("onoff_twice", "change_extra");
733                await sleep(500)
734                console.info("====>off start====");
735                appAccountManager.off('change', function (){
736                    console.info("====>off ActsAccountChangeOnOff_1000 finish====");
737                    appAccountManager.deleteAccount("onoff_twice", async (err)=>{
738                        console.info("====>delete account ActsAccountChangeOnOff_1000 err:" + JSON.stringify(err));
739                        try {
740                            expect(err).assertEqual(null);
741                            expect(twiceSign).assertEqual(2);
742                        } catch (err) {
743                            console.info('====>Assert err: ' + JSON.stringify(err));
744                        }
745                        console.info("====>ActsAccountChangeOnOff_1000 end====");
746                        await sleep(500);
747                        done();
748                    })
749                })
750            } catch(err){
751                console.error("====>setAccountExtraInfo fail err:" + JSON.stringify(err));
752                expect().assertFail();
753                done();
754            }
755        });
756
757        /*
758        * @tc.number    : ActsAccountChangeOnOff_1100
759        * @tc.name      : Subscribe/unsubscribe to the change event of application
760        * @tc.desc      : Subscription account information changes, where the bundleName in the parameter owners is
761        *                 duplicated
762        */
763        it('ActsAccountChangeOnOff_1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
764            console.info("====>ActsAccountChangeOnOff_1100 start====");
765            let dataMap = new Map();
766            var appAccountManager = account.createAppAccountManager();
767            console.info("====>creat appAccountManager finish");
768            console.info("====>add account ActsAccountChangeOnOff_1100 start");
769            await appAccountManager.addAccount("onoff_same");
770            console.info("====>on ActsAccountChangeOnOff_1100 start");
771            var sameSign = 0;
772            function onCallBack(data){
773                console.info("====>receive change 1100 data:" + JSON.stringify(data));
774                sameSign = sameSign + 1;
775                console.info("====>data.length:" + data.length);
776                for (let i = 0, len = data.length; i < len; i++) {
777                    dataMap.set(data[i].name, data[i].owner)
778                }
779                expect(dataMap.has("onoff_same")).assertTrue();
780                if (dataMap.has("onoff_same")) {
781                    let data = dataMap.get("onoff_same");
782                    console.info("====>the account owner is: " + data);
783                    expect(data).assertEqual("com.example.actsaccounttest");
784                }
785            }
786            try{
787                appAccountManager.on('change', ["com.example.actsaccounttest", "com.example.actsaccounttest"], onCallBack);
788            }
789            catch(err){
790                console.error("====>on ActsAccountChangeOnOff_1100 err:" + JSON.stringify(err));
791                expect().assertFail();
792                done();
793            }
794            console.info("====>setAccountExtraInfo start====");
795            try{
796                await appAccountManager.setAccountExtraInfo("onoff_same", "change_extra");
797                await sleep(500)
798                console.info("====>off 1100 start====");
799                appAccountManager.off('change', function (){
800                    console.info("====>off ActsAccountChangeOnOff_1100 finish====");
801                    appAccountManager.deleteAccount("onoff_same", async (err)=>{
802                        console.info("====>delete account ActsAccountChangeOnOff_1100 err:" + JSON.stringify(err));
803                        try {
804                            expect(err).assertEqual(null);
805                            expect(sameSign).assertEqual(1);
806                        } catch (err) {
807                            console.info('====>Assert err: ' + JSON.stringify(err));
808                        }
809                        console.info("====>ActsAccountChangeOnOff_1100 end====");
810                        await sleep(500);
811                        done();
812                    });
813                });
814            } catch(err){
815                console.error("====>setAccountExtraInfo fail err:" + JSON.stringify(err));
816                expect().assertFail();
817                done();
818            }
819        });
820
821        /*
822        * @tc.number    : ActsAccountChangeOnOff_1200
823        * @tc.name      : Subscribe/unsubscribe to the change event of application
824        * @tc.desc      : Repeatedly cancel the subscription after the subscription account information is changed
825        */
826        it('ActsAccountChangeOnOff_1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
827            console.info("====>ActsAccountChangeOnOff_1200 start====");
828            let dataMap = new Map();
829            var appAccountManager = account.createAppAccountManager();
830            console.info("====>creat appAccountManager finish");
831            console.info("====>add account ActsAccountChangeOnOff_1200 start");
832            await appAccountManager.addAccount("onoff_repeatoff");
833            console.info("====>on ActsAccountChangeOnOff_1200 start");
834            function changeOnCallback(data){
835                console.info("====>receive change 1200 data:" + JSON.stringify(data));
836                console.info("====>data.length:" + data.length);
837                for (let i = 0, len = data.length; i < len; i++) {
838                    dataMap.set(data[i].name, data[i].owner)
839                }
840                expect(dataMap.has("onoff_repeatoff")).assertTrue();
841                if (dataMap.has("onoff_repeatoff")) {
842                    let data = dataMap.get("onoff_repeatoff");
843                    console.info("====>the account owner is: " + data);
844                    expect(data).assertEqual("com.example.actsaccounttest");
845                }
846            }
847            try{
848                appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
849            }
850            catch(err){
851                console.error("====>on ActsAccountChangeOnOff_1200 err:" + JSON.stringify(err));
852                expect().assertFail();
853                done();
854            }
855            console.info("====>setAccountExtraInfo start====");
856            try{
857                await appAccountManager.setAccountExtraInfo("onoff_repeatoff", "change_extra");
858                await sleep(500)
859                console.info("====>off start====");
860                appAccountManager.off('change', function (){
861                    console.info("====>first off ActsAccountChangeOnOff_1200 finish====");
862                    appAccountManager.off('change', function (){
863                        console.info("====>second off ActsAccountChangeOnOff_1200 finish====");
864                        console.info("====>delete account 1200 start====");
865                        appAccountManager.deleteAccount("onoff_repeatoff", async (err)=>{
866                            console.info("====>delete account ActsAccountChangeOnOff_1200 err:" + JSON.stringify(err));
867                            try {
868                                expect(err).assertEqual(null);
869                            } catch (err) {
870                                console.info('====>Assert err: ' + JSON.stringify(err));
871                            }
872                            console.info("====>ActsAccountChangeOnOff_1200 end====");
873                            await sleep(500);
874                            done();
875                        })
876                    })
877                })
878            } catch(err){
879                console.error("====>setAccountExtraInfo fail err:" + JSON.stringify(err));
880                expect().assertFail();
881                done();
882            }
883        });
884
885        /*
886        * @tc.number    : ActsAccountChangeOnOff_1300
887        * @tc.name      : Subscribe/unsubscribe to the change event of application
888        * @tc.desc      : There is an unauthorized bundleName in the subscription parameter owners array, and the
889        *                 subscription fails
890        */
891        it('ActsAccountChangeOnOff_1300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
892            console.info("====>ActsAccountChangeOnOff_1300 start====");
893            var appAccountManager = account.createAppAccountManager();
894            console.info("====>creat appAccountManager finish");
895            console.info("====>add account ActsAccountChangeOnOff_1300 start");
896            await appAccountManager.addAccount("onoff_same");
897            console.info("====>on ActsAccountChangeOnOff_1300 start");
898            function changeOnCallBack(data){
899                console.info("====>receive change 1300 data:" + JSON.stringify(data));
900                expect().assertFail();
901                done();
902            }
903            var unauthorizedBundle = "com.example.actsaccountsceneonoff";
904            try{
905                appAccountManager.on('change', ["com.example.actsaccounttest", unauthorizedBundle], changeOnCallBack);
906            } catch(err){
907                console.error("====>on ActsAccountChangeOnOff_1300 err:" + JSON.stringify(err));
908                expect(err.code).assertEqual(201);
909            }
910            console.info("====>setAccountExtraInfo start====");
911            try{
912                await appAccountManager.setAccountExtraInfo("onoff_same", "change_extra");
913                await sleep(500)
914                console.info("====>delete account 1300 start====");
915                appAccountManager.deleteAccount("onoff_same", async (err)=>{
916                    console.info("====>delete account ActsAccountChangeOnOff_1300 err:" + JSON.stringify(err));
917                    try {
918                        expect(err).assertEqual(null);
919                    } catch (err) {
920                        console.info('====>Assert err: ' + JSON.stringify(err));
921                    }
922                    console.info("====>ActsAccountChangeOnOff_1300 end====");
923                    await sleep(500);
924                    done();
925                });
926            } catch(err){
927                console.error("====>setAccountExtraInfo fail err:" + JSON.stringify(err));
928                expect().assertFail();
929                done();
930            }
931        });
932
933        /*
934        * @tc.number    : ActsAccountChangeOnOff_1400
935        * @tc.name      : Subscribe/unsubscribe to the change event of application
936        * @tc.desc      : There is a bundleName that does not exist in the subscription parameter owners array, and the
937        *                 subscription fails
938        */
939        it('ActsAccountChangeOnOff_1400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
940            console.info("====>ActsAccountChangeOnOff_1400 start====");
941            var appAccountManager = account.createAppAccountManager();
942            console.info("====>creat appAccountManager finish");
943            console.info("====>add account ActsAccountChangeOnOff_1400 start");
944            await appAccountManager.addAccount("onoff_same");
945            console.info("====>on ActsAccountChangeOnOff_1400 start");
946            function changeOnCallBack(data){
947                console.info("====>receive change 1400 data:" + JSON.stringify(data));
948                appAccountManager.off('change');
949            }
950            var nonexistentBundle = "com.example.actsaccountnoneexistent";
951            try{
952                appAccountManager.on('change', ["com.example.actsaccounttest", nonexistentBundle], changeOnCallBack);
953            } catch(err){
954                console.error("====>on ActsAccountChangeOnOff_1400 err:" + JSON.stringify(err));
955                expect(err).assertFail();
956            }
957            console.info("====>setAccountExtraInfo start====");
958            try{
959                await appAccountManager.setAccountExtraInfo("onoff_same", "change_extra");
960                await sleep(500)
961                console.info("====>delete account 1400 start====");
962                appAccountManager.deleteAccount("onoff_same", async (err)=>{
963                    console.info("====>delete account ActsAccountChangeOnOff_1400 err:" + JSON.stringify(err));
964                    try {
965                        expect(err).assertEqual(null);
966                    } catch (err) {
967                        console.info('====>Assert err: ' + JSON.stringify(err));
968                    }
969                    console.info("====>ActsAccountChangeOnOff_1400 end====");
970                    await sleep(500);
971                    done();
972                });
973            } catch(err){
974                console.error("====>setAccountExtraInfo fail err:" + JSON.stringify(err));
975                expect().assertFail();
976                done();
977            }
978        })
979    })
980}