diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/AppAccess.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/AppAccess.test.js index 1ad3cc28cd6f7a7edc154fa14dfcee32b2c34adc..55e0d7cf6592e4601653974f486dec4887435ec1 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/AppAccess.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/AppAccess.test.js @@ -19,14 +19,13 @@ const TIMEOUT = 5000; const STRCOUNT = 1025; const EACHTIMEOUT = 500; describe('ActsAccountAppAccess', function () { - function sleep(delay) { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, delay) - }).then(() => { - console.info(`sleep #{time} over ...`) - }) + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } beforeAll(async function (done) { diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/AssociatedData.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/AssociatedData.test.js index 0293a194e6132a6eeb3894e2728875bbbac7f55d..1c902ffa6733c99a2013295f1640e666d9df8639 100644 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/AssociatedData.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/AssociatedData.test.js @@ -18,14 +18,13 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; const EACHTIMEOUT = 500; describe('ActsAccountAssociatedData', function () { - function sleep(delay) { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, delay) - }).then(() => { - console.info(`sleep #{time} over ...`) - }) + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } beforeAll(async function (done) { diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/CreatManager.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/CreatManager.test.js index c8abef7bb902a1ff7226e0f0b2b24221462dbd8e..177d97a9f193a1f115a43ec96c8102283ee040e1 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/CreatManager.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/CreatManager.test.js @@ -17,14 +17,13 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; describe('ActsCreatAppAccountManager', function () { - function sleep(delay) { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, delay) - }).then(() => { - console.info(`sleep #{time} over ...`) - }) + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } beforeAll(async function (done) { diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/Credential.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/Credential.test.js index a44b879c12289ed6073a6caf948813df23ff586e..02adbfe768e5bf82338911970e5206781e806154 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/Credential.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/Credential.test.js @@ -18,14 +18,13 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; const EACHTIMEOUT = 500; describe('ActsAccountCredential', function () { - function sleep(delay) { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, delay) - }).then(() => { - console.info(`sleep #{time} over ...`) - }) + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } beforeAll(async function (done) { diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/DeleteAccount.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/DeleteAccount.test.js index e28fd27f3fc4ce25c137d9d23913b343c0e37464..e2f7ac05a9fdff95040cf23b18ccbdc26cf6eb59 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/DeleteAccount.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/DeleteAccount.test.js @@ -18,14 +18,13 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const NAMELIMIT = 512; const TIMEOUT = 5000; describe('ActsAccountDeleteAccount', function () { - function sleep(delay) { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, delay) - }).then(() => { - console.info(`sleep #{time} over ...`) - }) + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } beforeAll(async function (done) { diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/ExtraInfo.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/ExtraInfo.test.js index 8602ef30378a85e78d913515e26a0f8116f8e804..a9daaf55d991a2fb6810cfc43ece60c9a169eadd 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/ExtraInfo.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/ExtraInfo.test.js @@ -18,14 +18,13 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; const EACHTIMEOUT = 500; describe('ActsAccountSetGetExtraInfo', function () { - function sleep(delay) { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, delay) - }).then(() => { - console.info(`sleep #{time} over ...`) - }) + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } beforeAll(async function (done) { 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 0750ed1517654701d7437d5c4465b7500739e467..36143a0da7fe0451b35ba39a8da218716bcc6850 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 @@ -18,15 +18,15 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; const ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED = 4521993; describe('ActsAccountNoPermission', function () { - function sleep(delay) { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, delay) - }).then(() => { - console.info(`sleep #{time} over ...`) - }) + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } + beforeAll(async function (done) { console.debug("====>beforeAll start===="); await sleep(TIMEOUT); diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js index c2d9797e47f9cc04615fc87dc1b4bd5b1f7459c6..9580b79053f3f1eb67a94adc85dc52343a333531 100644 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js @@ -29,23 +29,25 @@ const OWNERLENGTHLIMIT = 1024; const OWNERSELF = "com.example.actsaccounttest"; describe('ActsAccountOAuthToken', function () { - function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }); beforeEach(async function (done) { console.debug("====>beforeAll enter===="); - sleep(EACHTIMEOUT); + await sleep(EACHTIMEOUT); done(); }); 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 2328576d9aa9bbbc548ee9c1bdea5e1067dca003..1eadd4f1aa9bd1e4bdc0580528acc2b5ce1f7bc0 100644 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js @@ -20,15 +20,15 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; describe('ActsAccountChangeOnOff', async function () { - function sleep(delay) { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, delay) - }).then(() => { - console.info(`sleep #{time} over ...`) - }) + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } + beforeAll(async function (done) { console.debug("====>startAbility start===="); await featureAbility.startAbility( @@ -82,20 +82,19 @@ describe('ActsAccountChangeOnOff', async function () { commonevent.unsubscribe(subscriber, unSubscriberCallback); appAccountManager.disableAppAccess("changeonoff_extra", "com.example.actsaccountsceneonoff", disCallback); } - function publishCallback(err){ + async function publishCallback(err){ console.debug("====>publish call back err:" + JSON.stringify(err)); - setTimeout(async function (){ - console.debug("====>setAccountExtraInfo start===="); - try{ - await appAccountManager.setAccountExtraInfo("changeonoff_extra", "change_extra"); - } - catch(err){ - console.error("====>setAccountExtraInfo fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>setAccountExtraInfo finish===="); - }, 500) + await sleep(500); + console.debug("====>setAccountExtraInfo start===="); + try{ + await appAccountManager.setAccountExtraInfo("changeonoff_extra", "change_extra"); + } + catch(err){ + console.error("====>setAccountExtraInfo fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>setAccountExtraInfo finish===="); } var commonEventSubscribeInfo = { events: ["account_on_change_extra"] @@ -110,10 +109,9 @@ describe('ActsAccountChangeOnOff', async function () { var commonEventPublishData = { code: 1 } - setTimeout(function (){ - console.debug("====>publish event account_on_change 0100===="); - commonevent.publish("account_on_change", commonEventPublishData, publishCallback); - }, 1000); + await sleep(1000) + console.debug("====>publish event account_on_change 0100===="); + commonevent.publish("account_on_change", commonEventPublishData, publishCallback); }); /* @@ -145,20 +143,19 @@ describe('ActsAccountChangeOnOff', async function () { commonevent.unsubscribe(subscriber, unSubscriberCallback); appAccountManager.deleteAccount("onoff_associatedata", deleteAccountCallback); } - function publishCallback(err){ + async function publishCallback(err){ console.debug("====>publish call back err:" + JSON.stringify(err)); - setTimeout(async function (){ - console.debug("====>setAssociatedData start===="); - try{ - await appAccountManager.setAssociatedData("onoff_associatedata", "change_key", "change_value"); - } - catch(err){ - console.error("====>setAssociatedData fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>setAssociatedData finish===="); - }, 500) + await sleep(500) + console.debug("====>setAssociatedData start===="); + try{ + await appAccountManager.setAssociatedData("onoff_associatedata", "change_key", "change_value"); + } + catch(err){ + console.error("====>setAssociatedData fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>setAssociatedData finish===="); } var commonEventSubscribeInfo = { events: ["account_on_change_associatedata"] @@ -173,10 +170,9 @@ describe('ActsAccountChangeOnOff', async function () { var commonEventPublishData = { code: 2 } - setTimeout(function (){ - console.debug("====>publish event account_on_change 0200===="); - commonevent.publish("account_on_change", commonEventPublishData, publishCallback); - }, 1000); + await sleep(1000) + console.debug("====>publish event account_on_change 0200===="); + commonevent.publish("account_on_change", commonEventPublishData, publishCallback); }); /* @@ -208,20 +204,19 @@ describe('ActsAccountChangeOnOff', async function () { commonevent.unsubscribe(subscriber, unSubscriberCallback); appAccountManager.deleteAccount("onoff_credential", deleteAccountCallback); } - function publishCallback(err){ + async function publishCallback(err){ console.debug("====>publish call back err:" + JSON.stringify(err)); - setTimeout(async function (){ - console.debug("====>setAccountCredential start===="); - try{ - await appAccountManager.setAccountCredential("onoff_credential", "credentialType", "credential"); - } - catch(err){ - console.error("====>setAccountCredential fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>setAccountCredential finish===="); - }, 500) + await sleep(500) + console.debug("====>setAccountCredential start===="); + try{ + await appAccountManager.setAccountCredential("onoff_credential", "credentialType", "credential"); + } + catch(err){ + console.error("====>setAccountCredential fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>setAccountCredential finish===="); } var commonEventSubscribeInfo = { events: ["account_on_change_credential"] @@ -236,10 +231,9 @@ describe('ActsAccountChangeOnOff', async function () { var commonEventPublishData = { code: 3 } - setTimeout(function (){ - console.debug("====>publish event account_on_change 0300===="); - commonevent.publish("account_on_change", commonEventPublishData, publishCallback); - }, 1000); + await sleep(1000) + console.debug("====>publish event account_on_change 0300===="); + commonevent.publish("account_on_change", commonEventPublishData, publishCallback); }); /* @@ -275,20 +269,19 @@ describe('ActsAccountChangeOnOff', async function () { commonevent.unsubscribe(subscriber, unSubscriberCallback); appAccountManager.deleteAccount("onoff_deleteFir", deleteAccountCallback); } - function publishCallback(err){ + async function publishCallback(err){ console.debug("====>publish call back err:" + JSON.stringify(err)); - setTimeout(async function (){ - console.debug("====>deleteAccount start===="); - try{ - await appAccountManager.deleteAccount("onoff_deleteSec"); - } - catch(err){ - console.error("====>deleteAccount fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>deleteAccount finish===="); - }, 500) + await sleep(500) + console.debug("====>deleteAccount start===="); + try{ + await appAccountManager.deleteAccount("onoff_deleteSec"); + } + catch(err){ + console.error("====>deleteAccount fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>deleteAccount finish===="); } var commonEventSubscribeInfo = { events: ["account_on_delete_another"] @@ -303,10 +296,9 @@ describe('ActsAccountChangeOnOff', async function () { var commonEventPublishData = { code: 4 } - setTimeout(function (){ - console.debug("====>publish event account_on_change 0400===="); - commonevent.publish("account_on_change", commonEventPublishData, publishCallback); - }, 1000); + await sleep(1000) + console.debug("====>publish event account_on_change 0400===="); + commonevent.publish("account_on_change", commonEventPublishData, publishCallback); }); /* @@ -333,20 +325,19 @@ describe('ActsAccountChangeOnOff', async function () { commonevent.unsubscribe(subscriber, unSubscriberCallback); done(); } - function publishCallback(err){ + async function publishCallback(err){ console.debug("====>publish call back err:" + JSON.stringify(err)); - setTimeout(async function (){ - console.debug("====>deleteAccount start===="); - try{ - await appAccountManager.deleteAccount("onoff_delete"); - } - catch(err){ - console.error("====>deleteAccount fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>deleteAccount finish===="); - }, 500) + await sleep(500) + console.debug("====>deleteAccount start===="); + try{ + await appAccountManager.deleteAccount("onoff_delete"); + } + catch(err){ + console.error("====>deleteAccount fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>deleteAccount finish===="); } var commonEventSubscribeInfo = { events: ["account_on_change_delete"] @@ -361,10 +352,9 @@ describe('ActsAccountChangeOnOff', async function () { var commonEventPublishData = { code: 5 } - setTimeout(function (){ - console.debug("====>publish event account_on_change 0500===="); - commonevent.publish("account_on_change", commonEventPublishData, publishCallback); - }, 1000); + await sleep(1000) + console.debug("====>publish event account_on_change 0500===="); + commonevent.publish("account_on_change", commonEventPublishData, publishCallback); }); /* @@ -404,20 +394,19 @@ describe('ActsAccountChangeOnOff', async function () { commonevent.unsubscribe(subscriber, unSubscriberCallback); appAccountManager.deleteAccount("onoff_enableFir", deleteAccountCallback); } - function publishCallback(err){ + async function publishCallback(err){ console.debug("====>publish call back err:" + JSON.stringify(err)); - setTimeout(async function (){ - console.debug("====>disableAppAccess start===="); - try{ - await appAccountManager.disableAppAccess("onoff_enableSec", "com.example.actsaccountsceneonoff"); - } - catch(err){ - console.error("====>disableAppAccess fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>disableAppAccess finish===="); - }, 500) + await sleep(500) + console.debug("====>disableAppAccess start===="); + try{ + await appAccountManager.disableAppAccess("onoff_enableSec", "com.example.actsaccountsceneonoff"); + } + catch(err){ + console.error("====>disableAppAccess fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>disableAppAccess finish===="); } var commonEventSubscribeInfo = { events: ["account_on_disable_another"] @@ -432,10 +421,9 @@ describe('ActsAccountChangeOnOff', async function () { var commonEventPublishData = { code: 6 } - setTimeout(function (){ + await sleep(1000) console.debug("====>publish event account_on_change 0600===="); commonevent.publish("account_on_change", commonEventPublishData, publishCallback); - }, 1000); }); /* @@ -467,20 +455,19 @@ describe('ActsAccountChangeOnOff', async function () { commonevent.unsubscribe(subscriber, unSubscriberCallback); appAccountManager.deleteAccount("onoff_disable", deleteAccountCallback); } - function publishCallback(err){ + async function publishCallback(err){ console.debug("====>publish call back err:" + JSON.stringify(err)); - setTimeout(async function (){ - console.debug("====>disableAppAccess start===="); - try{ - await appAccountManager.disableAppAccess("onoff_disable", "com.example.actsaccountsceneonoff"); - } - catch(err){ - console.error("====>disableAppAccess fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>disableAppAccess finish===="); - }, 500) + await sleep(500) + console.debug("====>disableAppAccess start===="); + try{ + await appAccountManager.disableAppAccess("onoff_disable", "com.example.actsaccountsceneonoff"); + } + catch(err){ + console.error("====>disableAppAccess fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>disableAppAccess finish===="); } var commonEventSubscribeInfo = { events: ["account_on_change_disable"] @@ -495,10 +482,9 @@ describe('ActsAccountChangeOnOff', async function () { var commonEventPublishData = { code: 7 } - setTimeout(function (){ - console.debug("====>publish event account_on_change 0700===="); - commonevent.publish("account_on_change", commonEventPublishData, publishCallback); - }, 1000); + await sleep(1000) + console.debug("====>publish event account_on_change 0700===="); + commonevent.publish("account_on_change", commonEventPublishData, publishCallback); }); /* @@ -651,7 +637,7 @@ describe('ActsAccountChangeOnOff', async function () { } twiceSign = twiceSign + 1; } - function changeOnSecondCallback(data){ + async function changeOnSecondCallback(data){ console.debug("====>second receive change 1000 data:" + JSON.stringify(data)); console.debug("====>data.length:" + data.length); for (let i = 0, len = data.length; i < len; i++) { @@ -664,19 +650,18 @@ describe('ActsAccountChangeOnOff', async function () { expect(data).assertEqual("com.example.actsaccounttest"); } twiceSign = twiceSign + 1; - 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).assertEqual(null); - expect(twiceSign).assertEqual(2); - console.debug("====>ActsAccountChangeOnOff_1000 end===="); - done(); - }); + await sleep(1000) + 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).assertEqual(null); + expect(twiceSign).assertEqual(2); + console.debug("====>ActsAccountChangeOnOff_1000 end===="); + done(); }); - }, 1000) + }); } try{ appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnFirstCallback); @@ -744,19 +729,18 @@ describe('ActsAccountChangeOnOff', async function () { expect().assertFail(); done(); } - setTimeout(async function (){ - console.debug("====>off 1100 start===="); - expect(sameSign).assertEqual(1); - appAccountManager.off('change', function (){ - console.debug("====>off ActsAccountChangeOnOff_1100 finish===="); - appAccountManager.deleteAccount("onoff_same", (err)=>{ - console.debug("====>delete account ActsAccountChangeOnOff_1100 err:" + JSON.stringify(err)); - expect(err).assertEqual(null); - console.debug("====>ActsAccountChangeOnOff_1100 end===="); - done(); - }); + await sleep(1000) + console.debug("====>off 1100 start===="); + expect(sameSign).assertEqual(1); + appAccountManager.off('change', function (){ + console.debug("====>off ActsAccountChangeOnOff_1100 finish===="); + appAccountManager.deleteAccount("onoff_same", (err)=>{ + console.debug("====>delete account ActsAccountChangeOnOff_1100 err:" + JSON.stringify(err)); + expect(err).assertEqual(null); + console.debug("====>ActsAccountChangeOnOff_1100 end===="); + done(); }); - }, 1000) + }); }); /* @@ -786,17 +770,16 @@ describe('ActsAccountChangeOnOff', async function () { } appAccountManager.off('change', function (){ console.debug("====>first off ActsAccountChangeOnOff_1200 finish===="); - appAccountManager.off('change', function (){ + appAccountManager.off('change',async function (){ console.debug("====>second off ActsAccountChangeOnOff_1200 finish===="); - setTimeout(async function (){ - console.debug("====>delete account 1200 start===="); - appAccountManager.deleteAccount("onoff_repeatoff", (err)=>{ - console.debug("====>delete account ActsAccountChangeOnOff_1200 err:" + JSON.stringify(err)); - expect(err).assertEqual(null); - console.debug("====>ActsAccountChangeOnOff_1200 end===="); - done(); - }); - }, 1000) + await sleep(1000) + console.debug("====>delete account 1200 start===="); + appAccountManager.deleteAccount("onoff_repeatoff", (err)=>{ + console.debug("====>delete account ActsAccountChangeOnOff_1200 err:" + JSON.stringify(err)); + expect(err).assertEqual(null); + console.debug("====>ActsAccountChangeOnOff_1200 end===="); + done(); + }); }); }); } @@ -855,15 +838,14 @@ describe('ActsAccountChangeOnOff', async function () { expect().assertFail(); done(); } - setTimeout(async function (){ - console.debug("====>delete account 1300 start===="); - appAccountManager.deleteAccount("onoff_same", (err)=>{ - console.debug("====>delete account ActsAccountChangeOnOff_1300 err:" + JSON.stringify(err)); - expect(err).assertEqual(null); - console.debug("====>ActsAccountChangeOnOff_1300 end===="); - done(); - }); - }, 1000) + await sleep(1000) + console.debug("====>delete account 1300 start===="); + appAccountManager.deleteAccount("onoff_same", (err)=>{ + console.debug("====>delete account ActsAccountChangeOnOff_1300 err:" + JSON.stringify(err)); + expect(err).assertEqual(null); + console.debug("====>ActsAccountChangeOnOff_1300 end===="); + done(); + }); }); /* @@ -902,14 +884,13 @@ describe('ActsAccountChangeOnOff', async function () { expect().assertFail(); done(); } - setTimeout(async function (){ - console.debug("====>delete account 1400 start===="); - appAccountManager.deleteAccount("onoff_same", (err)=>{ - console.debug("====>delete account ActsAccountChangeOnOff_1400 err:" + JSON.stringify(err)); - expect(err).assertEqual(null); - console.debug("====>ActsAccountChangeOnOff_1400 end===="); - done(); - }); - }, 1000) + await sleep(1000) + console.debug("====>delete account 1400 start===="); + appAccountManager.deleteAccount("onoff_same", (err)=>{ + console.debug("====>delete account ActsAccountChangeOnOff_1400 err:" + JSON.stringify(err)); + expect(err).assertEqual(null); + console.debug("====>ActsAccountChangeOnOff_1400 end===="); + done(); + }); }); }) \ No newline at end of file diff --git a/account/appaccount/actsgetallaccounts/entry/src/main/js/test/Getallaccounts.test.js b/account/appaccount/actsgetallaccounts/entry/src/main/js/test/Getallaccounts.test.js index 646a969361e47072203e8c3c5fe7361e5304a2b8..79345c0f41b0cb32850a766bbf446f86a3cf8eae 100755 --- a/account/appaccount/actsgetallaccounts/entry/src/main/js/test/Getallaccounts.test.js +++ b/account/appaccount/actsgetallaccounts/entry/src/main/js/test/Getallaccounts.test.js @@ -20,6 +20,15 @@ const TIMEOUT = 2000; const LENGTHLIMIT = 1024; describe('ActsGetAllAccounts', function () { + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) + } + /* * @tc.number : ActsGetAllAccounts_0100 * @tc.name : getAllAccounts callback @@ -285,10 +294,9 @@ describe('ActsGetAllAccounts', function () { done(); }); } - setTimeout(async function(){ - console.debug("====>getAllAccounts 0900 start===="); - appAccountManager.getAllAccounts(selfBundle, getAllCallback); - }, TIMEOUT); + await sleep(TIMEOUT) + console.debug("====>getAllAccounts 0900 start===="); + appAccountManager.getAllAccounts(selfBundle, getAllCallback); }); /* @@ -318,31 +326,30 @@ describe('ActsGetAllAccounts', function () { }, }, ); - setTimeout(async function(){ - console.debug("====>getAllAccounts 1000 start===="); - try{ - var data = await appAccountManager.getAllAccounts(selfBundle); - } - catch(err){ - console.error("====>getAllAccounts 1000 fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>getAllAccounts 1000 data:" + JSON.stringify(data)); - try{ - expect(data[0].name).assertEqual("Account_application_promise"); - expect(data[0].owner).assertEqual("com.example.actsgetallaaccounts"); - } - catch(err){ - console.error("====>check data 1000 fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>delete account 1000 start===="); - await appAccountManager.deleteAccount("Account_application_promise"); - console.debug("====>ActsGetAllAccounts_1000 end===="); + await sleep(TIMEOUT) + console.debug("====>getAllAccounts 1000 start===="); + try{ + var data = await appAccountManager.getAllAccounts(selfBundle); + } + catch(err){ + console.error("====>getAllAccounts 1000 fail err:" + JSON.stringify(err)); + expect().assertFail(); done(); - }, TIMEOUT); + } + console.debug("====>getAllAccounts 1000 data:" + JSON.stringify(data)); + try{ + expect(data[0].name).assertEqual("Account_application_promise"); + expect(data[0].owner).assertEqual("com.example.actsgetallaaccounts"); + } + catch(err){ + console.error("====>check data 1000 fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.debug("====>delete account 1000 start===="); + await appAccountManager.deleteAccount("Account_application_promise"); + console.debug("====>ActsGetAllAccounts_1000 end===="); + done(); }); /* @@ -379,10 +386,9 @@ describe('ActsGetAllAccounts', function () { console.debug("====>ActsGetAllAccounts_1100 end===="); done(); } - setTimeout(async function(){ - console.debug("====>getAllAccounts 1100 start===="); - appAccountManager.getAllAccounts(specifiedBundle, getAllCallback); - }, TIMEOUT); + await sleep(TIMEOUT) + console.debug("====>getAllAccounts 1100 start===="); + appAccountManager.getAllAccounts(specifiedBundle, getAllCallback); }); /* @@ -410,22 +416,21 @@ describe('ActsGetAllAccounts', function () { }, }, ); - setTimeout(async function(){ - console.debug("====>getAllAccounts 1200 start===="); - try{ - var data = await appAccountManager.getAllAccounts(specifiedBundle); - } - catch(err){ - console.error("====>getAllAccounts 1200 fail err:" + JSON.stringify(err)); - expect().assertFail(); - done(); - } - console.debug("====>getAllAccounts 1200 data:" + JSON.stringify(data)); - expect(data[0].name).assertEqual("account_name_scene_single"); - expect(data[0].owner).assertEqual("com.example.actsscenegetallaccounts"); - console.debug("====>ActsGetAllAccounts_1200 end===="); + await sleep(TIMEOUT) + console.debug("====>getAllAccounts 1200 start===="); + try{ + var data = await appAccountManager.getAllAccounts(specifiedBundle); + } + catch(err){ + console.error("====>getAllAccounts 1200 fail err:" + JSON.stringify(err)); + expect().assertFail(); done(); - }, TIMEOUT); + } + console.debug("====>getAllAccounts 1200 data:" + JSON.stringify(data)); + expect(data[0].name).assertEqual("account_name_scene_single"); + expect(data[0].owner).assertEqual("com.example.actsscenegetallaccounts"); + console.debug("====>ActsGetAllAccounts_1200 end===="); + done(); }); /* diff --git a/account/appaccount/actssetchecksyncenable/entry/src/main/js/test/Syncenable.test.js b/account/appaccount/actssetchecksyncenable/entry/src/main/js/test/Syncenable.test.js index 58961207eb4191d2e9e950eef9e50fdb7fd8275e..f948c253c7f4d2f8e366d09b879a6dd177cf14c8 100755 --- a/account/appaccount/actssetchecksyncenable/entry/src/main/js/test/Syncenable.test.js +++ b/account/appaccount/actssetchecksyncenable/entry/src/main/js/test/Syncenable.test.js @@ -30,16 +30,18 @@ describe('ActsSetCheckSyncEnable', function () { var atManager = abilityAccessCtrl.createAtManager(); var result = await atManager.grantUserGrantedPermission(tokenID, PERMISSION_USER_NAME, PERMISSION_USER_SET); console.debug("tokenId" + tokenID + " result:" + result); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }) - function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } /* diff --git a/account/appaccount/getallaccessibleaccounts/actsgetallaccessiblemultiple/entry/src/main/js/test/Getmultiple.test.js b/account/appaccount/getallaccessibleaccounts/actsgetallaccessiblemultiple/entry/src/main/js/test/Getmultiple.test.js index 47e0a82c7dc8b623a0d6a1d67f1f8f19d90d1bd5..188c57427257e394bbdf2425800a4c250dc96da0 100755 --- a/account/appaccount/getallaccessibleaccounts/actsgetallaccessiblemultiple/entry/src/main/js/test/Getmultiple.test.js +++ b/account/appaccount/getallaccessibleaccounts/actsgetallaccessiblemultiple/entry/src/main/js/test/Getmultiple.test.js @@ -33,15 +33,17 @@ describe('ActsGetAllAccessibleMultiple', function () { }, }, ); - sleep(TIMEOUT); + await sleep(TIMEOUT); done(); }); - function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + async function sleep(delay) { + let timeoutId = null; + var promise = new Promise((resolve, reject) => { + timeoutId = setTimeout(() => resolve("done!"), delay); + }); + await promise + clearTimeout(timeoutId) } /*