diff --git a/api/@ohos.application.abilityDelegatorRegistry.d.ts b/api/@ohos.application.abilityDelegatorRegistry.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c21a8cc64ede0a8d5e28226ba6dc2087d3b8ff97 --- /dev/null +++ b/api/@ohos.application.abilityDelegatorRegistry.d.ts @@ -0,0 +1,62 @@ +/* + * 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 { AbilityDelegator } from './application/abilityDelegator' +import { AbilityDelegatorArgs } from './application/abilityDelegatorArgs' + +/** + * A global register used to store the AbilityDelegator and AbilityDelegatorArgs objects registered + * during application startup. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @import import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + * @permission N/A + */ +declare namespace abilityDelegatorRegistry { + /** + * Get the AbilityDelegator object of the application. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @return the AbilityDelegator object initialized when the application is started. + */ + function getAbilityDelegator(): AbilityDelegator; + + /** + * Get unit test parameters stored in the AbilityDelegatorArgs object. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @return the previously registered AbilityDelegatorArgs object. + */ + function getArguments(): AbilityDelegatorArgs; + + /** + * Describes all lifecycle states of an ability. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + export enum AbilityLifecycleState { + UNINITIALIZED, + CREATE, + FOREGROUND, + BACKGROUND, + DESTROY, + } +} + +export default abilityDelegatorRegistry; \ No newline at end of file diff --git a/api/@ohos.application.testRunner.d.ts b/api/@ohos.application.testRunner.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..58593017d019b48e98981fd1e5218d61cc7e77c8 --- /dev/null +++ b/api/@ohos.application.testRunner.d.ts @@ -0,0 +1,43 @@ +/* + * 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. + */ + +/** + * Base class for the test framework. + * If you want to implement your own unit test framework, you must inherit this class and overrides all its methods. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @import import TestRunner from '@ohos.application.testRunner' + * @permission N/A + */ +export interface TestRunner { + /** + * Prepare the unit testing environment for running test cases. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onPrepare(): void; + + /** + * Run all test cases. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onRun(): void; +} + +export default TestRunner; \ No newline at end of file diff --git a/api/application/abilityDelegator.d.ts b/api/application/abilityDelegator.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8f48ca1ad1e32788ac2727da7bf573bca17d33bd --- /dev/null +++ b/api/application/abilityDelegator.d.ts @@ -0,0 +1,153 @@ +/* + * 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 { AsyncCallback } from '../basic'; +import { Ability } from '../@ohos.application.Ability' +import { AbilityMonitor } from './abilityMonitor' +import { Context } from '../app/context' +import { ShellCmdResult } from './shellCmdResult' + +/** + * A global test utility interface used for adding AbilityMonitor objects and control lifecycle states of abilities. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @import import AbilityDelegator from 'application/abilityDelegator.d' + * @permission N/A + */ +export interface AbilityDelegator { + /** + * Add an AbilityMonitor object for monitoring the lifecycle state changes of the specified ability. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @param monitor AbilityMonitor object + */ + addAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback): void; + addAbilityMonitor(monitor: AbilityMonitor): Promise; + + /** + * Remove a specified AbilityMonitor object from the application memory. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @param monitor AbilityMonitor object + */ + removeAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback): void; + removeAbilityMonitor(monitor: AbilityMonitor): Promise; + + /** + * Wait for and returns the Ability object that matches the conditions set in the given AbilityMonitor. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @param monitor AbilityMonitor object + * @param timeout Maximum wait time, in milliseconds + * @return success: return the Ability object, failure: return null + */ + waitAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback): void; + waitAbilityMonitor(monitor: AbilityMonitor, timeout: number, callback: AsyncCallback): void; + waitAbilityMonitor(monitor: AbilityMonitor, timeout?: number): Promise; + + /** + * Obtain the application context. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @return App Context + */ + getAppContext(): Context; + + /** + * Obtain the lifecycle state of a specified ability. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @param ability The Ability object + * @return The state of the Ability object. enum AbilityLifecycleState + */ + getAbilityState(ability: Ability): number; + + /** + * Obtain the ability that is currently being displayed. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @return The top ability of the current application + */ + getCurrentTopAbility(callback: AsyncCallback): void; + getCurrentTopAbility(): Promise + + /** + * Invoke the Ability.onForeground() callback of a specified ability without changing its lifecycle state. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @param ability The ability object + * @return true: success false: failure + */ + doAbilityForeground(ability: Ability, callback: AsyncCallback): void; + doAbilityForeground(ability: Ability): Promise; + + /** + * Invoke the Ability.onBackground() callback of a specified ability without changing its lifecycle state. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @param ability The ability object + * @return true: success false: failure + */ + doAbilityBackground(ability: Ability, callback: AsyncCallback): void; + doAbilityBackground(ability: Ability): Promise; + + /** + * Prints log information to the unit testing console. + * The total length of the log information to be printed cannot exceed 1000 characters. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @param msg Log information + */ + print(msg: string, callback: AsyncCallback): void; + print(msg: string): Promise; + + /** + * Execute the given command in the aa tools side. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @param cmd Shell command + * @param timeoutSecs Timeout, in seconds + * @return ShellCmdResult object + */ + executeShellCommand(cmd: string, callback: AsyncCallback): void; + executeShellCommand(cmd: string, timeoutSecs: number, callback: AsyncCallback): void; + executeShellCommand(cmd: string, timeoutSecs?: number): Promise; + + /** + * Prints log information to the unit testing console. + * The total length of the log information to be printed cannot exceed 1000 characters. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @hide + * @param msg Log information + * @param code Result code + */ + finishTest(msg: string, code: number, callback: AsyncCallback): void; + finishTest(msg: string, code: number): Promise; +} + +export default AbilityDelegator; \ No newline at end of file diff --git a/api/application/abilityDelegatorArgs.d.ts b/api/application/abilityDelegatorArgs.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..321a68e0d256c10e48f33031dafaff2138b24167 --- /dev/null +++ b/api/application/abilityDelegatorArgs.d.ts @@ -0,0 +1,59 @@ +/* + * 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. + */ + + +/** + * Store unit testing-related parameters, including test case names, and test runner name. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @import import AbilityDelegatorArgs from 'application/abilityDelegatorArgs.d' + * @permission N/A + */ +export interface AbilityDelegatorArgs { + /** + * the bundle name of the application being tested. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + bundleName: string; + + /** + * the parameters used for unit testing. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + parameters: {[key: string]: string}; + + /** + * the class names of all test cases. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + testCaseNames: string; + + /** + * the class name of the test runner used to execute test cases. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + testRunnerClassName: string; +} + +export default AbilityDelegatorArgs; \ No newline at end of file diff --git a/api/application/abilityMonitor.d.ts b/api/application/abilityMonitor.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..81806c4369611e8fb3aaefa64ab368a0c452dc68 --- /dev/null +++ b/api/application/abilityMonitor.d.ts @@ -0,0 +1,91 @@ +/* + * 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. + */ + +/** + * Provide methods for matching monitored Ability objects that meet specified conditions. + * The most recently matched Ability objects will be saved in the AbilityMonitor object. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @import import AbilityMonitor from 'application/abilityMonitor.d' + * @permission N/A + */ +export interface AbilityMonitor { + /** + * The name of the ability to monitor. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + abilityName: string; + + /** + * Called back when the ability is started for initialization. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onAbilityCreate?:() => void; + + /** + * Called back when the state of the ability changes to foreground. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onAbilityForeground?:() => void; + + /** + * Called back when the state of the ability changes to background. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onAbilityBackground?:() => void; + + /** + * Called back before the ability is destroyed. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onAbilityDestroy?:() => void; + + /** + * Called back when an ability window stage is created. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onWindowStageCreate?:() => void; + + /** + * Called back when an ability window stage is restored. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onWindowStageRestore?:() => void; + + /** + * Called back when an ability window stage is destroyed. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + onWindowStageDestroy?:() => void; +} + +export default AbilityMonitor; \ No newline at end of file diff --git a/api/application/shellCmdResult.d.ts b/api/application/shellCmdResult.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..b8cc3f894a8eb9629dbcd60d3d53d6a1d60ed076 --- /dev/null +++ b/api/application/shellCmdResult.d.ts @@ -0,0 +1,42 @@ +/* + * 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. + */ + +/** + * A object that records the result of shell command executes. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @import import ShellCmdResult from 'application/shellCmdResult.d' + * @permission N/A + */ +export interface ShellCmdResult { + /** + * the cmd standard result. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + stdResult: String; + + /** + * shell cmd exec result. + * + * @since 9 + * @syscap SystemCapability.Ability.AbilityRuntime.Core + */ + exitCode: number; +} + +export default ShellCmdResult; \ No newline at end of file