diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/MainAbility/MainAbility.ts index 881e90c13c2404e167090ce55019ad24f8b4cc2b..7dcadfa152cddd2581481554ccea6fca19341b9c 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -47,4 +47,28 @@ export default class MainAbility extends Ability { // Ability has back to background console.log("[Demo] MainAbility onBackground") } + + onConfigurationUpdate(config) { + console.log('[Demo] MainAbility onConfigurationUpdate: ' + this.context.config.language) + console.log('[Demo] MainAbility onConfigurationUpdate: ' + config.language) + if (globalThis.UpdateConfiguration_0200_prepare_resolve) { + globalThis.UpdateConfiguration_0200_prepare_resolve(); + } + + if (!globalThis.UpdateConfiguration_0200_resolve) { + console.log("[Demo] MainAbility invalid resolve") + return; + } + + if (!globalThis.UpdateConfiguration_0200_reject) { + console.log("[Demo] MainAbility invalid reject") + return; + } + + if (this.context.config.language == "English" && config.language == "zh-Hans") { + globalThis.UpdateConfiguration_0200_resolve(); + } else { + globalThis.UpdateConfiguration_0200_reject(); + } + } }; diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets index 1f7f77d4a82970c8cc6bea378deb7dbb65bb5ccb..12f62432a26f35a4f3ad7d3c295311c33b7a8c13 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets @@ -131,5 +131,65 @@ export default function ApiCoverTest() { done(); } }); + + /* + * @tc.number SUB_AA_UpdateConfiguration_0200 + * @tc.name Test updateConfiguration. + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_UpdateConfiguration_0200', 0, async function (done) { + let enLanguage = { + language: 'English' + } + let zhLanguage = { + language: 'zh-Hans' + } + + // set language to english + await new Promise((resolve, reject) => { + globalThis.UpdateConfiguration_0200_prepare_resolve = resolve; + console.info("SUB_AA_UpdateConfiguration_0200 ----> before set language to english."); + abilityManager.updateConfiguration(enLanguage).then(() => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> set language to english succeed."); + }).catch(err => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> failed to set language to english: " + err); + globalThis.UpdateConfiguration_0200_prepare_resolve(); + }); + }).then(() => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> succees to set language."); + }).catch(err => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> failed to set language: " + err); + }).finally(() => { + globalThis.UpdateConfiguration_0200_prepare_resolve = null; + globalThis.UpdateConfiguration_0200_resolve = null; + globalThis.UpdateConfiguration_0200_reject = null; + console.info("SUB_AA_UpdateConfiguration_0200 ----> set promise to null after all"); + }); + + + // set language to chinese + await new Promise((resolve, reject) => { + globalThis.UpdateConfiguration_0200_resolve = resolve; + globalThis.UpdateConfiguration_0200_reject = reject; + console.info("SUB_AA_UpdateConfiguration_0200 ----> before set language to chinese."); + abilityManager.updateConfiguration(zhLanguage).then(() => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> set language to chinese succeed."); + }).catch(err => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> failed to set language to chinese: " + err); + }); + }).then(() => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> succees to set language."); + expect(true).assertTrue(); + }).catch(err => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> failed to set language: " + err); + expect(false).assertTrue(); + }).finally(() => { + globalThis.UpdateConfiguration_0200_resolve = null; + globalThis.UpdateConfiguration_0200_reject = null; + console.info("SUB_AA_UpdateConfiguration_0200 ----> set promise to null after all"); + done(); + }); + }); }) }